From fbc22af734af1758b0a05abce45b9ea70cd1b347 Mon Sep 17 00:00:00 2001 From: BeommoKoo-dev <95630007+BeommoKoo-dev@users.noreply.github.com> Date: Mon, 22 Jan 2024 21:55:03 +0900 Subject: [PATCH 1/2] =?UTF-8?q?revert=20:=20=EA=B8=B0=EC=A1=B4=20infra?= =?UTF-8?q?=EC=9D=98=20jpa=EA=B4=80=EB=A0=A8=20=ED=81=B4=EB=9E=98=EC=8A=A4?= =?UTF-8?q?=20revert?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../aws/api/S3FileController.java | 2 +- .../nabimarketbe/config/QuerydslConfig.java | 20 -- .../nabimarketbe/config/TestConfig.java | 19 -- .../prgrms/nabimarketbe/jpa/BaseEntity.java | 42 --- .../nabimarketbe/jpa/card/entity/Card.java | 172 ----------- .../jpa/card/entity/CardStatus.java | 7 - .../jpa/card/entity/TradeType.java | 6 - .../projection/CardCondenseResponseDTO.java | 22 -- .../projection/CardFamousResponseDTO.java | 16 -- .../card/projection/CardInfoResponseDTO.java | 18 -- .../projection/CardListReadResponseDTO.java | 29 -- .../card/projection/CardListResponseDTO.java | 8 - .../projection/CardPagingResponseDTO.java | 9 - .../projection/CardSuggestionResponseDTO.java | 14 - .../projection/CardSummaryResponseDTO.java | 16 -- .../CardUserSummaryResponseDTO.java | 9 - .../jpa/card/repository/CardRepository.java | 28 -- .../card/repository/CardRepositoryCustom.java | 37 --- .../card/repository/CardRepositoryImpl.java | 267 ------------------ .../jpa/cardImage/entity/CardImage.java | 58 ---- .../repository/CardImageBatchRepository.java | 36 --- .../repository/CardImageRepository.java | 13 - .../jpa/category/entity/Category.java | 32 --- .../jpa/category/entity/CategoryEnum.java | 13 - .../repository/CategoryRepository.java | 11 - .../jpa/chatroom/entity/ChatRoom.java | 45 --- .../projection/list/CardInfoListDTO.java | 16 -- .../projection/list/ChatRoomInfoListDTO.java | 16 -- .../projection/list/ChatRoomListWrapper.java | 14 - .../projection/list/FromCardInfoListDTO.java | 10 - .../projection/list/ToCardInfoListDTO.java | 10 - .../projection/list/UserInfoListDTO.java | 8 - .../projection/single/CardInfoDTO.java | 12 - .../projection/single/ChatRoomInfoDTO.java | 24 -- .../single/ChatRoomInfoWrapper.java | 8 - .../projection/single/FromCardInfoDTO.java | 10 - .../projection/single/ToCardInfoDTO.java | 10 - .../projection/single/UserInfoDTO.java | 8 - .../repository/ChatRoomRepository.java | 9 - .../repository/ChatRoomRepositoryCustom.java | 10 - .../repository/ChatRoomRepositoryImpl.java | 195 ------------- .../entity/CompleteRequest.java | 98 ------- .../entity/CompleteRequestStatus.java | 8 - .../HistoryListReadResponseDTO.java | 20 -- .../repository/CompleteRequestRepository.java | 50 ---- .../CompleteRequestRepositoryImpl.java | 170 ----------- .../CompleteRequestRepositryCustom.java | 11 - .../wrapper/CompleteRequestInfoDTO.java | 4 - .../wrapper/CompleteRequestSummaryDTO.java | 14 - .../HistoryListReadLimitResponseDTO.java | 10 - .../HistoryListReadPagingResponseDTO.java | 11 - .../nabimarketbe/jpa/dibs/entity/Dib.java | 52 ---- .../DibListReadPagingResponseDTO.java | 15 - .../projection/DibListReadResponseDTO.java | 29 -- .../jpa/dibs/repository/DibRepository.java | 14 - .../dibs/repository/DibRepositoryCustom.java | 11 - .../dibs/repository/DibRepositoryImpl.java | 80 ------ .../nabimarketbe/jpa/item/entity/Item.java | 74 ----- .../jpa/item/entity/PriceRange.java | 33 --- .../jpa/item/repository/ItemRepository.java | 7 - .../jpa/notification/entity/Notification.java | 59 ---- .../NotificationDetailResponseDTO.java | 20 -- .../NotificationPagingResponseDTO.java | 11 - .../repository/NotificationRepository.java | 19 -- .../NotificationRepositoryCustom.java | 15 - .../NotificationRepositoryImpl.java | 105 ------- .../jpa/refreshtoken/entity/RefreshToken.java | 43 --- .../repository/RefreshTokenRepository.java | 10 - .../jpa/suggestion/entity/DirectionType.java | 6 - .../jpa/suggestion/entity/Suggestion.java | 112 -------- .../suggestion/entity/SuggestionStatus.java | 7 - .../jpa/suggestion/entity/SuggestionType.java | 33 --- .../SuggestionDetailResponseDTO.java | 19 -- .../suggestion/projection/SuggestionInfo.java | 17 -- .../SuggestionListReadPagingResponseDTO.java | 9 - .../SuggestionListReadResponseDTO.java | 12 - .../repository/SuggestionRepository.java | 27 -- .../SuggestionRepositoryCustom.java | 16 -- .../repository/SuggestionRepositoryImpl.java | 168 ----------- .../nabimarketbe/jpa/user/entity/Role.java | 14 - .../nabimarketbe/jpa/user/entity/User.java | 118 -------- .../user/projection/UserIdResponseDTO.java | 4 - .../jpa/user/repository/UserRepository.java | 18 -- .../nabimarketbe/jpa/util/CursorPaging.java | 12 - .../nabimarketbe/jpa/util/KeyGenerator.java | 33 --- .../nabimarketbe/jpa/util/OrderCondition.java | 5 - .../nabimarketbe/jpa/util/QueryDslUtil.java | 54 ---- 87 files changed, 1 insertion(+), 2985 deletions(-) delete mode 100644 nabimarket-infra/src/main/java/org/prgrms/nabimarketbe/config/QuerydslConfig.java delete mode 100644 nabimarket-infra/src/main/java/org/prgrms/nabimarketbe/config/TestConfig.java delete mode 100644 nabimarket-infra/src/main/java/org/prgrms/nabimarketbe/jpa/BaseEntity.java delete mode 100644 nabimarket-infra/src/main/java/org/prgrms/nabimarketbe/jpa/card/entity/Card.java delete mode 100644 nabimarket-infra/src/main/java/org/prgrms/nabimarketbe/jpa/card/entity/CardStatus.java delete mode 100644 nabimarket-infra/src/main/java/org/prgrms/nabimarketbe/jpa/card/entity/TradeType.java delete mode 100644 nabimarket-infra/src/main/java/org/prgrms/nabimarketbe/jpa/card/projection/CardCondenseResponseDTO.java delete mode 100644 nabimarket-infra/src/main/java/org/prgrms/nabimarketbe/jpa/card/projection/CardFamousResponseDTO.java delete mode 100644 nabimarket-infra/src/main/java/org/prgrms/nabimarketbe/jpa/card/projection/CardInfoResponseDTO.java delete mode 100644 nabimarket-infra/src/main/java/org/prgrms/nabimarketbe/jpa/card/projection/CardListReadResponseDTO.java delete mode 100644 nabimarket-infra/src/main/java/org/prgrms/nabimarketbe/jpa/card/projection/CardListResponseDTO.java delete mode 100644 nabimarket-infra/src/main/java/org/prgrms/nabimarketbe/jpa/card/projection/CardPagingResponseDTO.java delete mode 100644 nabimarket-infra/src/main/java/org/prgrms/nabimarketbe/jpa/card/projection/CardSuggestionResponseDTO.java delete mode 100644 nabimarket-infra/src/main/java/org/prgrms/nabimarketbe/jpa/card/projection/CardSummaryResponseDTO.java delete mode 100644 nabimarket-infra/src/main/java/org/prgrms/nabimarketbe/jpa/card/projection/CardUserSummaryResponseDTO.java delete mode 100644 nabimarket-infra/src/main/java/org/prgrms/nabimarketbe/jpa/card/repository/CardRepository.java delete mode 100644 nabimarket-infra/src/main/java/org/prgrms/nabimarketbe/jpa/card/repository/CardRepositoryCustom.java delete mode 100644 nabimarket-infra/src/main/java/org/prgrms/nabimarketbe/jpa/card/repository/CardRepositoryImpl.java delete mode 100644 nabimarket-infra/src/main/java/org/prgrms/nabimarketbe/jpa/cardImage/entity/CardImage.java delete mode 100644 nabimarket-infra/src/main/java/org/prgrms/nabimarketbe/jpa/cardImage/repository/CardImageBatchRepository.java delete mode 100644 nabimarket-infra/src/main/java/org/prgrms/nabimarketbe/jpa/cardImage/repository/CardImageRepository.java delete mode 100644 nabimarket-infra/src/main/java/org/prgrms/nabimarketbe/jpa/category/entity/Category.java delete mode 100644 nabimarket-infra/src/main/java/org/prgrms/nabimarketbe/jpa/category/entity/CategoryEnum.java delete mode 100644 nabimarket-infra/src/main/java/org/prgrms/nabimarketbe/jpa/category/repository/CategoryRepository.java delete mode 100644 nabimarket-infra/src/main/java/org/prgrms/nabimarketbe/jpa/chatroom/entity/ChatRoom.java delete mode 100644 nabimarket-infra/src/main/java/org/prgrms/nabimarketbe/jpa/chatroom/projection/list/CardInfoListDTO.java delete mode 100644 nabimarket-infra/src/main/java/org/prgrms/nabimarketbe/jpa/chatroom/projection/list/ChatRoomInfoListDTO.java delete mode 100644 nabimarket-infra/src/main/java/org/prgrms/nabimarketbe/jpa/chatroom/projection/list/ChatRoomListWrapper.java delete mode 100644 nabimarket-infra/src/main/java/org/prgrms/nabimarketbe/jpa/chatroom/projection/list/FromCardInfoListDTO.java delete mode 100644 nabimarket-infra/src/main/java/org/prgrms/nabimarketbe/jpa/chatroom/projection/list/ToCardInfoListDTO.java delete mode 100644 nabimarket-infra/src/main/java/org/prgrms/nabimarketbe/jpa/chatroom/projection/list/UserInfoListDTO.java delete mode 100644 nabimarket-infra/src/main/java/org/prgrms/nabimarketbe/jpa/chatroom/projection/single/CardInfoDTO.java delete mode 100644 nabimarket-infra/src/main/java/org/prgrms/nabimarketbe/jpa/chatroom/projection/single/ChatRoomInfoDTO.java delete mode 100644 nabimarket-infra/src/main/java/org/prgrms/nabimarketbe/jpa/chatroom/projection/single/ChatRoomInfoWrapper.java delete mode 100644 nabimarket-infra/src/main/java/org/prgrms/nabimarketbe/jpa/chatroom/projection/single/FromCardInfoDTO.java delete mode 100644 nabimarket-infra/src/main/java/org/prgrms/nabimarketbe/jpa/chatroom/projection/single/ToCardInfoDTO.java delete mode 100644 nabimarket-infra/src/main/java/org/prgrms/nabimarketbe/jpa/chatroom/projection/single/UserInfoDTO.java delete mode 100644 nabimarket-infra/src/main/java/org/prgrms/nabimarketbe/jpa/chatroom/repository/ChatRoomRepository.java delete mode 100644 nabimarket-infra/src/main/java/org/prgrms/nabimarketbe/jpa/chatroom/repository/ChatRoomRepositoryCustom.java delete mode 100644 nabimarket-infra/src/main/java/org/prgrms/nabimarketbe/jpa/chatroom/repository/ChatRoomRepositoryImpl.java delete mode 100644 nabimarket-infra/src/main/java/org/prgrms/nabimarketbe/jpa/completerequest/entity/CompleteRequest.java delete mode 100644 nabimarket-infra/src/main/java/org/prgrms/nabimarketbe/jpa/completerequest/entity/CompleteRequestStatus.java delete mode 100644 nabimarket-infra/src/main/java/org/prgrms/nabimarketbe/jpa/completerequest/projection/HistoryListReadResponseDTO.java delete mode 100644 nabimarket-infra/src/main/java/org/prgrms/nabimarketbe/jpa/completerequest/repository/CompleteRequestRepository.java delete mode 100644 nabimarket-infra/src/main/java/org/prgrms/nabimarketbe/jpa/completerequest/repository/CompleteRequestRepositoryImpl.java delete mode 100644 nabimarket-infra/src/main/java/org/prgrms/nabimarketbe/jpa/completerequest/repository/CompleteRequestRepositryCustom.java delete mode 100644 nabimarket-infra/src/main/java/org/prgrms/nabimarketbe/jpa/completerequest/wrapper/CompleteRequestInfoDTO.java delete mode 100644 nabimarket-infra/src/main/java/org/prgrms/nabimarketbe/jpa/completerequest/wrapper/CompleteRequestSummaryDTO.java delete mode 100644 nabimarket-infra/src/main/java/org/prgrms/nabimarketbe/jpa/completerequest/wrapper/HistoryListReadLimitResponseDTO.java delete mode 100644 nabimarket-infra/src/main/java/org/prgrms/nabimarketbe/jpa/completerequest/wrapper/HistoryListReadPagingResponseDTO.java delete mode 100644 nabimarket-infra/src/main/java/org/prgrms/nabimarketbe/jpa/dibs/entity/Dib.java delete mode 100644 nabimarket-infra/src/main/java/org/prgrms/nabimarketbe/jpa/dibs/projection/DibListReadPagingResponseDTO.java delete mode 100644 nabimarket-infra/src/main/java/org/prgrms/nabimarketbe/jpa/dibs/projection/DibListReadResponseDTO.java delete mode 100644 nabimarket-infra/src/main/java/org/prgrms/nabimarketbe/jpa/dibs/repository/DibRepository.java delete mode 100644 nabimarket-infra/src/main/java/org/prgrms/nabimarketbe/jpa/dibs/repository/DibRepositoryCustom.java delete mode 100644 nabimarket-infra/src/main/java/org/prgrms/nabimarketbe/jpa/dibs/repository/DibRepositoryImpl.java delete mode 100644 nabimarket-infra/src/main/java/org/prgrms/nabimarketbe/jpa/item/entity/Item.java delete mode 100644 nabimarket-infra/src/main/java/org/prgrms/nabimarketbe/jpa/item/entity/PriceRange.java delete mode 100644 nabimarket-infra/src/main/java/org/prgrms/nabimarketbe/jpa/item/repository/ItemRepository.java delete mode 100644 nabimarket-infra/src/main/java/org/prgrms/nabimarketbe/jpa/notification/entity/Notification.java delete mode 100644 nabimarket-infra/src/main/java/org/prgrms/nabimarketbe/jpa/notification/projection/NotificationDetailResponseDTO.java delete mode 100644 nabimarket-infra/src/main/java/org/prgrms/nabimarketbe/jpa/notification/projection/NotificationPagingResponseDTO.java delete mode 100644 nabimarket-infra/src/main/java/org/prgrms/nabimarketbe/jpa/notification/repository/NotificationRepository.java delete mode 100644 nabimarket-infra/src/main/java/org/prgrms/nabimarketbe/jpa/notification/repository/NotificationRepositoryCustom.java delete mode 100644 nabimarket-infra/src/main/java/org/prgrms/nabimarketbe/jpa/notification/repository/NotificationRepositoryImpl.java delete mode 100644 nabimarket-infra/src/main/java/org/prgrms/nabimarketbe/jpa/refreshtoken/entity/RefreshToken.java delete mode 100644 nabimarket-infra/src/main/java/org/prgrms/nabimarketbe/jpa/refreshtoken/repository/RefreshTokenRepository.java delete mode 100644 nabimarket-infra/src/main/java/org/prgrms/nabimarketbe/jpa/suggestion/entity/DirectionType.java delete mode 100644 nabimarket-infra/src/main/java/org/prgrms/nabimarketbe/jpa/suggestion/entity/Suggestion.java delete mode 100644 nabimarket-infra/src/main/java/org/prgrms/nabimarketbe/jpa/suggestion/entity/SuggestionStatus.java delete mode 100644 nabimarket-infra/src/main/java/org/prgrms/nabimarketbe/jpa/suggestion/entity/SuggestionType.java delete mode 100644 nabimarket-infra/src/main/java/org/prgrms/nabimarketbe/jpa/suggestion/projection/SuggestionDetailResponseDTO.java delete mode 100644 nabimarket-infra/src/main/java/org/prgrms/nabimarketbe/jpa/suggestion/projection/SuggestionInfo.java delete mode 100644 nabimarket-infra/src/main/java/org/prgrms/nabimarketbe/jpa/suggestion/projection/SuggestionListReadPagingResponseDTO.java delete mode 100644 nabimarket-infra/src/main/java/org/prgrms/nabimarketbe/jpa/suggestion/projection/SuggestionListReadResponseDTO.java delete mode 100644 nabimarket-infra/src/main/java/org/prgrms/nabimarketbe/jpa/suggestion/repository/SuggestionRepository.java delete mode 100644 nabimarket-infra/src/main/java/org/prgrms/nabimarketbe/jpa/suggestion/repository/SuggestionRepositoryCustom.java delete mode 100644 nabimarket-infra/src/main/java/org/prgrms/nabimarketbe/jpa/suggestion/repository/SuggestionRepositoryImpl.java delete mode 100644 nabimarket-infra/src/main/java/org/prgrms/nabimarketbe/jpa/user/entity/Role.java delete mode 100644 nabimarket-infra/src/main/java/org/prgrms/nabimarketbe/jpa/user/entity/User.java delete mode 100644 nabimarket-infra/src/main/java/org/prgrms/nabimarketbe/jpa/user/projection/UserIdResponseDTO.java delete mode 100644 nabimarket-infra/src/main/java/org/prgrms/nabimarketbe/jpa/user/repository/UserRepository.java delete mode 100644 nabimarket-infra/src/main/java/org/prgrms/nabimarketbe/jpa/util/CursorPaging.java delete mode 100644 nabimarket-infra/src/main/java/org/prgrms/nabimarketbe/jpa/util/KeyGenerator.java delete mode 100644 nabimarket-infra/src/main/java/org/prgrms/nabimarketbe/jpa/util/OrderCondition.java delete mode 100644 nabimarket-infra/src/main/java/org/prgrms/nabimarketbe/jpa/util/QueryDslUtil.java diff --git a/nabimarket-infra/src/main/java/org/prgrms/nabimarketbe/aws/api/S3FileController.java b/nabimarket-infra/src/main/java/org/prgrms/nabimarketbe/aws/api/S3FileController.java index 8b5a7f88..d4c02947 100644 --- a/nabimarket-infra/src/main/java/org/prgrms/nabimarketbe/aws/api/S3FileController.java +++ b/nabimarket-infra/src/main/java/org/prgrms/nabimarketbe/aws/api/S3FileController.java @@ -1,4 +1,4 @@ -package org.prgrms.nabimarketbe.aws.api; +package org.prgrms.nabimarketbe.global.aws.api; import java.util.List; diff --git a/nabimarket-infra/src/main/java/org/prgrms/nabimarketbe/config/QuerydslConfig.java b/nabimarket-infra/src/main/java/org/prgrms/nabimarketbe/config/QuerydslConfig.java deleted file mode 100644 index 0c610a14..00000000 --- a/nabimarket-infra/src/main/java/org/prgrms/nabimarketbe/config/QuerydslConfig.java +++ /dev/null @@ -1,20 +0,0 @@ -package org.prgrms.nabimarketbe.config; - -import javax.persistence.EntityManager; -import javax.persistence.PersistenceContext; - -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; - -import com.querydsl.jpa.impl.JPAQueryFactory; - -@Configuration -public class QuerydslConfig { - @PersistenceContext - private EntityManager entityManager; - - @Bean - public JPAQueryFactory jpaQueryFactory() { - return new JPAQueryFactory(entityManager); - } -} diff --git a/nabimarket-infra/src/main/java/org/prgrms/nabimarketbe/config/TestConfig.java b/nabimarket-infra/src/main/java/org/prgrms/nabimarketbe/config/TestConfig.java deleted file mode 100644 index f0cb2fe7..00000000 --- a/nabimarket-infra/src/main/java/org/prgrms/nabimarketbe/config/TestConfig.java +++ /dev/null @@ -1,19 +0,0 @@ -// package org.prgrms.nabimarketbe.config; -// -// import com.querydsl.jpa.impl.JPAQueryFactory; -// import org.springframework.boot.test.context.TestConfiguration; -// import org.springframework.context.annotation.Bean; -// -// import javax.persistence.EntityManager; -// import javax.persistence.PersistenceContext; -// -// @TestConfiguration -// public class TestConfig { -// @PersistenceContext -// private EntityManager entityManager; -// -// @Bean -// public JPAQueryFactory jpaQueryFactory() { -// return new JPAQueryFactory(entityManager); -// } -// } diff --git a/nabimarket-infra/src/main/java/org/prgrms/nabimarketbe/jpa/BaseEntity.java b/nabimarket-infra/src/main/java/org/prgrms/nabimarketbe/jpa/BaseEntity.java deleted file mode 100644 index f966544f..00000000 --- a/nabimarket-infra/src/main/java/org/prgrms/nabimarketbe/jpa/BaseEntity.java +++ /dev/null @@ -1,42 +0,0 @@ - -package org.prgrms.nabimarketbe.jpa; - -import java.time.LocalDateTime; - -import javax.persistence.EntityListeners; -import javax.persistence.MappedSuperclass; -import javax.persistence.PrePersist; -import javax.persistence.PreUpdate; - -import org.springframework.data.annotation.CreatedDate; -import org.springframework.data.annotation.LastModifiedDate; -import org.springframework.data.jpa.domain.support.AuditingEntityListener; -import org.springframework.data.jpa.repository.config.EnableJpaAuditing; -import org.springframework.format.annotation.DateTimeFormat; - -import lombok.Getter; - -@EnableJpaAuditing -@Getter -@MappedSuperclass -@EntityListeners(AuditingEntityListener.class) -public abstract class BaseEntity { - @CreatedDate - @DateTimeFormat(pattern = "yyyy-MM-dd'T'HH:mm:ss") - private LocalDateTime createdDate; - - @LastModifiedDate - @DateTimeFormat(pattern = "yyyy-MM-dd'T'HH:mm:ss") - private LocalDateTime modifiedDate; - - @PrePersist - public void onPrePersist() { - this.createdDate = LocalDateTime.now().withNano(0); - this.modifiedDate = this.createdDate; - } - - @PreUpdate - public void onPreUpdate() { - this.modifiedDate = LocalDateTime.now().withNano(0); - } -} diff --git a/nabimarket-infra/src/main/java/org/prgrms/nabimarketbe/jpa/card/entity/Card.java b/nabimarket-infra/src/main/java/org/prgrms/nabimarketbe/jpa/card/entity/Card.java deleted file mode 100644 index 1aeb31e8..00000000 --- a/nabimarket-infra/src/main/java/org/prgrms/nabimarketbe/jpa/card/entity/Card.java +++ /dev/null @@ -1,172 +0,0 @@ -package org.prgrms.nabimarketbe.jpa.card.entity; - -import javax.persistence.Column; -import javax.persistence.Entity; -import javax.persistence.EnumType; -import javax.persistence.Enumerated; -import javax.persistence.FetchType; -import javax.persistence.GeneratedValue; -import javax.persistence.GenerationType; -import javax.persistence.Id; -import javax.persistence.JoinColumn; -import javax.persistence.Lob; -import javax.persistence.ManyToOne; -import javax.persistence.OneToOne; -import javax.persistence.Table; -import javax.validation.constraints.Min; -import javax.validation.constraints.NotBlank; -import javax.validation.constraints.NotNull; - -import org.prgrms.nabimarketbe.error.BaseException; -import org.prgrms.nabimarketbe.error.ErrorCode; -import org.prgrms.nabimarketbe.jpa.BaseEntity; -import org.prgrms.nabimarketbe.jpa.item.entity.Item; -import org.prgrms.nabimarketbe.jpa.user.entity.User; - -import lombok.AccessLevel; -import lombok.Builder; -import lombok.Getter; -import lombok.NoArgsConstructor; - -@Entity -@Table(name = "cards") -@Getter -@NoArgsConstructor(access = AccessLevel.PROTECTED) -public class Card extends BaseEntity { - @Id - @GeneratedValue(strategy = GenerationType.IDENTITY) - @Column(name = "card_id", nullable = false) - private Long cardId; - - @NotBlank(message = "공백을 허용하지 않습니다.") - @Column(name = "card_title", nullable = false, length = 30) - private String cardTitle; - - @Column(name = "thumbnail") - private String thumbnail; - - @NotBlank(message = "공백을 허용하지 않습니다.") - @Lob - @Column(name = "content", nullable = false, length = 255) - private String content; - - @Column(name = "trade_area", nullable = false, length = 30) - private String tradeArea; - - @NotNull(message = "비울 수 없는 값입니다.") - @Column(name = "poke_available", nullable = false) - private Boolean pokeAvailable; - - @Enumerated(EnumType.STRING) - @Column(name = "trade_type", nullable = false) - private TradeType tradeType; - - @Enumerated(EnumType.STRING) - @Column(name = "status", nullable = false) - private CardStatus status; - - @Min(value = 0, message = "최소 0 이상의 값이 필요합니다.") - @Column(name = "view_count", nullable = false) - private Integer viewCount; - - @Min(value = 0, message = "최소 0 이상의 값이 필요합니다.") - @Column(name = "dib_count", nullable = false) - private Integer dibCount; - - @Column(name = "is_active", nullable = false) - private Boolean isActive; - - @OneToOne(fetch = FetchType.LAZY) - @JoinColumn(name = "item_id") - private Item item; - - @ManyToOne(fetch = FetchType.LAZY) - @JoinColumn(name = "user_id") - private User user; - - @Builder - private Card( - String cardTitle, - String thumbnail, - String content, - String tradeArea, - Boolean pokeAvailable, - TradeType tradeType, - Item item, - User user - ) { - if (cardTitle.isBlank() || content.isBlank() || thumbnail.isBlank()) { - throw new BaseException(ErrorCode.INVALID_REQUEST); - } - - if (pokeAvailable == null || tradeType == null || tradeArea == null || item == null || user == null) { - throw new BaseException(ErrorCode.INVALID_REQUEST); - } - - this.cardTitle = cardTitle; - this.thumbnail = thumbnail; - this.content = content; - this.tradeArea = tradeArea; - this.pokeAvailable = pokeAvailable; - this.tradeType = tradeType; - this.status = CardStatus.TRADE_AVAILABLE; - this.viewCount = 0; - this.dibCount = 0; - this.isActive = true; - this.item = item; - this.user = user; - } - - public void updateThumbnail(String url) { - this.thumbnail = url; - } - - public void updateViewCount() { - this.viewCount += 1; - } - - // TODO : dibCount 동시성 - public void increaseDibCount() { - this.dibCount += 1; - } - - public void decreaseDibCount() { - this.dibCount -= 1; - } - - public void updateCardStatusToTradeAvailable() { - this.status = CardStatus.TRADE_AVAILABLE; - } - - public void updateCardStatusToReserved() { - this.status = CardStatus.RESERVED; - } - - public void updateCardStatusToTradeComplete() { - this.status = CardStatus.TRADE_COMPLETE; - } - - public void deleteCard() { - this.isActive = false; - } - - public Boolean isPokeAvailable() { - return pokeAvailable; - } - - public void updateCard( - String cardTitle, - String thumbnail, - Boolean pokeAvailable, - String content, - TradeType tradeType, - String tradeArea - ) { - this.cardTitle = cardTitle; - this.thumbnail = thumbnail; - this.pokeAvailable = pokeAvailable; - this.content = content; - this.tradeType = tradeType; - this.tradeArea = tradeArea; - } -} diff --git a/nabimarket-infra/src/main/java/org/prgrms/nabimarketbe/jpa/card/entity/CardStatus.java b/nabimarket-infra/src/main/java/org/prgrms/nabimarketbe/jpa/card/entity/CardStatus.java deleted file mode 100644 index 92d3aa47..00000000 --- a/nabimarket-infra/src/main/java/org/prgrms/nabimarketbe/jpa/card/entity/CardStatus.java +++ /dev/null @@ -1,7 +0,0 @@ -package org.prgrms.nabimarketbe.jpa.card.entity; - -public enum CardStatus { - TRADE_AVAILABLE, - RESERVED, - TRADE_COMPLETE -} diff --git a/nabimarket-infra/src/main/java/org/prgrms/nabimarketbe/jpa/card/entity/TradeType.java b/nabimarket-infra/src/main/java/org/prgrms/nabimarketbe/jpa/card/entity/TradeType.java deleted file mode 100644 index c42fe987..00000000 --- a/nabimarket-infra/src/main/java/org/prgrms/nabimarketbe/jpa/card/entity/TradeType.java +++ /dev/null @@ -1,6 +0,0 @@ -package org.prgrms.nabimarketbe.jpa.card.entity; - -public enum TradeType { - DIRECT_DEALING, - SHIPPING -} diff --git a/nabimarket-infra/src/main/java/org/prgrms/nabimarketbe/jpa/card/projection/CardCondenseResponseDTO.java b/nabimarket-infra/src/main/java/org/prgrms/nabimarketbe/jpa/card/projection/CardCondenseResponseDTO.java deleted file mode 100644 index dab5a238..00000000 --- a/nabimarket-infra/src/main/java/org/prgrms/nabimarketbe/jpa/card/projection/CardCondenseResponseDTO.java +++ /dev/null @@ -1,22 +0,0 @@ -package org.prgrms.nabimarketbe.jpa.card.projection; - -import org.prgrms.nabimarketbe.jpa.card.entity.Card; - -import lombok.Builder; - -@Builder -public record CardCondenseResponseDTO( - Long cardId, - - String itemName, - - String thumbnail -) { - public static CardCondenseResponseDTO from(Card card) { - return CardCondenseResponseDTO.builder() - .cardId(card.getCardId()) - .itemName(card.getItem().getItemName()) - .thumbnail(card.getThumbnail()) - .build(); - } -} diff --git a/nabimarket-infra/src/main/java/org/prgrms/nabimarketbe/jpa/card/projection/CardFamousResponseDTO.java b/nabimarket-infra/src/main/java/org/prgrms/nabimarketbe/jpa/card/projection/CardFamousResponseDTO.java deleted file mode 100644 index dcad9c8c..00000000 --- a/nabimarket-infra/src/main/java/org/prgrms/nabimarketbe/jpa/card/projection/CardFamousResponseDTO.java +++ /dev/null @@ -1,16 +0,0 @@ -package org.prgrms.nabimarketbe.jpa.card.projection; - -import org.prgrms.nabimarketbe.jpa.item.entity.PriceRange; - -import lombok.Getter; - -@Getter -public class CardFamousResponseDTO { - private Long cardId; - - private String itemName; - - private PriceRange priceRange; - - private String thumbnail; -} diff --git a/nabimarket-infra/src/main/java/org/prgrms/nabimarketbe/jpa/card/projection/CardInfoResponseDTO.java b/nabimarket-infra/src/main/java/org/prgrms/nabimarketbe/jpa/card/projection/CardInfoResponseDTO.java deleted file mode 100644 index c47e6dd4..00000000 --- a/nabimarket-infra/src/main/java/org/prgrms/nabimarketbe/jpa/card/projection/CardInfoResponseDTO.java +++ /dev/null @@ -1,18 +0,0 @@ -package org.prgrms.nabimarketbe.jpa.card.projection; - -import org.prgrms.nabimarketbe.jpa.item.entity.PriceRange; - -import lombok.Getter; - -@Getter -public class CardInfoResponseDTO { - private Long cardId; - - private String thumbnail; - - private String cardTitle; - - private String itemName; - - private PriceRange priceRange; -} diff --git a/nabimarket-infra/src/main/java/org/prgrms/nabimarketbe/jpa/card/projection/CardListReadResponseDTO.java b/nabimarket-infra/src/main/java/org/prgrms/nabimarketbe/jpa/card/projection/CardListReadResponseDTO.java deleted file mode 100644 index 8c57a09e..00000000 --- a/nabimarket-infra/src/main/java/org/prgrms/nabimarketbe/jpa/card/projection/CardListReadResponseDTO.java +++ /dev/null @@ -1,29 +0,0 @@ -package org.prgrms.nabimarketbe.jpa.card.projection; - -import java.time.LocalDateTime; - -import org.prgrms.nabimarketbe.jpa.card.entity.CardStatus; -import org.prgrms.nabimarketbe.jpa.item.entity.PriceRange; - -import lombok.Getter; -import lombok.NoArgsConstructor; - -@NoArgsConstructor -@Getter -public class CardListReadResponseDTO { - private Long cardId; - - private String cardTitle; - - private String itemName; - - private PriceRange priceRange; - - private String thumbnail; - - private CardStatus status; - - private LocalDateTime createdAt; - - private LocalDateTime modifiedAt; -} diff --git a/nabimarket-infra/src/main/java/org/prgrms/nabimarketbe/jpa/card/projection/CardListResponseDTO.java b/nabimarket-infra/src/main/java/org/prgrms/nabimarketbe/jpa/card/projection/CardListResponseDTO.java deleted file mode 100644 index ef2ced98..00000000 --- a/nabimarket-infra/src/main/java/org/prgrms/nabimarketbe/jpa/card/projection/CardListResponseDTO.java +++ /dev/null @@ -1,8 +0,0 @@ -package org.prgrms.nabimarketbe.jpa.card.projection; - -import java.util.List; - -public record CardListResponseDTO( - List cardList -) { -} diff --git a/nabimarket-infra/src/main/java/org/prgrms/nabimarketbe/jpa/card/projection/CardPagingResponseDTO.java b/nabimarket-infra/src/main/java/org/prgrms/nabimarketbe/jpa/card/projection/CardPagingResponseDTO.java deleted file mode 100644 index 4f4168dc..00000000 --- a/nabimarket-infra/src/main/java/org/prgrms/nabimarketbe/jpa/card/projection/CardPagingResponseDTO.java +++ /dev/null @@ -1,9 +0,0 @@ -package org.prgrms.nabimarketbe.jpa.card.projection; - -import java.util.List; - -public record CardPagingResponseDTO( - List cardList, - String nextCursorId -) { -} diff --git a/nabimarket-infra/src/main/java/org/prgrms/nabimarketbe/jpa/card/projection/CardSuggestionResponseDTO.java b/nabimarket-infra/src/main/java/org/prgrms/nabimarketbe/jpa/card/projection/CardSuggestionResponseDTO.java deleted file mode 100644 index 044b0db3..00000000 --- a/nabimarket-infra/src/main/java/org/prgrms/nabimarketbe/jpa/card/projection/CardSuggestionResponseDTO.java +++ /dev/null @@ -1,14 +0,0 @@ -package org.prgrms.nabimarketbe.jpa.card.projection; - -import org.prgrms.nabimarketbe.jpa.suggestion.projection.SuggestionInfo; - -import lombok.Getter; -import lombok.NoArgsConstructor; - -@Getter -@NoArgsConstructor -public class CardSuggestionResponseDTO { - private CardInfoResponseDTO cardInfo; - - private SuggestionInfo suggestionInfo; -} diff --git a/nabimarket-infra/src/main/java/org/prgrms/nabimarketbe/jpa/card/projection/CardSummaryResponseDTO.java b/nabimarket-infra/src/main/java/org/prgrms/nabimarketbe/jpa/card/projection/CardSummaryResponseDTO.java deleted file mode 100644 index 953eaa47..00000000 --- a/nabimarket-infra/src/main/java/org/prgrms/nabimarketbe/jpa/card/projection/CardSummaryResponseDTO.java +++ /dev/null @@ -1,16 +0,0 @@ -package org.prgrms.nabimarketbe.jpa.card.projection; - -import org.prgrms.nabimarketbe.jpa.item.entity.PriceRange; - -import lombok.Getter; - -@Getter -public class CardSummaryResponseDTO { - private Long cardId; - - private String itemName; - - private String thumbnail; - - private PriceRange priceRange; -} diff --git a/nabimarket-infra/src/main/java/org/prgrms/nabimarketbe/jpa/card/projection/CardUserSummaryResponseDTO.java b/nabimarket-infra/src/main/java/org/prgrms/nabimarketbe/jpa/card/projection/CardUserSummaryResponseDTO.java deleted file mode 100644 index e6cf61a7..00000000 --- a/nabimarket-infra/src/main/java/org/prgrms/nabimarketbe/jpa/card/projection/CardUserSummaryResponseDTO.java +++ /dev/null @@ -1,9 +0,0 @@ -package org.prgrms.nabimarketbe.jpa.card.projection; - -import org.prgrms.nabimarketbe.jpa.user.projection.UserIdResponseDTO; - -public record CardUserSummaryResponseDTO( - CardCondenseResponseDTO cardInfo, - UserIdResponseDTO userInfo -) { -} diff --git a/nabimarket-infra/src/main/java/org/prgrms/nabimarketbe/jpa/card/repository/CardRepository.java b/nabimarket-infra/src/main/java/org/prgrms/nabimarketbe/jpa/card/repository/CardRepository.java deleted file mode 100644 index 9c897a27..00000000 --- a/nabimarket-infra/src/main/java/org/prgrms/nabimarketbe/jpa/card/repository/CardRepository.java +++ /dev/null @@ -1,28 +0,0 @@ -package org.prgrms.nabimarketbe.jpa.card.repository; - -import java.util.Optional; - -import org.prgrms.nabimarketbe.jpa.card.entity.Card; -import org.prgrms.nabimarketbe.jpa.user.entity.User; -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; - -public interface CardRepository extends JpaRepository, CardRepositoryCustom { - @Query("SELECT c FROM Card c WHERE c.cardId = :cardId AND c.user = :user AND c.isActive = true") - Optional findByCardIdAndUser(@Param("cardId") Long cardId, @Param("user") User user); - - @Query("SELECT c FROM Card c WHERE c.cardId = :cardId AND c.isActive = true") - Optional findActiveCardById(@Param("cardId") Long cardId); - - @Query("SELECT c FROM Card c WHERE c.cardId = :cardId") - Optional findExistingCardById(@Param("cardId") Long cardId); - - @Query("SELECT c.viewCount FROM Card c WHERE c.cardId = :cardId") - Integer getCardViewCountById(@Param("cardId") Long cardId); - - @Query("UPDATE Card c SET c.viewCount = :viewCount WHERE c.cardId = :cardId") - @Modifying(clearAutomatically = true) - void updateViewCountByCardId(@Param("cardId") Long cardId, @Param("viewCount") Integer viewCount); -} diff --git a/nabimarket-infra/src/main/java/org/prgrms/nabimarketbe/jpa/card/repository/CardRepositoryCustom.java b/nabimarket-infra/src/main/java/org/prgrms/nabimarketbe/jpa/card/repository/CardRepositoryCustom.java deleted file mode 100644 index 7d35379f..00000000 --- a/nabimarket-infra/src/main/java/org/prgrms/nabimarketbe/jpa/card/repository/CardRepositoryCustom.java +++ /dev/null @@ -1,37 +0,0 @@ -package org.prgrms.nabimarketbe.jpa.card.repository; - -import java.util.List; - -import org.prgrms.nabimarketbe.jpa.card.projection.CardFamousResponseDTO; -import org.prgrms.nabimarketbe.jpa.card.projection.CardPagingResponseDTO; -import org.prgrms.nabimarketbe.jpa.card.projection.CardSuggestionResponseDTO; -import org.prgrms.nabimarketbe.jpa.card.entity.CardStatus; -import org.prgrms.nabimarketbe.jpa.category.entity.CategoryEnum; -import org.prgrms.nabimarketbe.jpa.item.entity.PriceRange; -import org.prgrms.nabimarketbe.jpa.user.entity.User; -import org.springframework.data.domain.Pageable; - -public interface CardRepositoryCustom { - CardPagingResponseDTO getCardsByCondition( - CategoryEnum category, - PriceRange priceRange, - List status, - String title, - String cursorId, - Pageable pageable - ); - - CardPagingResponseDTO getMyCardsByStatus( - User user, - CardStatus status, - String cursorId, - Integer size - ); - - List getSuggestionAvailableCards( - Long userId, - Long targetCardId - ); - - List getCardsByPopularity(); -} diff --git a/nabimarket-infra/src/main/java/org/prgrms/nabimarketbe/jpa/card/repository/CardRepositoryImpl.java b/nabimarket-infra/src/main/java/org/prgrms/nabimarketbe/jpa/card/repository/CardRepositoryImpl.java deleted file mode 100644 index c01ac77b..00000000 --- a/nabimarket-infra/src/main/java/org/prgrms/nabimarketbe/jpa/card/repository/CardRepositoryImpl.java +++ /dev/null @@ -1,267 +0,0 @@ -package org.prgrms.nabimarketbe.jpa.card.repository; - -import static org.prgrms.nabimarketbe.jpa.card.entity.QCard.card; -import static org.prgrms.nabimarketbe.jpa.item.entity.QItem.item; -import static org.prgrms.nabimarketbe.jpa.suggestion.entity.QSuggestion.suggestion; - -import java.util.List; - -import org.prgrms.nabimarketbe.jpa.card.entity.CardStatus; -import org.prgrms.nabimarketbe.jpa.card.projection.CardFamousResponseDTO; -import org.prgrms.nabimarketbe.jpa.card.projection.CardInfoResponseDTO; -import org.prgrms.nabimarketbe.jpa.card.projection.CardListReadResponseDTO; -import org.prgrms.nabimarketbe.jpa.card.projection.CardPagingResponseDTO; -import org.prgrms.nabimarketbe.jpa.card.projection.CardSuggestionResponseDTO; -import org.prgrms.nabimarketbe.jpa.category.entity.CategoryEnum; -import org.prgrms.nabimarketbe.jpa.item.entity.PriceRange; -import org.prgrms.nabimarketbe.jpa.suggestion.projection.SuggestionInfo; -import org.prgrms.nabimarketbe.jpa.user.entity.User; -import org.prgrms.nabimarketbe.jpa.util.CursorPaging; -import org.prgrms.nabimarketbe.jpa.util.QueryDslUtil; -import org.springframework.data.domain.Pageable; -import org.springframework.data.domain.Sort; - -import com.querydsl.core.types.ConstantImpl; -import com.querydsl.core.types.Projections; -import com.querydsl.core.types.dsl.BooleanExpression; -import com.querydsl.core.types.dsl.Expressions; -import com.querydsl.core.types.dsl.StringExpression; -import com.querydsl.core.types.dsl.StringExpressions; -import com.querydsl.core.types.dsl.StringTemplate; -import com.querydsl.jpa.impl.JPAQueryFactory; - -import lombok.RequiredArgsConstructor; - -@RequiredArgsConstructor -public class CardRepositoryImpl implements CardRepositoryCustom, CursorPaging { - private static final int FAMOUS_CARD_SIZE = 5; - - private final JPAQueryFactory jpaQueryFactory; - - @Override - public CardPagingResponseDTO getCardsByCondition( - CategoryEnum category, - PriceRange priceRange, - List status, - String cardTitle, - String cursorId, - Pageable pageable - ) { - List cardList = jpaQueryFactory.select( - Projections.fields( - CardListReadResponseDTO.class, - card.cardId, - card.cardTitle, - item.itemName, - item.priceRange, - card.thumbnail, - card.status, - card.createdDate.as("createdAt"), - card.modifiedDate.as("modifiedAt") - ) - ) - .from(card) - .leftJoin(item).on(card.item.itemId.eq(item.itemId)) - .where( - cursorId(cursorId), - categoryEquals(category), - statusEquals(status), - priceRangeEquals(priceRange), - titleEquals(cardTitle), - isCardActive() - ) - .orderBy(QueryDslUtil.getOrderSpecifier(pageable.getSort(), card)) - .limit(pageable.getPageSize()) - .fetch(); - - String nextCursor = - cardList.size() < pageable.getPageSize() ? null : generateCursor(cardList.get(cardList.size() - 1)); - - return new CardPagingResponseDTO(cardList, nextCursor); - } - - @Override - public CardPagingResponseDTO getMyCardsByStatus( - User user, - CardStatus status, - String cursorId, - Integer size - ) { - List cardList = jpaQueryFactory.select( - Projections.fields( - CardListReadResponseDTO.class, - card.cardId, - card.cardTitle, - item.itemName, - item.priceRange, - card.thumbnail, - card.status, - card.createdDate.as("createdAt"), - card.modifiedDate.as("modifiedAt") - ) - ) - .from(card) - .leftJoin(item).on(card.item.itemId.eq(item.itemId)) - .where( - cursorId(cursorId), - card.status.eq(status), - card.user.eq(user), - isCardActive() - ) - .orderBy( - QueryDslUtil.getOrderSpecifier( - Sort.by( - Sort.Order.desc("createdDate"), - Sort.Order.desc("cardId") - ), - card - ) - ) - .limit(size) - .fetch(); - - String nextCursor = cardList.size() < size ? null : generateCursor(cardList.get(cardList.size() - 1)); - - return new CardPagingResponseDTO(cardList, nextCursor); - } - - @Override - public List getSuggestionAvailableCards( - Long userId, - Long targetCardId - ) { - List cardList = jpaQueryFactory - .select( - Projections.fields( - CardSuggestionResponseDTO.class, - Projections.fields( - CardInfoResponseDTO.class, - card.cardId, - card.thumbnail, - card.cardTitle, - card.item.itemName, - card.item.priceRange - ).as("cardInfo"), - Projections.fields( - SuggestionInfo.class, - suggestion.suggestionType, - suggestion.suggestionStatus - ).as("suggestionInfo") - ) - ) - .from(card) - .leftJoin(suggestion).on(suggestion.fromCard.cardId.eq(card.cardId)) - .where( - card.user.userId.eq(userId), - isCardActive() - ) - .distinct() - .on(suggestion.toCard.cardId.eq(targetCardId)) - .fetch(); - - return cardList; - } - - @Override - public BooleanExpression cursorId(String cursorId) { - if (cursorId == null) { - return null; - } - - // 생성일자 - StringTemplate dateCursorTemplate = Expressions.stringTemplate( - "DATE_FORMAT({0}, {1})", - card.createdDate, - ConstantImpl.create("%Y%m%d%H%i%s") - ); - - // pk - StringExpression pkCursorTemplate = StringExpressions.lpad( - card.cardId.stringValue(), - 8, - '0' - ); - - return dateCursorTemplate.concat(pkCursorTemplate).lt(cursorId); - } - - @Override - public List getCardsByPopularity() { - List cardList = jpaQueryFactory - .select( - Projections.fields( - CardFamousResponseDTO.class, - card.cardId, - card.item.itemName, - card.item.priceRange, - card.thumbnail - ) - ) - .from(card) - .where( - statusEquals(CardStatus.TRADE_AVAILABLE), - isCardActive() - ) - .orderBy(card.viewCount.desc(), card.dibCount.desc()) - .limit(FAMOUS_CARD_SIZE) - .fetch(); - - return cardList; - } - - private BooleanExpression statusEquals(CardStatus status) { - if (status == null) { - return null; - } - - return card.status.eq(status); - } - - private BooleanExpression categoryEquals(CategoryEnum category) { - if (category == null) { - return null; - } - - return item.category.categoryName.eq(category); - } - - private BooleanExpression statusEquals(List statuses) { - if (statuses == null || statuses.isEmpty()) { - return null; - } - - BooleanExpression[] expressions = statuses.stream() - .map(card.status::eq) - .toArray(BooleanExpression[]::new); - - return Expressions.anyOf(expressions); - } - - private BooleanExpression priceRangeEquals(PriceRange priceRange) { - if (priceRange == null) { - return null; - } - - return item.priceRange.eq(priceRange); - } - - private BooleanExpression titleEquals(String title) { - if (title == null) { - return null; - } - - return card.cardTitle.contains(title); - } - - private BooleanExpression isCardActive() { - return card.isActive.eq(true); - } - - private String generateCursor(CardListReadResponseDTO cardListReadResponseDTO) { - return cardListReadResponseDTO.getCreatedAt().toString() // 디폴트는 생성일자 최신순 정렬 - .replace("T", "") - .replace("-", "") - .replace(":", "") - + String.format("%08d", cardListReadResponseDTO.getCardId()); - } -} diff --git a/nabimarket-infra/src/main/java/org/prgrms/nabimarketbe/jpa/cardImage/entity/CardImage.java b/nabimarket-infra/src/main/java/org/prgrms/nabimarketbe/jpa/cardImage/entity/CardImage.java deleted file mode 100644 index 95344a48..00000000 --- a/nabimarket-infra/src/main/java/org/prgrms/nabimarketbe/jpa/cardImage/entity/CardImage.java +++ /dev/null @@ -1,58 +0,0 @@ -package org.prgrms.nabimarketbe.jpa.cardImage.entity; - -import javax.persistence.Column; -import javax.persistence.Entity; -import javax.persistence.FetchType; -import javax.persistence.GeneratedValue; -import javax.persistence.GenerationType; -import javax.persistence.Id; -import javax.persistence.JoinColumn; -import javax.persistence.ManyToOne; -import javax.persistence.Table; -import javax.validation.constraints.NotBlank; - -import org.prgrms.nabimarketbe.jpa.BaseEntity; -import org.prgrms.nabimarketbe.jpa.card.entity.Card; -import org.prgrms.nabimarketbe.error.BaseException; -import org.prgrms.nabimarketbe.error.ErrorCode; - -import lombok.AccessLevel; -import lombok.Builder; -import lombok.Getter; -import lombok.NoArgsConstructor; - -@Entity -@Table(name = "card_images") -@NoArgsConstructor(access = AccessLevel.PROTECTED) -@Getter -public class CardImage extends BaseEntity { - @Id - @GeneratedValue(strategy = GenerationType.IDENTITY) - @Column(name = "card_image_id", nullable = false) - private Long cardImageId; - - @NotBlank(message = "공백을 허용하지 않습니다.") - @Column(name = "image_url", nullable = false) - private String imageUrl; - - @ManyToOne(fetch = FetchType.LAZY) - @JoinColumn(name = "card_id") - private Card card; - - @Builder - public CardImage( - String imageUrl, - Card card - ) { - if (imageUrl.isBlank()) { - throw new BaseException(ErrorCode.INVALID_REQUEST); - } - - if (card == null) { - throw new BaseException(ErrorCode.INVALID_REQUEST); - } - - this.imageUrl = imageUrl; - this.card = card; - } -} diff --git a/nabimarket-infra/src/main/java/org/prgrms/nabimarketbe/jpa/cardImage/repository/CardImageBatchRepository.java b/nabimarket-infra/src/main/java/org/prgrms/nabimarketbe/jpa/cardImage/repository/CardImageBatchRepository.java deleted file mode 100644 index b7a69d5f..00000000 --- a/nabimarket-infra/src/main/java/org/prgrms/nabimarketbe/jpa/cardImage/repository/CardImageBatchRepository.java +++ /dev/null @@ -1,36 +0,0 @@ -package org.prgrms.nabimarketbe.jpa.cardImage.repository; - -import java.sql.PreparedStatement; -import java.sql.Timestamp; -import java.time.LocalDateTime; -import java.util.List; - -import org.prgrms.nabimarketbe.jpa.cardImage.entity.CardImage; -import org.springframework.jdbc.core.JdbcTemplate; -import org.springframework.stereotype.Repository; -import org.springframework.transaction.annotation.Transactional; - -import lombok.RequiredArgsConstructor; - -@Repository -@RequiredArgsConstructor -public class CardImageBatchRepository { - - private final JdbcTemplate jdbcTemplate; - - private static final String sql = "INSERT INTO card_images (created_date, modified_date, image_url, card_id) VALUES (?, ?, ?, ?)"; - - @Transactional - public void saveAll(List cardImages) { - jdbcTemplate.batchUpdate( - sql, - cardImages, - cardImages.size(), - (PreparedStatement preparedStatement, CardImage cardImage) -> { - preparedStatement.setTimestamp(1, Timestamp.valueOf(LocalDateTime.now())); - preparedStatement.setTimestamp(2, Timestamp.valueOf(LocalDateTime.now())); - preparedStatement.setString(3, cardImage.getImageUrl()); - preparedStatement.setLong(4, cardImage.getCard().getCardId()); - }); - } -} diff --git a/nabimarket-infra/src/main/java/org/prgrms/nabimarketbe/jpa/cardImage/repository/CardImageRepository.java b/nabimarket-infra/src/main/java/org/prgrms/nabimarketbe/jpa/cardImage/repository/CardImageRepository.java deleted file mode 100644 index d3331223..00000000 --- a/nabimarket-infra/src/main/java/org/prgrms/nabimarketbe/jpa/cardImage/repository/CardImageRepository.java +++ /dev/null @@ -1,13 +0,0 @@ -package org.prgrms.nabimarketbe.jpa.cardImage.repository; - -import java.util.List; - -import org.prgrms.nabimarketbe.jpa.card.entity.Card; -import org.prgrms.nabimarketbe.jpa.cardImage.entity.CardImage; -import org.springframework.data.jpa.repository.JpaRepository; - -public interface CardImageRepository extends JpaRepository { - List findAllByCard(Card card); - - void deleteAllByCard(Card card); -} diff --git a/nabimarket-infra/src/main/java/org/prgrms/nabimarketbe/jpa/category/entity/Category.java b/nabimarket-infra/src/main/java/org/prgrms/nabimarketbe/jpa/category/entity/Category.java deleted file mode 100644 index 8c600ffa..00000000 --- a/nabimarket-infra/src/main/java/org/prgrms/nabimarketbe/jpa/category/entity/Category.java +++ /dev/null @@ -1,32 +0,0 @@ -package org.prgrms.nabimarketbe.jpa.category.entity; - -import javax.persistence.Column; -import javax.persistence.Entity; -import javax.persistence.EnumType; -import javax.persistence.Enumerated; -import javax.persistence.GeneratedValue; -import javax.persistence.GenerationType; -import javax.persistence.Id; -import javax.persistence.Table; - -import lombok.Getter; -import lombok.NoArgsConstructor; - -@Entity -@Table(name = "categories") -@Getter -@NoArgsConstructor -public class Category { - @Id - @GeneratedValue(strategy = GenerationType.IDENTITY) - @Column(name = "category_id", nullable = false) - private Long categoryId; - - @Enumerated(EnumType.STRING) - @Column(name = "category_name", nullable = false, unique = true) - private CategoryEnum categoryName; - - public Category(CategoryEnum categoryName) { - this.categoryName = categoryName; - } -} diff --git a/nabimarket-infra/src/main/java/org/prgrms/nabimarketbe/jpa/category/entity/CategoryEnum.java b/nabimarket-infra/src/main/java/org/prgrms/nabimarketbe/jpa/category/entity/CategoryEnum.java deleted file mode 100644 index 592eef9f..00000000 --- a/nabimarket-infra/src/main/java/org/prgrms/nabimarketbe/jpa/category/entity/CategoryEnum.java +++ /dev/null @@ -1,13 +0,0 @@ -package org.prgrms.nabimarketbe.jpa.category.entity; - -public enum CategoryEnum { - MALE_CLOTHES, - FEMALE_CLOTHES, - GOODS_ACCESSORY, - SHOES, - SPORTS, - BOOKS, - ELECTRONICS, - FURNITURE_INTERIOR, - HOME_ELECTRONICS -} diff --git a/nabimarket-infra/src/main/java/org/prgrms/nabimarketbe/jpa/category/repository/CategoryRepository.java b/nabimarket-infra/src/main/java/org/prgrms/nabimarketbe/jpa/category/repository/CategoryRepository.java deleted file mode 100644 index d007dff6..00000000 --- a/nabimarket-infra/src/main/java/org/prgrms/nabimarketbe/jpa/category/repository/CategoryRepository.java +++ /dev/null @@ -1,11 +0,0 @@ -package org.prgrms.nabimarketbe.jpa.category.repository; - -import java.util.Optional; - -import org.prgrms.nabimarketbe.jpa.category.entity.Category; -import org.prgrms.nabimarketbe.jpa.category.entity.CategoryEnum; -import org.springframework.data.jpa.repository.JpaRepository; - -public interface CategoryRepository extends JpaRepository { - Optional findCategoryByCategoryName(CategoryEnum categoryEnum); -} diff --git a/nabimarket-infra/src/main/java/org/prgrms/nabimarketbe/jpa/chatroom/entity/ChatRoom.java b/nabimarket-infra/src/main/java/org/prgrms/nabimarketbe/jpa/chatroom/entity/ChatRoom.java deleted file mode 100644 index 6af59777..00000000 --- a/nabimarket-infra/src/main/java/org/prgrms/nabimarketbe/jpa/chatroom/entity/ChatRoom.java +++ /dev/null @@ -1,45 +0,0 @@ -package org.prgrms.nabimarketbe.jpa.chatroom.entity; - -import javax.persistence.Column; -import javax.persistence.Entity; -import javax.persistence.FetchType; -import javax.persistence.GeneratedValue; -import javax.persistence.GenerationType; -import javax.persistence.Id; -import javax.persistence.JoinColumn; -import javax.persistence.OneToOne; -import javax.persistence.Table; -import javax.validation.constraints.NotBlank; - -import org.prgrms.nabimarketbe.jpa.BaseEntity; -import org.prgrms.nabimarketbe.jpa.suggestion.entity.Suggestion; - -import lombok.Getter; -import lombok.NoArgsConstructor; - -@Entity -@Table(name = "chat_rooms") -@NoArgsConstructor -@Getter -public class ChatRoom extends BaseEntity { - @Id - @GeneratedValue(strategy = GenerationType.IDENTITY) - @Column(name = "chat_room_id") - private Long chatRoomId; - - @NotBlank - @Column(nullable = false, name = "firestore_chat_room_path", unique = true) - private String fireStoreChatRoomPath; - - @OneToOne(fetch = FetchType.LAZY) - @JoinColumn(nullable = false, name = "suggestion_id", unique = true) - private Suggestion suggestion; - - public ChatRoom( - String fireStoreChatRoomPath, - Suggestion suggestion - ) { - this.fireStoreChatRoomPath = fireStoreChatRoomPath; - this.suggestion = suggestion; - } -} diff --git a/nabimarket-infra/src/main/java/org/prgrms/nabimarketbe/jpa/chatroom/projection/list/CardInfoListDTO.java b/nabimarket-infra/src/main/java/org/prgrms/nabimarketbe/jpa/chatroom/projection/list/CardInfoListDTO.java deleted file mode 100644 index cbf5106a..00000000 --- a/nabimarket-infra/src/main/java/org/prgrms/nabimarketbe/jpa/chatroom/projection/list/CardInfoListDTO.java +++ /dev/null @@ -1,16 +0,0 @@ -package org.prgrms.nabimarketbe.jpa.chatroom.projection.list; - -import org.prgrms.nabimarketbe.jpa.item.entity.PriceRange; - -import lombok.Getter; - -@Getter -public class CardInfoListDTO { - private Long cardId; - - private String itemName; - - private PriceRange priceRange; - - private String thumbnail; -} diff --git a/nabimarket-infra/src/main/java/org/prgrms/nabimarketbe/jpa/chatroom/projection/list/ChatRoomInfoListDTO.java b/nabimarket-infra/src/main/java/org/prgrms/nabimarketbe/jpa/chatroom/projection/list/ChatRoomInfoListDTO.java deleted file mode 100644 index 98b9d211..00000000 --- a/nabimarket-infra/src/main/java/org/prgrms/nabimarketbe/jpa/chatroom/projection/list/ChatRoomInfoListDTO.java +++ /dev/null @@ -1,16 +0,0 @@ -package org.prgrms.nabimarketbe.jpa.chatroom.projection.list; - -import java.time.LocalDateTime; - -import lombok.Getter; - -@Getter -public class ChatRoomInfoListDTO { - private Long chatRoomId; - - private LocalDateTime createdAt; - - private FromCardInfoListDTO fromCardInfo; - - private ToCardInfoListDTO toCardInfo; -} diff --git a/nabimarket-infra/src/main/java/org/prgrms/nabimarketbe/jpa/chatroom/projection/list/ChatRoomListWrapper.java b/nabimarket-infra/src/main/java/org/prgrms/nabimarketbe/jpa/chatroom/projection/list/ChatRoomListWrapper.java deleted file mode 100644 index f1fef949..00000000 --- a/nabimarket-infra/src/main/java/org/prgrms/nabimarketbe/jpa/chatroom/projection/list/ChatRoomListWrapper.java +++ /dev/null @@ -1,14 +0,0 @@ -package org.prgrms.nabimarketbe.jpa.chatroom.projection.list; - -import java.util.List; - -import lombok.AllArgsConstructor; -import lombok.Getter; - -@AllArgsConstructor -@Getter -public class ChatRoomListWrapper { - private List chatRoomList; - - private String nextCursorId; -} diff --git a/nabimarket-infra/src/main/java/org/prgrms/nabimarketbe/jpa/chatroom/projection/list/FromCardInfoListDTO.java b/nabimarket-infra/src/main/java/org/prgrms/nabimarketbe/jpa/chatroom/projection/list/FromCardInfoListDTO.java deleted file mode 100644 index 34f379cf..00000000 --- a/nabimarket-infra/src/main/java/org/prgrms/nabimarketbe/jpa/chatroom/projection/list/FromCardInfoListDTO.java +++ /dev/null @@ -1,10 +0,0 @@ -package org.prgrms.nabimarketbe.jpa.chatroom.projection.list; - -import lombok.Getter; - -@Getter -public class FromCardInfoListDTO { - private CardInfoListDTO cardInfo; - - private UserInfoListDTO userInfo; -} diff --git a/nabimarket-infra/src/main/java/org/prgrms/nabimarketbe/jpa/chatroom/projection/list/ToCardInfoListDTO.java b/nabimarket-infra/src/main/java/org/prgrms/nabimarketbe/jpa/chatroom/projection/list/ToCardInfoListDTO.java deleted file mode 100644 index ee34a5f1..00000000 --- a/nabimarket-infra/src/main/java/org/prgrms/nabimarketbe/jpa/chatroom/projection/list/ToCardInfoListDTO.java +++ /dev/null @@ -1,10 +0,0 @@ -package org.prgrms.nabimarketbe.jpa.chatroom.projection.list; - -import lombok.Getter; - -@Getter -public class ToCardInfoListDTO { - private CardInfoListDTO cardInfo; - - private UserInfoListDTO userInfo; -} diff --git a/nabimarket-infra/src/main/java/org/prgrms/nabimarketbe/jpa/chatroom/projection/list/UserInfoListDTO.java b/nabimarket-infra/src/main/java/org/prgrms/nabimarketbe/jpa/chatroom/projection/list/UserInfoListDTO.java deleted file mode 100644 index a718394d..00000000 --- a/nabimarket-infra/src/main/java/org/prgrms/nabimarketbe/jpa/chatroom/projection/list/UserInfoListDTO.java +++ /dev/null @@ -1,8 +0,0 @@ -package org.prgrms.nabimarketbe.jpa.chatroom.projection.list; - -import lombok.Getter; - -@Getter -public class UserInfoListDTO { - private Long userId; -} diff --git a/nabimarket-infra/src/main/java/org/prgrms/nabimarketbe/jpa/chatroom/projection/single/CardInfoDTO.java b/nabimarket-infra/src/main/java/org/prgrms/nabimarketbe/jpa/chatroom/projection/single/CardInfoDTO.java deleted file mode 100644 index 88514df6..00000000 --- a/nabimarket-infra/src/main/java/org/prgrms/nabimarketbe/jpa/chatroom/projection/single/CardInfoDTO.java +++ /dev/null @@ -1,12 +0,0 @@ -package org.prgrms.nabimarketbe.jpa.chatroom.projection.single; - -import lombok.Getter; - -@Getter -public class CardInfoDTO { - private Long cardId; - - private String itemName; - - private String thumbnail; -} diff --git a/nabimarket-infra/src/main/java/org/prgrms/nabimarketbe/jpa/chatroom/projection/single/ChatRoomInfoDTO.java b/nabimarket-infra/src/main/java/org/prgrms/nabimarketbe/jpa/chatroom/projection/single/ChatRoomInfoDTO.java deleted file mode 100644 index 290c287c..00000000 --- a/nabimarket-infra/src/main/java/org/prgrms/nabimarketbe/jpa/chatroom/projection/single/ChatRoomInfoDTO.java +++ /dev/null @@ -1,24 +0,0 @@ -package org.prgrms.nabimarketbe.jpa.chatroom.projection.single; - -import lombok.Getter; - -@Getter -public class ChatRoomInfoDTO { - private String fireStoreChatRoomId; - - private FromCardInfoDTO fromCardInfo; - - private ToCardInfoDTO toCardInfo; - - private Long completeRequestId; - - public void setCompleteRequestId(Long completeRequestId) { - this.completeRequestId = completeRequestId; - } - - public void updateFireStoreChatRoomId() { - String fireStoreDocumentName = fireStoreChatRoomId.split("/")[2]; - - this.fireStoreChatRoomId = fireStoreDocumentName; - } -} diff --git a/nabimarket-infra/src/main/java/org/prgrms/nabimarketbe/jpa/chatroom/projection/single/ChatRoomInfoWrapper.java b/nabimarket-infra/src/main/java/org/prgrms/nabimarketbe/jpa/chatroom/projection/single/ChatRoomInfoWrapper.java deleted file mode 100644 index 4e6a5f10..00000000 --- a/nabimarket-infra/src/main/java/org/prgrms/nabimarketbe/jpa/chatroom/projection/single/ChatRoomInfoWrapper.java +++ /dev/null @@ -1,8 +0,0 @@ -package org.prgrms.nabimarketbe.jpa.chatroom.projection.single; - -import lombok.Getter; - -@Getter -public class ChatRoomInfoWrapper { - private ChatRoomInfoDTO chatRoomInfo; -} diff --git a/nabimarket-infra/src/main/java/org/prgrms/nabimarketbe/jpa/chatroom/projection/single/FromCardInfoDTO.java b/nabimarket-infra/src/main/java/org/prgrms/nabimarketbe/jpa/chatroom/projection/single/FromCardInfoDTO.java deleted file mode 100644 index 7873ece7..00000000 --- a/nabimarket-infra/src/main/java/org/prgrms/nabimarketbe/jpa/chatroom/projection/single/FromCardInfoDTO.java +++ /dev/null @@ -1,10 +0,0 @@ -package org.prgrms.nabimarketbe.jpa.chatroom.projection.single; - -import lombok.Getter; - -@Getter -public class FromCardInfoDTO { - private CardInfoDTO cardInfo; - - private UserInfoDTO userInfo; -} diff --git a/nabimarket-infra/src/main/java/org/prgrms/nabimarketbe/jpa/chatroom/projection/single/ToCardInfoDTO.java b/nabimarket-infra/src/main/java/org/prgrms/nabimarketbe/jpa/chatroom/projection/single/ToCardInfoDTO.java deleted file mode 100644 index 8bda82cb..00000000 --- a/nabimarket-infra/src/main/java/org/prgrms/nabimarketbe/jpa/chatroom/projection/single/ToCardInfoDTO.java +++ /dev/null @@ -1,10 +0,0 @@ -package org.prgrms.nabimarketbe.jpa.chatroom.projection.single; - -import lombok.Getter; - -@Getter -public class ToCardInfoDTO { - private CardInfoDTO cardInfo; - - private UserInfoDTO userInfo; -} diff --git a/nabimarket-infra/src/main/java/org/prgrms/nabimarketbe/jpa/chatroom/projection/single/UserInfoDTO.java b/nabimarket-infra/src/main/java/org/prgrms/nabimarketbe/jpa/chatroom/projection/single/UserInfoDTO.java deleted file mode 100644 index 7cdf6e2e..00000000 --- a/nabimarket-infra/src/main/java/org/prgrms/nabimarketbe/jpa/chatroom/projection/single/UserInfoDTO.java +++ /dev/null @@ -1,8 +0,0 @@ -package org.prgrms.nabimarketbe.jpa.chatroom.projection.single; - -import lombok.Getter; - -@Getter -public class UserInfoDTO { - private Long userId; -} diff --git a/nabimarket-infra/src/main/java/org/prgrms/nabimarketbe/jpa/chatroom/repository/ChatRoomRepository.java b/nabimarket-infra/src/main/java/org/prgrms/nabimarketbe/jpa/chatroom/repository/ChatRoomRepository.java deleted file mode 100644 index 2634365a..00000000 --- a/nabimarket-infra/src/main/java/org/prgrms/nabimarketbe/jpa/chatroom/repository/ChatRoomRepository.java +++ /dev/null @@ -1,9 +0,0 @@ -package org.prgrms.nabimarketbe.jpa.chatroom.repository; - -import org.prgrms.nabimarketbe.jpa.chatroom.entity.ChatRoom; -import org.prgrms.nabimarketbe.jpa.suggestion.entity.Suggestion; -import org.springframework.data.jpa.repository.JpaRepository; - -public interface ChatRoomRepository extends JpaRepository, ChatRoomRepositoryCustom { - boolean existsChatRoomBySuggestion(Suggestion suggestion); -} diff --git a/nabimarket-infra/src/main/java/org/prgrms/nabimarketbe/jpa/chatroom/repository/ChatRoomRepositoryCustom.java b/nabimarket-infra/src/main/java/org/prgrms/nabimarketbe/jpa/chatroom/repository/ChatRoomRepositoryCustom.java deleted file mode 100644 index 32d9671a..00000000 --- a/nabimarket-infra/src/main/java/org/prgrms/nabimarketbe/jpa/chatroom/repository/ChatRoomRepositoryCustom.java +++ /dev/null @@ -1,10 +0,0 @@ -package org.prgrms.nabimarketbe.jpa.chatroom.repository; - -import org.prgrms.nabimarketbe.jpa.chatroom.projection.list.ChatRoomListWrapper; -import org.prgrms.nabimarketbe.jpa.chatroom.projection.single.ChatRoomInfoWrapper; - -public interface ChatRoomRepositoryCustom { - ChatRoomInfoWrapper getChatRoomInfoById(Long chatRoomId, Long completeRequestId); - - ChatRoomListWrapper getChatRoomList(Integer size, String cursorId, Long userId); -} diff --git a/nabimarket-infra/src/main/java/org/prgrms/nabimarketbe/jpa/chatroom/repository/ChatRoomRepositoryImpl.java b/nabimarket-infra/src/main/java/org/prgrms/nabimarketbe/jpa/chatroom/repository/ChatRoomRepositoryImpl.java deleted file mode 100644 index aabaa584..00000000 --- a/nabimarket-infra/src/main/java/org/prgrms/nabimarketbe/jpa/chatroom/repository/ChatRoomRepositoryImpl.java +++ /dev/null @@ -1,195 +0,0 @@ -package org.prgrms.nabimarketbe.jpa.chatroom.repository; - -import java.util.List; - -import org.prgrms.nabimarketbe.jpa.chatroom.entity.QChatRoom; -import org.prgrms.nabimarketbe.jpa.chatroom.projection.list.CardInfoListDTO; -import org.prgrms.nabimarketbe.jpa.chatroom.projection.list.ChatRoomInfoListDTO; -import org.prgrms.nabimarketbe.jpa.chatroom.projection.list.ChatRoomListWrapper; -import org.prgrms.nabimarketbe.jpa.chatroom.projection.list.FromCardInfoListDTO; -import org.prgrms.nabimarketbe.jpa.chatroom.projection.list.ToCardInfoListDTO; -import org.prgrms.nabimarketbe.jpa.chatroom.projection.list.UserInfoListDTO; -import org.prgrms.nabimarketbe.jpa.chatroom.projection.single.CardInfoDTO; -import org.prgrms.nabimarketbe.jpa.chatroom.projection.single.ChatRoomInfoDTO; -import org.prgrms.nabimarketbe.jpa.chatroom.projection.single.ChatRoomInfoWrapper; -import org.prgrms.nabimarketbe.jpa.chatroom.projection.single.FromCardInfoDTO; -import org.prgrms.nabimarketbe.jpa.chatroom.projection.single.ToCardInfoDTO; -import org.prgrms.nabimarketbe.jpa.chatroom.projection.single.UserInfoDTO; -import org.prgrms.nabimarketbe.jpa.suggestion.entity.QSuggestion; -import org.prgrms.nabimarketbe.jpa.util.CursorPaging; -import org.prgrms.nabimarketbe.jpa.util.QueryDslUtil; -import org.springframework.data.domain.Sort; - -import com.querydsl.core.types.ConstantImpl; -import com.querydsl.core.types.Projections; -import com.querydsl.core.types.dsl.BooleanExpression; -import com.querydsl.core.types.dsl.Expressions; -import com.querydsl.core.types.dsl.StringExpression; -import com.querydsl.core.types.dsl.StringExpressions; -import com.querydsl.core.types.dsl.StringTemplate; -import com.querydsl.jpa.impl.JPAQueryFactory; - -import lombok.RequiredArgsConstructor; - -@RequiredArgsConstructor -public class ChatRoomRepositoryImpl implements ChatRoomRepositoryCustom, CursorPaging { - private final JPAQueryFactory jpaQueryFactory; - - @Override - public ChatRoomInfoWrapper getChatRoomInfoById( - Long chatRoomId, - Long completeRequestId - ) { - ChatRoomInfoWrapper chatRoomInfo = jpaQueryFactory - .select( - Projections.fields( - ChatRoomInfoWrapper.class, - Projections.fields( - ChatRoomInfoDTO.class, - QChatRoom.chatRoom.fireStoreChatRoomPath.as("fireStoreChatRoomId"), - Projections.fields( - FromCardInfoDTO.class, - Projections.fields( - CardInfoDTO.class, - QSuggestion.suggestion.fromCard.cardId, - QSuggestion.suggestion.fromCard.item.itemName, - QSuggestion.suggestion.fromCard.thumbnail - ).as("cardInfo"), - Projections.fields( - UserInfoDTO.class, - QSuggestion.suggestion.fromCard.user.userId - ).as("userInfo") - ).as("fromCardInfo"), - Projections.fields( - ToCardInfoDTO.class, - Projections.fields( - CardInfoDTO.class, - QSuggestion.suggestion.toCard.cardId, - QSuggestion.suggestion.toCard.item.itemName, - QSuggestion.suggestion.toCard.thumbnail - ).as("cardInfo"), - Projections.fields( - UserInfoDTO.class, - QSuggestion.suggestion.toCard.user.userId - ).as("userInfo") - ).as("toCardInfo") - ).as("chatRoomInfo") - ) - ) - .from(QChatRoom.chatRoom) - .join(QSuggestion.suggestion) - .on(QChatRoom.chatRoom.suggestion.suggestionId.eq(QSuggestion.suggestion.suggestionId)) - .where(QChatRoom.chatRoom.chatRoomId.eq(chatRoomId)) - .fetchOne(); - - chatRoomInfo.getChatRoomInfo().updateFireStoreChatRoomId(); - chatRoomInfo.getChatRoomInfo().setCompleteRequestId(completeRequestId); - - return chatRoomInfo; - } - - @Override - public ChatRoomListWrapper getChatRoomList( - Integer size, - String cursorId, - Long userId - ) { - List chatRoomList = jpaQueryFactory - .select( - Projections.fields( - ChatRoomInfoListDTO.class, - QChatRoom.chatRoom.chatRoomId, - QChatRoom.chatRoom.createdDate.as("createdAt"), - Projections.fields( - FromCardInfoListDTO.class, - Projections.fields( - CardInfoListDTO.class, - QSuggestion.suggestion.fromCard.cardId, - QSuggestion.suggestion.fromCard.item.itemName, - QSuggestion.suggestion.fromCard.item.priceRange, - QSuggestion.suggestion.fromCard.thumbnail - ).as("cardInfo"), - Projections.fields( - UserInfoListDTO.class, - QSuggestion.suggestion.fromCard.user.userId - ).as("userInfo") - ).as("fromCardInfo"), - Projections.fields( - ToCardInfoListDTO.class, - Projections.fields( - CardInfoListDTO.class, - QSuggestion.suggestion.toCard.cardId, - QSuggestion.suggestion.toCard.item.itemName, - QSuggestion.suggestion.toCard.item.priceRange, - QSuggestion.suggestion.toCard.thumbnail - ).as("cardInfo"), - Projections.fields( - UserInfoListDTO.class, - QSuggestion.suggestion.toCard.user.userId - ).as("userInfo") - ).as("toCardInfo") - ) - ) - .from(QChatRoom.chatRoom) - .join(QSuggestion.suggestion) - .on(QChatRoom.chatRoom.suggestion.suggestionId.eq(QSuggestion.suggestion.suggestionId)) - .where( - cursorId(cursorId), - owner(userId) - ) - .orderBy( - QueryDslUtil.getOrderSpecifier( - Sort.by( - Sort.Order.desc("createdDate"), - Sort.Order.desc("chatRoomId") - ), - QChatRoom.chatRoom - ) - ) - .limit(size) - .fetch(); - - String nextCursor = - chatRoomList.size() < size ? null : generateCursor(chatRoomList.get(chatRoomList.size() - 1)); - - ChatRoomListWrapper chatRoomListWrapper = new ChatRoomListWrapper(chatRoomList, nextCursor); - - return chatRoomListWrapper; - } - - @Override - public BooleanExpression cursorId(String cursorId) { - if (cursorId == null) { - return null; - } - - // 생성일자 - StringTemplate dateCursorTemplate = Expressions.stringTemplate( - "DATE_FORMAT({0}, {1})", - QChatRoom.chatRoom.createdDate, - ConstantImpl.create("%Y%m%d%H%i%s") - ); - - // pk - StringExpression pkCursorTemplate = StringExpressions.lpad( - QChatRoom.chatRoom.chatRoomId.stringValue(), - 8, - '0' - ); - - return dateCursorTemplate.concat(pkCursorTemplate).lt(cursorId); - } - - private String generateCursor(ChatRoomInfoListDTO chatRoomInfoListDTO) { - return chatRoomInfoListDTO.getCreatedAt().toString() // 디폴트는 생성일자 최신순 정렬 - .replace("T", "") - .replace("-", "") - .replace(":", "") - + String.format("%08d", chatRoomInfoListDTO.getChatRoomId()); - } - - private BooleanExpression owner(Long userId) { - return QSuggestion.suggestion.fromCard.user.userId.eq(userId) - .or(QSuggestion.suggestion.toCard.user.userId.eq(userId)); - } -} diff --git a/nabimarket-infra/src/main/java/org/prgrms/nabimarketbe/jpa/completerequest/entity/CompleteRequest.java b/nabimarket-infra/src/main/java/org/prgrms/nabimarketbe/jpa/completerequest/entity/CompleteRequest.java deleted file mode 100644 index feb4ee2e..00000000 --- a/nabimarket-infra/src/main/java/org/prgrms/nabimarketbe/jpa/completerequest/entity/CompleteRequest.java +++ /dev/null @@ -1,98 +0,0 @@ -package org.prgrms.nabimarketbe.jpa.completerequest.entity; - -import javax.persistence.Column; -import javax.persistence.Entity; -import javax.persistence.EnumType; -import javax.persistence.Enumerated; -import javax.persistence.FetchType; -import javax.persistence.GeneratedValue; -import javax.persistence.GenerationType; -import javax.persistence.Id; -import javax.persistence.JoinColumn; -import javax.persistence.OneToOne; -import javax.persistence.Table; -import javax.persistence.UniqueConstraint; - -import org.prgrms.nabimarketbe.jpa.BaseEntity; -import org.prgrms.nabimarketbe.jpa.card.entity.Card; -import org.prgrms.nabimarketbe.error.BaseException; -import org.prgrms.nabimarketbe.error.ErrorCode; - -import lombok.AccessLevel; -import lombok.Getter; -import lombok.NoArgsConstructor; - -@Entity -@Getter -@Table(name = "complete_requests", - uniqueConstraints = { - @UniqueConstraint( - name = "complete_request_unique", - columnNames = {"from_card", "to_card"} - ) - }) -@NoArgsConstructor(access = AccessLevel.PROTECTED) -public class CompleteRequest extends BaseEntity { - @Id - @GeneratedValue(strategy = GenerationType.IDENTITY) - @Column(name = "complete_request_id", nullable = false) - private Long completeRequestId; - - @OneToOne(fetch = FetchType.LAZY) - @JoinColumn(name = "from_card", nullable = false) - private Card fromCard; - - @OneToOne(fetch = FetchType.LAZY) - @JoinColumn(name = "to_card", nullable = false) - private Card toCard; - - @Enumerated(EnumType.STRING) - private CompleteRequestStatus completeRequestStatus; - - public CompleteRequest( - Card fromCard, - Card toCard - ) { - if (fromCard == null || toCard == null) { - throw new BaseException(ErrorCode.INVALID_REQUEST); - } - - this.fromCard = fromCard; - this.toCard = toCard; - this.completeRequestStatus = CompleteRequestStatus.WAITING; - } - - public String createCompleteRequestMessage() { - String message = String.format( - "%s님이 %s과의 거래성사를 요청했습니다.", - fromCard.getUser().getNickname(), - toCard.getItem().getItemName() - ); - - return message; - } - - public String createCompleteRequestDecisionMessage(boolean isAccepted) { - String result = isAccepted ? "성사되었습니다" : "성사되지 못했습니다."; - String message = String.format( - "%s과 %s의 거래가 %s", - this.toCard.getItem().getItemName(), - this.fromCard.getItem().getItemName(), - result - ); - - return message; - } - - public void acceptCompleteRequest() { - this.completeRequestStatus = CompleteRequestStatus.ACCEPTED; - } - - public void refuseCompleteRequest() { - this.completeRequestStatus = CompleteRequestStatus.REFUSED; - } - - public void deleteCompleteRequest() { - this.completeRequestStatus = CompleteRequestStatus.DELETED; - } -} diff --git a/nabimarket-infra/src/main/java/org/prgrms/nabimarketbe/jpa/completerequest/entity/CompleteRequestStatus.java b/nabimarket-infra/src/main/java/org/prgrms/nabimarketbe/jpa/completerequest/entity/CompleteRequestStatus.java deleted file mode 100644 index 0338f458..00000000 --- a/nabimarket-infra/src/main/java/org/prgrms/nabimarketbe/jpa/completerequest/entity/CompleteRequestStatus.java +++ /dev/null @@ -1,8 +0,0 @@ -package org.prgrms.nabimarketbe.jpa.completerequest.entity; - -public enum CompleteRequestStatus { - WAITING, - ACCEPTED, - REFUSED, - DELETED -} diff --git a/nabimarket-infra/src/main/java/org/prgrms/nabimarketbe/jpa/completerequest/projection/HistoryListReadResponseDTO.java b/nabimarket-infra/src/main/java/org/prgrms/nabimarketbe/jpa/completerequest/projection/HistoryListReadResponseDTO.java deleted file mode 100644 index 5e75f3ac..00000000 --- a/nabimarket-infra/src/main/java/org/prgrms/nabimarketbe/jpa/completerequest/projection/HistoryListReadResponseDTO.java +++ /dev/null @@ -1,20 +0,0 @@ -package org.prgrms.nabimarketbe.jpa.completerequest.projection; - -import java.time.LocalDateTime; - -import org.prgrms.nabimarketbe.jpa.card.projection.CardSummaryResponseDTO; - -import lombok.Getter; - -@Getter -public class HistoryListReadResponseDTO { - private Long historyId; - - private CardSummaryResponseDTO fromCard; - - private CardSummaryResponseDTO toCard; - - private LocalDateTime createdAt; - - private LocalDateTime modifiedAt; -} diff --git a/nabimarket-infra/src/main/java/org/prgrms/nabimarketbe/jpa/completerequest/repository/CompleteRequestRepository.java b/nabimarket-infra/src/main/java/org/prgrms/nabimarketbe/jpa/completerequest/repository/CompleteRequestRepository.java deleted file mode 100644 index 0d48126c..00000000 --- a/nabimarket-infra/src/main/java/org/prgrms/nabimarketbe/jpa/completerequest/repository/CompleteRequestRepository.java +++ /dev/null @@ -1,50 +0,0 @@ -package org.prgrms.nabimarketbe.jpa.completerequest.repository; - -import java.util.Optional; - -import org.prgrms.nabimarketbe.jpa.card.entity.Card; -import org.prgrms.nabimarketbe.jpa.completerequest.entity.CompleteRequest; -import org.springframework.data.jpa.repository.JpaRepository; -import org.springframework.data.jpa.repository.Query; -import org.springframework.data.repository.query.Param; - -public interface CompleteRequestRepository extends JpaRepository, - CompleteRequestRepositryCustom { - @Query("select c " - + "from CompleteRequest c " - + "where c.fromCard = :fromCard and c.toCard = :toCard and c.completeRequestStatus != 'REFUSED' " + - "and c.fromCard = :fromCard and c.toCard = :toCard and c.completeRequestStatus != 'DELETED' " - + "or c.fromCard = :toCard and c.toCard = :fromCard and c.completeRequestStatus != 'REFUSED'" + - "and c.fromCard = :toCard and c.toCard = :fromCard and c.completeRequestStatus != 'DELETED'") - Optional findCompleteRequestByFromCardAndToCard( - @Param("fromCard") Card fromCard, - @Param("toCard") Card toCard - ); - - @Query( - "select count(c.completeRequestId) > 0 " - + "from CompleteRequest c " - + "where c.fromCard = :fromCard and c.toCard = :toCard and c.completeRequestStatus != 'REFUSED' " + - "and c.fromCard = :fromCard and c.toCard = :toCard and c.completeRequestStatus != 'DELETED' " - + "or c.fromCard = :toCard and c.toCard = :fromCard and c.completeRequestStatus != 'REFUSED' " - + "and c.fromCard = :toCard and c.toCard = :fromCard and c.completeRequestStatus != 'DELETED'") - Boolean exists(@Param("fromCard") Card fromCard, @Param("toCard") Card toCard); - - @Query( - "select count(c.completeRequestId) > 0 " - + "from CompleteRequest c " - + "where c.fromCard = :fromCard and c.completeRequestStatus != 'REFUSED' " + - "and c.fromCard = :fromCard and c.completeRequestStatus != 'DELETED' " - + "or c.toCard = :fromCard and c.completeRequestStatus != 'REFUSED' " + - "and c.toCard = :fromCard and c.completeRequestStatus != 'DELETED'") - Boolean existsByFromCard(@Param("fromCard") Card fromCard); - - @Query( - "select count(c.completeRequestId) > 0 " - + "from CompleteRequest c " - + "where c.toCard = :toCard and c.completeRequestStatus != 'REFUSED' " + - "and c.toCard = :toCard and c.completeRequestStatus != 'DELETED' " - + "or c.fromCard = :toCard and c.completeRequestStatus != 'REFUSED'" + - "and c.fromCard = :toCard and c.completeRequestStatus != 'DELETED'") - Boolean existsByToCard(@Param("toCard") Card toCard); -} diff --git a/nabimarket-infra/src/main/java/org/prgrms/nabimarketbe/jpa/completerequest/repository/CompleteRequestRepositoryImpl.java b/nabimarket-infra/src/main/java/org/prgrms/nabimarketbe/jpa/completerequest/repository/CompleteRequestRepositoryImpl.java deleted file mode 100644 index e21bb724..00000000 --- a/nabimarket-infra/src/main/java/org/prgrms/nabimarketbe/jpa/completerequest/repository/CompleteRequestRepositoryImpl.java +++ /dev/null @@ -1,170 +0,0 @@ -package org.prgrms.nabimarketbe.jpa.completerequest.repository; - -import static org.prgrms.nabimarketbe.jpa.card.entity.QCard.card; -import static org.prgrms.nabimarketbe.jpa.completerequest.entity.QCompleteRequest.completeRequest; - -import java.util.List; - -import org.prgrms.nabimarketbe.jpa.card.projection.CardSummaryResponseDTO; -import org.prgrms.nabimarketbe.jpa.completerequest.entity.CompleteRequestStatus; -import org.prgrms.nabimarketbe.jpa.completerequest.projection.HistoryListReadResponseDTO; -import org.prgrms.nabimarketbe.jpa.completerequest.wrapper.HistoryListReadLimitResponseDTO; -import org.prgrms.nabimarketbe.jpa.completerequest.wrapper.HistoryListReadPagingResponseDTO; -import org.prgrms.nabimarketbe.jpa.user.entity.User; -import org.prgrms.nabimarketbe.jpa.util.QueryDslUtil; -import org.springframework.data.domain.Sort; - -import com.querydsl.core.types.ConstantImpl; -import com.querydsl.core.types.Projections; -import com.querydsl.core.types.dsl.BooleanExpression; -import com.querydsl.core.types.dsl.Expressions; -import com.querydsl.core.types.dsl.StringExpressions; -import com.querydsl.core.types.dsl.StringTemplate; -import com.querydsl.jpa.impl.JPAQueryFactory; - -import lombok.RequiredArgsConstructor; -import lombok.extern.slf4j.Slf4j; - -@Slf4j -@RequiredArgsConstructor -public class CompleteRequestRepositoryImpl implements CompleteRequestRepositryCustom { - private final JPAQueryFactory jpaQueryFactory; - - @Override - public HistoryListReadLimitResponseDTO getHistoryBySize(Integer size) { - List historyList = jpaQueryFactory - .select( - Projections.fields( - HistoryListReadResponseDTO.class, - completeRequest.completeRequestId, - Projections.fields( - CardSummaryResponseDTO.class, - completeRequest.fromCard.cardId, - completeRequest.fromCard.item.itemName, - completeRequest.fromCard.thumbnail, - completeRequest.fromCard.item.priceRange - ).as("fromCard"), - Projections.fields( - CardSummaryResponseDTO.class, - completeRequest.toCard.cardId, - completeRequest.toCard.item.itemName, - completeRequest.toCard.thumbnail, - completeRequest.toCard.item.priceRange - ).as("toCard"), - completeRequest.createdDate.as("createdAt"), - completeRequest.modifiedDate.as("modifiedAt") - ) - ) - .from(completeRequest) - .leftJoin(card) - .on(card.cardId.eq(completeRequest.fromCard.cardId)) - .leftJoin(card) - .on(card.cardId.eq(completeRequest.toCard.cardId).as("toCardAlias")) - .where(completeRequest.completeRequestStatus.eq(CompleteRequestStatus.ACCEPTED)) - .orderBy( - QueryDslUtil.getOrderSpecifier( - Sort.by( - Sort.Order.desc("modifiedDate"), - Sort.Order.desc("completeRequestId") - ), - completeRequest - ) - ) - .limit(size) - .fetch(); - - return new HistoryListReadLimitResponseDTO(historyList); - } - - @Override - public HistoryListReadPagingResponseDTO getHistoryByUser( - User user, - String cursorId, - Integer size - ) { - List historyList = jpaQueryFactory - .select( - Projections.fields( - HistoryListReadResponseDTO.class, - completeRequest.completeRequestId, - Projections.fields( - CardSummaryResponseDTO.class, - completeRequest.fromCard.cardId, - completeRequest.fromCard.item.itemName, - completeRequest.fromCard.thumbnail, - completeRequest.fromCard.item.priceRange - ).as("fromCard"), - Projections.fields( - CardSummaryResponseDTO.class, - completeRequest.toCard.cardId, - completeRequest.toCard.item.itemName, - completeRequest.toCard.thumbnail, - completeRequest.toCard.item.priceRange - ).as("toCard"), - completeRequest.createdDate.as("createdAt"), - completeRequest.modifiedDate.as("modifiedAt") - ) - ) - .from(completeRequest) - .leftJoin(card) - .on(card.cardId.eq(completeRequest.fromCard.cardId)) - .leftJoin(card) - .on(card.cardId.eq(completeRequest.toCard.cardId).as("toCardAlias")) - .where(cursorIdLessThan(cursorId), - completeRequest.completeRequestStatus.eq(CompleteRequestStatus.ACCEPTED), - completeRequest.fromCard.user.eq(user) - .or(completeRequest.toCard.user.eq(user))) - .orderBy( - QueryDslUtil.getOrderSpecifier( - Sort.by( - Sort.Order.desc("modifiedDate"), - Sort.Order.desc("completeRequestId") - ), - completeRequest - ) - ) - .limit(size) - .fetch(); - - String nextCursor = historyList.size() < size - ? null : createCursorId(historyList.get(historyList.size() - 1)); - - return new HistoryListReadPagingResponseDTO(historyList, nextCursor); - } - - /** - * 커스텀 커서 id가 주어진 cursorId보다 작은지 확인 - */ - private BooleanExpression cursorIdLessThan(String cursorId) { - if (cursorId == null) { - return null; - } - - StringTemplate stringTemplate = Expressions.stringTemplate( - "DATE_FORMAT({0}, {1})", - completeRequest.createdDate, - ConstantImpl.create("%Y%m%d%H%i%s") - ); - - return stringTemplate.concat(StringExpressions.lpad( - completeRequest.completeRequestId.stringValue(), - 8, - '0' - )).lt(cursorId); - } - - /** - * 커서 id 생성 - */ - private String createCursorId(HistoryListReadResponseDTO historyListReadResponseDTO) { - return historyListReadResponseDTO.getCreatedAt().toString() - .replace("T", "") - .replace("-", "") - .replace(":", "") - + String.format( - "%08d", - historyListReadResponseDTO.getFromCard().getCardId() - + historyListReadResponseDTO.getToCard().getCardId() - ); - } -} diff --git a/nabimarket-infra/src/main/java/org/prgrms/nabimarketbe/jpa/completerequest/repository/CompleteRequestRepositryCustom.java b/nabimarket-infra/src/main/java/org/prgrms/nabimarketbe/jpa/completerequest/repository/CompleteRequestRepositryCustom.java deleted file mode 100644 index ccd905e2..00000000 --- a/nabimarket-infra/src/main/java/org/prgrms/nabimarketbe/jpa/completerequest/repository/CompleteRequestRepositryCustom.java +++ /dev/null @@ -1,11 +0,0 @@ -package org.prgrms.nabimarketbe.jpa.completerequest.repository; - -import org.prgrms.nabimarketbe.jpa.completerequest.wrapper.HistoryListReadLimitResponseDTO; -import org.prgrms.nabimarketbe.jpa.completerequest.wrapper.HistoryListReadPagingResponseDTO; -import org.prgrms.nabimarketbe.jpa.user.entity.User; - -public interface CompleteRequestRepositryCustom { - HistoryListReadLimitResponseDTO getHistoryBySize(Integer size); - - HistoryListReadPagingResponseDTO getHistoryByUser(User user, String cursorId, Integer size); -} diff --git a/nabimarket-infra/src/main/java/org/prgrms/nabimarketbe/jpa/completerequest/wrapper/CompleteRequestInfoDTO.java b/nabimarket-infra/src/main/java/org/prgrms/nabimarketbe/jpa/completerequest/wrapper/CompleteRequestInfoDTO.java deleted file mode 100644 index a1b7f043..00000000 --- a/nabimarket-infra/src/main/java/org/prgrms/nabimarketbe/jpa/completerequest/wrapper/CompleteRequestInfoDTO.java +++ /dev/null @@ -1,4 +0,0 @@ -package org.prgrms.nabimarketbe.jpa.completerequest.wrapper; - -public record CompleteRequestInfoDTO(CompleteRequestSummaryDTO completeRequestInfo) { -} diff --git a/nabimarket-infra/src/main/java/org/prgrms/nabimarketbe/jpa/completerequest/wrapper/CompleteRequestSummaryDTO.java b/nabimarket-infra/src/main/java/org/prgrms/nabimarketbe/jpa/completerequest/wrapper/CompleteRequestSummaryDTO.java deleted file mode 100644 index 8296a94b..00000000 --- a/nabimarket-infra/src/main/java/org/prgrms/nabimarketbe/jpa/completerequest/wrapper/CompleteRequestSummaryDTO.java +++ /dev/null @@ -1,14 +0,0 @@ -package org.prgrms.nabimarketbe.jpa.completerequest.wrapper; - -import org.prgrms.nabimarketbe.jpa.card.projection.CardUserSummaryResponseDTO; -import org.prgrms.nabimarketbe.jpa.completerequest.entity.CompleteRequestStatus; - -import lombok.Builder; - -@Builder -public record CompleteRequestSummaryDTO( - CardUserSummaryResponseDTO fromCard, - CardUserSummaryResponseDTO toCard, - CompleteRequestStatus status -) { -} diff --git a/nabimarket-infra/src/main/java/org/prgrms/nabimarketbe/jpa/completerequest/wrapper/HistoryListReadLimitResponseDTO.java b/nabimarket-infra/src/main/java/org/prgrms/nabimarketbe/jpa/completerequest/wrapper/HistoryListReadLimitResponseDTO.java deleted file mode 100644 index 7b643793..00000000 --- a/nabimarket-infra/src/main/java/org/prgrms/nabimarketbe/jpa/completerequest/wrapper/HistoryListReadLimitResponseDTO.java +++ /dev/null @@ -1,10 +0,0 @@ -package org.prgrms.nabimarketbe.jpa.completerequest.wrapper; - -import java.util.List; - -import org.prgrms.nabimarketbe.jpa.completerequest.projection.HistoryListReadResponseDTO; - -public record HistoryListReadLimitResponseDTO( - List historyList -) { -} diff --git a/nabimarket-infra/src/main/java/org/prgrms/nabimarketbe/jpa/completerequest/wrapper/HistoryListReadPagingResponseDTO.java b/nabimarket-infra/src/main/java/org/prgrms/nabimarketbe/jpa/completerequest/wrapper/HistoryListReadPagingResponseDTO.java deleted file mode 100644 index 6b97f354..00000000 --- a/nabimarket-infra/src/main/java/org/prgrms/nabimarketbe/jpa/completerequest/wrapper/HistoryListReadPagingResponseDTO.java +++ /dev/null @@ -1,11 +0,0 @@ -package org.prgrms.nabimarketbe.jpa.completerequest.wrapper; - -import java.util.List; - -import org.prgrms.nabimarketbe.jpa.completerequest.projection.HistoryListReadResponseDTO; - -public record HistoryListReadPagingResponseDTO( - List historyList, - String nextCursorId -) { -} diff --git a/nabimarket-infra/src/main/java/org/prgrms/nabimarketbe/jpa/dibs/entity/Dib.java b/nabimarket-infra/src/main/java/org/prgrms/nabimarketbe/jpa/dibs/entity/Dib.java deleted file mode 100644 index de34d5a6..00000000 --- a/nabimarket-infra/src/main/java/org/prgrms/nabimarketbe/jpa/dibs/entity/Dib.java +++ /dev/null @@ -1,52 +0,0 @@ -package org.prgrms.nabimarketbe.jpa.dibs.entity; - -import javax.persistence.Column; -import javax.persistence.Entity; -import javax.persistence.FetchType; -import javax.persistence.GeneratedValue; -import javax.persistence.GenerationType; -import javax.persistence.Id; -import javax.persistence.JoinColumn; -import javax.persistence.ManyToOne; -import javax.persistence.Table; - -import org.prgrms.nabimarketbe.jpa.BaseEntity; -import org.prgrms.nabimarketbe.jpa.card.entity.Card; -import org.prgrms.nabimarketbe.error.BaseException; -import org.prgrms.nabimarketbe.error.ErrorCode; -import org.prgrms.nabimarketbe.jpa.user.entity.User; - -import lombok.AccessLevel; -import lombok.Getter; -import lombok.NoArgsConstructor; - -@Getter -@Entity -@Table(name = "dibs") -@NoArgsConstructor(access = AccessLevel.PROTECTED) -public class Dib extends BaseEntity { - @Id - @GeneratedValue(strategy = GenerationType.IDENTITY) - @Column(name = "dib_id", nullable = false) - private Long dibId; - - @ManyToOne(fetch = FetchType.LAZY) - @JoinColumn(name = "user_id", nullable = false) - private User user; - - @ManyToOne(fetch = FetchType.LAZY) - @JoinColumn(name = "card_id", nullable = false) - private Card card; - - public Dib( - User user, - Card card - ) { - if (user == null || card == null) { - throw new BaseException(ErrorCode.INVALID_REQUEST); - } - - this.user = user; - this.card = card; - } -} diff --git a/nabimarket-infra/src/main/java/org/prgrms/nabimarketbe/jpa/dibs/projection/DibListReadPagingResponseDTO.java b/nabimarket-infra/src/main/java/org/prgrms/nabimarketbe/jpa/dibs/projection/DibListReadPagingResponseDTO.java deleted file mode 100644 index aba2c7d5..00000000 --- a/nabimarket-infra/src/main/java/org/prgrms/nabimarketbe/jpa/dibs/projection/DibListReadPagingResponseDTO.java +++ /dev/null @@ -1,15 +0,0 @@ -package org.prgrms.nabimarketbe.jpa.dibs.projection; - -import java.util.List; - -public record DibListReadPagingResponseDTO( - List dibList, - Long nextCursorId -) { - public static DibListReadPagingResponseDTO of( - List dibList, - Long nextCursorId - ) { - return new DibListReadPagingResponseDTO(dibList, nextCursorId); - } -} diff --git a/nabimarket-infra/src/main/java/org/prgrms/nabimarketbe/jpa/dibs/projection/DibListReadResponseDTO.java b/nabimarket-infra/src/main/java/org/prgrms/nabimarketbe/jpa/dibs/projection/DibListReadResponseDTO.java deleted file mode 100644 index f03df804..00000000 --- a/nabimarket-infra/src/main/java/org/prgrms/nabimarketbe/jpa/dibs/projection/DibListReadResponseDTO.java +++ /dev/null @@ -1,29 +0,0 @@ -package org.prgrms.nabimarketbe.jpa.dibs.projection; - -import java.time.LocalDateTime; - -import org.prgrms.nabimarketbe.jpa.card.entity.CardStatus; -import org.prgrms.nabimarketbe.jpa.item.entity.PriceRange; - -import lombok.Getter; - -@Getter -public class DibListReadResponseDTO { - private Long dibId; - - private Long cardId; - - private String cardTitle; - - private String itemName; - - private PriceRange priceRange; - - private String thumbnail; - - private CardStatus status; - - private LocalDateTime createdAt; - - private LocalDateTime modifiedAt; -} diff --git a/nabimarket-infra/src/main/java/org/prgrms/nabimarketbe/jpa/dibs/repository/DibRepository.java b/nabimarket-infra/src/main/java/org/prgrms/nabimarketbe/jpa/dibs/repository/DibRepository.java deleted file mode 100644 index 28b17109..00000000 --- a/nabimarket-infra/src/main/java/org/prgrms/nabimarketbe/jpa/dibs/repository/DibRepository.java +++ /dev/null @@ -1,14 +0,0 @@ -package org.prgrms.nabimarketbe.jpa.dibs.repository; - -import java.util.Optional; - -import org.prgrms.nabimarketbe.jpa.card.entity.Card; -import org.prgrms.nabimarketbe.jpa.dibs.entity.Dib; -import org.prgrms.nabimarketbe.jpa.user.entity.User; -import org.springframework.data.jpa.repository.JpaRepository; - -public interface DibRepository extends JpaRepository, DibRepositoryCustom { - Optional findDibByUserAndCard(User user, Card card); - - boolean existsDibByCardAndUser(Card card, User user); -} diff --git a/nabimarket-infra/src/main/java/org/prgrms/nabimarketbe/jpa/dibs/repository/DibRepositoryCustom.java b/nabimarket-infra/src/main/java/org/prgrms/nabimarketbe/jpa/dibs/repository/DibRepositoryCustom.java deleted file mode 100644 index bc1164fc..00000000 --- a/nabimarket-infra/src/main/java/org/prgrms/nabimarketbe/jpa/dibs/repository/DibRepositoryCustom.java +++ /dev/null @@ -1,11 +0,0 @@ -package org.prgrms.nabimarketbe.jpa.dibs.repository; - -import org.prgrms.nabimarketbe.jpa.dibs.projection.DibListReadPagingResponseDTO; - -public interface DibRepositoryCustom { - DibListReadPagingResponseDTO getUserDibsByDibId( - Long userId, - Long cursorId, - Integer size - ); -} diff --git a/nabimarket-infra/src/main/java/org/prgrms/nabimarketbe/jpa/dibs/repository/DibRepositoryImpl.java b/nabimarket-infra/src/main/java/org/prgrms/nabimarketbe/jpa/dibs/repository/DibRepositoryImpl.java deleted file mode 100644 index 7404a51e..00000000 --- a/nabimarket-infra/src/main/java/org/prgrms/nabimarketbe/jpa/dibs/repository/DibRepositoryImpl.java +++ /dev/null @@ -1,80 +0,0 @@ -package org.prgrms.nabimarketbe.jpa.dibs.repository; - -import java.util.List; - -import org.prgrms.nabimarketbe.jpa.card.entity.QCard; -import org.prgrms.nabimarketbe.jpa.dibs.entity.QDib; -import org.prgrms.nabimarketbe.jpa.dibs.projection.DibListReadPagingResponseDTO; -import org.prgrms.nabimarketbe.jpa.dibs.projection.DibListReadResponseDTO; - -import com.querydsl.core.types.Projections; -import com.querydsl.core.types.dsl.BooleanExpression; -import com.querydsl.jpa.impl.JPAQueryFactory; - -import lombok.RequiredArgsConstructor; - -@RequiredArgsConstructor -public class DibRepositoryImpl implements DibRepositoryCustom { - private final JPAQueryFactory jpaQueryFactory; - - @Override - public DibListReadPagingResponseDTO getUserDibsByDibId( - Long userId, - Long cursorId, - Integer size - ) { - List dibList = jpaQueryFactory.select( - Projections.fields( - DibListReadResponseDTO.class, - QDib.dib.dibId, - QCard.card.cardId, - QCard.card.cardTitle, - QCard.card.item.itemName, - QCard.card.item.priceRange, - QCard.card.thumbnail, - QCard.card.status, - QCard.card.createdDate.as("createdAt"), - QCard.card.modifiedDate.as("modifiedAt") - ) - ) - .from(QDib.dib) - .join(QCard.card).on(QCard.card.cardId.eq(QDib.dib.card.cardId)) - .where( - dibUserIdEquals(userId), - greaterThan(cursorId) - ) - .limit(size) - .fetch(); - - Long nextCursorId = generateCursor(dibList, size); - - return DibListReadPagingResponseDTO.of(dibList, nextCursorId); - } - - private Long generateCursor( - List dibList, - Integer size - ) { - if (dibList.size() == size) { - return dibList.get(dibList.size() - 1).getDibId(); - } - - return null; - } - - private BooleanExpression dibUserIdEquals(Long userId) { - if (userId == null) { - return null; - } - - return QDib.dib.user.userId.eq(userId); - } - - private BooleanExpression greaterThan(Long cursorId) { - if (cursorId == null) { - return null; - } - - return QDib.dib.dibId.gt(cursorId); - } -} diff --git a/nabimarket-infra/src/main/java/org/prgrms/nabimarketbe/jpa/item/entity/Item.java b/nabimarket-infra/src/main/java/org/prgrms/nabimarketbe/jpa/item/entity/Item.java deleted file mode 100644 index 68613220..00000000 --- a/nabimarket-infra/src/main/java/org/prgrms/nabimarketbe/jpa/item/entity/Item.java +++ /dev/null @@ -1,74 +0,0 @@ -package org.prgrms.nabimarketbe.jpa.item.entity; - -import javax.persistence.Column; -import javax.persistence.Entity; -import javax.persistence.EnumType; -import javax.persistence.Enumerated; -import javax.persistence.FetchType; -import javax.persistence.GeneratedValue; -import javax.persistence.GenerationType; -import javax.persistence.Id; -import javax.persistence.JoinColumn; -import javax.persistence.OneToOne; -import javax.persistence.Table; - -import org.prgrms.nabimarketbe.jpa.BaseEntity; -import org.prgrms.nabimarketbe.jpa.category.entity.Category; -import org.prgrms.nabimarketbe.error.BaseException; -import org.prgrms.nabimarketbe.error.ErrorCode; - -import lombok.AccessLevel; -import lombok.Builder; -import lombok.Getter; -import lombok.NoArgsConstructor; - -@Entity -@Table(name = "items") -@NoArgsConstructor(access = AccessLevel.PROTECTED) -@Getter -public class Item extends BaseEntity { - @Id - @GeneratedValue(strategy = GenerationType.IDENTITY) - @Column(name = "item_id", nullable = false) - private Long itemId; - - @Column(name = "item_name", nullable = false) - private String itemName; - - @Enumerated(EnumType.STRING) - @Column(name = "price_range", nullable = false) - private PriceRange priceRange; - - @OneToOne(fetch = FetchType.LAZY) - @JoinColumn(name = "category_id") - private Category category; - - @Builder - private Item( - String itemName, - PriceRange priceRange, - Category category - ) { - if (itemName.isBlank()) { - throw new BaseException(ErrorCode.UNKNOWN); - } - - if (priceRange == null || category == null) { - throw new BaseException(ErrorCode.UNKNOWN); - } - - this.itemName = itemName; - this.priceRange = priceRange; - this.category = category; - } - - public void updateItem( - String itemName, - PriceRange priceRange, - Category category - ) { - this.itemName = itemName; - this.priceRange = priceRange; - this.category = category; - } -} diff --git a/nabimarket-infra/src/main/java/org/prgrms/nabimarketbe/jpa/item/entity/PriceRange.java b/nabimarket-infra/src/main/java/org/prgrms/nabimarketbe/jpa/item/entity/PriceRange.java deleted file mode 100644 index 07a9cf62..00000000 --- a/nabimarket-infra/src/main/java/org/prgrms/nabimarketbe/jpa/item/entity/PriceRange.java +++ /dev/null @@ -1,33 +0,0 @@ -package org.prgrms.nabimarketbe.jpa.item.entity; - -import lombok.Getter; - -@Getter -public enum PriceRange { - PRICE_RANGE_ONE(1, 0, 10_000), - PRICE_RANGE_TWO(2, 10_000, 50_000), - PRICE_RANGE_THREE(3, 50_000, 100_000), - PRICE_RANGE_FOUR(4, 100_000, 200_000), - PRICE_RANGE_FIVE(5, 200_000, 300_000), - PRICE_RANGE_SIX(6, 300_000, 400_000), - PRICE_RANGE_SEVEN(7, 400_000, 500_000), - PRICE_RANGE_EIGHT(8, 500_000, Integer.MAX_VALUE); - - private Integer value; - private Integer priceFrom; - private Integer priceTo; - - PriceRange( - Integer value, - Integer priceFrom, - Integer priceTo - ) { - this.value = value; - this.priceFrom = priceFrom; - this.priceTo = priceTo; - } - - public boolean isHigherThan(PriceRange priceRange) { - return this.value > priceRange.value; - } -} diff --git a/nabimarket-infra/src/main/java/org/prgrms/nabimarketbe/jpa/item/repository/ItemRepository.java b/nabimarket-infra/src/main/java/org/prgrms/nabimarketbe/jpa/item/repository/ItemRepository.java deleted file mode 100644 index 6be713cd..00000000 --- a/nabimarket-infra/src/main/java/org/prgrms/nabimarketbe/jpa/item/repository/ItemRepository.java +++ /dev/null @@ -1,7 +0,0 @@ -package org.prgrms.nabimarketbe.jpa.item.repository; - -import org.prgrms.nabimarketbe.jpa.item.entity.Item; -import org.springframework.data.jpa.repository.JpaRepository; - -public interface ItemRepository extends JpaRepository { -} diff --git a/nabimarket-infra/src/main/java/org/prgrms/nabimarketbe/jpa/notification/entity/Notification.java b/nabimarket-infra/src/main/java/org/prgrms/nabimarketbe/jpa/notification/entity/Notification.java deleted file mode 100644 index c105c86f..00000000 --- a/nabimarket-infra/src/main/java/org/prgrms/nabimarketbe/jpa/notification/entity/Notification.java +++ /dev/null @@ -1,59 +0,0 @@ -package org.prgrms.nabimarketbe.jpa.notification.entity; - -import javax.persistence.Column; -import javax.persistence.Entity; -import javax.persistence.FetchType; -import javax.persistence.GeneratedValue; -import javax.persistence.GenerationType; -import javax.persistence.Id; -import javax.persistence.JoinColumn; -import javax.persistence.ManyToOne; -import javax.persistence.Table; - -import org.prgrms.nabimarketbe.jpa.BaseEntity; -import org.prgrms.nabimarketbe.jpa.card.entity.Card; -import org.prgrms.nabimarketbe.jpa.user.entity.User; - -import lombok.AccessLevel; -import lombok.Getter; -import lombok.NoArgsConstructor; - -@Getter -@Entity -@Table(name = "notifications") -@NoArgsConstructor(access = AccessLevel.PROTECTED) -public class Notification extends BaseEntity { - @Id - @GeneratedValue(strategy = GenerationType.IDENTITY) - @Column(name = "notifiaction_id", nullable = false) - private Long notificationId; - - @Column(name = "content", nullable = false) - private String content; - - @ManyToOne(fetch = FetchType.LAZY) - @JoinColumn(name = "user_id", nullable = false) - private User receiver; - - @ManyToOne(fetch = FetchType.LAZY) - @JoinColumn(name = "card_id", nullable = false) - private Card card; - - @Column(name = "is_read", nullable = false) - private boolean isRead; - - public Notification( - User user, - Card card, - String content - ) { - this.receiver = user; - this.card = card; - this.content = content; - this.isRead = false; - } - - public void updateToRead() { - this.isRead = true; - } -} diff --git a/nabimarket-infra/src/main/java/org/prgrms/nabimarketbe/jpa/notification/projection/NotificationDetailResponseDTO.java b/nabimarket-infra/src/main/java/org/prgrms/nabimarketbe/jpa/notification/projection/NotificationDetailResponseDTO.java deleted file mode 100644 index d446722c..00000000 --- a/nabimarket-infra/src/main/java/org/prgrms/nabimarketbe/jpa/notification/projection/NotificationDetailResponseDTO.java +++ /dev/null @@ -1,20 +0,0 @@ -package org.prgrms.nabimarketbe.jpa.notification.projection; - -import java.time.LocalDateTime; - -import lombok.Getter; - -@Getter -public class NotificationDetailResponseDTO { - private Long notificationId; - - private String content; - - private boolean isRead; - - private Long cardId; - - private LocalDateTime createdAt; - - private LocalDateTime modifiedAt; -} diff --git a/nabimarket-infra/src/main/java/org/prgrms/nabimarketbe/jpa/notification/projection/NotificationPagingResponseDTO.java b/nabimarket-infra/src/main/java/org/prgrms/nabimarketbe/jpa/notification/projection/NotificationPagingResponseDTO.java deleted file mode 100644 index 5e9a07e1..00000000 --- a/nabimarket-infra/src/main/java/org/prgrms/nabimarketbe/jpa/notification/projection/NotificationPagingResponseDTO.java +++ /dev/null @@ -1,11 +0,0 @@ -package org.prgrms.nabimarketbe.jpa.notification.projection; - -import java.util.List; - -import org.prgrms.nabimarketbe.jpa.notification.projection.NotificationDetailResponseDTO; - -public record NotificationPagingResponseDTO( - List notificationList, - String nextCursorId -) { -} diff --git a/nabimarket-infra/src/main/java/org/prgrms/nabimarketbe/jpa/notification/repository/NotificationRepository.java b/nabimarket-infra/src/main/java/org/prgrms/nabimarketbe/jpa/notification/repository/NotificationRepository.java deleted file mode 100644 index 2e73ccca..00000000 --- a/nabimarket-infra/src/main/java/org/prgrms/nabimarketbe/jpa/notification/repository/NotificationRepository.java +++ /dev/null @@ -1,19 +0,0 @@ -package org.prgrms.nabimarketbe.jpa.notification.repository; - -import java.util.List; - -import org.prgrms.nabimarketbe.jpa.notification.entity.Notification; -import org.prgrms.nabimarketbe.jpa.user.entity.User; -import org.springframework.data.jpa.repository.JpaRepository; -import org.springframework.data.jpa.repository.Modifying; -import org.springframework.data.jpa.repository.Query; - -public interface NotificationRepository extends JpaRepository, NotificationRepositoryCustom { - Long countNotificationByIsReadIsFalseAndReceiver(User receiver); - - @Query("UPDATE Notification n " - + "SET n.isRead=true " - + "WHERE n.receiver = :receiver AND n.notificationId in :notificationIds") - @Modifying(clearAutomatically = true) - void bulkUpdateNotificationsByIds(List notificationIds, User receiver); -} diff --git a/nabimarket-infra/src/main/java/org/prgrms/nabimarketbe/jpa/notification/repository/NotificationRepositoryCustom.java b/nabimarket-infra/src/main/java/org/prgrms/nabimarketbe/jpa/notification/repository/NotificationRepositoryCustom.java deleted file mode 100644 index 875cd59a..00000000 --- a/nabimarket-infra/src/main/java/org/prgrms/nabimarketbe/jpa/notification/repository/NotificationRepositoryCustom.java +++ /dev/null @@ -1,15 +0,0 @@ -package org.prgrms.nabimarketbe.jpa.notification.repository; - -import org.prgrms.nabimarketbe.jpa.notification.projection.NotificationPagingResponseDTO; -import org.prgrms.nabimarketbe.jpa.user.entity.User; -import org.springframework.data.domain.Pageable; - -public interface NotificationRepositoryCustom { - NotificationPagingResponseDTO getNotificationsByIsRead( - User receiver, - Boolean isRead, - Integer size, - String cursorId, - Pageable pageable - ); -} diff --git a/nabimarket-infra/src/main/java/org/prgrms/nabimarketbe/jpa/notification/repository/NotificationRepositoryImpl.java b/nabimarket-infra/src/main/java/org/prgrms/nabimarketbe/jpa/notification/repository/NotificationRepositoryImpl.java deleted file mode 100644 index dd50b5ae..00000000 --- a/nabimarket-infra/src/main/java/org/prgrms/nabimarketbe/jpa/notification/repository/NotificationRepositoryImpl.java +++ /dev/null @@ -1,105 +0,0 @@ -package org.prgrms.nabimarketbe.jpa.notification.repository; - -import java.util.List; - -import org.prgrms.nabimarketbe.jpa.notification.entity.QNotification; -import org.prgrms.nabimarketbe.jpa.notification.projection.NotificationDetailResponseDTO; -import org.prgrms.nabimarketbe.jpa.notification.projection.NotificationPagingResponseDTO; -import org.prgrms.nabimarketbe.jpa.user.entity.User; -import org.prgrms.nabimarketbe.jpa.util.CursorPaging; -import org.prgrms.nabimarketbe.jpa.util.QueryDslUtil; -import org.springframework.data.domain.Pageable; - -import com.querydsl.core.types.ConstantImpl; -import com.querydsl.core.types.Projections; -import com.querydsl.core.types.dsl.BooleanExpression; -import com.querydsl.core.types.dsl.Expressions; -import com.querydsl.core.types.dsl.StringExpression; -import com.querydsl.core.types.dsl.StringExpressions; -import com.querydsl.core.types.dsl.StringTemplate; -import com.querydsl.jpa.impl.JPAQueryFactory; - -import lombok.RequiredArgsConstructor; - -@RequiredArgsConstructor -public class NotificationRepositoryImpl implements NotificationRepositoryCustom, CursorPaging { - private final JPAQueryFactory jpaQueryFactory; - - @Override - public NotificationPagingResponseDTO getNotificationsByIsRead( - User receiver, - Boolean isRead, - Integer size, - String cursorId, - Pageable pageable - ) { - List notificationList = jpaQueryFactory.select( - Projections.fields( - NotificationDetailResponseDTO.class, - QNotification.notification.notificationId, - QNotification.notification.content, - QNotification.notification.isRead, - QNotification.notification.card.cardId, - QNotification.notification.createdDate.as("createdAt"), - QNotification.notification.modifiedDate.as("modifiedAt") - ) - ) - .from(QNotification.notification) - .where( - receiverEquals(receiver), - cursorId(cursorId), - isReadEquals(isRead) - ) - .orderBy(QueryDslUtil.getOrderSpecifier(pageable.getSort(), QNotification.notification)) - .limit(pageable.getPageSize()) - .fetch(); - - String nextCursorId = notificationList.size() < pageable.getPageSize() ? - null : generateCursor(notificationList.get(notificationList.size() - 1)); - - return new NotificationPagingResponseDTO(notificationList, nextCursorId); - } - - @Override - public BooleanExpression cursorId(String cursorId) { - if (cursorId == null) { - return null; - } - - // 생성일자 - StringTemplate dateCursorTemplate = Expressions.stringTemplate( - "DATE_FORMAT({0}, {1})", - QNotification.notification.createdDate, - ConstantImpl.create("%Y%m%d%H%i%s") - ); - - // pk - StringExpression pkCursorTemplate = StringExpressions.lpad( - QNotification.notification.notificationId.stringValue(), - 8, - '0' - ); - - return dateCursorTemplate.concat(pkCursorTemplate).lt(cursorId); - } - - private BooleanExpression receiverEquals(User receiver) { - return QNotification.notification.receiver.eq(receiver); - } - - private String generateCursor(NotificationDetailResponseDTO notificationDetailResponseDTO) { - return notificationDetailResponseDTO.getCreatedAt().toString() // 디폴트는 생성일자 최신순 정렬 - .replace("T", "") - .replace("-", "") - .replace(":", "") - + String.format("%08d", notificationDetailResponseDTO.getNotificationId()); - } - - private BooleanExpression isReadEquals(Boolean isRead) { - if (isRead == null) { - return null; - } - - return QNotification.notification.isRead.eq(isRead); - } -} diff --git a/nabimarket-infra/src/main/java/org/prgrms/nabimarketbe/jpa/refreshtoken/entity/RefreshToken.java b/nabimarket-infra/src/main/java/org/prgrms/nabimarketbe/jpa/refreshtoken/entity/RefreshToken.java deleted file mode 100644 index 3debe738..00000000 --- a/nabimarket-infra/src/main/java/org/prgrms/nabimarketbe/jpa/refreshtoken/entity/RefreshToken.java +++ /dev/null @@ -1,43 +0,0 @@ -package org.prgrms.nabimarketbe.jpa.refreshtoken.entity; - -import javax.persistence.Column; -import javax.persistence.Entity; -import javax.persistence.GeneratedValue; -import javax.persistence.GenerationType; -import javax.persistence.Id; -import javax.persistence.Table; - -import org.prgrms.nabimarketbe.jpa.BaseEntity; - -import lombok.Getter; -import lombok.NoArgsConstructor; - -@Entity -@Table(name = "refresh_token") -@Getter -@NoArgsConstructor -public class RefreshToken extends BaseEntity { - @Id - @GeneratedValue(strategy = GenerationType.IDENTITY) - private Long id; - - @Column(nullable = false, unique = true) - private Long userId; - - @Column(nullable = false, unique = true) - private String token; - - public RefreshToken updateToken(String token) { - this.token = token; - - return this; - } - - public RefreshToken( - Long userId, - String token - ) { - this.userId = userId; - this.token = token; - } -} diff --git a/nabimarket-infra/src/main/java/org/prgrms/nabimarketbe/jpa/refreshtoken/repository/RefreshTokenRepository.java b/nabimarket-infra/src/main/java/org/prgrms/nabimarketbe/jpa/refreshtoken/repository/RefreshTokenRepository.java deleted file mode 100644 index 07488022..00000000 --- a/nabimarket-infra/src/main/java/org/prgrms/nabimarketbe/jpa/refreshtoken/repository/RefreshTokenRepository.java +++ /dev/null @@ -1,10 +0,0 @@ -package org.prgrms.nabimarketbe.jpa.refreshtoken.repository; - -import java.util.Optional; - -import org.prgrms.nabimarketbe.jpa.refreshtoken.entity.RefreshToken; -import org.springframework.data.jpa.repository.JpaRepository; - -public interface RefreshTokenRepository extends JpaRepository { - Optional findByUserId(Long userId); -} diff --git a/nabimarket-infra/src/main/java/org/prgrms/nabimarketbe/jpa/suggestion/entity/DirectionType.java b/nabimarket-infra/src/main/java/org/prgrms/nabimarketbe/jpa/suggestion/entity/DirectionType.java deleted file mode 100644 index a481796c..00000000 --- a/nabimarket-infra/src/main/java/org/prgrms/nabimarketbe/jpa/suggestion/entity/DirectionType.java +++ /dev/null @@ -1,6 +0,0 @@ -package org.prgrms.nabimarketbe.jpa.suggestion.entity; - -public enum DirectionType { - SEND, - RECEIVE -} diff --git a/nabimarket-infra/src/main/java/org/prgrms/nabimarketbe/jpa/suggestion/entity/Suggestion.java b/nabimarket-infra/src/main/java/org/prgrms/nabimarketbe/jpa/suggestion/entity/Suggestion.java deleted file mode 100644 index 63068bf6..00000000 --- a/nabimarket-infra/src/main/java/org/prgrms/nabimarketbe/jpa/suggestion/entity/Suggestion.java +++ /dev/null @@ -1,112 +0,0 @@ -package org.prgrms.nabimarketbe.jpa.suggestion.entity; - -import javax.persistence.Entity; -import javax.persistence.EnumType; -import javax.persistence.Enumerated; -import javax.persistence.FetchType; -import javax.persistence.GeneratedValue; -import javax.persistence.GenerationType; -import javax.persistence.Id; -import javax.persistence.JoinColumn; -import javax.persistence.ManyToOne; -import javax.persistence.Table; -import javax.persistence.UniqueConstraint; - -import org.prgrms.nabimarketbe.jpa.BaseEntity; -import org.prgrms.nabimarketbe.jpa.card.entity.Card; -import org.prgrms.nabimarketbe.error.BaseException; -import org.prgrms.nabimarketbe.error.ErrorCode; - -import lombok.Builder; -import lombok.Getter; -import lombok.NoArgsConstructor; - -@Entity -@Getter -@NoArgsConstructor -@Table(name = "suggestions", - uniqueConstraints = { - @UniqueConstraint( - name = "suggestion_unique", - columnNames = {"from_card", "to_card"} - ) - }) -public class Suggestion extends BaseEntity { - @Id - @GeneratedValue(strategy = GenerationType.IDENTITY) - private Long suggestionId; - - @Enumerated(EnumType.STRING) - private SuggestionType suggestionType; - - @ManyToOne(fetch = FetchType.LAZY) - @JoinColumn(name = "from_card", nullable = false) - private Card fromCard; - - @ManyToOne(fetch = FetchType.LAZY) - @JoinColumn(name = "to_card", nullable = false) - private Card toCard; - - @Enumerated(EnumType.STRING) - private SuggestionStatus suggestionStatus; - - @Builder - public Suggestion( - SuggestionType suggestionType, - Card fromCard, - Card toCard - ) { - if (suggestionType == null || fromCard == null || toCard == null) { - throw new BaseException(ErrorCode.INVALID_REQUEST); - } - - this.suggestionType = suggestionType; - this.fromCard = fromCard; - this.toCard = toCard; - this.suggestionStatus = SuggestionStatus.WAITING; - } - - public boolean isAccepted() { - return suggestionStatus.equals(SuggestionStatus.ACCEPTED); - } - - public void decideSuggestion(Boolean isAccpeted) { - if (isAccpeted) { - acceptSuggestion(); - } else { - refuseSuggestion(); - } - } - - public String createSuggestionRequestMessage() { - String message = String.format( - "%s에 대한 %s님의 새로운 제안이 도착하였습니다.", - toCard.getItem().getItemName(), - fromCard.getUser().getNickname() - ); - - return message; - } - - public String createSuggestionDecisionMessage(boolean isAccepted) { - String suggestionResult = isAccepted ? "수락" : "거절"; - String suggestionType = this.suggestionType.getName(); - String message = String.format( - "%s에 대한 %s의 %s이(가) %s 되었습니다.", - toCard.getItem().getItemName(), - fromCard.getItem().getItemName(), - suggestionType, - suggestionResult - ); - - return message; - } - - private void acceptSuggestion() { - this.suggestionStatus = SuggestionStatus.ACCEPTED; - } - - private void refuseSuggestion() { - this.suggestionStatus = SuggestionStatus.REFUSED; - } -} diff --git a/nabimarket-infra/src/main/java/org/prgrms/nabimarketbe/jpa/suggestion/entity/SuggestionStatus.java b/nabimarket-infra/src/main/java/org/prgrms/nabimarketbe/jpa/suggestion/entity/SuggestionStatus.java deleted file mode 100644 index d718b99b..00000000 --- a/nabimarket-infra/src/main/java/org/prgrms/nabimarketbe/jpa/suggestion/entity/SuggestionStatus.java +++ /dev/null @@ -1,7 +0,0 @@ -package org.prgrms.nabimarketbe.jpa.suggestion.entity; - -public enum SuggestionStatus { - WAITING, - ACCEPTED, - REFUSED -} diff --git a/nabimarket-infra/src/main/java/org/prgrms/nabimarketbe/jpa/suggestion/entity/SuggestionType.java b/nabimarket-infra/src/main/java/org/prgrms/nabimarketbe/jpa/suggestion/entity/SuggestionType.java deleted file mode 100644 index f13e8bd5..00000000 --- a/nabimarket-infra/src/main/java/org/prgrms/nabimarketbe/jpa/suggestion/entity/SuggestionType.java +++ /dev/null @@ -1,33 +0,0 @@ -package org.prgrms.nabimarketbe.jpa.suggestion.entity; - -import java.util.function.BiFunction; - -import org.prgrms.nabimarketbe.jpa.item.entity.Item; - -import lombok.Getter; - -@Getter -public enum SuggestionType { - OFFER("오퍼", (fromItem, toItem) -> (fromItem.getPriceRange().equals(toItem.getPriceRange()) - || fromItem.getPriceRange().getValue() > toItem.getPriceRange().getValue())), - POKE("찔러보기", (fromItem, toItem) -> (fromItem.getPriceRange().getValue() < toItem.getPriceRange().getValue())); - - private final String name; - - public final BiFunction suggestionValidationFunction; - - SuggestionType( - String name, - BiFunction suggestionValidationFunction - ) { - this.name = name; - this.suggestionValidationFunction = suggestionValidationFunction; - } - - public boolean isSuggestionAvailable( - Item fromItem, - Item toItem - ) { - return this.suggestionValidationFunction.apply(fromItem, toItem); - } -} diff --git a/nabimarket-infra/src/main/java/org/prgrms/nabimarketbe/jpa/suggestion/projection/SuggestionDetailResponseDTO.java b/nabimarket-infra/src/main/java/org/prgrms/nabimarketbe/jpa/suggestion/projection/SuggestionDetailResponseDTO.java deleted file mode 100644 index de3333be..00000000 --- a/nabimarket-infra/src/main/java/org/prgrms/nabimarketbe/jpa/suggestion/projection/SuggestionDetailResponseDTO.java +++ /dev/null @@ -1,19 +0,0 @@ -package org.prgrms.nabimarketbe.jpa.suggestion.projection; - -import java.time.LocalDateTime; - -import org.prgrms.nabimarketbe.jpa.suggestion.entity.DirectionType; -import org.prgrms.nabimarketbe.jpa.suggestion.entity.SuggestionStatus; -import org.prgrms.nabimarketbe.jpa.suggestion.entity.SuggestionType; - -import lombok.Getter; - -@Getter -public class SuggestionDetailResponseDTO { - private Long suggestionId; - private SuggestionType suggestionType; - private SuggestionStatus suggestionStatus; - private LocalDateTime createdAt; - private LocalDateTime modifiedAt; - private DirectionType directionType; -} diff --git a/nabimarket-infra/src/main/java/org/prgrms/nabimarketbe/jpa/suggestion/projection/SuggestionInfo.java b/nabimarket-infra/src/main/java/org/prgrms/nabimarketbe/jpa/suggestion/projection/SuggestionInfo.java deleted file mode 100644 index e66a49d0..00000000 --- a/nabimarket-infra/src/main/java/org/prgrms/nabimarketbe/jpa/suggestion/projection/SuggestionInfo.java +++ /dev/null @@ -1,17 +0,0 @@ -package org.prgrms.nabimarketbe.jpa.suggestion.projection; - -import org.prgrms.nabimarketbe.jpa.suggestion.entity.SuggestionStatus; -import org.prgrms.nabimarketbe.jpa.suggestion.entity.SuggestionType; - -import lombok.Getter; - -@Getter -public class SuggestionInfo { - private SuggestionType suggestionType; - - private SuggestionStatus suggestionStatus; - - public void updateSuggestionType(SuggestionType suggestionType) { - this.suggestionType = suggestionType; - } -} diff --git a/nabimarket-infra/src/main/java/org/prgrms/nabimarketbe/jpa/suggestion/projection/SuggestionListReadPagingResponseDTO.java b/nabimarket-infra/src/main/java/org/prgrms/nabimarketbe/jpa/suggestion/projection/SuggestionListReadPagingResponseDTO.java deleted file mode 100644 index bf776687..00000000 --- a/nabimarket-infra/src/main/java/org/prgrms/nabimarketbe/jpa/suggestion/projection/SuggestionListReadPagingResponseDTO.java +++ /dev/null @@ -1,9 +0,0 @@ -package org.prgrms.nabimarketbe.jpa.suggestion.projection; - -import java.util.List; - -public record SuggestionListReadPagingResponseDTO( - List suggestionList, - String nextCursorId -) { -} diff --git a/nabimarket-infra/src/main/java/org/prgrms/nabimarketbe/jpa/suggestion/projection/SuggestionListReadResponseDTO.java b/nabimarket-infra/src/main/java/org/prgrms/nabimarketbe/jpa/suggestion/projection/SuggestionListReadResponseDTO.java deleted file mode 100644 index 1ab02536..00000000 --- a/nabimarket-infra/src/main/java/org/prgrms/nabimarketbe/jpa/suggestion/projection/SuggestionListReadResponseDTO.java +++ /dev/null @@ -1,12 +0,0 @@ -package org.prgrms.nabimarketbe.jpa.suggestion.projection; - -import org.prgrms.nabimarketbe.jpa.card.projection.CardInfoResponseDTO; - -import lombok.Getter; - -@Getter -public class SuggestionListReadResponseDTO { - private CardInfoResponseDTO cardInfo; - - private SuggestionDetailResponseDTO suggestionInfo; -} diff --git a/nabimarket-infra/src/main/java/org/prgrms/nabimarketbe/jpa/suggestion/repository/SuggestionRepository.java b/nabimarket-infra/src/main/java/org/prgrms/nabimarketbe/jpa/suggestion/repository/SuggestionRepository.java deleted file mode 100644 index 386d9f06..00000000 --- a/nabimarket-infra/src/main/java/org/prgrms/nabimarketbe/jpa/suggestion/repository/SuggestionRepository.java +++ /dev/null @@ -1,27 +0,0 @@ -package org.prgrms.nabimarketbe.jpa.suggestion.repository; - -import java.util.Optional; - -import org.prgrms.nabimarketbe.jpa.card.entity.Card; -import org.prgrms.nabimarketbe.jpa.suggestion.entity.Suggestion; -import org.springframework.data.jpa.repository.JpaRepository; -import org.springframework.data.jpa.repository.Query; -import org.springframework.data.repository.query.Param; - -public interface SuggestionRepository extends JpaRepository, SuggestionRepositoryCustom { - @Query("select s " - + "from Suggestion s " - + "where s.fromCard = :fromCard and s.toCard = :toCard " - + "or s.fromCard = :toCard and s.toCard = :fromCard") - Optional findSuggestionByFromCardAndToCard( - @Param("fromCard") Card fromCard, - @Param("toCard") Card toCard - ); - - @Query( - "select count(s.suggestionId) > 0 " + - "from Suggestion s " - + "where s.fromCard = :fromCard and s.toCard = :toCard " - + "or s.fromCard = :toCard and s.toCard = :fromCard") - Boolean exists(@Param("fromCard") Card fromCard, @Param("toCard") Card toCard); -} diff --git a/nabimarket-infra/src/main/java/org/prgrms/nabimarketbe/jpa/suggestion/repository/SuggestionRepositoryCustom.java b/nabimarket-infra/src/main/java/org/prgrms/nabimarketbe/jpa/suggestion/repository/SuggestionRepositoryCustom.java deleted file mode 100644 index 255ede1f..00000000 --- a/nabimarket-infra/src/main/java/org/prgrms/nabimarketbe/jpa/suggestion/repository/SuggestionRepositoryCustom.java +++ /dev/null @@ -1,16 +0,0 @@ -package org.prgrms.nabimarketbe.jpa.suggestion.repository; - -import org.prgrms.nabimarketbe.jpa.suggestion.entity.DirectionType; -import org.prgrms.nabimarketbe.jpa.suggestion.entity.SuggestionType; -import org.prgrms.nabimarketbe.jpa.suggestion.projection.SuggestionListReadPagingResponseDTO; - -public interface SuggestionRepositoryCustom { - SuggestionListReadPagingResponseDTO getSuggestionsByType( - DirectionType directionType, - SuggestionType suggestionType, - Long cardId, - String cursorId, - Integer size - ); - -} diff --git a/nabimarket-infra/src/main/java/org/prgrms/nabimarketbe/jpa/suggestion/repository/SuggestionRepositoryImpl.java b/nabimarket-infra/src/main/java/org/prgrms/nabimarketbe/jpa/suggestion/repository/SuggestionRepositoryImpl.java deleted file mode 100644 index 78c4c695..00000000 --- a/nabimarket-infra/src/main/java/org/prgrms/nabimarketbe/jpa/suggestion/repository/SuggestionRepositoryImpl.java +++ /dev/null @@ -1,168 +0,0 @@ -package org.prgrms.nabimarketbe.jpa.suggestion.repository; - -import java.util.List; - -import org.prgrms.nabimarketbe.error.BaseException; -import org.prgrms.nabimarketbe.error.ErrorCode; -import org.prgrms.nabimarketbe.jpa.card.entity.CardStatus; -import org.prgrms.nabimarketbe.jpa.card.entity.QCard; -import org.prgrms.nabimarketbe.jpa.card.projection.CardInfoResponseDTO; -import org.prgrms.nabimarketbe.jpa.suggestion.entity.DirectionType; -import org.prgrms.nabimarketbe.jpa.suggestion.entity.QSuggestion; -import org.prgrms.nabimarketbe.jpa.suggestion.entity.SuggestionType; -import org.prgrms.nabimarketbe.jpa.suggestion.projection.SuggestionDetailResponseDTO; -import org.prgrms.nabimarketbe.jpa.suggestion.projection.SuggestionListReadPagingResponseDTO; -import org.prgrms.nabimarketbe.jpa.suggestion.projection.SuggestionListReadResponseDTO; -import org.prgrms.nabimarketbe.jpa.util.QueryDslUtil; -import org.springframework.data.domain.Sort; - -import com.querydsl.core.types.ConstantImpl; -import com.querydsl.core.types.Projections; -import com.querydsl.core.types.dsl.BooleanExpression; -import com.querydsl.core.types.dsl.Expressions; -import com.querydsl.core.types.dsl.StringExpressions; -import com.querydsl.core.types.dsl.StringTemplate; -import com.querydsl.jpa.impl.JPAQueryFactory; - -import lombok.RequiredArgsConstructor; - -@RequiredArgsConstructor -public class SuggestionRepositoryImpl implements SuggestionRepositoryCustom { - private final JPAQueryFactory jpaQueryFactory; - - @Override - public SuggestionListReadPagingResponseDTO getSuggestionsByType( - DirectionType directionType, - SuggestionType suggestionType, - Long cardId, - String cursorId, - Integer size - ) { - List suggestionList = jpaQueryFactory - .select( - Projections.fields( - SuggestionListReadResponseDTO.class, - Projections.fields( - CardInfoResponseDTO.class, - getQCardCounter(directionType).cardId, - getQCardCounter(directionType).cardTitle, - getQCardCounter(directionType).item.itemName, - getQCardCounter(directionType).item.priceRange, - getQCardCounter(directionType).thumbnail - ).as("cardInfo"), - Projections.fields( - SuggestionDetailResponseDTO.class, - QSuggestion.suggestion.suggestionId, - QSuggestion.suggestion.suggestionType, - QSuggestion.suggestion.suggestionStatus, - QSuggestion.suggestion.createdDate.as("createdAt"), - QSuggestion.suggestion.modifiedDate.as("modifiedAt"), - Expressions.as(Expressions.constant(directionType), "directionType") - ).as("suggestionInfo") - ) - ) - .from(QSuggestion.suggestion) - .join(getQcardByDirectionType(directionType), QCard.card) - .on(getExpressionByDirectionType(directionType, cardId)) - .where( - cursorIdLessThan(cursorId), - suggestionTypeEquals(suggestionType), - getQCardCounter(directionType).isActive.eq(true), - getQCardCounter(directionType).status.eq(CardStatus.TRADE_AVAILABLE) - ) - .orderBy( - QueryDslUtil.getOrderSpecifier( - Sort.by( - Sort.Order.desc("createdDate"), - Sort.Order.desc("suggestionId") - ), - QSuggestion.suggestion - ) - ) - .limit(size) - .fetch(); - - String nextCursor = suggestionList.size() < size - ? null : createCursorId(suggestionList.get(suggestionList.size() - 1)); - - return new SuggestionListReadPagingResponseDTO(suggestionList, nextCursor); - } - - /** - * 오퍼, 찔러보기 필터링 - */ - private BooleanExpression suggestionTypeEquals(SuggestionType suggestionType) { - if (suggestionType == null) { - throw new BaseException(ErrorCode.INVALID_REQUEST); - } - - return QSuggestion.suggestion.suggestionType.eq(suggestionType); - } - - /** - * 커스텀 커서 id가 주어진 cursorId보다 작은지 확인 - */ - private BooleanExpression cursorIdLessThan(String cursorId) { - if (cursorId == null) { - return null; - } - - StringTemplate stringTemplate = Expressions.stringTemplate( - "DATE_FORMAT({0}, {1})", - QSuggestion.suggestion.createdDate, - ConstantImpl.create("%Y%m%d%H%i%s") - ); - - return stringTemplate.concat(StringExpressions.lpad( - QSuggestion.suggestion.suggestionId.stringValue(), - 8, - '0' - )).lt(cursorId); - } - - /** - * 커서 id 생성 - */ - private String createCursorId(SuggestionListReadResponseDTO suggestionListReadResponseDTO) { - return suggestionListReadResponseDTO.getSuggestionInfo().getCreatedAt().toString() - .replace("T", "") - .replace("-", "") - .replace(":", "") - + String.format("%08d", suggestionListReadResponseDTO.getSuggestionInfo().getSuggestionId()); - } - - /** - * 내 카드의 대상이 받은 / 보낸 제안인지에 따른 join 절 분기문 처리 - */ - private QCard getQcardByDirectionType(DirectionType directionType) { - return switch (directionType) { - case RECEIVE -> QSuggestion.suggestion.toCard; - case SEND -> QSuggestion.suggestion.fromCard; - }; - } - - /** - * 받은 / 보낸 제안인지에 따른 Projections.fields 분기문 처리 - * 내가 받은 제안 조회 -> fromCard 필드 - * 내가 보낸 제안 -> toCard 필드 - */ - private QCard getQCardCounter(DirectionType directionType) { - return switch (directionType) { - case RECEIVE -> QSuggestion.suggestion.fromCard; - case SEND -> QSuggestion.suggestion.toCard; - }; - } - - /** - * 받은 / 보낸 제안인지에 따른 on 절 분기문 처리 - */ - private BooleanExpression getExpressionByDirectionType( - DirectionType directionType, - Long cardId - ) { - return switch (directionType) { - case RECEIVE -> QSuggestion.suggestion.toCard.cardId.eq(cardId); - case SEND -> QSuggestion.suggestion.fromCard.cardId.eq(cardId); - }; - } -} diff --git a/nabimarket-infra/src/main/java/org/prgrms/nabimarketbe/jpa/user/entity/Role.java b/nabimarket-infra/src/main/java/org/prgrms/nabimarketbe/jpa/user/entity/Role.java deleted file mode 100644 index 9bed9cac..00000000 --- a/nabimarket-infra/src/main/java/org/prgrms/nabimarketbe/jpa/user/entity/Role.java +++ /dev/null @@ -1,14 +0,0 @@ -package org.prgrms.nabimarketbe.jpa.user.entity; - -import lombok.Getter; -import lombok.RequiredArgsConstructor; - -@Getter -@RequiredArgsConstructor -public enum Role { - GUEST("ROLE_GUEST"), - - USER("ROLE_USER"); - - private final String key; -} diff --git a/nabimarket-infra/src/main/java/org/prgrms/nabimarketbe/jpa/user/entity/User.java b/nabimarket-infra/src/main/java/org/prgrms/nabimarketbe/jpa/user/entity/User.java deleted file mode 100644 index 703725c0..00000000 --- a/nabimarket-infra/src/main/java/org/prgrms/nabimarketbe/jpa/user/entity/User.java +++ /dev/null @@ -1,118 +0,0 @@ -package org.prgrms.nabimarketbe.jpa.user.entity; - -import java.util.Collection; -import java.util.Collections; - -import javax.persistence.Column; -import javax.persistence.Entity; -import javax.persistence.GeneratedValue; -import javax.persistence.GenerationType; -import javax.persistence.Id; -import javax.persistence.Table; - -import org.prgrms.nabimarketbe.jpa.BaseEntity; -import org.prgrms.nabimarketbe.error.BaseException; -import org.prgrms.nabimarketbe.error.ErrorCode; -import org.springframework.security.core.GrantedAuthority; -import org.springframework.security.core.authority.SimpleGrantedAuthority; -import org.springframework.security.core.userdetails.UserDetails; - -import com.fasterxml.jackson.annotation.JsonProperty; - -import lombok.AllArgsConstructor; -import lombok.Builder; -import lombok.Getter; -import lombok.NoArgsConstructor; - -@Entity -@Getter -@NoArgsConstructor -@AllArgsConstructor -@Table(name = "users") -public class User extends BaseEntity implements UserDetails { - @Id - @GeneratedValue(strategy = GenerationType.IDENTITY) - private Long userId; - - @Column(nullable = false, unique = true, length = 30) - private String accountId; - - @Column(name = "nickname", nullable = false, length = 20, unique = true) - private String nickname; - - @Column(name = "user_image_url") - private String imageUrl; - - @Column(length = 100, nullable = false) - private String provider; - - @Column(name = "user_role", nullable = false) - private String role; - - @Builder - private User( - String accountId, - String nickname, - String imageUrl, - String provider, - String role - ) { - if (accountId.isBlank() || nickname.isBlank() || provider.isBlank() || role.isBlank()) { - throw new BaseException(ErrorCode.INVALID_REQUEST); - } - - this.accountId = accountId; - this.nickname = nickname; - this.imageUrl = imageUrl; - this.provider = provider; - this.role = role; - } - - public void updateNickname(String nickname) { - this.nickname = nickname; - } - - public void updateImageUrl(String imageUrl) { - this.imageUrl = imageUrl; - } - - @Override - public Collection getAuthorities() { - return Collections.singletonList(new SimpleGrantedAuthority(this.role.toString())); - } - - @Override - public String getPassword() { - return null; - } - - @JsonProperty(access = JsonProperty.Access.WRITE_ONLY) - @Override - public String getUsername() { - return String.valueOf(this.userId); - } - - @JsonProperty(access = JsonProperty.Access.WRITE_ONLY) - @Override - public boolean isAccountNonExpired() { - return true; - } - - @JsonProperty(access = JsonProperty.Access.WRITE_ONLY) - @Override - public boolean isAccountNonLocked() { - return true; - } - - @JsonProperty(access = JsonProperty.Access.WRITE_ONLY) - @Override - public boolean isCredentialsNonExpired() { - return true; - } - - @JsonProperty(access = JsonProperty.Access.WRITE_ONLY) - @Override - public boolean isEnabled() { - return true; - } -} diff --git a/nabimarket-infra/src/main/java/org/prgrms/nabimarketbe/jpa/user/projection/UserIdResponseDTO.java b/nabimarket-infra/src/main/java/org/prgrms/nabimarketbe/jpa/user/projection/UserIdResponseDTO.java deleted file mode 100644 index 90dfb975..00000000 --- a/nabimarket-infra/src/main/java/org/prgrms/nabimarketbe/jpa/user/projection/UserIdResponseDTO.java +++ /dev/null @@ -1,4 +0,0 @@ -package org.prgrms.nabimarketbe.jpa.user.projection; - -public record UserIdResponseDTO(Long userId) { -} diff --git a/nabimarket-infra/src/main/java/org/prgrms/nabimarketbe/jpa/user/repository/UserRepository.java b/nabimarket-infra/src/main/java/org/prgrms/nabimarketbe/jpa/user/repository/UserRepository.java deleted file mode 100644 index 493dc151..00000000 --- a/nabimarket-infra/src/main/java/org/prgrms/nabimarketbe/jpa/user/repository/UserRepository.java +++ /dev/null @@ -1,18 +0,0 @@ -package org.prgrms.nabimarketbe.jpa.user.repository; - -import java.util.Optional; - -import org.prgrms.nabimarketbe.jpa.user.entity.User; -import org.springframework.data.jpa.repository.JpaRepository; -import org.springframework.stereotype.Repository; - -@Repository -public interface UserRepository extends JpaRepository { - Optional findByNickname(String name); - - Optional findByAccountIdAndProvider(String accountId, String provider); - - Optional findByAccountId(String oauthId); - - boolean existsUserByNickname(String nickname); -} diff --git a/nabimarket-infra/src/main/java/org/prgrms/nabimarketbe/jpa/util/CursorPaging.java b/nabimarket-infra/src/main/java/org/prgrms/nabimarketbe/jpa/util/CursorPaging.java deleted file mode 100644 index a36b1f82..00000000 --- a/nabimarket-infra/src/main/java/org/prgrms/nabimarketbe/jpa/util/CursorPaging.java +++ /dev/null @@ -1,12 +0,0 @@ -package org.prgrms.nabimarketbe.jpa.util; - -import com.querydsl.core.types.dsl.BooleanExpression; - -public interface CursorPaging { - /** - * cursorId를 받아 cursor Id로 조건절을 만드는 메소드 - * @param cursorId - * @return - */ - BooleanExpression cursorId(String cursorId); -} diff --git a/nabimarket-infra/src/main/java/org/prgrms/nabimarketbe/jpa/util/KeyGenerator.java b/nabimarket-infra/src/main/java/org/prgrms/nabimarketbe/jpa/util/KeyGenerator.java deleted file mode 100644 index 98f521c7..00000000 --- a/nabimarket-infra/src/main/java/org/prgrms/nabimarketbe/jpa/util/KeyGenerator.java +++ /dev/null @@ -1,33 +0,0 @@ -package org.prgrms.nabimarketbe.jpa.util; - -public class KeyGenerator { - public static final String CARD_VIEW_CACHE_PREFIX = "CARD-VIEW-CACHE:"; - - private static final String CARD_VIEW_LOCK_PREFIX = "CARD-VIEW-LOCK:"; - - private static final String CARD_READER_CACHE_PREFIX = "CARD-READER-CACHE:"; - - private static final String SUGGESTION_CREATE_LOCK_PREFIX = "SUGGESTION-CREATE-LOCK:"; - - public static String generateSuggestionLockKey( - Long fromCardId, - Long toCardId - ) { - Long firstId = Math.min(fromCardId, toCardId); - Long secondId = Math.max(fromCardId, toCardId); - - return SUGGESTION_CREATE_LOCK_PREFIX + String.format("%d-%d", firstId, secondId); - } - - public static String generateCardViewLockKey(Long cardId) { - return CARD_VIEW_LOCK_PREFIX + cardId; - } - - public static String generateCardViewCacheKey(Long cardId) { - return CARD_VIEW_CACHE_PREFIX + cardId; - } - - public static String generateCardReaderCacheKey(Long userId) { - return CARD_READER_CACHE_PREFIX + userId; - } -} diff --git a/nabimarket-infra/src/main/java/org/prgrms/nabimarketbe/jpa/util/OrderCondition.java b/nabimarket-infra/src/main/java/org/prgrms/nabimarketbe/jpa/util/OrderCondition.java deleted file mode 100644 index ae0861d1..00000000 --- a/nabimarket-infra/src/main/java/org/prgrms/nabimarketbe/jpa/util/OrderCondition.java +++ /dev/null @@ -1,5 +0,0 @@ -package org.prgrms.nabimarketbe.jpa.util; - -public enum OrderCondition { - CARD_CREATED_DESC -} diff --git a/nabimarket-infra/src/main/java/org/prgrms/nabimarketbe/jpa/util/QueryDslUtil.java b/nabimarket-infra/src/main/java/org/prgrms/nabimarketbe/jpa/util/QueryDslUtil.java deleted file mode 100644 index 1997d7c5..00000000 --- a/nabimarket-infra/src/main/java/org/prgrms/nabimarketbe/jpa/util/QueryDslUtil.java +++ /dev/null @@ -1,54 +0,0 @@ -package org.prgrms.nabimarketbe.jpa.util; - -import java.util.ArrayList; -import java.util.List; - -import org.springframework.data.domain.Sort; - -import com.querydsl.core.types.Order; -import com.querydsl.core.types.OrderSpecifier; -import com.querydsl.core.types.Path; -import com.querydsl.core.types.dsl.Expressions; - -public class QueryDslUtil { - /** - * 정렬을 기준을 반환하기 위한 메소드. - * 여러 정렬 조건들을 반환할 수 있다. - * - * @param sort Sort 객체 - * @param parent compileQuerydsl 빌드를 통해서 생성된 Q타입 클래스의 객체(Sort의 대상이 되는 Q타입 클래스 객체를 전달한다.) - * @return - */ - public static OrderSpecifier[] getOrderSpecifier( - Sort sort, - Path parent - ) { - List orders = new ArrayList<>(); - - for (Sort.Order order : sort) { // Sort에 여러 정렬 기준이 담겨 올 수 있음 - Order direction = order.getDirection().isAscending() ? Order.ASC : Order.DESC; - orders.add(QueryDslUtil.getSortedColumn(direction, parent, order.getProperty())); - } - - return orders.toArray(OrderSpecifier[]::new); - } - - /** - * Order, Path, fieldName을 전달하면 OrderSpecifier 객체를 리턴하는 Util 클래스. - * Sort시 마다 사용할 수 있도록 한다. - * - * @param order - * @param parent compileQuerydsl 빌드를 통해서 생성된 Q타입 클래스의 객체(Sort의 대상이 되는 Q타입 클래스 객체를 전달한다.) - * @param fieldName - * @return OrderSpecifier 객체 - */ - public static OrderSpecifier getSortedColumn( - Order order, - Path parent, - String fieldName - ) { - Path fieldPath = Expressions.path(Object.class, parent, fieldName); - - return new OrderSpecifier(order, fieldPath); - } -} From 5ffbece94a92ba7b3ca388a86868be1c579f4d7b Mon Sep 17 00:00:00 2001 From: BeommoKoo-dev <95630007+BeommoKoo-dev@users.noreply.github.com> Date: Mon, 22 Jan 2024 22:16:35 +0900 Subject: [PATCH 2/2] =?UTF-8?q?revert=20:=20=EA=B8=B0=EC=A1=B4=20infra=20?= =?UTF-8?q?=ED=81=B4=EB=9E=98=EC=8A=A4=20domain=EB=AA=A8=EB=93=88=EB=A1=9C?= =?UTF-8?q?=20revert?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- build.gradle | 1 + .../nabimarketbe/card/CardController.java | 18 +- .../chatroom/ChatRoomController.java | 5 +- .../CompleteRequestController.java | 7 +- .../nabimarketbe/dibs/DibController.java | 2 +- .../notification/NotificationController.java | 2 +- .../suggestion/SuggestionController.java | 9 +- .../dto/request/CardCreateRequestDTO.java | 14 +- .../request/CardStatusUpdateRequestDTO.java | 2 +- .../dto/request/CardUpdateRequestDTO.java | 14 +- .../dto/response/CardCreateResponseDTO.java | 12 +- .../dto/response/CardDetailResponseDTO.java | 13 +- .../dto/response/CardUpdateResponseDTO.java | 12 +- .../card/service/CardService.java | 44 +-- .../card/service/CardViewCountService.java | 4 +- .../request/CardImageCreateRequestDTO.java | 5 +- .../chatroom/service/ChatRoomService.java | 15 +- .../response/CompleteRequestResponseDTO.java | 4 +- .../service/CompleteRequestService.java | 33 +-- .../config/SecurityConfiguration.java | 2 +- .../dto/response/DibCreateResponseDTO.java | 2 +- .../nabimarketbe/dibs/service/DibService.java | 14 +- .../event/NotificationCreateEvent.java | 4 +- .../jwt/provider/JwtProvider.java | 4 +- .../service/NotificationService.java | 13 +- .../oauth2/google/dto/GoogleUserInfoDTO.java | 4 +- .../service/CustomUserDetailsService.java | 2 +- .../dto/response/SuggestionResponseDTO.java | 6 +- .../suggestion/service/SuggestionService.java | 21 +- .../user/dto/request/SocialUserInfoDTO.java | 4 +- .../user/dto/response/UserGetResponseDTO.java | 2 +- .../dto/response/UserLoginResponseDTO.java | 2 +- .../dto/response/UserSummaryResponseDTO.java | 3 +- .../dto/response/UserUpdateResponseDTO.java | 3 +- .../user/service/SignService.java | 9 +- .../user/service/UserService.java | 5 +- nabimarket-domain/build.gradle | 21 ++ .../org/prgrms/nabimarketbe/BaseEntity.java | 40 +++ .../prgrms/nabimarketbe/card/entity/Card.java | 172 +++++++++++ .../nabimarketbe/card/entity/CardStatus.java | 7 + .../nabimarketbe/card/entity/TradeType.java | 6 + .../projection/CardCondenseResponseDTO.java | 22 ++ .../projection/CardFamousResponseDTO.java | 16 ++ .../card/projection/CardInfoResponseDTO.java | 18 ++ .../projection/CardListReadResponseDTO.java | 29 ++ .../card/projection/CardListResponseDTO.java | 8 + .../projection/CardPagingResponseDTO.java | 9 + .../projection/CardSuggestionResponseDTO.java | 14 + .../projection/CardSummaryResponseDTO.java | 16 ++ .../CardUserSummaryResponseDTO.java | 9 + .../card/repository/CardRepository.java | 28 ++ .../card/repository/CardRepositoryCustom.java | 37 +++ .../card/repository/CardRepositoryImpl.java | 267 ++++++++++++++++++ .../cardImage/entity/CardImage.java | 58 ++++ .../repository/CardImageBatchRepository.java | 36 +++ .../repository/CardImageRepository.java | 13 + .../category/entity/Category.java | 32 +++ .../category/entity/CategoryEnum.java | 13 + .../repository/CategoryRepository.java | 11 + .../chatroom/entity/ChatRoom.java | 45 +++ .../projection/list/CardInfoListDTO.java | 16 ++ .../projection/list/ChatRoomInfoListDTO.java | 16 ++ .../projection/list/ChatRoomListWrapper.java | 14 + .../projection/list/FromCardInfoListDTO.java | 10 + .../projection/list/ToCardInfoListDTO.java | 10 + .../projection/list/UserInfoListDTO.java | 8 + .../projection/single/CardInfoDTO.java | 12 + .../projection/single/ChatRoomInfoDTO.java | 24 ++ .../single/ChatRoomInfoWrapper.java | 8 + .../projection/single/FromCardInfoDTO.java | 10 + .../projection/single/ToCardInfoDTO.java | 10 + .../projection/single/UserInfoDTO.java | 8 + .../repository/ChatRoomRepository.java | 9 + .../repository/ChatRoomRepositoryCustom.java | 10 + .../repository/ChatRoomRepositoryImpl.java | 195 +++++++++++++ .../entity/CompleteRequest.java | 98 +++++++ .../entity/CompleteRequestStatus.java | 8 + .../HistoryListReadResponseDTO.java | 20 ++ .../repository/CompleteRequestRepository.java | 50 ++++ .../CompleteRequestRepositoryImpl.java | 169 +++++++++++ .../CompleteRequestRepositryCustom.java | 11 + .../wrapper/CompleteRequestInfoDTO.java | 4 + .../wrapper/CompleteRequestSummaryDTO.java | 14 + .../HistoryListReadLimitResponseDTO.java | 10 + .../HistoryListReadPagingResponseDTO.java | 11 + .../nabimarketbe/config/QuerydslConfig.java | 20 ++ .../prgrms/nabimarketbe/dibs/entity/Dib.java | 52 ++++ .../projection/DibListReadResponseDTO.java | 29 ++ .../dibs/repository/DibRepository.java | 14 + .../dibs/repository/DibRepositoryCustom.java | 11 + .../dibs/repository/DibRepositoryImpl.java | 80 ++++++ .../wrapper/DibListReadPagingResponseDTO.java | 17 ++ .../prgrms/nabimarketbe/item/entity/Item.java | 74 +++++ .../nabimarketbe/item/entity/PriceRange.java | 33 +++ .../item/repository/ItemRepository.java | 7 + .../notification/entity/Notification.java | 59 ++++ .../NotificationDetailResponseDTO.java | 20 ++ .../repository/NotificationRepository.java | 19 ++ .../NotificationRepositoryCustom.java | 15 + .../NotificationRepositoryImpl.java | 105 +++++++ .../NotificationPagingResponseDTO.java | 11 + .../security/entity/RefreshToken.java | 43 +++ .../repository/RefreshTokenRepository.java | 10 + .../suggestion/entity/DirectionType.java | 6 + .../suggestion/entity/Suggestion.java | 112 ++++++++ .../suggestion/entity/SuggestionStatus.java | 7 + .../suggestion/entity/SuggestionType.java | 33 +++ .../SuggestionDetailResponseDTO.java | 19 ++ .../suggestion/projection/SuggestionInfo.java | 17 ++ .../SuggestionListReadPagingResponseDTO.java | 9 + .../SuggestionListReadResponseDTO.java | 12 + .../repository/SuggestionRepository.java | 27 ++ .../SuggestionRepositoryCustom.java | 16 ++ .../repository/SuggestionRepositoryImpl.java | 168 +++++++++++ .../prgrms/nabimarketbe/user/entity/Role.java | 14 + .../prgrms/nabimarketbe/user/entity/User.java | 118 ++++++++ .../user/projection/UserIdResponseDTO.java | 4 + .../user/repository/UserRepository.java | 18 ++ .../nabimarketbe/util/CursorPaging.java | 12 + .../nabimarketbe/util/OrderCondition.java | 5 + .../nabimarketbe/util/QueryDslUtil.java | 54 ++++ nabimarket-infra/build.gradle | 22 -- .../nabimarketbe/util/KeyGenerator.java | 33 +++ 123 files changed, 3149 insertions(+), 174 deletions(-) create mode 100644 nabimarket-domain/src/main/java/org/prgrms/nabimarketbe/BaseEntity.java create mode 100644 nabimarket-domain/src/main/java/org/prgrms/nabimarketbe/card/entity/Card.java create mode 100644 nabimarket-domain/src/main/java/org/prgrms/nabimarketbe/card/entity/CardStatus.java create mode 100644 nabimarket-domain/src/main/java/org/prgrms/nabimarketbe/card/entity/TradeType.java create mode 100644 nabimarket-domain/src/main/java/org/prgrms/nabimarketbe/card/projection/CardCondenseResponseDTO.java create mode 100644 nabimarket-domain/src/main/java/org/prgrms/nabimarketbe/card/projection/CardFamousResponseDTO.java create mode 100644 nabimarket-domain/src/main/java/org/prgrms/nabimarketbe/card/projection/CardInfoResponseDTO.java create mode 100644 nabimarket-domain/src/main/java/org/prgrms/nabimarketbe/card/projection/CardListReadResponseDTO.java create mode 100644 nabimarket-domain/src/main/java/org/prgrms/nabimarketbe/card/projection/CardListResponseDTO.java create mode 100644 nabimarket-domain/src/main/java/org/prgrms/nabimarketbe/card/projection/CardPagingResponseDTO.java create mode 100644 nabimarket-domain/src/main/java/org/prgrms/nabimarketbe/card/projection/CardSuggestionResponseDTO.java create mode 100644 nabimarket-domain/src/main/java/org/prgrms/nabimarketbe/card/projection/CardSummaryResponseDTO.java create mode 100644 nabimarket-domain/src/main/java/org/prgrms/nabimarketbe/card/projection/CardUserSummaryResponseDTO.java create mode 100644 nabimarket-domain/src/main/java/org/prgrms/nabimarketbe/card/repository/CardRepository.java create mode 100644 nabimarket-domain/src/main/java/org/prgrms/nabimarketbe/card/repository/CardRepositoryCustom.java create mode 100644 nabimarket-domain/src/main/java/org/prgrms/nabimarketbe/card/repository/CardRepositoryImpl.java create mode 100644 nabimarket-domain/src/main/java/org/prgrms/nabimarketbe/cardImage/entity/CardImage.java create mode 100644 nabimarket-domain/src/main/java/org/prgrms/nabimarketbe/cardImage/repository/CardImageBatchRepository.java create mode 100644 nabimarket-domain/src/main/java/org/prgrms/nabimarketbe/cardImage/repository/CardImageRepository.java create mode 100644 nabimarket-domain/src/main/java/org/prgrms/nabimarketbe/category/entity/Category.java create mode 100644 nabimarket-domain/src/main/java/org/prgrms/nabimarketbe/category/entity/CategoryEnum.java create mode 100644 nabimarket-domain/src/main/java/org/prgrms/nabimarketbe/category/repository/CategoryRepository.java create mode 100644 nabimarket-domain/src/main/java/org/prgrms/nabimarketbe/chatroom/entity/ChatRoom.java create mode 100644 nabimarket-domain/src/main/java/org/prgrms/nabimarketbe/chatroom/projection/list/CardInfoListDTO.java create mode 100644 nabimarket-domain/src/main/java/org/prgrms/nabimarketbe/chatroom/projection/list/ChatRoomInfoListDTO.java create mode 100644 nabimarket-domain/src/main/java/org/prgrms/nabimarketbe/chatroom/projection/list/ChatRoomListWrapper.java create mode 100644 nabimarket-domain/src/main/java/org/prgrms/nabimarketbe/chatroom/projection/list/FromCardInfoListDTO.java create mode 100644 nabimarket-domain/src/main/java/org/prgrms/nabimarketbe/chatroom/projection/list/ToCardInfoListDTO.java create mode 100644 nabimarket-domain/src/main/java/org/prgrms/nabimarketbe/chatroom/projection/list/UserInfoListDTO.java create mode 100644 nabimarket-domain/src/main/java/org/prgrms/nabimarketbe/chatroom/projection/single/CardInfoDTO.java create mode 100644 nabimarket-domain/src/main/java/org/prgrms/nabimarketbe/chatroom/projection/single/ChatRoomInfoDTO.java create mode 100644 nabimarket-domain/src/main/java/org/prgrms/nabimarketbe/chatroom/projection/single/ChatRoomInfoWrapper.java create mode 100644 nabimarket-domain/src/main/java/org/prgrms/nabimarketbe/chatroom/projection/single/FromCardInfoDTO.java create mode 100644 nabimarket-domain/src/main/java/org/prgrms/nabimarketbe/chatroom/projection/single/ToCardInfoDTO.java create mode 100644 nabimarket-domain/src/main/java/org/prgrms/nabimarketbe/chatroom/projection/single/UserInfoDTO.java create mode 100644 nabimarket-domain/src/main/java/org/prgrms/nabimarketbe/chatroom/repository/ChatRoomRepository.java create mode 100644 nabimarket-domain/src/main/java/org/prgrms/nabimarketbe/chatroom/repository/ChatRoomRepositoryCustom.java create mode 100644 nabimarket-domain/src/main/java/org/prgrms/nabimarketbe/chatroom/repository/ChatRoomRepositoryImpl.java create mode 100644 nabimarket-domain/src/main/java/org/prgrms/nabimarketbe/completeRequest/entity/CompleteRequest.java create mode 100644 nabimarket-domain/src/main/java/org/prgrms/nabimarketbe/completeRequest/entity/CompleteRequestStatus.java create mode 100644 nabimarket-domain/src/main/java/org/prgrms/nabimarketbe/completeRequest/projection/HistoryListReadResponseDTO.java create mode 100644 nabimarket-domain/src/main/java/org/prgrms/nabimarketbe/completeRequest/repository/CompleteRequestRepository.java create mode 100644 nabimarket-domain/src/main/java/org/prgrms/nabimarketbe/completeRequest/repository/CompleteRequestRepositoryImpl.java create mode 100644 nabimarket-domain/src/main/java/org/prgrms/nabimarketbe/completeRequest/repository/CompleteRequestRepositryCustom.java create mode 100644 nabimarket-domain/src/main/java/org/prgrms/nabimarketbe/completeRequest/wrapper/CompleteRequestInfoDTO.java create mode 100644 nabimarket-domain/src/main/java/org/prgrms/nabimarketbe/completeRequest/wrapper/CompleteRequestSummaryDTO.java create mode 100644 nabimarket-domain/src/main/java/org/prgrms/nabimarketbe/completeRequest/wrapper/HistoryListReadLimitResponseDTO.java create mode 100644 nabimarket-domain/src/main/java/org/prgrms/nabimarketbe/completeRequest/wrapper/HistoryListReadPagingResponseDTO.java create mode 100644 nabimarket-domain/src/main/java/org/prgrms/nabimarketbe/config/QuerydslConfig.java create mode 100644 nabimarket-domain/src/main/java/org/prgrms/nabimarketbe/dibs/entity/Dib.java create mode 100644 nabimarket-domain/src/main/java/org/prgrms/nabimarketbe/dibs/projection/DibListReadResponseDTO.java create mode 100644 nabimarket-domain/src/main/java/org/prgrms/nabimarketbe/dibs/repository/DibRepository.java create mode 100644 nabimarket-domain/src/main/java/org/prgrms/nabimarketbe/dibs/repository/DibRepositoryCustom.java create mode 100644 nabimarket-domain/src/main/java/org/prgrms/nabimarketbe/dibs/repository/DibRepositoryImpl.java create mode 100644 nabimarket-domain/src/main/java/org/prgrms/nabimarketbe/dibs/wrapper/DibListReadPagingResponseDTO.java create mode 100644 nabimarket-domain/src/main/java/org/prgrms/nabimarketbe/item/entity/Item.java create mode 100644 nabimarket-domain/src/main/java/org/prgrms/nabimarketbe/item/entity/PriceRange.java create mode 100644 nabimarket-domain/src/main/java/org/prgrms/nabimarketbe/item/repository/ItemRepository.java create mode 100644 nabimarket-domain/src/main/java/org/prgrms/nabimarketbe/notification/entity/Notification.java create mode 100644 nabimarket-domain/src/main/java/org/prgrms/nabimarketbe/notification/projection/NotificationDetailResponseDTO.java create mode 100644 nabimarket-domain/src/main/java/org/prgrms/nabimarketbe/notification/repository/NotificationRepository.java create mode 100644 nabimarket-domain/src/main/java/org/prgrms/nabimarketbe/notification/repository/NotificationRepositoryCustom.java create mode 100644 nabimarket-domain/src/main/java/org/prgrms/nabimarketbe/notification/repository/NotificationRepositoryImpl.java create mode 100644 nabimarket-domain/src/main/java/org/prgrms/nabimarketbe/notification/wrapper/NotificationPagingResponseDTO.java create mode 100644 nabimarket-domain/src/main/java/org/prgrms/nabimarketbe/security/entity/RefreshToken.java create mode 100644 nabimarket-domain/src/main/java/org/prgrms/nabimarketbe/security/jwt/repository/RefreshTokenRepository.java create mode 100644 nabimarket-domain/src/main/java/org/prgrms/nabimarketbe/suggestion/entity/DirectionType.java create mode 100644 nabimarket-domain/src/main/java/org/prgrms/nabimarketbe/suggestion/entity/Suggestion.java create mode 100644 nabimarket-domain/src/main/java/org/prgrms/nabimarketbe/suggestion/entity/SuggestionStatus.java create mode 100644 nabimarket-domain/src/main/java/org/prgrms/nabimarketbe/suggestion/entity/SuggestionType.java create mode 100644 nabimarket-domain/src/main/java/org/prgrms/nabimarketbe/suggestion/projection/SuggestionDetailResponseDTO.java create mode 100644 nabimarket-domain/src/main/java/org/prgrms/nabimarketbe/suggestion/projection/SuggestionInfo.java create mode 100644 nabimarket-domain/src/main/java/org/prgrms/nabimarketbe/suggestion/projection/SuggestionListReadPagingResponseDTO.java create mode 100644 nabimarket-domain/src/main/java/org/prgrms/nabimarketbe/suggestion/projection/SuggestionListReadResponseDTO.java create mode 100644 nabimarket-domain/src/main/java/org/prgrms/nabimarketbe/suggestion/repository/SuggestionRepository.java create mode 100644 nabimarket-domain/src/main/java/org/prgrms/nabimarketbe/suggestion/repository/SuggestionRepositoryCustom.java create mode 100644 nabimarket-domain/src/main/java/org/prgrms/nabimarketbe/suggestion/repository/SuggestionRepositoryImpl.java create mode 100644 nabimarket-domain/src/main/java/org/prgrms/nabimarketbe/user/entity/Role.java create mode 100644 nabimarket-domain/src/main/java/org/prgrms/nabimarketbe/user/entity/User.java create mode 100644 nabimarket-domain/src/main/java/org/prgrms/nabimarketbe/user/projection/UserIdResponseDTO.java create mode 100644 nabimarket-domain/src/main/java/org/prgrms/nabimarketbe/user/repository/UserRepository.java create mode 100644 nabimarket-domain/src/main/java/org/prgrms/nabimarketbe/util/CursorPaging.java create mode 100644 nabimarket-domain/src/main/java/org/prgrms/nabimarketbe/util/OrderCondition.java create mode 100644 nabimarket-domain/src/main/java/org/prgrms/nabimarketbe/util/QueryDslUtil.java create mode 100644 nabimarket-infra/src/main/java/org/prgrms/nabimarketbe/util/KeyGenerator.java diff --git a/build.gradle b/build.gradle index ab54270a..d94eb85b 100644 --- a/build.gradle +++ b/build.gradle @@ -60,6 +60,7 @@ project(':nabimarket-api') { implementation project(':nabimarket-common') implementation project(':nabimarket-application') implementation project(':nabimarket-infra') + compileOnly project(':nabimarket-domain') // domain의 projection dto를 알기 위한 의존성 } } diff --git a/nabimarket-api/src/main/java/org/prgrms/nabimarketbe/card/CardController.java b/nabimarket-api/src/main/java/org/prgrms/nabimarketbe/card/CardController.java index 747419a4..e14c2486 100644 --- a/nabimarket-api/src/main/java/org/prgrms/nabimarketbe/card/CardController.java +++ b/nabimarket-api/src/main/java/org/prgrms/nabimarketbe/card/CardController.java @@ -9,18 +9,20 @@ import org.prgrms.nabimarketbe.card.dto.response.CardUpdateResponseDTO; import org.prgrms.nabimarketbe.card.dto.response.wrapper.CardResponseDTO; import org.prgrms.nabimarketbe.card.dto.response.wrapper.CardUserResponseDTO; -import org.prgrms.nabimarketbe.jpa.card.entity.CardStatus; -import org.prgrms.nabimarketbe.jpa.card.projection.CardFamousResponseDTO; -import org.prgrms.nabimarketbe.jpa.card.projection.CardListResponseDTO; -import org.prgrms.nabimarketbe.jpa.card.projection.CardPagingResponseDTO; -import org.prgrms.nabimarketbe.jpa.card.projection.CardSuggestionResponseDTO; +import org.prgrms.nabimarketbe.card.entity.CardStatus; +import org.prgrms.nabimarketbe.card.projection.CardFamousResponseDTO; +import org.prgrms.nabimarketbe.card.projection.CardListResponseDTO; +import org.prgrms.nabimarketbe.card.projection.CardPagingResponseDTO; +import org.prgrms.nabimarketbe.card.projection.CardSuggestionResponseDTO; +import org.prgrms.nabimarketbe.category.entity.CategoryEnum; +import org.prgrms.nabimarketbe.item.entity.PriceRange; + import org.prgrms.nabimarketbe.card.service.CardService; -import org.prgrms.nabimarketbe.jpa.category.entity.CategoryEnum; -import org.prgrms.nabimarketbe.jpa.item.entity.PriceRange; -import org.prgrms.nabimarketbe.jpa.util.OrderCondition; + import org.prgrms.nabimarketbe.model.CommonResult; import org.prgrms.nabimarketbe.model.ResponseFactory; import org.prgrms.nabimarketbe.model.SingleResult; +import org.prgrms.nabimarketbe.util.OrderCondition; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.DeleteMapping; import org.springframework.web.bind.annotation.GetMapping; diff --git a/nabimarket-api/src/main/java/org/prgrms/nabimarketbe/chatroom/ChatRoomController.java b/nabimarket-api/src/main/java/org/prgrms/nabimarketbe/chatroom/ChatRoomController.java index 539ecdf4..82544b89 100644 --- a/nabimarket-api/src/main/java/org/prgrms/nabimarketbe/chatroom/ChatRoomController.java +++ b/nabimarket-api/src/main/java/org/prgrms/nabimarketbe/chatroom/ChatRoomController.java @@ -1,7 +1,8 @@ package org.prgrms.nabimarketbe.chatroom; -import org.prgrms.nabimarketbe.jpa.chatroom.projection.list.ChatRoomListWrapper; -import org.prgrms.nabimarketbe.jpa.chatroom.projection.single.ChatRoomInfoWrapper; + +import org.prgrms.nabimarketbe.chatroom.projection.list.ChatRoomListWrapper; +import org.prgrms.nabimarketbe.chatroom.projection.single.ChatRoomInfoWrapper; import org.prgrms.nabimarketbe.chatroom.service.ChatRoomService; import org.prgrms.nabimarketbe.model.ResponseFactory; import org.prgrms.nabimarketbe.model.SingleResult; diff --git a/nabimarket-api/src/main/java/org/prgrms/nabimarketbe/completeRequest/CompleteRequestController.java b/nabimarket-api/src/main/java/org/prgrms/nabimarketbe/completeRequest/CompleteRequestController.java index 29c81b6f..a6454aa8 100644 --- a/nabimarket-api/src/main/java/org/prgrms/nabimarketbe/completeRequest/CompleteRequestController.java +++ b/nabimarket-api/src/main/java/org/prgrms/nabimarketbe/completeRequest/CompleteRequestController.java @@ -4,9 +4,10 @@ import org.prgrms.nabimarketbe.completeRequest.dto.request.CompleteRequestUpdateDTO; import org.prgrms.nabimarketbe.completeRequest.dto.response.CompleteRequestResponseDTO; import org.prgrms.nabimarketbe.completeRequest.service.CompleteRequestService; -import org.prgrms.nabimarketbe.jpa.completerequest.wrapper.CompleteRequestInfoDTO; -import org.prgrms.nabimarketbe.jpa.completerequest.wrapper.HistoryListReadLimitResponseDTO; -import org.prgrms.nabimarketbe.jpa.completerequest.wrapper.HistoryListReadPagingResponseDTO; + +import org.prgrms.nabimarketbe.completeRequest.wrapper.CompleteRequestInfoDTO; +import org.prgrms.nabimarketbe.completeRequest.wrapper.HistoryListReadLimitResponseDTO; +import org.prgrms.nabimarketbe.completeRequest.wrapper.HistoryListReadPagingResponseDTO; import org.prgrms.nabimarketbe.model.ResponseFactory; import org.prgrms.nabimarketbe.model.SingleResult; import org.springframework.http.ResponseEntity; diff --git a/nabimarket-api/src/main/java/org/prgrms/nabimarketbe/dibs/DibController.java b/nabimarket-api/src/main/java/org/prgrms/nabimarketbe/dibs/DibController.java index 596f691a..b9afbc0e 100644 --- a/nabimarket-api/src/main/java/org/prgrms/nabimarketbe/dibs/DibController.java +++ b/nabimarket-api/src/main/java/org/prgrms/nabimarketbe/dibs/DibController.java @@ -2,8 +2,8 @@ import org.prgrms.nabimarketbe.dibs.dto.response.DibCreateResponseDTO; import org.prgrms.nabimarketbe.dibs.service.DibService; -import org.prgrms.nabimarketbe.jpa.dibs.projection.DibListReadPagingResponseDTO; import org.prgrms.nabimarketbe.dibs.dto.wrapper.DibResponseDTO; +import org.prgrms.nabimarketbe.dibs.wrapper.DibListReadPagingResponseDTO; import org.prgrms.nabimarketbe.model.CommonResult; import org.prgrms.nabimarketbe.model.ResponseFactory; import org.prgrms.nabimarketbe.model.SingleResult; diff --git a/nabimarket-api/src/main/java/org/prgrms/nabimarketbe/notification/NotificationController.java b/nabimarket-api/src/main/java/org/prgrms/nabimarketbe/notification/NotificationController.java index 73ab8322..524cfd25 100644 --- a/nabimarket-api/src/main/java/org/prgrms/nabimarketbe/notification/NotificationController.java +++ b/nabimarket-api/src/main/java/org/prgrms/nabimarketbe/notification/NotificationController.java @@ -8,7 +8,7 @@ import org.prgrms.nabimarketbe.notification.dto.request.NotificationReadRequestDTO; import org.prgrms.nabimarketbe.notification.dto.response.NotificationUnreadCountResponseDTO; import org.prgrms.nabimarketbe.notification.service.NotificationService; -import org.prgrms.nabimarketbe.jpa.notification.projection.NotificationPagingResponseDTO; +import org.prgrms.nabimarketbe.notification.wrapper.NotificationPagingResponseDTO; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PutMapping; diff --git a/nabimarket-api/src/main/java/org/prgrms/nabimarketbe/suggestion/SuggestionController.java b/nabimarket-api/src/main/java/org/prgrms/nabimarketbe/suggestion/SuggestionController.java index de01f66e..f6d532da 100644 --- a/nabimarket-api/src/main/java/org/prgrms/nabimarketbe/suggestion/SuggestionController.java +++ b/nabimarket-api/src/main/java/org/prgrms/nabimarketbe/suggestion/SuggestionController.java @@ -5,11 +5,12 @@ import org.prgrms.nabimarketbe.suggestion.dto.request.SuggestionRequestDTO; import org.prgrms.nabimarketbe.suggestion.dto.request.SuggestionUpdateRequestDTO; import org.prgrms.nabimarketbe.suggestion.dto.response.SuggestionResponseDTO; -import org.prgrms.nabimarketbe.jpa.suggestion.entity.DirectionType; -import org.prgrms.nabimarketbe.jpa.suggestion.entity.SuggestionType; -import org.prgrms.nabimarketbe.jpa.suggestion.projection.SuggestionListReadPagingResponseDTO; + +import org.prgrms.nabimarketbe.suggestion.entity.DirectionType; +import org.prgrms.nabimarketbe.suggestion.entity.SuggestionType; +import org.prgrms.nabimarketbe.suggestion.projection.SuggestionListReadPagingResponseDTO; import org.prgrms.nabimarketbe.suggestion.service.SuggestionService; -import org.prgrms.nabimarketbe.jpa.util.KeyGenerator; +import org.prgrms.nabimarketbe.util.KeyGenerator; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PathVariable; diff --git a/nabimarket-application/src/main/java/org/prgrms/nabimarketbe/card/dto/request/CardCreateRequestDTO.java b/nabimarket-application/src/main/java/org/prgrms/nabimarketbe/card/dto/request/CardCreateRequestDTO.java index f7d34eae..fb18bbbc 100644 --- a/nabimarket-application/src/main/java/org/prgrms/nabimarketbe/card/dto/request/CardCreateRequestDTO.java +++ b/nabimarket-application/src/main/java/org/prgrms/nabimarketbe/card/dto/request/CardCreateRequestDTO.java @@ -8,14 +8,14 @@ import javax.validation.constraints.Size; import org.prgrms.nabimarketbe.annotation.ValidEnum; +import org.prgrms.nabimarketbe.card.entity.Card; +import org.prgrms.nabimarketbe.card.entity.TradeType; import org.prgrms.nabimarketbe.cardimage.dto.request.CardImageCreateRequestDTO; -import org.prgrms.nabimarketbe.jpa.card.entity.Card; -import org.prgrms.nabimarketbe.jpa.card.entity.TradeType; -import org.prgrms.nabimarketbe.jpa.category.entity.Category; -import org.prgrms.nabimarketbe.jpa.category.entity.CategoryEnum; -import org.prgrms.nabimarketbe.jpa.item.entity.Item; -import org.prgrms.nabimarketbe.jpa.item.entity.PriceRange; -import org.prgrms.nabimarketbe.jpa.user.entity.User; +import org.prgrms.nabimarketbe.category.entity.Category; +import org.prgrms.nabimarketbe.category.entity.CategoryEnum; +import org.prgrms.nabimarketbe.item.entity.Item; +import org.prgrms.nabimarketbe.item.entity.PriceRange; +import org.prgrms.nabimarketbe.user.entity.User; import io.swagger.v3.oas.annotations.media.Schema; diff --git a/nabimarket-application/src/main/java/org/prgrms/nabimarketbe/card/dto/request/CardStatusUpdateRequestDTO.java b/nabimarket-application/src/main/java/org/prgrms/nabimarketbe/card/dto/request/CardStatusUpdateRequestDTO.java index 0596174c..38fa1345 100644 --- a/nabimarket-application/src/main/java/org/prgrms/nabimarketbe/card/dto/request/CardStatusUpdateRequestDTO.java +++ b/nabimarket-application/src/main/java/org/prgrms/nabimarketbe/card/dto/request/CardStatusUpdateRequestDTO.java @@ -1,7 +1,7 @@ package org.prgrms.nabimarketbe.card.dto.request; import org.prgrms.nabimarketbe.annotation.ValidEnum; -import org.prgrms.nabimarketbe.jpa.card.entity.CardStatus; +import org.prgrms.nabimarketbe.card.entity.CardStatus; public record CardStatusUpdateRequestDTO( @ValidEnum(enumClass = CardStatus.class, message = "유효하지 않은 상태입니다.") diff --git a/nabimarket-application/src/main/java/org/prgrms/nabimarketbe/card/dto/request/CardUpdateRequestDTO.java b/nabimarket-application/src/main/java/org/prgrms/nabimarketbe/card/dto/request/CardUpdateRequestDTO.java index 026791d8..3ef4228c 100644 --- a/nabimarket-application/src/main/java/org/prgrms/nabimarketbe/card/dto/request/CardUpdateRequestDTO.java +++ b/nabimarket-application/src/main/java/org/prgrms/nabimarketbe/card/dto/request/CardUpdateRequestDTO.java @@ -7,14 +7,14 @@ import javax.validation.constraints.Size; import org.prgrms.nabimarketbe.annotation.ValidEnum; +import org.prgrms.nabimarketbe.card.entity.Card; +import org.prgrms.nabimarketbe.card.entity.TradeType; import org.prgrms.nabimarketbe.cardimage.dto.request.CardImageCreateRequestDTO; -import org.prgrms.nabimarketbe.jpa.card.entity.Card; -import org.prgrms.nabimarketbe.jpa.card.entity.TradeType; -import org.prgrms.nabimarketbe.jpa.category.entity.Category; -import org.prgrms.nabimarketbe.jpa.category.entity.CategoryEnum; -import org.prgrms.nabimarketbe.jpa.item.entity.Item; -import org.prgrms.nabimarketbe.jpa.item.entity.PriceRange; -import org.prgrms.nabimarketbe.jpa.user.entity.User; +import org.prgrms.nabimarketbe.category.entity.Category; +import org.prgrms.nabimarketbe.category.entity.CategoryEnum; +import org.prgrms.nabimarketbe.item.entity.Item; +import org.prgrms.nabimarketbe.item.entity.PriceRange; +import org.prgrms.nabimarketbe.user.entity.User; public record CardUpdateRequestDTO( @NotBlank(message = "공백을 허용하지 않습니다.") diff --git a/nabimarket-application/src/main/java/org/prgrms/nabimarketbe/card/dto/response/CardCreateResponseDTO.java b/nabimarket-application/src/main/java/org/prgrms/nabimarketbe/card/dto/response/CardCreateResponseDTO.java index 5c9a9a3e..d076e0e1 100644 --- a/nabimarket-application/src/main/java/org/prgrms/nabimarketbe/card/dto/response/CardCreateResponseDTO.java +++ b/nabimarket-application/src/main/java/org/prgrms/nabimarketbe/card/dto/response/CardCreateResponseDTO.java @@ -3,13 +3,13 @@ import java.time.LocalDateTime; import java.util.List; +import org.prgrms.nabimarketbe.card.entity.Card; +import org.prgrms.nabimarketbe.card.entity.TradeType; +import org.prgrms.nabimarketbe.cardImage.entity.CardImage; import org.prgrms.nabimarketbe.cardimage.dto.response.CardImageCreateResponseDTO; -import org.prgrms.nabimarketbe.jpa.card.entity.Card; -import org.prgrms.nabimarketbe.jpa.card.entity.TradeType; -import org.prgrms.nabimarketbe.jpa.cardImage.entity.CardImage; -import org.prgrms.nabimarketbe.jpa.category.entity.CategoryEnum; -import org.prgrms.nabimarketbe.jpa.item.entity.Item; -import org.prgrms.nabimarketbe.jpa.item.entity.PriceRange; +import org.prgrms.nabimarketbe.category.entity.CategoryEnum; +import org.prgrms.nabimarketbe.item.entity.Item; +import org.prgrms.nabimarketbe.item.entity.PriceRange; import lombok.Builder; diff --git a/nabimarket-application/src/main/java/org/prgrms/nabimarketbe/card/dto/response/CardDetailResponseDTO.java b/nabimarket-application/src/main/java/org/prgrms/nabimarketbe/card/dto/response/CardDetailResponseDTO.java index dad32b56..b81ec643 100644 --- a/nabimarket-application/src/main/java/org/prgrms/nabimarketbe/card/dto/response/CardDetailResponseDTO.java +++ b/nabimarket-application/src/main/java/org/prgrms/nabimarketbe/card/dto/response/CardDetailResponseDTO.java @@ -3,14 +3,13 @@ import java.time.LocalDateTime; import java.util.List; +import org.prgrms.nabimarketbe.card.entity.Card; +import org.prgrms.nabimarketbe.card.entity.CardStatus; +import org.prgrms.nabimarketbe.card.entity.TradeType; +import org.prgrms.nabimarketbe.cardImage.entity.CardImage; import org.prgrms.nabimarketbe.cardimage.dto.response.CardImageSingleReadResponseDTO; -import org.prgrms.nabimarketbe.jpa.card.entity.Card; -import org.prgrms.nabimarketbe.jpa.card.entity.CardStatus; -import org.prgrms.nabimarketbe.jpa.card.entity.TradeType; -import org.prgrms.nabimarketbe.jpa.cardImage.entity.CardImage; -import org.prgrms.nabimarketbe.jpa.category.entity.CategoryEnum; -import org.prgrms.nabimarketbe.jpa.item.entity.PriceRange; - +import org.prgrms.nabimarketbe.category.entity.CategoryEnum; +import org.prgrms.nabimarketbe.item.entity.PriceRange; import lombok.Builder; @Builder diff --git a/nabimarket-application/src/main/java/org/prgrms/nabimarketbe/card/dto/response/CardUpdateResponseDTO.java b/nabimarket-application/src/main/java/org/prgrms/nabimarketbe/card/dto/response/CardUpdateResponseDTO.java index 51802911..2dd0a733 100644 --- a/nabimarket-application/src/main/java/org/prgrms/nabimarketbe/card/dto/response/CardUpdateResponseDTO.java +++ b/nabimarket-application/src/main/java/org/prgrms/nabimarketbe/card/dto/response/CardUpdateResponseDTO.java @@ -3,13 +3,13 @@ import java.time.LocalDateTime; import java.util.List; +import org.prgrms.nabimarketbe.card.entity.Card; +import org.prgrms.nabimarketbe.card.entity.TradeType; +import org.prgrms.nabimarketbe.cardImage.entity.CardImage; import org.prgrms.nabimarketbe.cardimage.dto.response.CardImageUpdateResponseDTO; -import org.prgrms.nabimarketbe.jpa.card.entity.Card; -import org.prgrms.nabimarketbe.jpa.card.entity.TradeType; -import org.prgrms.nabimarketbe.jpa.cardImage.entity.CardImage; -import org.prgrms.nabimarketbe.jpa.category.entity.CategoryEnum; -import org.prgrms.nabimarketbe.jpa.item.entity.Item; -import org.prgrms.nabimarketbe.jpa.item.entity.PriceRange; +import org.prgrms.nabimarketbe.category.entity.CategoryEnum; +import org.prgrms.nabimarketbe.item.entity.Item; +import org.prgrms.nabimarketbe.item.entity.PriceRange; import lombok.Builder; diff --git a/nabimarket-application/src/main/java/org/prgrms/nabimarketbe/card/service/CardService.java b/nabimarket-application/src/main/java/org/prgrms/nabimarketbe/card/service/CardService.java index 1badf037..5aa53a9e 100644 --- a/nabimarket-application/src/main/java/org/prgrms/nabimarketbe/card/service/CardService.java +++ b/nabimarket-application/src/main/java/org/prgrms/nabimarketbe/card/service/CardService.java @@ -11,32 +11,32 @@ import org.prgrms.nabimarketbe.card.dto.response.CardUpdateResponseDTO; import org.prgrms.nabimarketbe.card.dto.response.wrapper.CardResponseDTO; import org.prgrms.nabimarketbe.card.dto.response.wrapper.CardUserResponseDTO; +import org.prgrms.nabimarketbe.card.entity.Card; +import org.prgrms.nabimarketbe.card.entity.CardStatus; +import org.prgrms.nabimarketbe.card.projection.CardFamousResponseDTO; +import org.prgrms.nabimarketbe.card.projection.CardListResponseDTO; +import org.prgrms.nabimarketbe.card.projection.CardPagingResponseDTO; +import org.prgrms.nabimarketbe.card.projection.CardSuggestionResponseDTO; +import org.prgrms.nabimarketbe.card.repository.CardRepository; +import org.prgrms.nabimarketbe.cardImage.entity.CardImage; +import org.prgrms.nabimarketbe.cardImage.repository.CardImageBatchRepository; +import org.prgrms.nabimarketbe.cardImage.repository.CardImageRepository; +import org.prgrms.nabimarketbe.category.entity.Category; +import org.prgrms.nabimarketbe.category.entity.CategoryEnum; +import org.prgrms.nabimarketbe.category.repository.CategoryRepository; +import org.prgrms.nabimarketbe.dibs.repository.DibRepository; import org.prgrms.nabimarketbe.error.BaseException; import org.prgrms.nabimarketbe.error.ErrorCode; -import org.prgrms.nabimarketbe.jpa.card.entity.Card; -import org.prgrms.nabimarketbe.jpa.card.entity.CardStatus; -import org.prgrms.nabimarketbe.jpa.card.projection.CardFamousResponseDTO; -import org.prgrms.nabimarketbe.jpa.card.projection.CardListResponseDTO; -import org.prgrms.nabimarketbe.jpa.card.projection.CardPagingResponseDTO; -import org.prgrms.nabimarketbe.jpa.card.projection.CardSuggestionResponseDTO; -import org.prgrms.nabimarketbe.jpa.card.repository.CardRepository; -import org.prgrms.nabimarketbe.jpa.cardImage.entity.CardImage; -import org.prgrms.nabimarketbe.jpa.cardImage.repository.CardImageBatchRepository; -import org.prgrms.nabimarketbe.jpa.cardImage.repository.CardImageRepository; -import org.prgrms.nabimarketbe.jpa.category.entity.Category; -import org.prgrms.nabimarketbe.jpa.category.entity.CategoryEnum; -import org.prgrms.nabimarketbe.jpa.category.repository.CategoryRepository; -import org.prgrms.nabimarketbe.jpa.dibs.repository.DibRepository; -import org.prgrms.nabimarketbe.jpa.item.entity.Item; -import org.prgrms.nabimarketbe.jpa.item.entity.PriceRange; -import org.prgrms.nabimarketbe.jpa.item.repository.ItemRepository; -import org.prgrms.nabimarketbe.jpa.suggestion.entity.SuggestionType; -import org.prgrms.nabimarketbe.jpa.suggestion.repository.SuggestionRepository; -import org.prgrms.nabimarketbe.jpa.user.entity.User; -import org.prgrms.nabimarketbe.jpa.user.repository.UserRepository; -import org.prgrms.nabimarketbe.jpa.util.OrderCondition; +import org.prgrms.nabimarketbe.item.entity.Item; +import org.prgrms.nabimarketbe.item.entity.PriceRange; +import org.prgrms.nabimarketbe.item.repository.ItemRepository; +import org.prgrms.nabimarketbe.suggestion.entity.SuggestionType; +import org.prgrms.nabimarketbe.suggestion.repository.SuggestionRepository; import org.prgrms.nabimarketbe.user.dto.response.UserSummaryResponseDTO; +import org.prgrms.nabimarketbe.user.entity.User; +import org.prgrms.nabimarketbe.user.repository.UserRepository; import org.prgrms.nabimarketbe.user.service.CheckService; +import org.prgrms.nabimarketbe.util.OrderCondition; import org.springframework.data.domain.PageRequest; import org.springframework.data.domain.Sort; import org.springframework.stereotype.Service; diff --git a/nabimarket-application/src/main/java/org/prgrms/nabimarketbe/card/service/CardViewCountService.java b/nabimarket-application/src/main/java/org/prgrms/nabimarketbe/card/service/CardViewCountService.java index a3d81368..5565d637 100644 --- a/nabimarket-application/src/main/java/org/prgrms/nabimarketbe/card/service/CardViewCountService.java +++ b/nabimarket-application/src/main/java/org/prgrms/nabimarketbe/card/service/CardViewCountService.java @@ -3,9 +3,9 @@ import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; -import org.prgrms.nabimarketbe.jpa.card.repository.CardRepository; +import org.prgrms.nabimarketbe.card.repository.CardRepository; import org.prgrms.nabimarketbe.redisson.RedisDAO; -import org.prgrms.nabimarketbe.jpa.util.KeyGenerator; +import org.prgrms.nabimarketbe.util.KeyGenerator; import org.springframework.scheduling.annotation.Async; import org.springframework.scheduling.annotation.Scheduled; import org.springframework.stereotype.Service; diff --git a/nabimarket-application/src/main/java/org/prgrms/nabimarketbe/cardimage/dto/request/CardImageCreateRequestDTO.java b/nabimarket-application/src/main/java/org/prgrms/nabimarketbe/cardimage/dto/request/CardImageCreateRequestDTO.java index d4613fff..fa1c0792 100644 --- a/nabimarket-application/src/main/java/org/prgrms/nabimarketbe/cardimage/dto/request/CardImageCreateRequestDTO.java +++ b/nabimarket-application/src/main/java/org/prgrms/nabimarketbe/cardimage/dto/request/CardImageCreateRequestDTO.java @@ -2,9 +2,8 @@ import javax.validation.constraints.NotBlank; -import org.prgrms.nabimarketbe.jpa.card.entity.Card; -import org.prgrms.nabimarketbe.jpa.cardImage.entity.CardImage; - +import org.prgrms.nabimarketbe.card.entity.Card; +import org.prgrms.nabimarketbe.cardImage.entity.CardImage; public record CardImageCreateRequestDTO( @NotBlank String url diff --git a/nabimarket-application/src/main/java/org/prgrms/nabimarketbe/chatroom/service/ChatRoomService.java b/nabimarket-application/src/main/java/org/prgrms/nabimarketbe/chatroom/service/ChatRoomService.java index 76921850..36d21482 100644 --- a/nabimarket-application/src/main/java/org/prgrms/nabimarketbe/chatroom/service/ChatRoomService.java +++ b/nabimarket-application/src/main/java/org/prgrms/nabimarketbe/chatroom/service/ChatRoomService.java @@ -3,15 +3,16 @@ import java.util.HashMap; import java.util.Map; +import org.prgrms.nabimarketbe.card.entity.Card; +import org.prgrms.nabimarketbe.chatroom.entity.ChatRoom; +import org.prgrms.nabimarketbe.chatroom.projection.list.ChatRoomListWrapper; +import org.prgrms.nabimarketbe.chatroom.projection.single.ChatRoomInfoWrapper; +import org.prgrms.nabimarketbe.chatroom.repository.ChatRoomRepository; +import org.prgrms.nabimarketbe.completeRequest.repository.CompleteRequestRepository; import org.prgrms.nabimarketbe.error.BaseException; import org.prgrms.nabimarketbe.error.ErrorCode; -import org.prgrms.nabimarketbe.jpa.card.entity.Card; -import org.prgrms.nabimarketbe.jpa.chatroom.entity.ChatRoom; -import org.prgrms.nabimarketbe.jpa.chatroom.projection.list.ChatRoomListWrapper; -import org.prgrms.nabimarketbe.jpa.chatroom.projection.single.ChatRoomInfoWrapper; -import org.prgrms.nabimarketbe.jpa.chatroom.repository.ChatRoomRepository; -import org.prgrms.nabimarketbe.jpa.completerequest.repository.CompleteRequestRepository; -import org.prgrms.nabimarketbe.jpa.suggestion.entity.Suggestion; + +import org.prgrms.nabimarketbe.suggestion.entity.Suggestion; import org.prgrms.nabimarketbe.user.service.CheckService; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; diff --git a/nabimarket-application/src/main/java/org/prgrms/nabimarketbe/completeRequest/dto/response/CompleteRequestResponseDTO.java b/nabimarket-application/src/main/java/org/prgrms/nabimarketbe/completeRequest/dto/response/CompleteRequestResponseDTO.java index 98fa835d..4c5d4d5e 100644 --- a/nabimarket-application/src/main/java/org/prgrms/nabimarketbe/completeRequest/dto/response/CompleteRequestResponseDTO.java +++ b/nabimarket-application/src/main/java/org/prgrms/nabimarketbe/completeRequest/dto/response/CompleteRequestResponseDTO.java @@ -2,8 +2,8 @@ import java.time.LocalDateTime; -import org.prgrms.nabimarketbe.jpa.completerequest.entity.CompleteRequest; -import org.prgrms.nabimarketbe.jpa.completerequest.entity.CompleteRequestStatus; +import org.prgrms.nabimarketbe.completeRequest.entity.CompleteRequest; +import org.prgrms.nabimarketbe.completeRequest.entity.CompleteRequestStatus; import lombok.Builder; diff --git a/nabimarket-application/src/main/java/org/prgrms/nabimarketbe/completeRequest/service/CompleteRequestService.java b/nabimarket-application/src/main/java/org/prgrms/nabimarketbe/completeRequest/service/CompleteRequestService.java index 048a8d10..6ec68043 100644 --- a/nabimarket-application/src/main/java/org/prgrms/nabimarketbe/completeRequest/service/CompleteRequestService.java +++ b/nabimarket-application/src/main/java/org/prgrms/nabimarketbe/completeRequest/service/CompleteRequestService.java @@ -1,26 +1,27 @@ package org.prgrms.nabimarketbe.completeRequest.service; +import org.prgrms.nabimarketbe.card.entity.Card; +import org.prgrms.nabimarketbe.card.entity.CardStatus; +import org.prgrms.nabimarketbe.card.projection.CardCondenseResponseDTO; +import org.prgrms.nabimarketbe.card.projection.CardUserSummaryResponseDTO; +import org.prgrms.nabimarketbe.card.repository.CardRepository; import org.prgrms.nabimarketbe.completeRequest.dto.request.CompleteRequestDTO; import org.prgrms.nabimarketbe.completeRequest.dto.response.CompleteRequestResponseDTO; +import org.prgrms.nabimarketbe.completeRequest.entity.CompleteRequest; +import org.prgrms.nabimarketbe.completeRequest.repository.CompleteRequestRepository; +import org.prgrms.nabimarketbe.completeRequest.wrapper.CompleteRequestInfoDTO; +import org.prgrms.nabimarketbe.completeRequest.wrapper.CompleteRequestSummaryDTO; +import org.prgrms.nabimarketbe.completeRequest.wrapper.HistoryListReadLimitResponseDTO; +import org.prgrms.nabimarketbe.completeRequest.wrapper.HistoryListReadPagingResponseDTO; import org.prgrms.nabimarketbe.error.BaseException; import org.prgrms.nabimarketbe.error.ErrorCode; import org.prgrms.nabimarketbe.event.NotificationCreateEvent; -import org.prgrms.nabimarketbe.jpa.card.entity.Card; -import org.prgrms.nabimarketbe.jpa.card.entity.CardStatus; -import org.prgrms.nabimarketbe.jpa.card.projection.CardCondenseResponseDTO; -import org.prgrms.nabimarketbe.jpa.card.projection.CardUserSummaryResponseDTO; -import org.prgrms.nabimarketbe.jpa.card.repository.CardRepository; -import org.prgrms.nabimarketbe.jpa.completerequest.entity.CompleteRequest; -import org.prgrms.nabimarketbe.jpa.completerequest.repository.CompleteRequestRepository; -import org.prgrms.nabimarketbe.jpa.completerequest.wrapper.CompleteRequestInfoDTO; -import org.prgrms.nabimarketbe.jpa.completerequest.wrapper.CompleteRequestSummaryDTO; -import org.prgrms.nabimarketbe.jpa.completerequest.wrapper.HistoryListReadLimitResponseDTO; -import org.prgrms.nabimarketbe.jpa.completerequest.wrapper.HistoryListReadPagingResponseDTO; -import org.prgrms.nabimarketbe.jpa.suggestion.entity.Suggestion; -import org.prgrms.nabimarketbe.jpa.suggestion.repository.SuggestionRepository; -import org.prgrms.nabimarketbe.jpa.user.entity.User; -import org.prgrms.nabimarketbe.jpa.user.projection.UserIdResponseDTO; -import org.prgrms.nabimarketbe.jpa.user.repository.UserRepository; + +import org.prgrms.nabimarketbe.suggestion.entity.Suggestion; +import org.prgrms.nabimarketbe.suggestion.repository.SuggestionRepository; +import org.prgrms.nabimarketbe.user.entity.User; +import org.prgrms.nabimarketbe.user.projection.UserIdResponseDTO; +import org.prgrms.nabimarketbe.user.repository.UserRepository; import org.prgrms.nabimarketbe.user.service.CheckService; import org.springframework.context.ApplicationEventPublisher; import org.springframework.stereotype.Service; diff --git a/nabimarket-application/src/main/java/org/prgrms/nabimarketbe/config/SecurityConfiguration.java b/nabimarket-application/src/main/java/org/prgrms/nabimarketbe/config/SecurityConfiguration.java index 4d350318..a30c21e8 100644 --- a/nabimarket-application/src/main/java/org/prgrms/nabimarketbe/config/SecurityConfiguration.java +++ b/nabimarket-application/src/main/java/org/prgrms/nabimarketbe/config/SecurityConfiguration.java @@ -1,11 +1,11 @@ package org.prgrms.nabimarketbe.config; -import org.prgrms.nabimarketbe.jpa.user.entity.Role; import org.prgrms.nabimarketbe.jwt.filter.JwtAuthenticationFilter; import org.prgrms.nabimarketbe.jwt.filter.JwtExceptionFilter; import org.prgrms.nabimarketbe.jwt.handler.CustomAccessDeniedHandler; import org.prgrms.nabimarketbe.jwt.handler.CustomAuthenticationEntryPoint; import org.prgrms.nabimarketbe.jwt.provider.JwtProvider; +import org.prgrms.nabimarketbe.user.entity.Role; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.http.HttpMethod; diff --git a/nabimarket-application/src/main/java/org/prgrms/nabimarketbe/dibs/dto/response/DibCreateResponseDTO.java b/nabimarket-application/src/main/java/org/prgrms/nabimarketbe/dibs/dto/response/DibCreateResponseDTO.java index c48fe13c..6d353ec9 100644 --- a/nabimarket-application/src/main/java/org/prgrms/nabimarketbe/dibs/dto/response/DibCreateResponseDTO.java +++ b/nabimarket-application/src/main/java/org/prgrms/nabimarketbe/dibs/dto/response/DibCreateResponseDTO.java @@ -2,7 +2,7 @@ import java.time.LocalDateTime; -import org.prgrms.nabimarketbe.jpa.dibs.entity.Dib; +import org.prgrms.nabimarketbe.dibs.entity.Dib; import lombok.Builder; diff --git a/nabimarket-application/src/main/java/org/prgrms/nabimarketbe/dibs/service/DibService.java b/nabimarket-application/src/main/java/org/prgrms/nabimarketbe/dibs/service/DibService.java index e4a715ca..d5409c22 100644 --- a/nabimarket-application/src/main/java/org/prgrms/nabimarketbe/dibs/service/DibService.java +++ b/nabimarket-application/src/main/java/org/prgrms/nabimarketbe/dibs/service/DibService.java @@ -1,16 +1,16 @@ package org.prgrms.nabimarketbe.dibs.service; +import org.prgrms.nabimarketbe.card.entity.Card; +import org.prgrms.nabimarketbe.card.repository.CardRepository; import org.prgrms.nabimarketbe.dibs.dto.response.DibCreateResponseDTO; import org.prgrms.nabimarketbe.dibs.dto.wrapper.DibResponseDTO; +import org.prgrms.nabimarketbe.dibs.entity.Dib; +import org.prgrms.nabimarketbe.dibs.repository.DibRepository; +import org.prgrms.nabimarketbe.dibs.wrapper.DibListReadPagingResponseDTO; import org.prgrms.nabimarketbe.error.BaseException; import org.prgrms.nabimarketbe.error.ErrorCode; -import org.prgrms.nabimarketbe.jpa.card.entity.Card; -import org.prgrms.nabimarketbe.jpa.card.repository.CardRepository; -import org.prgrms.nabimarketbe.jpa.dibs.entity.Dib; -import org.prgrms.nabimarketbe.jpa.dibs.projection.DibListReadPagingResponseDTO; -import org.prgrms.nabimarketbe.jpa.dibs.repository.DibRepository; -import org.prgrms.nabimarketbe.jpa.user.entity.User; -import org.prgrms.nabimarketbe.jpa.user.repository.UserRepository; +import org.prgrms.nabimarketbe.user.entity.User; +import org.prgrms.nabimarketbe.user.repository.UserRepository; import org.prgrms.nabimarketbe.user.service.CheckService; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; diff --git a/nabimarket-application/src/main/java/org/prgrms/nabimarketbe/event/NotificationCreateEvent.java b/nabimarket-application/src/main/java/org/prgrms/nabimarketbe/event/NotificationCreateEvent.java index c9b88c63..aae94445 100644 --- a/nabimarket-application/src/main/java/org/prgrms/nabimarketbe/event/NotificationCreateEvent.java +++ b/nabimarket-application/src/main/java/org/prgrms/nabimarketbe/event/NotificationCreateEvent.java @@ -1,7 +1,7 @@ package org.prgrms.nabimarketbe.event; -import org.prgrms.nabimarketbe.jpa.card.entity.Card; -import org.prgrms.nabimarketbe.jpa.user.entity.User; +import org.prgrms.nabimarketbe.card.entity.Card; +import org.prgrms.nabimarketbe.user.entity.User; import lombok.Getter; import lombok.RequiredArgsConstructor; diff --git a/nabimarket-application/src/main/java/org/prgrms/nabimarketbe/jwt/provider/JwtProvider.java b/nabimarket-application/src/main/java/org/prgrms/nabimarketbe/jwt/provider/JwtProvider.java index 23c95d79..cedcd61a 100644 --- a/nabimarket-application/src/main/java/org/prgrms/nabimarketbe/jwt/provider/JwtProvider.java +++ b/nabimarket-application/src/main/java/org/prgrms/nabimarketbe/jwt/provider/JwtProvider.java @@ -9,10 +9,10 @@ import javax.transaction.Transactional; import org.prgrms.nabimarketbe.error.ErrorCode; -import org.prgrms.nabimarketbe.jpa.refreshtoken.entity.RefreshToken; import org.prgrms.nabimarketbe.jwt.dto.AccessTokenResponseDTO; import org.prgrms.nabimarketbe.jwt.dto.TokenResponseDTO; -import org.prgrms.nabimarketbe.jpa.refreshtoken.repository.RefreshTokenRepository; +import org.prgrms.nabimarketbe.security.entity.RefreshToken; +import org.prgrms.nabimarketbe.security.jwt.repository.RefreshTokenRepository; import org.springframework.beans.factory.annotation.Value; import org.springframework.security.authentication.UsernamePasswordAuthenticationToken; import org.springframework.security.core.Authentication; diff --git a/nabimarket-application/src/main/java/org/prgrms/nabimarketbe/notification/service/NotificationService.java b/nabimarket-application/src/main/java/org/prgrms/nabimarketbe/notification/service/NotificationService.java index a015a34f..c116d984 100644 --- a/nabimarket-application/src/main/java/org/prgrms/nabimarketbe/notification/service/NotificationService.java +++ b/nabimarket-application/src/main/java/org/prgrms/nabimarketbe/notification/service/NotificationService.java @@ -2,16 +2,17 @@ import java.util.List; +import org.prgrms.nabimarketbe.card.entity.Card; import org.prgrms.nabimarketbe.error.BaseException; import org.prgrms.nabimarketbe.error.ErrorCode; -import org.prgrms.nabimarketbe.jpa.card.entity.Card; -import org.prgrms.nabimarketbe.jpa.notification.entity.Notification; -import org.prgrms.nabimarketbe.jpa.notification.projection.NotificationPagingResponseDTO; -import org.prgrms.nabimarketbe.jpa.notification.repository.NotificationRepository; -import org.prgrms.nabimarketbe.jpa.user.entity.User; -import org.prgrms.nabimarketbe.jpa.user.repository.UserRepository; + import org.prgrms.nabimarketbe.notification.dto.request.NotificationReadRequestDTO; import org.prgrms.nabimarketbe.notification.dto.response.NotificationUnreadCountResponseDTO; +import org.prgrms.nabimarketbe.notification.entity.Notification; +import org.prgrms.nabimarketbe.notification.repository.NotificationRepository; +import org.prgrms.nabimarketbe.notification.wrapper.NotificationPagingResponseDTO; +import org.prgrms.nabimarketbe.user.entity.User; +import org.prgrms.nabimarketbe.user.repository.UserRepository; import org.prgrms.nabimarketbe.user.service.CheckService; import org.springframework.data.domain.PageRequest; import org.springframework.data.domain.Sort; diff --git a/nabimarket-application/src/main/java/org/prgrms/nabimarketbe/oauth2/google/dto/GoogleUserInfoDTO.java b/nabimarket-application/src/main/java/org/prgrms/nabimarketbe/oauth2/google/dto/GoogleUserInfoDTO.java index 0bc32d9e..b0fb7161 100644 --- a/nabimarket-application/src/main/java/org/prgrms/nabimarketbe/oauth2/google/dto/GoogleUserInfoDTO.java +++ b/nabimarket-application/src/main/java/org/prgrms/nabimarketbe/oauth2/google/dto/GoogleUserInfoDTO.java @@ -1,7 +1,7 @@ package org.prgrms.nabimarketbe.oauth2.google.dto; -import org.prgrms.nabimarketbe.jpa.user.entity.Role; -import org.prgrms.nabimarketbe.jpa.user.entity.User; +import org.prgrms.nabimarketbe.user.entity.Role; +import org.prgrms.nabimarketbe.user.entity.User; public record GoogleUserInfoDTO( String id diff --git a/nabimarket-application/src/main/java/org/prgrms/nabimarketbe/oauth2/kakao/service/CustomUserDetailsService.java b/nabimarket-application/src/main/java/org/prgrms/nabimarketbe/oauth2/kakao/service/CustomUserDetailsService.java index f653f300..5f04603b 100644 --- a/nabimarket-application/src/main/java/org/prgrms/nabimarketbe/oauth2/kakao/service/CustomUserDetailsService.java +++ b/nabimarket-application/src/main/java/org/prgrms/nabimarketbe/oauth2/kakao/service/CustomUserDetailsService.java @@ -1,6 +1,6 @@ package org.prgrms.nabimarketbe.oauth2.kakao.service; -import org.prgrms.nabimarketbe.jpa.user.repository.UserRepository; +import org.prgrms.nabimarketbe.user.repository.UserRepository; import org.springframework.security.core.userdetails.UserDetails; import org.springframework.security.core.userdetails.UserDetailsService; import org.springframework.security.core.userdetails.UsernameNotFoundException; diff --git a/nabimarket-application/src/main/java/org/prgrms/nabimarketbe/suggestion/dto/response/SuggestionResponseDTO.java b/nabimarket-application/src/main/java/org/prgrms/nabimarketbe/suggestion/dto/response/SuggestionResponseDTO.java index 20e6ec62..0effd8e1 100644 --- a/nabimarket-application/src/main/java/org/prgrms/nabimarketbe/suggestion/dto/response/SuggestionResponseDTO.java +++ b/nabimarket-application/src/main/java/org/prgrms/nabimarketbe/suggestion/dto/response/SuggestionResponseDTO.java @@ -2,9 +2,9 @@ import java.time.LocalDateTime; -import org.prgrms.nabimarketbe.jpa.suggestion.entity.Suggestion; -import org.prgrms.nabimarketbe.jpa.suggestion.entity.SuggestionStatus; -import org.prgrms.nabimarketbe.jpa.suggestion.entity.SuggestionType; +import org.prgrms.nabimarketbe.suggestion.entity.Suggestion; +import org.prgrms.nabimarketbe.suggestion.entity.SuggestionStatus; +import org.prgrms.nabimarketbe.suggestion.entity.SuggestionType; import lombok.Builder; diff --git a/nabimarket-application/src/main/java/org/prgrms/nabimarketbe/suggestion/service/SuggestionService.java b/nabimarket-application/src/main/java/org/prgrms/nabimarketbe/suggestion/service/SuggestionService.java index 0db73da1..504483f3 100644 --- a/nabimarket-application/src/main/java/org/prgrms/nabimarketbe/suggestion/service/SuggestionService.java +++ b/nabimarket-application/src/main/java/org/prgrms/nabimarketbe/suggestion/service/SuggestionService.java @@ -1,22 +1,23 @@ package org.prgrms.nabimarketbe.suggestion.service; +import org.prgrms.nabimarketbe.card.entity.Card; +import org.prgrms.nabimarketbe.card.entity.CardStatus; +import org.prgrms.nabimarketbe.card.repository.CardRepository; import org.prgrms.nabimarketbe.chatroom.service.ChatRoomService; import org.prgrms.nabimarketbe.error.BaseException; import org.prgrms.nabimarketbe.error.ErrorCode; import org.prgrms.nabimarketbe.event.NotificationCreateEvent; -import org.prgrms.nabimarketbe.jpa.card.entity.Card; -import org.prgrms.nabimarketbe.jpa.card.entity.CardStatus; -import org.prgrms.nabimarketbe.jpa.card.repository.CardRepository; -import org.prgrms.nabimarketbe.jpa.suggestion.entity.DirectionType; -import org.prgrms.nabimarketbe.jpa.suggestion.entity.Suggestion; -import org.prgrms.nabimarketbe.jpa.suggestion.entity.SuggestionType; -import org.prgrms.nabimarketbe.jpa.suggestion.projection.SuggestionListReadPagingResponseDTO; -import org.prgrms.nabimarketbe.jpa.suggestion.repository.SuggestionRepository; -import org.prgrms.nabimarketbe.jpa.user.entity.User; -import org.prgrms.nabimarketbe.jpa.user.repository.UserRepository; + import org.prgrms.nabimarketbe.redisson.DistributedLock; import org.prgrms.nabimarketbe.suggestion.dto.request.SuggestionRequestDTO; import org.prgrms.nabimarketbe.suggestion.dto.response.SuggestionResponseDTO; +import org.prgrms.nabimarketbe.suggestion.entity.DirectionType; +import org.prgrms.nabimarketbe.suggestion.entity.Suggestion; +import org.prgrms.nabimarketbe.suggestion.entity.SuggestionType; +import org.prgrms.nabimarketbe.suggestion.projection.SuggestionListReadPagingResponseDTO; +import org.prgrms.nabimarketbe.suggestion.repository.SuggestionRepository; +import org.prgrms.nabimarketbe.user.entity.User; +import org.prgrms.nabimarketbe.user.repository.UserRepository; import org.prgrms.nabimarketbe.user.service.CheckService; import org.springframework.context.ApplicationEventPublisher; import org.springframework.stereotype.Service; diff --git a/nabimarket-application/src/main/java/org/prgrms/nabimarketbe/user/dto/request/SocialUserInfoDTO.java b/nabimarket-application/src/main/java/org/prgrms/nabimarketbe/user/dto/request/SocialUserInfoDTO.java index 54447ddf..dc052679 100644 --- a/nabimarket-application/src/main/java/org/prgrms/nabimarketbe/user/dto/request/SocialUserInfoDTO.java +++ b/nabimarket-application/src/main/java/org/prgrms/nabimarketbe/user/dto/request/SocialUserInfoDTO.java @@ -2,8 +2,8 @@ import javax.validation.constraints.NotBlank; -import org.prgrms.nabimarketbe.jpa.user.entity.Role; -import org.prgrms.nabimarketbe.jpa.user.entity.User; +import org.prgrms.nabimarketbe.user.entity.Role; +import org.prgrms.nabimarketbe.user.entity.User; import lombok.Builder; diff --git a/nabimarket-application/src/main/java/org/prgrms/nabimarketbe/user/dto/response/UserGetResponseDTO.java b/nabimarket-application/src/main/java/org/prgrms/nabimarketbe/user/dto/response/UserGetResponseDTO.java index 726f61d3..7c66d18c 100644 --- a/nabimarket-application/src/main/java/org/prgrms/nabimarketbe/user/dto/response/UserGetResponseDTO.java +++ b/nabimarket-application/src/main/java/org/prgrms/nabimarketbe/user/dto/response/UserGetResponseDTO.java @@ -2,7 +2,7 @@ import java.time.LocalDateTime; -import org.prgrms.nabimarketbe.jpa.user.entity.User; +import org.prgrms.nabimarketbe.user.entity.User; import lombok.Builder; diff --git a/nabimarket-application/src/main/java/org/prgrms/nabimarketbe/user/dto/response/UserLoginResponseDTO.java b/nabimarket-application/src/main/java/org/prgrms/nabimarketbe/user/dto/response/UserLoginResponseDTO.java index 7d5e01c5..8989f0f6 100644 --- a/nabimarket-application/src/main/java/org/prgrms/nabimarketbe/user/dto/response/UserLoginResponseDTO.java +++ b/nabimarket-application/src/main/java/org/prgrms/nabimarketbe/user/dto/response/UserLoginResponseDTO.java @@ -1,7 +1,7 @@ package org.prgrms.nabimarketbe.user.dto.response; import org.prgrms.nabimarketbe.jwt.dto.TokenResponseDTO; -import org.prgrms.nabimarketbe.jpa.user.entity.User; +import org.prgrms.nabimarketbe.user.entity.User; public record UserLoginResponseDTO( UserGetResponseDTO userInfo, diff --git a/nabimarket-application/src/main/java/org/prgrms/nabimarketbe/user/dto/response/UserSummaryResponseDTO.java b/nabimarket-application/src/main/java/org/prgrms/nabimarketbe/user/dto/response/UserSummaryResponseDTO.java index a04bbe22..8b0943df 100644 --- a/nabimarket-application/src/main/java/org/prgrms/nabimarketbe/user/dto/response/UserSummaryResponseDTO.java +++ b/nabimarket-application/src/main/java/org/prgrms/nabimarketbe/user/dto/response/UserSummaryResponseDTO.java @@ -1,6 +1,7 @@ package org.prgrms.nabimarketbe.user.dto.response; -import org.prgrms.nabimarketbe.jpa.user.entity.User; + +import org.prgrms.nabimarketbe.user.entity.User; import lombok.Builder; diff --git a/nabimarket-application/src/main/java/org/prgrms/nabimarketbe/user/dto/response/UserUpdateResponseDTO.java b/nabimarket-application/src/main/java/org/prgrms/nabimarketbe/user/dto/response/UserUpdateResponseDTO.java index 28df5e79..cea62328 100644 --- a/nabimarket-application/src/main/java/org/prgrms/nabimarketbe/user/dto/response/UserUpdateResponseDTO.java +++ b/nabimarket-application/src/main/java/org/prgrms/nabimarketbe/user/dto/response/UserUpdateResponseDTO.java @@ -1,6 +1,7 @@ package org.prgrms.nabimarketbe.user.dto.response; -import org.prgrms.nabimarketbe.jpa.user.entity.User; + +import org.prgrms.nabimarketbe.user.entity.User; import lombok.Builder; diff --git a/nabimarket-application/src/main/java/org/prgrms/nabimarketbe/user/service/SignService.java b/nabimarket-application/src/main/java/org/prgrms/nabimarketbe/user/service/SignService.java index 984f0234..2f2a6831 100644 --- a/nabimarket-application/src/main/java/org/prgrms/nabimarketbe/user/service/SignService.java +++ b/nabimarket-application/src/main/java/org/prgrms/nabimarketbe/user/service/SignService.java @@ -4,15 +4,16 @@ import org.prgrms.nabimarketbe.error.BaseException; import org.prgrms.nabimarketbe.error.ErrorCode; -import org.prgrms.nabimarketbe.jpa.refreshtoken.entity.RefreshToken; -import org.prgrms.nabimarketbe.jpa.refreshtoken.repository.RefreshTokenRepository; -import org.prgrms.nabimarketbe.jpa.user.entity.User; -import org.prgrms.nabimarketbe.jpa.user.repository.UserRepository; + import org.prgrms.nabimarketbe.jwt.dto.AccessTokenResponseDTO; import org.prgrms.nabimarketbe.jwt.dto.TokenResponseDTO; import org.prgrms.nabimarketbe.jwt.provider.JwtProvider; +import org.prgrms.nabimarketbe.security.entity.RefreshToken; +import org.prgrms.nabimarketbe.security.jwt.repository.RefreshTokenRepository; import org.prgrms.nabimarketbe.user.dto.request.SocialUserInfoDTO; import org.prgrms.nabimarketbe.user.dto.response.UserLoginResponseDTO; +import org.prgrms.nabimarketbe.user.entity.User; +import org.prgrms.nabimarketbe.user.repository.UserRepository; import org.springframework.security.core.userdetails.UsernameNotFoundException; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; diff --git a/nabimarket-application/src/main/java/org/prgrms/nabimarketbe/user/service/UserService.java b/nabimarket-application/src/main/java/org/prgrms/nabimarketbe/user/service/UserService.java index 0b6c3e48..acdcb576 100644 --- a/nabimarket-application/src/main/java/org/prgrms/nabimarketbe/user/service/UserService.java +++ b/nabimarket-application/src/main/java/org/prgrms/nabimarketbe/user/service/UserService.java @@ -5,13 +5,14 @@ import org.prgrms.nabimarketbe.aws.service.S3FileUploadService; import org.prgrms.nabimarketbe.error.BaseException; import org.prgrms.nabimarketbe.error.ErrorCode; -import org.prgrms.nabimarketbe.jpa.user.entity.User; -import org.prgrms.nabimarketbe.jpa.user.repository.UserRepository; + import org.prgrms.nabimarketbe.user.dto.request.UserNicknameUpdateRequestDTO; import org.prgrms.nabimarketbe.user.dto.request.UserProfileUpdateRequestDTO; import org.prgrms.nabimarketbe.user.dto.response.UserGetResponseDTO; import org.prgrms.nabimarketbe.user.dto.response.UserResponseDTO; import org.prgrms.nabimarketbe.user.dto.response.UserUpdateResponseDTO; +import org.prgrms.nabimarketbe.user.entity.User; +import org.prgrms.nabimarketbe.user.repository.UserRepository; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; diff --git a/nabimarket-domain/build.gradle b/nabimarket-domain/build.gradle index 4b30614e..c1dd035e 100644 --- a/nabimarket-domain/build.gradle +++ b/nabimarket-domain/build.gradle @@ -1,6 +1,27 @@ /** * Domain */ +plugins { + id "com.ewerk.gradle.plugins.querydsl" version "1.0.10" +} + +configurations { + querydsl.extendsFrom compileClasspath +} + +// Qtype 생성 경로 +def querydslDir = "$buildDir/generated/querydsl" +querydsl { + jpa = true + querydslSourcesDir = querydslDir +} +sourceSets { + main.java.srcDir querydslDir +} +compileQuerydsl { + options.annotationProcessorPath = configurations.querydsl +} + dependencies { // validation implementation 'org.springframework.boot:spring-boot-starter-validation' diff --git a/nabimarket-domain/src/main/java/org/prgrms/nabimarketbe/BaseEntity.java b/nabimarket-domain/src/main/java/org/prgrms/nabimarketbe/BaseEntity.java new file mode 100644 index 00000000..95651d61 --- /dev/null +++ b/nabimarket-domain/src/main/java/org/prgrms/nabimarketbe/BaseEntity.java @@ -0,0 +1,40 @@ + +package org.prgrms.nabimarketbe; + +import java.time.LocalDateTime; + +import javax.persistence.EntityListeners; +import javax.persistence.MappedSuperclass; +import javax.persistence.PrePersist; +import javax.persistence.PreUpdate; + +import org.springframework.data.annotation.CreatedDate; +import org.springframework.data.annotation.LastModifiedDate; +import org.springframework.data.jpa.domain.support.AuditingEntityListener; +import org.springframework.format.annotation.DateTimeFormat; + +import lombok.Getter; + +@Getter +@MappedSuperclass +@EntityListeners(AuditingEntityListener.class) +public abstract class BaseEntity { + @CreatedDate + @DateTimeFormat(pattern = "yyyy-MM-dd'T'HH:mm:ss") + private LocalDateTime createdDate; + + @LastModifiedDate + @DateTimeFormat(pattern = "yyyy-MM-dd'T'HH:mm:ss") + private LocalDateTime modifiedDate; + + @PrePersist + public void onPrePersist() { + this.createdDate = LocalDateTime.now().withNano(0); + this.modifiedDate = this.createdDate; + } + + @PreUpdate + public void onPreUpdate() { + this.modifiedDate = LocalDateTime.now().withNano(0); + } +} diff --git a/nabimarket-domain/src/main/java/org/prgrms/nabimarketbe/card/entity/Card.java b/nabimarket-domain/src/main/java/org/prgrms/nabimarketbe/card/entity/Card.java new file mode 100644 index 00000000..80338cc4 --- /dev/null +++ b/nabimarket-domain/src/main/java/org/prgrms/nabimarketbe/card/entity/Card.java @@ -0,0 +1,172 @@ +package org.prgrms.nabimarketbe.card.entity; + +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.EnumType; +import javax.persistence.Enumerated; +import javax.persistence.FetchType; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; +import javax.persistence.Id; +import javax.persistence.JoinColumn; +import javax.persistence.Lob; +import javax.persistence.ManyToOne; +import javax.persistence.OneToOne; +import javax.persistence.Table; +import javax.validation.constraints.Min; +import javax.validation.constraints.NotBlank; +import javax.validation.constraints.NotNull; + +import org.prgrms.nabimarketbe.BaseEntity; +import org.prgrms.nabimarketbe.error.BaseException; +import org.prgrms.nabimarketbe.error.ErrorCode; +import org.prgrms.nabimarketbe.item.entity.Item; +import org.prgrms.nabimarketbe.user.entity.User; + +import lombok.AccessLevel; +import lombok.Builder; +import lombok.Getter; +import lombok.NoArgsConstructor; + +@Entity +@Table(name = "cards") +@Getter +@NoArgsConstructor(access = AccessLevel.PROTECTED) +public class Card extends BaseEntity { + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + @Column(name = "card_id", nullable = false) + private Long cardId; + + @NotBlank(message = "공백을 허용하지 않습니다.") + @Column(name = "card_title", nullable = false, length = 30) + private String cardTitle; + + @Column(name = "thumbnail") + private String thumbnail; + + @NotBlank(message = "공백을 허용하지 않습니다.") + @Lob + @Column(name = "content", nullable = false, length = 255) + private String content; + + @Column(name = "trade_area", nullable = false, length = 30) + private String tradeArea; + + @NotNull(message = "비울 수 없는 값입니다.") + @Column(name = "poke_available", nullable = false) + private Boolean pokeAvailable; + + @Enumerated(EnumType.STRING) + @Column(name = "trade_type", nullable = false) + private TradeType tradeType; + + @Enumerated(EnumType.STRING) + @Column(name = "status", nullable = false) + private CardStatus status; + + @Min(value = 0, message = "최소 0 이상의 값이 필요합니다.") + @Column(name = "view_count", nullable = false) + private Integer viewCount; + + @Min(value = 0, message = "최소 0 이상의 값이 필요합니다.") + @Column(name = "dib_count", nullable = false) + private Integer dibCount; + + @Column(name = "is_active", nullable = false) + private Boolean isActive; + + @OneToOne(fetch = FetchType.LAZY) + @JoinColumn(name = "item_id") + private Item item; + + @ManyToOne(fetch = FetchType.LAZY) + @JoinColumn(name = "user_id") + private User user; + + @Builder + private Card( + String cardTitle, + String thumbnail, + String content, + String tradeArea, + Boolean pokeAvailable, + TradeType tradeType, + Item item, + User user + ) { + if (cardTitle.isBlank() || content.isBlank() || thumbnail.isBlank()) { + throw new BaseException(ErrorCode.INVALID_REQUEST); + } + + if (pokeAvailable == null || tradeType == null || tradeArea == null || item == null || user == null) { + throw new BaseException(ErrorCode.INVALID_REQUEST); + } + + this.cardTitle = cardTitle; + this.thumbnail = thumbnail; + this.content = content; + this.tradeArea = tradeArea; + this.pokeAvailable = pokeAvailable; + this.tradeType = tradeType; + this.status = CardStatus.TRADE_AVAILABLE; + this.viewCount = 0; + this.dibCount = 0; + this.isActive = true; + this.item = item; + this.user = user; + } + + public void updateThumbnail(String url) { + this.thumbnail = url; + } + + public void updateViewCount() { + this.viewCount += 1; + } + + // TODO : dibCount 동시성 + public void increaseDibCount() { + this.dibCount += 1; + } + + public void decreaseDibCount() { + this.dibCount -= 1; + } + + public void updateCardStatusToTradeAvailable() { + this.status = CardStatus.TRADE_AVAILABLE; + } + + public void updateCardStatusToReserved() { + this.status = CardStatus.RESERVED; + } + + public void updateCardStatusToTradeComplete() { + this.status = CardStatus.TRADE_COMPLETE; + } + + public void deleteCard() { + this.isActive = false; + } + + public Boolean isPokeAvailable() { + return pokeAvailable; + } + + public void updateCard( + String cardTitle, + String thumbnail, + Boolean pokeAvailable, + String content, + TradeType tradeType, + String tradeArea + ) { + this.cardTitle = cardTitle; + this.thumbnail = thumbnail; + this.pokeAvailable = pokeAvailable; + this.content = content; + this.tradeType = tradeType; + this.tradeArea = tradeArea; + } +} diff --git a/nabimarket-domain/src/main/java/org/prgrms/nabimarketbe/card/entity/CardStatus.java b/nabimarket-domain/src/main/java/org/prgrms/nabimarketbe/card/entity/CardStatus.java new file mode 100644 index 00000000..847a4efe --- /dev/null +++ b/nabimarket-domain/src/main/java/org/prgrms/nabimarketbe/card/entity/CardStatus.java @@ -0,0 +1,7 @@ +package org.prgrms.nabimarketbe.card.entity; + +public enum CardStatus { + TRADE_AVAILABLE, + RESERVED, + TRADE_COMPLETE +} diff --git a/nabimarket-domain/src/main/java/org/prgrms/nabimarketbe/card/entity/TradeType.java b/nabimarket-domain/src/main/java/org/prgrms/nabimarketbe/card/entity/TradeType.java new file mode 100644 index 00000000..6e613b10 --- /dev/null +++ b/nabimarket-domain/src/main/java/org/prgrms/nabimarketbe/card/entity/TradeType.java @@ -0,0 +1,6 @@ +package org.prgrms.nabimarketbe.card.entity; + +public enum TradeType { + DIRECT_DEALING, + SHIPPING +} diff --git a/nabimarket-domain/src/main/java/org/prgrms/nabimarketbe/card/projection/CardCondenseResponseDTO.java b/nabimarket-domain/src/main/java/org/prgrms/nabimarketbe/card/projection/CardCondenseResponseDTO.java new file mode 100644 index 00000000..6c8edfd6 --- /dev/null +++ b/nabimarket-domain/src/main/java/org/prgrms/nabimarketbe/card/projection/CardCondenseResponseDTO.java @@ -0,0 +1,22 @@ +package org.prgrms.nabimarketbe.card.projection; + +import org.prgrms.nabimarketbe.card.entity.Card; + +import lombok.Builder; + +@Builder +public record CardCondenseResponseDTO( + Long cardId, + + String itemName, + + String thumbnail +) { + public static CardCondenseResponseDTO from(Card card) { + return CardCondenseResponseDTO.builder() + .cardId(card.getCardId()) + .itemName(card.getItem().getItemName()) + .thumbnail(card.getThumbnail()) + .build(); + } +} diff --git a/nabimarket-domain/src/main/java/org/prgrms/nabimarketbe/card/projection/CardFamousResponseDTO.java b/nabimarket-domain/src/main/java/org/prgrms/nabimarketbe/card/projection/CardFamousResponseDTO.java new file mode 100644 index 00000000..90901246 --- /dev/null +++ b/nabimarket-domain/src/main/java/org/prgrms/nabimarketbe/card/projection/CardFamousResponseDTO.java @@ -0,0 +1,16 @@ +package org.prgrms.nabimarketbe.card.projection; + +import org.prgrms.nabimarketbe.item.entity.PriceRange; + +import lombok.Getter; + +@Getter +public class CardFamousResponseDTO { + private Long cardId; + + private String itemName; + + private PriceRange priceRange; + + private String thumbnail; +} diff --git a/nabimarket-domain/src/main/java/org/prgrms/nabimarketbe/card/projection/CardInfoResponseDTO.java b/nabimarket-domain/src/main/java/org/prgrms/nabimarketbe/card/projection/CardInfoResponseDTO.java new file mode 100644 index 00000000..163bc75c --- /dev/null +++ b/nabimarket-domain/src/main/java/org/prgrms/nabimarketbe/card/projection/CardInfoResponseDTO.java @@ -0,0 +1,18 @@ +package org.prgrms.nabimarketbe.card.projection; + +import org.prgrms.nabimarketbe.item.entity.PriceRange; + +import lombok.Getter; + +@Getter +public class CardInfoResponseDTO { + private Long cardId; + + private String thumbnail; + + private String cardTitle; + + private String itemName; + + private PriceRange priceRange; +} diff --git a/nabimarket-domain/src/main/java/org/prgrms/nabimarketbe/card/projection/CardListReadResponseDTO.java b/nabimarket-domain/src/main/java/org/prgrms/nabimarketbe/card/projection/CardListReadResponseDTO.java new file mode 100644 index 00000000..94d3606e --- /dev/null +++ b/nabimarket-domain/src/main/java/org/prgrms/nabimarketbe/card/projection/CardListReadResponseDTO.java @@ -0,0 +1,29 @@ +package org.prgrms.nabimarketbe.card.projection; + +import java.time.LocalDateTime; + +import org.prgrms.nabimarketbe.card.entity.CardStatus; +import org.prgrms.nabimarketbe.item.entity.PriceRange; + +import lombok.Getter; +import lombok.NoArgsConstructor; + +@NoArgsConstructor +@Getter +public class CardListReadResponseDTO { + private Long cardId; + + private String cardTitle; + + private String itemName; + + private PriceRange priceRange; + + private String thumbnail; + + private CardStatus status; + + private LocalDateTime createdAt; + + private LocalDateTime modifiedAt; +} diff --git a/nabimarket-domain/src/main/java/org/prgrms/nabimarketbe/card/projection/CardListResponseDTO.java b/nabimarket-domain/src/main/java/org/prgrms/nabimarketbe/card/projection/CardListResponseDTO.java new file mode 100644 index 00000000..1f9b293e --- /dev/null +++ b/nabimarket-domain/src/main/java/org/prgrms/nabimarketbe/card/projection/CardListResponseDTO.java @@ -0,0 +1,8 @@ +package org.prgrms.nabimarketbe.card.projection; + +import java.util.List; + +public record CardListResponseDTO( + List cardList +) { +} diff --git a/nabimarket-domain/src/main/java/org/prgrms/nabimarketbe/card/projection/CardPagingResponseDTO.java b/nabimarket-domain/src/main/java/org/prgrms/nabimarketbe/card/projection/CardPagingResponseDTO.java new file mode 100644 index 00000000..e46d32bd --- /dev/null +++ b/nabimarket-domain/src/main/java/org/prgrms/nabimarketbe/card/projection/CardPagingResponseDTO.java @@ -0,0 +1,9 @@ +package org.prgrms.nabimarketbe.card.projection; + +import java.util.List; + +public record CardPagingResponseDTO( + List cardList, + String nextCursorId +) { +} diff --git a/nabimarket-domain/src/main/java/org/prgrms/nabimarketbe/card/projection/CardSuggestionResponseDTO.java b/nabimarket-domain/src/main/java/org/prgrms/nabimarketbe/card/projection/CardSuggestionResponseDTO.java new file mode 100644 index 00000000..ac42d382 --- /dev/null +++ b/nabimarket-domain/src/main/java/org/prgrms/nabimarketbe/card/projection/CardSuggestionResponseDTO.java @@ -0,0 +1,14 @@ +package org.prgrms.nabimarketbe.card.projection; + +import org.prgrms.nabimarketbe.suggestion.projection.SuggestionInfo; + +import lombok.Getter; +import lombok.NoArgsConstructor; + +@Getter +@NoArgsConstructor +public class CardSuggestionResponseDTO { + private CardInfoResponseDTO cardInfo; + + private SuggestionInfo suggestionInfo; +} diff --git a/nabimarket-domain/src/main/java/org/prgrms/nabimarketbe/card/projection/CardSummaryResponseDTO.java b/nabimarket-domain/src/main/java/org/prgrms/nabimarketbe/card/projection/CardSummaryResponseDTO.java new file mode 100644 index 00000000..49b5737e --- /dev/null +++ b/nabimarket-domain/src/main/java/org/prgrms/nabimarketbe/card/projection/CardSummaryResponseDTO.java @@ -0,0 +1,16 @@ +package org.prgrms.nabimarketbe.card.projection; + +import org.prgrms.nabimarketbe.item.entity.PriceRange; + +import lombok.Getter; + +@Getter +public class CardSummaryResponseDTO { + private Long cardId; + + private String itemName; + + private String thumbnail; + + private PriceRange priceRange; +} diff --git a/nabimarket-domain/src/main/java/org/prgrms/nabimarketbe/card/projection/CardUserSummaryResponseDTO.java b/nabimarket-domain/src/main/java/org/prgrms/nabimarketbe/card/projection/CardUserSummaryResponseDTO.java new file mode 100644 index 00000000..ffd8d7f8 --- /dev/null +++ b/nabimarket-domain/src/main/java/org/prgrms/nabimarketbe/card/projection/CardUserSummaryResponseDTO.java @@ -0,0 +1,9 @@ +package org.prgrms.nabimarketbe.card.projection; + +import org.prgrms.nabimarketbe.user.projection.UserIdResponseDTO; + +public record CardUserSummaryResponseDTO( + CardCondenseResponseDTO cardInfo, + UserIdResponseDTO userInfo +) { +} diff --git a/nabimarket-domain/src/main/java/org/prgrms/nabimarketbe/card/repository/CardRepository.java b/nabimarket-domain/src/main/java/org/prgrms/nabimarketbe/card/repository/CardRepository.java new file mode 100644 index 00000000..70e2863a --- /dev/null +++ b/nabimarket-domain/src/main/java/org/prgrms/nabimarketbe/card/repository/CardRepository.java @@ -0,0 +1,28 @@ +package org.prgrms.nabimarketbe.card.repository; + +import java.util.Optional; + +import org.prgrms.nabimarketbe.card.entity.Card; +import org.prgrms.nabimarketbe.user.entity.User; +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; + +public interface CardRepository extends JpaRepository, CardRepositoryCustom { + @Query("SELECT c FROM Card c WHERE c.cardId = :cardId AND c.user = :user AND c.isActive = true") + Optional findByCardIdAndUser(@Param("cardId") Long cardId, @Param("user") User user); + + @Query("SELECT c FROM Card c WHERE c.cardId = :cardId AND c.isActive = true") + Optional findActiveCardById(@Param("cardId") Long cardId); + + @Query("SELECT c FROM Card c WHERE c.cardId = :cardId") + Optional findExistingCardById(@Param("cardId") Long cardId); + + @Query("SELECT c.viewCount FROM Card c WHERE c.cardId = :cardId") + Integer getCardViewCountById(@Param("cardId") Long cardId); + + @Query("UPDATE Card c SET c.viewCount = :viewCount WHERE c.cardId = :cardId") + @Modifying(clearAutomatically = true) + void updateViewCountByCardId(@Param("cardId") Long cardId, @Param("viewCount") Integer viewCount); +} diff --git a/nabimarket-domain/src/main/java/org/prgrms/nabimarketbe/card/repository/CardRepositoryCustom.java b/nabimarket-domain/src/main/java/org/prgrms/nabimarketbe/card/repository/CardRepositoryCustom.java new file mode 100644 index 00000000..0ddb7a86 --- /dev/null +++ b/nabimarket-domain/src/main/java/org/prgrms/nabimarketbe/card/repository/CardRepositoryCustom.java @@ -0,0 +1,37 @@ +package org.prgrms.nabimarketbe.card.repository; + +import java.util.List; + +import org.prgrms.nabimarketbe.card.projection.CardFamousResponseDTO; +import org.prgrms.nabimarketbe.card.projection.CardPagingResponseDTO; +import org.prgrms.nabimarketbe.card.projection.CardSuggestionResponseDTO; +import org.prgrms.nabimarketbe.card.entity.CardStatus; +import org.prgrms.nabimarketbe.category.entity.CategoryEnum; +import org.prgrms.nabimarketbe.item.entity.PriceRange; +import org.prgrms.nabimarketbe.user.entity.User; +import org.springframework.data.domain.Pageable; + +public interface CardRepositoryCustom { + CardPagingResponseDTO getCardsByCondition( + CategoryEnum category, + PriceRange priceRange, + List status, + String title, + String cursorId, + Pageable pageable + ); + + CardPagingResponseDTO getMyCardsByStatus( + User user, + CardStatus status, + String cursorId, + Integer size + ); + + List getSuggestionAvailableCards( + Long userId, + Long targetCardId + ); + + List getCardsByPopularity(); +} diff --git a/nabimarket-domain/src/main/java/org/prgrms/nabimarketbe/card/repository/CardRepositoryImpl.java b/nabimarket-domain/src/main/java/org/prgrms/nabimarketbe/card/repository/CardRepositoryImpl.java new file mode 100644 index 00000000..4bae3403 --- /dev/null +++ b/nabimarket-domain/src/main/java/org/prgrms/nabimarketbe/card/repository/CardRepositoryImpl.java @@ -0,0 +1,267 @@ +package org.prgrms.nabimarketbe.card.repository; + +import static org.prgrms.nabimarketbe.card.entity.QCard.card; +import static org.prgrms.nabimarketbe.item.entity.QItem.item; +import static org.prgrms.nabimarketbe.suggestion.entity.QSuggestion.suggestion; + +import java.util.List; + +import org.prgrms.nabimarketbe.card.entity.CardStatus; +import org.prgrms.nabimarketbe.card.projection.CardFamousResponseDTO; +import org.prgrms.nabimarketbe.card.projection.CardInfoResponseDTO; +import org.prgrms.nabimarketbe.card.projection.CardListReadResponseDTO; +import org.prgrms.nabimarketbe.card.projection.CardPagingResponseDTO; +import org.prgrms.nabimarketbe.card.projection.CardSuggestionResponseDTO; +import org.prgrms.nabimarketbe.category.entity.CategoryEnum; +import org.prgrms.nabimarketbe.item.entity.PriceRange; +import org.prgrms.nabimarketbe.suggestion.projection.SuggestionInfo; +import org.prgrms.nabimarketbe.user.entity.User; +import org.prgrms.nabimarketbe.util.CursorPaging; +import org.prgrms.nabimarketbe.util.QueryDslUtil; +import org.springframework.data.domain.Pageable; +import org.springframework.data.domain.Sort; + +import com.querydsl.core.types.ConstantImpl; +import com.querydsl.core.types.Projections; +import com.querydsl.core.types.dsl.BooleanExpression; +import com.querydsl.core.types.dsl.Expressions; +import com.querydsl.core.types.dsl.StringExpression; +import com.querydsl.core.types.dsl.StringExpressions; +import com.querydsl.core.types.dsl.StringTemplate; +import com.querydsl.jpa.impl.JPAQueryFactory; + +import lombok.RequiredArgsConstructor; + +@RequiredArgsConstructor +public class CardRepositoryImpl implements CardRepositoryCustom, CursorPaging { + private static final int FAMOUS_CARD_SIZE = 5; + + private final JPAQueryFactory jpaQueryFactory; + + @Override + public CardPagingResponseDTO getCardsByCondition( + CategoryEnum category, + PriceRange priceRange, + List status, + String cardTitle, + String cursorId, + Pageable pageable + ) { + List cardList = jpaQueryFactory.select( + Projections.fields( + CardListReadResponseDTO.class, + card.cardId, + card.cardTitle, + item.itemName, + item.priceRange, + card.thumbnail, + card.status, + card.createdDate.as("createdAt"), + card.modifiedDate.as("modifiedAt") + ) + ) + .from(card) + .leftJoin(item).on(card.item.itemId.eq(item.itemId)) + .where( + cursorId(cursorId), + categoryEquals(category), + statusEquals(status), + priceRangeEquals(priceRange), + titleEquals(cardTitle), + isCardActive() + ) + .orderBy(QueryDslUtil.getOrderSpecifier(pageable.getSort(), card)) + .limit(pageable.getPageSize()) + .fetch(); + + String nextCursor = + cardList.size() < pageable.getPageSize() ? null : generateCursor(cardList.get(cardList.size() - 1)); + + return new CardPagingResponseDTO(cardList, nextCursor); + } + + @Override + public CardPagingResponseDTO getMyCardsByStatus( + User user, + CardStatus status, + String cursorId, + Integer size + ) { + List cardList = jpaQueryFactory.select( + Projections.fields( + CardListReadResponseDTO.class, + card.cardId, + card.cardTitle, + item.itemName, + item.priceRange, + card.thumbnail, + card.status, + card.createdDate.as("createdAt"), + card.modifiedDate.as("modifiedAt") + ) + ) + .from(card) + .leftJoin(item).on(card.item.itemId.eq(item.itemId)) + .where( + cursorId(cursorId), + card.status.eq(status), + card.user.eq(user), + isCardActive() + ) + .orderBy( + QueryDslUtil.getOrderSpecifier( + Sort.by( + Sort.Order.desc("createdDate"), + Sort.Order.desc("cardId") + ), + card + ) + ) + .limit(size) + .fetch(); + + String nextCursor = cardList.size() < size ? null : generateCursor(cardList.get(cardList.size() - 1)); + + return new CardPagingResponseDTO(cardList, nextCursor); + } + + @Override + public List getSuggestionAvailableCards( + Long userId, + Long targetCardId + ) { + List cardList = jpaQueryFactory + .select( + Projections.fields( + CardSuggestionResponseDTO.class, + Projections.fields( + CardInfoResponseDTO.class, + card.cardId, + card.thumbnail, + card.cardTitle, + card.item.itemName, + card.item.priceRange + ).as("cardInfo"), + Projections.fields( + SuggestionInfo.class, + suggestion.suggestionType, + suggestion.suggestionStatus + ).as("suggestionInfo") + ) + ) + .from(card) + .leftJoin(suggestion).on(suggestion.fromCard.cardId.eq(card.cardId)) + .where( + card.user.userId.eq(userId), + isCardActive() + ) + .distinct() + .on(suggestion.toCard.cardId.eq(targetCardId)) + .fetch(); + + return cardList; + } + + @Override + public BooleanExpression cursorId(String cursorId) { + if (cursorId == null) { + return null; + } + + // 생성일자 + StringTemplate dateCursorTemplate = Expressions.stringTemplate( + "DATE_FORMAT({0}, {1})", + card.createdDate, + ConstantImpl.create("%Y%m%d%H%i%s") + ); + + // pk + StringExpression pkCursorTemplate = StringExpressions.lpad( + card.cardId.stringValue(), + 8, + '0' + ); + + return dateCursorTemplate.concat(pkCursorTemplate).lt(cursorId); + } + + @Override + public List getCardsByPopularity() { + List cardList = jpaQueryFactory + .select( + Projections.fields( + CardFamousResponseDTO.class, + card.cardId, + card.item.itemName, + card.item.priceRange, + card.thumbnail + ) + ) + .from(card) + .where( + statusEquals(CardStatus.TRADE_AVAILABLE), + isCardActive() + ) + .orderBy(card.viewCount.desc(), card.dibCount.desc()) + .limit(FAMOUS_CARD_SIZE) + .fetch(); + + return cardList; + } + + private BooleanExpression statusEquals(CardStatus status) { + if (status == null) { + return null; + } + + return card.status.eq(status); + } + + private BooleanExpression categoryEquals(CategoryEnum category) { + if (category == null) { + return null; + } + + return item.category.categoryName.eq(category); + } + + private BooleanExpression statusEquals(List statuses) { + if (statuses == null || statuses.isEmpty()) { + return null; + } + + BooleanExpression[] expressions = statuses.stream() + .map(card.status::eq) + .toArray(BooleanExpression[]::new); + + return Expressions.anyOf(expressions); + } + + private BooleanExpression priceRangeEquals(PriceRange priceRange) { + if (priceRange == null) { + return null; + } + + return item.priceRange.eq(priceRange); + } + + private BooleanExpression titleEquals(String title) { + if (title == null) { + return null; + } + + return card.cardTitle.contains(title); + } + + private BooleanExpression isCardActive() { + return card.isActive.eq(true); + } + + private String generateCursor(CardListReadResponseDTO cardListReadResponseDTO) { + return cardListReadResponseDTO.getCreatedAt().toString() // 디폴트는 생성일자 최신순 정렬 + .replace("T", "") + .replace("-", "") + .replace(":", "") + + String.format("%08d", cardListReadResponseDTO.getCardId()); + } +} diff --git a/nabimarket-domain/src/main/java/org/prgrms/nabimarketbe/cardImage/entity/CardImage.java b/nabimarket-domain/src/main/java/org/prgrms/nabimarketbe/cardImage/entity/CardImage.java new file mode 100644 index 00000000..44d32b65 --- /dev/null +++ b/nabimarket-domain/src/main/java/org/prgrms/nabimarketbe/cardImage/entity/CardImage.java @@ -0,0 +1,58 @@ +package org.prgrms.nabimarketbe.cardImage.entity; + +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.FetchType; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; +import javax.persistence.Id; +import javax.persistence.JoinColumn; +import javax.persistence.ManyToOne; +import javax.persistence.Table; +import javax.validation.constraints.NotBlank; + +import org.prgrms.nabimarketbe.BaseEntity; +import org.prgrms.nabimarketbe.card.entity.Card; +import org.prgrms.nabimarketbe.error.BaseException; +import org.prgrms.nabimarketbe.error.ErrorCode; + +import lombok.AccessLevel; +import lombok.Builder; +import lombok.Getter; +import lombok.NoArgsConstructor; + +@Entity +@Table(name = "card_images") +@NoArgsConstructor(access = AccessLevel.PROTECTED) +@Getter +public class CardImage extends BaseEntity { + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + @Column(name = "card_image_id", nullable = false) + private Long cardImageId; + + @NotBlank(message = "공백을 허용하지 않습니다.") + @Column(name = "image_url", nullable = false) + private String imageUrl; + + @ManyToOne(fetch = FetchType.LAZY) + @JoinColumn(name = "card_id") + private Card card; + + @Builder + public CardImage( + String imageUrl, + Card card + ) { + if (imageUrl.isBlank()) { + throw new BaseException(ErrorCode.INVALID_REQUEST); + } + + if (card == null) { + throw new BaseException(ErrorCode.INVALID_REQUEST); + } + + this.imageUrl = imageUrl; + this.card = card; + } +} diff --git a/nabimarket-domain/src/main/java/org/prgrms/nabimarketbe/cardImage/repository/CardImageBatchRepository.java b/nabimarket-domain/src/main/java/org/prgrms/nabimarketbe/cardImage/repository/CardImageBatchRepository.java new file mode 100644 index 00000000..4f138598 --- /dev/null +++ b/nabimarket-domain/src/main/java/org/prgrms/nabimarketbe/cardImage/repository/CardImageBatchRepository.java @@ -0,0 +1,36 @@ +package org.prgrms.nabimarketbe.cardImage.repository; + +import java.sql.PreparedStatement; +import java.sql.Timestamp; +import java.time.LocalDateTime; +import java.util.List; + +import org.prgrms.nabimarketbe.cardImage.entity.CardImage; +import org.springframework.jdbc.core.JdbcTemplate; +import org.springframework.stereotype.Repository; +import org.springframework.transaction.annotation.Transactional; + +import lombok.RequiredArgsConstructor; + +@Repository +@RequiredArgsConstructor +public class CardImageBatchRepository { + + private final JdbcTemplate jdbcTemplate; + + private static final String sql = "INSERT INTO card_images (created_date, modified_date, image_url, card_id) VALUES (?, ?, ?, ?)"; + + @Transactional + public void saveAll(List cardImages) { + jdbcTemplate.batchUpdate( + sql, + cardImages, + cardImages.size(), + (PreparedStatement preparedStatement, CardImage cardImage) -> { + preparedStatement.setTimestamp(1, Timestamp.valueOf(LocalDateTime.now())); + preparedStatement.setTimestamp(2, Timestamp.valueOf(LocalDateTime.now())); + preparedStatement.setString(3, cardImage.getImageUrl()); + preparedStatement.setLong(4, cardImage.getCard().getCardId()); + }); + } +} diff --git a/nabimarket-domain/src/main/java/org/prgrms/nabimarketbe/cardImage/repository/CardImageRepository.java b/nabimarket-domain/src/main/java/org/prgrms/nabimarketbe/cardImage/repository/CardImageRepository.java new file mode 100644 index 00000000..036b2e8f --- /dev/null +++ b/nabimarket-domain/src/main/java/org/prgrms/nabimarketbe/cardImage/repository/CardImageRepository.java @@ -0,0 +1,13 @@ +package org.prgrms.nabimarketbe.cardImage.repository; + +import java.util.List; + +import org.prgrms.nabimarketbe.card.entity.Card; +import org.prgrms.nabimarketbe.cardImage.entity.CardImage; +import org.springframework.data.jpa.repository.JpaRepository; + +public interface CardImageRepository extends JpaRepository { + List findAllByCard(Card card); + + void deleteAllByCard(Card card); +} diff --git a/nabimarket-domain/src/main/java/org/prgrms/nabimarketbe/category/entity/Category.java b/nabimarket-domain/src/main/java/org/prgrms/nabimarketbe/category/entity/Category.java new file mode 100644 index 00000000..5d5946d5 --- /dev/null +++ b/nabimarket-domain/src/main/java/org/prgrms/nabimarketbe/category/entity/Category.java @@ -0,0 +1,32 @@ +package org.prgrms.nabimarketbe.category.entity; + +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.EnumType; +import javax.persistence.Enumerated; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; +import javax.persistence.Id; +import javax.persistence.Table; + +import lombok.Getter; +import lombok.NoArgsConstructor; + +@Entity +@Table(name = "categories") +@Getter +@NoArgsConstructor +public class Category { + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + @Column(name = "category_id", nullable = false) + private Long categoryId; + + @Enumerated(EnumType.STRING) + @Column(name = "category_name", nullable = false, unique = true) + private CategoryEnum categoryName; + + public Category(CategoryEnum categoryName) { + this.categoryName = categoryName; + } +} diff --git a/nabimarket-domain/src/main/java/org/prgrms/nabimarketbe/category/entity/CategoryEnum.java b/nabimarket-domain/src/main/java/org/prgrms/nabimarketbe/category/entity/CategoryEnum.java new file mode 100644 index 00000000..605f620e --- /dev/null +++ b/nabimarket-domain/src/main/java/org/prgrms/nabimarketbe/category/entity/CategoryEnum.java @@ -0,0 +1,13 @@ +package org.prgrms.nabimarketbe.category.entity; + +public enum CategoryEnum { + MALE_CLOTHES, + FEMALE_CLOTHES, + GOODS_ACCESSORY, + SHOES, + SPORTS, + BOOKS, + ELECTRONICS, + FURNITURE_INTERIOR, + HOME_ELECTRONICS +} diff --git a/nabimarket-domain/src/main/java/org/prgrms/nabimarketbe/category/repository/CategoryRepository.java b/nabimarket-domain/src/main/java/org/prgrms/nabimarketbe/category/repository/CategoryRepository.java new file mode 100644 index 00000000..aa00d16b --- /dev/null +++ b/nabimarket-domain/src/main/java/org/prgrms/nabimarketbe/category/repository/CategoryRepository.java @@ -0,0 +1,11 @@ +package org.prgrms.nabimarketbe.category.repository; + +import java.util.Optional; + +import org.prgrms.nabimarketbe.category.entity.Category; +import org.prgrms.nabimarketbe.category.entity.CategoryEnum; +import org.springframework.data.jpa.repository.JpaRepository; + +public interface CategoryRepository extends JpaRepository { + Optional findCategoryByCategoryName(CategoryEnum categoryEnum); +} diff --git a/nabimarket-domain/src/main/java/org/prgrms/nabimarketbe/chatroom/entity/ChatRoom.java b/nabimarket-domain/src/main/java/org/prgrms/nabimarketbe/chatroom/entity/ChatRoom.java new file mode 100644 index 00000000..a54af97c --- /dev/null +++ b/nabimarket-domain/src/main/java/org/prgrms/nabimarketbe/chatroom/entity/ChatRoom.java @@ -0,0 +1,45 @@ +package org.prgrms.nabimarketbe.chatroom.entity; + +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.FetchType; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; +import javax.persistence.Id; +import javax.persistence.JoinColumn; +import javax.persistence.OneToOne; +import javax.persistence.Table; +import javax.validation.constraints.NotBlank; + +import org.prgrms.nabimarketbe.BaseEntity; +import org.prgrms.nabimarketbe.suggestion.entity.Suggestion; + +import lombok.Getter; +import lombok.NoArgsConstructor; + +@Entity +@Table(name = "chat_rooms") +@NoArgsConstructor +@Getter +public class ChatRoom extends BaseEntity { + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + @Column(name = "chat_room_id") + private Long chatRoomId; + + @NotBlank + @Column(nullable = false, name = "firestore_chat_room_path", unique = true) + private String fireStoreChatRoomPath; + + @OneToOne(fetch = FetchType.LAZY) + @JoinColumn(nullable = false, name = "suggestion_id", unique = true) + private Suggestion suggestion; + + public ChatRoom( + String fireStoreChatRoomPath, + Suggestion suggestion + ) { + this.fireStoreChatRoomPath = fireStoreChatRoomPath; + this.suggestion = suggestion; + } +} diff --git a/nabimarket-domain/src/main/java/org/prgrms/nabimarketbe/chatroom/projection/list/CardInfoListDTO.java b/nabimarket-domain/src/main/java/org/prgrms/nabimarketbe/chatroom/projection/list/CardInfoListDTO.java new file mode 100644 index 00000000..970d89d8 --- /dev/null +++ b/nabimarket-domain/src/main/java/org/prgrms/nabimarketbe/chatroom/projection/list/CardInfoListDTO.java @@ -0,0 +1,16 @@ +package org.prgrms.nabimarketbe.chatroom.projection.list; + +import org.prgrms.nabimarketbe.item.entity.PriceRange; + +import lombok.Getter; + +@Getter +public class CardInfoListDTO { + private Long cardId; + + private String itemName; + + private PriceRange priceRange; + + private String thumbnail; +} diff --git a/nabimarket-domain/src/main/java/org/prgrms/nabimarketbe/chatroom/projection/list/ChatRoomInfoListDTO.java b/nabimarket-domain/src/main/java/org/prgrms/nabimarketbe/chatroom/projection/list/ChatRoomInfoListDTO.java new file mode 100644 index 00000000..04ebccdc --- /dev/null +++ b/nabimarket-domain/src/main/java/org/prgrms/nabimarketbe/chatroom/projection/list/ChatRoomInfoListDTO.java @@ -0,0 +1,16 @@ +package org.prgrms.nabimarketbe.chatroom.projection.list; + +import java.time.LocalDateTime; + +import lombok.Getter; + +@Getter +public class ChatRoomInfoListDTO { + private Long chatRoomId; + + private LocalDateTime createdAt; + + private FromCardInfoListDTO fromCardInfo; + + private ToCardInfoListDTO toCardInfo; +} diff --git a/nabimarket-domain/src/main/java/org/prgrms/nabimarketbe/chatroom/projection/list/ChatRoomListWrapper.java b/nabimarket-domain/src/main/java/org/prgrms/nabimarketbe/chatroom/projection/list/ChatRoomListWrapper.java new file mode 100644 index 00000000..41817d00 --- /dev/null +++ b/nabimarket-domain/src/main/java/org/prgrms/nabimarketbe/chatroom/projection/list/ChatRoomListWrapper.java @@ -0,0 +1,14 @@ +package org.prgrms.nabimarketbe.chatroom.projection.list; + +import java.util.List; + +import lombok.AllArgsConstructor; +import lombok.Getter; + +@AllArgsConstructor +@Getter +public class ChatRoomListWrapper { + private List chatRoomList; + + private String nextCursorId; +} diff --git a/nabimarket-domain/src/main/java/org/prgrms/nabimarketbe/chatroom/projection/list/FromCardInfoListDTO.java b/nabimarket-domain/src/main/java/org/prgrms/nabimarketbe/chatroom/projection/list/FromCardInfoListDTO.java new file mode 100644 index 00000000..8a4140e4 --- /dev/null +++ b/nabimarket-domain/src/main/java/org/prgrms/nabimarketbe/chatroom/projection/list/FromCardInfoListDTO.java @@ -0,0 +1,10 @@ +package org.prgrms.nabimarketbe.chatroom.projection.list; + +import lombok.Getter; + +@Getter +public class FromCardInfoListDTO { + private CardInfoListDTO cardInfo; + + private UserInfoListDTO userInfo; +} diff --git a/nabimarket-domain/src/main/java/org/prgrms/nabimarketbe/chatroom/projection/list/ToCardInfoListDTO.java b/nabimarket-domain/src/main/java/org/prgrms/nabimarketbe/chatroom/projection/list/ToCardInfoListDTO.java new file mode 100644 index 00000000..3fde50b6 --- /dev/null +++ b/nabimarket-domain/src/main/java/org/prgrms/nabimarketbe/chatroom/projection/list/ToCardInfoListDTO.java @@ -0,0 +1,10 @@ +package org.prgrms.nabimarketbe.chatroom.projection.list; + +import lombok.Getter; + +@Getter +public class ToCardInfoListDTO { + private CardInfoListDTO cardInfo; + + private UserInfoListDTO userInfo; +} diff --git a/nabimarket-domain/src/main/java/org/prgrms/nabimarketbe/chatroom/projection/list/UserInfoListDTO.java b/nabimarket-domain/src/main/java/org/prgrms/nabimarketbe/chatroom/projection/list/UserInfoListDTO.java new file mode 100644 index 00000000..c9c6c726 --- /dev/null +++ b/nabimarket-domain/src/main/java/org/prgrms/nabimarketbe/chatroom/projection/list/UserInfoListDTO.java @@ -0,0 +1,8 @@ +package org.prgrms.nabimarketbe.chatroom.projection.list; + +import lombok.Getter; + +@Getter +public class UserInfoListDTO { + private Long userId; +} diff --git a/nabimarket-domain/src/main/java/org/prgrms/nabimarketbe/chatroom/projection/single/CardInfoDTO.java b/nabimarket-domain/src/main/java/org/prgrms/nabimarketbe/chatroom/projection/single/CardInfoDTO.java new file mode 100644 index 00000000..c6d465c6 --- /dev/null +++ b/nabimarket-domain/src/main/java/org/prgrms/nabimarketbe/chatroom/projection/single/CardInfoDTO.java @@ -0,0 +1,12 @@ +package org.prgrms.nabimarketbe.chatroom.projection.single; + +import lombok.Getter; + +@Getter +public class CardInfoDTO { + private Long cardId; + + private String itemName; + + private String thumbnail; +} diff --git a/nabimarket-domain/src/main/java/org/prgrms/nabimarketbe/chatroom/projection/single/ChatRoomInfoDTO.java b/nabimarket-domain/src/main/java/org/prgrms/nabimarketbe/chatroom/projection/single/ChatRoomInfoDTO.java new file mode 100644 index 00000000..0aafb0a0 --- /dev/null +++ b/nabimarket-domain/src/main/java/org/prgrms/nabimarketbe/chatroom/projection/single/ChatRoomInfoDTO.java @@ -0,0 +1,24 @@ +package org.prgrms.nabimarketbe.chatroom.projection.single; + +import lombok.Getter; + +@Getter +public class ChatRoomInfoDTO { + private String fireStoreChatRoomId; + + private FromCardInfoDTO fromCardInfo; + + private ToCardInfoDTO toCardInfo; + + private Long completeRequestId; + + public void setCompleteRequestId(Long completeRequestId) { + this.completeRequestId = completeRequestId; + } + + public void updateFireStoreChatRoomId() { + String fireStoreDocumentName = fireStoreChatRoomId.split("/")[2]; + + this.fireStoreChatRoomId = fireStoreDocumentName; + } +} diff --git a/nabimarket-domain/src/main/java/org/prgrms/nabimarketbe/chatroom/projection/single/ChatRoomInfoWrapper.java b/nabimarket-domain/src/main/java/org/prgrms/nabimarketbe/chatroom/projection/single/ChatRoomInfoWrapper.java new file mode 100644 index 00000000..0c05b45a --- /dev/null +++ b/nabimarket-domain/src/main/java/org/prgrms/nabimarketbe/chatroom/projection/single/ChatRoomInfoWrapper.java @@ -0,0 +1,8 @@ +package org.prgrms.nabimarketbe.chatroom.projection.single; + +import lombok.Getter; + +@Getter +public class ChatRoomInfoWrapper { + private ChatRoomInfoDTO chatRoomInfo; +} diff --git a/nabimarket-domain/src/main/java/org/prgrms/nabimarketbe/chatroom/projection/single/FromCardInfoDTO.java b/nabimarket-domain/src/main/java/org/prgrms/nabimarketbe/chatroom/projection/single/FromCardInfoDTO.java new file mode 100644 index 00000000..d431c51b --- /dev/null +++ b/nabimarket-domain/src/main/java/org/prgrms/nabimarketbe/chatroom/projection/single/FromCardInfoDTO.java @@ -0,0 +1,10 @@ +package org.prgrms.nabimarketbe.chatroom.projection.single; + +import lombok.Getter; + +@Getter +public class FromCardInfoDTO { + private CardInfoDTO cardInfo; + + private UserInfoDTO userInfo; +} diff --git a/nabimarket-domain/src/main/java/org/prgrms/nabimarketbe/chatroom/projection/single/ToCardInfoDTO.java b/nabimarket-domain/src/main/java/org/prgrms/nabimarketbe/chatroom/projection/single/ToCardInfoDTO.java new file mode 100644 index 00000000..edb2ae99 --- /dev/null +++ b/nabimarket-domain/src/main/java/org/prgrms/nabimarketbe/chatroom/projection/single/ToCardInfoDTO.java @@ -0,0 +1,10 @@ +package org.prgrms.nabimarketbe.chatroom.projection.single; + +import lombok.Getter; + +@Getter +public class ToCardInfoDTO { + private CardInfoDTO cardInfo; + + private UserInfoDTO userInfo; +} diff --git a/nabimarket-domain/src/main/java/org/prgrms/nabimarketbe/chatroom/projection/single/UserInfoDTO.java b/nabimarket-domain/src/main/java/org/prgrms/nabimarketbe/chatroom/projection/single/UserInfoDTO.java new file mode 100644 index 00000000..3bcf3fb0 --- /dev/null +++ b/nabimarket-domain/src/main/java/org/prgrms/nabimarketbe/chatroom/projection/single/UserInfoDTO.java @@ -0,0 +1,8 @@ +package org.prgrms.nabimarketbe.chatroom.projection.single; + +import lombok.Getter; + +@Getter +public class UserInfoDTO { + private Long userId; +} diff --git a/nabimarket-domain/src/main/java/org/prgrms/nabimarketbe/chatroom/repository/ChatRoomRepository.java b/nabimarket-domain/src/main/java/org/prgrms/nabimarketbe/chatroom/repository/ChatRoomRepository.java new file mode 100644 index 00000000..0d17522f --- /dev/null +++ b/nabimarket-domain/src/main/java/org/prgrms/nabimarketbe/chatroom/repository/ChatRoomRepository.java @@ -0,0 +1,9 @@ +package org.prgrms.nabimarketbe.chatroom.repository; + +import org.prgrms.nabimarketbe.chatroom.entity.ChatRoom; +import org.prgrms.nabimarketbe.suggestion.entity.Suggestion; +import org.springframework.data.jpa.repository.JpaRepository; + +public interface ChatRoomRepository extends JpaRepository, ChatRoomRepositoryCustom { + boolean existsChatRoomBySuggestion(Suggestion suggestion); +} diff --git a/nabimarket-domain/src/main/java/org/prgrms/nabimarketbe/chatroom/repository/ChatRoomRepositoryCustom.java b/nabimarket-domain/src/main/java/org/prgrms/nabimarketbe/chatroom/repository/ChatRoomRepositoryCustom.java new file mode 100644 index 00000000..d0ebfe69 --- /dev/null +++ b/nabimarket-domain/src/main/java/org/prgrms/nabimarketbe/chatroom/repository/ChatRoomRepositoryCustom.java @@ -0,0 +1,10 @@ +package org.prgrms.nabimarketbe.chatroom.repository; + +import org.prgrms.nabimarketbe.chatroom.projection.list.ChatRoomListWrapper; +import org.prgrms.nabimarketbe.chatroom.projection.single.ChatRoomInfoWrapper; + +public interface ChatRoomRepositoryCustom { + ChatRoomInfoWrapper getChatRoomInfoById(Long chatRoomId, Long completeRequestId); + + ChatRoomListWrapper getChatRoomList(Integer size, String cursorId, Long userId); +} diff --git a/nabimarket-domain/src/main/java/org/prgrms/nabimarketbe/chatroom/repository/ChatRoomRepositoryImpl.java b/nabimarket-domain/src/main/java/org/prgrms/nabimarketbe/chatroom/repository/ChatRoomRepositoryImpl.java new file mode 100644 index 00000000..00dc4580 --- /dev/null +++ b/nabimarket-domain/src/main/java/org/prgrms/nabimarketbe/chatroom/repository/ChatRoomRepositoryImpl.java @@ -0,0 +1,195 @@ +package org.prgrms.nabimarketbe.chatroom.repository; + +import java.util.List; + +import org.prgrms.nabimarketbe.chatroom.entity.QChatRoom; +import org.prgrms.nabimarketbe.chatroom.projection.list.CardInfoListDTO; +import org.prgrms.nabimarketbe.chatroom.projection.list.ChatRoomInfoListDTO; +import org.prgrms.nabimarketbe.chatroom.projection.list.ChatRoomListWrapper; +import org.prgrms.nabimarketbe.chatroom.projection.list.FromCardInfoListDTO; +import org.prgrms.nabimarketbe.chatroom.projection.list.ToCardInfoListDTO; +import org.prgrms.nabimarketbe.chatroom.projection.list.UserInfoListDTO; +import org.prgrms.nabimarketbe.chatroom.projection.single.CardInfoDTO; +import org.prgrms.nabimarketbe.chatroom.projection.single.ChatRoomInfoDTO; +import org.prgrms.nabimarketbe.chatroom.projection.single.ChatRoomInfoWrapper; +import org.prgrms.nabimarketbe.chatroom.projection.single.FromCardInfoDTO; +import org.prgrms.nabimarketbe.chatroom.projection.single.ToCardInfoDTO; +import org.prgrms.nabimarketbe.chatroom.projection.single.UserInfoDTO; +import org.prgrms.nabimarketbe.suggestion.entity.QSuggestion; +import org.prgrms.nabimarketbe.util.CursorPaging; +import org.prgrms.nabimarketbe.util.QueryDslUtil; +import org.springframework.data.domain.Sort; + +import com.querydsl.core.types.ConstantImpl; +import com.querydsl.core.types.Projections; +import com.querydsl.core.types.dsl.BooleanExpression; +import com.querydsl.core.types.dsl.Expressions; +import com.querydsl.core.types.dsl.StringExpression; +import com.querydsl.core.types.dsl.StringExpressions; +import com.querydsl.core.types.dsl.StringTemplate; +import com.querydsl.jpa.impl.JPAQueryFactory; + +import lombok.RequiredArgsConstructor; + +@RequiredArgsConstructor +public class ChatRoomRepositoryImpl implements ChatRoomRepositoryCustom, CursorPaging { + private final JPAQueryFactory jpaQueryFactory; + + @Override + public ChatRoomInfoWrapper getChatRoomInfoById( + Long chatRoomId, + Long completeRequestId + ) { + ChatRoomInfoWrapper chatRoomInfo = jpaQueryFactory + .select( + Projections.fields( + ChatRoomInfoWrapper.class, + Projections.fields( + ChatRoomInfoDTO.class, + QChatRoom.chatRoom.fireStoreChatRoomPath.as("fireStoreChatRoomId"), + Projections.fields( + FromCardInfoDTO.class, + Projections.fields( + CardInfoDTO.class, + QSuggestion.suggestion.fromCard.cardId, + QSuggestion.suggestion.fromCard.item.itemName, + QSuggestion.suggestion.fromCard.thumbnail + ).as("cardInfo"), + Projections.fields( + UserInfoDTO.class, + QSuggestion.suggestion.fromCard.user.userId + ).as("userInfo") + ).as("fromCardInfo"), + Projections.fields( + ToCardInfoDTO.class, + Projections.fields( + CardInfoDTO.class, + QSuggestion.suggestion.toCard.cardId, + QSuggestion.suggestion.toCard.item.itemName, + QSuggestion.suggestion.toCard.thumbnail + ).as("cardInfo"), + Projections.fields( + UserInfoDTO.class, + QSuggestion.suggestion.toCard.user.userId + ).as("userInfo") + ).as("toCardInfo") + ).as("chatRoomInfo") + ) + ) + .from(QChatRoom.chatRoom) + .join(QSuggestion.suggestion) + .on(QChatRoom.chatRoom.suggestion.suggestionId.eq(QSuggestion.suggestion.suggestionId)) + .where(QChatRoom.chatRoom.chatRoomId.eq(chatRoomId)) + .fetchOne(); + + chatRoomInfo.getChatRoomInfo().updateFireStoreChatRoomId(); + chatRoomInfo.getChatRoomInfo().setCompleteRequestId(completeRequestId); + + return chatRoomInfo; + } + + @Override + public ChatRoomListWrapper getChatRoomList( + Integer size, + String cursorId, + Long userId + ) { + List chatRoomList = jpaQueryFactory + .select( + Projections.fields( + ChatRoomInfoListDTO.class, + QChatRoom.chatRoom.chatRoomId, + QChatRoom.chatRoom.createdDate.as("createdAt"), + Projections.fields( + FromCardInfoListDTO.class, + Projections.fields( + CardInfoListDTO.class, + QSuggestion.suggestion.fromCard.cardId, + QSuggestion.suggestion.fromCard.item.itemName, + QSuggestion.suggestion.fromCard.item.priceRange, + QSuggestion.suggestion.fromCard.thumbnail + ).as("cardInfo"), + Projections.fields( + UserInfoListDTO.class, + QSuggestion.suggestion.fromCard.user.userId + ).as("userInfo") + ).as("fromCardInfo"), + Projections.fields( + ToCardInfoListDTO.class, + Projections.fields( + CardInfoListDTO.class, + QSuggestion.suggestion.toCard.cardId, + QSuggestion.suggestion.toCard.item.itemName, + QSuggestion.suggestion.toCard.item.priceRange, + QSuggestion.suggestion.toCard.thumbnail + ).as("cardInfo"), + Projections.fields( + UserInfoListDTO.class, + QSuggestion.suggestion.toCard.user.userId + ).as("userInfo") + ).as("toCardInfo") + ) + ) + .from(QChatRoom.chatRoom) + .join(QSuggestion.suggestion) + .on(QChatRoom.chatRoom.suggestion.suggestionId.eq(QSuggestion.suggestion.suggestionId)) + .where( + cursorId(cursorId), + owner(userId) + ) + .orderBy( + QueryDslUtil.getOrderSpecifier( + Sort.by( + Sort.Order.desc("createdDate"), + Sort.Order.desc("chatRoomId") + ), + QChatRoom.chatRoom + ) + ) + .limit(size) + .fetch(); + + String nextCursor = + chatRoomList.size() < size ? null : generateCursor(chatRoomList.get(chatRoomList.size() - 1)); + + ChatRoomListWrapper chatRoomListWrapper = new ChatRoomListWrapper(chatRoomList, nextCursor); + + return chatRoomListWrapper; + } + + @Override + public BooleanExpression cursorId(String cursorId) { + if (cursorId == null) { + return null; + } + + // 생성일자 + StringTemplate dateCursorTemplate = Expressions.stringTemplate( + "DATE_FORMAT({0}, {1})", + QChatRoom.chatRoom.createdDate, + ConstantImpl.create("%Y%m%d%H%i%s") + ); + + // pk + StringExpression pkCursorTemplate = StringExpressions.lpad( + QChatRoom.chatRoom.chatRoomId.stringValue(), + 8, + '0' + ); + + return dateCursorTemplate.concat(pkCursorTemplate).lt(cursorId); + } + + private String generateCursor(ChatRoomInfoListDTO chatRoomInfoListDTO) { + return chatRoomInfoListDTO.getCreatedAt().toString() // 디폴트는 생성일자 최신순 정렬 + .replace("T", "") + .replace("-", "") + .replace(":", "") + + String.format("%08d", chatRoomInfoListDTO.getChatRoomId()); + } + + private BooleanExpression owner(Long userId) { + return QSuggestion.suggestion.fromCard.user.userId.eq(userId) + .or(QSuggestion.suggestion.toCard.user.userId.eq(userId)); + } +} diff --git a/nabimarket-domain/src/main/java/org/prgrms/nabimarketbe/completeRequest/entity/CompleteRequest.java b/nabimarket-domain/src/main/java/org/prgrms/nabimarketbe/completeRequest/entity/CompleteRequest.java new file mode 100644 index 00000000..4dccf127 --- /dev/null +++ b/nabimarket-domain/src/main/java/org/prgrms/nabimarketbe/completeRequest/entity/CompleteRequest.java @@ -0,0 +1,98 @@ +package org.prgrms.nabimarketbe.completeRequest.entity; + +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.EnumType; +import javax.persistence.Enumerated; +import javax.persistence.FetchType; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; +import javax.persistence.Id; +import javax.persistence.JoinColumn; +import javax.persistence.OneToOne; +import javax.persistence.Table; +import javax.persistence.UniqueConstraint; + +import org.prgrms.nabimarketbe.BaseEntity; +import org.prgrms.nabimarketbe.card.entity.Card; +import org.prgrms.nabimarketbe.error.BaseException; +import org.prgrms.nabimarketbe.error.ErrorCode; + +import lombok.AccessLevel; +import lombok.Getter; +import lombok.NoArgsConstructor; + +@Entity +@Getter +@Table(name = "complete_requests", + uniqueConstraints = { + @UniqueConstraint( + name = "complete_request_unique", + columnNames = {"from_card", "to_card"} + ) + }) +@NoArgsConstructor(access = AccessLevel.PROTECTED) +public class CompleteRequest extends BaseEntity { + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + @Column(name = "complete_request_id", nullable = false) + private Long completeRequestId; + + @OneToOne(fetch = FetchType.LAZY) + @JoinColumn(name = "from_card", nullable = false) + private Card fromCard; + + @OneToOne(fetch = FetchType.LAZY) + @JoinColumn(name = "to_card", nullable = false) + private Card toCard; + + @Enumerated(EnumType.STRING) + private CompleteRequestStatus completeRequestStatus; + + public CompleteRequest( + Card fromCard, + Card toCard + ) { + if (fromCard == null || toCard == null) { + throw new BaseException(ErrorCode.INVALID_REQUEST); + } + + this.fromCard = fromCard; + this.toCard = toCard; + this.completeRequestStatus = CompleteRequestStatus.WAITING; + } + + public String createCompleteRequestMessage() { + String message = String.format( + "%s님이 %s과의 거래성사를 요청했습니다.", + fromCard.getUser().getNickname(), + toCard.getItem().getItemName() + ); + + return message; + } + + public String createCompleteRequestDecisionMessage(boolean isAccepted) { + String result = isAccepted ? "성사되었습니다" : "성사되지 못했습니다."; + String message = String.format( + "%s과 %s의 거래가 %s", + this.toCard.getItem().getItemName(), + this.fromCard.getItem().getItemName(), + result + ); + + return message; + } + + public void acceptCompleteRequest() { + this.completeRequestStatus = CompleteRequestStatus.ACCEPTED; + } + + public void refuseCompleteRequest() { + this.completeRequestStatus = CompleteRequestStatus.REFUSED; + } + + public void deleteCompleteRequest() { + this.completeRequestStatus = CompleteRequestStatus.DELETED; + } +} diff --git a/nabimarket-domain/src/main/java/org/prgrms/nabimarketbe/completeRequest/entity/CompleteRequestStatus.java b/nabimarket-domain/src/main/java/org/prgrms/nabimarketbe/completeRequest/entity/CompleteRequestStatus.java new file mode 100644 index 00000000..302c68d8 --- /dev/null +++ b/nabimarket-domain/src/main/java/org/prgrms/nabimarketbe/completeRequest/entity/CompleteRequestStatus.java @@ -0,0 +1,8 @@ +package org.prgrms.nabimarketbe.completeRequest.entity; + +public enum CompleteRequestStatus { + WAITING, + ACCEPTED, + REFUSED, + DELETED +} diff --git a/nabimarket-domain/src/main/java/org/prgrms/nabimarketbe/completeRequest/projection/HistoryListReadResponseDTO.java b/nabimarket-domain/src/main/java/org/prgrms/nabimarketbe/completeRequest/projection/HistoryListReadResponseDTO.java new file mode 100644 index 00000000..2204c097 --- /dev/null +++ b/nabimarket-domain/src/main/java/org/prgrms/nabimarketbe/completeRequest/projection/HistoryListReadResponseDTO.java @@ -0,0 +1,20 @@ +package org.prgrms.nabimarketbe.completeRequest.projection; + +import java.time.LocalDateTime; + +import org.prgrms.nabimarketbe.card.projection.CardSummaryResponseDTO; + +import lombok.Getter; + +@Getter +public class HistoryListReadResponseDTO { + private Long historyId; + + private CardSummaryResponseDTO fromCard; + + private CardSummaryResponseDTO toCard; + + private LocalDateTime createdAt; + + private LocalDateTime modifiedAt; +} diff --git a/nabimarket-domain/src/main/java/org/prgrms/nabimarketbe/completeRequest/repository/CompleteRequestRepository.java b/nabimarket-domain/src/main/java/org/prgrms/nabimarketbe/completeRequest/repository/CompleteRequestRepository.java new file mode 100644 index 00000000..f5577706 --- /dev/null +++ b/nabimarket-domain/src/main/java/org/prgrms/nabimarketbe/completeRequest/repository/CompleteRequestRepository.java @@ -0,0 +1,50 @@ +package org.prgrms.nabimarketbe.completeRequest.repository; + +import java.util.Optional; + +import org.prgrms.nabimarketbe.card.entity.Card; +import org.prgrms.nabimarketbe.completeRequest.entity.CompleteRequest; +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.jpa.repository.Query; +import org.springframework.data.repository.query.Param; + +public interface CompleteRequestRepository extends JpaRepository, + CompleteRequestRepositryCustom { + @Query("select c " + + "from CompleteRequest c " + + "where c.fromCard = :fromCard and c.toCard = :toCard and c.completeRequestStatus != 'REFUSED' " + + "and c.fromCard = :fromCard and c.toCard = :toCard and c.completeRequestStatus != 'DELETED' " + + "or c.fromCard = :toCard and c.toCard = :fromCard and c.completeRequestStatus != 'REFUSED'" + + "and c.fromCard = :toCard and c.toCard = :fromCard and c.completeRequestStatus != 'DELETED'") + Optional findCompleteRequestByFromCardAndToCard( + @Param("fromCard") Card fromCard, + @Param("toCard") Card toCard + ); + + @Query( + "select count(c.completeRequestId) > 0 " + + "from CompleteRequest c " + + "where c.fromCard = :fromCard and c.toCard = :toCard and c.completeRequestStatus != 'REFUSED' " + + "and c.fromCard = :fromCard and c.toCard = :toCard and c.completeRequestStatus != 'DELETED' " + + "or c.fromCard = :toCard and c.toCard = :fromCard and c.completeRequestStatus != 'REFUSED' " + + "and c.fromCard = :toCard and c.toCard = :fromCard and c.completeRequestStatus != 'DELETED'") + Boolean exists(@Param("fromCard") Card fromCard, @Param("toCard") Card toCard); + + @Query( + "select count(c.completeRequestId) > 0 " + + "from CompleteRequest c " + + "where c.fromCard = :fromCard and c.completeRequestStatus != 'REFUSED' " + + "and c.fromCard = :fromCard and c.completeRequestStatus != 'DELETED' " + + "or c.toCard = :fromCard and c.completeRequestStatus != 'REFUSED' " + + "and c.toCard = :fromCard and c.completeRequestStatus != 'DELETED'") + Boolean existsByFromCard(@Param("fromCard") Card fromCard); + + @Query( + "select count(c.completeRequestId) > 0 " + + "from CompleteRequest c " + + "where c.toCard = :toCard and c.completeRequestStatus != 'REFUSED' " + + "and c.toCard = :toCard and c.completeRequestStatus != 'DELETED' " + + "or c.fromCard = :toCard and c.completeRequestStatus != 'REFUSED'" + + "and c.fromCard = :toCard and c.completeRequestStatus != 'DELETED'") + Boolean existsByToCard(@Param("toCard") Card toCard); +} diff --git a/nabimarket-domain/src/main/java/org/prgrms/nabimarketbe/completeRequest/repository/CompleteRequestRepositoryImpl.java b/nabimarket-domain/src/main/java/org/prgrms/nabimarketbe/completeRequest/repository/CompleteRequestRepositoryImpl.java new file mode 100644 index 00000000..fc6c4703 --- /dev/null +++ b/nabimarket-domain/src/main/java/org/prgrms/nabimarketbe/completeRequest/repository/CompleteRequestRepositoryImpl.java @@ -0,0 +1,169 @@ +package org.prgrms.nabimarketbe.completeRequest.repository; + +import java.util.List; + +import org.prgrms.nabimarketbe.card.entity.QCard; +import org.prgrms.nabimarketbe.card.projection.CardSummaryResponseDTO; +import org.prgrms.nabimarketbe.completeRequest.entity.CompleteRequestStatus; +import org.prgrms.nabimarketbe.completeRequest.entity.QCompleteRequest; +import org.prgrms.nabimarketbe.completeRequest.projection.HistoryListReadResponseDTO; +import org.prgrms.nabimarketbe.completeRequest.wrapper.HistoryListReadLimitResponseDTO; +import org.prgrms.nabimarketbe.completeRequest.wrapper.HistoryListReadPagingResponseDTO; +import org.prgrms.nabimarketbe.user.entity.User; +import org.prgrms.nabimarketbe.util.QueryDslUtil; +import org.springframework.data.domain.Sort; + +import com.querydsl.core.types.ConstantImpl; +import com.querydsl.core.types.Projections; +import com.querydsl.core.types.dsl.BooleanExpression; +import com.querydsl.core.types.dsl.Expressions; +import com.querydsl.core.types.dsl.StringExpressions; +import com.querydsl.core.types.dsl.StringTemplate; +import com.querydsl.jpa.impl.JPAQueryFactory; + +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; + +@Slf4j +@RequiredArgsConstructor +public class CompleteRequestRepositoryImpl implements CompleteRequestRepositryCustom { + private final JPAQueryFactory jpaQueryFactory; + + @Override + public HistoryListReadLimitResponseDTO getHistoryBySize(Integer size) { + List historyList = jpaQueryFactory + .select( + Projections.fields( + HistoryListReadResponseDTO.class, + QCompleteRequest.completeRequest.completeRequestId, + Projections.fields( + CardSummaryResponseDTO.class, + QCompleteRequest.completeRequest.fromCard.cardId, + QCompleteRequest.completeRequest.fromCard.item.itemName, + QCompleteRequest.completeRequest.fromCard.thumbnail, + QCompleteRequest.completeRequest.fromCard.item.priceRange + ).as("fromCard"), + Projections.fields( + CardSummaryResponseDTO.class, + QCompleteRequest.completeRequest.toCard.cardId, + QCompleteRequest.completeRequest.toCard.item.itemName, + QCompleteRequest.completeRequest.toCard.thumbnail, + QCompleteRequest.completeRequest.toCard.item.priceRange + ).as("toCard"), + QCompleteRequest.completeRequest.createdDate.as("createdAt"), + QCompleteRequest.completeRequest.modifiedDate.as("modifiedAt") + ) + ) + .from(QCompleteRequest.completeRequest) + .leftJoin(QCard.card) + .on(QCard.card.cardId.eq(QCompleteRequest.completeRequest.fromCard.cardId)) + .leftJoin(QCard.card) + .on(QCard.card.cardId.eq(QCompleteRequest.completeRequest.toCard.cardId).as("toCardAlias")) + .where(QCompleteRequest.completeRequest.completeRequestStatus.eq(CompleteRequestStatus.ACCEPTED)) + .orderBy( + QueryDslUtil.getOrderSpecifier( + Sort.by( + Sort.Order.desc("modifiedDate"), + Sort.Order.desc("completeRequestId") + ), + QCompleteRequest.completeRequest + ) + ) + .limit(size) + .fetch(); + + return new HistoryListReadLimitResponseDTO(historyList); + } + + @Override + public HistoryListReadPagingResponseDTO getHistoryByUser( + User user, + String cursorId, + Integer size + ) { + List historyList = jpaQueryFactory + .select( + Projections.fields( + HistoryListReadResponseDTO.class, + QCompleteRequest.completeRequest.completeRequestId, + Projections.fields( + CardSummaryResponseDTO.class, + QCompleteRequest.completeRequest.fromCard.cardId, + QCompleteRequest.completeRequest.fromCard.item.itemName, + QCompleteRequest.completeRequest.fromCard.thumbnail, + QCompleteRequest.completeRequest.fromCard.item.priceRange + ).as("fromCard"), + Projections.fields( + CardSummaryResponseDTO.class, + QCompleteRequest.completeRequest.toCard.cardId, + QCompleteRequest.completeRequest.toCard.item.itemName, + QCompleteRequest.completeRequest.toCard.thumbnail, + QCompleteRequest.completeRequest.toCard.item.priceRange + ).as("toCard"), + QCompleteRequest.completeRequest.createdDate.as("createdAt"), + QCompleteRequest.completeRequest.modifiedDate.as("modifiedAt") + ) + ) + .from(QCompleteRequest.completeRequest) + .leftJoin(QCard.card) + .on(QCard.card.cardId.eq(QCompleteRequest.completeRequest.fromCard.cardId)) + .leftJoin(QCard.card) + .on(QCard.card.cardId.eq(QCompleteRequest.completeRequest.toCard.cardId).as("toCardAlias")) + .where(cursorIdLessThan(cursorId), + QCompleteRequest.completeRequest.completeRequestStatus.eq(CompleteRequestStatus.ACCEPTED), + QCompleteRequest.completeRequest.fromCard.user.eq(user) + .or(QCompleteRequest.completeRequest.toCard.user.eq(user))) + .orderBy( + QueryDslUtil.getOrderSpecifier( + Sort.by( + Sort.Order.desc("modifiedDate"), + Sort.Order.desc("completeRequestId") + ), + QCompleteRequest.completeRequest + ) + ) + .limit(size) + .fetch(); + + String nextCursor = historyList.size() < size + ? null : createCursorId(historyList.get(historyList.size() - 1)); + + return new HistoryListReadPagingResponseDTO(historyList, nextCursor); + } + + /** + * 커스텀 커서 id가 주어진 cursorId보다 작은지 확인 + */ + private BooleanExpression cursorIdLessThan(String cursorId) { + if (cursorId == null) { + return null; + } + + StringTemplate stringTemplate = Expressions.stringTemplate( + "DATE_FORMAT({0}, {1})", + QCompleteRequest.completeRequest.createdDate, + ConstantImpl.create("%Y%m%d%H%i%s") + ); + + return stringTemplate.concat(StringExpressions.lpad( + QCompleteRequest.completeRequest.completeRequestId.stringValue(), + 8, + '0' + )).lt(cursorId); + } + + /** + * 커서 id 생성 + */ + private String createCursorId(HistoryListReadResponseDTO historyListReadResponseDTO) { + return historyListReadResponseDTO.getCreatedAt().toString() + .replace("T", "") + .replace("-", "") + .replace(":", "") + + String.format( + "%08d", + historyListReadResponseDTO.getFromCard().getCardId() + + historyListReadResponseDTO.getToCard().getCardId() + ); + } +} diff --git a/nabimarket-domain/src/main/java/org/prgrms/nabimarketbe/completeRequest/repository/CompleteRequestRepositryCustom.java b/nabimarket-domain/src/main/java/org/prgrms/nabimarketbe/completeRequest/repository/CompleteRequestRepositryCustom.java new file mode 100644 index 00000000..72b3c114 --- /dev/null +++ b/nabimarket-domain/src/main/java/org/prgrms/nabimarketbe/completeRequest/repository/CompleteRequestRepositryCustom.java @@ -0,0 +1,11 @@ +package org.prgrms.nabimarketbe.completeRequest.repository; + +import org.prgrms.nabimarketbe.completeRequest.wrapper.HistoryListReadLimitResponseDTO; +import org.prgrms.nabimarketbe.completeRequest.wrapper.HistoryListReadPagingResponseDTO; +import org.prgrms.nabimarketbe.user.entity.User; + +public interface CompleteRequestRepositryCustom { + HistoryListReadLimitResponseDTO getHistoryBySize(Integer size); + + HistoryListReadPagingResponseDTO getHistoryByUser(User user, String cursorId, Integer size); +} diff --git a/nabimarket-domain/src/main/java/org/prgrms/nabimarketbe/completeRequest/wrapper/CompleteRequestInfoDTO.java b/nabimarket-domain/src/main/java/org/prgrms/nabimarketbe/completeRequest/wrapper/CompleteRequestInfoDTO.java new file mode 100644 index 00000000..b244f4d4 --- /dev/null +++ b/nabimarket-domain/src/main/java/org/prgrms/nabimarketbe/completeRequest/wrapper/CompleteRequestInfoDTO.java @@ -0,0 +1,4 @@ +package org.prgrms.nabimarketbe.completeRequest.wrapper; + +public record CompleteRequestInfoDTO(CompleteRequestSummaryDTO completeRequestInfo) { +} diff --git a/nabimarket-domain/src/main/java/org/prgrms/nabimarketbe/completeRequest/wrapper/CompleteRequestSummaryDTO.java b/nabimarket-domain/src/main/java/org/prgrms/nabimarketbe/completeRequest/wrapper/CompleteRequestSummaryDTO.java new file mode 100644 index 00000000..ea79cefc --- /dev/null +++ b/nabimarket-domain/src/main/java/org/prgrms/nabimarketbe/completeRequest/wrapper/CompleteRequestSummaryDTO.java @@ -0,0 +1,14 @@ +package org.prgrms.nabimarketbe.completeRequest.wrapper; + +import org.prgrms.nabimarketbe.card.projection.CardUserSummaryResponseDTO; +import org.prgrms.nabimarketbe.completeRequest.entity.CompleteRequestStatus; + +import lombok.Builder; + +@Builder +public record CompleteRequestSummaryDTO( + CardUserSummaryResponseDTO fromCard, + CardUserSummaryResponseDTO toCard, + CompleteRequestStatus status +) { +} diff --git a/nabimarket-domain/src/main/java/org/prgrms/nabimarketbe/completeRequest/wrapper/HistoryListReadLimitResponseDTO.java b/nabimarket-domain/src/main/java/org/prgrms/nabimarketbe/completeRequest/wrapper/HistoryListReadLimitResponseDTO.java new file mode 100644 index 00000000..298a60f9 --- /dev/null +++ b/nabimarket-domain/src/main/java/org/prgrms/nabimarketbe/completeRequest/wrapper/HistoryListReadLimitResponseDTO.java @@ -0,0 +1,10 @@ +package org.prgrms.nabimarketbe.completeRequest.wrapper; + +import java.util.List; + +import org.prgrms.nabimarketbe.completeRequest.projection.HistoryListReadResponseDTO; + +public record HistoryListReadLimitResponseDTO( + List historyList +) { +} diff --git a/nabimarket-domain/src/main/java/org/prgrms/nabimarketbe/completeRequest/wrapper/HistoryListReadPagingResponseDTO.java b/nabimarket-domain/src/main/java/org/prgrms/nabimarketbe/completeRequest/wrapper/HistoryListReadPagingResponseDTO.java new file mode 100644 index 00000000..50c46230 --- /dev/null +++ b/nabimarket-domain/src/main/java/org/prgrms/nabimarketbe/completeRequest/wrapper/HistoryListReadPagingResponseDTO.java @@ -0,0 +1,11 @@ +package org.prgrms.nabimarketbe.completeRequest.wrapper; + +import java.util.List; + +import org.prgrms.nabimarketbe.completeRequest.projection.HistoryListReadResponseDTO; + +public record HistoryListReadPagingResponseDTO( + List historyList, + String nextCursorId +) { +} diff --git a/nabimarket-domain/src/main/java/org/prgrms/nabimarketbe/config/QuerydslConfig.java b/nabimarket-domain/src/main/java/org/prgrms/nabimarketbe/config/QuerydslConfig.java new file mode 100644 index 00000000..0c610a14 --- /dev/null +++ b/nabimarket-domain/src/main/java/org/prgrms/nabimarketbe/config/QuerydslConfig.java @@ -0,0 +1,20 @@ +package org.prgrms.nabimarketbe.config; + +import javax.persistence.EntityManager; +import javax.persistence.PersistenceContext; + +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; + +import com.querydsl.jpa.impl.JPAQueryFactory; + +@Configuration +public class QuerydslConfig { + @PersistenceContext + private EntityManager entityManager; + + @Bean + public JPAQueryFactory jpaQueryFactory() { + return new JPAQueryFactory(entityManager); + } +} diff --git a/nabimarket-domain/src/main/java/org/prgrms/nabimarketbe/dibs/entity/Dib.java b/nabimarket-domain/src/main/java/org/prgrms/nabimarketbe/dibs/entity/Dib.java new file mode 100644 index 00000000..62aaa5e4 --- /dev/null +++ b/nabimarket-domain/src/main/java/org/prgrms/nabimarketbe/dibs/entity/Dib.java @@ -0,0 +1,52 @@ +package org.prgrms.nabimarketbe.dibs.entity; + +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.FetchType; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; +import javax.persistence.Id; +import javax.persistence.JoinColumn; +import javax.persistence.ManyToOne; +import javax.persistence.Table; + +import org.prgrms.nabimarketbe.BaseEntity; +import org.prgrms.nabimarketbe.card.entity.Card; +import org.prgrms.nabimarketbe.error.BaseException; +import org.prgrms.nabimarketbe.error.ErrorCode; +import org.prgrms.nabimarketbe.user.entity.User; + +import lombok.AccessLevel; +import lombok.Getter; +import lombok.NoArgsConstructor; + +@Getter +@Entity +@Table(name = "dibs") +@NoArgsConstructor(access = AccessLevel.PROTECTED) +public class Dib extends BaseEntity { + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + @Column(name = "dib_id", nullable = false) + private Long dibId; + + @ManyToOne(fetch = FetchType.LAZY) + @JoinColumn(name = "user_id", nullable = false) + private User user; + + @ManyToOne(fetch = FetchType.LAZY) + @JoinColumn(name = "card_id", nullable = false) + private Card card; + + public Dib( + User user, + Card card + ) { + if (user == null || card == null) { + throw new BaseException(ErrorCode.INVALID_REQUEST); + } + + this.user = user; + this.card = card; + } +} diff --git a/nabimarket-domain/src/main/java/org/prgrms/nabimarketbe/dibs/projection/DibListReadResponseDTO.java b/nabimarket-domain/src/main/java/org/prgrms/nabimarketbe/dibs/projection/DibListReadResponseDTO.java new file mode 100644 index 00000000..0e1940ef --- /dev/null +++ b/nabimarket-domain/src/main/java/org/prgrms/nabimarketbe/dibs/projection/DibListReadResponseDTO.java @@ -0,0 +1,29 @@ +package org.prgrms.nabimarketbe.dibs.projection; + +import java.time.LocalDateTime; + +import org.prgrms.nabimarketbe.card.entity.CardStatus; +import org.prgrms.nabimarketbe.item.entity.PriceRange; + +import lombok.Getter; + +@Getter +public class DibListReadResponseDTO { + private Long dibId; + + private Long cardId; + + private String cardTitle; + + private String itemName; + + private PriceRange priceRange; + + private String thumbnail; + + private CardStatus status; + + private LocalDateTime createdAt; + + private LocalDateTime modifiedAt; +} diff --git a/nabimarket-domain/src/main/java/org/prgrms/nabimarketbe/dibs/repository/DibRepository.java b/nabimarket-domain/src/main/java/org/prgrms/nabimarketbe/dibs/repository/DibRepository.java new file mode 100644 index 00000000..aac6a399 --- /dev/null +++ b/nabimarket-domain/src/main/java/org/prgrms/nabimarketbe/dibs/repository/DibRepository.java @@ -0,0 +1,14 @@ +package org.prgrms.nabimarketbe.dibs.repository; + +import java.util.Optional; + +import org.prgrms.nabimarketbe.card.entity.Card; +import org.prgrms.nabimarketbe.dibs.entity.Dib; +import org.prgrms.nabimarketbe.user.entity.User; +import org.springframework.data.jpa.repository.JpaRepository; + +public interface DibRepository extends JpaRepository, DibRepositoryCustom { + Optional findDibByUserAndCard(User user, Card card); + + boolean existsDibByCardAndUser(Card card, User user); +} diff --git a/nabimarket-domain/src/main/java/org/prgrms/nabimarketbe/dibs/repository/DibRepositoryCustom.java b/nabimarket-domain/src/main/java/org/prgrms/nabimarketbe/dibs/repository/DibRepositoryCustom.java new file mode 100644 index 00000000..eb7c3900 --- /dev/null +++ b/nabimarket-domain/src/main/java/org/prgrms/nabimarketbe/dibs/repository/DibRepositoryCustom.java @@ -0,0 +1,11 @@ +package org.prgrms.nabimarketbe.dibs.repository; + +import org.prgrms.nabimarketbe.dibs.wrapper.DibListReadPagingResponseDTO; + +public interface DibRepositoryCustom { + DibListReadPagingResponseDTO getUserDibsByDibId( + Long userId, + Long cursorId, + Integer size + ); +} diff --git a/nabimarket-domain/src/main/java/org/prgrms/nabimarketbe/dibs/repository/DibRepositoryImpl.java b/nabimarket-domain/src/main/java/org/prgrms/nabimarketbe/dibs/repository/DibRepositoryImpl.java new file mode 100644 index 00000000..f4ae69b3 --- /dev/null +++ b/nabimarket-domain/src/main/java/org/prgrms/nabimarketbe/dibs/repository/DibRepositoryImpl.java @@ -0,0 +1,80 @@ +package org.prgrms.nabimarketbe.dibs.repository; + +import java.util.List; + +import org.prgrms.nabimarketbe.card.entity.QCard; +import org.prgrms.nabimarketbe.dibs.entity.QDib; +import org.prgrms.nabimarketbe.dibs.projection.DibListReadResponseDTO; +import org.prgrms.nabimarketbe.dibs.wrapper.DibListReadPagingResponseDTO; + +import com.querydsl.core.types.Projections; +import com.querydsl.core.types.dsl.BooleanExpression; +import com.querydsl.jpa.impl.JPAQueryFactory; + +import lombok.RequiredArgsConstructor; + +@RequiredArgsConstructor +public class DibRepositoryImpl implements DibRepositoryCustom { + private final JPAQueryFactory jpaQueryFactory; + + @Override + public DibListReadPagingResponseDTO getUserDibsByDibId( + Long userId, + Long cursorId, + Integer size + ) { + List dibList = jpaQueryFactory.select( + Projections.fields( + DibListReadResponseDTO.class, + QDib.dib.dibId, + QCard.card.cardId, + QCard.card.cardTitle, + QCard.card.item.itemName, + QCard.card.item.priceRange, + QCard.card.thumbnail, + QCard.card.status, + QCard.card.createdDate.as("createdAt"), + QCard.card.modifiedDate.as("modifiedAt") + ) + ) + .from(QDib.dib) + .join(QCard.card).on(QCard.card.cardId.eq(QDib.dib.card.cardId)) + .where( + dibUserIdEquals(userId), + greaterThan(cursorId) + ) + .limit(size) + .fetch(); + + Long nextCursorId = generateCursor(dibList, size); + + return DibListReadPagingResponseDTO.of(dibList, nextCursorId); + } + + private Long generateCursor( + List dibList, + Integer size + ) { + if (dibList.size() == size) { + return dibList.get(dibList.size() - 1).getDibId(); + } + + return null; + } + + private BooleanExpression dibUserIdEquals(Long userId) { + if (userId == null) { + return null; + } + + return QDib.dib.user.userId.eq(userId); + } + + private BooleanExpression greaterThan(Long cursorId) { + if (cursorId == null) { + return null; + } + + return QDib.dib.dibId.gt(cursorId); + } +} diff --git a/nabimarket-domain/src/main/java/org/prgrms/nabimarketbe/dibs/wrapper/DibListReadPagingResponseDTO.java b/nabimarket-domain/src/main/java/org/prgrms/nabimarketbe/dibs/wrapper/DibListReadPagingResponseDTO.java new file mode 100644 index 00000000..0f9ffb0b --- /dev/null +++ b/nabimarket-domain/src/main/java/org/prgrms/nabimarketbe/dibs/wrapper/DibListReadPagingResponseDTO.java @@ -0,0 +1,17 @@ +package org.prgrms.nabimarketbe.dibs.wrapper; + +import java.util.List; + +import org.prgrms.nabimarketbe.dibs.projection.DibListReadResponseDTO; + +public record DibListReadPagingResponseDTO( + List dibList, + Long nextCursorId +) { + public static DibListReadPagingResponseDTO of( + List dibList, + Long nextCursorId + ) { + return new DibListReadPagingResponseDTO(dibList, nextCursorId); + } +} diff --git a/nabimarket-domain/src/main/java/org/prgrms/nabimarketbe/item/entity/Item.java b/nabimarket-domain/src/main/java/org/prgrms/nabimarketbe/item/entity/Item.java new file mode 100644 index 00000000..a3d55fa6 --- /dev/null +++ b/nabimarket-domain/src/main/java/org/prgrms/nabimarketbe/item/entity/Item.java @@ -0,0 +1,74 @@ +package org.prgrms.nabimarketbe.item.entity; + +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.EnumType; +import javax.persistence.Enumerated; +import javax.persistence.FetchType; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; +import javax.persistence.Id; +import javax.persistence.JoinColumn; +import javax.persistence.OneToOne; +import javax.persistence.Table; + +import org.prgrms.nabimarketbe.BaseEntity; +import org.prgrms.nabimarketbe.category.entity.Category; +import org.prgrms.nabimarketbe.error.BaseException; +import org.prgrms.nabimarketbe.error.ErrorCode; + +import lombok.AccessLevel; +import lombok.Builder; +import lombok.Getter; +import lombok.NoArgsConstructor; + +@Entity +@Table(name = "items") +@NoArgsConstructor(access = AccessLevel.PROTECTED) +@Getter +public class Item extends BaseEntity { + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + @Column(name = "item_id", nullable = false) + private Long itemId; + + @Column(name = "item_name", nullable = false) + private String itemName; + + @Enumerated(EnumType.STRING) + @Column(name = "price_range", nullable = false) + private PriceRange priceRange; + + @OneToOne(fetch = FetchType.LAZY) + @JoinColumn(name = "category_id") + private Category category; + + @Builder + private Item( + String itemName, + PriceRange priceRange, + Category category + ) { + if (itemName.isBlank()) { + throw new BaseException(ErrorCode.UNKNOWN); + } + + if (priceRange == null || category == null) { + throw new BaseException(ErrorCode.UNKNOWN); + } + + this.itemName = itemName; + this.priceRange = priceRange; + this.category = category; + } + + public void updateItem( + String itemName, + PriceRange priceRange, + Category category + ) { + this.itemName = itemName; + this.priceRange = priceRange; + this.category = category; + } +} diff --git a/nabimarket-domain/src/main/java/org/prgrms/nabimarketbe/item/entity/PriceRange.java b/nabimarket-domain/src/main/java/org/prgrms/nabimarketbe/item/entity/PriceRange.java new file mode 100644 index 00000000..37bb5b4e --- /dev/null +++ b/nabimarket-domain/src/main/java/org/prgrms/nabimarketbe/item/entity/PriceRange.java @@ -0,0 +1,33 @@ +package org.prgrms.nabimarketbe.item.entity; + +import lombok.Getter; + +@Getter +public enum PriceRange { + PRICE_RANGE_ONE(1, 0, 10_000), + PRICE_RANGE_TWO(2, 10_000, 50_000), + PRICE_RANGE_THREE(3, 50_000, 100_000), + PRICE_RANGE_FOUR(4, 100_000, 200_000), + PRICE_RANGE_FIVE(5, 200_000, 300_000), + PRICE_RANGE_SIX(6, 300_000, 400_000), + PRICE_RANGE_SEVEN(7, 400_000, 500_000), + PRICE_RANGE_EIGHT(8, 500_000, Integer.MAX_VALUE); + + private Integer value; + private Integer priceFrom; + private Integer priceTo; + + PriceRange( + Integer value, + Integer priceFrom, + Integer priceTo + ) { + this.value = value; + this.priceFrom = priceFrom; + this.priceTo = priceTo; + } + + public boolean isHigherThan(PriceRange priceRange) { + return this.value > priceRange.value; + } +} diff --git a/nabimarket-domain/src/main/java/org/prgrms/nabimarketbe/item/repository/ItemRepository.java b/nabimarket-domain/src/main/java/org/prgrms/nabimarketbe/item/repository/ItemRepository.java new file mode 100644 index 00000000..df4d1889 --- /dev/null +++ b/nabimarket-domain/src/main/java/org/prgrms/nabimarketbe/item/repository/ItemRepository.java @@ -0,0 +1,7 @@ +package org.prgrms.nabimarketbe.item.repository; + +import org.prgrms.nabimarketbe.item.entity.Item; +import org.springframework.data.jpa.repository.JpaRepository; + +public interface ItemRepository extends JpaRepository { +} diff --git a/nabimarket-domain/src/main/java/org/prgrms/nabimarketbe/notification/entity/Notification.java b/nabimarket-domain/src/main/java/org/prgrms/nabimarketbe/notification/entity/Notification.java new file mode 100644 index 00000000..ee963011 --- /dev/null +++ b/nabimarket-domain/src/main/java/org/prgrms/nabimarketbe/notification/entity/Notification.java @@ -0,0 +1,59 @@ +package org.prgrms.nabimarketbe.notification.entity; + +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.FetchType; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; +import javax.persistence.Id; +import javax.persistence.JoinColumn; +import javax.persistence.ManyToOne; +import javax.persistence.Table; + +import org.prgrms.nabimarketbe.BaseEntity; +import org.prgrms.nabimarketbe.card.entity.Card; +import org.prgrms.nabimarketbe.user.entity.User; + +import lombok.AccessLevel; +import lombok.Getter; +import lombok.NoArgsConstructor; + +@Getter +@Entity +@Table(name = "notifications") +@NoArgsConstructor(access = AccessLevel.PROTECTED) +public class Notification extends BaseEntity { + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + @Column(name = "notifiaction_id", nullable = false) + private Long notificationId; + + @Column(name = "content", nullable = false) + private String content; + + @ManyToOne(fetch = FetchType.LAZY) + @JoinColumn(name = "user_id", nullable = false) + private User receiver; + + @ManyToOne(fetch = FetchType.LAZY) + @JoinColumn(name = "card_id", nullable = false) + private Card card; + + @Column(name = "is_read", nullable = false) + private boolean isRead; + + public Notification( + User user, + Card card, + String content + ) { + this.receiver = user; + this.card = card; + this.content = content; + this.isRead = false; + } + + public void updateToRead() { + this.isRead = true; + } +} diff --git a/nabimarket-domain/src/main/java/org/prgrms/nabimarketbe/notification/projection/NotificationDetailResponseDTO.java b/nabimarket-domain/src/main/java/org/prgrms/nabimarketbe/notification/projection/NotificationDetailResponseDTO.java new file mode 100644 index 00000000..eef234ea --- /dev/null +++ b/nabimarket-domain/src/main/java/org/prgrms/nabimarketbe/notification/projection/NotificationDetailResponseDTO.java @@ -0,0 +1,20 @@ +package org.prgrms.nabimarketbe.notification.projection; + +import java.time.LocalDateTime; + +import lombok.Getter; + +@Getter +public class NotificationDetailResponseDTO { + private Long notificationId; + + private String content; + + private boolean isRead; + + private Long cardId; + + private LocalDateTime createdAt; + + private LocalDateTime modifiedAt; +} diff --git a/nabimarket-domain/src/main/java/org/prgrms/nabimarketbe/notification/repository/NotificationRepository.java b/nabimarket-domain/src/main/java/org/prgrms/nabimarketbe/notification/repository/NotificationRepository.java new file mode 100644 index 00000000..65cf9016 --- /dev/null +++ b/nabimarket-domain/src/main/java/org/prgrms/nabimarketbe/notification/repository/NotificationRepository.java @@ -0,0 +1,19 @@ +package org.prgrms.nabimarketbe.notification.repository; + +import java.util.List; + +import org.prgrms.nabimarketbe.notification.entity.Notification; +import org.prgrms.nabimarketbe.user.entity.User; +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.jpa.repository.Modifying; +import org.springframework.data.jpa.repository.Query; + +public interface NotificationRepository extends JpaRepository, NotificationRepositoryCustom { + Long countNotificationByIsReadIsFalseAndReceiver(User receiver); + + @Query("UPDATE Notification n " + + "SET n.isRead=true " + + "WHERE n.receiver = :receiver AND n.notificationId in :notificationIds") + @Modifying(clearAutomatically = true) + void bulkUpdateNotificationsByIds(List notificationIds, User receiver); +} diff --git a/nabimarket-domain/src/main/java/org/prgrms/nabimarketbe/notification/repository/NotificationRepositoryCustom.java b/nabimarket-domain/src/main/java/org/prgrms/nabimarketbe/notification/repository/NotificationRepositoryCustom.java new file mode 100644 index 00000000..cad785af --- /dev/null +++ b/nabimarket-domain/src/main/java/org/prgrms/nabimarketbe/notification/repository/NotificationRepositoryCustom.java @@ -0,0 +1,15 @@ +package org.prgrms.nabimarketbe.notification.repository; + +import org.prgrms.nabimarketbe.notification.wrapper.NotificationPagingResponseDTO; +import org.prgrms.nabimarketbe.user.entity.User; +import org.springframework.data.domain.Pageable; + +public interface NotificationRepositoryCustom { + NotificationPagingResponseDTO getNotificationsByIsRead( + User receiver, + Boolean isRead, + Integer size, + String cursorId, + Pageable pageable + ); +} diff --git a/nabimarket-domain/src/main/java/org/prgrms/nabimarketbe/notification/repository/NotificationRepositoryImpl.java b/nabimarket-domain/src/main/java/org/prgrms/nabimarketbe/notification/repository/NotificationRepositoryImpl.java new file mode 100644 index 00000000..f4fdf65e --- /dev/null +++ b/nabimarket-domain/src/main/java/org/prgrms/nabimarketbe/notification/repository/NotificationRepositoryImpl.java @@ -0,0 +1,105 @@ +package org.prgrms.nabimarketbe.notification.repository; + +import java.util.List; + +import org.prgrms.nabimarketbe.notification.entity.QNotification; +import org.prgrms.nabimarketbe.notification.projection.NotificationDetailResponseDTO; +import org.prgrms.nabimarketbe.notification.wrapper.NotificationPagingResponseDTO; +import org.prgrms.nabimarketbe.user.entity.User; +import org.prgrms.nabimarketbe.util.CursorPaging; +import org.prgrms.nabimarketbe.util.QueryDslUtil; +import org.springframework.data.domain.Pageable; + +import com.querydsl.core.types.ConstantImpl; +import com.querydsl.core.types.Projections; +import com.querydsl.core.types.dsl.BooleanExpression; +import com.querydsl.core.types.dsl.Expressions; +import com.querydsl.core.types.dsl.StringExpression; +import com.querydsl.core.types.dsl.StringExpressions; +import com.querydsl.core.types.dsl.StringTemplate; +import com.querydsl.jpa.impl.JPAQueryFactory; + +import lombok.RequiredArgsConstructor; + +@RequiredArgsConstructor +public class NotificationRepositoryImpl implements NotificationRepositoryCustom, CursorPaging { + private final JPAQueryFactory jpaQueryFactory; + + @Override + public NotificationPagingResponseDTO getNotificationsByIsRead( + User receiver, + Boolean isRead, + Integer size, + String cursorId, + Pageable pageable + ) { + List notificationList = jpaQueryFactory.select( + Projections.fields( + NotificationDetailResponseDTO.class, + QNotification.notification.notificationId, + QNotification.notification.content, + QNotification.notification.isRead, + QNotification.notification.card.cardId, + QNotification.notification.createdDate.as("createdAt"), + QNotification.notification.modifiedDate.as("modifiedAt") + ) + ) + .from(QNotification.notification) + .where( + receiverEquals(receiver), + cursorId(cursorId), + isReadEquals(isRead) + ) + .orderBy(QueryDslUtil.getOrderSpecifier(pageable.getSort(), QNotification.notification)) + .limit(pageable.getPageSize()) + .fetch(); + + String nextCursorId = notificationList.size() < pageable.getPageSize() ? + null : generateCursor(notificationList.get(notificationList.size() - 1)); + + return new NotificationPagingResponseDTO(notificationList, nextCursorId); + } + + @Override + public BooleanExpression cursorId(String cursorId) { + if (cursorId == null) { + return null; + } + + // 생성일자 + StringTemplate dateCursorTemplate = Expressions.stringTemplate( + "DATE_FORMAT({0}, {1})", + QNotification.notification.createdDate, + ConstantImpl.create("%Y%m%d%H%i%s") + ); + + // pk + StringExpression pkCursorTemplate = StringExpressions.lpad( + QNotification.notification.notificationId.stringValue(), + 8, + '0' + ); + + return dateCursorTemplate.concat(pkCursorTemplate).lt(cursorId); + } + + private BooleanExpression receiverEquals(User receiver) { + return QNotification.notification.receiver.eq(receiver); + } + + private String generateCursor(NotificationDetailResponseDTO notificationDetailResponseDTO) { + return notificationDetailResponseDTO.getCreatedAt().toString() // 디폴트는 생성일자 최신순 정렬 + .replace("T", "") + .replace("-", "") + .replace(":", "") + + String.format("%08d", notificationDetailResponseDTO.getNotificationId()); + } + + private BooleanExpression isReadEquals(Boolean isRead) { + if (isRead == null) { + return null; + } + + return QNotification.notification.isRead.eq(isRead); + } +} diff --git a/nabimarket-domain/src/main/java/org/prgrms/nabimarketbe/notification/wrapper/NotificationPagingResponseDTO.java b/nabimarket-domain/src/main/java/org/prgrms/nabimarketbe/notification/wrapper/NotificationPagingResponseDTO.java new file mode 100644 index 00000000..11e097ca --- /dev/null +++ b/nabimarket-domain/src/main/java/org/prgrms/nabimarketbe/notification/wrapper/NotificationPagingResponseDTO.java @@ -0,0 +1,11 @@ +package org.prgrms.nabimarketbe.notification.wrapper; + +import java.util.List; + +import org.prgrms.nabimarketbe.notification.projection.NotificationDetailResponseDTO; + +public record NotificationPagingResponseDTO( + List notificationList, + String nextCursorId +) { +} diff --git a/nabimarket-domain/src/main/java/org/prgrms/nabimarketbe/security/entity/RefreshToken.java b/nabimarket-domain/src/main/java/org/prgrms/nabimarketbe/security/entity/RefreshToken.java new file mode 100644 index 00000000..9f56d7c6 --- /dev/null +++ b/nabimarket-domain/src/main/java/org/prgrms/nabimarketbe/security/entity/RefreshToken.java @@ -0,0 +1,43 @@ +package org.prgrms.nabimarketbe.security.entity; + +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; +import javax.persistence.Id; +import javax.persistence.Table; + +import org.prgrms.nabimarketbe.BaseEntity; + +import lombok.Getter; +import lombok.NoArgsConstructor; + +@Entity +@Table(name = "refresh_token") +@Getter +@NoArgsConstructor +public class RefreshToken extends BaseEntity { + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + private Long id; + + @Column(nullable = false, unique = true) + private Long userId; + + @Column(nullable = false, unique = true) + private String token; + + public RefreshToken updateToken(String token) { + this.token = token; + + return this; + } + + public RefreshToken( + Long userId, + String token + ) { + this.userId = userId; + this.token = token; + } +} diff --git a/nabimarket-domain/src/main/java/org/prgrms/nabimarketbe/security/jwt/repository/RefreshTokenRepository.java b/nabimarket-domain/src/main/java/org/prgrms/nabimarketbe/security/jwt/repository/RefreshTokenRepository.java new file mode 100644 index 00000000..0c00284f --- /dev/null +++ b/nabimarket-domain/src/main/java/org/prgrms/nabimarketbe/security/jwt/repository/RefreshTokenRepository.java @@ -0,0 +1,10 @@ +package org.prgrms.nabimarketbe.security.jwt.repository; + +import java.util.Optional; + +import org.prgrms.nabimarketbe.security.entity.RefreshToken; +import org.springframework.data.jpa.repository.JpaRepository; + +public interface RefreshTokenRepository extends JpaRepository { + Optional findByUserId(Long userId); +} diff --git a/nabimarket-domain/src/main/java/org/prgrms/nabimarketbe/suggestion/entity/DirectionType.java b/nabimarket-domain/src/main/java/org/prgrms/nabimarketbe/suggestion/entity/DirectionType.java new file mode 100644 index 00000000..314f9240 --- /dev/null +++ b/nabimarket-domain/src/main/java/org/prgrms/nabimarketbe/suggestion/entity/DirectionType.java @@ -0,0 +1,6 @@ +package org.prgrms.nabimarketbe.suggestion.entity; + +public enum DirectionType { + SEND, + RECEIVE +} diff --git a/nabimarket-domain/src/main/java/org/prgrms/nabimarketbe/suggestion/entity/Suggestion.java b/nabimarket-domain/src/main/java/org/prgrms/nabimarketbe/suggestion/entity/Suggestion.java new file mode 100644 index 00000000..180d881a --- /dev/null +++ b/nabimarket-domain/src/main/java/org/prgrms/nabimarketbe/suggestion/entity/Suggestion.java @@ -0,0 +1,112 @@ +package org.prgrms.nabimarketbe.suggestion.entity; + +import javax.persistence.Entity; +import javax.persistence.EnumType; +import javax.persistence.Enumerated; +import javax.persistence.FetchType; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; +import javax.persistence.Id; +import javax.persistence.JoinColumn; +import javax.persistence.ManyToOne; +import javax.persistence.Table; +import javax.persistence.UniqueConstraint; + +import org.prgrms.nabimarketbe.BaseEntity; +import org.prgrms.nabimarketbe.card.entity.Card; +import org.prgrms.nabimarketbe.error.BaseException; +import org.prgrms.nabimarketbe.error.ErrorCode; + +import lombok.Builder; +import lombok.Getter; +import lombok.NoArgsConstructor; + +@Entity +@Getter +@NoArgsConstructor +@Table(name = "suggestions", + uniqueConstraints = { + @UniqueConstraint( + name = "suggestion_unique", + columnNames = {"from_card", "to_card"} + ) + }) +public class Suggestion extends BaseEntity { + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + private Long suggestionId; + + @Enumerated(EnumType.STRING) + private SuggestionType suggestionType; + + @ManyToOne(fetch = FetchType.LAZY) + @JoinColumn(name = "from_card", nullable = false) + private Card fromCard; + + @ManyToOne(fetch = FetchType.LAZY) + @JoinColumn(name = "to_card", nullable = false) + private Card toCard; + + @Enumerated(EnumType.STRING) + private SuggestionStatus suggestionStatus; + + @Builder + public Suggestion( + SuggestionType suggestionType, + Card fromCard, + Card toCard + ) { + if (suggestionType == null || fromCard == null || toCard == null) { + throw new BaseException(ErrorCode.INVALID_REQUEST); + } + + this.suggestionType = suggestionType; + this.fromCard = fromCard; + this.toCard = toCard; + this.suggestionStatus = SuggestionStatus.WAITING; + } + + public boolean isAccepted() { + return suggestionStatus.equals(SuggestionStatus.ACCEPTED); + } + + public void decideSuggestion(Boolean isAccpeted) { + if (isAccpeted) { + acceptSuggestion(); + } else { + refuseSuggestion(); + } + } + + public String createSuggestionRequestMessage() { + String message = String.format( + "%s에 대한 %s님의 새로운 제안이 도착하였습니다.", + toCard.getItem().getItemName(), + fromCard.getUser().getNickname() + ); + + return message; + } + + public String createSuggestionDecisionMessage(boolean isAccepted) { + String suggestionResult = isAccepted ? "수락" : "거절"; + String suggestionType = this.suggestionType.getName(); + String message = String.format( + "%s에 대한 %s의 %s이(가) %s 되었습니다.", + toCard.getItem().getItemName(), + fromCard.getItem().getItemName(), + suggestionType, + suggestionResult + ); + + return message; + } + + private void acceptSuggestion() { + this.suggestionStatus = SuggestionStatus.ACCEPTED; + } + + private void refuseSuggestion() { + this.suggestionStatus = SuggestionStatus.REFUSED; + } +} diff --git a/nabimarket-domain/src/main/java/org/prgrms/nabimarketbe/suggestion/entity/SuggestionStatus.java b/nabimarket-domain/src/main/java/org/prgrms/nabimarketbe/suggestion/entity/SuggestionStatus.java new file mode 100644 index 00000000..dbcad0cc --- /dev/null +++ b/nabimarket-domain/src/main/java/org/prgrms/nabimarketbe/suggestion/entity/SuggestionStatus.java @@ -0,0 +1,7 @@ +package org.prgrms.nabimarketbe.suggestion.entity; + +public enum SuggestionStatus { + WAITING, + ACCEPTED, + REFUSED +} diff --git a/nabimarket-domain/src/main/java/org/prgrms/nabimarketbe/suggestion/entity/SuggestionType.java b/nabimarket-domain/src/main/java/org/prgrms/nabimarketbe/suggestion/entity/SuggestionType.java new file mode 100644 index 00000000..223a0191 --- /dev/null +++ b/nabimarket-domain/src/main/java/org/prgrms/nabimarketbe/suggestion/entity/SuggestionType.java @@ -0,0 +1,33 @@ +package org.prgrms.nabimarketbe.suggestion.entity; + +import java.util.function.BiFunction; + +import org.prgrms.nabimarketbe.item.entity.Item; + +import lombok.Getter; + +@Getter +public enum SuggestionType { + OFFER("오퍼", (fromItem, toItem) -> (fromItem.getPriceRange().equals(toItem.getPriceRange()) + || fromItem.getPriceRange().getValue() > toItem.getPriceRange().getValue())), + POKE("찔러보기", (fromItem, toItem) -> (fromItem.getPriceRange().getValue() < toItem.getPriceRange().getValue())); + + private final String name; + + public final BiFunction suggestionValidationFunction; + + SuggestionType( + String name, + BiFunction suggestionValidationFunction + ) { + this.name = name; + this.suggestionValidationFunction = suggestionValidationFunction; + } + + public boolean isSuggestionAvailable( + Item fromItem, + Item toItem + ) { + return this.suggestionValidationFunction.apply(fromItem, toItem); + } +} diff --git a/nabimarket-domain/src/main/java/org/prgrms/nabimarketbe/suggestion/projection/SuggestionDetailResponseDTO.java b/nabimarket-domain/src/main/java/org/prgrms/nabimarketbe/suggestion/projection/SuggestionDetailResponseDTO.java new file mode 100644 index 00000000..9ebb2bf0 --- /dev/null +++ b/nabimarket-domain/src/main/java/org/prgrms/nabimarketbe/suggestion/projection/SuggestionDetailResponseDTO.java @@ -0,0 +1,19 @@ +package org.prgrms.nabimarketbe.suggestion.projection; + +import java.time.LocalDateTime; + +import org.prgrms.nabimarketbe.suggestion.entity.DirectionType; +import org.prgrms.nabimarketbe.suggestion.entity.SuggestionStatus; +import org.prgrms.nabimarketbe.suggestion.entity.SuggestionType; + +import lombok.Getter; + +@Getter +public class SuggestionDetailResponseDTO { + private Long suggestionId; + private SuggestionType suggestionType; + private SuggestionStatus suggestionStatus; + private LocalDateTime createdAt; + private LocalDateTime modifiedAt; + private DirectionType directionType; +} diff --git a/nabimarket-domain/src/main/java/org/prgrms/nabimarketbe/suggestion/projection/SuggestionInfo.java b/nabimarket-domain/src/main/java/org/prgrms/nabimarketbe/suggestion/projection/SuggestionInfo.java new file mode 100644 index 00000000..28dd1a25 --- /dev/null +++ b/nabimarket-domain/src/main/java/org/prgrms/nabimarketbe/suggestion/projection/SuggestionInfo.java @@ -0,0 +1,17 @@ +package org.prgrms.nabimarketbe.suggestion.projection; + +import org.prgrms.nabimarketbe.suggestion.entity.SuggestionStatus; +import org.prgrms.nabimarketbe.suggestion.entity.SuggestionType; + +import lombok.Getter; + +@Getter +public class SuggestionInfo { + private SuggestionType suggestionType; + + private SuggestionStatus suggestionStatus; + + public void updateSuggestionType(SuggestionType suggestionType) { + this.suggestionType = suggestionType; + } +} diff --git a/nabimarket-domain/src/main/java/org/prgrms/nabimarketbe/suggestion/projection/SuggestionListReadPagingResponseDTO.java b/nabimarket-domain/src/main/java/org/prgrms/nabimarketbe/suggestion/projection/SuggestionListReadPagingResponseDTO.java new file mode 100644 index 00000000..aec51654 --- /dev/null +++ b/nabimarket-domain/src/main/java/org/prgrms/nabimarketbe/suggestion/projection/SuggestionListReadPagingResponseDTO.java @@ -0,0 +1,9 @@ +package org.prgrms.nabimarketbe.suggestion.projection; + +import java.util.List; + +public record SuggestionListReadPagingResponseDTO( + List suggestionList, + String nextCursorId +) { +} diff --git a/nabimarket-domain/src/main/java/org/prgrms/nabimarketbe/suggestion/projection/SuggestionListReadResponseDTO.java b/nabimarket-domain/src/main/java/org/prgrms/nabimarketbe/suggestion/projection/SuggestionListReadResponseDTO.java new file mode 100644 index 00000000..15803780 --- /dev/null +++ b/nabimarket-domain/src/main/java/org/prgrms/nabimarketbe/suggestion/projection/SuggestionListReadResponseDTO.java @@ -0,0 +1,12 @@ +package org.prgrms.nabimarketbe.suggestion.projection; + +import org.prgrms.nabimarketbe.card.projection.CardInfoResponseDTO; + +import lombok.Getter; + +@Getter +public class SuggestionListReadResponseDTO { + private CardInfoResponseDTO cardInfo; + + private SuggestionDetailResponseDTO suggestionInfo; +} diff --git a/nabimarket-domain/src/main/java/org/prgrms/nabimarketbe/suggestion/repository/SuggestionRepository.java b/nabimarket-domain/src/main/java/org/prgrms/nabimarketbe/suggestion/repository/SuggestionRepository.java new file mode 100644 index 00000000..c57ace24 --- /dev/null +++ b/nabimarket-domain/src/main/java/org/prgrms/nabimarketbe/suggestion/repository/SuggestionRepository.java @@ -0,0 +1,27 @@ +package org.prgrms.nabimarketbe.suggestion.repository; + +import java.util.Optional; + +import org.prgrms.nabimarketbe.card.entity.Card; +import org.prgrms.nabimarketbe.suggestion.entity.Suggestion; +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.jpa.repository.Query; +import org.springframework.data.repository.query.Param; + +public interface SuggestionRepository extends JpaRepository, SuggestionRepositoryCustom { + @Query("select s " + + "from Suggestion s " + + "where s.fromCard = :fromCard and s.toCard = :toCard " + + "or s.fromCard = :toCard and s.toCard = :fromCard") + Optional findSuggestionByFromCardAndToCard( + @Param("fromCard") Card fromCard, + @Param("toCard") Card toCard + ); + + @Query( + "select count(s.suggestionId) > 0 " + + "from Suggestion s " + + "where s.fromCard = :fromCard and s.toCard = :toCard " + + "or s.fromCard = :toCard and s.toCard = :fromCard") + Boolean exists(@Param("fromCard") Card fromCard, @Param("toCard") Card toCard); +} diff --git a/nabimarket-domain/src/main/java/org/prgrms/nabimarketbe/suggestion/repository/SuggestionRepositoryCustom.java b/nabimarket-domain/src/main/java/org/prgrms/nabimarketbe/suggestion/repository/SuggestionRepositoryCustom.java new file mode 100644 index 00000000..552fcc41 --- /dev/null +++ b/nabimarket-domain/src/main/java/org/prgrms/nabimarketbe/suggestion/repository/SuggestionRepositoryCustom.java @@ -0,0 +1,16 @@ +package org.prgrms.nabimarketbe.suggestion.repository; + +import org.prgrms.nabimarketbe.suggestion.entity.DirectionType; +import org.prgrms.nabimarketbe.suggestion.entity.SuggestionType; +import org.prgrms.nabimarketbe.suggestion.projection.SuggestionListReadPagingResponseDTO; + +public interface SuggestionRepositoryCustom { + SuggestionListReadPagingResponseDTO getSuggestionsByType( + DirectionType directionType, + SuggestionType suggestionType, + Long cardId, + String cursorId, + Integer size + ); + +} diff --git a/nabimarket-domain/src/main/java/org/prgrms/nabimarketbe/suggestion/repository/SuggestionRepositoryImpl.java b/nabimarket-domain/src/main/java/org/prgrms/nabimarketbe/suggestion/repository/SuggestionRepositoryImpl.java new file mode 100644 index 00000000..f303e1e1 --- /dev/null +++ b/nabimarket-domain/src/main/java/org/prgrms/nabimarketbe/suggestion/repository/SuggestionRepositoryImpl.java @@ -0,0 +1,168 @@ +package org.prgrms.nabimarketbe.suggestion.repository; + +import java.util.List; + +import org.prgrms.nabimarketbe.card.entity.CardStatus; +import org.prgrms.nabimarketbe.card.entity.QCard; +import org.prgrms.nabimarketbe.card.projection.CardInfoResponseDTO; +import org.prgrms.nabimarketbe.error.BaseException; +import org.prgrms.nabimarketbe.error.ErrorCode; +import org.prgrms.nabimarketbe.suggestion.entity.DirectionType; +import org.prgrms.nabimarketbe.suggestion.entity.QSuggestion; +import org.prgrms.nabimarketbe.suggestion.entity.SuggestionType; +import org.prgrms.nabimarketbe.suggestion.projection.SuggestionDetailResponseDTO; +import org.prgrms.nabimarketbe.suggestion.projection.SuggestionListReadPagingResponseDTO; +import org.prgrms.nabimarketbe.suggestion.projection.SuggestionListReadResponseDTO; +import org.prgrms.nabimarketbe.util.QueryDslUtil; +import org.springframework.data.domain.Sort; + +import com.querydsl.core.types.ConstantImpl; +import com.querydsl.core.types.Projections; +import com.querydsl.core.types.dsl.BooleanExpression; +import com.querydsl.core.types.dsl.Expressions; +import com.querydsl.core.types.dsl.StringExpressions; +import com.querydsl.core.types.dsl.StringTemplate; +import com.querydsl.jpa.impl.JPAQueryFactory; + +import lombok.RequiredArgsConstructor; + +@RequiredArgsConstructor +public class SuggestionRepositoryImpl implements SuggestionRepositoryCustom { + private final JPAQueryFactory jpaQueryFactory; + + @Override + public SuggestionListReadPagingResponseDTO getSuggestionsByType( + DirectionType directionType, + SuggestionType suggestionType, + Long cardId, + String cursorId, + Integer size + ) { + List suggestionList = jpaQueryFactory + .select( + Projections.fields( + SuggestionListReadResponseDTO.class, + Projections.fields( + CardInfoResponseDTO.class, + getQCardCounter(directionType).cardId, + getQCardCounter(directionType).cardTitle, + getQCardCounter(directionType).item.itemName, + getQCardCounter(directionType).item.priceRange, + getQCardCounter(directionType).thumbnail + ).as("cardInfo"), + Projections.fields( + SuggestionDetailResponseDTO.class, + QSuggestion.suggestion.suggestionId, + QSuggestion.suggestion.suggestionType, + QSuggestion.suggestion.suggestionStatus, + QSuggestion.suggestion.createdDate.as("createdAt"), + QSuggestion.suggestion.modifiedDate.as("modifiedAt"), + Expressions.as(Expressions.constant(directionType), "directionType") + ).as("suggestionInfo") + ) + ) + .from(QSuggestion.suggestion) + .join(getQcardByDirectionType(directionType), QCard.card) + .on(getExpressionByDirectionType(directionType, cardId)) + .where( + cursorIdLessThan(cursorId), + suggestionTypeEquals(suggestionType), + getQCardCounter(directionType).isActive.eq(true), + getQCardCounter(directionType).status.eq(CardStatus.TRADE_AVAILABLE) + ) + .orderBy( + QueryDslUtil.getOrderSpecifier( + Sort.by( + Sort.Order.desc("createdDate"), + Sort.Order.desc("suggestionId") + ), + QSuggestion.suggestion + ) + ) + .limit(size) + .fetch(); + + String nextCursor = suggestionList.size() < size + ? null : createCursorId(suggestionList.get(suggestionList.size() - 1)); + + return new SuggestionListReadPagingResponseDTO(suggestionList, nextCursor); + } + + /** + * 오퍼, 찔러보기 필터링 + */ + private BooleanExpression suggestionTypeEquals(SuggestionType suggestionType) { + if (suggestionType == null) { + throw new BaseException(ErrorCode.INVALID_REQUEST); + } + + return QSuggestion.suggestion.suggestionType.eq(suggestionType); + } + + /** + * 커스텀 커서 id가 주어진 cursorId보다 작은지 확인 + */ + private BooleanExpression cursorIdLessThan(String cursorId) { + if (cursorId == null) { + return null; + } + + StringTemplate stringTemplate = Expressions.stringTemplate( + "DATE_FORMAT({0}, {1})", + QSuggestion.suggestion.createdDate, + ConstantImpl.create("%Y%m%d%H%i%s") + ); + + return stringTemplate.concat(StringExpressions.lpad( + QSuggestion.suggestion.suggestionId.stringValue(), + 8, + '0' + )).lt(cursorId); + } + + /** + * 커서 id 생성 + */ + private String createCursorId(SuggestionListReadResponseDTO suggestionListReadResponseDTO) { + return suggestionListReadResponseDTO.getSuggestionInfo().getCreatedAt().toString() + .replace("T", "") + .replace("-", "") + .replace(":", "") + + String.format("%08d", suggestionListReadResponseDTO.getSuggestionInfo().getSuggestionId()); + } + + /** + * 내 카드의 대상이 받은 / 보낸 제안인지에 따른 join 절 분기문 처리 + */ + private QCard getQcardByDirectionType(DirectionType directionType) { + return switch (directionType) { + case RECEIVE -> QSuggestion.suggestion.toCard; + case SEND -> QSuggestion.suggestion.fromCard; + }; + } + + /** + * 받은 / 보낸 제안인지에 따른 Projections.fields 분기문 처리 + * 내가 받은 제안 조회 -> fromCard 필드 + * 내가 보낸 제안 -> toCard 필드 + */ + private QCard getQCardCounter(DirectionType directionType) { + return switch (directionType) { + case RECEIVE -> QSuggestion.suggestion.fromCard; + case SEND -> QSuggestion.suggestion.toCard; + }; + } + + /** + * 받은 / 보낸 제안인지에 따른 on 절 분기문 처리 + */ + private BooleanExpression getExpressionByDirectionType( + DirectionType directionType, + Long cardId + ) { + return switch (directionType) { + case RECEIVE -> QSuggestion.suggestion.toCard.cardId.eq(cardId); + case SEND -> QSuggestion.suggestion.fromCard.cardId.eq(cardId); + }; + } +} diff --git a/nabimarket-domain/src/main/java/org/prgrms/nabimarketbe/user/entity/Role.java b/nabimarket-domain/src/main/java/org/prgrms/nabimarketbe/user/entity/Role.java new file mode 100644 index 00000000..422fc371 --- /dev/null +++ b/nabimarket-domain/src/main/java/org/prgrms/nabimarketbe/user/entity/Role.java @@ -0,0 +1,14 @@ +package org.prgrms.nabimarketbe.user.entity; + +import lombok.Getter; +import lombok.RequiredArgsConstructor; + +@Getter +@RequiredArgsConstructor +public enum Role { + GUEST("ROLE_GUEST"), + + USER("ROLE_USER"); + + private final String key; +} diff --git a/nabimarket-domain/src/main/java/org/prgrms/nabimarketbe/user/entity/User.java b/nabimarket-domain/src/main/java/org/prgrms/nabimarketbe/user/entity/User.java new file mode 100644 index 00000000..b0ddd66d --- /dev/null +++ b/nabimarket-domain/src/main/java/org/prgrms/nabimarketbe/user/entity/User.java @@ -0,0 +1,118 @@ +package org.prgrms.nabimarketbe.user.entity; + +import java.util.Collection; +import java.util.Collections; + +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; +import javax.persistence.Id; +import javax.persistence.Table; + +import org.prgrms.nabimarketbe.BaseEntity; +import org.prgrms.nabimarketbe.error.BaseException; +import org.prgrms.nabimarketbe.error.ErrorCode; +import org.springframework.security.core.GrantedAuthority; +import org.springframework.security.core.authority.SimpleGrantedAuthority; +import org.springframework.security.core.userdetails.UserDetails; + +import com.fasterxml.jackson.annotation.JsonProperty; + +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Getter; +import lombok.NoArgsConstructor; + +@Entity +@Getter +@NoArgsConstructor +@AllArgsConstructor +@Table(name = "users") +public class User extends BaseEntity implements UserDetails { + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + private Long userId; + + @Column(nullable = false, unique = true, length = 30) + private String accountId; + + @Column(name = "nickname", nullable = false, length = 20, unique = true) + private String nickname; + + @Column(name = "user_image_url") + private String imageUrl; + + @Column(length = 100, nullable = false) + private String provider; + + @Column(name = "user_role", nullable = false) + private String role; + + @Builder + private User( + String accountId, + String nickname, + String imageUrl, + String provider, + String role + ) { + if (accountId.isBlank() || nickname.isBlank() || provider.isBlank() || role.isBlank()) { + throw new BaseException(ErrorCode.INVALID_REQUEST); + } + + this.accountId = accountId; + this.nickname = nickname; + this.imageUrl = imageUrl; + this.provider = provider; + this.role = role; + } + + public void updateNickname(String nickname) { + this.nickname = nickname; + } + + public void updateImageUrl(String imageUrl) { + this.imageUrl = imageUrl; + } + + @Override + public Collection getAuthorities() { + return Collections.singletonList(new SimpleGrantedAuthority(this.role.toString())); + } + + @Override + public String getPassword() { + return null; + } + + @JsonProperty(access = JsonProperty.Access.WRITE_ONLY) + @Override + public String getUsername() { + return String.valueOf(this.userId); + } + + @JsonProperty(access = JsonProperty.Access.WRITE_ONLY) + @Override + public boolean isAccountNonExpired() { + return true; + } + + @JsonProperty(access = JsonProperty.Access.WRITE_ONLY) + @Override + public boolean isAccountNonLocked() { + return true; + } + + @JsonProperty(access = JsonProperty.Access.WRITE_ONLY) + @Override + public boolean isCredentialsNonExpired() { + return true; + } + + @JsonProperty(access = JsonProperty.Access.WRITE_ONLY) + @Override + public boolean isEnabled() { + return true; + } +} diff --git a/nabimarket-domain/src/main/java/org/prgrms/nabimarketbe/user/projection/UserIdResponseDTO.java b/nabimarket-domain/src/main/java/org/prgrms/nabimarketbe/user/projection/UserIdResponseDTO.java new file mode 100644 index 00000000..cbff9357 --- /dev/null +++ b/nabimarket-domain/src/main/java/org/prgrms/nabimarketbe/user/projection/UserIdResponseDTO.java @@ -0,0 +1,4 @@ +package org.prgrms.nabimarketbe.user.projection; + +public record UserIdResponseDTO(Long userId) { +} diff --git a/nabimarket-domain/src/main/java/org/prgrms/nabimarketbe/user/repository/UserRepository.java b/nabimarket-domain/src/main/java/org/prgrms/nabimarketbe/user/repository/UserRepository.java new file mode 100644 index 00000000..18bbd8aa --- /dev/null +++ b/nabimarket-domain/src/main/java/org/prgrms/nabimarketbe/user/repository/UserRepository.java @@ -0,0 +1,18 @@ +package org.prgrms.nabimarketbe.user.repository; + +import java.util.Optional; + +import org.prgrms.nabimarketbe.user.entity.User; +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.stereotype.Repository; + +@Repository +public interface UserRepository extends JpaRepository { + Optional findByNickname(String name); + + Optional findByAccountIdAndProvider(String accountId, String provider); + + Optional findByAccountId(String oauthId); + + boolean existsUserByNickname(String nickname); +} diff --git a/nabimarket-domain/src/main/java/org/prgrms/nabimarketbe/util/CursorPaging.java b/nabimarket-domain/src/main/java/org/prgrms/nabimarketbe/util/CursorPaging.java new file mode 100644 index 00000000..caa931e8 --- /dev/null +++ b/nabimarket-domain/src/main/java/org/prgrms/nabimarketbe/util/CursorPaging.java @@ -0,0 +1,12 @@ +package org.prgrms.nabimarketbe.util; + +import com.querydsl.core.types.dsl.BooleanExpression; + +public interface CursorPaging { + /** + * cursorId를 받아 cursor Id로 조건절을 만드는 메소드 + * @param cursorId + * @return + */ + BooleanExpression cursorId(String cursorId); +} diff --git a/nabimarket-domain/src/main/java/org/prgrms/nabimarketbe/util/OrderCondition.java b/nabimarket-domain/src/main/java/org/prgrms/nabimarketbe/util/OrderCondition.java new file mode 100644 index 00000000..6a87bdfe --- /dev/null +++ b/nabimarket-domain/src/main/java/org/prgrms/nabimarketbe/util/OrderCondition.java @@ -0,0 +1,5 @@ +package org.prgrms.nabimarketbe.util; + +public enum OrderCondition { + CARD_CREATED_DESC +} diff --git a/nabimarket-domain/src/main/java/org/prgrms/nabimarketbe/util/QueryDslUtil.java b/nabimarket-domain/src/main/java/org/prgrms/nabimarketbe/util/QueryDslUtil.java new file mode 100644 index 00000000..029e3983 --- /dev/null +++ b/nabimarket-domain/src/main/java/org/prgrms/nabimarketbe/util/QueryDslUtil.java @@ -0,0 +1,54 @@ +package org.prgrms.nabimarketbe.util; + +import java.util.ArrayList; +import java.util.List; + +import org.springframework.data.domain.Sort; + +import com.querydsl.core.types.Order; +import com.querydsl.core.types.OrderSpecifier; +import com.querydsl.core.types.Path; +import com.querydsl.core.types.dsl.Expressions; + +public class QueryDslUtil { + /** + * 정렬을 기준을 반환하기 위한 메소드. + * 여러 정렬 조건들을 반환할 수 있다. + * + * @param sort Sort 객체 + * @param parent compileQuerydsl 빌드를 통해서 생성된 Q타입 클래스의 객체(Sort의 대상이 되는 Q타입 클래스 객체를 전달한다.) + * @return + */ + public static OrderSpecifier[] getOrderSpecifier( + Sort sort, + Path parent + ) { + List orders = new ArrayList<>(); + + for (Sort.Order order : sort) { // Sort에 여러 정렬 기준이 담겨 올 수 있음 + Order direction = order.getDirection().isAscending() ? Order.ASC : Order.DESC; + orders.add(QueryDslUtil.getSortedColumn(direction, parent, order.getProperty())); + } + + return orders.toArray(OrderSpecifier[]::new); + } + + /** + * Order, Path, fieldName을 전달하면 OrderSpecifier 객체를 리턴하는 Util 클래스. + * Sort시 마다 사용할 수 있도록 한다. + * + * @param order + * @param parent compileQuerydsl 빌드를 통해서 생성된 Q타입 클래스의 객체(Sort의 대상이 되는 Q타입 클래스 객체를 전달한다.) + * @param fieldName + * @return OrderSpecifier 객체 + */ + public static OrderSpecifier getSortedColumn( + Order order, + Path parent, + String fieldName + ) { + Path fieldPath = Expressions.path(Object.class, parent, fieldName); + + return new OrderSpecifier(order, fieldPath); + } +} diff --git a/nabimarket-infra/build.gradle b/nabimarket-infra/build.gradle index df768a41..4ebfbb74 100644 --- a/nabimarket-infra/build.gradle +++ b/nabimarket-infra/build.gradle @@ -1,28 +1,6 @@ /** * Infra */ -plugins { - id "com.ewerk.gradle.plugins.querydsl" version "1.0.10" -} - -configurations { - querydsl.extendsFrom compileClasspath -} - -// Qtype 생성 경로 -def querydslDir = "$buildDir/generated/querydsl" -querydsl { - jpa = true - querydslSourcesDir = querydslDir -} -sourceSets { - main.java.srcDir querydslDir -} -compileQuerydsl { - options.annotationProcessorPath = configurations.querydsl -} - - dependencies { // redisson implementation "org.redisson:redisson-spring-boot-starter:3.21.1" diff --git a/nabimarket-infra/src/main/java/org/prgrms/nabimarketbe/util/KeyGenerator.java b/nabimarket-infra/src/main/java/org/prgrms/nabimarketbe/util/KeyGenerator.java new file mode 100644 index 00000000..1b5d122f --- /dev/null +++ b/nabimarket-infra/src/main/java/org/prgrms/nabimarketbe/util/KeyGenerator.java @@ -0,0 +1,33 @@ +package org.prgrms.nabimarketbe.util; + +public class KeyGenerator { + public static final String CARD_VIEW_CACHE_PREFIX = "CARD-VIEW-CACHE:"; + + private static final String CARD_VIEW_LOCK_PREFIX = "CARD-VIEW-LOCK:"; + + private static final String CARD_READER_CACHE_PREFIX = "CARD-READER-CACHE:"; + + private static final String SUGGESTION_CREATE_LOCK_PREFIX = "SUGGESTION-CREATE-LOCK:"; + + public static String generateSuggestionLockKey( + Long fromCardId, + Long toCardId + ) { + Long firstId = Math.min(fromCardId, toCardId); + Long secondId = Math.max(fromCardId, toCardId); + + return SUGGESTION_CREATE_LOCK_PREFIX + String.format("%d-%d", firstId, secondId); + } + + public static String generateCardViewLockKey(Long cardId) { + return CARD_VIEW_LOCK_PREFIX + cardId; + } + + public static String generateCardViewCacheKey(Long cardId) { + return CARD_VIEW_CACHE_PREFIX + cardId; + } + + public static String generateCardReaderCacheKey(Long userId) { + return CARD_READER_CACHE_PREFIX + userId; + } +}