Skip to content

Commit

Permalink
Merge pull request #175 from team-offonoff/nofification
Browse files Browse the repository at this point in the history
알림 메시지 내용을 서버에서 제작한다.
  • Loading branch information
60jong authored Feb 26, 2024
2 parents 4ed2cc7 + 4f8f9d0 commit 5547d06
Show file tree
Hide file tree
Showing 37 changed files with 344 additions and 320 deletions.
2 changes: 1 addition & 1 deletion server-config
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -23,7 +23,7 @@
public class TopicEventHandler {

private final VotingTopicService votingTopicService;
private final NoticeService noticeService;
private final NotificationService notificationService;

/**
* 투표 생성 이벤트 -> VotingTopicContainer에서 관리 추가
Expand All @@ -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());
}

/**
Expand All @@ -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);
}
}
}
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
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.NoticeResponseFactory;
import life.offonoff.ab.web.response.notification.NotificationResponse;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

Expand All @@ -20,9 +20,10 @@
@Slf4j
@RequiredArgsConstructor
@Service
public class NoticeService {
public class NotificationService {

public static final int VOTE_COUNT_MODULO = 100;
@Value("${ab.notification.vote_on_topic.count_unit}")
public int voteCountUnit;

private final MemberRepository memberRepository;
private final NotificationRepository notificationRepository;
Expand Down Expand Up @@ -77,17 +78,17 @@ public void noticeVoteCountOnTopic(Topic topic) {
notificationRepository.save(notification);
}

public List<NoticeResponse> findAllByReceiverId(Long memberId) {
public List<NotificationResponse> findAllByReceiverId(Long memberId) {

return notificationRepository.findAllByReceiverIdOrderByCreatedAtDesc(memberId)
.stream()
.map(NoticeResponseFactory::createNoticeResponse)
.map(NotificationResponse::new)
.toList();
}

public boolean shouldNoticeVoteCountForTopic(Topic topic) {
// TODO : 투표 취소 후 다시 100단위를 넘었을 때 중복 알림 처리 && 추상화
return topic.getVoteCount() % VOTE_COUNT_MODULO == 0;
return topic.getVoteCount() % voteCountUnit == 0;
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/life/offonoff/ab/domain/member/Member.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
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)
@Entity
@DiscriminatorValue(COMMENT_ON_TOPIC_NOTIFICATION)
public class CommentOnTopicNotification extends Notification {
@Override
public String getType() {
return COMMENT_ON_TOPIC_NOTIFICATION;
}
}
Original file line number Diff line number Diff line change
@@ -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)
Expand All @@ -26,4 +24,9 @@ public DefaultNotification(Member receiver, String title, String content) {
this.title = title;
this.content = content;
}

@Override
public String getType() {
return DEFAULT;
}
}
Original file line number Diff line number Diff line change
@@ -1,20 +1,21 @@
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)
@Entity
@DiscriminatorValue(LIKE_IN_COMMENT_NOTIFICATION)
public class LikeInCommentNotification extends Notification {

@Override
public String getType() {
return LIKE_IN_COMMENT_NOTIFICATION;
}
}
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -34,4 +34,6 @@ public Notification(Member receiver) {
public void check() {
this.checked = true;
}

public abstract String getType();
}
Original file line number Diff line number Diff line change
@@ -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";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
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.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)
Expand All @@ -29,4 +28,9 @@ public VoteCountOnTopicNotification(Member receiver, Topic topic) {
this.topic = topic;
this.totalVoteCount = topic.getVoteCount();
}

@Override
public String getType() {
return VOTE_COUNT_ON_TOPIC_NOTIFICATION;
}
}
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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)
Expand All @@ -22,4 +22,9 @@ public VoteResultNotification(Member member, VoteResult voteResult) {
super(member);
this.voteResult = voteResult;
}

@Override
public String getType() {
return VOTE_RESULT_NOTIFICATION;
}
}
Original file line number Diff line number Diff line change
@@ -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;

Expand All @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
Original file line number Diff line number Diff line change
@@ -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;

Expand Down
Original file line number Diff line number Diff line change
@@ -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;

Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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<List<NoticeResponse>> getNotices(@Authorized Long memberId) {
return ResponseEntity.ok(noticeService.findAllByReceiverId(memberId));
public ResponseEntity<List<NotificationResponse>> getNotifications(@Authorized Long memberId) {
return ResponseEntity.ok(notificationService.findAllByReceiverId(memberId));
}
}

This file was deleted.

This file was deleted.

Loading

0 comments on commit 5547d06

Please sign in to comment.