diff --git a/src/main/java/com/hanaro/triptogether/teamMember/domain/TeamMemberRepository.java b/src/main/java/com/hanaro/triptogether/teamMember/domain/TeamMemberRepository.java index 51f7a71..6a03097 100644 --- a/src/main/java/com/hanaro/triptogether/teamMember/domain/TeamMemberRepository.java +++ b/src/main/java/com/hanaro/triptogether/teamMember/domain/TeamMemberRepository.java @@ -1,5 +1,6 @@ package com.hanaro.triptogether.teamMember.domain; +import com.hanaro.triptogether.member.domain.Member; import com.hanaro.triptogether.team.domain.Team; import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.Query; @@ -18,4 +19,6 @@ public interface TeamMemberRepository extends JpaRepository { List findTeamMemberByMember_MemberIdx(Long memberIdx); Optional findTeamMemberByMember_MemberIdxAndTeam_TeamIdx(Long memberIdx, Long teamIdx); + + TeamMember findTeamMemberByMemberAndTeam(Member member, Team team); } diff --git a/src/main/java/com/hanaro/triptogether/teamMember/service/impl/TeamMemberServiceImpl.java b/src/main/java/com/hanaro/triptogether/teamMember/service/impl/TeamMemberServiceImpl.java index 52daa22..e2907de 100644 --- a/src/main/java/com/hanaro/triptogether/teamMember/service/impl/TeamMemberServiceImpl.java +++ b/src/main/java/com/hanaro/triptogether/teamMember/service/impl/TeamMemberServiceImpl.java @@ -193,13 +193,20 @@ public void joinTeamMember(JoinTeamMemberReq joinTeamMemberReq) { Member member = memberRepository.findById(joinTeamMemberReq.getMemberIdx()).orElseThrow(() -> new ApiException(ExceptionEnum.MEMBER_NOT_FOUND)); Team team = teamRepository.findById(joinTeamMemberReq.getTeamIdx()).orElseThrow(() -> new ApiException(ExceptionEnum.TEAM_NOT_FOUND)); - TeamMember teamMember = TeamMember.builder() - .team(team) - .member(member) - .teamMemberState(TeamMemberState.수락대기) - .createdAt(LocalDateTime.now()).build(); - - teamMemberRepository.save(teamMember); + TeamMember existingTeamMember = teamMemberRepository.findTeamMemberByMemberAndTeam(member, team); + + if (existingTeamMember != null) { + existingTeamMember.updateTeamMemberState(TeamMemberState.수락대기); + teamMemberRepository.save(existingTeamMember); + } else { + TeamMember teamMember = TeamMember.builder() + .team(team) + .member(member) + .teamMemberState(TeamMemberState.수락대기) + .createdAt(LocalDateTime.now()) + .build(); + teamMemberRepository.save(teamMember); + } } @Override