Commit 83fc091d authored by Shanelle Valencia's avatar Shanelle Valencia

Pull from master

parents 1229cb4c 787f79e7
#HELP.md
#.gradle
build/
.gradle
#!gradle/wrapper/gradle-wrapper.jar
#!**/src/main/**/build/
#!**/src/test/**/build/
......
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;
......@@ -22,29 +23,26 @@ public class StudentMarksController {
@Autowired StudentService studentService;
// (GET) findall studentmarks
@GetMapping
@GetMapping("/studentMarks")
ResponseEntity<List<StudentMarks>> findAllStudentMarks(){
return ResponseEntity.ok(studentService.findAllStudents());
}
// (POST) create studentmark
@PostMapping("/studentMarks")
public ResponseEntity<StudentMarks> createMarks(@RequestBody StudentMarks studentMarks) {
StudentMarks studentMarks1 = studentService.addStudent(studentMarks);
return ResponseEntity.ok().body(studentMarks1);
return ResponseEntity.ok(studentService.addStudent(studentMarks));
}
// (GET) find studentmark by id
@GetMapping
ResponseEntity<StudentMarks> findStudentMarksById(String id){
StudentMarks sm = studentService.getStudentById(id);
if (sm == null){
return new ResponseEntity<>(HttpStatus.NOT_FOUND);
}
else {
return ResponseEntity.ok(sm);
}
@GetMapping("/studentMarks/{id}")
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);
}
//
// // Get a particular employee
// // GET: http://localhost:8080/api/v1/employees/__num__
......@@ -71,13 +69,13 @@ public class StudentMarksController {
@PutMapping("/studentMarks/update/{emailAddress}")
public ResponseEntity<StudentMarks> updateStudentMarks(@PathVariable (value= "emailAddress") String emailAddressId) throws ConfigDataResourceNotFoundException {
StudentMarks studentMarks = studentService.getStudentById(emailAddressId)
final StudentMarks updatedStudentMarks = studentService.editStudentMarks(studentMarks);
return ResponseEntity.ok(updatedStudentMarks);
}
// @PutMapping("/studentMarks/update/{emailAddress}")
// public ResponseEntity<StudentMarks> updateStudentMarks(@PathVariable (value= "emailAddress") String emailAddressId) throws ConfigDataResourceNotFoundException {
// StudentMarks studentMarks = studentService.getStudentById(emailAddressId);
//
// final StudentMarks updatedStudentMarks = studentService.editStudentMarks(studentMarks);
// return ResponseEntity.ok(updatedStudentMarks);
// }
......
package com.StudentServices.MarksService.exception;
import java.util.Date;
public class ErrorDetails {
private Date timestamp;
private String message;
private String details;
public ErrorDetails(Date timestamp, String message, String details) {
this.timestamp = timestamp;
this.message = message;
this.details = details;
}
public Date getTimestamp() {
return timestamp;
}
public void setTimestamp(Date timestamp) {
this.timestamp = timestamp;
}
public String getMessage() {
return message;
}
public void setMessage(String message) {
this.message = message;
}
public String getDetails() {
return details;
}
public void setDetails(String details) {
this.details = details;
}
}
package com.StudentServices.MarksService.exception;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.context.request.WebRequest;
import org.springframework.web.servlet.mvc.method.annotation.ResponseEntityExceptionHandler;
import java.util.Date;
public class GlobalExceptionHandler extends ResponseEntityExceptionHandler {
public ResponseEntity<?> resourceNotFoundException(ResourceNotFoundException ex, WebRequest webRequest) {
ErrorDetails errorDetails = new ErrorDetails(new Date(), ex.getMessage(), webRequest.getDescription(false));
return new ResponseEntity<>(errorDetails, HttpStatus.NOT_FOUND);
}
}
\ No newline at end of file
package com.StudentServices.MarksService.exception;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.ResponseStatus;
@ResponseStatus(value = HttpStatus.NOT_FOUND)
public class ResourceNotFoundException extends Exception {
public ResourceNotFoundException(String message) {
super(message);
}
}
\ No newline at end of file
......@@ -20,7 +20,7 @@ public class StudentService {
public List<StudentMarks> findAllStudents() {
return null;
return studentRepository.findAll();
}
public StudentMarks addStudent(StudentMarks studentMarks) {
......@@ -28,12 +28,15 @@ public class StudentService {
}
public StudentMarks getStudentById(String ID) {
Optional<StudentMarks> sm = studentRepository.findById(ID);
return sm.orElse(null);
public Optional<StudentMarks> getStudentById(String ID) {
return studentRepository.findById(ID);
}
public void updateStudent(StudentMarks studentMarks) {}
public StudentMarks editStudentMarks(StudentMarks studentMarks) {
studentMarks.setMarks(studentMarks.getMarks());
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment