diff --git a/src/main/java/com/example/bilda_server/controller/EvaluationController.java b/src/main/java/com/example/bilda_server/controller/EvaluationController.java index d66a1d2..a55dc12 100644 --- a/src/main/java/com/example/bilda_server/controller/EvaluationController.java +++ b/src/main/java/com/example/bilda_server/controller/EvaluationController.java @@ -3,11 +3,14 @@ import com.example.bilda_server.auth.CustomUserDetails; import com.example.bilda_server.request.EvaluationRequestDTO; +import com.example.bilda_server.response.BaseResponse; import com.example.bilda_server.response.ResponseDto; import com.example.bilda_server.response.TeamMemberEvaluationDTO; import com.example.bilda_server.service.EvaluationService; import io.swagger.v3.oas.annotations.Operation; +import jakarta.persistence.EntityNotFoundException; import lombok.RequiredArgsConstructor; +import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; import org.springframework.security.core.annotation.AuthenticationPrincipal; import org.springframework.web.bind.annotation.*; @@ -28,19 +31,39 @@ public ResponseDto createEvaluation( @RequestBody EvaluationRequestDTO evaluationDTO, @AuthenticationPrincipal CustomUserDetails userDetails ) { - evaluationService.createAndReflectEvaluation(evaluationDTO, userDetails.getId()); - return ResponseDto.success("평가 반영 완료"); + try{ + evaluationService.createAndReflectEvaluation(evaluationDTO, userDetails.getId()); + return ResponseDto.success("평가 반영 완료"); + }catch (EntityNotFoundException ex) { + // EntityNotFoundException 발생 시 + return ResponseDto.fail(HttpStatus.NOT_FOUND, ex.getMessage()); + } catch (RuntimeException ex) { + return ResponseDto.fail(HttpStatus.BAD_REQUEST, ex.getMessage()); + } catch (Exception ex) { + // 그 외 일반 예외 발생 시 + return ResponseDto.fail(HttpStatus.INTERNAL_SERVER_ERROR, "서버 내부 오류"); + } + } @Operation(summary = "팀원 평가 여부 조회하기", description = "requestParam으로 조회하는 유저의 id를 가져오고 teamId를 pathVariable로 넘기면 팀원들의 평가 여부를 확인할 수 있습니다. ", tags = { "EvaluationController"}) @GetMapping("/status/{teamId}") - public ResponseEntity> getEvaluationStatus( + public ResponseEntity getEvaluationStatus( @PathVariable Long teamId, @AuthenticationPrincipal CustomUserDetails userDetails ) { - List evaluationStatus = evaluationService.getEvaluationStatusOfTeamMembers(userDetails.getId(), teamId); - return ResponseEntity.ok(evaluationStatus); + try{ + List evaluationStatus = evaluationService.getEvaluationStatusOfTeamMembers(userDetails.getId(), teamId); + return ResponseEntity.ok(evaluationStatus); + }catch (EntityNotFoundException ex) { + // EntityNotFoundException 발생 시 + return new ResponseEntity<>(new BaseResponse<>(HttpStatus.NOT_FOUND.value(), ex.getMessage(), null), HttpStatus.NOT_FOUND); + }catch (Exception ex) { + // 그 외 일반 예외 발생 시 + return new ResponseEntity<>(new BaseResponse<>(HttpStatus.INTERNAL_SERVER_ERROR.value(), "서버 내부 오류", null), HttpStatus.INTERNAL_SERVER_ERROR); + } + } diff --git a/src/main/java/com/example/bilda_server/controller/PageController.java b/src/main/java/com/example/bilda_server/controller/PageController.java index ba83ae6..268e2a2 100644 --- a/src/main/java/com/example/bilda_server/controller/PageController.java +++ b/src/main/java/com/example/bilda_server/controller/PageController.java @@ -3,10 +3,12 @@ import com.example.bilda_server.auth.CustomUserDetails; import com.example.bilda_server.response.PageAverageDTO; +import com.example.bilda_server.response.ResponseDto; import com.example.bilda_server.response.TeamMemberEvaluationDTO; import com.example.bilda_server.service.PageService; import io.swagger.v3.oas.annotations.Operation; import lombok.RequiredArgsConstructor; +import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; import org.springframework.security.core.annotation.AuthenticationPrincipal; import org.springframework.web.bind.annotation.*; @@ -23,15 +25,26 @@ public class PageController { @Operation(summary = "마이페이지 조회", description = "마이페이지의 정보들을 조회할 수 있습니다. ", tags = { "PageController"}) @GetMapping("") - public PageAverageDTO getPageByUserId(@AuthenticationPrincipal CustomUserDetails userDetails) { - return pageService.getAverageScores(userDetails.getId()); + public ResponseDto getPageByUserId(@AuthenticationPrincipal CustomUserDetails userDetails) { + try{ + PageAverageDTO pageAverage = pageService.getAverageScores(userDetails.getId()); + return ResponseDto.success("마이 페이지 조회", pageAverage); + }catch (Exception ex) { + return ResponseDto.fail(HttpStatus.INTERNAL_SERVER_ERROR, "서버 내부 오류"); + } + } @Operation(summary = "팀원의 마이페이지 조회", description = "조회하고자하는 user의 id를 pathVariable로 넘기면 마이페이지의 정보들을 조회할 수 있습니다. ", tags = { "PageController"}) @GetMapping("/{userId}") - public PageAverageDTO getPageByUserId(@PathVariable Long userId) { - return pageService.getAverageScores(userId); + public ResponseDto getPageByUserId(@PathVariable Long userId) { + try{ + PageAverageDTO pageAverage = pageService.getAverageScores(userId); + return ResponseDto.success("마이 페이지 조회", pageAverage); + }catch (Exception ex) { + return ResponseDto.fail(HttpStatus.INTERNAL_SERVER_ERROR, "서버 내부 오류"); + } } diff --git a/src/main/java/com/example/bilda_server/controller/SubjectController.java b/src/main/java/com/example/bilda_server/controller/SubjectController.java index b2d2f66..893aa35 100644 --- a/src/main/java/com/example/bilda_server/controller/SubjectController.java +++ b/src/main/java/com/example/bilda_server/controller/SubjectController.java @@ -13,7 +13,9 @@ import io.swagger.v3.oas.annotations.media.Schema; import io.swagger.v3.oas.annotations.responses.ApiResponse; import io.swagger.v3.oas.annotations.responses.ApiResponses; +import jakarta.persistence.EntityNotFoundException; import lombok.RequiredArgsConstructor; +import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; import org.springframework.security.core.annotation.AuthenticationPrincipal; import org.springframework.stereotype.Controller; @@ -43,8 +45,14 @@ public class SubjectController { public ResponseDto> getSubjectsByDepartment( @AuthenticationPrincipal CustomUserDetails userDetails ) { - List subjects = subjectService.findSubjectsByUserDepartment(userDetails.getId()); - return ResponseDto.success("과목 정보 조회 완료", subjects); + + try{ + List subjects = subjectService.findSubjectsByUserDepartment(userDetails.getId()); + return ResponseDto.success("과목 정보 조회 완료", subjects); + }catch (EntityNotFoundException ex) { + return ResponseDto.fail(HttpStatus.NOT_FOUND, ex.getMessage()); + } + } @Operation(summary = "유저가 속해있는 과목정보 가져오기", description = "유저가 듣고있는 과목정보를 가져올 수 있습니다. ", tags = {"SubjectController"}) @@ -58,8 +66,14 @@ public ResponseDto> getSubjectsByDepartment( @GetMapping("") @ResponseBody public ResponseDto> getSubjects(@AuthenticationPrincipal CustomUserDetails userDetails) { - List subjects = subjectService.findSubjectsByUserId(userDetails.getId()); - return ResponseDto.success("유저가 속해 있는 과목 정보 조회 완료", subjects); + + try{ + List subjects = subjectService.findSubjectsByUserId(userDetails.getId()); + return ResponseDto.success("유저가 속해 있는 과목 정보 조회 완료", subjects); + }catch (EntityNotFoundException ex) { + return ResponseDto.fail(HttpStatus.NOT_FOUND, ex.getMessage()); + } + } @Operation(summary = "유저가 듣고 있는 과목 추가하기", description = "SubjectId를 pathVariable로 넘기면 유저가 듣고 있는 과목을 추가할 수 있습니다. ", tags = {"SubjectController"}) @@ -74,8 +88,19 @@ public ResponseDto> getSubjects(@AuthenticationPr public ResponseEntity> addSubjectToUser( @PathVariable Long subjectCode, @AuthenticationPrincipal CustomUserDetails userDetails) { - UserSubjectDTO userSubjectDTO = subjectService.addUserToSubject(subjectCode, userDetails.getId()); - return ResponseEntity.ok(new BaseResponse<>(200, "유저의 과목 추가 성공", userSubjectDTO)); + try{ + UserSubjectDTO userSubjectDTO = subjectService.addUserToSubject(subjectCode, userDetails.getId()); + return ResponseEntity.ok(new BaseResponse<>(200, "유저의 과목 추가 성공", userSubjectDTO)); + }catch (EntityNotFoundException ex) { + return new ResponseEntity<>(new BaseResponse<>(HttpStatus.NOT_FOUND.value(), ex.getMessage(), null), HttpStatus.NOT_FOUND); + }catch (IllegalStateException ex) { + // IllegalStateException 발생 시 + return new ResponseEntity<>(new BaseResponse<>(HttpStatus.BAD_REQUEST.value(), ex.getMessage(), null), HttpStatus.BAD_REQUEST); + } catch (Exception ex) { + // 그 외 일반 예외 발생 시 + return new ResponseEntity<>(new BaseResponse<>(HttpStatus.INTERNAL_SERVER_ERROR.value(), "서버 내부 오류", null), HttpStatus.INTERNAL_SERVER_ERROR); + } + } } diff --git a/src/main/java/com/example/bilda_server/controller/TeamController.java b/src/main/java/com/example/bilda_server/controller/TeamController.java index 79f4473..e0eb6f2 100644 --- a/src/main/java/com/example/bilda_server/controller/TeamController.java +++ b/src/main/java/com/example/bilda_server/controller/TeamController.java @@ -1,7 +1,6 @@ package com.example.bilda_server.controller; import com.example.bilda_server.auth.CustomUserDetails; -import com.example.bilda_server.domain.entity.Team; import com.example.bilda_server.request.CreateTeamRequest; import com.example.bilda_server.response.*; import com.example.bilda_server.service.TeamService; @@ -10,7 +9,9 @@ import io.swagger.v3.oas.annotations.media.Schema; import io.swagger.v3.oas.annotations.responses.ApiResponse; import io.swagger.v3.oas.annotations.responses.ApiResponses; +import jakarta.persistence.EntityNotFoundException; import lombok.RequiredArgsConstructor; +import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; import org.springframework.security.core.annotation.AuthenticationPrincipal; import org.springframework.stereotype.Controller; @@ -36,14 +37,16 @@ public class TeamController { }) @GetMapping("/{teamId}") @ResponseBody - public ResponseDto getTeam( - @PathVariable Long teamId - ) { - - TeamResponseDTO team = teamService.findTeam(teamId); - return ResponseDto.success("팀 정보 조회 안료", team); + public ResponseDto getTeam(@PathVariable Long teamId) { + try { + TeamResponseDTO team = teamService.findTeam(teamId); + return ResponseDto.success("팀 정보 조회 완료", team); + } catch (EntityNotFoundException ex) { + return ResponseDto.fail(HttpStatus.NOT_FOUND, ex.getMessage()); + } } + @ApiResponses({ @ApiResponse(responseCode = "200", description = "OK", content = @Content(schema = @Schema(implementation = TeamResponseDTO[].class))), @@ -57,8 +60,12 @@ public ResponseDto getTeam( public ResponseDto> getTeams( @AuthenticationPrincipal CustomUserDetails userDetails ) { - List teams = teamService.findTeamsByUserId(userDetails.getId()); - return ResponseDto.success("유저가 속해있는 팀 정보 조회 완료", teams); + try{ + List teams = teamService.findTeamsByUserId(userDetails.getId()); + return ResponseDto.success("유저가 속해있는 팀 정보 조회 완료", teams); + }catch (EntityNotFoundException ex) { + return ResponseDto.fail(HttpStatus.NOT_FOUND, ex.getMessage()); + } } @Operation(summary = "과목에 해당하는 팀들의 정보 가져오기", description = "SubjectId를 pahtvariable로 넘기면 해당 과목에 대해 개설된 팀들의 정보가 나옵니다. recruitmentStatus로 분기 처리해주시면 됩니다. ", tags = {"TeamController"}) @@ -73,8 +80,13 @@ public ResponseDto> getTeams( public ResponseDto> getTeamsBySubjectID( @PathVariable Long subjectId ) { - List teams = teamService.findTeamsBySubjectId(subjectId); - return ResponseDto.success("과목에 해당하는 팀 정보 조회 완료", teams); + try{ + List teams = teamService.findTeamsBySubjectId(subjectId); + return ResponseDto.success("과목에 해당하는 팀 정보 조회 완료", teams); + }catch (EntityNotFoundException ex) { + return ResponseDto.fail(HttpStatus.NOT_FOUND, ex.getMessage()); + } + } @@ -87,12 +99,17 @@ public ResponseDto> getTeamsBySubjectID( @ApiResponse(responseCode = "500", description = "Internal Server Error") }) @PostMapping("/create") - public ResponseEntity> createTeam( + public ResponseEntity createTeam( @RequestBody CreateTeamRequest request, @AuthenticationPrincipal CustomUserDetails userDetails) { + try{ + TeamResponseDTO team = teamService.createTeam(userDetails.getId(), request); + return ResponseEntity.ok(new BaseResponse<>(200, "팀 생성", team)); + }catch (EntityNotFoundException ex) { + BaseResponse errorResponse = new BaseResponse<>(HttpStatus.NOT_FOUND.value(), ex.getMessage(), null); + return new ResponseEntity<>(errorResponse, HttpStatus.NOT_FOUND); + } - TeamResponseDTO team = teamService.createTeam(userDetails.getId(), request); - return ResponseEntity.ok(new BaseResponse<>(200, "팀 생성", team)); } @Operation(summary = "팀 조인 요청 수락하기", description = "TeamId와 팀에 추가할 userId를 pathVariable로 넘기면 leader가 join요청을 수락할 수 있습니다. userId는 팀 조인 요청을 확인하는 api를 통해 가져와 주세요 조인을 수락했을 때 해당 팀의 인원수가 초기 설정한 max인원수와 같아지면 team의 모집 상태는 모집 완료로 바뀌게 됩니다.", tags = { @@ -103,16 +120,26 @@ public ResponseEntity> createTeam( @ApiResponse(responseCode = "400", description = "No pending request from the user to this team"), @ApiResponse(responseCode = "500", description = "Internal Server Error") }) - @PostMapping("{teamId}/approve/{pendingUserId}") + @PostMapping("/{teamId}/approve/{pendingUserId}") public ResponseEntity> approveJoinRequest( - @PathVariable Long teamId, - @PathVariable Long pendingUserId - ) { - teamService.approvePendingUser(teamId, pendingUserId); - return ResponseEntity.ok(new BaseResponse<>(200, "팀 조인 요청 수락", null)); - + @PathVariable Long teamId, + @PathVariable Long pendingUserId) { + try { + teamService.approvePendingUser(teamId, pendingUserId); + return ResponseEntity.ok(new BaseResponse<>(200, "팀 조인 요청 수락", null)); + } catch (EntityNotFoundException ex) { + // EntityNotFoundException 발생 시 + return new ResponseEntity<>(new BaseResponse<>(HttpStatus.NOT_FOUND.value(), ex.getMessage(), null), HttpStatus.NOT_FOUND); + } catch (IllegalStateException ex) { + // IllegalStateException 발생 시 + return new ResponseEntity<>(new BaseResponse<>(HttpStatus.BAD_REQUEST.value(), ex.getMessage(), null), HttpStatus.BAD_REQUEST); + } catch (Exception ex) { + // 그 외 일반 예외 발생 시 + return new ResponseEntity<>(new BaseResponse<>(HttpStatus.INTERNAL_SERVER_ERROR.value(), "서버 내부 오류", null), HttpStatus.INTERNAL_SERVER_ERROR); + } } + @Operation(summary = "팀 조인 요청 거절하기", description = "TeamId와 팀에 추가할 userId를 pathVariable로 넘기면 leader가 join요청을 거절할 수 있습니다. ", tags = { "TeamController"}) @PostMapping("{teamId}/reject/{pendingUserId}") @@ -120,8 +147,20 @@ public ResponseDto rejectJoinRequest( @PathVariable Long teamId, @PathVariable Long pendingUserId ) { - teamService.rejectPendingUser(teamId, pendingUserId); - return ResponseDto.success( "팀 조인 요청 거절", null); + try{ + teamService.rejectPendingUser(teamId, pendingUserId); + return ResponseDto.success( "팀 조인 요청 거절", null); + }catch (EntityNotFoundException ex) { + // EntityNotFoundException 발생 시 + return ResponseDto.fail(HttpStatus.NOT_FOUND, ex.getMessage()); + } catch (IllegalStateException ex) { + // IllegalStateException 발생 시 + return ResponseDto.fail(HttpStatus.BAD_REQUEST, ex.getMessage()); + } catch (Exception ex) { + // 그 외 일반 예외 발생 시 + return ResponseDto.fail(HttpStatus.INTERNAL_SERVER_ERROR, "서버 내부 오류"); + } + } @@ -132,18 +171,34 @@ public ResponseEntity> requestJoinTeam( @PathVariable Long teamId, @AuthenticationPrincipal CustomUserDetails userDetails ) { - teamService.addPendingUserToTeam(teamId, userDetails.getId()); - return ResponseEntity.ok(new BaseResponse<>(200, "팀 조인 요청 완료", null)); + try{ + teamService.addPendingUserToTeam(teamId, userDetails.getId()); + return ResponseEntity.ok(new BaseResponse<>(200, "팀 조인 요청 완료", null)); + }catch (EntityNotFoundException ex) { + return new ResponseEntity<>(new BaseResponse<>(HttpStatus.NOT_FOUND.value(), ex.getMessage(), null), HttpStatus.NOT_FOUND); + }catch (IllegalStateException ex) { + // IllegalStateException 발생 시 + return new ResponseEntity<>(new BaseResponse<>(HttpStatus.BAD_REQUEST.value(), ex.getMessage(), null), HttpStatus.BAD_REQUEST); + } catch (Exception ex) { + // 그 외 일반 예외 발생 시 + return new ResponseEntity<>(new BaseResponse<>(HttpStatus.INTERNAL_SERVER_ERROR.value(), "서버 내부 오류", null), HttpStatus.INTERNAL_SERVER_ERROR); + } + } + + @Operation(summary = "팀 조인 요청 확인하기", description = "TeamId를 pathVariable로 넘기면 해당 팀에 조인 요청을 보낸 사용자들이 불러와집니다 ", tags = { "TeamController"}) @GetMapping("/{teamId}/recruit") public ResponseEntity>> getPendingUsersByTeamId( @PathVariable Long teamId ) { - - List pendingUsers = teamService.getPendingUsers(teamId); - return ResponseEntity.ok(new BaseResponse<>(200, "팀 조인 요청 확인", pendingUsers)); + try{ + List pendingUsers = teamService.getPendingUsers(teamId); + return ResponseEntity.ok(new BaseResponse<>(200, "팀 조인 요청 확인", pendingUsers)); + }catch (EntityNotFoundException ex) { + return new ResponseEntity<>(new BaseResponse<>(HttpStatus.NOT_FOUND.value(), ex.getMessage(), null), HttpStatus.NOT_FOUND); + } } @@ -153,9 +208,12 @@ public ResponseEntity>> getPendingUsersByTeamI public ResponseDto completeTeam( @PathVariable Long teamId ) { - teamService.setCompleteStatus(teamId); - return ResponseDto.success(); - + try{ + teamService.setCompleteStatus(teamId); + return ResponseDto.success(); + }catch (EntityNotFoundException ex) { + return ResponseDto.fail(HttpStatus.NOT_FOUND, ex.getMessage()); + } } @Operation(summary = "종료된 팀 불러오기", description = "user가 가지고 있는 팀들중 팀플이 완료된 팀들이 불러와집니다. ", tags = {"TeamController"}) @@ -165,9 +223,15 @@ public ResponseDto completeTeam( @ApiResponse(responseCode = "500", description = "Internal Server Error") }) @PostMapping("/completed-teams") - public ResponseEntity> getCompletedTeams(@AuthenticationPrincipal CustomUserDetails userDetails) { - List completedTeams = teamService.findCompletedTeam(userDetails.getId()); - return ResponseEntity.ok(completedTeams); + public ResponseEntity getCompletedTeams(@AuthenticationPrincipal CustomUserDetails userDetails) { + try{ + List completedTeams = teamService.findCompletedTeam(userDetails.getId()); + return ResponseEntity.ok(completedTeams); + }catch (EntityNotFoundException ex) { + return new ResponseEntity<>(new BaseResponse<>(HttpStatus.NOT_FOUND.value(), ex.getMessage(), null), HttpStatus.NOT_FOUND); + } + + } } diff --git a/src/main/java/com/example/bilda_server/controller/UserController.java b/src/main/java/com/example/bilda_server/controller/UserController.java index 294ad96..f3fcbf1 100644 --- a/src/main/java/com/example/bilda_server/controller/UserController.java +++ b/src/main/java/com/example/bilda_server/controller/UserController.java @@ -20,6 +20,7 @@ import io.swagger.v3.oas.annotations.responses.ApiResponses; import jakarta.validation.Valid; import lombok.RequiredArgsConstructor; +import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; import org.springframework.security.core.annotation.AuthenticationPrincipal; import org.springframework.web.bind.annotation.PostMapping; @@ -39,14 +40,23 @@ public class UserController { "UserController"}) @PostMapping("/signin") public ResponseDto signin(@RequestBody @Valid SignInRequest signinRequest) { - return ResponseDto.success("로그인 성공", userService.signin(signinRequest)); + try{ + return ResponseDto.success("로그인 성공", userService.signin(signinRequest)); + }catch (Exception e) { + return ResponseDto.fail(HttpStatus.BAD_REQUEST, e.getMessage()); + } + } @Operation(summary = "회원 가입 요청", description = "HTTP Body를 토대로 회원 가입을 진행합니다.", tags = { "UserController"}) @PostMapping("/signup") public ResponseDto signup(@RequestBody @Valid SignupRequest signupRequest) { - return ResponseDto.success("회원 가입 성공", userService.signup(signupRequest)); + try{ + return ResponseDto.success("회원 가입 성공", userService.signup(signupRequest)); + }catch (Exception e) { + return ResponseDto.fail(HttpStatus.BAD_REQUEST, e.getMessage()); + } } @Operation(summary = "비밀 번호 변경 요청", description = "변경할 비밀번호를 HTTP Body에 담아 보내면 비밀번호가 변경됩니다.", tags = { @@ -56,8 +66,13 @@ public ResponseDto changePassword( @RequestBody @Valid ChangePasswordRequest changePasswordRequest, @AuthenticationPrincipal CustomUserDetails userDetails) { - return ResponseDto.success("비밀번호 변경 완료", - userService.changePassword(changePasswordRequest, userDetails)); + try{ + return ResponseDto.success("비밀번호 변경 완료", + userService.changePassword(changePasswordRequest, userDetails)); + }catch (Exception e) { + return ResponseDto.fail(HttpStatus.BAD_REQUEST, e.getMessage()); + } + } @Operation(summary = "닉네임 변경 요청", description = "변경할 닉네임을 HTTP Body에 담아 보내면 닉네임이 변경됩니다.", tags = { @@ -66,9 +81,13 @@ public ResponseDto changePassword( public ResponseDto changeNickname( @RequestBody @Valid ChangeNicknameRequest changeNicknameRequest, @AuthenticationPrincipal CustomUserDetails userDetails) { + try{ + return ResponseDto.success("닉네임 변경 완료", + userService.changeNickname(changeNicknameRequest, userDetails)); + }catch (Exception e) { + return ResponseDto.fail(HttpStatus.BAD_REQUEST, e.getMessage()); + } - return ResponseDto.success("닉네임 변경 완료", - userService.changeNickname(changeNicknameRequest, userDetails)); } } diff --git a/src/main/java/com/example/bilda_server/service/SubjectService.java b/src/main/java/com/example/bilda_server/service/SubjectService.java index 3508a44..7a48b32 100644 --- a/src/main/java/com/example/bilda_server/service/SubjectService.java +++ b/src/main/java/com/example/bilda_server/service/SubjectService.java @@ -25,7 +25,7 @@ public class SubjectService { public List findSubjectsByUserDepartment(Long userId) { User user = userRepository.findById(userId) - .orElseThrow(() -> new RuntimeException("User not found")); + .orElseThrow(() -> new EntityNotFoundException("User not found")); Department department = user.getDepartment(); return subjectRepository.findByDepartmentsContaining(department); @@ -44,9 +44,9 @@ public List findSubjectsByUserId(Long userId) { public UserSubjectDTO addUserToSubject(Long subjectCode, Long userId) { User user = userRepository.findById(userId) - .orElseThrow(()->new RuntimeException("User not found")); + .orElseThrow(()->new EntityNotFoundException("User not found")); Subject subject = subjectRepository.findById(subjectCode) - .orElseThrow(() -> new RuntimeException("Subject not found")); + .orElseThrow(() -> new EntityNotFoundException("Subject not found")); if (user.getSubjects().contains(subject)) { throw new IllegalStateException("User already add the Subject");