diff --git a/src/main/java/com/depromeet/domain/notification/api/PushController.java b/src/main/java/com/depromeet/domain/notification/api/NotificationController.java similarity index 63% rename from src/main/java/com/depromeet/domain/notification/api/PushController.java rename to src/main/java/com/depromeet/domain/notification/api/NotificationController.java index 9b197110f..124457584 100644 --- a/src/main/java/com/depromeet/domain/notification/api/PushController.java +++ b/src/main/java/com/depromeet/domain/notification/api/NotificationController.java @@ -1,11 +1,13 @@ package com.depromeet.domain.notification.api; -import com.depromeet.domain.notification.application.PushService; +import com.depromeet.domain.notification.application.NotificationService; +import com.depromeet.domain.notification.dto.NotificationFindAllResponse; import com.depromeet.domain.notification.dto.request.PushMissionRemindRequest; import com.depromeet.domain.notification.dto.request.PushUrgingSendRequest; import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.tags.Tag; import jakarta.validation.Valid; +import java.util.List; import lombok.RequiredArgsConstructor; import org.springframework.web.bind.annotation.*; @@ -13,18 +15,24 @@ @RestController @RequestMapping("/notifications") @RequiredArgsConstructor -public class PushController { - private final PushService pushService; +public class NotificationController { + private final NotificationService notificationService; + + @Operation(summary = "알림센터 조회", description = "알림센터 목록을 조회합니다.") + @GetMapping + public List notificationFindAll() { + return notificationService.findAllNotification(); + } @Operation(summary = "재촉하기", description = "당일 미션을 완료하지 않은 친구에게 재촉하기 Push Message를 발송합니다.") @PostMapping("/urging") public void urgingSend(@Valid @RequestBody PushUrgingSendRequest request) { - pushService.sendUrgingPush(request); + notificationService.sendUrgingPush(request); } @Operation(summary = "미션 타이머 리마인드 알림", description = "인증을 놓치는 경우에 대비하여 리마인드 알림을 전송합니다.") @PostMapping("/missions/remind") public void missionRemindSend(@Valid @RequestBody PushMissionRemindRequest request) { - pushService.sendMissionRemindPush(request); + notificationService.sendMissionRemindPush(request); } } diff --git a/src/main/java/com/depromeet/domain/notification/application/PushService.java b/src/main/java/com/depromeet/domain/notification/application/NotificationService.java similarity index 84% rename from src/main/java/com/depromeet/domain/notification/application/PushService.java rename to src/main/java/com/depromeet/domain/notification/application/NotificationService.java index 33e763498..892dcec2f 100644 --- a/src/main/java/com/depromeet/domain/notification/application/PushService.java +++ b/src/main/java/com/depromeet/domain/notification/application/NotificationService.java @@ -8,6 +8,7 @@ import com.depromeet.domain.notification.dao.NotificationRepository; import com.depromeet.domain.notification.domain.Notification; import com.depromeet.domain.notification.domain.NotificationType; +import com.depromeet.domain.notification.dto.NotificationFindAllResponse; import com.depromeet.domain.notification.dto.request.PushMissionRemindRequest; import com.depromeet.domain.notification.dto.request.PushUrgingSendRequest; import com.depromeet.global.common.constants.PushNotificationConstants; @@ -15,6 +16,8 @@ import com.depromeet.global.error.exception.ErrorCode; import com.depromeet.global.util.MemberUtil; import java.time.Instant; +import java.util.List; +import java.util.stream.Collectors; import lombok.RequiredArgsConstructor; import org.springframework.scheduling.TaskScheduler; import org.springframework.stereotype.Service; @@ -23,7 +26,7 @@ @Service @RequiredArgsConstructor @Transactional -public class PushService { +public class NotificationService { private final MemberUtil memberUtil; private final FcmService fcmService; private final MissionRepository missionRepository; @@ -68,6 +71,17 @@ public void sendMissionRemindPush(PushMissionRemindRequest request) { Instant.now().plusSeconds(request.seconds())); } + public List findAllNotification() { + final Member member = memberUtil.getCurrentMember(); + return notificationRepository.findAllByTargetMemberId(member.getId()).stream() + .map( + notification -> + NotificationFindAllResponse.of( + notification.getNotificationType(), + notification.getCreatedAt())) + .collect(Collectors.toList()); + } + private void validateFinishedMission(Mission mission) { if (mission.isFinished()) { throw new CustomException(ErrorCode.FINISHED_MISSION_URGING_NOT_ALLOWED); diff --git a/src/main/java/com/depromeet/domain/notification/dao/NotificationRepository.java b/src/main/java/com/depromeet/domain/notification/dao/NotificationRepository.java index 0b70f4801..e904858d9 100644 --- a/src/main/java/com/depromeet/domain/notification/dao/NotificationRepository.java +++ b/src/main/java/com/depromeet/domain/notification/dao/NotificationRepository.java @@ -2,10 +2,13 @@ import com.depromeet.domain.notification.domain.Notification; import com.depromeet.domain.notification.domain.NotificationType; +import java.util.List; import java.util.Optional; import org.springframework.data.jpa.repository.JpaRepository; public interface NotificationRepository extends JpaRepository { Optional findBySourceMemberIdAndTargetMemberIdAndNotificationType( Long sourceId, Long targetId, NotificationType notificationType); + + List findAllByTargetMemberId(Long memberId); } diff --git a/src/main/java/com/depromeet/domain/notification/dto/NotificationFindAllResponse.java b/src/main/java/com/depromeet/domain/notification/dto/NotificationFindAllResponse.java new file mode 100644 index 000000000..ffac7c406 --- /dev/null +++ b/src/main/java/com/depromeet/domain/notification/dto/NotificationFindAllResponse.java @@ -0,0 +1,16 @@ +package com.depromeet.domain.notification.dto; + +import com.depromeet.domain.mission.domain.*; +import com.depromeet.domain.notification.domain.NotificationType; +import io.swagger.v3.oas.annotations.media.Schema; +import java.time.LocalDateTime; + +public record NotificationFindAllResponse( + @Schema(description = "알림 타입") NotificationType notificationType, + @Schema(description = "알림 날짜") LocalDateTime createdAt) { + + public static NotificationFindAllResponse of( + NotificationType notificationType, LocalDateTime createdAt) { + return new NotificationFindAllResponse(notificationType, createdAt); + } +} diff --git a/src/test/java/com/depromeet/domain/notification/application/PushServiceTest.java b/src/test/java/com/depromeet/domain/notification/application/NotificationServiceTest.java similarity index 95% rename from src/test/java/com/depromeet/domain/notification/application/PushServiceTest.java rename to src/test/java/com/depromeet/domain/notification/application/NotificationServiceTest.java index 82150bf67..0492f9783 100644 --- a/src/test/java/com/depromeet/domain/notification/application/PushServiceTest.java +++ b/src/test/java/com/depromeet/domain/notification/application/NotificationServiceTest.java @@ -41,7 +41,7 @@ @SpringBootTest @ActiveProfiles("test") -class PushServiceTest { +class NotificationServiceTest { @Autowired private DatabaseCleaner databaseCleaner; @Autowired private MemberUtil memberUtil; @@ -56,7 +56,7 @@ class PushServiceTest { @Autowired private MissionRecordRepository missionRecordRepository; - @Autowired private PushService pushService; + @Autowired private NotificationService notificationService; @BeforeEach void setUp() { @@ -76,7 +76,7 @@ class 친구에게_미션을_재촉할_때 { PushUrgingSendRequest request = new PushUrgingSendRequest(1L); // when, then - assertThatThrownBy(() -> pushService.sendUrgingPush(request)) + assertThatThrownBy(() -> notificationService.sendUrgingPush(request)) .isInstanceOf(CustomException.class) .hasMessage(ErrorCode.MEMBER_NOT_FOUND.getMessage()); } @@ -90,7 +90,7 @@ class 친구에게_미션을_재촉할_때 { Profile.createProfile("testNickname1", "testImageUrl1"))); // when, then - assertThatThrownBy(() -> pushService.sendUrgingPush(request)) + assertThatThrownBy(() -> notificationService.sendUrgingPush(request)) .isInstanceOf(CustomException.class) .hasMessage(ErrorCode.MISSION_NOT_FOUND.getMessage()); } @@ -119,7 +119,7 @@ class 친구에게_미션을_재촉할_때 { currentMember)); // when, then - assertThatThrownBy(() -> pushService.sendUrgingPush(request)) + assertThatThrownBy(() -> notificationService.sendUrgingPush(request)) .isInstanceOf(CustomException.class) .hasMessage(ErrorCode.SELF_SENDING_NOT_ALLOWED.getMessage()); } @@ -152,7 +152,7 @@ class 친구에게_미션을_재촉할_때 { targetMember)); // when, then - assertThatThrownBy(() -> pushService.sendUrgingPush(request)) + assertThatThrownBy(() -> notificationService.sendUrgingPush(request)) .isInstanceOf(CustomException.class) .hasMessage(ErrorCode.FINISHED_MISSION_URGING_NOT_ALLOWED.getMessage()); } @@ -202,7 +202,7 @@ class 친구에게_미션을_재촉할_때 { missionRecordRepository.save(missionRecord); // when, then - assertThatThrownBy(() -> pushService.sendUrgingPush(request)) + assertThatThrownBy(() -> notificationService.sendUrgingPush(request)) .isInstanceOf(CustomException.class) .hasMessage(ErrorCode.TODAY_COMPLETED_MISSION_SENDING_NOT_ALLOWED.getMessage()); } @@ -240,7 +240,7 @@ class 친구에게_미션을_재촉할_때 { targetMember)); // when - pushService.sendUrgingPush(request); + notificationService.sendUrgingPush(request); // then Optional optionalNotification = notificationRepository.findById(1L);