Skip to content

Commit

Permalink
fix: 모임초대 수락/거절 api 구현
Browse files Browse the repository at this point in the history
  • Loading branch information
ny2060 committed Jun 10, 2024
1 parent 5096d59 commit 367c26c
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 8 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.enumeration.TeamMemberState;
import com.hanaro.triptogether.member.domain.Member;
import com.hanaro.triptogether.team.domain.Team;
import org.springframework.data.jpa.repository.JpaRepository;
Expand All @@ -26,6 +27,6 @@ public interface TeamMemberRepository extends JpaRepository<TeamMember,Long> {

TeamMember findTeamMemberByMemberAndTeam(Member member, Team team);

TeamMember findTeamMemberByTeamMemberState(String teamMemberState);
TeamMember findTeamMemberByTeamMemberStateAndTeam_TeamIdx(TeamMemberState teamMemberState, Long team_teamIdx);

}
Original file line number Diff line number Diff line change
Expand Up @@ -123,16 +123,16 @@ public void acceptTeamMembers(AcceptTeamMembersReqDto acceptTeamMembersReqDto) {
public void rejectTeamMember(AcceptTeamMemberReqDto acceptTeamMemberReqDto) throws IOException {
Team team = teamRepository.findById(acceptTeamMemberReqDto.getTeamIdx()).orElseThrow(() -> new ApiException(ExceptionEnum.TEAM_NOT_FOUND));
List<TeamMember> teamMembers = teamMemberRepository.findTeamMembersByTeam(team);
Member member = memberRepository.findById(acceptTeamMemberReqDto.getTeamMemberIdx()).orElseThrow(EntityNotFoundException::new);
TeamMember teamMember = teamMemberRepository.findById(acceptTeamMemberReqDto.getTeamMemberIdx()).orElseThrow(EntityNotFoundException::new);

for(int i = 0; i < teamMembers.size(); i++) {
if (acceptTeamMemberReqDto.getTeamMemberIdx().equals(teamMembers.get(i).getTeamMemberIdx())) {
teamMembers.get(i).updateTeamMemberState(TeamMemberState.거절);
teamMembers.get(i).delete(LocalDateTime.now(), acceptTeamMemberReqDto.getMemberIdx());
teamMemberRepository.save(teamMembers.get(i));
}
}

firebaseFCMService.sendMessageTo(FcmSendDto.builder().token(member.getFcmToken()).title("모임 참여 거절").body(team.getTeamName()+"모임가입에 거절되었습니다.").build());
firebaseFCMService.sendMessageTo(FcmSendDto.builder().token(teamMember.getMember().getFcmToken()).title("모임 참여 거절").body(team.getTeamName()+"모임가입에 거절되었습니다.").build());

}

Expand Down Expand Up @@ -204,14 +204,13 @@ public void joinTeamMember(JoinTeamMemberReq joinTeamMemberReq) throws IOExcepti
Team team = teamRepository.findById(joinTeamMemberReq.getTeamIdx()).orElseThrow(() -> new ApiException(ExceptionEnum.TEAM_NOT_FOUND));

TeamMember existingTeamMember = teamMemberRepository.findTeamMemberByMemberAndTeam(member, team);
TeamMember teamBossMember = teamMemberRepository.findTeamMemberByTeamMemberState("총무");
TeamMember teamBossMember = teamMemberRepository.findTeamMemberByTeamMemberStateAndTeam_TeamIdx(TeamMemberState.총무,joinTeamMemberReq.getTeamIdx());
if (existingTeamMember != null) {
existingTeamMember.updateTeamMemberState(TeamMemberState.수락대기);
existingTeamMember.delete(null, null);
teamMemberRepository.save(existingTeamMember);
if (existingTeamMember.getTeamMemberState().equals("총무")) {
firebaseFCMService.sendMessageTo(FcmSendDto.builder().token(teamBossMember.getMember().getFcmToken()).title("모임 참여 요청 알림").body(member.getMemberName()+"님이 "+team.getTeamName()+"모임에 참여하기를 원합니다.").build());
}
firebaseFCMService.sendMessageTo(FcmSendDto.builder().token(teamBossMember.getMember().getFcmToken()).title("모임 참여 요청 알림").body(member.getMemberName()+"님이 "+team.getTeamName()+"모임에 참여하기를 원합니다.").build());

} else {
TeamMember teamMember = TeamMember.builder()
.team(team)
Expand All @@ -220,6 +219,8 @@ public void joinTeamMember(JoinTeamMemberReq joinTeamMemberReq) throws IOExcepti
.createdAt(LocalDateTime.now())
.build();
teamMemberRepository.save(teamMember);
firebaseFCMService.sendMessageTo(FcmSendDto.builder().token(teamMember.getMember().getFcmToken()).title("모임 참여 요청 알림").body(member.getMemberName()+"님이 "+team.getTeamName()+"모임에 참여하기를 원합니다.").build());

}


Expand Down

0 comments on commit 367c26c

Please sign in to comment.