Skip to content

Commit

Permalink
[feat] #109 방 삭제 시 fcm 알림 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
minwoo0419 committed Jun 9, 2024
1 parent 96ced3b commit 422b79e
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,11 @@ public ResponseEntity<Void> enterRoom(
}

@DeleteMapping("/rooms/{roomId}")
public ResponseEntity<Room> deleteRoom(
public ResponseEntity<Void> deleteRoom(
@UserId final Long userId,
@PathVariable final Long roomId
) {
return ResponseEntity.ok(roomService.deleteRoom(roomId, userId));
roomService.deleteRoom(roomId, userId);
return ResponseEntity.ok().build();
}
}
2 changes: 2 additions & 0 deletions src/main/java/com/telepigeon/server/dto/type/FcmContent.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ public enum FcmContent {
QUESTION("질문이 도착했습니다.", "오늘의 질문을 확인하세요!", "ROOM_CLICK", "question"),
ANSWER("답변이 도착했습니다.", "상대방의 답변을 확인하세요!", "ROOM_CLICK", "answer"),
HURRY("재촉하기가 도착했습니다.", "상대방에게 답변을 보내보세요!", "ROOM_CLICK", "hurry"),
ROOM_ENTER("상대방이 입장했습니다", "상대방과 대화를 시작하세요!", "ROOM_CLICK", "room"),
ROOM_LEAVE("상대방이 퇴장했습니다", "상대방이 퇴장했습니다", "ROOM_CLICK", "room"),
;

private final String title;
Expand Down
38 changes: 28 additions & 10 deletions src/main/java/com/telepigeon/server/service/room/RoomService.java
Original file line number Diff line number Diff line change
Expand Up @@ -135,26 +135,44 @@ public Profile enterRoom(final RoomEnterDto roomEnterDto, final Long userId) {

Profile profile = profileSaver.save(Profile.create(user, room));
Profile receiver = profileRetriever.findByUserNotAndRoom(user, room);
fcmService.send(
receiver.getUser().getFcmToken(),
FcmMessageDto.of(
FcmContent.ROOM_ENTER,
room.getId()
)
);
sendQuestionFirst(receiver, profile);
sendQuestionFirst(profile, receiver);
return profile;
}

@Transactional
public Room deleteRoom(final Long roomId, final Long userId) {
public void deleteRoom(final Long roomId, final Long userId) {
Room room = roomRetriever.findById(roomId);
User user = userRetriever.findById(userId);

Profile profile = profileRetriever.findByUserAndRoom(user, room);
List<Worry> worryList = worryRetriever.findAllByProfile(profile);

profile.updateIsDeleted();
worryList.forEach(worryRemover::remove);

if (profileRetriever.countByRoomAndIsDeleted(room, true) == 2)
if (profileRetriever.existsByUserNotAndRoom(user, room)){
Profile opponentProfile = profileRetriever.findByUserNotAndRoom(user, room);
if (!opponentProfile.isDeleted()){
Profile profile = profileRetriever.findByUserAndRoom(user, room);
List<Worry> worryList = worryRetriever.findAllByProfile(profile);

profile.updateIsDeleted();
worryList.forEach(worryRemover::remove);
fcmService.send(
opponentProfile.getUser().getFcmToken(),
FcmMessageDto.of(
FcmContent.ROOM_LEAVE,
room.getId()
)
);
} else {
roomRemover.remove(room);
}
} else {
roomRemover.remove(room);

return room;
}
}

private String createCode() {
Expand Down

0 comments on commit 422b79e

Please sign in to comment.