From 422b79e51e740c268c2447c64450434d9f22be9b Mon Sep 17 00:00:00 2001 From: minwoo0419 Date: Sun, 9 Jun 2024 16:06:59 +0900 Subject: [PATCH] =?UTF-8?q?[feat]=20#109=20=EB=B0=A9=20=EC=82=AD=EC=A0=9C?= =?UTF-8?q?=20=EC=8B=9C=20fcm=20=EC=95=8C=EB=A6=BC=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../server/controller/RoomController.java | 5 ++- .../server/dto/type/FcmContent.java | 2 + .../server/service/room/RoomService.java | 38 ++++++++++++++----- 3 files changed, 33 insertions(+), 12 deletions(-) diff --git a/src/main/java/com/telepigeon/server/controller/RoomController.java b/src/main/java/com/telepigeon/server/controller/RoomController.java index 0dbe797..51bcad7 100644 --- a/src/main/java/com/telepigeon/server/controller/RoomController.java +++ b/src/main/java/com/telepigeon/server/controller/RoomController.java @@ -51,10 +51,11 @@ public ResponseEntity enterRoom( } @DeleteMapping("/rooms/{roomId}") - public ResponseEntity deleteRoom( + public ResponseEntity deleteRoom( @UserId final Long userId, @PathVariable final Long roomId ) { - return ResponseEntity.ok(roomService.deleteRoom(roomId, userId)); + roomService.deleteRoom(roomId, userId); + return ResponseEntity.ok().build(); } } diff --git a/src/main/java/com/telepigeon/server/dto/type/FcmContent.java b/src/main/java/com/telepigeon/server/dto/type/FcmContent.java index fed1c68..786d0ad 100644 --- a/src/main/java/com/telepigeon/server/dto/type/FcmContent.java +++ b/src/main/java/com/telepigeon/server/dto/type/FcmContent.java @@ -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; diff --git a/src/main/java/com/telepigeon/server/service/room/RoomService.java b/src/main/java/com/telepigeon/server/service/room/RoomService.java index 0792d8a..998801f 100644 --- a/src/main/java/com/telepigeon/server/service/room/RoomService.java +++ b/src/main/java/com/telepigeon/server/service/room/RoomService.java @@ -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 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 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() {