Skip to content

Commit a2c9004

Browse files
committed
Added POSTMAN collection for testng webflux-02-mongo-rest-api
1 parent 72192ae commit a2c9004

File tree

19 files changed

+762
-0
lines changed

19 files changed

+762
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,171 @@
1+
{
2+
"info": {
3+
"_postman_id": "63f2790a-bdfa-4eff-bef5-7094c62857ad",
4+
"name": "Spring_WebFlux_MongoDB",
5+
"schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json"
6+
},
7+
"item": [
8+
{
9+
"name": "CREATE Contact",
10+
"request": {
11+
"method": "POST",
12+
"header": [
13+
{
14+
"key": "Content-Type",
15+
"value": "application/json",
16+
"type": "text"
17+
}
18+
],
19+
"body": {
20+
"mode": "raw",
21+
"raw": "{\n \"email\": \"[email protected]\",\n \"name\": \"Test from Postman\",\n \"phone\": \"110000000000\"\n}"
22+
},
23+
"url": {
24+
"raw": "{{baseURL}}/controller/contacts",
25+
"host": [
26+
"{{baseURL}}"
27+
],
28+
"path": [
29+
"controller",
30+
"contacts"
31+
],
32+
"query": [
33+
{
34+
"key": "",
35+
"value": null,
36+
"disabled": true
37+
}
38+
]
39+
},
40+
"description": "Create a Contact Object"
41+
},
42+
"response": []
43+
},
44+
{
45+
"name": "UPDATE Contact",
46+
"request": {
47+
"method": "PUT",
48+
"header": [],
49+
"body": {
50+
"mode": "raw",
51+
"raw": "{\"id\":\"5f14887390baf8178f4b9283\",\"name\":\"Test from Postman updated\",\"email\":\"[email protected]\",\"phone\":\"110000000000\"}",
52+
"options": {
53+
"raw": {
54+
"language": "json"
55+
}
56+
}
57+
},
58+
"url": {
59+
"raw": "{{baseURL}}/controller/contacts/5f14887390baf8178f4b9283",
60+
"host": [
61+
"{{baseURL}}"
62+
],
63+
"path": [
64+
"controller",
65+
"contacts",
66+
"5f14887390baf8178f4b9283"
67+
]
68+
}
69+
},
70+
"response": []
71+
},
72+
{
73+
"name": "DELETE Contact",
74+
"request": {
75+
"method": "DELETE",
76+
"header": [],
77+
"url": {
78+
"raw": "{{baseURL}}/controller/contacts/5f14887390baf8178f4b9283",
79+
"host": [
80+
"{{baseURL}}"
81+
],
82+
"path": [
83+
"controller",
84+
"contacts",
85+
"5f14887390baf8178f4b9283"
86+
]
87+
}
88+
},
89+
"response": []
90+
},
91+
{
92+
"name": "GET by Id Contact",
93+
"request": {
94+
"method": "GET",
95+
"header": [
96+
{
97+
"key": "Accept",
98+
"value": "application/json",
99+
"type": "text"
100+
}
101+
],
102+
"url": {
103+
"raw": "{{baseURL}}/controller/contacts/5f14887390baf8178f4b9283",
104+
"host": [
105+
"{{baseURL}}"
106+
],
107+
"path": [
108+
"controller",
109+
"contacts",
110+
"5f14887390baf8178f4b9283"
111+
]
112+
}
113+
},
114+
"response": []
115+
},
116+
{
117+
"name": "GET all Contacts",
118+
"request": {
119+
"method": "GET",
120+
"header": [
121+
{
122+
"key": "Accept",
123+
"value": "application/json",
124+
"type": "text"
125+
}
126+
],
127+
"url": {
128+
"raw": "{{baseURL}}/controller/contacts/",
129+
"host": [
130+
"{{baseURL}}"
131+
],
132+
"path": [
133+
"controller",
134+
"contacts",
135+
""
136+
]
137+
}
138+
},
139+
"response": []
140+
}
141+
],
142+
"event": [
143+
{
144+
"listen": "prerequest",
145+
"script": {
146+
"id": "31f1f75f-6c38-4778-94c7-06c893e4b8bf",
147+
"type": "text/javascript",
148+
"exec": [
149+
""
150+
]
151+
}
152+
},
153+
{
154+
"listen": "test",
155+
"script": {
156+
"id": "82a43092-b47a-458c-a240-8c26389ba8ac",
157+
"type": "text/javascript",
158+
"exec": [
159+
""
160+
]
161+
}
162+
}
163+
],
164+
"variable": [
165+
{
166+
"id": "98d97b59-b13f-401d-8fb8-aaaa965345f8",
167+
"key": "baseURL",
168+
"value": "http://localhost:8083"
169+
}
170+
]
171+
}

webflux-02-mongo-rest-api/pom.xml

