Commit 678277ca authored by Darrick Yong's avatar Darrick Yong

add edit/delete by email

parent 7556ff7c
......@@ -50,11 +50,26 @@ public class DetailsController {
return studentService.updateStudent(studentId, student);
}
@PutMapping("/students/email/{email:.+}")
public Student updateStudentByEmail(@PathVariable(value = "email") String email, @RequestBody Student student) throws ResourceNotFoundException {
Student studentToUpdate = studentService.getStudentByEmail(email)
.orElseThrow(() -> new ResourceNotFoundException("Student with email" + email + "not found."));
return studentService.updateStudent(studentToUpdate.getId(), student);
}
@DeleteMapping("/students/{id}")
public Map<String, Boolean> deleteEmployee(@PathVariable(value = "id") Long studentId) throws ResourceNotFoundException {
public Map<String, Boolean> deleteStudent(@PathVariable(value = "id") Long studentId) throws ResourceNotFoundException {
Student student = studentService.getStudentById(studentId)
.orElseThrow(() -> new ResourceNotFoundException("Student by Id Not Found" + studentId));
return studentService.deleteStudent(studentId);
}
@DeleteMapping("/students/email/{email:.+}")
public Map<String, Boolean> deleteStudentByEmail(@PathVariable(value = "email") String email) throws ResourceNotFoundException {
Student student = studentService.getStudentByEmail(email)
.orElseThrow(() -> new ResourceNotFoundException("Student with email" + email + "not found."));
return studentService.deleteStudent(student.getId());
}
}
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