Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Lokesh Singh
Web Flux Demo
Commits
7f7031e4
Commit
7f7031e4
authored
2 years ago
by
Lokesh Singh
Browse files
Options
Download
Email Patches
Plain Diff
added a method in controller class
parent
171e9d49
master
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/main/java/com/lokesh/webfluxdemo/controller/AnimalController.java
+13
-3
...a/com/lokesh/webfluxdemo/controller/AnimalController.java
with
13 additions
and
3 deletions
+13
-3
src/main/java/com/lokesh/webfluxdemo/controller/AnimalController.java
+
13
-
3
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
Supports
Markdown
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
Menu
Projects
Groups
Snippets
Help