diff --git a/src/main/java/life/offonoff/ab/application/event/topic/TopicEventHandler.java b/src/main/java/life/offonoff/ab/application/event/topic/TopicEventHandler.java index b64d165f..d4ce93a8 100644 --- a/src/main/java/life/offonoff/ab/application/event/topic/TopicEventHandler.java +++ b/src/main/java/life/offonoff/ab/application/event/topic/TopicEventHandler.java @@ -1,6 +1,6 @@ package life.offonoff.ab.application.event.topic; -import life.offonoff.ab.application.notice.NoticeService; +import life.offonoff.ab.application.notification.NotificationService; import life.offonoff.ab.application.service.vote.VotingTopicService; import life.offonoff.ab.application.service.vote.votingtopic.container.VotingTopic; import life.offonoff.ab.domain.topic.Topic; @@ -23,7 +23,7 @@ public class TopicEventHandler { private final VotingTopicService votingTopicService; - private final NoticeService noticeService; + private final NotificationService notificationService; /** * 투표 생성 이벤트 -> VotingTopicContainer에서 관리 추가 @@ -42,7 +42,7 @@ public void addTopic(TopicCreateEvent event) { public void voteClosed(VoteClosedEvent event) { log.info("# Topic Vote Closed / topic-id : {}, deadline : {}", event.topic().getId(), event.topic().getDeadline()); - noticeService.noticeVoteResult(event.result()); + notificationService.noticeVoteResult(event.result()); } /** @@ -53,8 +53,8 @@ public void voted(VotedEvent event) { Topic topic = event.getVote() .getTopic(); - if (noticeService.shouldNoticeVoteCountForTopic(topic)) { - noticeService.noticeVoteCountOnTopic(topic); + if (notificationService.shouldNoticeVoteCountForTopic(topic)) { + notificationService.noticeVoteCountOnTopic(topic); } } } diff --git a/src/main/java/life/offonoff/ab/application/notice/NoticeService.java b/src/main/java/life/offonoff/ab/application/notification/NotificationService.java similarity index 85% rename from src/main/java/life/offonoff/ab/application/notice/NoticeService.java rename to src/main/java/life/offonoff/ab/application/notification/NotificationService.java index 8df83044..48470225 100644 --- a/src/main/java/life/offonoff/ab/application/notice/NoticeService.java +++ b/src/main/java/life/offonoff/ab/application/notification/NotificationService.java @@ -1,15 +1,13 @@ -package life.offonoff.ab.application.notice; +package life.offonoff.ab.application.notification; import life.offonoff.ab.domain.member.Member; -import life.offonoff.ab.domain.notice.VoteCountOnTopicNotification; -import life.offonoff.ab.domain.notice.VoteResultNotification; +import life.offonoff.ab.domain.notification.VoteCountOnTopicNotification; +import life.offonoff.ab.domain.notification.VoteResultNotification; import life.offonoff.ab.domain.topic.Topic; import life.offonoff.ab.domain.vote.VoteResult; import life.offonoff.ab.repository.member.MemberRepository; import life.offonoff.ab.repository.notice.NotificationRepository; -import life.offonoff.ab.web.response.notice.NoticeResponse; -import life.offonoff.ab.web.response.notice.message.NoticeMessage; -import life.offonoff.ab.web.response.notice.message.NoticeMessageFactory; +import life.offonoff.ab.web.response.notification.NotificationResponse; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Value; @@ -22,7 +20,7 @@ @Slf4j @RequiredArgsConstructor @Service -public class NoticeService { +public class NotificationService { @Value("${ab.notification.vote_on_topic.count_unit}") public int voteCountUnit; @@ -80,11 +78,11 @@ public void noticeVoteCountOnTopic(Topic topic) { notificationRepository.save(notification); } - public List findAllByReceiverId(Long memberId) { + public List findAllByReceiverId(Long memberId) { return notificationRepository.findAllByReceiverIdOrderByCreatedAtDesc(memberId) .stream() - .map(NoticeResponse::new) + .map(NotificationResponse::new) .toList(); } diff --git a/src/main/java/life/offonoff/ab/application/service/TopicService.java b/src/main/java/life/offonoff/ab/application/service/TopicService.java index 31889389..7c60887b 100644 --- a/src/main/java/life/offonoff/ab/application/service/TopicService.java +++ b/src/main/java/life/offonoff/ab/application/service/TopicService.java @@ -171,8 +171,8 @@ private void doHide(final Member member, final Topic topic) { private void cancelHide(final Member member, final Topic topic) { member.cancelHideIfExists(topic); } - //== Vote ==// + @Transactional public VoteResponse voteForTopicByMember(final Long topicId, final Long memberId, final VoteRequest request) { Member member = findMember(memberId); diff --git a/src/main/java/life/offonoff/ab/domain/member/Member.java b/src/main/java/life/offonoff/ab/domain/member/Member.java index 72a0066c..58568b79 100644 --- a/src/main/java/life/offonoff/ab/domain/member/Member.java +++ b/src/main/java/life/offonoff/ab/domain/member/Member.java @@ -5,7 +5,7 @@ import life.offonoff.ab.domain.comment.Comment; import life.offonoff.ab.domain.comment.HatedComment; import life.offonoff.ab.domain.comment.LikedComment; -import life.offonoff.ab.domain.notice.Notification; +import life.offonoff.ab.domain.notification.Notification; import life.offonoff.ab.domain.topic.Topic; import life.offonoff.ab.domain.topic.choice.ChoiceOption; import life.offonoff.ab.domain.topic.hide.HiddenTopic; diff --git a/src/main/java/life/offonoff/ab/domain/notice/CommentOnTopicNotification.java b/src/main/java/life/offonoff/ab/domain/notification/CommentOnTopicNotification.java similarity index 60% rename from src/main/java/life/offonoff/ab/domain/notice/CommentOnTopicNotification.java rename to src/main/java/life/offonoff/ab/domain/notification/CommentOnTopicNotification.java index 2ace8d80..78b303d3 100644 --- a/src/main/java/life/offonoff/ab/domain/notice/CommentOnTopicNotification.java +++ b/src/main/java/life/offonoff/ab/domain/notification/CommentOnTopicNotification.java @@ -1,16 +1,12 @@ -package life.offonoff.ab.domain.notice; +package life.offonoff.ab.domain.notification; import jakarta.persistence.DiscriminatorValue; import jakarta.persistence.Entity; -import jakarta.persistence.FetchType; -import jakarta.persistence.ManyToOne; -import life.offonoff.ab.domain.member.Member; -import life.offonoff.ab.domain.vote.VoteResult; import lombok.AccessLevel; import lombok.Getter; import lombok.NoArgsConstructor; -import static life.offonoff.ab.domain.notice.NotificationType.COMMENT_ON_TOPIC_NOTIFICATION; +import static life.offonoff.ab.domain.notification.NotificationType.COMMENT_ON_TOPIC_NOTIFICATION; // TODO:수정대상 @Getter @NoArgsConstructor(access = AccessLevel.PROTECTED) diff --git a/src/main/java/life/offonoff/ab/domain/notice/DefaultNotification.java b/src/main/java/life/offonoff/ab/domain/notification/DefaultNotification.java similarity index 72% rename from src/main/java/life/offonoff/ab/domain/notice/DefaultNotification.java rename to src/main/java/life/offonoff/ab/domain/notification/DefaultNotification.java index 68d1a758..d6b2c63c 100644 --- a/src/main/java/life/offonoff/ab/domain/notice/DefaultNotification.java +++ b/src/main/java/life/offonoff/ab/domain/notification/DefaultNotification.java @@ -1,15 +1,13 @@ -package life.offonoff.ab.domain.notice; +package life.offonoff.ab.domain.notification; import jakarta.persistence.DiscriminatorValue; import jakarta.persistence.Entity; import life.offonoff.ab.domain.member.Member; -import life.offonoff.ab.domain.topic.Topic; import lombok.AccessLevel; import lombok.Getter; import lombok.NoArgsConstructor; -import static life.offonoff.ab.domain.notice.NotificationType.DEFAULT; -import static life.offonoff.ab.domain.notice.NotificationType.VOTE_COUNT_ON_TOPIC_NOTIFICATION; +import static life.offonoff.ab.domain.notification.NotificationType.DEFAULT; @Getter @NoArgsConstructor(access = AccessLevel.PROTECTED) diff --git a/src/main/java/life/offonoff/ab/domain/notice/LikeInCommentNotification.java b/src/main/java/life/offonoff/ab/domain/notification/LikeInCommentNotification.java similarity index 60% rename from src/main/java/life/offonoff/ab/domain/notice/LikeInCommentNotification.java rename to src/main/java/life/offonoff/ab/domain/notification/LikeInCommentNotification.java index 58aedefe..f9102c4b 100644 --- a/src/main/java/life/offonoff/ab/domain/notice/LikeInCommentNotification.java +++ b/src/main/java/life/offonoff/ab/domain/notification/LikeInCommentNotification.java @@ -1,16 +1,12 @@ -package life.offonoff.ab.domain.notice; +package life.offonoff.ab.domain.notification; import jakarta.persistence.DiscriminatorValue; import jakarta.persistence.Entity; -import jakarta.persistence.FetchType; -import jakarta.persistence.ManyToOne; -import life.offonoff.ab.domain.member.Member; -import life.offonoff.ab.domain.vote.VoteResult; import lombok.AccessLevel; import lombok.Getter; import lombok.NoArgsConstructor; -import static life.offonoff.ab.domain.notice.NotificationType.LIKE_IN_COMMENT_NOTIFICATION; +import static life.offonoff.ab.domain.notification.NotificationType.LIKE_IN_COMMENT_NOTIFICATION; // TODO:수정대상 @Getter @NoArgsConstructor(access = AccessLevel.PROTECTED) diff --git a/src/main/java/life/offonoff/ab/domain/notice/Notification.java b/src/main/java/life/offonoff/ab/domain/notification/Notification.java similarity index 95% rename from src/main/java/life/offonoff/ab/domain/notice/Notification.java rename to src/main/java/life/offonoff/ab/domain/notification/Notification.java index 21db5549..eece565b 100644 --- a/src/main/java/life/offonoff/ab/domain/notice/Notification.java +++ b/src/main/java/life/offonoff/ab/domain/notification/Notification.java @@ -1,4 +1,4 @@ -package life.offonoff.ab.domain.notice; +package life.offonoff.ab.domain.notification; import jakarta.persistence.*; import life.offonoff.ab.domain.BaseEntity; diff --git a/src/main/java/life/offonoff/ab/domain/notice/NotificationType.java b/src/main/java/life/offonoff/ab/domain/notification/NotificationType.java similarity index 89% rename from src/main/java/life/offonoff/ab/domain/notice/NotificationType.java rename to src/main/java/life/offonoff/ab/domain/notification/NotificationType.java index 0bbbfdce..54cac474 100644 --- a/src/main/java/life/offonoff/ab/domain/notice/NotificationType.java +++ b/src/main/java/life/offonoff/ab/domain/notification/NotificationType.java @@ -1,4 +1,4 @@ -package life.offonoff.ab.domain.notice; +package life.offonoff.ab.domain.notification; public class NotificationType { public static final String DEFAULT = "DEFAULT"; diff --git a/src/main/java/life/offonoff/ab/domain/notice/VoteCountOnTopicNotification.java b/src/main/java/life/offonoff/ab/domain/notification/VoteCountOnTopicNotification.java similarity index 83% rename from src/main/java/life/offonoff/ab/domain/notice/VoteCountOnTopicNotification.java rename to src/main/java/life/offonoff/ab/domain/notification/VoteCountOnTopicNotification.java index bbcb4729..bd7f2976 100644 --- a/src/main/java/life/offonoff/ab/domain/notice/VoteCountOnTopicNotification.java +++ b/src/main/java/life/offonoff/ab/domain/notification/VoteCountOnTopicNotification.java @@ -1,4 +1,4 @@ -package life.offonoff.ab.domain.notice; +package life.offonoff.ab.domain.notification; import jakarta.persistence.DiscriminatorValue; import jakarta.persistence.Entity; @@ -6,12 +6,11 @@ import jakarta.persistence.ManyToOne; import life.offonoff.ab.domain.member.Member; import life.offonoff.ab.domain.topic.Topic; -import life.offonoff.ab.domain.vote.VoteResult; import lombok.AccessLevel; import lombok.Getter; import lombok.NoArgsConstructor; -import static life.offonoff.ab.domain.notice.NotificationType.VOTE_COUNT_ON_TOPIC_NOTIFICATION; +import static life.offonoff.ab.domain.notification.NotificationType.VOTE_COUNT_ON_TOPIC_NOTIFICATION; @Getter @NoArgsConstructor(access = AccessLevel.PROTECTED) diff --git a/src/main/java/life/offonoff/ab/domain/notice/VoteResultNotification.java b/src/main/java/life/offonoff/ab/domain/notification/VoteResultNotification.java similarity index 85% rename from src/main/java/life/offonoff/ab/domain/notice/VoteResultNotification.java rename to src/main/java/life/offonoff/ab/domain/notification/VoteResultNotification.java index a501d5e0..297fab3a 100644 --- a/src/main/java/life/offonoff/ab/domain/notice/VoteResultNotification.java +++ b/src/main/java/life/offonoff/ab/domain/notification/VoteResultNotification.java @@ -1,4 +1,4 @@ -package life.offonoff.ab.domain.notice; +package life.offonoff.ab.domain.notification; import jakarta.persistence.*; import life.offonoff.ab.domain.member.Member; @@ -7,7 +7,7 @@ import lombok.Getter; import lombok.NoArgsConstructor; -import static life.offonoff.ab.domain.notice.NotificationType.*; +import static life.offonoff.ab.domain.notification.NotificationType.*; @Getter @NoArgsConstructor(access = AccessLevel.PROTECTED) diff --git a/src/main/java/life/offonoff/ab/repository/notice/NotificationJdbcRepository.java b/src/main/java/life/offonoff/ab/repository/notice/NotificationJdbcRepository.java index b57dc22a..41425bb1 100644 --- a/src/main/java/life/offonoff/ab/repository/notice/NotificationJdbcRepository.java +++ b/src/main/java/life/offonoff/ab/repository/notice/NotificationJdbcRepository.java @@ -1,6 +1,6 @@ package life.offonoff.ab.repository.notice; -import life.offonoff.ab.domain.notice.VoteResultNotification; +import life.offonoff.ab.domain.notification.VoteResultNotification; import org.springframework.jdbc.core.JdbcTemplate; import org.springframework.stereotype.Repository; @@ -9,7 +9,7 @@ import java.time.LocalDateTime; import java.util.List; -import static life.offonoff.ab.domain.notice.NotificationType.*; +import static life.offonoff.ab.domain.notification.NotificationType.*; @Repository public class NotificationJdbcRepository { diff --git a/src/main/java/life/offonoff/ab/repository/notice/NotificationRepository.java b/src/main/java/life/offonoff/ab/repository/notice/NotificationRepository.java index 64a96805..51a38e72 100644 --- a/src/main/java/life/offonoff/ab/repository/notice/NotificationRepository.java +++ b/src/main/java/life/offonoff/ab/repository/notice/NotificationRepository.java @@ -1,6 +1,6 @@ package life.offonoff.ab.repository.notice; -import life.offonoff.ab.domain.notice.Notification; +import life.offonoff.ab.domain.notification.Notification; import org.springframework.data.jpa.repository.JpaRepository; import java.util.List; diff --git a/src/main/java/life/offonoff/ab/repository/notice/NotificationRepositoryCustom.java b/src/main/java/life/offonoff/ab/repository/notice/NotificationRepositoryCustom.java index df91e39c..19396d87 100644 --- a/src/main/java/life/offonoff/ab/repository/notice/NotificationRepositoryCustom.java +++ b/src/main/java/life/offonoff/ab/repository/notice/NotificationRepositoryCustom.java @@ -1,6 +1,6 @@ package life.offonoff.ab.repository.notice; -import life.offonoff.ab.domain.notice.VoteResultNotification; +import life.offonoff.ab.domain.notification.VoteResultNotification; import java.util.List; diff --git a/src/main/java/life/offonoff/ab/repository/notice/NotificationRepositoryImpl.java b/src/main/java/life/offonoff/ab/repository/notice/NotificationRepositoryImpl.java index 58e8647d..96e0a6d7 100644 --- a/src/main/java/life/offonoff/ab/repository/notice/NotificationRepositoryImpl.java +++ b/src/main/java/life/offonoff/ab/repository/notice/NotificationRepositoryImpl.java @@ -1,6 +1,6 @@ package life.offonoff.ab.repository.notice; -import life.offonoff.ab.domain.notice.VoteResultNotification; +import life.offonoff.ab.domain.notification.VoteResultNotification; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Repository; diff --git a/src/main/java/life/offonoff/ab/web/NoticeController.java b/src/main/java/life/offonoff/ab/web/NotificationController.java similarity index 50% rename from src/main/java/life/offonoff/ab/web/NoticeController.java rename to src/main/java/life/offonoff/ab/web/NotificationController.java index a48b938a..027c35e5 100644 --- a/src/main/java/life/offonoff/ab/web/NoticeController.java +++ b/src/main/java/life/offonoff/ab/web/NotificationController.java @@ -1,8 +1,8 @@ package life.offonoff.ab.web; -import life.offonoff.ab.application.notice.NoticeService; +import life.offonoff.ab.application.notification.NotificationService; import life.offonoff.ab.web.common.aspect.auth.Authorized; -import life.offonoff.ab.web.response.notice.NoticeResponse; +import life.offonoff.ab.web.response.notification.NotificationResponse; import lombok.RequiredArgsConstructor; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.GetMapping; @@ -13,13 +13,13 @@ @RequiredArgsConstructor @RestController -@RequestMapping("/notices") -public class NoticeController { +@RequestMapping("/notifications") +public class NotificationController { - private final NoticeService noticeService; + private final NotificationService notificationService; @GetMapping("") - public ResponseEntity> getNotices(@Authorized Long memberId) { - return ResponseEntity.ok(noticeService.findAllByReceiverId(memberId)); + public ResponseEntity> getNotifications(@Authorized Long memberId) { + return ResponseEntity.ok(notificationService.findAllByReceiverId(memberId)); } } diff --git a/src/main/java/life/offonoff/ab/web/response/notice/NoticeResponse.java b/src/main/java/life/offonoff/ab/web/response/notice/NoticeResponse.java deleted file mode 100644 index 5e014ca2..00000000 --- a/src/main/java/life/offonoff/ab/web/response/notice/NoticeResponse.java +++ /dev/null @@ -1,26 +0,0 @@ -package life.offonoff.ab.web.response.notice; - -import life.offonoff.ab.domain.notice.Notification; -import life.offonoff.ab.web.response.notice.message.NoticeMessage; -import life.offonoff.ab.web.response.notice.message.NoticeMessageFactory; -import lombok.Getter; - -@Getter -public class NoticeResponse { - - private String type; - private Boolean checked; - private NoticeMessage message; - - public NoticeResponse(Notification notification) { - this.type = notification.getType(); - this.checked = notification.getChecked(); - this.message = NoticeMessageFactory.createNoticeMessage(notification); - } - - public NoticeResponse(String type, Boolean checked, NoticeMessage message) { - this.type = type; - this.checked = checked; - this.message = message; - } -} diff --git a/src/main/java/life/offonoff/ab/web/response/notice/message/DefaultNoticeMessage.java b/src/main/java/life/offonoff/ab/web/response/notice/message/DefaultNoticeMessage.java deleted file mode 100644 index a7810a08..00000000 --- a/src/main/java/life/offonoff/ab/web/response/notice/message/DefaultNoticeMessage.java +++ /dev/null @@ -1,13 +0,0 @@ -package life.offonoff.ab.web.response.notice.message; - -import life.offonoff.ab.domain.notice.DefaultNotification; -import life.offonoff.ab.web.response.notice.message.NoticeMessage; -import lombok.Getter; - -import static life.offonoff.ab.domain.notice.NotificationType.DEFAULT; - -public class DefaultNoticeMessage extends NoticeMessage { - public DefaultNoticeMessage(DefaultNotification notification) { - super(notification.getTitle(), notification.getContent()); - } -} diff --git a/src/main/java/life/offonoff/ab/web/response/notice/message/NoticeMessageFactory.java b/src/main/java/life/offonoff/ab/web/response/notice/message/NoticeMessageFactory.java deleted file mode 100644 index da370a4f..00000000 --- a/src/main/java/life/offonoff/ab/web/response/notice/message/NoticeMessageFactory.java +++ /dev/null @@ -1,25 +0,0 @@ -package life.offonoff.ab.web.response.notice.message; - -import life.offonoff.ab.domain.notice.DefaultNotification; -import life.offonoff.ab.domain.notice.Notification; -import life.offonoff.ab.domain.notice.VoteCountOnTopicNotification; -import life.offonoff.ab.domain.notice.VoteResultNotification; - -public class NoticeMessageFactory { - - public static NoticeMessage createNoticeMessage(Notification notification) { - if (notification instanceof DefaultNotification) { - return new DefaultNoticeMessage((DefaultNotification) notification); - } - - if (notification instanceof VoteResultNotification) { - return new VoteResultNoticeMessage((VoteResultNotification) notification); - } - - if (notification instanceof VoteCountOnTopicNotification) { - return new VoteCountOnTopicNoticeMessage((VoteCountOnTopicNotification) notification); - } - - throw new RuntimeException(); - } -} diff --git a/src/main/java/life/offonoff/ab/web/response/notice/message/VoteCountOnTopicNoticeMessage.java b/src/main/java/life/offonoff/ab/web/response/notice/message/VoteCountOnTopicNoticeMessage.java deleted file mode 100644 index 2b0363aa..00000000 --- a/src/main/java/life/offonoff/ab/web/response/notice/message/VoteCountOnTopicNoticeMessage.java +++ /dev/null @@ -1,29 +0,0 @@ -package life.offonoff.ab.web.response.notice.message; - -import life.offonoff.ab.domain.notice.VoteCountOnTopicNotification; -import life.offonoff.ab.domain.topic.Topic; -import life.offonoff.ab.web.response.notice.message.NoticeMessage; -import life.offonoff.ab.web.response.notice.message.NoticeMessageTemplate; -import lombok.Getter; - -import static life.offonoff.ab.domain.notice.NotificationType.VOTE_COUNT_ON_TOPIC_NOTIFICATION; -import static life.offonoff.ab.web.response.notice.message.NoticeMessageTemplate.VOTE_COUNT_ON_TOPIC_TITLE; - -@Getter -public class VoteCountOnTopicNoticeMessage extends NoticeMessage { - - private Long topicId; - - public VoteCountOnTopicNoticeMessage(String title, String content, Long topicId) { - super(title, content); - this.topicId = topicId; - } - - public VoteCountOnTopicNoticeMessage(VoteCountOnTopicNotification notification) { - super(VOTE_COUNT_ON_TOPIC_TITLE.formatted(notification.getTopic().getVoteCount()), - notification.getTopic().getTitle()); - - this.topicId = notification.getTopic() - .getId(); - } -} diff --git a/src/main/java/life/offonoff/ab/web/response/notification/NotificationResponse.java b/src/main/java/life/offonoff/ab/web/response/notification/NotificationResponse.java new file mode 100644 index 00000000..10b1df06 --- /dev/null +++ b/src/main/java/life/offonoff/ab/web/response/notification/NotificationResponse.java @@ -0,0 +1,26 @@ +package life.offonoff.ab.web.response.notification; + +import life.offonoff.ab.domain.notification.Notification; +import life.offonoff.ab.web.response.notification.message.NotificationMessage; +import life.offonoff.ab.web.response.notification.message.NotificationMessageFactory; +import lombok.Getter; + +@Getter +public class NotificationResponse { + + private String type; + private Boolean checked; + private NotificationMessage message; + + public NotificationResponse(Notification notification) { + this.type = notification.getType(); + this.checked = notification.getChecked(); + this.message = NotificationMessageFactory.createNoticeMessage(notification); + } + + public NotificationResponse(String type, Boolean checked, NotificationMessage message) { + this.type = type; + this.checked = checked; + this.message = message; + } +} diff --git a/src/main/java/life/offonoff/ab/web/response/notification/message/DefaultNotificationMessage.java b/src/main/java/life/offonoff/ab/web/response/notification/message/DefaultNotificationMessage.java new file mode 100644 index 00000000..48727d9b --- /dev/null +++ b/src/main/java/life/offonoff/ab/web/response/notification/message/DefaultNotificationMessage.java @@ -0,0 +1,9 @@ +package life.offonoff.ab.web.response.notification.message; + +import life.offonoff.ab.domain.notification.DefaultNotification; + +public class DefaultNotificationMessage extends NotificationMessage { + public DefaultNotificationMessage(DefaultNotification notification) { + super(notification.getTitle(), notification.getContent()); + } +} diff --git a/src/main/java/life/offonoff/ab/web/response/notice/message/NoticeMessage.java b/src/main/java/life/offonoff/ab/web/response/notification/message/NotificationMessage.java similarity index 50% rename from src/main/java/life/offonoff/ab/web/response/notice/message/NoticeMessage.java rename to src/main/java/life/offonoff/ab/web/response/notification/message/NotificationMessage.java index 254dbed4..b6ff5c17 100644 --- a/src/main/java/life/offonoff/ab/web/response/notice/message/NoticeMessage.java +++ b/src/main/java/life/offonoff/ab/web/response/notification/message/NotificationMessage.java @@ -1,14 +1,14 @@ -package life.offonoff.ab.web.response.notice.message; +package life.offonoff.ab.web.response.notification.message; import lombok.Getter; @Getter -public abstract class NoticeMessage { +public abstract class NotificationMessage { private final String title; private final String content; - public NoticeMessage(String title, String content) { + public NotificationMessage(String title, String content) { this.title = title; this.content = content; } diff --git a/src/main/java/life/offonoff/ab/web/response/notification/message/NotificationMessageFactory.java b/src/main/java/life/offonoff/ab/web/response/notification/message/NotificationMessageFactory.java new file mode 100644 index 00000000..7602465e --- /dev/null +++ b/src/main/java/life/offonoff/ab/web/response/notification/message/NotificationMessageFactory.java @@ -0,0 +1,25 @@ +package life.offonoff.ab.web.response.notification.message; + +import life.offonoff.ab.domain.notification.DefaultNotification; +import life.offonoff.ab.domain.notification.Notification; +import life.offonoff.ab.domain.notification.VoteCountOnTopicNotification; +import life.offonoff.ab.domain.notification.VoteResultNotification; + +public class NotificationMessageFactory { + + public static NotificationMessage createNoticeMessage(Notification notification) { + if (notification instanceof DefaultNotification) { + return new DefaultNotificationMessage((DefaultNotification) notification); + } + + if (notification instanceof VoteResultNotification) { + return new VoteResultNotificationMessage((VoteResultNotification) notification); + } + + if (notification instanceof VoteCountOnTopicNotification) { + return new VoteCountOnTopicNotificationMessage((VoteCountOnTopicNotification) notification); + } + + throw new RuntimeException(); + } +} diff --git a/src/main/java/life/offonoff/ab/web/response/notice/message/NoticeMessageTemplate.java b/src/main/java/life/offonoff/ab/web/response/notification/message/NotificationMessageTemplate.java similarity index 83% rename from src/main/java/life/offonoff/ab/web/response/notice/message/NoticeMessageTemplate.java rename to src/main/java/life/offonoff/ab/web/response/notification/message/NotificationMessageTemplate.java index 32f921e6..aff7fc67 100644 --- a/src/main/java/life/offonoff/ab/web/response/notice/message/NoticeMessageTemplate.java +++ b/src/main/java/life/offonoff/ab/web/response/notification/message/NotificationMessageTemplate.java @@ -1,6 +1,6 @@ -package life.offonoff.ab.web.response.notice.message; +package life.offonoff.ab.web.response.notification.message; -public class NoticeMessageTemplate { +public class NotificationMessageTemplate { public static final String VOTE_RESULT_TITLE = "투표가 마감 되었어요.\n지금 바로 결과를 확인해보세요!"; public static final String VOTE_COUNT_ON_TOPIC_TITLE = "내가 만든 토픽의 투표수가\n%d을 돌파했어요!"; diff --git a/src/main/java/life/offonoff/ab/web/response/notification/message/VoteCountOnTopicNotificationMessage.java b/src/main/java/life/offonoff/ab/web/response/notification/message/VoteCountOnTopicNotificationMessage.java new file mode 100644 index 00000000..fa6f24a6 --- /dev/null +++ b/src/main/java/life/offonoff/ab/web/response/notification/message/VoteCountOnTopicNotificationMessage.java @@ -0,0 +1,25 @@ +package life.offonoff.ab.web.response.notification.message; + +import life.offonoff.ab.domain.notification.VoteCountOnTopicNotification; +import lombok.Getter; + +import static life.offonoff.ab.web.response.notification.message.NotificationMessageTemplate.VOTE_COUNT_ON_TOPIC_TITLE; + +@Getter +public class VoteCountOnTopicNotificationMessage extends NotificationMessage { + + private Long topicId; + + public VoteCountOnTopicNotificationMessage(String title, String content, Long topicId) { + super(title, content); + this.topicId = topicId; + } + + public VoteCountOnTopicNotificationMessage(VoteCountOnTopicNotification notification) { + super(VOTE_COUNT_ON_TOPIC_TITLE.formatted(notification.getTopic().getVoteCount()), + notification.getTopic().getTitle()); + + this.topicId = notification.getTopic() + .getId(); + } +} diff --git a/src/main/java/life/offonoff/ab/web/response/notice/message/VoteResultNoticeMessage.java b/src/main/java/life/offonoff/ab/web/response/notification/message/VoteResultNotificationMessage.java similarity index 50% rename from src/main/java/life/offonoff/ab/web/response/notice/message/VoteResultNoticeMessage.java rename to src/main/java/life/offonoff/ab/web/response/notification/message/VoteResultNotificationMessage.java index 07f8363e..b8eca8b1 100644 --- a/src/main/java/life/offonoff/ab/web/response/notice/message/VoteResultNoticeMessage.java +++ b/src/main/java/life/offonoff/ab/web/response/notification/message/VoteResultNotificationMessage.java @@ -1,21 +1,21 @@ -package life.offonoff.ab.web.response.notice.message; +package life.offonoff.ab.web.response.notification.message; -import life.offonoff.ab.domain.notice.VoteResultNotification; +import life.offonoff.ab.domain.notification.VoteResultNotification; import lombok.Getter; -import static life.offonoff.ab.web.response.notice.message.NoticeMessageTemplate.VOTE_RESULT_TITLE; +import static life.offonoff.ab.web.response.notification.message.NotificationMessageTemplate.VOTE_RESULT_TITLE; @Getter -public class VoteResultNoticeMessage extends NoticeMessage { +public class VoteResultNotificationMessage extends NotificationMessage { private Long topicId; - public VoteResultNoticeMessage(String content, Long topicId) { + public VoteResultNotificationMessage(String content, Long topicId) { super(VOTE_RESULT_TITLE, content); this.topicId = topicId; } - public VoteResultNoticeMessage(VoteResultNotification notification) { + public VoteResultNotificationMessage(VoteResultNotification notification) { super(VOTE_RESULT_TITLE, notification.getVoteResult() .getTopic() .getTitle()); diff --git a/src/test/java/life/offonoff/ab/application/notice/NoticeServiceIntegrationTest.java b/src/test/java/life/offonoff/ab/application/notification/NotificationServiceIntegrationTest.java similarity index 74% rename from src/test/java/life/offonoff/ab/application/notice/NoticeServiceIntegrationTest.java rename to src/test/java/life/offonoff/ab/application/notification/NotificationServiceIntegrationTest.java index 548cded5..e136aa85 100644 --- a/src/test/java/life/offonoff/ab/application/notice/NoticeServiceIntegrationTest.java +++ b/src/test/java/life/offonoff/ab/application/notification/NotificationServiceIntegrationTest.java @@ -1,11 +1,11 @@ -package life.offonoff.ab.application.notice; +package life.offonoff.ab.application.notification; import jakarta.persistence.EntityManager; import life.offonoff.ab.domain.TestEntityUtil; import life.offonoff.ab.domain.member.Member; import life.offonoff.ab.domain.topic.Topic; -import life.offonoff.ab.web.response.notice.NoticeResponse; -import life.offonoff.ab.web.response.notice.message.VoteCountOnTopicNoticeMessage; +import life.offonoff.ab.web.response.notification.NotificationResponse; +import life.offonoff.ab.web.response.notification.message.VoteCountOnTopicNotificationMessage; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; @@ -21,10 +21,10 @@ @Transactional @SpringBootTest @DisplayName("NoticeService 스프링 컨테이너 통합테스트") -public class NoticeServiceIntegrationTest { +public class NotificationServiceIntegrationTest { @Autowired - NoticeService noticeService; + NotificationService notificationService; @Value("${ab.notification.vote_on_topic.count_unit}") int voteCountUnit; @@ -42,7 +42,7 @@ void topic_voteCount_should_noticed() { .build().buildTopic(); // when - boolean shouldNotice = noticeService.shouldNoticeVoteCountForTopic(topic); + boolean shouldNotice = notificationService.shouldNoticeVoteCountForTopic(topic); // then assertThat(shouldNotice).isTrue(); @@ -61,12 +61,12 @@ void create_VoteCountOnTopicNotification() { .build().buildTopic(); em.persist(topic); - noticeService.noticeVoteCountOnTopic(topic); + notificationService.noticeVoteCountOnTopic(topic); // when - List responses = noticeService.findAllByReceiverId(author.getId()); + List responses = notificationService.findAllByReceiverId(author.getId()); // then - assertThat(responses.get(0).getMessage()).isInstanceOf(VoteCountOnTopicNoticeMessage.class); + assertThat(responses.get(0).getMessage()).isInstanceOf(VoteCountOnTopicNotificationMessage.class); } } diff --git a/src/test/java/life/offonoff/ab/application/notice/NoticeServiceTest.java b/src/test/java/life/offonoff/ab/application/notification/NotificationServiceTest.java similarity index 85% rename from src/test/java/life/offonoff/ab/application/notice/NoticeServiceTest.java rename to src/test/java/life/offonoff/ab/application/notification/NotificationServiceTest.java index 257aa6da..fae2c8c5 100644 --- a/src/test/java/life/offonoff/ab/application/notice/NoticeServiceTest.java +++ b/src/test/java/life/offonoff/ab/application/notification/NotificationServiceTest.java @@ -1,12 +1,12 @@ -package life.offonoff.ab.application.notice; +package life.offonoff.ab.application.notification; import life.offonoff.ab.domain.member.Member; -import life.offonoff.ab.domain.notice.DefaultNotification; +import life.offonoff.ab.domain.notification.DefaultNotification; import life.offonoff.ab.domain.topic.Topic; import life.offonoff.ab.domain.vote.VoteResult; import life.offonoff.ab.repository.member.MemberRepository; import life.offonoff.ab.repository.notice.NotificationRepository; -import life.offonoff.ab.web.response.notice.NoticeResponse; +import life.offonoff.ab.web.response.notification.NotificationResponse; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; @@ -22,10 +22,10 @@ import static org.mockito.Mockito.*; @ExtendWith(MockitoExtension.class) -class NoticeServiceTest { +class NotificationServiceTest { @InjectMocks - NoticeService noticeService; + NotificationService notificationService; @Mock MemberRepository memberRepository; @Mock @@ -52,7 +52,7 @@ void notice_VoteResult_to_voter() { when(memberRepository.findAllListeningVoteResultAndVotedTopicId(anyLong())).thenReturn(voteMembers); // when - noticeService.noticeVoteResult(result); + notificationService.noticeVoteResult(result); // then assertThat(voter.getNotifications().size()).isGreaterThan(0); @@ -78,7 +78,7 @@ void notice_VoteResult_to_author() { when(memberRepository.findAllListeningVoteResultAndVotedTopicId(anyLong())).thenReturn(Collections.emptyList()); // when - noticeService.noticeVoteResult(result); + notificationService.noticeVoteResult(result); // then assertThat(author.getNotifications().size()).isGreaterThan(0); @@ -96,7 +96,7 @@ void find_NoticeResponses() { .thenReturn(List.of(notification)); // when - List responses = noticeService.findAllByReceiverId(receiver.getId()); + List responses = notificationService.findAllByReceiverId(receiver.getId()); // then assertThat(responses.size()).isGreaterThan(0); diff --git a/src/test/java/life/offonoff/ab/application/service/event/topic/TopicEventHandlerTest.java b/src/test/java/life/offonoff/ab/application/service/event/topic/TopicEventHandlerTest.java index 293fbe68..ab1c9435 100644 --- a/src/test/java/life/offonoff/ab/application/service/event/topic/TopicEventHandlerTest.java +++ b/src/test/java/life/offonoff/ab/application/service/event/topic/TopicEventHandlerTest.java @@ -1,8 +1,7 @@ package life.offonoff.ab.application.service.event.topic; import life.offonoff.ab.application.event.topic.*; -import life.offonoff.ab.application.notice.NoticeService; -import life.offonoff.ab.domain.member.Member; +import life.offonoff.ab.application.notification.NotificationService; import life.offonoff.ab.domain.topic.Topic; import life.offonoff.ab.domain.topic.choice.ChoiceOption; import life.offonoff.ab.domain.vote.Vote; @@ -22,7 +21,7 @@ class TopicEventHandlerTest { @Autowired private TopicEventHandler topicEventHandler; @MockBean - private NoticeService noticeService; + private NotificationService notificationService; @Test @DisplayName("Voting End 시에 Notice Service 호출") @@ -34,13 +33,13 @@ void invoke_noticeService_when_voting_ended() { VoteResult result = new VoteResult(); result.setTopic(topic); - doNothing().when(noticeService).noticeVoteResult(any(VoteResult.class)); + doNothing().when(notificationService).noticeVoteResult(any(VoteResult.class)); // when topicEventHandler.voteClosed(new VoteClosedEvent(topic, result)); // then - verify(noticeService).noticeVoteResult(any(VoteResult.class)); + verify(notificationService).noticeVoteResult(any(VoteResult.class)); } @Test @@ -49,13 +48,13 @@ void noticeVoteCount_when_shouldNoticeVoteCount() { // given Vote vote = createVote(ChoiceOption.CHOICE_A); - when(noticeService.shouldNoticeVoteCountForTopic(any())) + when(notificationService.shouldNoticeVoteCountForTopic(any())) .thenReturn(true); // when topicEventHandler.voted(new VotedEvent(vote)); // then - verify(noticeService).noticeVoteCountOnTopic(any()); + verify(notificationService).noticeVoteCountOnTopic(any()); } } \ No newline at end of file diff --git a/src/test/java/life/offonoff/ab/repository/notice/NotificationRepositoryTest.java b/src/test/java/life/offonoff/ab/repository/notice/NotificationRepositoryTest.java index 650d25dc..50fe8c17 100644 --- a/src/test/java/life/offonoff/ab/repository/notice/NotificationRepositoryTest.java +++ b/src/test/java/life/offonoff/ab/repository/notice/NotificationRepositoryTest.java @@ -4,11 +4,8 @@ import life.offonoff.ab.configuration.TestJPAConfig; import life.offonoff.ab.domain.TestEntityUtil.TestMember; import life.offonoff.ab.domain.member.Member; -import life.offonoff.ab.domain.notice.DefaultNotification; -import life.offonoff.ab.domain.notice.Notification; -import life.offonoff.ab.domain.notice.VoteCountOnTopicNotification; -import life.offonoff.ab.domain.notice.VoteResultNotification; -import life.offonoff.ab.web.response.notice.NoticeResponse; +import life.offonoff.ab.domain.notification.DefaultNotification; +import life.offonoff.ab.domain.notification.Notification; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest; @@ -16,10 +13,7 @@ import java.util.List; -import static life.offonoff.ab.domain.TestEntityUtil.createRandomMember; import static org.assertj.core.api.Assertions.assertThat; -import static org.mockito.ArgumentMatchers.anyLong; -import static org.mockito.Mockito.when; @DataJpaTest @Import(TestJPAConfig.class) diff --git a/src/test/java/life/offonoff/ab/web/NoticeControllerTest.java b/src/test/java/life/offonoff/ab/web/NotificationControllerTest.java similarity index 59% rename from src/test/java/life/offonoff/ab/web/NoticeControllerTest.java rename to src/test/java/life/offonoff/ab/web/NotificationControllerTest.java index b823c456..700d37f8 100644 --- a/src/test/java/life/offonoff/ab/web/NoticeControllerTest.java +++ b/src/test/java/life/offonoff/ab/web/NotificationControllerTest.java @@ -1,15 +1,13 @@ package life.offonoff.ab.web; -import life.offonoff.ab.application.notice.NoticeService; +import life.offonoff.ab.application.notification.NotificationService; import life.offonoff.ab.config.WebConfig; -import life.offonoff.ab.domain.notice.NotificationType; import life.offonoff.ab.restdocs.RestDocsTest; import life.offonoff.ab.util.token.JwtProvider; import life.offonoff.ab.web.common.aspect.auth.AuthorizedArgumentResolver; -import life.offonoff.ab.web.response.notice.NoticeResponse; -import life.offonoff.ab.web.response.notice.message.NoticeMessageTemplate; -import life.offonoff.ab.web.response.notice.message.VoteCountOnTopicNoticeMessage; -import life.offonoff.ab.web.response.notice.message.VoteResultNoticeMessage; +import life.offonoff.ab.web.response.notification.NotificationResponse; +import life.offonoff.ab.web.response.notification.message.VoteCountOnTopicNotificationMessage; +import life.offonoff.ab.web.response.notification.message.VoteResultNotificationMessage; import org.junit.jupiter.api.Test; import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest; import org.springframework.boot.test.mock.mockito.MockBean; @@ -18,38 +16,38 @@ import java.util.List; -import static life.offonoff.ab.domain.notice.NotificationType.VOTE_COUNT_ON_TOPIC_NOTIFICATION; -import static life.offonoff.ab.web.response.notice.message.NoticeMessageTemplate.VOTE_COUNT_ON_TOPIC_TITLE; +import static life.offonoff.ab.domain.notification.NotificationType.VOTE_COUNT_ON_TOPIC_NOTIFICATION; +import static life.offonoff.ab.web.response.notification.message.NotificationMessageTemplate.VOTE_COUNT_ON_TOPIC_TITLE; import static org.mockito.ArgumentMatchers.nullable; import static org.mockito.Mockito.when; import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; -@WebMvcTest(value = NoticeController.class, +@WebMvcTest(value = NotificationController.class, excludeFilters = { @ComponentScan.Filter(type = FilterType.ASSIGNABLE_TYPE, classes = WebConfig.class), @ComponentScan.Filter(type = FilterType.ASSIGNABLE_TYPE, classes = JwtProvider.class), @ComponentScan.Filter(type = FilterType.ASSIGNABLE_TYPE, classes = AuthorizedArgumentResolver.class) }) -class NoticeControllerTest extends RestDocsTest { +class NotificationControllerTest extends RestDocsTest { @MockBean - NoticeService noticeService; + NotificationService notificationService; @Test void get_members_notifications() throws Exception { // given - NoticeResponse voteResultResponse = new NoticeResponse( + NotificationResponse voteResultResponse = new NotificationResponse( VOTE_COUNT_ON_TOPIC_NOTIFICATION, false, - new VoteResultNoticeMessage("test_title1", 1L)); + new VoteResultNotificationMessage("test_title1", 1L)); - NoticeResponse voteCountResponse = new NoticeResponse( + NotificationResponse voteCountResponse = new NotificationResponse( VOTE_COUNT_ON_TOPIC_NOTIFICATION, false, - new VoteCountOnTopicNoticeMessage(VOTE_COUNT_ON_TOPIC_TITLE.formatted(100), "test_title2", 2L)); + new VoteCountOnTopicNotificationMessage(VOTE_COUNT_ON_TOPIC_TITLE.formatted(100), "test_title2", 2L)); - when(noticeService.findAllByReceiverId(nullable(Long.class))) + when(notificationService.findAllByReceiverId(nullable(Long.class))) .thenReturn(List.of(voteResultResponse, voteCountResponse)); // then @@ -59,6 +57,6 @@ void get_members_notifications() throws Exception { } private static class NoticeUri { - public static String BASE = "/notices"; + public static String BASE = "/notifications"; } } \ No newline at end of file diff --git a/src/test/java/life/offonoff/ab/web/response/notice/NoticeMessageFactoryTest.java b/src/test/java/life/offonoff/ab/web/response/notice/NoticeMessageFactoryTest.java deleted file mode 100644 index ea98affc..00000000 --- a/src/test/java/life/offonoff/ab/web/response/notice/NoticeMessageFactoryTest.java +++ /dev/null @@ -1,31 +0,0 @@ -package life.offonoff.ab.web.response.notice; - -import life.offonoff.ab.domain.member.Member; -import life.offonoff.ab.domain.notice.VoteCountOnTopicNotification; -import life.offonoff.ab.domain.topic.Topic; -import life.offonoff.ab.web.response.notice.message.NoticeMessage; -import life.offonoff.ab.web.response.notice.message.NoticeMessageFactory; -import life.offonoff.ab.web.response.notice.message.VoteCountOnTopicNoticeMessage; -import org.junit.jupiter.api.Test; - -import static life.offonoff.ab.domain.TestEntityUtil.createRandomMember; -import static life.offonoff.ab.domain.TestEntityUtil.createRandomTopic; -import static org.assertj.core.api.Assertions.*; - -class NoticeMessageFactoryTest { - - @Test - void create_NoticeMessage() { - // given - Topic topic = createRandomTopic(); - Member member = createRandomMember(); - - VoteCountOnTopicNotification notification = new VoteCountOnTopicNotification(member, topic); - - // when - NoticeMessage noticeMessage = NoticeMessageFactory.createNoticeMessage(notification); - - // then - assertThat(noticeMessage).isInstanceOf(VoteCountOnTopicNoticeMessage.class); - } -} \ No newline at end of file diff --git a/src/test/java/life/offonoff/ab/web/response/notification/NotificationMessageFactoryTest.java b/src/test/java/life/offonoff/ab/web/response/notification/NotificationMessageFactoryTest.java new file mode 100644 index 00000000..286e1999 --- /dev/null +++ b/src/test/java/life/offonoff/ab/web/response/notification/NotificationMessageFactoryTest.java @@ -0,0 +1,31 @@ +package life.offonoff.ab.web.response.notification; + +import life.offonoff.ab.domain.member.Member; +import life.offonoff.ab.domain.notification.VoteCountOnTopicNotification; +import life.offonoff.ab.domain.topic.Topic; +import life.offonoff.ab.web.response.notification.message.NotificationMessage; +import life.offonoff.ab.web.response.notification.message.NotificationMessageFactory; +import life.offonoff.ab.web.response.notification.message.VoteCountOnTopicNotificationMessage; +import org.junit.jupiter.api.Test; + +import static life.offonoff.ab.domain.TestEntityUtil.createRandomMember; +import static life.offonoff.ab.domain.TestEntityUtil.createRandomTopic; +import static org.assertj.core.api.Assertions.*; + +class NotificationMessageFactoryTest { + + @Test + void create_NoticeMessage() { + // given + Topic topic = createRandomTopic(); + Member member = createRandomMember(); + + VoteCountOnTopicNotification notification = new VoteCountOnTopicNotification(member, topic); + + // when + NotificationMessage notificationMessage = NotificationMessageFactory.createNoticeMessage(notification); + + // then + assertThat(notificationMessage).isInstanceOf(VoteCountOnTopicNotificationMessage.class); + } +} \ No newline at end of file