Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
R
reactive-web
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
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
Ashok Kumar K
reactive-web
Commits
6cbe12e3
Commit
6cbe12e3
authored
Sep 21, 2020
by
Ashok Kumar K
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
added getAllProducts and changed 'as' operator to 'flatMap'
parent
c53896a7
Changes
5
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
30 additions
and
7 deletions
+30
-7
ProductHandler.java
...java/com/nisum/reactiveweb/controller/ProductHandler.java
+12
-7
ProductRepository.java
...a/com/nisum/reactiveweb/repository/ProductRepository.java
+3
-0
ProductRepositoryImpl.java
...m/nisum/reactiveweb/repository/ProductRepositoryImpl.java
+6
-0
ProductService.java
...in/java/com/nisum/reactiveweb/service/ProductService.java
+3
-0
ProductServiceImpl.java
...ava/com/nisum/reactiveweb/service/ProductServiceImpl.java
+6
-0
No files found.
src/main/java/com/nisum/reactiveweb/controller/ProductHandler.java
View file @
6cbe12e3
...
...
@@ -40,29 +40,34 @@ public class ProductHandler {
.
path
(
"/product"
,
()
->
route
()
.
GET
(
SKU_TEXT_PATH_VAR
,
req
->
productService
.
getProductBySku
(
req
.
pathVariable
(
SKU_TEXT
))
.
as
(
productMono
->
ok
()
.
body
(
productMono
,
Product
.
class
))
.
flatMap
(
product
->
ok
()
.
body
Value
(
product
))
)
.
POST
(
""
,
req
->
req
.
bodyToMono
(
Product
.
class
)
.
doOnNext
(
this
::
validateProduct
)
.
flatMap
(
productService:
:
saveProduct
)
.
as
(
productMono
->
created
(
req
.
uri
())
.
body
(
productMono
,
Product
.
class
))
.
flatMap
(
product
->
created
(
req
.
uri
())
.
body
Value
(
product
))
)
.
PUT
(
SKU_TEXT_PATH_VAR
,
req
->
req
.
bodyToMono
(
Product
.
class
)
.
doOnNext
(
this
::
validateProduct
)
.
flatMap
(
product
->
productService
.
updateProduct
(
req
.
pathVariable
(
SKU_TEXT
),
product
))
.
as
(
productMono
->
accepted
()
.
body
(
productMono
,
Product
.
class
))
.
flatMap
(
product
->
accepted
()
.
body
Value
(
product
))
)
.
DELETE
(
SKU_TEXT_PATH_VAR
,
req
->
productService
.
removeProduct
(
req
.
pathVariable
(
SKU_TEXT
))
.
as
(
res
->
ok
().
body
(
res
,
String
.
clas
s
))
.
flatMap
(
res
->
ok
().
bodyValue
(
re
s
))
)
.
build
())
.
path
(
"/products"
,
()
->
route
()
.
GET
(
""
,
req
->
ok
()
.
body
(
productService
.
getAllProducts
(),
Product
.
class
)
).
build
())
.
build
();
}
...
...
src/main/java/com/nisum/reactiveweb/repository/ProductRepository.java
View file @
6cbe12e3
package
com
.
nisum
.
reactiveweb
.
repository
;
import
com.nisum.reactiveweb.model.Product
;
import
reactor.core.publisher.Flux
;
import
reactor.core.publisher.Mono
;
public
interface
ProductRepository
{
Mono
<
Product
>
getProductBySku
(
String
id
);
Flux
<
Product
>
getAllProducts
();
Mono
<
Product
>
saveProduct
(
Product
product
);
Mono
<
Product
>
updateProduct
(
String
sku
,
Product
product
);
...
...
src/main/java/com/nisum/reactiveweb/repository/ProductRepositoryImpl.java
View file @
6cbe12e3
...
...
@@ -3,6 +3,7 @@ package com.nisum.reactiveweb.repository;
import
com.mongodb.client.result.DeleteResult
;
import
com.nisum.reactiveweb.model.Product
;
import
lombok.AllArgsConstructor
;
import
reactor.core.publisher.Flux
;
import
reactor.core.publisher.Mono
;
import
org.springframework.data.mongodb.core.FindAndModifyOptions
;
...
...
@@ -23,6 +24,11 @@ public class ProductRepositoryImpl implements ProductRepository {
return
template
.
findById
(
sku
,
Product
.
class
);
}
@Override
public
Flux
<
Product
>
getAllProducts
()
{
return
template
.
findAll
(
Product
.
class
);
}
@Override
public
Mono
<
Product
>
saveProduct
(
Product
product
)
{
return
template
.
save
(
product
);
...
...
src/main/java/com/nisum/reactiveweb/service/ProductService.java
View file @
6cbe12e3
package
com
.
nisum
.
reactiveweb
.
service
;
import
com.nisum.reactiveweb.model.Product
;
import
reactor.core.publisher.Flux
;
import
reactor.core.publisher.Mono
;
import
org.springframework.stereotype.Service
;
...
...
@@ -9,6 +10,8 @@ import org.springframework.stereotype.Service;
public
interface
ProductService
{
Mono
<
Product
>
getProductBySku
(
String
sku
);
Flux
<
Product
>
getAllProducts
();
Mono
<
Product
>
saveProduct
(
Product
product
);
Mono
<
Product
>
updateProduct
(
String
sku
,
Product
product
);
...
...
src/main/java/com/nisum/reactiveweb/service/ProductServiceImpl.java
View file @
6cbe12e3
...
...
@@ -5,6 +5,7 @@ import com.nisum.reactiveweb.model.Product;
import
com.nisum.reactiveweb.repository.ProductRepository
;
import
lombok.AllArgsConstructor
;
import
lombok.extern.slf4j.Slf4j
;
import
reactor.core.publisher.Flux
;
import
reactor.core.publisher.Mono
;
import
org.springframework.stereotype.Service
;
...
...
@@ -21,6 +22,11 @@ public class ProductServiceImpl implements ProductService {
.
switchIfEmpty
(
Mono
.
error
(
new
ProductNotFoundException
()));
}
@Override
public
Flux
<
Product
>
getAllProducts
()
{
return
repository
.
getAllProducts
();
}
@Override
public
Mono
<
Product
>
saveProduct
(
Product
productToSave
)
{
return
Mono
.
just
(
productToSave
)
...
...
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