From faccb1ff6dc295da24697b9dd00ff9cbac3c59ed Mon Sep 17 00:00:00 2001 From: Lemonade255 Date: Tue, 21 Nov 2023 15:14:18 +0900 Subject: [PATCH] =?UTF-8?q?feat(BE):=20=EB=A7=A4=EC=B9=AD=20=EC=8B=A0?= =?UTF-8?q?=EC=B2=AD=20=EC=83=9D=EC=84=B1/=EC=88=98=EB=9D=BD/=EA=B1=B0?= =?UTF-8?q?=EC=A0=88=20=EC=8B=9C=20=EC=95=8C=EB=A6=BC=20=ED=91=9C=EC=8B=9C?= =?UTF-8?q?=20BUS-230-matching-application-notification=20#225?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/MatchingApplicationService.java | 29 +++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/example/api/matching/service/MatchingApplicationService.java b/src/main/java/com/example/api/matching/service/MatchingApplicationService.java index a7c4007..f66f4d3 100644 --- a/src/main/java/com/example/api/matching/service/MatchingApplicationService.java +++ b/src/main/java/com/example/api/matching/service/MatchingApplicationService.java @@ -17,6 +17,13 @@ import com.example.api.matching.dto.FindMatchingDto; import com.example.api.matching.dto.SaveMatchingApplicationDto; import com.example.api.member.service.MemberService; +import com.example.api.notification.adapter.out.persistence.NotificationMapperInterface; +import com.example.api.notification.application.port.out.SaveNotificationPort; +import com.example.api.notification.application.port.out.UserNotificationPort; +import com.example.api.notification.domain.Notification; +import com.example.api.notification.dto.SaveNotificationDto; +import com.example.api.notification.dto.UserNotificationDto; +import com.example.api.notification.type.NotificationTypeEnum; import com.example.api.user.adapter.out.persistence.UserEntity; import com.example.api.user.adapter.out.persistence.UserMapperInterface; import com.example.api.user.application.port.out.FindUserPort; @@ -33,11 +40,14 @@ @Slf4j @Transactional(readOnly = true) public class MatchingApplicationService implements MatchingApplicationUsecase { - private final UserMapperInterface userMapper; - private final MatchingMapperInterface matchingMapper; private final FindUserPort findUserPort; private final FindMatchingPort findMatchingPort; private final MatchingApplicationPort matchingApplicationPort; + private final SaveNotificationPort saveNotificationPort; + private final UserNotificationPort userNotificationPort; + private final UserMapperInterface userMapper; + private final MatchingMapperInterface matchingMapper; + private final NotificationMapperInterface notificationMapper; private final MemberService memberService; private final FcmService fcmService; @@ -139,6 +149,21 @@ public void processMatchingApplication(SaveMatchingApplicationDto matchingApplic memberService.addMember(matchingEntity.getChatRoomId(), matchingApplication.getUserId()); } + // 알림 추가 + SaveNotificationDto saveNotificationDto = SaveNotificationDto.builder() + .type(state.equals(ApplicationStateEnum.Approved) ? NotificationTypeEnum.ApplicationApproved : NotificationTypeEnum.ApplicationDeclined) + .content(state.equals(ApplicationStateEnum.Approved) ? "매칭 신청이 수락되었어요!" : "매칭 신청이 거절되었어요.") + .isActive(true) + .build(); + Notification notification = saveNotificationPort.createNotification(notificationMapper.toDomain(saveNotificationDto)); + UserNotificationDto userNotificationDto = UserNotificationDto.builder() + .userId(matchingApplicationDto.getUserId()) + .notificationId(notification.getNotificationId()) + .isRead(false) + .readAt(null) + .build(); + userNotificationPort.createUserNotification(notificationMapper.toEntity(userNotificationDto)); + // 푸시 알림 전송 FcmDto fcmDto = FcmDto.builder() .userId(matchingApplication.getUserId())