Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
W
webflux-practice-2
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
Sumaiyya Burney
webflux-practice-2
Commits
0dfbe993
Commit
0dfbe993
authored
May 03, 2021
by
Sumaiyya Burney
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Consumes endpoints with web client
parent
b7d1807c
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
48 additions
and
8 deletions
+48
-8
StudentWebClient.java
...a/com/nisum/learning/student/client/StudentWebClient.java
+41
-0
StudentRepository.java
.../nisum/learning/student/repository/StudentRepository.java
+1
-2
StudentService.java
...va/com/nisum/learning/student/service/StudentService.java
+6
-6
No files found.
src/main/java/com/nisum/learning/student/client/StudentWebClient.java
0 → 100644
View file @
0dfbe993
package
com
.
nisum
.
learning
.
student
.
client
;
import
com.nisum.learning.student.model.Student
;
import
org.springframework.web.reactive.function.client.WebClient
;
import
reactor.core.publisher.Flux
;
import
reactor.core.publisher.Mono
;
public
class
StudentWebClient
{
WebClient
webClient
=
WebClient
.
builder
().
baseUrl
(
"http://localhost:8080"
).
build
();
public
Flux
<
Student
>
findAll
(){
Flux
<
Student
>
students
=
webClient
.
get
()
.
uri
(
"/students"
)
.
exchangeToFlux
(
clientResponse
->
clientResponse
.
bodyToFlux
(
Student
.
class
));
return
students
;
}
public
Mono
<
Student
>
create
(
Student
newStudent
)
{
Mono
<
Student
>
student
=
webClient
.
post
()
.
uri
(
"/students"
)
.
body
(
Mono
.
just
(
newStudent
),
Student
.
class
)
.
retrieve
()
.
bodyToMono
(
Student
.
class
);
return
student
;
}
public
Mono
<
Student
>
update
(
Student
s
)
{
Mono
<
Student
>
student
=
webClient
.
put
()
.
uri
(
uriBuilder
->
uriBuilder
.
path
(
"/students/{id}"
).
build
(
s
.
getId
()))
.
body
(
Mono
.
just
(
s
),
Student
.
class
)
.
retrieve
()
.
bodyToMono
(
Student
.
class
);
return
student
;
}
public
void
delete
(
Integer
id
)
{
webClient
.
delete
()
.
uri
(
uriBuilder
->
uriBuilder
.
path
(
"/students/{id}"
).
build
(
id
))
.
retrieve
();
}
}
src/main/java/com/nisum/learning/student/repository/StudentRepository.java
View file @
0dfbe993
package
com
.
nisum
.
learning
.
student
.
repository
;
package
com
.
nisum
.
learning
.
student
.
repository
;
import
com.nisum.learning.student.model.Student
;
import
org.springframework.data.mongodb.repository.ReactiveMongoRepository
;
import
org.springframework.data.mongodb.repository.ReactiveMongoRepository
;
import
org.springframework.stereotype.Repository
;
import
org.springframework.stereotype.Repository
;
@Repository
@Repository
public
interface
StudentRepository
extends
ReactiveMongoRepository
<
Student
,
Integer
>
{
public
interface
StudentRepository
<
Student
,
Integer
>
extends
ReactiveMongoRepository
<
Student
,
Integer
>
{
}
}
src/main/java/com/nisum/learning/student/service/StudentService.java
View file @
0dfbe993
...
@@ -10,25 +10,25 @@ import reactor.core.publisher.Mono;
...
@@ -10,25 +10,25 @@ import reactor.core.publisher.Mono;
@Service
@Service
public
class
StudentService
{
public
class
StudentService
{
@Autowired
@Autowired
StudentRepository
studentRepo
;
StudentRepository
<
Student
,
Integer
>
studentRepository
;
public
Flux
<
Student
>
findAll
()
{
public
Flux
<
Student
>
findAll
()
{
return
studentRepo
.
findAll
();
return
studentRepo
sitory
.
findAll
();
}
}
public
Mono
<
Student
>
findById
(
Integer
id
){
public
Mono
<
Student
>
findById
(
Integer
id
){
return
studentRepo
.
findById
(
id
);
return
studentRepo
sitory
.
findById
(
id
);
}
}
public
void
create
(
Student
newStudent
){
public
void
create
(
Student
newStudent
){
studentRepo
.
save
(
newStudent
).
subscribe
();
studentRepo
sitory
.
save
(
newStudent
).
subscribe
();
}
}
public
Mono
<
Student
>
update
(
Student
newStudent
){
public
Mono
<
Student
>
update
(
Student
newStudent
){
return
studentRepo
.
save
(
newStudent
);
return
studentRepo
sitory
.
save
(
newStudent
);
}
}
public
void
deleteById
(
int
id
){
public
void
deleteById
(
int
id
){
studentRepo
.
deleteById
(
id
);
studentRepo
sitory
.
deleteById
(
id
);
}
}
}
}
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