From 5249b60397974ef57e5561e06075d2dde22d1e4e Mon Sep 17 00:00:00 2001 From: yunyun Date: Mon, 24 Jan 2022 20:16:55 +0900 Subject: [PATCH 01/16] =?UTF-8?q?refactor:=20follow=20entity=20=EC=82=AD?= =?UTF-8?q?=EC=A0=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../convertor/NotificationConvertor.java | 3 - .../entity/FollowNotification.java | 65 ------------------- .../FollowNotificationRepository.java | 4 -- .../LoudSpeakerNotificationRepository.java | 8 --- .../service/NotificationService.java | 4 -- 5 files changed, 84 deletions(-) delete mode 100644 src/main/java/org/slams/server/notification/entity/FollowNotification.java diff --git a/src/main/java/org/slams/server/notification/convertor/NotificationConvertor.java b/src/main/java/org/slams/server/notification/convertor/NotificationConvertor.java index ff645d33..d2c55543 100644 --- a/src/main/java/org/slams/server/notification/convertor/NotificationConvertor.java +++ b/src/main/java/org/slams/server/notification/convertor/NotificationConvertor.java @@ -5,13 +5,10 @@ import org.slams.server.notification.dto.response.FollowerInfo; import org.slams.server.notification.dto.response.LoudspeakerInfo; import org.slams.server.notification.dto.response.NotificationResponse; -import org.slams.server.notification.entity.FollowNotification; -import org.slams.server.notification.entity.LoudSpeakerNotification; import org.slams.server.notification.entity.NotificationIndex; import org.slams.server.notification.entity.NotificationType; import org.springframework.stereotype.Component; -import java.time.LocalDateTime; import java.util.*; import java.util.stream.Collectors; diff --git a/src/main/java/org/slams/server/notification/entity/FollowNotification.java b/src/main/java/org/slams/server/notification/entity/FollowNotification.java deleted file mode 100644 index 54d5fef5..00000000 --- a/src/main/java/org/slams/server/notification/entity/FollowNotification.java +++ /dev/null @@ -1,65 +0,0 @@ -package org.slams.server.notification.entity; - -import lombok.AccessLevel; -import lombok.Builder; -import lombok.Getter; -import lombok.NoArgsConstructor; -import org.slams.server.common.BaseEntity; -import org.slams.server.user.entity.User; - -import javax.persistence.*; - -import java.util.UUID; - -import static com.google.common.base.Preconditions.checkArgument; - -/** - * Created by yunyun on 2021/12/14. - */ - -@Getter -@NoArgsConstructor(access = AccessLevel.PROTECTED) -@Entity -@Table(name = "follow_notification") -public class FollowNotification { - @Id - @GeneratedValue(strategy = GenerationType.IDENTITY) - @Column(name="id") - private Long id; - - @ManyToOne(fetch = FetchType.EAGER) - @JoinColumn(name = "creator_id", nullable = false, referencedColumnName = "id") - private User creator; - - @Column - private Long userId; - - @Column - private Long checkCreatorId ; - - private FollowNotification(User creator, Long userId, Long checkCreatorId){ - checkArgument(creator != null, "creator 정보는 null을 허용하지 않습니다."); - checkArgument(userId != null, "userId 정보는 null을 허용하지 않습니다."); - - this.creator = creator; - this.userId = userId; - this.checkCreatorId = checkCreatorId; - } - - @Builder - public FollowNotification(Long id, User creator, Long userId, Long checkCreatorId){ - checkArgument(id != null, "id는 null을 허용하지 않습니다."); - checkArgument(creator != null, "creator 정보는 null을 허용하지 않습니다."); - checkArgument(userId != null, "userId 정보는 null을 허용하지 않습니다."); - - this.id = id; - this.creator = creator; - this.userId = userId; - this.checkCreatorId = checkCreatorId; - } - - public static FollowNotification of(User creator, Long userId, Long checkCreatorId){ - return new FollowNotification(creator, userId, checkCreatorId); - } - -} diff --git a/src/main/java/org/slams/server/notification/repository/FollowNotificationRepository.java b/src/main/java/org/slams/server/notification/repository/FollowNotificationRepository.java index 3ddacbe2..3f1e6b27 100644 --- a/src/main/java/org/slams/server/notification/repository/FollowNotificationRepository.java +++ b/src/main/java/org/slams/server/notification/repository/FollowNotificationRepository.java @@ -1,15 +1,11 @@ package org.slams.server.notification.repository; -import org.slams.server.notification.entity.FollowNotification; -import org.slams.server.notification.entity.LoudSpeakerNotification; import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.Modifying; import org.springframework.data.jpa.repository.Query; import org.springframework.data.repository.query.Param; import org.springframework.transaction.annotation.Transactional; -import javax.persistence.CascadeType; -import java.lang.annotation.Native; import java.util.List; import java.util.Optional; diff --git a/src/main/java/org/slams/server/notification/repository/LoudSpeakerNotificationRepository.java b/src/main/java/org/slams/server/notification/repository/LoudSpeakerNotificationRepository.java index d965013b..822c556b 100644 --- a/src/main/java/org/slams/server/notification/repository/LoudSpeakerNotificationRepository.java +++ b/src/main/java/org/slams/server/notification/repository/LoudSpeakerNotificationRepository.java @@ -1,15 +1,7 @@ package org.slams.server.notification.repository; -import org.slams.server.notification.entity.FollowNotification; import org.slams.server.notification.entity.LoudSpeakerNotification; import org.springframework.data.jpa.repository.JpaRepository; -import org.springframework.data.jpa.repository.Modifying; -import org.springframework.data.jpa.repository.Query; -import org.springframework.data.repository.query.Param; -import org.springframework.transaction.annotation.Transactional; - -import java.util.List; -import java.util.Optional; /** * Created by yunyun on 2021/12/15. diff --git a/src/main/java/org/slams/server/notification/service/NotificationService.java b/src/main/java/org/slams/server/notification/service/NotificationService.java index e416e73a..1a7cc444 100644 --- a/src/main/java/org/slams/server/notification/service/NotificationService.java +++ b/src/main/java/org/slams/server/notification/service/NotificationService.java @@ -6,20 +6,16 @@ import org.slams.server.court.exception.CourtNotFoundException; import org.slams.server.court.repository.CourtRepository; import org.slams.server.notification.Exception.InvalidCourtStartTimeException; -import org.slams.server.notification.Exception.NotificationNotFoundException; import org.slams.server.notification.convertor.NotificationConvertor; import org.slams.server.notification.dto.request.FollowNotificationRequest; import org.slams.server.notification.dto.request.LoudspeakerNotificationRequest; import org.slams.server.notification.dto.request.UpdateIsClickedStatusRequest; import org.slams.server.notification.dto.response.NotificationResponse; -import org.slams.server.notification.entity.FollowNotification; import org.slams.server.notification.entity.LoudSpeakerNotification; import org.slams.server.notification.entity.NotificationIndex; -import org.slams.server.notification.entity.NotificationType; import org.slams.server.notification.repository.FollowNotificationRepository; import org.slams.server.notification.repository.LoudSpeakerNotificationRepository; import org.slams.server.notification.repository.NotificationIndexRepository; -import org.slams.server.reservation.exception.ReservationNotFoundException; import org.slams.server.reservation.repository.ReservationRepository; import org.slams.server.user.entity.User; import org.slams.server.user.exception.UserNotFoundException; From 78d2418e9cc5b458bf6684a2bb63ad787a613593 Mon Sep 17 00:00:00 2001 From: yunyun Date: Mon, 24 Jan 2022 20:19:17 +0900 Subject: [PATCH 02/16] =?UTF-8?q?refactor:=20LoudspeakerNotification?= =?UTF-8?q?=EC=97=90=EC=84=9C=20Loudspeaker=EB=A1=9C=20=EC=97=94=ED=84=B0?= =?UTF-8?q?=ED=8B=B0=20=EC=9D=B4=EB=A6=84=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...oudSpeakerNotification.java => LoudSpeaker.java} | 13 +++++-------- .../notification/entity/NotificationIndex.java | 11 ++++------- .../LoudSpeakerNotificationRepository.java | 4 ++-- .../notification/service/NotificationService.java | 4 ++-- 4 files changed, 13 insertions(+), 19 deletions(-) rename src/main/java/org/slams/server/notification/entity/{LoudSpeakerNotification.java => LoudSpeaker.java} (79%) diff --git a/src/main/java/org/slams/server/notification/entity/LoudSpeakerNotification.java b/src/main/java/org/slams/server/notification/entity/LoudSpeaker.java similarity index 79% rename from src/main/java/org/slams/server/notification/entity/LoudSpeakerNotification.java rename to src/main/java/org/slams/server/notification/entity/LoudSpeaker.java index 7696f823..cf3a7dae 100644 --- a/src/main/java/org/slams/server/notification/entity/LoudSpeakerNotification.java +++ b/src/main/java/org/slams/server/notification/entity/LoudSpeaker.java @@ -4,12 +4,9 @@ import lombok.Builder; import lombok.Getter; import lombok.NoArgsConstructor; -import org.slams.server.common.BaseEntity; import org.slams.server.court.entity.Court; import javax.persistence.*; -import java.util.List; -import java.util.UUID; import static com.google.common.base.Preconditions.checkArgument; @@ -21,7 +18,7 @@ @NoArgsConstructor(access = AccessLevel.PROTECTED) @Entity @Table(name = "loudspeaker_notification") -public class LoudSpeakerNotification { +public class LoudSpeaker { @Id @GeneratedValue(strategy = GenerationType.IDENTITY) @Column(name="id") @@ -37,7 +34,7 @@ public class LoudSpeakerNotification { @Column private Long userId; - private LoudSpeakerNotification(Court court, int startTime, Long userId){ + private LoudSpeaker(Court court, int startTime, Long userId){ checkArgument(court != null, "court 정보는 null을 허용하지 않습니다."); checkArgument(0<= startTime && startTime<25, "경기 시작시간은 0이상 24시이하만 가능합니다."); checkArgument(userId != null, "userId 정보는 null을 허용하지 않습니다."); @@ -48,7 +45,7 @@ private LoudSpeakerNotification(Court court, int startTime, Long userId){ } @Builder - public LoudSpeakerNotification(Long id, Court court, int startTime, Long userId){ + public LoudSpeaker(Long id, Court court, int startTime, Long userId){ checkArgument(id != null, "id는 null을 허용하지 않습니다."); checkArgument(court != null, "court 정보는 null을 허용하지 않습니다."); checkArgument(userId != null, "userId 정보는 null을 허용하지 않습니다."); @@ -60,8 +57,8 @@ public LoudSpeakerNotification(Long id, Court court, int startTime, Long userId) this.userId = userId; } - public static LoudSpeakerNotification of(Court court, int startTime, Long userId){ - return new LoudSpeakerNotification(court, startTime, userId); + public static LoudSpeaker of(Court court, int startTime, Long userId){ + return new LoudSpeaker(court, startTime, userId); } diff --git a/src/main/java/org/slams/server/notification/entity/NotificationIndex.java b/src/main/java/org/slams/server/notification/entity/NotificationIndex.java index 3a5d7b82..55789471 100644 --- a/src/main/java/org/slams/server/notification/entity/NotificationIndex.java +++ b/src/main/java/org/slams/server/notification/entity/NotificationIndex.java @@ -1,15 +1,12 @@ package org.slams.server.notification.entity; import lombok.AccessLevel; -import lombok.Builder; import lombok.Getter; import lombok.NoArgsConstructor; import org.slams.server.common.BaseEntity; import javax.persistence.*; -import java.util.UUID; - import static com.google.common.base.Preconditions.checkArgument; /** @@ -35,7 +32,7 @@ public class NotificationIndex extends BaseEntity { @OneToOne(fetch = FetchType.EAGER) @JoinColumn(name = "loudspeaker_noti_id", referencedColumnName = "id") - private LoudSpeakerNotification loudSpeakerNotification; + private LoudSpeaker loudSpeakerNotification; @Enumerated(EnumType.STRING) private NotificationType notificationType; @@ -57,7 +54,7 @@ private NotificationIndex(Long userId, FollowNotification followNotification, Lo this.checkCreatorId = checkCreatorId; } - private NotificationIndex(Long userId, LoudSpeakerNotification loudSpeakerNotification){ + private NotificationIndex(Long userId, LoudSpeaker loudSpeakerNotification){ checkArgument(userId != null, "userId는 null을 허용하지 않습니다."); this.userId = userId; this.notificationType = NotificationType.LOUDSPEAKER; @@ -78,7 +75,7 @@ public NotificationIndex(Long id, Long userId, FollowNotification followNotifica this.checkCreatorId = checkCreatorId; } - public NotificationIndex(Long id, Long userId, LoudSpeakerNotification loudSpeakerNotification, + public NotificationIndex(Long id, Long userId, LoudSpeaker loudSpeakerNotification, NotificationType notificationType, boolean isRead, boolean isClicked){ checkArgument(id != null, "id는 null을 허용하지 않습니다."); checkArgument(userId != null, "userId는 null을 허용하지 않습니다."); @@ -91,7 +88,7 @@ public NotificationIndex(Long id, Long userId, LoudSpeakerNotification loudSpeak this.isClicked = isClicked; } - public static NotificationIndex createLoudSpeakerNoti(Long userId, LoudSpeakerNotification loudSpeakerNotification){ + public static NotificationIndex createLoudSpeakerNoti(Long userId, LoudSpeaker loudSpeakerNotification){ return new NotificationIndex(userId, loudSpeakerNotification); } diff --git a/src/main/java/org/slams/server/notification/repository/LoudSpeakerNotificationRepository.java b/src/main/java/org/slams/server/notification/repository/LoudSpeakerNotificationRepository.java index 822c556b..907d09ab 100644 --- a/src/main/java/org/slams/server/notification/repository/LoudSpeakerNotificationRepository.java +++ b/src/main/java/org/slams/server/notification/repository/LoudSpeakerNotificationRepository.java @@ -1,11 +1,11 @@ package org.slams.server.notification.repository; -import org.slams.server.notification.entity.LoudSpeakerNotification; +import org.slams.server.notification.entity.LoudSpeaker; import org.springframework.data.jpa.repository.JpaRepository; /** * Created by yunyun on 2021/12/15. */ -public interface LoudSpeakerNotificationRepository extends JpaRepository { +public interface LoudSpeakerNotificationRepository extends JpaRepository { } diff --git a/src/main/java/org/slams/server/notification/service/NotificationService.java b/src/main/java/org/slams/server/notification/service/NotificationService.java index 1a7cc444..071c79ea 100644 --- a/src/main/java/org/slams/server/notification/service/NotificationService.java +++ b/src/main/java/org/slams/server/notification/service/NotificationService.java @@ -11,7 +11,7 @@ import org.slams.server.notification.dto.request.LoudspeakerNotificationRequest; import org.slams.server.notification.dto.request.UpdateIsClickedStatusRequest; import org.slams.server.notification.dto.response.NotificationResponse; -import org.slams.server.notification.entity.LoudSpeakerNotification; +import org.slams.server.notification.entity.LoudSpeaker; import org.slams.server.notification.entity.NotificationIndex; import org.slams.server.notification.repository.FollowNotificationRepository; import org.slams.server.notification.repository.LoudSpeakerNotificationRepository; @@ -59,7 +59,7 @@ public NotificationResponse saveForLoudSpeakerNotification(LoudspeakerNotificati .findById(request.getCourtId()) .orElseThrow(() -> new CourtNotFoundException("해당 코트가 존재하지 않습니다.")); - LoudSpeakerNotification loudSpeakerNotification = LoudSpeakerNotification.of( + LoudSpeaker loudSpeakerNotification = LoudSpeaker.of( court, request.getStartTime(), userId From ad7ed21f3b074bab580105a923d06bddaeb75021 Mon Sep 17 00:00:00 2001 From: yunyun Date: Mon, 24 Jan 2022 20:20:51 +0900 Subject: [PATCH 03/16] =?UTF-8?q?refactor:=20Notification=20entity?= =?UTF-8?q?=EB=A1=9C=20=EC=9D=B4=EB=A6=84=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../convertor/NotificationConvertor.java | 6 ++--- ...tificationIndex.java => Notification.java} | 22 ++++++++-------- .../NotificationIndexRepository.java | 26 +++++++++---------- .../service/NotificationService.java | 10 +++---- .../server/user/service/UserService.java | 14 ---------- 5 files changed, 32 insertions(+), 46 deletions(-) rename src/main/java/org/slams/server/notification/entity/{NotificationIndex.java => Notification.java} (73%) diff --git a/src/main/java/org/slams/server/notification/convertor/NotificationConvertor.java b/src/main/java/org/slams/server/notification/convertor/NotificationConvertor.java index d2c55543..10bf510d 100644 --- a/src/main/java/org/slams/server/notification/convertor/NotificationConvertor.java +++ b/src/main/java/org/slams/server/notification/convertor/NotificationConvertor.java @@ -5,7 +5,7 @@ import org.slams.server.notification.dto.response.FollowerInfo; import org.slams.server.notification.dto.response.LoudspeakerInfo; import org.slams.server.notification.dto.response.NotificationResponse; -import org.slams.server.notification.entity.NotificationIndex; +import org.slams.server.notification.entity.Notification; import org.slams.server.notification.entity.NotificationType; import org.springframework.stereotype.Component; @@ -19,7 +19,7 @@ @Component public class NotificationConvertor { - public List toDtoList(List notifications){ + public List toDtoList(List notifications){ /** null 유효성 검사 추가 **/ // followNotificationList @@ -28,7 +28,7 @@ public List toDtoList(List notification .collect(Collectors.toList()); } - public NotificationResponse toDto(NotificationIndex notification){ + public NotificationResponse toDto(Notification notification){ if (notification.getNotificationType().equals(NotificationType.LOUDSPEAKER)){ return NotificationResponse.createForLoudspeakerNotification( notification.getId(), diff --git a/src/main/java/org/slams/server/notification/entity/NotificationIndex.java b/src/main/java/org/slams/server/notification/entity/Notification.java similarity index 73% rename from src/main/java/org/slams/server/notification/entity/NotificationIndex.java rename to src/main/java/org/slams/server/notification/entity/Notification.java index 55789471..1908a86d 100644 --- a/src/main/java/org/slams/server/notification/entity/NotificationIndex.java +++ b/src/main/java/org/slams/server/notification/entity/Notification.java @@ -17,7 +17,7 @@ @NoArgsConstructor(access = AccessLevel.PROTECTED) @Entity @Table(name = "notification_index") -public class NotificationIndex extends BaseEntity { +public class Notification extends BaseEntity { @Id @GeneratedValue(strategy = GenerationType.IDENTITY) @Column(name="id") @@ -46,7 +46,7 @@ public class NotificationIndex extends BaseEntity { @Column private Long checkCreatorId ; - private NotificationIndex(Long userId, FollowNotification followNotification, Long checkCreatorId){ + private Notification(Long userId, FollowNotification followNotification, Long checkCreatorId){ checkArgument(userId != null, "userId는 null을 허용하지 않습니다."); this.userId = userId; this.notificationType = NotificationType.FOLLOWING; @@ -54,15 +54,15 @@ private NotificationIndex(Long userId, FollowNotification followNotification, Lo this.checkCreatorId = checkCreatorId; } - private NotificationIndex(Long userId, LoudSpeaker loudSpeakerNotification){ + private Notification(Long userId, LoudSpeaker loudSpeakerNotification){ checkArgument(userId != null, "userId는 null을 허용하지 않습니다."); this.userId = userId; this.notificationType = NotificationType.LOUDSPEAKER; this.loudSpeakerNotification = loudSpeakerNotification; } - public NotificationIndex(Long id, Long userId, FollowNotification followNotification, - NotificationType notificationType, boolean isRead, boolean isClicked, Long checkCreatorId){ + public Notification(Long id, Long userId, FollowNotification followNotification, + NotificationType notificationType, boolean isRead, boolean isClicked, Long checkCreatorId){ checkArgument(id != null, "id는 null을 허용하지 않습니다."); checkArgument(userId != null, "userId는 null을 허용하지 않습니다."); checkArgument(notificationType != null, "notificationType 정보는 null을 허용하지 않습니다."); @@ -75,8 +75,8 @@ public NotificationIndex(Long id, Long userId, FollowNotification followNotifica this.checkCreatorId = checkCreatorId; } - public NotificationIndex(Long id, Long userId, LoudSpeaker loudSpeakerNotification, - NotificationType notificationType, boolean isRead, boolean isClicked){ + public Notification(Long id, Long userId, LoudSpeaker loudSpeakerNotification, + NotificationType notificationType, boolean isRead, boolean isClicked){ checkArgument(id != null, "id는 null을 허용하지 않습니다."); checkArgument(userId != null, "userId는 null을 허용하지 않습니다."); checkArgument(notificationType != null, "notificationType 정보는 null을 허용하지 않습니다."); @@ -88,13 +88,13 @@ public NotificationIndex(Long id, Long userId, LoudSpeaker loudSpeakerNotificati this.isClicked = isClicked; } - public static NotificationIndex createLoudSpeakerNoti(Long userId, LoudSpeaker loudSpeakerNotification){ - return new NotificationIndex(userId, loudSpeakerNotification); + public static Notification createLoudSpeakerNoti(Long userId, LoudSpeaker loudSpeakerNotification){ + return new Notification(userId, loudSpeakerNotification); } - public static NotificationIndex createFollowNoti(Long userId, FollowNotification followNotification, Long checkCreatorId){ - return new NotificationIndex(userId, followNotification, checkCreatorId); + public static Notification createFollowNoti(Long userId, FollowNotification followNotification, Long checkCreatorId){ + return new Notification(userId, followNotification, checkCreatorId); } diff --git a/src/main/java/org/slams/server/notification/repository/NotificationIndexRepository.java b/src/main/java/org/slams/server/notification/repository/NotificationIndexRepository.java index 02fcd592..830c0f3d 100644 --- a/src/main/java/org/slams/server/notification/repository/NotificationIndexRepository.java +++ b/src/main/java/org/slams/server/notification/repository/NotificationIndexRepository.java @@ -1,6 +1,6 @@ package org.slams.server.notification.repository; -import org.slams.server.notification.entity.NotificationIndex; +import org.slams.server.notification.entity.Notification; import org.springframework.data.domain.Pageable; import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.Modifying; @@ -14,37 +14,37 @@ * Created by yunyun on 2021/12/08. */ -public interface NotificationIndexRepository extends JpaRepository { +public interface NotificationIndexRepository extends JpaRepository { - @Query("SELECT a.id FROM NotificationIndex a WHERE a.userId =:userId AND a.id < :lastId ORDER BY a.createdAt desc") + @Query("SELECT a.id FROM Notification a WHERE a.userId =:userId AND a.id < :lastId ORDER BY a.createdAt desc") List findIdByUserLessThanAlarmIdByCreated( @Param("userId") Long userId, @Param("lastId") Long lastId, Pageable pageable ); - @Query("SELECT a.id FROM NotificationIndex a WHERE a.userId =:userId ORDER BY a.createdAt desc") + @Query("SELECT a.id FROM Notification a WHERE a.userId =:userId ORDER BY a.createdAt desc") List findIdByUserByCreated( @Param("userId") Long userId, Pageable pageable ); - @Query("SELECT a FROM NotificationIndex a WHERE a.userId =:userId AND a.id < :lastId ORDER BY a.createdAt desc") - List findAllByUserLessThanAlarmIdByCreated( + @Query("SELECT a FROM Notification a WHERE a.userId =:userId AND a.id < :lastId ORDER BY a.createdAt desc") + List findAllByUserLessThanAlarmIdByCreated( @Param("userId") Long userId, @Param("lastId") Long lastId, Pageable pageable ); - @Query("SELECT a FROM NotificationIndex a WHERE a.userId =:userId ORDER BY a.createdAt desc") - List findAllByUserByCreated( + @Query("SELECT a FROM Notification a WHERE a.userId =:userId ORDER BY a.createdAt desc") + List findAllByUserByCreated( @Param("userId") Long userId, Pageable pageable ); @Transactional @Modifying() - @Query("UPDATE NotificationIndex n SET n.isClicked=:status WHERE n.userId=:userId") + @Query("UPDATE Notification n SET n.isClicked=:status WHERE n.userId=:userId") Integer updateIsClicked( @Param("userId") Long userId, @Param("status") boolean status @@ -52,7 +52,7 @@ Integer updateIsClicked( @Transactional @Modifying() - @Query("UPDATE NotificationIndex n SET n.isRead=:status WHERE n.userId=:userId") + @Query("UPDATE Notification n SET n.isRead=:status WHERE n.userId=:userId") Integer updateIsRead( @Param("userId") Long userId, @Param("status") boolean status @@ -60,14 +60,14 @@ Integer updateIsRead( @Transactional @Modifying - @Query("DELETE FROM NotificationIndex n WHERE n.checkCreatorId=:userId AND n.userId=:receiverId") + @Query("DELETE FROM Notification n WHERE n.checkCreatorId=:userId AND n.userId=:receiverId") void deleteByReceiverIdAndUserId( @Param("receiverId") Long receiverId, @Param("userId") Long userId ); - @Query("SELECT n FROM NotificationIndex n WHERE n.checkCreatorId=:creatorId AND n.userId=:receiverId") - NotificationIndex findByReceiverIdAndCreatorId( + @Query("SELECT n FROM Notification n WHERE n.checkCreatorId=:creatorId AND n.userId=:receiverId") + Notification findByReceiverIdAndCreatorId( @Param("receiverId") Long receiverId, @Param("creatorId") Long creatorId ); diff --git a/src/main/java/org/slams/server/notification/service/NotificationService.java b/src/main/java/org/slams/server/notification/service/NotificationService.java index 071c79ea..f81b4055 100644 --- a/src/main/java/org/slams/server/notification/service/NotificationService.java +++ b/src/main/java/org/slams/server/notification/service/NotificationService.java @@ -12,7 +12,7 @@ import org.slams.server.notification.dto.request.UpdateIsClickedStatusRequest; import org.slams.server.notification.dto.response.NotificationResponse; import org.slams.server.notification.entity.LoudSpeaker; -import org.slams.server.notification.entity.NotificationIndex; +import org.slams.server.notification.entity.Notification; import org.slams.server.notification.repository.FollowNotificationRepository; import org.slams.server.notification.repository.LoudSpeakerNotificationRepository; import org.slams.server.notification.repository.NotificationIndexRepository; @@ -66,7 +66,7 @@ public NotificationResponse saveForLoudSpeakerNotification(LoudspeakerNotificati ); return notificationConvertor.toDto(notificationRepository.save( - NotificationIndex.createLoudSpeakerNoti(userId, loudSpeakerNotificationRepository.save(loudSpeakerNotification)) + Notification.createLoudSpeakerNoti(userId, loudSpeakerNotificationRepository.save(loudSpeakerNotification)) )); } @@ -84,7 +84,7 @@ public NotificationResponse saveForFollowNotification(FollowNotificationRequest ); return notificationConvertor.toDto(notificationRepository.save( - NotificationIndex.createFollowNoti(request.getReceiverId(), followNotificationRepository.save(followNotification), userId) + Notification.createFollowNoti(request.getReceiverId(), followNotificationRepository.save(followNotification), userId) )); } @@ -93,7 +93,7 @@ public List findAllByUserId(Long userId, CursorPageRequest return notificationConvertor.toDtoList(cursorPageForFindAllByUserId(userId, cursorRequest)); } - public List cursorPageForFindAllByUserId(Long userId, CursorPageRequest cursorRequest){ + public List cursorPageForFindAllByUserId(Long userId, CursorPageRequest cursorRequest){ PageRequest pageable = PageRequest.of(0, cursorRequest.getSize()); return cursorRequest.getIsFirst() ? notificationRepository.findAllByUserByCreated(userId, pageable) : @@ -134,7 +134,7 @@ public void deleteFollowNotification(FollowNotificationRequest request, Long use followNotificationRepository.deleteByReceiverIdAndUserId(request.getReceiverId(), userId); } - public NotificationIndex findByReceiverIdCreatorId(Long receiverId, Long creatorId){ + public Notification findByReceiverIdCreatorId(Long receiverId, Long creatorId){ return notificationRepository.findByReceiverIdAndCreatorId(receiverId, creatorId); } diff --git a/src/main/java/org/slams/server/user/service/UserService.java b/src/main/java/org/slams/server/user/service/UserService.java index 92682eb7..b2860dc5 100644 --- a/src/main/java/org/slams/server/user/service/UserService.java +++ b/src/main/java/org/slams/server/user/service/UserService.java @@ -2,18 +2,11 @@ import lombok.RequiredArgsConstructor; import org.slams.server.common.api.CursorPageRequest; -import org.slams.server.common.api.CursorPageResponse; import org.slams.server.common.utils.AwsS3Uploader; -import org.slams.server.court.entity.Texture; import org.slams.server.favorite.repository.FavoriteRepository; import org.slams.server.follow.repository.FollowRepository; -import org.slams.server.notification.dto.response.CourtInfo; -import org.slams.server.notification.dto.response.FollowerInfo; -import org.slams.server.notification.dto.response.LoudspeakerInfo; import org.slams.server.notification.dto.response.NotificationResponse; -import org.slams.server.notification.entity.NotificationIndex; -import org.slams.server.notification.entity.NotificationType; import org.slams.server.notification.service.NotificationService; import org.slams.server.user.dto.request.ExtraUserInfoRequest; import org.slams.server.user.dto.response.*; @@ -21,22 +14,15 @@ import org.slams.server.user.exception.SameUserException; import org.slams.server.user.exception.UserNotFoundException; import org.slams.server.user.repository.UserRepository; -import org.springframework.data.domain.PageRequest; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import org.springframework.web.multipart.MultipartFile; -import javax.management.Notification; import java.io.IOException; import java.text.MessageFormat; -import java.time.LocalDateTime; -import java.util.Collections; import java.util.List; import java.util.stream.Collectors; -import static org.slams.server.notification.entity.NotificationType.FOLLOWING; -import static org.slams.server.notification.entity.NotificationType.LOUDSPEAKER; - @Transactional(readOnly = true) @Service @RequiredArgsConstructor From 5273c56486031cfcd09f71df6ca7798f2e652aa6 Mon Sep 17 00:00:00 2001 From: yunyun Date: Mon, 24 Jan 2022 20:27:01 +0900 Subject: [PATCH 04/16] =?UTF-8?q?feat:=20=EB=85=BC=EC=9D=98=20=ED=9B=84,?= =?UTF-8?q?=20=EB=B3=80=EA=B2=BD=EB=90=9C=20entity=20=ED=98=95=EC=8B=9D?= =?UTF-8?q?=EC=9C=BC=EB=A1=9C=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../common/ValidationMessage.java | 35 ++++++++ .../notification/entity/LoudSpeaker.java | 76 +++++++++++------ .../notification/entity/Notification.java | 85 +++++++++---------- .../notification/entity/NotificationType.java | 2 +- 4 files changed, 124 insertions(+), 74 deletions(-) create mode 100644 src/main/java/org/slams/server/notification/common/ValidationMessage.java diff --git a/src/main/java/org/slams/server/notification/common/ValidationMessage.java b/src/main/java/org/slams/server/notification/common/ValidationMessage.java new file mode 100644 index 00000000..b88050d1 --- /dev/null +++ b/src/main/java/org/slams/server/notification/common/ValidationMessage.java @@ -0,0 +1,35 @@ +package org.slams.server.notification.common; + +/** + * Created by yunyun on 2022/01/24. + */ +public enum ValidationMessage { + // common + NOTNULL_ID("Id는 NULL 을 허용하지 않습니다."), + + // user + NOTNULL_USERID("UserId는 NULL 을 허용하지 않습니다."), + NOTNULL_USER("User 정보는 NULL 을 허용하지 않습니다."), + + // notification + NOTNULL_NOTIFICATION_TYPE("Notification Type 정보는 NULL 을 허용하지 않습니다."), + + + // court + NOTNULL_COURT("경기장 정보는 NULL 을 허용하지 않습니다."), + NOTNULL_START_TIME("경기 시작 시간의 정보는 NULL 을 허용하지 않습니다."), + NOTNULL_END_TIME("경기 끝 시간의 정보는 NULL 을 허용하지 않습니다.") + + ; + + + private String message; + + ValidationMessage(String message) { + this.message = message; + } + + public String getMessage() { + return message; + } +} \ No newline at end of file diff --git a/src/main/java/org/slams/server/notification/entity/LoudSpeaker.java b/src/main/java/org/slams/server/notification/entity/LoudSpeaker.java index cf3a7dae..b1794e83 100644 --- a/src/main/java/org/slams/server/notification/entity/LoudSpeaker.java +++ b/src/main/java/org/slams/server/notification/entity/LoudSpeaker.java @@ -1,13 +1,17 @@ package org.slams.server.notification.entity; import lombok.AccessLevel; -import lombok.Builder; import lombok.Getter; import lombok.NoArgsConstructor; +import org.slams.server.common.BaseEntity; import org.slams.server.court.entity.Court; +import org.slams.server.notification.common.ValidationMessage; +import org.slams.server.user.entity.User; import javax.persistence.*; +import java.time.LocalDateTime; + import static com.google.common.base.Preconditions.checkArgument; /** @@ -17,49 +21,69 @@ @Getter @NoArgsConstructor(access = AccessLevel.PROTECTED) @Entity -@Table(name = "loudspeaker_notification") -public class LoudSpeaker { +@Table(name = "loudspeaker") +public class LoudSpeaker extends BaseEntity { + @Id @GeneratedValue(strategy = GenerationType.IDENTITY) @Column(name="id") private Long id; - @ManyToOne(fetch = FetchType.EAGER) - @JoinColumn(name = "court_id", nullable = false, referencedColumnName = "id") + @ManyToOne(fetch = FetchType.EAGER, cascade = CascadeType.REMOVE) + @JoinColumn(name = "user_id", referencedColumnName = "id") + private User user; + + @ManyToOne(fetch = FetchType.EAGER, cascade = CascadeType.REMOVE) + @JoinColumn(name = "court_id", referencedColumnName = "id") private Court court; @Column - private int startTime; + private LocalDateTime startTime; @Column - private Long userId; - - private LoudSpeaker(Court court, int startTime, Long userId){ - checkArgument(court != null, "court 정보는 null을 허용하지 않습니다."); - checkArgument(0<= startTime && startTime<25, "경기 시작시간은 0이상 24시이하만 가능합니다."); - checkArgument(userId != null, "userId 정보는 null을 허용하지 않습니다."); + private LocalDateTime endTime; + public LoudSpeaker ( + Long id, + User user, + Court court, + LocalDateTime startTime, + LocalDateTime endTime + ){ + checkArgument(id != null, ValidationMessage.NOTNULL_ID); + checkArgument(user != null, ValidationMessage.NOTNULL_USER); + checkArgument(court != null, ValidationMessage.NOTNULL_COURT); + checkArgument(startTime != null, ValidationMessage.NOTNULL_START_TIME); + checkArgument(endTime != null, ValidationMessage.NOTNULL_END_TIME); + this.id = id; + this.user = user; this.court = court; this.startTime = startTime; - this.userId = userId; + this.endTime = endTime; } - @Builder - public LoudSpeaker(Long id, Court court, int startTime, Long userId){ - checkArgument(id != null, "id는 null을 허용하지 않습니다."); - checkArgument(court != null, "court 정보는 null을 허용하지 않습니다."); - checkArgument(userId != null, "userId 정보는 null을 허용하지 않습니다."); - checkArgument(0<= startTime && startTime<25, "경기 시작시간은 0이상 24시이하만 가능합니다."); - - this.id = id; + private LoudSpeaker( + User user, + Court court, + LocalDateTime startTime, + LocalDateTime endTime + ){ + checkArgument(user != null, ValidationMessage.NOTNULL_USER); + checkArgument(court != null, ValidationMessage.NOTNULL_COURT); + checkArgument(startTime != null, ValidationMessage.NOTNULL_START_TIME); + checkArgument(endTime != null, ValidationMessage.NOTNULL_END_TIME); + this.user = user; this.court = court; this.startTime = startTime; - this.userId = userId; + this.endTime = endTime; } - public static LoudSpeaker of(Court court, int startTime, Long userId){ - return new LoudSpeaker(court, startTime, userId); + public static LoudSpeaker createLoudSpeaker( + User user, + Court court, + LocalDateTime startTime, + LocalDateTime endTime + ){ + return new LoudSpeaker(user, court, startTime, endTime); } - - } diff --git a/src/main/java/org/slams/server/notification/entity/Notification.java b/src/main/java/org/slams/server/notification/entity/Notification.java index 1908a86d..b254e114 100644 --- a/src/main/java/org/slams/server/notification/entity/Notification.java +++ b/src/main/java/org/slams/server/notification/entity/Notification.java @@ -4,6 +4,8 @@ import lombok.Getter; import lombok.NoArgsConstructor; import org.slams.server.common.BaseEntity; +import org.slams.server.follow.entity.Follow; +import org.slams.server.notification.common.ValidationMessage; import javax.persistence.*; @@ -16,7 +18,7 @@ @Getter @NoArgsConstructor(access = AccessLevel.PROTECTED) @Entity -@Table(name = "notification_index") +@Table(name = "notification") public class Notification extends BaseEntity { @Id @GeneratedValue(strategy = GenerationType.IDENTITY) @@ -27,15 +29,15 @@ public class Notification extends BaseEntity { private Long userId; @OneToOne(fetch = FetchType.EAGER, cascade = CascadeType.REMOVE) - @JoinColumn(name = "follow_noti_id", referencedColumnName = "id") - private FollowNotification followNotification; + @JoinColumn(name = "follow_id", referencedColumnName = "id") + private Follow follow; @OneToOne(fetch = FetchType.EAGER) - @JoinColumn(name = "loudspeaker_noti_id", referencedColumnName = "id") - private LoudSpeaker loudSpeakerNotification; + @JoinColumn(name = "loudspeaker_id", referencedColumnName = "id") + private LoudSpeaker loudSpeaker; @Enumerated(EnumType.STRING) - private NotificationType notificationType; + private NotificationType type; @Column(columnDefinition = "boolean default false") private boolean isRead; @@ -43,59 +45,48 @@ public class Notification extends BaseEntity { @Column(columnDefinition = "boolean default false") private boolean isClicked; - @Column - private Long checkCreatorId ; - - private Notification(Long userId, FollowNotification followNotification, Long checkCreatorId){ - checkArgument(userId != null, "userId는 null을 허용하지 않습니다."); - this.userId = userId; - this.notificationType = NotificationType.FOLLOWING; - this.followNotification = followNotification; - this.checkCreatorId = checkCreatorId; - } - - private Notification(Long userId, LoudSpeaker loudSpeakerNotification){ - checkArgument(userId != null, "userId는 null을 허용하지 않습니다."); - this.userId = userId; - this.notificationType = NotificationType.LOUDSPEAKER; - this.loudSpeakerNotification = loudSpeakerNotification; - } - - public Notification(Long id, Long userId, FollowNotification followNotification, - NotificationType notificationType, boolean isRead, boolean isClicked, Long checkCreatorId){ - checkArgument(id != null, "id는 null을 허용하지 않습니다."); - checkArgument(userId != null, "userId는 null을 허용하지 않습니다."); - checkArgument(notificationType != null, "notificationType 정보는 null을 허용하지 않습니다."); + public Notification(Long id, + Long userId, + Follow follow, + LoudSpeaker loudSpeaker, + NotificationType type, + boolean isRead, + boolean isClicked){ + checkArgument(id != null, ValidationMessage.NOTNULL_ID); + checkArgument(userId != null, ValidationMessage.NOTNULL_USERID); + checkArgument(type != null, ValidationMessage.NOTNULL_NOTIFICATION_TYPE); this.id = id; this.userId = userId; - this.followNotification = followNotification; - this.notificationType = notificationType; + this.follow = follow; + this.loudSpeaker = loudSpeaker; this.isRead = isRead; this.isClicked = isClicked; - this.checkCreatorId = checkCreatorId; } - public Notification(Long id, Long userId, LoudSpeaker loudSpeakerNotification, - NotificationType notificationType, boolean isRead, boolean isClicked){ - checkArgument(id != null, "id는 null을 허용하지 않습니다."); - checkArgument(userId != null, "userId는 null을 허용하지 않습니다."); - checkArgument(notificationType != null, "notificationType 정보는 null을 허용하지 않습니다."); - this.id = id; + private Notification( + Long userId, + Follow follow, + LoudSpeaker loudSpeaker, + NotificationType type + ){ + checkArgument(id != null, ValidationMessage.NOTNULL_ID); + checkArgument(userId != null, ValidationMessage.NOTNULL_USERID); + checkArgument(type != null, ValidationMessage.NOTNULL_NOTIFICATION_TYPE); this.userId = userId; - this.loudSpeakerNotification = loudSpeakerNotification; - this.notificationType = notificationType; - this.isRead = isRead; - this.isClicked = isClicked; + this.follow = follow; + this.loudSpeaker = loudSpeaker; + this.type = type; } - public static Notification createLoudSpeakerNoti(Long userId, LoudSpeaker loudSpeakerNotification){ - return new Notification(userId, loudSpeakerNotification); + + public static Notification createLoudSpeaker(Long userId, LoudSpeaker loudSpeaker){ + return new Notification(userId, null, loudSpeaker, NotificationType.LOUDSPEAKER); } - public static Notification createFollowNoti(Long userId, FollowNotification followNotification, Long checkCreatorId){ - return new Notification(userId, followNotification, checkCreatorId); + public static Notification createFollow(Long userId, Follow follow){ + return new Notification(userId, follow, null, NotificationType.FOLLOW); } -} +} \ No newline at end of file diff --git a/src/main/java/org/slams/server/notification/entity/NotificationType.java b/src/main/java/org/slams/server/notification/entity/NotificationType.java index 7b8c4083..133a0c1c 100644 --- a/src/main/java/org/slams/server/notification/entity/NotificationType.java +++ b/src/main/java/org/slams/server/notification/entity/NotificationType.java @@ -4,6 +4,6 @@ * Created by yunyun on 2021/12/03. */ public enum NotificationType { - FOLLOWING, + FOLLOW, LOUDSPEAKER; } From 02a10f1229ad1bf5fba3c0bcd2e48e4c0d821143 Mon Sep 17 00:00:00 2001 From: yunyun Date: Sat, 29 Jan 2022 22:00:36 +0900 Subject: [PATCH 05/16] =?UTF-8?q?feat:=20eneity=EC=99=80=20dto=20=EC=9C=A0?= =?UTF-8?q?=ED=9A=A8=EC=84=B1=20=EA=B2=80=EC=82=AC=20=EA=B3=B5=ED=86=B5=20?= =?UTF-8?q?=EB=AC=B8=EA=B5=AC=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../slams/server/notification/common/ValidationMessage.java | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/main/java/org/slams/server/notification/common/ValidationMessage.java b/src/main/java/org/slams/server/notification/common/ValidationMessage.java index b88050d1..14a09c19 100644 --- a/src/main/java/org/slams/server/notification/common/ValidationMessage.java +++ b/src/main/java/org/slams/server/notification/common/ValidationMessage.java @@ -10,16 +10,18 @@ public enum ValidationMessage { // user NOTNULL_USERID("UserId는 NULL 을 허용하지 않습니다."), NOTNULL_USER("User 정보는 NULL 을 허용하지 않습니다."), + NOT_EMPTY_NICKNAME("nickname은 빈값을 허용하지 않습니다."), // notification NOTNULL_NOTIFICATION_TYPE("Notification Type 정보는 NULL 을 허용하지 않습니다."), - // court NOTNULL_COURT("경기장 정보는 NULL 을 허용하지 않습니다."), NOTNULL_START_TIME("경기 시작 시간의 정보는 NULL 을 허용하지 않습니다."), - NOTNULL_END_TIME("경기 끝 시간의 정보는 NULL 을 허용하지 않습니다.") + NOTNULL_END_TIME("경기 끝 시간의 정보는 NULL 을 허용하지 않습니다."), + NOT_EMPTY_NAME("경기장 이름은 빈값을 허용하지 않습니다."), + MORE_THAN_ONE_BASKET_COUNT("골대의 개수는 1개 이상이어야 합니다.") ; From cc450f4e73dda99434d27160349a9209d5fd313e Mon Sep 17 00:00:00 2001 From: yunyun Date: Sat, 29 Jan 2022 22:01:46 +0900 Subject: [PATCH 06/16] =?UTF-8?q?feat:=20dto=20=EC=83=88=EB=A1=9C=20?= =?UTF-8?q?=EC=B6=94=EA=B0=80=20=EB=B0=8F=20=EB=B6=88=ED=91=9C=ED=95=9C=20?= =?UTF-8?q?dto=20=EC=82=AD=EC=A0=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../org/slams/server/common/dto/BaseDto.java | 11 +++++ .../CourtInfo.java => common/dto/Court.java} | 18 +++---- .../org/slams/server/common/dto/Follow.java | 24 ++++++++++ .../org/slams/server/common/dto/User.java | 47 +++++++++++++++++++ .../dto/response/FollowerInfo.java | 32 ------------- .../dto/response/Loudspeaker.java | 43 +++++++++++++++++ .../dto/response/LoudspeakerInfo.java | 30 ------------ 7 files changed, 135 insertions(+), 70 deletions(-) create mode 100644 src/main/java/org/slams/server/common/dto/BaseDto.java rename src/main/java/org/slams/server/{notification/dto/response/CourtInfo.java => common/dto/Court.java} (64%) create mode 100644 src/main/java/org/slams/server/common/dto/Follow.java create mode 100644 src/main/java/org/slams/server/common/dto/User.java delete mode 100644 src/main/java/org/slams/server/notification/dto/response/FollowerInfo.java create mode 100644 src/main/java/org/slams/server/notification/dto/response/Loudspeaker.java delete mode 100644 src/main/java/org/slams/server/notification/dto/response/LoudspeakerInfo.java diff --git a/src/main/java/org/slams/server/common/dto/BaseDto.java b/src/main/java/org/slams/server/common/dto/BaseDto.java new file mode 100644 index 00000000..0a5f9caa --- /dev/null +++ b/src/main/java/org/slams/server/common/dto/BaseDto.java @@ -0,0 +1,11 @@ +package org.slams.server.common.dto; + +import java.time.LocalDateTime; + +/** + * Created by yunyun on 2022/01/24. + */ +public class BaseDto { + private LocalDateTime createdAt; + private LocalDateTime updatedAt; +} diff --git a/src/main/java/org/slams/server/notification/dto/response/CourtInfo.java b/src/main/java/org/slams/server/common/dto/Court.java similarity index 64% rename from src/main/java/org/slams/server/notification/dto/response/CourtInfo.java rename to src/main/java/org/slams/server/common/dto/Court.java index 330b2746..5e10bc6f 100644 --- a/src/main/java/org/slams/server/notification/dto/response/CourtInfo.java +++ b/src/main/java/org/slams/server/common/dto/Court.java @@ -1,18 +1,20 @@ -package org.slams.server.notification.dto.response; +package org.slams.server.common.dto; +import com.fasterxml.jackson.annotation.JsonInclude; import lombok.Builder; import lombok.Getter; import org.slams.server.court.entity.Texture; +import org.slams.server.notification.common.ValidationMessage; import static com.google.common.base.Preconditions.checkArgument; import static org.apache.commons.lang3.StringUtils.isNotEmpty; /** - * Created by yunyun on 2021/12/14. + * Created by yunyun on 2022/01/24. */ - @Getter -public class CourtInfo { +@JsonInclude(JsonInclude.Include.NON_NULL) +public class Court { private final Long id; private final String name; private final double latitude; @@ -22,7 +24,7 @@ public class CourtInfo { private final Texture texture; @Builder - public CourtInfo( + public Court( Long id, String name, double latitude, @@ -31,9 +33,9 @@ public CourtInfo( int basketCount, Texture texture ){ - checkArgument(id != null, "userId는 null을 허용하지 않습니다."); - checkArgument(isNotEmpty(name), "농구장는 빈값을 허용하지 않습니다."); - checkArgument(basketCount >= 0, "골대 개수는 0이상만 가능합니다."); + checkArgument(id != null, ValidationMessage.NOTNULL_ID); + checkArgument(isNotEmpty(name), ValidationMessage.NOT_EMPTY_NAME); + checkArgument(basketCount > 0, ValidationMessage.MORE_THAN_ONE_BASKET_COUNT); this.id = id; this.name = name; diff --git a/src/main/java/org/slams/server/common/dto/Follow.java b/src/main/java/org/slams/server/common/dto/Follow.java new file mode 100644 index 00000000..584d7b97 --- /dev/null +++ b/src/main/java/org/slams/server/common/dto/Follow.java @@ -0,0 +1,24 @@ +package org.slams.server.common.dto; + +/** + * Created by yunyun on 2022/01/24. + */ + +import com.fasterxml.jackson.annotation.JsonInclude; +import lombok.Builder; + +@JsonInclude(JsonInclude.Include.NON_NULL) +public class Follow extends BaseDto{ + private User creator; + private User receiver; + + @Builder + public Follow( + User creator, + User receiver + ){ + this.creator = creator; + this.receiver = receiver; + } + +} diff --git a/src/main/java/org/slams/server/common/dto/User.java b/src/main/java/org/slams/server/common/dto/User.java new file mode 100644 index 00000000..ce0fec9d --- /dev/null +++ b/src/main/java/org/slams/server/common/dto/User.java @@ -0,0 +1,47 @@ +package org.slams.server.common.dto; + +import com.fasterxml.jackson.annotation.JsonInclude; +import lombok.Builder; +import org.slams.server.notification.common.ValidationMessage; +import org.slams.server.user.entity.Position; +import org.slams.server.user.entity.Proficiency; + +import java.util.List; + +import static com.google.common.base.Preconditions.checkArgument; +import static org.apache.commons.lang3.StringUtils.isNotEmpty; + +/** + * Created by yunyun on 2022/01/24. + */ + +@JsonInclude(JsonInclude.Include.NON_NULL) +public class User extends BaseDto{ + + private Long id; + private String nickname; + private String profileImage; + private String description; + private Proficiency proficiency; + private List positions; + + @Builder + public User( + Long id, + String nickname, + String profileImage, + String description, + Proficiency proficiency, + List positions + ){ + checkArgument(id != null, ValidationMessage.NOTNULL_ID); + checkArgument(isNotEmpty(nickname), ValidationMessage.NOT_EMPTY_NICKNAME); + + this.id = id; + this.nickname = nickname; + this.profileImage = profileImage; + this.description = description; + this.positions = positions; + + } +} diff --git a/src/main/java/org/slams/server/notification/dto/response/FollowerInfo.java b/src/main/java/org/slams/server/notification/dto/response/FollowerInfo.java deleted file mode 100644 index 2a1b3fa5..00000000 --- a/src/main/java/org/slams/server/notification/dto/response/FollowerInfo.java +++ /dev/null @@ -1,32 +0,0 @@ -package org.slams.server.notification.dto.response; - -import lombok.Builder; -import lombok.Getter; - -import static com.google.common.base.Preconditions.checkArgument; -import static org.apache.commons.lang3.StringUtils.isNotEmpty; - -/** - * Created by yunyun on 2021/12/14. - */ - -@Getter -public class FollowerInfo { - private final Long userId; - private final String userNickname; - private final String userImage; - - @Builder - public FollowerInfo( - Long userId, - String userNickname, - String userImage - ){ - checkArgument(userId != null, "userId는 null을 허용하지 않습니다."); - checkArgument(isNotEmpty(userNickname), "userNickname는 빈값을 허용하지 않습니다."); - - this.userId = userId; - this.userNickname = userNickname; - this.userImage = userImage; - } -} diff --git a/src/main/java/org/slams/server/notification/dto/response/Loudspeaker.java b/src/main/java/org/slams/server/notification/dto/response/Loudspeaker.java new file mode 100644 index 00000000..9cb38f9f --- /dev/null +++ b/src/main/java/org/slams/server/notification/dto/response/Loudspeaker.java @@ -0,0 +1,43 @@ +package org.slams.server.notification.dto.response; + +import com.fasterxml.jackson.annotation.JsonInclude; +import lombok.Builder; +import org.slams.server.common.dto.Court; +import org.slams.server.common.dto.User; +import org.slams.server.notification.common.ValidationMessage; + +import java.time.LocalDateTime; + +import static com.google.common.base.Preconditions.checkArgument; + +/** + * Created by yunyun on 2022/01/24. + */ + +@JsonInclude(JsonInclude.Include.NON_NULL) +public class Loudspeaker { + private Long id; + private User user; + private Court court; + private LocalDateTime startTime; + + @Builder + public Loudspeaker( + Long id, + User user, + Court court, + LocalDateTime startTime + ){ + checkArgument(id != null, ValidationMessage.NOTNULL_ID); + checkArgument(user != null, ValidationMessage.NOTNULL_USER); + checkArgument(court != null, ValidationMessage.NOTNULL_COURT); + checkArgument(startTime != null, ValidationMessage.NOTNULL_START_TIME); + + this.id = id; + this.user = user; + this.court = court; + this.startTime = startTime; + } + + +} diff --git a/src/main/java/org/slams/server/notification/dto/response/LoudspeakerInfo.java b/src/main/java/org/slams/server/notification/dto/response/LoudspeakerInfo.java deleted file mode 100644 index e8fbe55c..00000000 --- a/src/main/java/org/slams/server/notification/dto/response/LoudspeakerInfo.java +++ /dev/null @@ -1,30 +0,0 @@ -package org.slams.server.notification.dto.response; - -import com.fasterxml.jackson.annotation.JsonProperty; -import lombok.Builder; -import lombok.Getter; - -import static com.google.common.base.Preconditions.checkArgument; - -/** - * Created by yunyun on 2021/12/14. - */ - -@Getter -public class LoudspeakerInfo { - - @JsonProperty("courtInfo") - private final CourtInfo courtInfo; - private final int startTime; - - @Builder - public LoudspeakerInfo( - CourtInfo courtInfo, - int startTime) { - checkArgument(courtInfo != null, "courtInfo는 null을 허용하지 않습니다."); - checkArgument(0<= startTime && startTime<25, "경기 시작시간은 0이상 24시이하만 가능합니다."); - - this.courtInfo = courtInfo; - this.startTime = startTime; - } -} From 68ffbe865bda3f49a1188b6616ce7e94a8904a6e Mon Sep 17 00:00:00 2001 From: yunyun Date: Sat, 29 Jan 2022 22:02:30 +0900 Subject: [PATCH 07/16] =?UTF-8?q?feat:=20=EC=83=88=EB=A1=9C=20=EC=88=98?= =?UTF-8?q?=EC=A0=95=EB=90=9C=20dto=20=EC=97=90=20=EB=A7=9E=EC=B6=B0=20?= =?UTF-8?q?=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../dto/response/NotificationResponse.java | 26 +++++++++---------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/src/main/java/org/slams/server/notification/dto/response/NotificationResponse.java b/src/main/java/org/slams/server/notification/dto/response/NotificationResponse.java index 54b16438..52259ae2 100644 --- a/src/main/java/org/slams/server/notification/dto/response/NotificationResponse.java +++ b/src/main/java/org/slams/server/notification/dto/response/NotificationResponse.java @@ -1,7 +1,8 @@ package org.slams.server.notification.dto.response; -import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonInclude; import lombok.Getter; +import org.slams.server.common.dto.Follow; import org.slams.server.notification.entity.NotificationType; import java.time.LocalDateTime; @@ -13,17 +14,16 @@ */ @Getter +@JsonInclude(JsonInclude.Include.NON_NULL) public class NotificationResponse { private final Long id; private final NotificationType type; - @JsonProperty("followerInfo") - private final FollowerInfo followerInfo; + private final Follow follow; - @JsonProperty("loudspeakerInfo") - private final LoudspeakerInfo loudspeakerInfo; + private final Loudspeaker loudspeaker; private final Boolean isRead; @@ -36,8 +36,8 @@ public class NotificationResponse { private NotificationResponse( Long id, NotificationType type, - FollowerInfo followerInfo, - LoudspeakerInfo loudspeakerInfo, + Follow follow, + Loudspeaker loudspeaker, boolean isRead, boolean isClicked, LocalDateTime createdAt, @@ -45,8 +45,8 @@ private NotificationResponse( ){ this.id = id; this.type = type; - this.followerInfo = followerInfo; - this.loudspeakerInfo = loudspeakerInfo; + this.follow = follow; + this.loudspeaker = loudspeaker; this.isRead = isRead; this.isClicked = isClicked; this.createdAt = createdAt; @@ -56,25 +56,25 @@ private NotificationResponse( public static NotificationResponse createForFollowNotification( Long id, NotificationType type, - FollowerInfo followerInfo, + Follow follow, boolean isRead, boolean isClicked, LocalDateTime createdAt, LocalDateTime updatedAt ){ - return new NotificationResponse(id, type, followerInfo, null, isRead, isClicked, createdAt, updatedAt); + return new NotificationResponse(id, type, follow, null, isRead, isClicked, createdAt, updatedAt); } public static NotificationResponse createForLoudspeakerNotification( Long id, NotificationType type, - LoudspeakerInfo loudspeakerInfo, + Loudspeaker loudspeaker, boolean isRead, boolean isClicked, LocalDateTime createdAt, LocalDateTime updatedAt ){ - return new NotificationResponse(id, type, null, loudspeakerInfo, isRead, isClicked, createdAt, updatedAt); + return new NotificationResponse(id, type, null, loudspeaker, isRead, isClicked, createdAt, updatedAt); } } From fba0c302d398e31a35e80c2bdd5fe8255c3593e6 Mon Sep 17 00:00:00 2001 From: yunyun Date: Sat, 29 Jan 2022 22:03:28 +0900 Subject: [PATCH 08/16] =?UTF-8?q?feat:=20=EB=B6=88=ED=95=84=EC=9A=94?= =?UTF-8?q?=ED=95=9C=20repository=20=EC=82=AD=EC=A0=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../FollowNotificationRepository.java | 38 ------------------- 1 file changed, 38 deletions(-) delete mode 100644 src/main/java/org/slams/server/notification/repository/FollowNotificationRepository.java diff --git a/src/main/java/org/slams/server/notification/repository/FollowNotificationRepository.java b/src/main/java/org/slams/server/notification/repository/FollowNotificationRepository.java deleted file mode 100644 index 3f1e6b27..00000000 --- a/src/main/java/org/slams/server/notification/repository/FollowNotificationRepository.java +++ /dev/null @@ -1,38 +0,0 @@ -package org.slams.server.notification.repository; - -import org.springframework.data.jpa.repository.JpaRepository; -import org.springframework.data.jpa.repository.Modifying; -import org.springframework.data.jpa.repository.Query; -import org.springframework.data.repository.query.Param; -import org.springframework.transaction.annotation.Transactional; - -import java.util.List; -import java.util.Optional; - -/** - * Created by yunyun on 2021/12/15. - */ -public interface FollowNotificationRepository extends JpaRepository { - - - @Query("SELECT f.id FROM FollowNotification f WHERE f.creator.id=:userId AND f.userId=:receiverId") - List findByReceiverIdAndUserId( - @Param("receiverId") Long receiverId, - @Param("userId") Long userId - ); - - @Query("SELECT f FROM FollowNotification f WHERE f.creator.id=:userId AND f.userId=:receiverId") - Optional findOneByReceiverIdAndUserId( - @Param("receiverId") Long receiverId, - @Param("userId") Long userId - ); - - @Transactional - @Modifying - @Query("DELETE FROM FollowNotification n WHERE n.checkCreatorId=:userId AND n.userId=:receiverId") - void deleteByReceiverIdAndUserId( - @Param("receiverId") Long receiverId, - @Param("userId") Long userId - ); - -} From 070d42a23403d164bc8b713a311003b44ad5cb4a Mon Sep 17 00:00:00 2001 From: yunyun Date: Sat, 29 Jan 2022 22:04:37 +0900 Subject: [PATCH 09/16] =?UTF-8?q?feat:=20loudspeaker=20entity=20=EC=88=98?= =?UTF-8?q?=EC=A0=95=EB=90=9C=20=EC=BB=AC=EB=9F=BC=EC=97=90=20=EB=A7=9E?= =?UTF-8?q?=EA=B2=8C=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/org/slams/server/notification/entity/LoudSpeaker.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/org/slams/server/notification/entity/LoudSpeaker.java b/src/main/java/org/slams/server/notification/entity/LoudSpeaker.java index b1794e83..3a33b2f5 100644 --- a/src/main/java/org/slams/server/notification/entity/LoudSpeaker.java +++ b/src/main/java/org/slams/server/notification/entity/LoudSpeaker.java @@ -78,7 +78,7 @@ private LoudSpeaker( this.endTime = endTime; } - public static LoudSpeaker createLoudSpeaker( + public static LoudSpeaker of( User user, Court court, LocalDateTime startTime, From 8b86f498ce756e383fcede5b6a778cb96d77d189 Mon Sep 17 00:00:00 2001 From: yunyun Date: Sat, 29 Jan 2022 22:05:51 +0900 Subject: [PATCH 10/16] =?UTF-8?q?feat:=20entity=20=EC=9D=B4=EB=A6=84=20?= =?UTF-8?q?=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...erNotificationRepository.java => LoudspeakerRepository.java} | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) rename src/main/java/org/slams/server/notification/repository/{LoudSpeakerNotificationRepository.java => LoudspeakerRepository.java} (69%) diff --git a/src/main/java/org/slams/server/notification/repository/LoudSpeakerNotificationRepository.java b/src/main/java/org/slams/server/notification/repository/LoudspeakerRepository.java similarity index 69% rename from src/main/java/org/slams/server/notification/repository/LoudSpeakerNotificationRepository.java rename to src/main/java/org/slams/server/notification/repository/LoudspeakerRepository.java index 907d09ab..5d4d91db 100644 --- a/src/main/java/org/slams/server/notification/repository/LoudSpeakerNotificationRepository.java +++ b/src/main/java/org/slams/server/notification/repository/LoudspeakerRepository.java @@ -6,6 +6,6 @@ /** * Created by yunyun on 2021/12/15. */ -public interface LoudSpeakerNotificationRepository extends JpaRepository { +public interface LoudspeakerRepository extends JpaRepository { } From d5ec583e263d87e4c7998e0da5e2b44f4bd3da75 Mon Sep 17 00:00:00 2001 From: yunyun Date: Sat, 29 Jan 2022 22:06:22 +0900 Subject: [PATCH 11/16] =?UTF-8?q?feat:=20=EC=BB=AC=EB=9F=BC=20=EC=88=98?= =?UTF-8?q?=EC=A0=95=EC=9C=BC=EB=A1=9C=20=EC=BF=BC=EB=A6=AC=20=EB=B3=80?= =?UTF-8?q?=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...itory.java => NotificationRepository.java} | 21 ++++++++++--------- 1 file changed, 11 insertions(+), 10 deletions(-) rename src/main/java/org/slams/server/notification/repository/{NotificationIndexRepository.java => NotificationRepository.java} (76%) diff --git a/src/main/java/org/slams/server/notification/repository/NotificationIndexRepository.java b/src/main/java/org/slams/server/notification/repository/NotificationRepository.java similarity index 76% rename from src/main/java/org/slams/server/notification/repository/NotificationIndexRepository.java rename to src/main/java/org/slams/server/notification/repository/NotificationRepository.java index 830c0f3d..fa0fb458 100644 --- a/src/main/java/org/slams/server/notification/repository/NotificationIndexRepository.java +++ b/src/main/java/org/slams/server/notification/repository/NotificationRepository.java @@ -1,6 +1,7 @@ package org.slams.server.notification.repository; import org.slams.server.notification.entity.Notification; +import org.slams.server.notification.entity.NotificationType; import org.springframework.data.domain.Pageable; import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.Modifying; @@ -14,7 +15,7 @@ * Created by yunyun on 2021/12/08. */ -public interface NotificationIndexRepository extends JpaRepository { +public interface NotificationRepository extends JpaRepository { @Query("SELECT a.id FROM Notification a WHERE a.userId =:userId AND a.id < :lastId ORDER BY a.createdAt desc") List findIdByUserLessThanAlarmIdByCreated( @@ -60,16 +61,16 @@ Integer updateIsRead( @Transactional @Modifying - @Query("DELETE FROM Notification n WHERE n.checkCreatorId=:userId AND n.userId=:receiverId") - void deleteByReceiverIdAndUserId( + @Query("DELETE FROM Notification n WHERE n.follow.follower.id=:sendId AND n.userId=:receiverId AND n.type='FOLLOW'") + void deleteByReceiverIdAndSendIdOnFollowNotification( @Param("receiverId") Long receiverId, - @Param("userId") Long userId - ); + @Param("sendId") Long sendId + ); - @Query("SELECT n FROM Notification n WHERE n.checkCreatorId=:creatorId AND n.userId=:receiverId") - Notification findByReceiverIdAndCreatorId( - @Param("receiverId") Long receiverId, - @Param("creatorId") Long creatorId - ); +// @Query("SELECT n FROM Notification n WHERE n.checkCreatorId=:creatorId AND n.userId=:receiverId") +// Notification findByReceiverIdAndCreatorId( +// @Param("receiverId") Long receiverId, +// @Param("creatorId") Long creatorId +// ); } From f4c6dc5df5a5f0b0dd868438545875362959e675 Mon Sep 17 00:00:00 2001 From: yunyun Date: Sat, 29 Jan 2022 22:09:07 +0900 Subject: [PATCH 12/16] =?UTF-8?q?feat:=20=EC=88=98=EC=A0=95=EB=90=9C=20dto?= =?UTF-8?q?=EC=99=80=20entity=20=EC=97=90=20=EB=A7=9E=EA=B2=8C=20=EC=88=98?= =?UTF-8?q?=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 공지 reqeust 수정 - 공지 관련 controler 수정 - convertor 수정 --- .../NotificationWebSocketController.java | 14 +-- .../convertor/NotificationConvertor.java | 116 +++++------------- .../LoudspeakerNotificationRequest.java | 8 +- .../service/NotificationService.java | 58 +++++---- 4 files changed, 75 insertions(+), 121 deletions(-) diff --git a/src/main/java/org/slams/server/notification/controller/NotificationWebSocketController.java b/src/main/java/org/slams/server/notification/controller/NotificationWebSocketController.java index d6a1b00e..b35cd019 100644 --- a/src/main/java/org/slams/server/notification/controller/NotificationWebSocketController.java +++ b/src/main/java/org/slams/server/notification/controller/NotificationWebSocketController.java @@ -105,21 +105,21 @@ public void saveLoudSpeakerAndThenSending( LoudspeakerNotificationRequest request, SimpMessageHeaderAccessor headerAccessor ){ - Long userId = websocketUtil.findTokenFromHeader(headerAccessor); - List bookerIds = reservationRepository.findBeakerIdByCourtId(request.getCourtId()); + Long sendId = websocketUtil.findTokenFromHeader(headerAccessor); + List receiverIds = reservationRepository.findBeakerIdByCourtId(request.getCourtId()); - for (Long bookId : bookerIds){ - if (bookId.equals(userId)){ + for (Long receiverId : receiverIds){ + if (receiverId.equals(sendId)){ continue; } - NotificationResponse notification = notificationService.saveForLoudSpeakerNotification(request, bookId); + NotificationResponse notification = notificationService.saveForLoudSpeakerNotification(request, receiverId, sendId); websocket.convertAndSend( - String.format("/user/%d/notification", bookId), + String.format("/user/%d/notification", receiverId), notification ); } - ChatContentsResponse chatContentsResponse = chatContentsService.saveChatLoudSpeakerContent(request, userId); + ChatContentsResponse chatContentsResponse = chatContentsService.saveChatLoudSpeakerContent(request, sendId); websocket.convertAndSend( String.format("/user/%d/chat", request.getCourtId()), chatContentsResponse diff --git a/src/main/java/org/slams/server/notification/convertor/NotificationConvertor.java b/src/main/java/org/slams/server/notification/convertor/NotificationConvertor.java index 10bf510d..c817fd7c 100644 --- a/src/main/java/org/slams/server/notification/convertor/NotificationConvertor.java +++ b/src/main/java/org/slams/server/notification/convertor/NotificationConvertor.java @@ -1,9 +1,10 @@ package org.slams.server.notification.convertor; +import org.slams.server.common.dto.Court; +import org.slams.server.common.dto.Follow; +import org.slams.server.common.dto.User; import org.slams.server.notification.Exception.InvalidNotificationTypeException; -import org.slams.server.notification.dto.response.CourtInfo; -import org.slams.server.notification.dto.response.FollowerInfo; -import org.slams.server.notification.dto.response.LoudspeakerInfo; +import org.slams.server.notification.dto.response.Loudspeaker; import org.slams.server.notification.dto.response.NotificationResponse; import org.slams.server.notification.entity.Notification; import org.slams.server.notification.entity.NotificationType; @@ -20,8 +21,10 @@ public class NotificationConvertor { public List toDtoList(List notifications){ - /** null 유효성 검사 추가 **/ - // followNotificationList + + if (notifications.isEmpty()){ + return Collections.emptyList(); + } return notifications.stream() .map(v -> toDto(v)) @@ -29,21 +32,21 @@ public List toDtoList(List notifications){ } public NotificationResponse toDto(Notification notification){ - if (notification.getNotificationType().equals(NotificationType.LOUDSPEAKER)){ + if (notification.getType().equals(NotificationType.LOUDSPEAKER)){ return NotificationResponse.createForLoudspeakerNotification( notification.getId(), NotificationType.LOUDSPEAKER, - LoudspeakerInfo.builder() - .courtInfo(CourtInfo.builder() - .id(notification.getLoudSpeakerNotification().getCourt().getId()) - .name(notification.getLoudSpeakerNotification().getCourt().getName()) - .texture(notification.getLoudSpeakerNotification().getCourt().getTexture()) - .longitude(notification.getLoudSpeakerNotification().getCourt().getLongitude()) - .latitude(notification.getLoudSpeakerNotification().getCourt().getLatitude()) - .image(notification.getLoudSpeakerNotification().getCourt().getImage()) - .basketCount(notification.getLoudSpeakerNotification().getCourt().getBasketCount()) + Loudspeaker.builder() + .court(Court.builder() + .id(notification.getLoudSpeaker().getCourt().getId()) + .name(notification.getLoudSpeaker().getCourt().getName()) + .texture(notification.getLoudSpeaker().getCourt().getTexture()) + .longitude(notification.getLoudSpeaker().getCourt().getLongitude()) + .latitude(notification.getLoudSpeaker().getCourt().getLatitude()) + .image(notification.getLoudSpeaker().getCourt().getImage()) + .basketCount(notification.getLoudSpeaker().getCourt().getBasketCount()) .build()) - .startTime(notification.getLoudSpeakerNotification().getStartTime()) + .startTime(notification.getLoudSpeaker().getStartTime()) .build(), notification.isRead(), notification.isClicked(), @@ -52,14 +55,18 @@ public NotificationResponse toDto(Notification notification){ ); } - if (notification.getNotificationType().equals(NotificationType.FOLLOWING)){ + if (notification.getType().equals(NotificationType.FOLLOW)){ return NotificationResponse.createForFollowNotification( notification.getId(), - NotificationType.FOLLOWING, - FollowerInfo.builder() - .userId(notification.getFollowNotification().getCreator().getId()) - .userImage(notification.getFollowNotification().getCreator().getProfileImage()) - .userNickname(notification.getFollowNotification().getCreator().getNickname()) + NotificationType.FOLLOW, + Follow.builder() + .creator( + User.builder() + .id(notification.getFollow().getFollower().getId()) + .profileImage(notification.getFollow().getFollower().getProfileImage()) + .nickname(notification.getFollow().getFollower().getNickname()) + .build() + ) .build(), notification.isRead(), notification.isClicked(), @@ -70,71 +77,6 @@ public NotificationResponse toDto(Notification notification){ throw new InvalidNotificationTypeException("존재하지 않는 공지 타입입니다."); } -// -// public List toDtoListForLoudspeakerNotification(List loudSpeakerNotificationList){ -// /** null 유효성 검사 추가 **/ -// // followNotificationList -// -// return loudSpeakerNotificationList.stream() -// .map(v -> toDtoForLoudNotification(v)) -// .collect(Collectors.toList()); -// } -// -// public NotificationResponse toDtoForFollowNotification(FollowNotification followNotification){ -// /** null 유효성 검사 추가 **/ -// //followNotification.getNotification(); -// //followNotification.getFollower(); -// -// return NotificationResponse.createForFollowNotification( -// followNotification.getNotificationType(), -// FollowerInfo.builder() -// .userId(followNotification.getCreator().getId()) -// .userImage(followNotification.getCreator().getProfileImage()) -// .userNickname(followNotification.getCreator().getNickname()) -// .build(), -// followNotification.isRead(), -// followNotification.isClicked(), -// followNotification.getCreatedAt(), -// followNotification.getUpdateAt() -// ); -// } -// -// public NotificationResponse toDtoForLoudNotification(LoudSpeakerNotification loudSpeakerNotification){ -// -// return NotificationResponse.createForLoudspeakerNotification( -// loudSpeakerNotification.getNotificationType(), -// LoudspeakerInfo.builder() -// .courtInfo(CourtInfo.builder() -// .id(loudSpeakerNotification.getCourt().getId()) -// .basketCount(loudSpeakerNotification.getCourt().getBasketCount()) -// .image(loudSpeakerNotification.getCourt().getImage()) -// .latitude(loudSpeakerNotification.getCourt().getLatitude()) -// .longitude(loudSpeakerNotification.getCourt().getLongitude()) -// .name(loudSpeakerNotification.getCourt().getName()) -// .texture(loudSpeakerNotification.getCourt().getTexture()) -// .build() -// ) -// .startTime(loudSpeakerNotification.getStartTime()) -// .build(), -// loudSpeakerNotification.isRead(), -// loudSpeakerNotification.isClicked(), -// loudSpeakerNotification.getCreatedAt(), -// loudSpeakerNotification.getUpdateAt() -// ); -// } -// -// /** created로 정렬 **/ -// public List mergeListForFollowNotificationAndLoudspeakerNotification( -// List followNotificationList, -// List loudSpeakerNotificationList -// ){ -// followNotificationList.addAll(loudSpeakerNotificationList); -// if(followNotificationList.size() > 0){ -// Collections.sort(followNotificationList); -// return followNotificationList; -// } -// return Collections.emptyList(); -// } } diff --git a/src/main/java/org/slams/server/notification/dto/request/LoudspeakerNotificationRequest.java b/src/main/java/org/slams/server/notification/dto/request/LoudspeakerNotificationRequest.java index 2d0485d6..4943fb16 100644 --- a/src/main/java/org/slams/server/notification/dto/request/LoudspeakerNotificationRequest.java +++ b/src/main/java/org/slams/server/notification/dto/request/LoudspeakerNotificationRequest.java @@ -3,6 +3,8 @@ import lombok.Getter; import lombok.Setter; +import java.time.LocalDateTime; + /** * Created by yunyun on 2021/12/14. */ @@ -10,15 +12,17 @@ @Getter public class LoudspeakerNotificationRequest { private final Long courtId; - private final int startTime; + private final LocalDateTime startTime; + private final LocalDateTime endTime; private final Long reservationId; - public LoudspeakerNotificationRequest(Long courtId, int startTime, Long reservationId){ + public LoudspeakerNotificationRequest(Long courtId, LocalDateTime startTime, LocalDateTime endTime, Long reservationId){ /** websocket으로 runtimeException을 낼 경우, 세션 끊어지는가? * 혹시 모르니까, 객체에 값을 넣기 전에 유효성 검사를 하자. */ this.courtId = courtId; this.startTime = startTime; + this.endTime = endTime; this.reservationId = reservationId; } diff --git a/src/main/java/org/slams/server/notification/service/NotificationService.java b/src/main/java/org/slams/server/notification/service/NotificationService.java index f81b4055..bf2b749b 100644 --- a/src/main/java/org/slams/server/notification/service/NotificationService.java +++ b/src/main/java/org/slams/server/notification/service/NotificationService.java @@ -5,7 +5,9 @@ import org.slams.server.court.entity.Court; import org.slams.server.court.exception.CourtNotFoundException; import org.slams.server.court.repository.CourtRepository; -import org.slams.server.notification.Exception.InvalidCourtStartTimeException; +import org.slams.server.follow.entity.Follow; +import org.slams.server.follow.exception.FollowNotFoundException; +import org.slams.server.follow.repository.FollowRepository; import org.slams.server.notification.convertor.NotificationConvertor; import org.slams.server.notification.dto.request.FollowNotificationRequest; import org.slams.server.notification.dto.request.LoudspeakerNotificationRequest; @@ -13,9 +15,8 @@ import org.slams.server.notification.dto.response.NotificationResponse; import org.slams.server.notification.entity.LoudSpeaker; import org.slams.server.notification.entity.Notification; -import org.slams.server.notification.repository.FollowNotificationRepository; -import org.slams.server.notification.repository.LoudSpeakerNotificationRepository; -import org.slams.server.notification.repository.NotificationIndexRepository; +import org.slams.server.notification.repository.LoudspeakerRepository; +import org.slams.server.notification.repository.NotificationRepository; import org.slams.server.reservation.repository.ReservationRepository; import org.slams.server.user.entity.User; import org.slams.server.user.exception.UserNotFoundException; @@ -36,55 +37,63 @@ @RequiredArgsConstructor public class NotificationService { - private final NotificationIndexRepository notificationRepository; - private final FollowNotificationRepository followNotificationRepository; - private final LoudSpeakerNotificationRepository loudSpeakerNotificationRepository; + private final NotificationRepository notificationRepository; + private final LoudspeakerRepository loudSpeakerNotificationRepository; private final UserRepository userRepository; + private final FollowRepository followRepository; private final NotificationConvertor notificationConvertor; private final CourtRepository courtRepository; private final ReservationRepository reservationRepository; - public NotificationResponse saveForLoudSpeakerNotification(LoudspeakerNotificationRequest request, Long userId){ + public NotificationResponse saveForLoudSpeakerNotification(LoudspeakerNotificationRequest request, Long receiverId, Long sendId){ /** 예약 도메인 관련 **/ /** 테스트를 위해 주석처리 var reservation = reservationRepository.findById(request.getReservationId()) .orElseThrow(() -> new ReservationNotFoundException("존재하지 않은 예약입니다.")); **/ - if(LocalDateTime.now().getHour() - request.getStartTime() < 0 && LocalDateTime.now().getHour() - request.getStartTime() <= 1) { - throw new InvalidCourtStartTimeException("경기 시작 1시간 이전에만 확성기 기능을 사용하실 수 있습니다."); - } + + /** start time 과 end time 보낼지, start time과 time block으로 보낼지 결정해야 함. 전자라면, start time < end time 요효성 검사해야함 **/ Court court = courtRepository .findById(request.getCourtId()) .orElseThrow(() -> new CourtNotFoundException("해당 코트가 존재하지 않습니다.")); + User sender = userRepository.findById(sendId) + .orElseThrow(() -> new UserNotFoundException("공지를 보내는 이는 존재하지 않는 사용지 입니다.")); LoudSpeaker loudSpeakerNotification = LoudSpeaker.of( + sender, court, request.getStartTime(), - userId + request.getEndTime() ); return notificationConvertor.toDto(notificationRepository.save( - Notification.createLoudSpeakerNoti(userId, loudSpeakerNotificationRepository.save(loudSpeakerNotification)) + Notification.createLoudSpeaker(receiverId, loudSpeakerNotificationRepository.save(loudSpeakerNotification)) )); } public NotificationResponse saveForFollowNotification(FollowNotificationRequest request, Long userId){ - Optional followNotificationForChecked = followNotificationRepository.findOneByReceiverIdAndUserId(request.getReceiverId(), userId); User creator = userRepository .findById(userId) .orElseThrow(() -> new UserNotFoundException("팔로우한 해당 사용자는 존재하지 않는 사용자 입니다.")); - FollowNotification followNotification = FollowNotification.of( - creator, - request.getReceiverId(), - userId - ); + User receiver = userRepository + .findById(request.getReceiverId()) + .orElseThrow(() -> new UserNotFoundException("팔로우 당한 사용자는 존재하지 않는 사용자 입니다.")); + + /** follow service 에서 follow 저장하는 로직의 리턴 값을 저장된 객체로 요청해보기. 지금 리턴값은 void 임 + * 불필요하게 user 정보를 들고 와서 저장하게 됨. + * **/ + + + Follow follow = followRepository + .findByFollowerAndFollowing(creator, receiver) + .orElseThrow(() -> new FollowNotFoundException("존재하지 않는 follow 정보 입니다.")); return notificationConvertor.toDto(notificationRepository.save( - Notification.createFollowNoti(request.getReceiverId(), followNotificationRepository.save(followNotification), userId) + Notification.createFollow(request.getReceiverId(), follow) )); } @@ -130,12 +139,11 @@ public void updateIsClickedStatus(UpdateIsClickedStatusRequest request, Long use @Transactional public void deleteFollowNotification(FollowNotificationRequest request, Long userId){ - notificationRepository.deleteByReceiverIdAndUserId(request.getReceiverId(), userId); - followNotificationRepository.deleteByReceiverIdAndUserId(request.getReceiverId(), userId); + notificationRepository.deleteByReceiverIdAndSendIdOnFollowNotification(request.getReceiverId(), userId); } - public Notification findByReceiverIdCreatorId(Long receiverId, Long creatorId){ - return notificationRepository.findByReceiverIdAndCreatorId(receiverId, creatorId); - } +// public Notification findByReceiverIdCreatorId(Long receiverId, Long creatorId){ +// return notificationRepository.findByReceiverIdAndCreatorId(receiverId, creatorId); +// } } From d6f1db73a56f379d1e47682ae274b32bbe76101b Mon Sep 17 00:00:00 2001 From: yunyun Date: Sat, 29 Jan 2022 22:10:12 +0900 Subject: [PATCH 13/16] =?UTF-8?q?feat:=20=EA=B3=B5=EC=A7=80=20=EB=82=B4?= =?UTF-8?q?=EC=9A=A9=EC=97=90=20end=20time=EC=99=80=20start=20time=20?= =?UTF-8?q?=EC=9D=98=20=ED=83=80=EC=9E=85=20=EB=B3=80=EA=B2=BD=EC=99=80=20?= =?UTF-8?q?=EC=A0=95=EB=B3=B4=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../org/slams/server/chat/service/ChatContentsService.java | 2 +- .../org/slams/server/chat/service/ChatContentsServiceTest.java | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/main/java/org/slams/server/chat/service/ChatContentsService.java b/src/main/java/org/slams/server/chat/service/ChatContentsService.java index d8a9857e..2d4de10c 100644 --- a/src/main/java/org/slams/server/chat/service/ChatContentsService.java +++ b/src/main/java/org/slams/server/chat/service/ChatContentsService.java @@ -79,7 +79,7 @@ public ChatContentsResponse saveChatLoudSpeakerContent(LoudspeakerNotificationRe .orElseThrow(() -> new UserNotFoundException("해당 작성자는 존재하지 않는 사용자입니다.")); ChatLoudSpeakerContent chatLoudSpeakerContent = chatLoudSpeakerContentRepository.save( - ChatLoudSpeakerContent.of(request.getStartTime()) + ChatLoudSpeakerContent.of(request.getStartTime().getHour()) ); ChatContents chatContents = ChatContents.createLoudspeakerContent( ChatContentType.LOUDSPEAKER, diff --git a/src/test/java/org/slams/server/chat/service/ChatContentsServiceTest.java b/src/test/java/org/slams/server/chat/service/ChatContentsServiceTest.java index 10bd7aab..b73da5e8 100644 --- a/src/test/java/org/slams/server/chat/service/ChatContentsServiceTest.java +++ b/src/test/java/org/slams/server/chat/service/ChatContentsServiceTest.java @@ -139,7 +139,8 @@ void saveChatLoudSpeakerContent(){ //Given LoudspeakerNotificationRequest request = new LoudspeakerNotificationRequest( court.getId(), - 10, + LocalDateTime.now(), + LocalDateTime.now().plusHours(2L), reservation.getId() ); Long userId = user.getId(); From d721bea5059b6476d98f26cb582f99af634568d3 Mon Sep 17 00:00:00 2001 From: yunyun Date: Sat, 29 Jan 2022 22:10:35 +0900 Subject: [PATCH 14/16] =?UTF-8?q?test:=20=EA=B3=B5=EC=A7=80=20=EB=82=B4?= =?UTF-8?q?=EC=9A=A9=EC=97=90=20end=20time=EC=99=80=20start=20time=20?= =?UTF-8?q?=EC=9D=98=20=ED=83=80=EC=9E=85=20=EB=B3=80=EA=B2=BD=EC=99=80=20?= =?UTF-8?q?=EC=A0=95=EB=B3=B4=20=EC=B6=94?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/NotificationControllerTest.java | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/src/test/java/org/slams/server/notification/controller/NotificationControllerTest.java b/src/test/java/org/slams/server/notification/controller/NotificationControllerTest.java index 5f5f67fb..a2adb65c 100644 --- a/src/test/java/org/slams/server/notification/controller/NotificationControllerTest.java +++ b/src/test/java/org/slams/server/notification/controller/NotificationControllerTest.java @@ -3,9 +3,8 @@ import com.fasterxml.jackson.databind.ObjectMapper; import org.junit.jupiter.api.*; import org.slams.server.court.repository.CourtRepository; -import org.slams.server.notification.repository.FollowNotificationRepository; -import org.slams.server.notification.repository.LoudSpeakerNotificationRepository; -import org.slams.server.notification.repository.NotificationIndexRepository; +import org.slams.server.notification.repository.LoudspeakerRepository; +import org.slams.server.notification.repository.NotificationRepository; import org.slams.server.notification.service.NotificationService; import org.slams.server.user.repository.UserRepository; import org.slams.server.user.service.UserService; @@ -46,7 +45,7 @@ class NotificationControllerTest { ObjectMapper objectMapper; @Autowired - private NotificationIndexRepository notificationIndexRepository; + private NotificationRepository notificationIndexRepository; @Autowired private NotificationService notificationService; @@ -58,10 +57,7 @@ class NotificationControllerTest { private UserRepository userRepository; @Autowired - private FollowNotificationRepository followNotificationRepository; - - @Autowired - private LoudSpeakerNotificationRepository loudSpeakerNotificationRepository; + private LoudspeakerRepository loudSpeakerNotificationRepository; @Autowired private UserService userService; From 7388d50a57843b741d0b8aa942f3560cf758d54f Mon Sep 17 00:00:00 2001 From: yunyun Date: Sat, 29 Jan 2022 22:11:12 +0900 Subject: [PATCH 15/16] =?UTF-8?q?fix:=20=EA=B3=B5=EC=A7=80=20=EB=8F=84?= =?UTF-8?q?=EB=A9=94=EC=9D=B8=EC=9D=98=20dto=20=EB=B3=80=EA=B2=BD=EC=9C=BC?= =?UTF-8?q?=EB=A1=9C=20=EC=88=98=EC=A0=95=EB=90=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/org/slams/server/common/query/DummyCourtQuery.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/org/slams/server/common/query/DummyCourtQuery.java b/src/main/java/org/slams/server/common/query/DummyCourtQuery.java index 8a20152d..2ad0751c 100644 --- a/src/main/java/org/slams/server/common/query/DummyCourtQuery.java +++ b/src/main/java/org/slams/server/common/query/DummyCourtQuery.java @@ -126,11 +126,11 @@ public void insertExcel() throws IOException, InvalidFormatException { } public void insertNotificationDummy(Long userId, int dataSize){ - LoudspeakerNotificationRequest request = new LoudspeakerNotificationRequest(1L, LocalDateTime.now().getHour(), 1L); + LoudspeakerNotificationRequest request = new LoudspeakerNotificationRequest(1L, LocalDateTime.now(), LocalDateTime.now().plusHours(2L), 1L); int index = 0; while (index < dataSize){ - notificationService.saveForLoudSpeakerNotification(request, userId); + notificationService.saveForLoudSpeakerNotification(request, userId, userId); index = index + 1; } From 11a7937bcf547eb510516b258c29de9572d1779b Mon Sep 17 00:00:00 2001 From: yunyun Date: Sat, 29 Jan 2022 22:12:15 +0900 Subject: [PATCH 16/16] =?UTF-8?q?test:=20=EA=B3=B5=EC=A7=80=EC=9D=98=20end?= =?UTF-8?q?=20time=20=EC=B6=94=EA=B0=80,=20start=20time=20=ED=83=80?= =?UTF-8?q?=EC=9E=85=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../slams/server/user/controller/UserControllerTest.java | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/src/test/java/org/slams/server/user/controller/UserControllerTest.java b/src/test/java/org/slams/server/user/controller/UserControllerTest.java index 1744a277..3cef4ec8 100644 --- a/src/test/java/org/slams/server/user/controller/UserControllerTest.java +++ b/src/test/java/org/slams/server/user/controller/UserControllerTest.java @@ -5,10 +5,6 @@ import org.junit.jupiter.api.Test; import org.slams.server.court.entity.Court; import org.slams.server.court.entity.Texture; -import org.slams.server.notification.dto.response.CourtInfo; -import org.slams.server.notification.dto.response.FollowerInfo; -import org.slams.server.notification.dto.response.LoudspeakerInfo; -import org.slams.server.notification.dto.response.NotificationResponse; import org.slams.server.user.dto.request.ExtraUserInfoRequest; import org.slams.server.user.dto.response.*; import org.slams.server.user.entity.Position; @@ -27,7 +23,6 @@ import org.springframework.core.io.support.ResourcePropertySource; import org.springframework.http.MediaType; import org.springframework.restdocs.payload.JsonFieldType; -import org.springframework.test.context.ActiveProfiles; import org.springframework.test.web.servlet.MockMvc; import org.springframework.test.web.servlet.ResultActions; import org.springframework.test.web.servlet.request.MockMvcRequestBuilders; @@ -35,14 +30,12 @@ import java.io.IOException; import java.time.LocalDateTime; import java.util.Arrays; -import java.util.Collections; import java.util.List; import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.anyLong; import static org.mockito.BDDMockito.given; -import static org.slams.server.notification.entity.NotificationType.FOLLOWING; -import static org.slams.server.notification.entity.NotificationType.LOUDSPEAKER; +import static org.slams.server.notification.entity.NotificationType.FOLLOW; import static org.springframework.restdocs.mockmvc.MockMvcRestDocumentation.document; import static org.springframework.restdocs.operation.preprocess.Preprocessors.*; import static org.springframework.restdocs.operation.preprocess.Preprocessors.prettyPrint;