Skip to content

Commit

Permalink
Merge pull request #185 from FOREGG-DEV/dev
Browse files Browse the repository at this point in the history
♻️ refactor: 탈퇴 에러 처리
  • Loading branch information
DongJun1110 authored Dec 11, 2024
2 parents 20f5230 + 1abc19b commit 6f45989
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import foregg.foreggserver.domain.Notification;
import foregg.foreggserver.domain.Reply;
import foregg.foreggserver.domain.enums.NotificationType;
import foregg.foreggserver.dto.notificationDTO.NotificationResponseDTO;
import foregg.foreggserver.dto.notificationDTO.NotificationResponseDTO.NotificationDTO;
import foregg.foreggserver.util.DateUtil;

Expand Down Expand Up @@ -33,9 +32,9 @@ public static List<NotificationDTO> toNotificationResponse(List<Notification> no
for (Notification notification : notificationList) {
NotificationDTO dto = NotificationDTO.builder()
.id(notification.getId())
.targetKey(notification.getChallengeId().toString())
.targetKey(notification.getTargetId().toString())
.notificationType(notification.getNotificationType())
.sender(notification.getSender().getNickname())
.sender(notification.getSender())
.elapsedTime(DateUtil.getElapsedTime(notification.getCreatedAt()))
.createdAt(notification.getCreatedAt().toString())
.build();
Expand Down
7 changes: 3 additions & 4 deletions src/main/java/foregg/foreggserver/domain/Notification.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,8 @@ public class Notification extends BaseEntity {
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;

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

@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "receiver_id")
Expand All @@ -34,6 +33,6 @@ public class Notification extends BaseEntity {
private NotificationType notificationType;

@Column(nullable = false)
private Long challengeId;
private Long targetId;
}

Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,10 @@ public interface NotificationRepository extends JpaRepository<Notification, Long

List<Notification> findBySenderAndReceiverAndDate(User sender, User receiver, String date);

Notification findBySenderAndReceiverAndDateAndNotificationType(User sender, User receiver, String date, NotificationType notificationType);
Notification findBySenderAndReceiverAndDateAndNotificationType(String senderNickname, User receiver, String date, NotificationType notificationType);

List<Notification> findBySenderAndDateAndNotificationType(User sender, String date, NotificationType notificationType);
List<Notification> findBySenderAndDateAndNotificationType(String senderNickname, String date, NotificationType notificationType);

List<Notification> findByReceiver(User receiver);

}
Original file line number Diff line number Diff line change
Expand Up @@ -99,9 +99,9 @@ public List<ChallengeParticipantsDTO> getParticipants(Long challengeId, boolean
for (ChallengeParticipation cp : challengeParticipations) {
Notification notification;
if (isSuccess) {
notification = notificationRepository.findBySenderAndReceiverAndDateAndNotificationType(currentUser, cp.getUser(), LocalDate.now().toString(), NotificationType.CLAP);
notification = notificationRepository.findBySenderAndReceiverAndDateAndNotificationType(currentUser.getChallengeName(), cp.getUser(), LocalDate.now().toString(), NotificationType.CLAP);
} else {
notification = notificationRepository.findBySenderAndReceiverAndDateAndNotificationType(currentUser, cp.getUser(), LocalDate.now().toString(), NotificationType.SUPPORT);
notification = notificationRepository.findBySenderAndReceiverAndDateAndNotificationType(currentUser.getChallengeName(), cp.getUser(), LocalDate.now().toString(), NotificationType.SUPPORT);
}
if (notification == null) {
result.add(ChallengeConverter.toChallengeParticipantDTO(cp, false));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -173,16 +173,16 @@ public void cheer(Long receiverId, NotificationType type, Long challengeId) {

catchCheerException(challengeParticipation, type);

List<Notification> notificationList = notificationRepository.findBySenderAndDateAndNotificationType(sender, LocalDate.now().toString(), type);
List<Notification> notificationList = notificationRepository.findBySenderAndDateAndNotificationType(sender.getChallengeName(), LocalDate.now().toString(), type);
if (notificationList.size() >= 3) {
throw new ChallengeHandler(NO_MORE_THAN_THIRD_TIME);
}

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

Notification notification = notificationService.createNotification(type, receiver, sender, challengeId);
Notification notification = notificationService.createNotification(type, receiver, sender.getChallengeName(), challengeId);
notificationRepository.save(notification);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,19 @@
import foregg.foreggserver.converter.DailyConverter;
import foregg.foreggserver.domain.*;
import foregg.foreggserver.domain.Record;
import foregg.foreggserver.domain.enums.NotificationType;
import foregg.foreggserver.dto.dailyDTO.DailyRequestDTO;
import foregg.foreggserver.dto.dailyDTO.DailyRequestDTO.DailyReplyRequestDTO;
import foregg.foreggserver.dto.dailyDTO.SideEffectRequestDTO;
import foregg.foreggserver.dto.dailyDTO.SideEffectResponseDTO;
import foregg.foreggserver.jwt.SecurityUtil;
import foregg.foreggserver.repository.DailyRepository;
import foregg.foreggserver.repository.NotificationRepository;
import foregg.foreggserver.repository.ReplyRepository;
import foregg.foreggserver.repository.SideEffectRepository;
import foregg.foreggserver.service.fcmService.FcmService;
import foregg.foreggserver.service.myPageService.MyPageQueryService;
import foregg.foreggserver.service.notificationService.NotificationService;
import foregg.foreggserver.service.recordService.RecordQueryService;
import foregg.foreggserver.service.s3Service.S3Service;
import foregg.foreggserver.service.userService.UserQueryService;
Expand Down Expand Up @@ -48,6 +51,8 @@ public class DailyService {
private final MyPageQueryService myPageQueryService;
private final S3Service s3Service;
private final ReplyRepository replyRepository;
private final NotificationService notificationService;
private final NotificationRepository notificationRepository;

public void writeDaily(DailyRequestDTO dto, String imageUrl) {
User user = userQueryService.getUser();
Expand Down Expand Up @@ -94,6 +99,8 @@ public void reply(DailyReplyRequestDTO dto) {
.build();
replyRepository.save(reply);
daily.setReply(reply);
Notification notification = notificationService.createNotification(NotificationType.REPLY, wife, userQueryService.getUser().getNickname(), daily.getId());
notificationRepository.save(notification);
}

public void writeSideEffect(SideEffectRequestDTO dto) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -182,13 +182,13 @@ public void cancelScheduledTasks(Long recordId) {
}

//알림 만드는 로직
public Notification createNotification(NotificationType notificationType, User receiver, User sender, Long challengeId) {
public Notification createNotification(NotificationType notificationType, User receiver, String sender, Long targetId) {
return Notification.builder()
.notificationType(notificationType)
.receiver(receiver)
.sender(sender)
.date(LocalDate.now().toString())
.challengeId(challengeId)
.targetId(targetId)
.build();
}

Expand Down

0 comments on commit 6f45989

Please sign in to comment.