Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
W
Web Flux Demo
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
Lokesh Singh
Web Flux Demo
Commits
7f7031e4
Commit
7f7031e4
authored
2 years ago
by
Lokesh Singh
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
added a method in controller class
parent
171e9d49
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
13 additions
and
3 deletions
+13
-3
AnimalController.java
...a/com/lokesh/webfluxdemo/controller/AnimalController.java
+13
-3
No files found.
src/main/java/com/lokesh/webfluxdemo/controller/AnimalController.java
View file @
7f7031e4
package
com
.
lokesh
.
webfluxdemo
.
controller
;
import
com.lokesh.webfluxdemo.config.MongoConfig
;
import
com.lokesh.webfluxdemo.model.Animal
;
import
com.lokesh.webfluxdemo.repository.AnimalRepository
;
import
com.lokesh.webfluxdemo.resource.AnimalResource
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.http.HttpStatus
;
import
org.springframework.http.MediaType
;
import
org.springframework.web.bind.annotation.GetMapping
;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.RestController
;
import
org.springframework.web.bind.annotation.*
;
import
reactor.core.publisher.Flux
;
import
reactor.core.publisher.Mono
;
import
java.time.Duration
;
...
...
@@ -19,9 +20,18 @@ public class AnimalController {
private
AnimalRepository
animalRepository
;
@GetMapping
(
produces
=
MediaType
.
APPLICATION_STREAM_JSON_VALUE
)
@ResponseStatus
(
HttpStatus
.
OK
)
public
Flux
<
AnimalResource
>
findAll
()
{
return
animalRepository
.
findAll
()
.
map
(
AnimalResource:
:
new
)
.
delayElements
(
Duration
.
ofSeconds
(
1L
));
}
@GetMapping
(
value
=
"/{id}"
)
// @ResponseStatus(HttpStatus.OK)
public
Mono
<
AnimalResource
>
findAnimalById
(
@PathVariable
(
"id"
)
String
id
)
{
return
animalRepository
.
findById
(
id
)
.
map
(
AnimalResource:
:
new
)
.
delayElement
(
Duration
.
ofSeconds
(
1L
));
}
}
This diff is collapsed.
Click to expand it.
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