|
| 1 | +package com.chooz.notification.application; |
| 2 | + |
| 3 | +import com.chooz.common.exception.BadRequestException; |
| 4 | +import com.chooz.common.exception.ErrorCode; |
| 5 | +import com.chooz.notification.application.dto.CommentLikedContent; |
| 6 | +import com.chooz.notification.application.dto.TargetPostDto; |
| 7 | +import com.chooz.notification.application.dto.TargetUserDto; |
| 8 | +import com.chooz.notification.domain.NotificationQueryRepository; |
| 9 | +import lombok.RequiredArgsConstructor; |
| 10 | +import org.springframework.stereotype.Service; |
| 11 | + |
| 12 | +@Service |
| 13 | +@RequiredArgsConstructor |
| 14 | +public class NotificationContentAssembler { |
| 15 | + |
| 16 | + private final NotificationQueryRepository notificationQueryDslRepository; |
| 17 | + |
| 18 | + public CommentLikedContent forCommentLiked(Long commentId, Long likerId) { |
| 19 | + TargetUserDto targetUserDto = notificationQueryDslRepository.getUser(likerId) |
| 20 | + .orElseThrow(() -> new BadRequestException(ErrorCode.USER_NOT_FOUND)); |
| 21 | + TargetUserDto commentAuthorDto = notificationQueryDslRepository.getUserByCommentId(commentId) |
| 22 | + .orElseThrow(() -> new BadRequestException(ErrorCode.USER_NOT_FOUND)); |
| 23 | + TargetPostDto targetPostDto = notificationQueryDslRepository.getPost(commentId) |
| 24 | + .orElseThrow(() -> new BadRequestException(ErrorCode.POST_NOT_FOUND)); |
| 25 | + |
| 26 | + return new CommentLikedContent( |
| 27 | + targetUserDto.nickname(), |
| 28 | + targetUserDto.profileUrl(), |
| 29 | + targetPostDto.imageUrl(), |
| 30 | + commentAuthorDto.id(), |
| 31 | + commentAuthorDto.nickname() |
| 32 | + ); |
| 33 | + } |
| 34 | + |
| 35 | +// public NotificationContent forVoteClosed(Long postId) { |
| 36 | +// String title = postPort.getPostTitle(postId).orElse("투표 마감"); |
| 37 | +// String body = "참여한 투표가 마감되었어요."; |
| 38 | +// String thumbnail = postPort.getPostThumbnailUrl(postId).orElse(null); |
| 39 | +// return new NotificationContent(title, body, thumbnail); |
| 40 | +// } |
| 41 | +// |
| 42 | +// public NotificationContent forPostParticipated(Long postId, Long voterId) { |
| 43 | +// String title = postPort.getPostTitle(postId).orElse("새로운 참여"); |
| 44 | +// String voter = userPort.getDisplayName(voterId).orElse("누군가"); |
| 45 | +// String body = voter + "님이 내 투표에 참여했어요."; |
| 46 | +// String thumbnail = userPort.getAvatarUrl(voterId).orElse(null); |
| 47 | +// return new NotificationContent(title, body, thumbnail); |
| 48 | +// } |
| 49 | +} |
0 commit comments