Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,6 @@

import jakarta.annotation.Nullable;
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotNull;

public record FcmSendRequest(
@NotNull Long memberId,
@Nullable String token,
@NotBlank String title,
@NotBlank String content) {}
@Nullable String token, @NotBlank String title, @NotBlank String content) {}
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.doubleo.passservice.domain.notification.service;

import com.doubleo.passservice.domain.notification.domain.MemberNotification;
import com.doubleo.passservice.domain.notification.dto.request.FcmSendRequest;
import com.doubleo.passservice.domain.notification.repository.MemberNotificationRepository;
import com.google.firebase.messaging.*;
Expand All @@ -18,10 +17,6 @@ public class FcmService {
private final MemberNotificationRepository memberNotificationRepository;

public void sendNotification(FcmSendRequest request) {
MemberNotification memberNotification =
MemberNotification.createMemberNotification(
request.memberId(), request.title(), request.content());
memberNotificationRepository.save(memberNotification);
if (request.token() == null || request.token().isEmpty()) {
log.info("FCM token is null");
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

import com.doubleo.hospitalservice.domain.area.grpc.server.AreaResponse;
import com.doubleo.memberservice.domain.member.grpc.server.MemberResponse;
import com.doubleo.passservice.domain.notification.domain.MemberNotification;
import com.doubleo.passservice.domain.notification.dto.request.FcmSendRequest;
import com.doubleo.passservice.domain.notification.repository.MemberNotificationRepository;
import com.doubleo.passservice.domain.notification.service.FcmService;
import com.doubleo.passservice.domain.pass.domain.Pass;
import com.doubleo.passservice.domain.pass.domain.PassArea;
Expand Down Expand Up @@ -38,15 +40,22 @@
@RequiredArgsConstructor
public class PassServiceImpl implements PassService {

public static final String GUARDIAN_APPLY_NOTIFICATION_TITLE = "보호자 신청";
public static final String GUARDIAN_APPLY_NOTIFICATION_CONTENT = "%s 님이 보호자 신청 요청을 하였습니다.";
public static final String GUARDIAN_PASS_APPLY_NOTIFICATION_TITLE = "보호자 출입 신청";
public static final String GUARDIAN_PASS_APPLY_NOTIFICATION_CONTENT =
"%s님이 보호자 출입 신청 요청을 하였습니다.";
public static final String GUARDIAN_PASS_APPLY_TO_GUARDIAN_TITLE = "보호자 출입 신청";
public static final String GUARDIAN_PASS_APPLY_TO_GUARDIAN_CONTENT =
"%s, %s님에 대한 보호자 출입이 신청되었습니다.";
public static final String GUARDIAN_PASS_APPLY_TO_PATIENT_TITLE = "보호자 출입 신청";
public static final String GUARDIAN_PASS_APPLY_TO_PATIENT_CONTENT = "%s, %s님이 보호자 출입을 신청하였습니다.";
public static final String GUARDIAN_APPROVED_NOTIFICATION_TITLE = "보호자 신청 승인";
public static final String GUARDIAN_APPROVED_NOTIFICATION_CONTENT = "%s 님의 보호자 신청이 승인되었습니다.";
public static final String GUARDIAN_APPROVED_NOTIFICATION_CONTENT = "%s님의 보호자 신청이 승인되었습니다.";
public static final String GUARDIAN_REJECTED_NOTIFICATION_TITLE = "보호자 신청 거절";
public static final String GUARDIAN_REJECTED_NOTIFICATION_CONTENT = "%s 님의 보호자 신청이 거절되었습니다.";
public static final String GUARDIAN_REJECTED_NOTIFICATION_CONTENT = "%s님의 보호자 신청이 거절되었습니다.";

private final PassRepository passRepository;
private final PassAreaRepository passAreaRepository;
private final MemberNotificationRepository memberNotificationRepository;
private final MemberClient memberClient;
private final AreaClient areaClient;
private final PatientClient patientClient;
Expand Down Expand Up @@ -243,40 +252,64 @@ public PassCreateResponse createGuardianAndUpdatePassStatus(
areaCodes);
fcmService.sendNotification(
new FcmSendRequest(
member.getMemberId(),
member.getFcmToken(),
GUARDIAN_APPROVED_NOTIFICATION_TITLE,
String.format(
GUARDIAN_APPROVED_NOTIFICATION_CONTENT,
member.getMemberName())));
memberNotificationRepository.save(
MemberNotification.createMemberNotification(
member.getMemberId(),
GUARDIAN_APPROVED_NOTIFICATION_TITLE,
String.format(
GUARDIAN_APPROVED_NOTIFICATION_CONTENT,
member.getMemberName())));
if (patientMember != null) {
fcmService.sendNotification(
new FcmSendRequest(
patientMember.getMemberId(),
patientMember.getFcmToken(),
GUARDIAN_APPROVED_NOTIFICATION_TITLE,
String.format(
GUARDIAN_APPROVED_NOTIFICATION_CONTENT,
member.getMemberName())));
memberNotificationRepository.save(
MemberNotification.createMemberNotification(
patientMember.getMemberId(),
GUARDIAN_APPROVED_NOTIFICATION_TITLE,
String.format(
GUARDIAN_APPROVED_NOTIFICATION_CONTENT,
member.getMemberName())));
}
} else if (issuanceStatus == IssuanceStatus.REJECTED) {
fcmService.sendNotification(
new FcmSendRequest(
member.getMemberId(),
member.getFcmToken(),
GUARDIAN_REJECTED_NOTIFICATION_TITLE,
String.format(
GUARDIAN_REJECTED_NOTIFICATION_CONTENT,
member.getMemberName())));
memberNotificationRepository.save(
MemberNotification.createMemberNotification(
member.getMemberId(),
GUARDIAN_REJECTED_NOTIFICATION_TITLE,
String.format(
GUARDIAN_REJECTED_NOTIFICATION_CONTENT,
member.getMemberName())));
if (patientMember != null) {
fcmService.sendNotification(
new FcmSendRequest(
patientMember.getMemberId(),
patientMember.getFcmToken(),
GUARDIAN_REJECTED_NOTIFICATION_TITLE,
String.format(
GUARDIAN_REJECTED_NOTIFICATION_CONTENT,
member.getMemberName())));
memberNotificationRepository.save(
MemberNotification.createMemberNotification(
patientMember.getMemberId(),
GUARDIAN_REJECTED_NOTIFICATION_TITLE,
String.format(
GUARDIAN_REJECTED_NOTIFICATION_CONTENT,
member.getMemberName())));
}
}
return new PassCreateResponse(pass.getId());
Expand Down Expand Up @@ -341,13 +374,30 @@ private PassCreateResponse createPass(
if (patientMember != null) {
fcmService.sendNotification(
new FcmSendRequest(
patientMember.getMemberId(),
patientMember.getFcmToken(),
GUARDIAN_APPLY_NOTIFICATION_TITLE,
GUARDIAN_PASS_APPLY_NOTIFICATION_TITLE,
String.format(
GUARDIAN_APPLY_NOTIFICATION_CONTENT,
GUARDIAN_PASS_APPLY_NOTIFICATION_CONTENT,
member.getMemberName())));
memberNotificationRepository.save(
MemberNotification.createMemberNotification(
patientMember.getMemberId(),
GUARDIAN_PASS_APPLY_TO_PATIENT_TITLE,
String.format(
GUARDIAN_PASS_APPLY_TO_PATIENT_CONTENT,
pass.getStartAt()
.format(DateTimeFormatter.ofPattern("yyyy-MM-dd")),
member.getMemberName())));
}
memberNotificationRepository.save(
MemberNotification.createMemberNotification(
member.getMemberId(),
GUARDIAN_PASS_APPLY_TO_GUARDIAN_TITLE,
String.format(
GUARDIAN_PASS_APPLY_TO_GUARDIAN_CONTENT,
pass.getStartAt()
.format(DateTimeFormatter.ofPattern("yyyy-MM-dd")),
patient.getName())));
}

if (status == IssuanceStatus.ISSUED) {
Expand Down