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
b7d1807c
Commit
b7d1807c
authored
May 03, 2021
by
Sumaiyya Burney
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Adds REST controller/endpoints
parent
dea58750
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
59 additions
and
15 deletions
+59
-15
StudentService.java
src/main/java/com/nisum/learning/student/StudentService.java
+0
-5
StudentController.java
.../nisum/learning/student/controller/StudentController.java
+16
-10
StudentRepository.java
.../nisum/learning/student/repository/StudentRepository.java
+9
-0
StudentService.java
...va/com/nisum/learning/student/service/StudentService.java
+34
-0
No files found.
src/main/java/com/nisum/learning/student/StudentService.java
deleted
100644 → 0
View file @
dea58750
package
com
.
nisum
.
learning
.
student
;
public
class
StudentService
{
}
src/main/java/com/nisum/learning/student/controller/StudentController.java
View file @
b7d1807c
package
com
.
nisum
.
learning
.
student
.
controller
;
package
com
.
nisum
.
learning
.
student
.
controller
;
import
com.nisum.learning.student.model.Student
;
import
com.nisum.learning.student.model.Student
;
import
org.springframework.http.ResponseEntity
;
import
com.nisum.learning.student.service.StudentService
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.http.HttpStatus
;
import
org.springframework.web.bind.annotation.*
;
import
org.springframework.web.bind.annotation.*
;
import
org.springframework.web.reactive.function.client.WebClient
;
import
reactor.core.publisher.Flux
;
import
reactor.core.publisher.Flux
;
import
reactor.core.publisher.Mono
;
import
reactor.core.publisher.Mono
;
@RestController
@RestController
@RequestMapping
(
"/students"
)
@RequestMapping
(
"/students"
)
public
class
StudentController
{
public
class
StudentController
{
@Autowired
StudentService
studentService
;
//for demo/ref purposes
public
static
void
main
(
String
[]
args
)
{
public
static
void
main
(
String
[]
args
)
{
Flux
<
Integer
>
nums
=
Flux
.
just
(
1
,
2
,
3
)
/*.concatWith(Flux.error(new RuntimeException("Exception occurred")))*/
;
Flux
<
Integer
>
nums
=
Flux
.
just
(
1
,
2
,
3
)
/*.concatWith(Flux.error(new RuntimeException("Exception occurred")))*/
;
nums
.
log
()
nums
.
log
()
...
@@ -20,26 +25,27 @@ public class StudentController {
...
@@ -20,26 +25,27 @@ public class StudentController {
@GetMapping
()
@GetMapping
()
public
Flux
<
Student
>
getAllStudents
(){
public
Flux
<
Student
>
getAllStudents
(){
return
null
;
return
studentService
.
findAll
()
;
}
}
@GetMapping
(
"/{id}"
)
@GetMapping
(
"/{id}"
)
public
Mono
<
Student
>
getStudentById
(
@PathVariable
int
id
){
public
Mono
<
Student
>
getStudentById
(
@PathVariable
int
id
){
return
null
;
return
studentService
.
findById
(
id
)
;
}
}
@PostMapping
()
@PostMapping
()
public
ResponseEntity
<
Student
>
createStudent
(
@RequestBody
Student
newStudent
){
@ResponseStatus
(
HttpStatus
.
CREATED
)
return
null
;
public
void
createStudent
(
@RequestBody
Student
newStudent
){
studentService
.
create
(
newStudent
);
}
}
@PutMapping
(
"/{id}"
)
@PutMapping
(
"/{id}"
)
public
Mono
<
ResponseEntity
<
Student
>
>
updateStudentById
(
@RequestBody
Student
newStudent
){
public
Mono
<
Student
>
updateStudentById
(
@RequestBody
Student
newStudent
){
return
null
;
return
studentService
.
update
(
newStudent
)
;
}
}
@DeleteMapping
(
"/{id}"
)
@DeleteMapping
(
"/{id}"
)
public
Mono
<
ResponseEntity
<
Student
>>
deleteStudentById
(
@PathVariable
int
id
){
public
void
deleteStudentById
(
@PathVariable
int
id
){
return
null
;
studentService
.
deleteById
(
id
)
;
}
}
}
}
src/main/java/com/nisum/learning/student/repository/StudentRepository.java
0 → 100644
View file @
b7d1807c
package
com
.
nisum
.
learning
.
student
.
repository
;
import
com.nisum.learning.student.model.Student
;
import
org.springframework.data.mongodb.repository.ReactiveMongoRepository
;
import
org.springframework.stereotype.Repository
;
@Repository
public
interface
StudentRepository
extends
ReactiveMongoRepository
<
Student
,
Integer
>
{
}
src/main/java/com/nisum/learning/student/service/StudentService.java
0 → 100644
View file @
b7d1807c
package
com
.
nisum
.
learning
.
student
.
service
;
import
com.nisum.learning.student.model.Student
;
import
com.nisum.learning.student.repository.StudentRepository
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Service
;
import
reactor.core.publisher.Flux
;
import
reactor.core.publisher.Mono
;
@Service
public
class
StudentService
{
@Autowired
StudentRepository
studentRepo
;
public
Flux
<
Student
>
findAll
()
{
return
studentRepo
.
findAll
();
}
public
Mono
<
Student
>
findById
(
Integer
id
){
return
studentRepo
.
findById
(
id
);
}
public
void
create
(
Student
newStudent
){
studentRepo
.
save
(
newStudent
).
subscribe
();
}
public
Mono
<
Student
>
update
(
Student
newStudent
){
return
studentRepo
.
save
(
newStudent
);
}
public
void
deleteById
(
int
id
){
studentRepo
.
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