Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
W
webflux-springboot-CRUD-app
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Christopher Cottier
webflux-springboot-CRUD-app
Commits
3f1d11a1
Commit
3f1d11a1
authored
Apr 23, 2021
by
ccottier
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
working put statement for product
parent
ec6b701a
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
35 additions
and
0 deletions
+35
-0
ProductController.java
...a/com/nisum/webfluxday2/controller/ProductController.java
+10
-0
ProductService.java
...in/java/com/nisum/webfluxday2/service/ProductService.java
+25
-0
No files found.
src/main/java/com/nisum/webfluxday2/controller/ProductController.java
View file @
3f1d11a1
...
...
@@ -32,5 +32,15 @@ public class ProductController {
return
productService
.
addProduct
(
productRequest
);
}
@PutMapping
(
"/products/{id}"
)
public
Mono
<
ProductResponse
>
alterProduct
(
@PathVariable
String
id
,
@RequestBody
ProductRequest
productRequest
){
return
productService
.
alterProduct
(
id
,
productRequest
);
}
@DeleteMapping
(
"/products/{id}"
)
public
Mono
<
Boolean
>
deleteProduct
(
@PathVariable
String
id
){
return
productService
.
deleteProduct
(
id
);
}
}
src/main/java/com/nisum/webfluxday2/service/ProductService.java
View file @
3f1d11a1
...
...
@@ -30,4 +30,29 @@ public class ProductService {
Mono
<
Product
>
product
=
productRepository
.
findById
(
id
);
return
product
.
map
(
prod
->
new
ProductResponse
(
prod
));
}
public
Mono
<
ProductResponse
>
alterProduct
(
String
id
,
ProductRequest
productRequest
)
{
System
.
out
.
println
(
"put service"
);
Mono
<
Product
>
product
=
productRepository
.
findById
(
id
);
return
product
.
flatMap
(
prod
->
{
prod
.
setDescription
(
productRequest
.
getDescription
());
prod
.
setPrice
(
productRequest
.
getPrice
());
prod
.
setName
(
productRequest
.
getName
());
return
productRepository
.
save
(
prod
);
}).
map
(
prod
->
new
ProductResponse
(
prod
));
}
public
Mono
<
Boolean
>
deleteProduct
(
String
id
)
{
Mono
<
Product
>
productToDelete
=
productRepository
.
findById
(
id
);
return
productToDelete
.
map
(
product
->
{
productRepository
.
delete
(
product
);
return
product
;
}).
hasElement
();
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment