Skip to content

Commit

Permalink
fix assigning teacher to a subject
Browse files Browse the repository at this point in the history
  • Loading branch information
HunorTotBagi committed Sep 22, 2024
1 parent f3d7323 commit b39b1b3
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ public ResponseEntity<TeacherEntity> deleteTeacher(@PathVariable Integer teacher
return new ResponseEntity<>(teacherService.deleteTeacher(teacherId), HttpStatus.OK);
}

@PutMapping("/teaches/Subject")
public ResponseEntity<TeacherEntity> teacherTeachesSubject(@PathVariable Integer teacherId, @RequestBody TeacherRequestDTO teacherDTOBody) {
return new ResponseEntity<>(teacherService.teacherTeachesSubject(teacherId, teacherDTOBody), HttpStatus.OK);
@PutMapping("/{teacherId}/subject/{subjectId}")
public ResponseEntity<TeacherEntity> teacherTeachesSubject(@PathVariable Integer teacherId, @PathVariable Integer subjectId) {
return new ResponseEntity<>(teacherService.teacherTeachesSubject(teacherId, subjectId), HttpStatus.OK);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,5 @@ public interface TeacherService {

public TeacherEntity deleteTeacher(Integer teacherId);

public TeacherEntity teacherTeachesSubject(Integer teacherId, TeacherRequestDTO teacherRequestDTO);
public TeacherEntity teacherTeachesSubject(Integer teacherId, Integer subjectId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ private UserEntity createUser(String firstName, String lastName, String email, S
throw new IllegalArgumentException("Invalid email format.");
}

RoleEntity newRole = roleRepository.findById(202).orElseThrow(() -> new NotFoundException("Role", 202));
RoleEntity newRole = roleRepository.findById(3).orElseThrow(() -> new NotFoundException("Role", 3));

UserEntity user = new UserEntity();
user.setName(firstName);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import com.electric_diary.entities.ClassEntity;
import com.electric_diary.entities.ParentEntity;
import com.electric_diary.entities.StudentEntity;
import com.electric_diary.entities.TeacherEntity;
import com.electric_diary.entities.UserEntity;
import com.electric_diary.exception.NotFoundException;
import com.electric_diary.repositories.ClassRepository;
Expand Down Expand Up @@ -90,6 +91,9 @@ public StudentEntity updateStudent(Integer studentId, StudentRequestDTO studentR
@Override
public StudentEntity deleteStudent(Integer studentId) {
StudentEntity student = getStudentById(studentId);

student.getParent().getStudents().remove(student);

studentRepository.delete(student);
logger.info("Deleted student with ID {}.", studentId);
return student;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,9 +100,9 @@ public TeacherEntity deleteTeacher(Integer teacherId) {
}

@Override
public TeacherEntity teacherTeachesSubject(Integer teacherId, TeacherRequestDTO teacherRequestDTO) {
public TeacherEntity teacherTeachesSubject(Integer teacherId, Integer subjectId) {
TeacherEntity teacher = getTeacherById(teacherId);
SubjectEntity subject = getSubjectById(teacherRequestDTO.getSubjectId());
SubjectEntity subject = getSubjectById(subjectId);

teacher.addSubjects(subject);
teacherRepository.save(teacher);
Expand Down

0 comments on commit b39b1b3

Please sign in to comment.