Skip to content

Commit

Permalink
[fix] 매칭 종료 알림 대상 수정
Browse files Browse the repository at this point in the history
  • Loading branch information
tmdtmdqorekf committed May 19, 2024
1 parent c1ff59c commit d1e9914
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,5 @@
@Setter
public class MatchFinishRequestDto {
private String matchId;
private Long loginUserId; // 현재 로그인 한 유저 아이디 (알림 대상)
private Long enderId; // 종료를 누른 유저 아이디
}
Original file line number Diff line number Diff line change
Expand Up @@ -162,8 +162,8 @@ public MatchAcceptResponse acceptMatchRequest(MatchIdDto dto) {
Long senderId = getLongId(redisTemplate.opsForHash().get(key, "senderId"));
Long receiverId = getLongId(redisTemplate.opsForHash().get(key, "receiverId"));

ChatroomCreationDto chatroomCreationDto = new ChatroomCreationDto(senderId, receiverId);
Long chatroomId = chatroomService.createChatroom(chatroomCreationDto);
// ChatroomCreationDto chatroomCreationDto = new ChatroomCreationDto(senderId, receiverId);
// Long chatroomId = chatroomService.createChatroom(chatroomCreationDto);

redisTemplate.opsForHash().put(key, "status", "accepted");

Expand Down Expand Up @@ -207,7 +207,7 @@ public MatchAcceptResponse acceptMatchRequest(MatchIdDto dto) {
match.setSenderId(senderId);
match.setReceiverId(receiverId);
match.setStatus("accepted");
match.setChatroomId(chatroomId);
// match.setChatroomId(chatroomId);

return match;
}
Expand Down Expand Up @@ -336,24 +336,16 @@ public MatchStatusDto finishMatch(MatchFinishRequestDto dto) {
Long senderId = getLongId(redisTemplate.opsForHash().get(key, "senderId"));
Long receiverId = getLongId(redisTemplate.opsForHash().get(key, "receiverId"));

// Case 1: 본인이 종료한 경우
if (dto.getEnderId().equals(dto.getLoginUserId())) {
if (dto.getEnderId().equals(senderId)) { // 본인이 매칭 요청을 보낸 경우
sendMatchFinishNotification(receiverId);
} else { // 본인이 매칭 요청을 받은 경우
sendMatchFinishNotification(senderId);
}
if (!dto.getEnderId().equals(senderId) && !dto.getEnderId().equals(receiverId)) {
throw new CustomException(ErrorCode.USER_NOT_FOUND);
}
// Case 2: 상대방이 종료한 경우
else {
if (dto.getEnderId().equals(senderId)) { // 상대방이 매칭 요청을 보낸 경우
sendMatchFinishNotification(senderId);
} else { // 상대방이 매칭 요청을 받은 경우
sendMatchFinishNotification(receiverId);
}

if (dto.getEnderId().equals(senderId)) {
sendMatchFinishNotification(senderId, receiverId);
} else {
sendMatchFinishNotification(receiverId, senderId);
}

// 종료로 상태 변경
redisTemplate.opsForHash().put("matchId:" + dto.getMatchId() + "-info", "status", "finished");

MatchStatusDto match = new MatchStatusDto();
Expand All @@ -372,11 +364,12 @@ private void validateFinishMatch(String matchId) {
throw new CustomException(ErrorCode.REQUEST_ALREADY_FINISHED);
}
}

private void sendMatchFinishNotification(Long targetUserId) {
User toUser = userRepository.findByUserId(targetUserId).orElseThrow();

private void sendMatchFinishNotification(Long fromUserId, Long toUserId) {
User fromUser = userRepository.findByUserId(fromUserId).orElseThrow();
User toUser = userRepository.findByUserId(toUserId).orElseThrow();
fcmService.sendPushMessageTo(toUser.getDeviceToken(), "커피챗 매칭 종료",
toUser.getNickname() + "님과의 커피챗이 종료되었습니다.");
fromUser.getNickname() + "님과의 커피챗이 종료되었습니다.");
}

// 매칭 요청 종료 확인
Expand Down

0 comments on commit d1e9914

Please sign in to comment.