From 9d2d8f05d35e0a3bdb04dd71d6eb74ad0c7cb5b7 Mon Sep 17 00:00:00 2001 From: dev-Crayon Date: Wed, 1 May 2024 15:29:22 +0900 Subject: [PATCH] =?UTF-8?q?[Hotfix]:=20=ED=91=B8=EC=8B=9C=EC=95=8C?= =?UTF-8?q?=EB=A6=BC=20=EC=A0=84=EC=86=A1=20=EB=A1=9C=EC=A7=81=20=EB=B3=80?= =?UTF-8?q?=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../external/firebase/FCMPushService.java | 1 + .../firebase/dto/PushNotificationRequest.java | 3 +- .../friend/application/FriendService.java | 95 ++++++++++--------- .../notice/application/NoticeService.java | 2 + .../pill/application/PillService.java | 1 + .../PillPushNotificationService.java | 1 + .../sticker/application/StickerService.java | 57 +++++------ 7 files changed, 87 insertions(+), 73 deletions(-) diff --git a/src/main/java/io/sobok/SobokSobok/external/firebase/FCMPushService.java b/src/main/java/io/sobok/SobokSobok/external/firebase/FCMPushService.java index 1258776..d918510 100644 --- a/src/main/java/io/sobok/SobokSobok/external/firebase/FCMPushService.java +++ b/src/main/java/io/sobok/SobokSobok/external/firebase/FCMPushService.java @@ -49,6 +49,7 @@ public void sendNotificationByToken(PushNotificationRequest request) { ) .putData("title", request.title()) .putData("body", request.body()) + .putData("type", request.type()) .build(); sendMessageToFirebase(message, user.getId()); diff --git a/src/main/java/io/sobok/SobokSobok/external/firebase/dto/PushNotificationRequest.java b/src/main/java/io/sobok/SobokSobok/external/firebase/dto/PushNotificationRequest.java index 0a2a09b..3708cec 100644 --- a/src/main/java/io/sobok/SobokSobok/external/firebase/dto/PushNotificationRequest.java +++ b/src/main/java/io/sobok/SobokSobok/external/firebase/dto/PushNotificationRequest.java @@ -12,6 +12,7 @@ public record PushNotificationRequest( String title, String body, String image, - Map data + Map data, + String type ) { } diff --git a/src/main/java/io/sobok/SobokSobok/friend/application/FriendService.java b/src/main/java/io/sobok/SobokSobok/friend/application/FriendService.java index 4c5ff7c..ee3089e 100644 --- a/src/main/java/io/sobok/SobokSobok/friend/application/FriendService.java +++ b/src/main/java/io/sobok/SobokSobok/friend/application/FriendService.java @@ -26,9 +26,11 @@ import io.sobok.SobokSobok.notice.domain.NoticeType; import io.sobok.SobokSobok.notice.infrastructure.NoticeQueryRepository; import io.sobok.SobokSobok.notice.infrastructure.NoticeRepository; + import java.time.LocalDateTime; import java.util.List; import java.util.stream.Collectors; + import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -57,43 +59,44 @@ public AddFriendResponse addFriend(Long userId, AddFriendRequest request) { User receiver = UserServiceUtil.findUserById(userRepository, request.memberId()); if (friendRepository.countBySenderId(sender.getId()) >= 5 || - friendRepository.countBySenderId(receiver.getId()) >= 5) { + friendRepository.countBySenderId(receiver.getId()) >= 5) { throw new ConflictException(ErrorCode.EXCEEDED_FRIEND_COUNT); } if (noticeQueryRepository.isAlreadyFriendRequestFromSender(sender.getId(), receiver.getId()) - || noticeQueryRepository.isAlreadyFriendRequestFromSender(receiver.getId(), - sender.getId())) { + || noticeQueryRepository.isAlreadyFriendRequestFromSender(receiver.getId(), + sender.getId())) { throw new ConflictException(ErrorCode.ALREADY_FRIEND); } Notice notice = noticeRepository.save( - Notice.newInstance( - sender.getId(), - receiver.getId(), - NoticeType.FRIEND, - NoticeStatus.WAITING - ) + Notice.newInstance( + sender.getId(), + receiver.getId(), + NoticeType.FRIEND, + NoticeStatus.WAITING + ) ); sendFriendRepository.save( - SendFriend.newInstance( - notice.getId(), - request.friendName() - ) + SendFriend.newInstance( + notice.getId(), + request.friendName() + ) ); fcmPushService.sendNotificationByToken(PushNotificationRequest.builder() .userId(receiver.getId()) .title(sender.getUsername() + "님이 친구를 신청했어요") + .type("notice") .build()); return AddFriendResponse.builder() - .noticeId(notice.getId()) - .senderName(sender.getUsername()) - .memberName(receiver.getUsername()) - .isOkay(NoticeStatus.WAITING) - .build(); + .noticeId(notice.getId()) + .senderName(sender.getUsername()) + .memberName(receiver.getUsername()) + .isOkay(NoticeStatus.WAITING) + .build(); } @Transactional(readOnly = true) @@ -101,22 +104,22 @@ public List getFriendList(Long userId) { UserServiceUtil.existsUserById(userRepository, userId); return friendRepository.findAllBySenderId(userId) - .stream().map(friend -> - FriendListResponse.builder() - .friendId(friend.getId()) - .memberId(friend.getReceiverId()) - .friendName(friend.getFriendName()) - .build() - ).collect(Collectors.toList()); + .stream().map(friend -> + FriendListResponse.builder() + .friendId(friend.getId()) + .memberId(friend.getReceiverId()) + .friendName(friend.getFriendName()) + .build() + ).collect(Collectors.toList()); } @Transactional(noRollbackFor = {ConflictException.class}) public HandleFriendRequestResponse updateNoticeStatus(Long userId, Long noticeId, - HandleFriendRequest request) { + HandleFriendRequest request) { UserServiceUtil.existsUserById(userRepository, userId); Notice notice = noticeRepository.findById(noticeId) - .orElseThrow(() -> new BadRequestException(ErrorCode.BAD_REQUEST_EXCEPTION)); + .orElseThrow(() -> new BadRequestException(ErrorCode.BAD_REQUEST_EXCEPTION)); if (!userId.equals(notice.getReceiverId())) { throw new ForbiddenException(ErrorCode.FORBIDDEN_EXCEPTION); @@ -126,7 +129,7 @@ public HandleFriendRequestResponse updateNoticeStatus(Long userId, Long noticeId User receiver = UserServiceUtil.findUserById(userRepository, userId); if (friendRepository.countBySenderId(userId) >= 5 || - friendRepository.countBySenderId(sender.getId()) >= 5) { + friendRepository.countBySenderId(sender.getId()) >= 5) { notice.updateIsOkay(NoticeStatus.REFUSE); throw new ConflictException(ErrorCode.EXCEEDED_FRIEND_COUNT); } @@ -136,34 +139,36 @@ public HandleFriendRequestResponse updateNoticeStatus(Long userId, Long noticeId if (request.isOkay() == NoticeStatus.ACCEPT) { SendFriend sendFriend = sendFriendRepository.findByNoticeId(noticeId); friendRepository.save(Friend.newInstance( - sender.getId(), - userId, - sendFriend.getFriendName() + sender.getId(), + userId, + sendFriend.getFriendName() )); friendRepository.save(Friend.newInstance( - userId, - sender.getId(), - sender.getUsername() + userId, + sender.getId(), + sender.getUsername() )); fcmPushService.sendNotificationByToken(PushNotificationRequest.builder() .userId(sender.getId()) .title(receiver.getUsername() + "님이 친구를 수락했어요") + .type("notice") .build()); } else { fcmPushService.sendNotificationByToken(PushNotificationRequest.builder() .userId(sender.getId()) .title(receiver.getUsername() + "님이 친구를 거절했어요") + .type("notice") .build()); } return HandleFriendRequestResponse.builder() - .noticeId(notice.getId()) - .memberName(sender.getUsername()) - .isOkay(request.isOkay()) - .updatedAt(LocalDateTime.now()) - .build(); + .noticeId(notice.getId()) + .memberName(sender.getUsername()) + .isOkay(request.isOkay()) + .updatedAt(LocalDateTime.now()) + .build(); } @Transactional @@ -171,7 +176,7 @@ public UpdateFriendNameResponse updateFriendName(Long userId, Long friendId, Upd UserServiceUtil.existsUserById(userRepository, userId); Friend friend = friendRepository.findById(friendId) - .orElseThrow(() -> new ForbiddenException(ErrorCode.FORBIDDEN_EXCEPTION)); + .orElseThrow(() -> new ForbiddenException(ErrorCode.FORBIDDEN_EXCEPTION)); if (!friend.getSenderId().equals(userId)) { throw new ForbiddenException(ErrorCode.FORBIDDEN_EXCEPTION); @@ -180,11 +185,11 @@ public UpdateFriendNameResponse updateFriendName(Long userId, Long friendId, Upd friend.updateFriendName(request.friendName()); return UpdateFriendNameResponse.builder() - .friendId(friendId) - .userId(userId) - .memberId(friend.getReceiverId()) - .friendName(request.friendName()) - .build(); + .friendId(friendId) + .userId(userId) + .memberId(friend.getReceiverId()) + .friendName(request.friendName()) + .build(); } @Transactional diff --git a/src/main/java/io/sobok/SobokSobok/notice/application/NoticeService.java b/src/main/java/io/sobok/SobokSobok/notice/application/NoticeService.java index 24b7648..c31a228 100644 --- a/src/main/java/io/sobok/SobokSobok/notice/application/NoticeService.java +++ b/src/main/java/io/sobok/SobokSobok/notice/application/NoticeService.java @@ -104,6 +104,7 @@ public void completePillNotice(Long userId, Long pillId, NoticeStatus isOkay) { fcmPushService.sendNotificationByToken(PushNotificationRequest.builder() .userId(sender.getId()) .title(receiver.getUsername() + "님이 약 일정을 거절했어요") + .type("notice") .build()); } @@ -113,6 +114,7 @@ public void completePillNotice(Long userId, Long pillId, NoticeStatus isOkay) { fcmPushService.sendNotificationByToken(PushNotificationRequest.builder() .userId(sender.getId()) .title(receiver.getUsername() + "님이 약 일정을 수락했어요") + .type("notice") .build()); } diff --git a/src/main/java/io/sobok/SobokSobok/pill/application/PillService.java b/src/main/java/io/sobok/SobokSobok/pill/application/PillService.java index d781788..d1667c6 100644 --- a/src/main/java/io/sobok/SobokSobok/pill/application/PillService.java +++ b/src/main/java/io/sobok/SobokSobok/pill/application/PillService.java @@ -137,6 +137,7 @@ public void sendPill(Long userId, Long friendId, PillRequest request) { .userId(friendId) .title(receiverUsername + "님이 보낸 약 일정을 확인해보세요!") .body(pillNameSentence.toString()) + .type("notice") .build()); } diff --git a/src/main/java/io/sobok/SobokSobok/scheduler/PillPushNotificationService.java b/src/main/java/io/sobok/SobokSobok/scheduler/PillPushNotificationService.java index 7a597a2..6a4ad09 100644 --- a/src/main/java/io/sobok/SobokSobok/scheduler/PillPushNotificationService.java +++ b/src/main/java/io/sobok/SobokSobok/scheduler/PillPushNotificationService.java @@ -47,6 +47,7 @@ private void notifyPillSchedule(LocalDate date, String time) { .userId(pill.getUserId()) .title("[" + pill.getPillName() + "]" + DateUtil.getKoreanTime(time)) .body("소중한 '" + user.getUsername() + "'님, 약 드실 시간이에요\n다 드시면 앱에서 체크 버튼을 눌러주세요") + .type("main") .build() ); } diff --git a/src/main/java/io/sobok/SobokSobok/sticker/application/StickerService.java b/src/main/java/io/sobok/SobokSobok/sticker/application/StickerService.java index c6cbc58..d1d21a9 100644 --- a/src/main/java/io/sobok/SobokSobok/sticker/application/StickerService.java +++ b/src/main/java/io/sobok/SobokSobok/sticker/application/StickerService.java @@ -24,8 +24,10 @@ import io.sobok.SobokSobok.sticker.ui.dto.ReceivedStickerResponse; import io.sobok.SobokSobok.sticker.ui.dto.StickerActionResponse; import io.sobok.SobokSobok.sticker.ui.dto.StickerResponse; + import java.util.List; import java.util.stream.Collectors; + import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -47,10 +49,10 @@ public class StickerService { @Transactional public List getStickerList() { return stickerRepository.findAll().stream().map( - sticker -> StickerResponse.builder() - .stickerId(sticker.getId()) - .stickerImg(sticker.getStickerImg()) - .build() + sticker -> StickerResponse.builder() + .stickerId(sticker.getId()) + .stickerImg(sticker.getStickerImg()) + .build() ).collect(Collectors.toList()); } @@ -58,7 +60,7 @@ public List getStickerList() { public StickerActionResponse sendSticker(Long userId, Long scheduleId, Long stickerId) { UserServiceUtil.existsUserById(userRepository, userId); PillSchedule pillSchedule = PillScheduleServiceUtil.findPillScheduleById( - pillScheduleRepository, scheduleId); + pillScheduleRepository, scheduleId); StickerServiceUtil.existsStickerById(stickerRepository, stickerId); if (!pillSchedule.getIsCheck()) { @@ -77,35 +79,36 @@ public StickerActionResponse sendSticker(Long userId, Long scheduleId, Long stic } LikeSchedule likeSchedule = likeScheduleRepository.save( - LikeSchedule.builder() - .scheduleId(scheduleId) - .senderId(userId) - .stickerId(stickerId) - .build() + LikeSchedule.builder() + .scheduleId(scheduleId) + .senderId(userId) + .stickerId(stickerId) + .build() ); fcmPushService.sendNotificationByToken(PushNotificationRequest.builder() .userId(receiver.getId()) .title(senderUsername + "님이 " + pill.getPillName() + " 복약에 반응을 남겼어요!") .body("받은 스티커를 확인해보세요") + .type("main") .build()); return StickerActionResponse.builder() - .likeScheduleId(likeSchedule.getId()) - .scheduleId(likeSchedule.getScheduleId()) - .senderId(likeSchedule.getSenderId()) - .stickerId(likeSchedule.getStickerId()) - .createdAt(likeSchedule.getCreatedAt()) - .updatedAt(likeSchedule.getUpdatedAt()) - .build(); + .likeScheduleId(likeSchedule.getId()) + .scheduleId(likeSchedule.getScheduleId()) + .senderId(likeSchedule.getSenderId()) + .stickerId(likeSchedule.getStickerId()) + .createdAt(likeSchedule.getCreatedAt()) + .updatedAt(likeSchedule.getUpdatedAt()) + .build(); } @Transactional public StickerActionResponse updateSendSticker(Long userId, Long likeScheduleId, - Long stickerId) { + Long stickerId) { UserServiceUtil.existsUserById(userRepository, userId); LikeSchedule likeSchedule = likeScheduleRepository.findById(likeScheduleId) - .orElseThrow(() -> new NotFoundException(ErrorCode.UNREGISTERED_LIKE_SCHEDULE)); + .orElseThrow(() -> new NotFoundException(ErrorCode.UNREGISTERED_LIKE_SCHEDULE)); StickerServiceUtil.existsStickerById(stickerRepository, stickerId); if (!likeSchedule.isLikeScheduleSender(userId)) { @@ -115,20 +118,20 @@ public StickerActionResponse updateSendSticker(Long userId, Long likeScheduleId, likeSchedule.changeSticker(stickerId); return StickerActionResponse.builder() - .likeScheduleId(likeSchedule.getId()) - .scheduleId(likeSchedule.getScheduleId()) - .senderId(likeSchedule.getSenderId()) - .stickerId(likeSchedule.getStickerId()) - .createdAt(likeSchedule.getCreatedAt()) - .updatedAt(likeSchedule.getUpdatedAt()) - .build(); + .likeScheduleId(likeSchedule.getId()) + .scheduleId(likeSchedule.getScheduleId()) + .senderId(likeSchedule.getSenderId()) + .stickerId(likeSchedule.getStickerId()) + .createdAt(likeSchedule.getCreatedAt()) + .updatedAt(likeSchedule.getUpdatedAt()) + .build(); } @Transactional public List getReceivedStickerList(Long userId, Long scheduleId) { UserServiceUtil.existsUserById(userRepository, userId); PillSchedule pillSchedule = PillScheduleServiceUtil.findPillScheduleById( - pillScheduleRepository, scheduleId); + pillScheduleRepository, scheduleId); Pill pill = PillServiceUtil.findPillById(pillRepository, pillSchedule.getPillId()); if (!pill.isPillUser(userId) && !friendQueryRepository.isAlreadyFriend(userId, pill.getUserId())) {