Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -11,21 +11,21 @@

public class NotificationConverter {

public static List<NotificationDTO> fromReplyToNotification(List<Reply> replyList) {
List<NotificationDTO> result = new ArrayList<>();
for (Reply reply : replyList) {
NotificationDTO dto = NotificationDTO.builder()
.id(reply.getId())
.targetKey(reply.getDaily().getDate())
.notificationType(NotificationType.REPLY)
.sender(reply.getSender().getNickname())
.elapsedTime(DateUtil.getElapsedTime(reply.getCreatedAt()))
.createdAt(reply.getCreatedAt().toString())
.build();
result.add(dto);
}
return result;
}
// public static List<NotificationDTO> fromReplyToNotification(List<Reply> replyList) {
// List<NotificationDTO> result = new ArrayList<>();
// for (Reply reply : replyList) {
// NotificationDTO dto = NotificationDTO.builder()
// .id(reply.getId())
// .targetKey(reply.getDaily().getDate())
// .notificationType(NotificationType.REPLY)
// .sender(reply.getSender().getNickname())
// .elapsedTime(DateUtil.getElapsedTime(reply.getCreatedAt()))
// .createdAt(reply.getCreatedAt().toString())
// .build();
// result.add(dto);
// }
// return result;
// }

public static List<NotificationDTO> toNotificationResponse(List<Notification> notificationList) {
List<NotificationDTO> result = new ArrayList<>();
Expand Down
10 changes: 4 additions & 6 deletions src/main/java/foregg/foreggserver/domain/Reply.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,10 @@ public class Reply extends BaseEntity {
@JoinColumn(name = "daily_id")
private Daily daily;

@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "receiver")
private User receiver;
@Column(nullable = false)
private Long receiverId;

@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "sender")
private User sender;
@Column(nullable = false)
private Long senderId;

}
3 changes: 0 additions & 3 deletions src/main/java/foregg/foreggserver/domain/User.java
Original file line number Diff line number Diff line change
Expand Up @@ -92,9 +92,6 @@ public class User extends BaseEntity implements UserDetails {
@OneToMany(mappedBy = "user", cascade = CascadeType.ALL, orphanRemoval = true)
private List<LedgerMemo> ledgerMemos;

@OneToMany(mappedBy = "receiver", cascade = CascadeType.ALL, orphanRemoval = true)
private List<Reply> replies;

// Jwt 전용 설정 (UserDetails 인터페이스 구현)

@ElementCollection(fetch = FetchType.EAGER) //roles 컬렉션
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@

public interface ReplyRepository extends JpaRepository<Reply, Long> {

List<Reply> findByReceiver(User user);
List<Reply> findByReceiverId(Long receiverId);

}
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ public void cheer(Long receiverId, NotificationType type, Long challengeId) {
throw new ChallengeHandler(NO_MORE_THAN_THIRD_TIME);
}

if (notificationRepository.findBySenderAndReceiverAndDateAndNotificationType(sender.getChallengeName(), receiver, LocalDate.now().toString(), type) != null) {
if (notificationRepository.findBySenderAndReceiverAndDateAndNotificationTypeAndTargetId(sender.getChallengeName(), receiver, LocalDate.now().toString(), type, challengeId) != null) {
throw new ChallengeHandler(ALREADY_SEND_CHEER);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,8 @@ public void reply(DailyReplyRequestDTO dto) {
.content(dto.getContent())
.replyEmojiType(dto.getReplyEmojiType())
.daily(daily)
.receiver(wife)
.sender(userQueryService.getUser())
.receiverId(wife.getId())
.senderId(userQueryService.getUser().getId())
.build();
replyRepository.save(reply);
daily.setReply(reply);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,15 @@
import foregg.foreggserver.domain.Notification;
import foregg.foreggserver.domain.Reply;
import foregg.foreggserver.domain.User;
import foregg.foreggserver.domain.enums.NotificationType;
import foregg.foreggserver.dto.notificationDTO.NotificationResponseDTO;
import foregg.foreggserver.dto.notificationDTO.NotificationResponseDTO.NotificationDTO;
import foregg.foreggserver.jwt.SecurityUtil;
import foregg.foreggserver.repository.NotificationRepository;
import foregg.foreggserver.repository.ReplyRepository;
import foregg.foreggserver.repository.UserRepository;
import foregg.foreggserver.service.userService.UserQueryService;
import foregg.foreggserver.util.DateUtil;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
Expand All @@ -29,6 +32,7 @@
public class NotificationQueryService {

private final ReplyRepository replyRepository;
private final UserRepository userRepository;
private final UserQueryService userQueryService;
private final NotificationRepository notificationRepository;

Expand All @@ -39,7 +43,7 @@ public NotificationResponseDTO getNotificationHistory(int page) {
User user = userQueryService.getUser();

// 필터링된 Reply 리스트
List<Reply> replyList = replyRepository.findByReceiver(user).stream()
List<Reply> replyList = replyRepository.findByReceiverId(user.getId()).stream()
.filter(reply -> reply.getCreatedAt().isAfter(thresholdDate))
.toList();

Expand All @@ -49,7 +53,7 @@ public NotificationResponseDTO getNotificationHistory(int page) {
.toList();

// 결과 생성
result.addAll(NotificationConverter.fromReplyToNotification(replyList));
result.addAll(this.fromReplyToNotification(replyList));
result.addAll(NotificationConverter.toNotificationResponse(notificationList));

// createdAt 순서로 정렬
Expand Down Expand Up @@ -77,5 +81,21 @@ public NotificationResponseDTO getNotificationHistory(int page) {
.build();
}

private List<NotificationDTO> fromReplyToNotification(List<Reply> replyList) {
List<NotificationDTO> result = new ArrayList<>();
for (Reply reply : replyList) {
NotificationDTO dto = NotificationDTO.builder()
.id(reply.getId())
.targetKey(reply.getDaily().getDate())
.notificationType(NotificationType.REPLY)
.sender(userRepository.findById(reply.getSenderId()).get().getNickname())
.elapsedTime(DateUtil.getElapsedTime(reply.getCreatedAt()))
.createdAt(reply.getCreatedAt().toString())
.build();
result.add(dto);
}
return result;
}


}