-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: #173 질문 생성/종료 원격 알림 구현 및 알림 엔티티 구성방식 변경
- Loading branch information
1 parent
519bfaa
commit 8158f70
Showing
17 changed files
with
206 additions
and
47 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
77 changes: 66 additions & 11 deletions
77
src/main/java/com/server/capple/domain/notifiaction/mapper/NotificationMapper.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,83 @@ | ||
package com.server.capple.domain.notifiaction.mapper; | ||
|
||
import com.server.capple.config.apns.dto.ApnsClientRequest; | ||
import com.server.capple.domain.board.entity.Board; | ||
import com.server.capple.domain.boardComment.entity.BoardComment; | ||
import com.server.capple.domain.notifiaction.dto.NotificationResponse.NotificationInfo; | ||
import com.server.capple.domain.notifiaction.entity.Notification; | ||
import com.server.capple.domain.notifiaction.entity.NotificationType; | ||
import com.server.capple.domain.question.entity.Question; | ||
import com.server.capple.global.common.SliceResponse; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.springframework.data.domain.Slice; | ||
import org.springframework.stereotype.Component; | ||
|
||
@Slf4j | ||
@Component | ||
public class NotificationMapper { | ||
public Notification toNotification(Long memberId, ApnsClientRequest.BoardNotificationBody boardNotificationBody) { | ||
public Notification toNotification(Long memberId, Board board, NotificationType type) { | ||
return Notification.builder() | ||
.memberId(memberId) | ||
.title(boardNotificationBody.getAps().getAlert().getTitle()) | ||
.content(boardNotificationBody.getAps().getAlert().getBody()) | ||
.boardId(boardNotificationBody.getBoardId()) | ||
.board(board) | ||
.type(type) | ||
.build(); | ||
} | ||
|
||
public Notification toNotification(Long memberId, ApnsClientRequest.BoardCommentNotificationBody boardCommentNotificationBody) { | ||
public Notification toNotification(Long memberId, Board board, BoardComment boardComment, NotificationType type) { | ||
return Notification.builder() | ||
.memberId(memberId) | ||
.title(boardCommentNotificationBody.getAps().getAlert().getTitle()) | ||
.subtitle(boardCommentNotificationBody.getAps().getAlert().getSubtitle()) | ||
.content(boardCommentNotificationBody.getAps().getAlert().getBody()) | ||
.boardId(boardCommentNotificationBody.getBoardId()) | ||
.boardCommentId(boardCommentNotificationBody.getBoardCommentId()) | ||
.board(board) | ||
.boardComment(boardComment) | ||
.type(type) | ||
.build(); | ||
} | ||
|
||
public Notification toNotification(Question question, NotificationType type) { | ||
return Notification.builder() | ||
.question(question) | ||
.type(type) | ||
.build(); | ||
} | ||
|
||
public SliceResponse<NotificationInfo> toNotificationInfoSlice(Slice<Notification> notification) { | ||
return SliceResponse.toSliceResponse(notification, notification.stream().map(this::toNotificationInfo).toList()); | ||
} | ||
|
||
private NotificationInfo toNotificationInfo(Notification notification) { | ||
return switch (notification.getType()) { | ||
case BOARD_HEART -> toBoardNotificationInfo(notification); | ||
case BOARD_COMMENT, BOARD_COMMENT_DUPLICATE, BOARD_COMMENT_HEART -> | ||
toBoardCommentNotificationInfo(notification); | ||
case TODAY_QUESTION_PUBLISHED, TODAY_QUESTION_CLOSED -> toQuestionNotificationInfo(notification); | ||
}; | ||
} | ||
|
||
private NotificationInfo toBoardNotificationInfo(Notification notification) { | ||
return NotificationInfo.builder() | ||
.title(notification.getType().getTitle()) | ||
.content(notification.getBoard().getContent()) | ||
.boardId(notification.getBoard().getId().toString()) | ||
.createdAt(notification.getCreatedAt()) | ||
.build(); | ||
} | ||
|
||
private NotificationInfo toBoardCommentNotificationInfo(Notification notification) { | ||
return NotificationInfo.builder() | ||
.title(notification.getType().getTitle()) | ||
.subtitle(notification.getBoardComment().getContent()) | ||
.content(notification.getBoard().getContent()) | ||
.boardId(notification.getBoard().getId().toString()) | ||
.boardCommentId(notification.getBoardComment().getId().toString()) | ||
.createdAt(notification.getCreatedAt()) | ||
.build(); | ||
} | ||
|
||
private NotificationInfo toQuestionNotificationInfo(Notification notification) { | ||
return NotificationInfo.builder() | ||
.title(notification.getType().getTitle()) | ||
.subtitle(notification.getType().getContent()) | ||
.content(notification.getQuestion().getContent()) | ||
.questionId(notification.getQuestion().getId().toString()) | ||
.createdAt(notification.getCreatedAt()) | ||
.build(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.