Skip to content

Commit

Permalink
Merge pull request #226 from swm-nodriversomabus/BUS-230-matching-app…
Browse files Browse the repository at this point in the history
…lication-notification

feat(BE): 매칭 신청 생성/수락/거절 시 알림 표시 BUS-230-matching-application-notific…
  • Loading branch information
Lemonade255 authored Nov 21, 2023
2 parents 7623fe7 + faccb1f commit a443853
Showing 1 changed file with 27 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;

Expand Down Expand Up @@ -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())
Expand Down

0 comments on commit a443853

Please sign in to comment.