Commit 4200bc4e authored by Philippe Fonzin's avatar Philippe Fonzin

update student marks

parent ec43b553
...@@ -4,10 +4,11 @@ ...@@ -4,10 +4,11 @@
<component name="GradleSettings"> <component name="GradleSettings">
<option name="linkedExternalProjectsSettings"> <option name="linkedExternalProjectsSettings">
<GradleProjectSettings> <GradleProjectSettings>
<option name="delegatedBuild" value="true" />
<option name="testRunner" value="GRADLE" />
<option name="distributionType" value="DEFAULT_WRAPPED" /> <option name="distributionType" value="DEFAULT_WRAPPED" />
<option name="externalProjectPath" value="$PROJECT_DIR$" /> <option name="externalProjectPath" value="$PROJECT_DIR$" />
<option name="gradleHome" value="/usr/local/Cellar/gradle/6.8.3/libexec" /> <option name="gradleJvm" value="1.8" />
<option name="gradleJvm" value="openjdk-15" />
<option name="modules"> <option name="modules">
<set> <set>
<option value="$PROJECT_DIR$" /> <option value="$PROJECT_DIR$" />
......
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<project version="4"> <project version="4">
<component name="ExternalStorageConfigurationManager" enabled="true" /> <component name="ExternalStorageConfigurationManager" enabled="true" />
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_8" project-jdk-name="openjdk-15" project-jdk-type="JavaSDK" /> <component name="ProjectRootManager" version="2" languageLevel="JDK_1_8" default="true" project-jdk-name="1.8" project-jdk-type="JavaSDK" />
</project> </project>
\ No newline at end of file
com/StudentServices/MarksService/exception/ResourceNotFoundException.java
com.StudentServices.MarksService.exception.ResourceNotFoundException
com/StudentServices/MarksService/exception/ErrorDetails.java
com.StudentServices.MarksService.exception.ErrorDetails
com/StudentServices/MarksService/MarksServiceApplication.java com/StudentServices/MarksService/MarksServiceApplication.java
com.StudentServices.MarksService.MarksServiceApplication com.StudentServices.MarksService.MarksServiceApplication
com/StudentServices/MarksService/repository/StudentRepository.java com/StudentServices/MarksService/exception/GlobalExceptionHandler.java
com.StudentServices.MarksService.repository.StudentRepository com.StudentServices.MarksService.exception.GlobalExceptionHandler
com/StudentServices/MarksService/model/StudentMarks.java com/StudentServices/MarksService/model/StudentMarks.java
com.StudentServices.MarksService.model.StudentMarks com.StudentServices.MarksService.model.StudentMarks
com/StudentServices/MarksService/repository/StudentRepository.java
com.StudentServices.MarksService.repository.StudentRepository
com/StudentServices/MarksService/service/StudentService.java com/StudentServices/MarksService/service/StudentService.java
com.StudentServices.MarksService.service.StudentService com.StudentServices.MarksService.service.StudentService
com/StudentServices/MarksService/controller/StudentMarksController.java com/StudentServices/MarksService/controller/StudentMarksController.java
......
...@@ -8,6 +8,8 @@ import org.springframework.http.HttpStatus; ...@@ -8,6 +8,8 @@ import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity; import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List; import java.util.List;
@CrossOrigin(origins = "*") @CrossOrigin(origins = "*")
...@@ -40,6 +42,20 @@ public class StudentMarksController { ...@@ -40,6 +42,20 @@ public class StudentMarksController {
// (PUT) update studentmark by id // (PUT) update studentmark by id
@PutMapping("/studentMarks/{id}/{course}")
ResponseEntity<StudentMarks> updateStudent(@PathVariable String id, @PathVariable String course, @RequestBody String grade) throws ResourceNotFoundException {
StudentMarks student = studentService.getStudentById(id).
orElseThrow( () -> new ResourceNotFoundException("Student was not found: " + id));
if (student.getMarks().get(course).length() > 0) {
student.getMarks().put(course, grade);
} else {
throw new ResourceNotFoundException("course not found");
}
studentService.updateStudent(student);
return ResponseEntity.ok(student);
}
// (DELETE) delete studentmark by id // (DELETE) delete studentmark by id
@DeleteMapping("remove/{id}") @DeleteMapping("remove/{id}")
......
...@@ -34,10 +34,12 @@ public class StudentService { ...@@ -34,10 +34,12 @@ public class StudentService {
public void updateStudent(StudentMarks studentMarks) { public void updateStudent(StudentMarks studentMarks) {
studentRepository.save(studentMarks);
} }
public void deleteStudent(StudentMarks studentMarks) { studentRepository.delete(studentMarks); } public void deleteStudent(StudentMarks studentMarks) {
studentRepository.delete(studentMarks);
}
} }
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