+71
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
5+
<parent>
6+
<artifactId>spring-webflux-tutorial</artifactId>
7+
<groupId>com.jstobigdata</groupId>
8+
<version>1.0-SNAPSHOT</version>
9+
</parent>
10+
<modelVersion>4.0.0</modelVersion>
11+
<packaging>jar</packaging>
12+
<artifactId>webflux-02-mongo-rest-functional-approach</artifactId>
13+
<description>Build a Spring Webflux + MongoDB non blocking REST API using functional approach</description>
14+
15+
<properties>
16+
<springfox.version>3.0.0-SNAPSHOT</springfox.version>
17+
</properties>
18+
19+
<dependencies>
20+
<dependency>
21+
<groupId>org.springframework.boot</groupId>
22+
<artifactId>spring-boot-starter-webflux</artifactId>
23+
</dependency>
24+
25+
<dependency>
26+
<groupId>org.springframework.boot</groupId>
27+
<artifactId>spring-boot-starter-data-mongodb-reactive</artifactId>
28+
</dependency>
29+
30+
<!--Swagger dependencies -->
31+
<dependency>
32+
<groupId>io.springfox</groupId>
33+
<artifactId>springfox-boot-starter</artifactId>
34+
<version>3.0.0</version>
35+
</dependency>
36+
37+
<dependency>
38+
<groupId>org.springframework.boot</groupId>
39+
<artifactId>spring-boot-starter-test</artifactId>
40+
<scope>test</scope>
41+
<exclusions>
42+
<exclusion>
43+
<groupId>org.junit.vintage</groupId>
44+
<artifactId>junit-vintage-engine</artifactId>
45+
</exclusion>
46+
</exclusions>
47+
</dependency>
48+
49+
<dependency>
50+
<groupId>io.projectreactor</groupId>
51+
<artifactId>reactor-test</artifactId>
52+
<scope>test</scope>
53+
</dependency>
54+
55+
<dependency>
56+
<groupId>org.springframework.boot</groupId>
57+
<artifactId>spring-boot-devtools</artifactId>
58+
<optional>true</optional>
59+
<scope>runtime</scope>
60+
</dependency>
61+
</dependencies>
62+
63+
<repositories>
64+
<repository>
65+
<id>jcenter-snapshots</id>
66+
<name>jcenter</name>
67+
<url>http://oss.jfrog.org/artifactory/oss-snapshot-local/</url>
68+
</repository>
69+
</repositories>
70+
71+
</project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package c.jbd.webflux;
2+
3+
import org.springframework.boot.SpringApplication;
4+
import org.springframework.boot.autoconfigure.SpringBootApplication;
5+
import springfox.documentation.oas.annotations.EnableOpenApi;
6+
import springfox.documentation.swagger2.annotations.EnableSwagger2;
7+
import springfox.documentation.swagger2.annotations.EnableSwagger2WebFlux;
8+
9+
@SpringBootApplication
10+
@EnableSwagger2
11+
public class SpringBootMongoRest {
12+
public static void main(String[] args) {
13+
SpringApplication.run(SpringBootMongoRest.class, args);
14+
}
15+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package c.jbd.webflux.controller;
2+
3+
import org.springframework.web.bind.annotation.RestControllerAdvice;
4+
5+
//@RestControllerAdvice
6+
public class AppExceptionHandler {
7+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
package c.jbd.webflux.controller;
2+
3+
import c.jbd.webflux.data.mongo.Contact;
4+
import c.jbd.webflux.data.mongo.ContactRepository;
5+
import org.springframework.beans.factory.annotation.Autowired;
6+
import org.springframework.http.HttpStatus;
7+
import org.springframework.http.ResponseEntity;
8+
import org.springframework.web.bind.annotation.*;
9+
import reactor.core.publisher.Flux;
10+
import reactor.core.publisher.Mono;
11+
12+
//@RestController
13+
@RequestMapping("/controller")
14+
public class ContactController {
15+
16+
private final ContactRepository contactRepository;
17+
18+
@Autowired
19+
public ContactController(ContactRepository contactRepository) {
20+
this.contactRepository = contactRepository;
21+
}
22+
23+
@GetMapping("/contacts")
24+
public Flux<Contact> getAllContacts() {
25+
return contactRepository.findAll();
26+
}
27+
28+
@GetMapping(value = "/contacts/{id}")
29+
public Mono<ResponseEntity<Contact>> getContact(@PathVariable String id) {
30+
return contactRepository.findById(id)
31+
.map(contact -> new ResponseEntity<>(contact, HttpStatus.OK))
32+
.defaultIfEmpty(new ResponseEntity<>(HttpStatus.NOT_FOUND));
33+
}
34+
35+
@GetMapping(value = "/contacts/byEmail/{email}")
36+
public Mono<ResponseEntity<Contact>> getByEmail(@PathVariable String email) {
37+
return contactRepository.findFirstByEmail(email)
38+
.map(contact -> new ResponseEntity<>(contact, HttpStatus.OK))
39+
.defaultIfEmpty(new ResponseEntity<>(HttpStatus.NOT_FOUND));
40+
}
41+
42+
@PostMapping("/contacts")
43+
public Mono<ResponseEntity<Contact>> insertContact(@RequestBody Contact contact){
44+
return contactRepository.insert(contact)
45+
.map(contact1 -> new ResponseEntity<>(contact1, HttpStatus.ACCEPTED))
46+
.defaultIfEmpty(new ResponseEntity<>(contact, HttpStatus.NOT_ACCEPTABLE));
47+
}
48+
49+
@PutMapping("/contacts/{id}")
50+
public Mono<ResponseEntity<Contact>> updateContact(@RequestBody Contact contact, @PathVariable String id) {
51+
return contactRepository.findById(id)
52+
.flatMap(contact1 -> {
53+
contact.setId(id);
54+
return contactRepository.save(contact)
55+
.map(contact2 -> new ResponseEntity<>(contact2, HttpStatus.ACCEPTED));
56+
}).defaultIfEmpty(new ResponseEntity<>(HttpStatus.NOT_FOUND));
57+
}
58+
59+
@DeleteMapping(value = "/contacts/{id}")
60+
public Mono<Void> deleteContact(@PathVariable String id) {
61+
return contactRepository.deleteById(id);
62+
}
63+
}

0 commit comments

Comments
 (0)