From 3b1425b4453e0b4fae2a7d735bbf32947a0ebecb Mon Sep 17 00:00:00 2001 From: Geunsik Kim <93639883+600gramSik@users.noreply.github.com> Date: Sat, 3 Aug 2024 19:38:07 +0900 Subject: [PATCH] =?UTF-8?q?[REFACTOR]=20=ED=8C=80=EC=9B=90=20=EC=B4=88?= =?UTF-8?q?=EB=8C=80=20=EC=8B=9C=20=EB=8B=89=EB=84=A4=EC=9E=84=EC=9C=BC?= =?UTF-8?q?=EB=A1=9C=20=EC=B4=88=EB=8C=80=EB=90=98=EA=B2=8C=20=EB=81=94=20?= =?UTF-8?q?=EA=B5=AC=ED=98=84=20(#166)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * ♻️refactor: 팀 초대 시 사용자 닉네임으로 받게 구현 (#165) * 💄style:최종코드 수정 (#165) * 💄style: 최종코드 수정 (#165) * ♻️refactor: 불필요한 예외처리 제외 (#165) --- .../repository/ProfileJpaRepository.java | 1 + .../accounts/repository/UserJpaRepository.java | 2 -- .../dto/request/TeamInviteRequestDto.java | 2 +- .../dto/response/TeamInviteResponseDto.java | 2 ++ .../myteam/service/TeamInviteService.java | 17 +++++++++-------- 5 files changed, 13 insertions(+), 11 deletions(-) diff --git a/src/main/java/com/capstone/BnagFer/domain/accounts/repository/ProfileJpaRepository.java b/src/main/java/com/capstone/BnagFer/domain/accounts/repository/ProfileJpaRepository.java index cf7366b6..b759803a 100644 --- a/src/main/java/com/capstone/BnagFer/domain/accounts/repository/ProfileJpaRepository.java +++ b/src/main/java/com/capstone/BnagFer/domain/accounts/repository/ProfileJpaRepository.java @@ -17,4 +17,5 @@ public interface ProfileJpaRepository extends JpaRepository { Optional findByUserId(Long userId); Profile findByNickname(String nickname); + } diff --git a/src/main/java/com/capstone/BnagFer/domain/accounts/repository/UserJpaRepository.java b/src/main/java/com/capstone/BnagFer/domain/accounts/repository/UserJpaRepository.java index e139e9c0..f6ffd73c 100644 --- a/src/main/java/com/capstone/BnagFer/domain/accounts/repository/UserJpaRepository.java +++ b/src/main/java/com/capstone/BnagFer/domain/accounts/repository/UserJpaRepository.java @@ -2,8 +2,6 @@ import com.capstone.BnagFer.domain.accounts.entity.User; import com.capstone.BnagFer.domain.report.entity.UserActivity; -import org.springframework.data.domain.Page; -import org.springframework.data.domain.Pageable; import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.Modifying; import org.springframework.data.jpa.repository.Query; diff --git a/src/main/java/com/capstone/BnagFer/domain/myteam/dto/request/TeamInviteRequestDto.java b/src/main/java/com/capstone/BnagFer/domain/myteam/dto/request/TeamInviteRequestDto.java index d5e50e8e..008b1676 100644 --- a/src/main/java/com/capstone/BnagFer/domain/myteam/dto/request/TeamInviteRequestDto.java +++ b/src/main/java/com/capstone/BnagFer/domain/myteam/dto/request/TeamInviteRequestDto.java @@ -5,7 +5,7 @@ import com.capstone.BnagFer.domain.myteam.entity.TeamInvite; public record TeamInviteRequestDto( - Long userId, + String nickName, Long teamId) { public TeamInvite toEntity(User invitedUser, Team team, User inviter) { diff --git a/src/main/java/com/capstone/BnagFer/domain/myteam/dto/response/TeamInviteResponseDto.java b/src/main/java/com/capstone/BnagFer/domain/myteam/dto/response/TeamInviteResponseDto.java index 2f136780..66592efc 100644 --- a/src/main/java/com/capstone/BnagFer/domain/myteam/dto/response/TeamInviteResponseDto.java +++ b/src/main/java/com/capstone/BnagFer/domain/myteam/dto/response/TeamInviteResponseDto.java @@ -11,6 +11,7 @@ public record TeamInviteResponseDto( Long inviteId, Long teamId, Long invitedUserId, + String nickName, Long inviterId) { public static TeamInviteResponseDto from(TeamInvite teamInvite) { @@ -18,6 +19,7 @@ public static TeamInviteResponseDto from(TeamInvite teamInvite) { .inviteId(teamInvite.getId()) .teamId(teamInvite.getTeam().getId()) .invitedUserId(teamInvite.getInvitedUser().getId()) + .nickName(teamInvite.getInvitedUser().getProfile().getNickname()) .inviterId(teamInvite.getInviter().getId()) .build(); } diff --git a/src/main/java/com/capstone/BnagFer/domain/myteam/service/TeamInviteService.java b/src/main/java/com/capstone/BnagFer/domain/myteam/service/TeamInviteService.java index 14a97192..08ca9e1e 100644 --- a/src/main/java/com/capstone/BnagFer/domain/myteam/service/TeamInviteService.java +++ b/src/main/java/com/capstone/BnagFer/domain/myteam/service/TeamInviteService.java @@ -1,7 +1,8 @@ package com.capstone.BnagFer.domain.myteam.service; +import com.capstone.BnagFer.domain.accounts.entity.Profile; import com.capstone.BnagFer.domain.accounts.entity.User; -import com.capstone.BnagFer.domain.accounts.repository.UserJpaRepository; +import com.capstone.BnagFer.domain.accounts.repository.ProfileJpaRepository; import com.capstone.BnagFer.domain.accounts.service.account.AccountsCommonService; import com.capstone.BnagFer.domain.myteam.dto.request.TeamInviteRequestDto; import com.capstone.BnagFer.domain.myteam.dto.response.TeamInviteResponseDto; @@ -21,18 +22,18 @@ @RequiredArgsConstructor @Transactional public class TeamInviteService { - private final TeamInviteRepository teamInviteRepository; private final AccountsCommonService accountsCommonService; private final TeamRepository teamRepository; private final TeamMembersRepository teamMembersRepository; - private final UserJpaRepository userJpaRepository; + private final ProfileJpaRepository profileJpaRepository; public TeamInviteResponseDto inviteTeamMembers(TeamInviteRequestDto request, User inviter) { - // 초대하려는 사용자를 ID로 찾아오고, 없으면 USER_NOT_FOUND 예외를 던진다 - User invitedUser = userJpaRepository.findById(request.userId()) - .orElseThrow(() -> new TeamMemberExceptionHandler(ErrorCode.USER_NOT_FOUND)); - - // 초대가 이루어질 팀을 ID로 찾아오고, 없으면 TEAM_NOT_FOUND 예외를 던진다 + Profile profile = profileJpaRepository.findByNickname(request.nickName()); + if(profile==null){ + throw new TeamMemberExceptionHandler(ErrorCode.USER_NOT_FOUND); + } + User invitedUser = profile.getUser(); + //초대가 이루어질 팀을 ID로 찾아오고, 없으면 TEAM_NOT_FOUND 예외를 던진다 Team team = teamRepository.findById(request.teamId()) .orElseThrow(() -> new TeamExceptionHandler(ErrorCode.TEAM_NOT_FOUND));