Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: 모임 초대 알림 api 구현 #161

Merged
merged 2 commits into from
Jun 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import java.time.LocalDateTime;

@Entity
@Table(name = "Account_transaction_details")
@Table(name = "account_transaction_details")
public class AccountTransactionDetails extends BaseEntity {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.hanaro.triptogether.teamMember.controller;

import com.hanaro.triptogether.common.firebase.FirebaseFCMService;
import com.hanaro.triptogether.teamMember.dto.request.*;
import com.hanaro.triptogether.teamMember.dto.response.TeamMembersResDto;
import com.hanaro.triptogether.teamMember.service.TeamMemberService;
Expand All @@ -9,13 +10,15 @@
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import java.io.IOException;
import java.util.List;
import java.util.Map;

@RestController
@RequiredArgsConstructor
public class TeamMemberContoller {
private final TeamMemberService teamMemberService;
private final FirebaseFCMService firebaseFCMService;

// 모임원 전체 출력
@PostMapping("/team")
Expand All @@ -32,8 +35,9 @@ public void changeOwner(@RequestBody ChangeOwnerReqDto changeOwnerReqDto) {

// 모임원 수락 (수락대기-> 모임원으로 상태 변경)
@PutMapping("/team/accept-one")
public void acceptTeamMember(@RequestBody AcceptTeamMemberReqDto acceptTeamMemberReqDto) {
public void acceptTeamMember(@RequestBody AcceptTeamMemberReqDto acceptTeamMemberReqDto) throws IOException {
teamMemberService.acceptTeamMember(acceptTeamMemberReqDto);

}

// 모임원 전체 수락 (수락대기-> 모임원으로 상태 변경)
Expand Down Expand Up @@ -68,7 +72,7 @@ public void exportTeamMembers(@RequestBody RejectTeamMembersReqDto rejectTeamMem

// 모임 가입
@PostMapping("/team/join")
public void joinTeamMember(@RequestBody JoinTeamMemberReq joinTeamMemberReq) {
public void joinTeamMember(@RequestBody JoinTeamMemberReq joinTeamMemberReq) throws IOException {
teamMemberService.joinTeamMember(joinTeamMemberReq);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import com.hanaro.triptogether.teamMember.dto.request.*;
import com.hanaro.triptogether.teamMember.dto.response.TeamMembersResDto;

import java.io.IOException;
import java.util.List;
import java.util.Optional;

Expand All @@ -16,7 +17,7 @@ public interface TeamMemberService {
void changeOwner(ChangeOwnerReqDto changeOwnerReqDto);

// 모임원 수락 (수락대기-> 모임원으로 상태 변경)
void acceptTeamMember(AcceptTeamMemberReqDto acceptTeamMemberReqDto);
void acceptTeamMember(AcceptTeamMemberReqDto acceptTeamMemberReqDto) throws IOException;

// 모임원 전체 수락 (수락대기-> 모임원으로 상태 변경)
void acceptTeamMembers(AcceptTeamMembersReqDto acceptTeamMembersReqDto);
Expand Down Expand Up @@ -44,7 +45,7 @@ public interface TeamMemberService {
void validateTeamMemberState(TeamMember teamMember);

// 모임 가입
void joinTeamMember(JoinTeamMemberReq joinTeamMemberReq);
void joinTeamMember(JoinTeamMemberReq joinTeamMemberReq) throws IOException;

// 팀멤버idx로 팀멤버 검색
TeamMember checkIsMyTeamByTeamMemberIdx(Long team_member_idx);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
package com.hanaro.triptogether.teamMember.service.impl;

import com.hanaro.triptogether.common.firebase.FirebaseFCMService;
import com.hanaro.triptogether.enumeration.TeamMemberState;
import com.hanaro.triptogether.exception.ApiException;
import com.hanaro.triptogether.exception.ExceptionEnum;
import com.hanaro.triptogether.exchangeRate.dto.request.FcmSendDto;
import com.hanaro.triptogether.exchangeRate.exception.EntityNotFoundException;
import com.hanaro.triptogether.member.domain.Member;
import com.hanaro.triptogether.member.domain.MemberRepository;
import com.hanaro.triptogether.team.domain.Team;
Expand All @@ -16,6 +19,7 @@
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.io.IOException;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.List;
Expand All @@ -27,6 +31,7 @@ public class TeamMemberServiceImpl implements TeamMemberService {
private final TeamMemberRepository teamMemberRepository;
private final TeamRepository teamRepository;
private final MemberRepository memberRepository;
private final FirebaseFCMService firebaseFCMService;

// 모임원 전체 출력
@Transactional
Expand Down Expand Up @@ -80,17 +85,19 @@ public void changeOwner(ChangeOwnerReqDto changeOwnerReqDto) {
// 모임원 수락 (수락대기-> 모임원으로 상태 변경)
@Transactional
@Override
public void acceptTeamMember(AcceptTeamMemberReqDto acceptTeamMemberReqDto) {
public void acceptTeamMember(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.getMemberIdx()).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).updateModified(LocalDateTime.now(), acceptTeamMemberReqDto.getMemberIdx());
teamMemberRepository.save(teamMembers.get(i));
}
}
firebaseFCMService.sendMessageTo(FcmSendDto.builder().token(member.getFcmToken()).title("모임 참여 승인 완료").body(team.getTeamName()+"모임에 가입되었습니다.").build());

}

// 모임원 전체 수락 (수락대기-> 모임원으로 상태 변경)
Expand Down Expand Up @@ -189,7 +196,7 @@ public List<TeamMember> findTeamMemberByMemberIdx(Long member_idx) {
// 모임 가입
@Transactional
@Override
public void joinTeamMember(JoinTeamMemberReq joinTeamMemberReq) {
public void joinTeamMember(JoinTeamMemberReq joinTeamMemberReq) throws IOException {
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));

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

}

@Override
Expand Down
Loading