Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
S
Student-Marks-Microservice
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
Vishal Vaddadhi
Student-Marks-Microservice
Commits
43d67ae2
Commit
43d67ae2
authored
Apr 02, 2021
by
Kyle Muldoon
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Reworked getStudentById to return an optional. Controller now returns HTTP exceptions when needed
parent
ee30cc91
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
16 additions
and
11 deletions
+16
-11
StudentMarksController.java
...vices/MarksService/controller/StudentMarksController.java
+12
-8
StudentService.java
.../StudentServices/MarksService/service/StudentService.java
+4
-3
No files found.
src/main/java/com/StudentServices/MarksService/controller/StudentMarksController.java
View file @
43d67ae2
package
com
.
StudentServices
.
MarksService
.
controller
;
import
com.StudentServices.MarksService.exception.ResourceNotFoundException
;
import
com.StudentServices.MarksService.model.StudentMarks
;
import
com.StudentServices.MarksService.service.StudentService
;
import
org.springframework.beans.factory.annotation.Autowired
;
...
...
@@ -31,18 +32,21 @@ public class StudentMarksController {
// (GET) find studentmark by id
@GetMapping
(
"/studentMarks/{id}"
)
ResponseEntity
<
StudentMarks
>
findStudentMarksById
(
@PathVariable
String
id
){
StudentMarks
sm
=
studentService
.
getStudentById
(
id
);
if
(
sm
==
null
){
return
new
ResponseEntity
<>(
HttpStatus
.
NOT_FOUND
);
}
else
{
return
ResponseEntity
.
ok
(
sm
);
}
ResponseEntity
<
StudentMarks
>
findStudentMarksById
(
@PathVariable
String
id
)
throws
ResourceNotFoundException
{
StudentMarks
sm
=
studentService
.
getStudentById
(
id
).
orElseThrow
(
()
->
new
ResourceNotFoundException
(
"Student Marks not found... "
+
id
));
return
ResponseEntity
.
ok
(
sm
);
}
// (PUT) update studentmark by id
// (DELETE) delete studentmark by id
// @DeleteMapping("remove/{id}")
// ResponseEntity<StudentMarks> deleteStudentMarkById(@PathVariable String id) {
// StudentMarks sm = studentService.getStudentById(id)
// }
//////////////////////////////////
...
...
src/main/java/com/StudentServices/MarksService/service/StudentService.java
View file @
43d67ae2
...
...
@@ -27,11 +27,12 @@ public class StudentService {
return
studentRepository
.
save
(
studentMarks
);
}
public
StudentMarks
getStudentById
(
String
ID
)
{
Optional
<
StudentMarks
>
sm
=
studentRepository
.
findById
(
ID
);
return
s
m
.
orElse
(
null
);
public
Optional
<
StudentMarks
>
getStudentById
(
String
ID
)
{
return
s
tudentRepository
.
findById
(
ID
);
}
public
void
updateStudent
(
StudentMarks
studentMarks
)
{
}
...
...
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