Skip to content

Commit

Permalink
Merge branch 'dev' into fix/account-detail
Browse files Browse the repository at this point in the history
  • Loading branch information
mummhy0811 authored Jun 10, 2024
2 parents fae8e0f + 0785248 commit 716ee57
Show file tree
Hide file tree
Showing 2 changed files with 19 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 @@ -19,6 +20,10 @@ public interface TeamMemberRepository extends JpaRepository<TeamMember,Long> {

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


@Query("SELECT count(*) FROM TeamMember tm where tm.team = :team and deletedAt is null and (tm.teamMemberState=\"총무\" or tm.teamMemberState=\"모임원\")")
Integer findTeamMembersByTeamAndTeamMemberState(Team team);

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 716ee57

Please sign in to comment.