[Start Spring Boot] Delete, Update에 예외 추가하기

·2024년 3월 19일
0

Start Spring Boot!

목록 보기
20/53
post-thumbnail

예외 적용하기

Delete

    @DeleteMapping("/{id}")
    public void deleteTeam(@PathVariable long id) {
        TeamDTO teamDTO = teamService.getTeamById(id);
        if(teamDTO == null) {
            throw new TeamNotFoundException("Team not found with id: " + id);
        }
        teamService.deleteTeam(id);
    }
    

Update

    @PutMapping("/{id}")
    public TeamDTO updateTeam(@PathVariable long id, TeamDTO team) {
        TeamDTO teamDTO = teamService.getTeamById(id);
        if(teamDTO == null) {
            throw new TeamNotFoundException("Team not found with id: " + id);
        }
        return teamService.updateTeam(id, team);
    }
    

Delete

    @DeleteMapping("/{id}")
    public void deleteTeam(@PathVariable long id) {
        TeamDTO teamDTO = teamService.getTeamById(id);
        if(teamDTO == null) {
            throw new TeamNotFoundException("Team not found with id: " + id);
        }
        teamService.deleteTeam(id);
    }
  • 다음과 같이 조회를 한 후, 예외를 적용하였다.
profile
백엔드 개발자가 꿈인 컴공과

0개의 댓글

관련 채용 정보