Skip to content

Commit

Permalink
fix: 모임가입- 기존 멤버 대응 기능 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
yubin-im committed Jun 10, 2024
1 parent f756ad1 commit 0b11286
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 7 deletions.
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -18,4 +19,6 @@ public interface TeamMemberRepository extends JpaRepository<TeamMember,Long> {
List<TeamMember> findTeamMemberByMember_MemberIdx(Long memberIdx);

Optional<TeamMember> findTeamMemberByMember_MemberIdxAndTeam_TeamIdx(Long memberIdx, Long teamIdx);

TeamMember findTeamMemberByMemberAndTeam(Member member, Team team);
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 0b11286

Please sign in to comment.