From 42d349f75b6aa47713c028beb3b4bdd2baaebd8f Mon Sep 17 00:00:00 2001 From: haroya01 Date: Mon, 4 Sep 2023 12:43:50 +0900 Subject: [PATCH 01/22] =?UTF-8?q?feat=20:=20category=EA=B2=80=EC=83=89=20?= =?UTF-8?q?=EC=B4=88=EA=B8=B0=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/entity/AuctionStatus.java | 3 +-- .../repostiory/AuctionItemRepository.java | 24 ++++++++++++++++++- .../Search/AuctionItemSearchService.java | 15 ++++++++++++ .../Search/IAuctionItemSearchService.java | 16 ------------- 4 files changed, 39 insertions(+), 19 deletions(-) create mode 100644 src/main/java/megabrain/gyeongnamgyeongmae/auctionItem/service/Search/AuctionItemSearchService.java delete mode 100644 src/main/java/megabrain/gyeongnamgyeongmae/auctionItem/service/Search/IAuctionItemSearchService.java diff --git a/src/main/java/megabrain/gyeongnamgyeongmae/auctionItem/domain/entity/AuctionStatus.java b/src/main/java/megabrain/gyeongnamgyeongmae/auctionItem/domain/entity/AuctionStatus.java index 6734bc5..97e30bd 100644 --- a/src/main/java/megabrain/gyeongnamgyeongmae/auctionItem/domain/entity/AuctionStatus.java +++ b/src/main/java/megabrain/gyeongnamgyeongmae/auctionItem/domain/entity/AuctionStatus.java @@ -3,8 +3,7 @@ public enum AuctionStatus { ONGOING("진행중"), CLOSED("경매마감"), - BIDDING("입찰중"), - SOLD("낙찰완료"); + BIDDING("입찰중"); private final String status; diff --git a/src/main/java/megabrain/gyeongnamgyeongmae/auctionItem/domain/repostiory/AuctionItemRepository.java b/src/main/java/megabrain/gyeongnamgyeongmae/auctionItem/domain/repostiory/AuctionItemRepository.java index f775ed7..e9f0f64 100644 --- a/src/main/java/megabrain/gyeongnamgyeongmae/auctionItem/domain/repostiory/AuctionItemRepository.java +++ b/src/main/java/megabrain/gyeongnamgyeongmae/auctionItem/domain/repostiory/AuctionItemRepository.java @@ -1,6 +1,28 @@ package megabrain.gyeongnamgyeongmae.auctionItem.domain.repostiory; import megabrain.gyeongnamgyeongmae.auctionItem.domain.entity.AuctionItem; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.Pageable; import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.jpa.repository.Query; -public interface AuctionItemRepository extends JpaRepository {} +public interface AuctionItemRepository extends JpaRepository { + + // + @Query( + value = + "SELECT auctionItem FROM AuctionItem auctionItem WHERE auctionItem.category.id = :category") + Page searchAuctionItem( + // String searchStatus, + // boolean auctionStatus, + // String searchPrice, + // String searchTime, + // double latitude, + // double longitude, + // int km, + Long category, + // boolean like, + // boolean comment, + // boolean temperature, + Pageable pageable); +} diff --git a/src/main/java/megabrain/gyeongnamgyeongmae/auctionItem/service/Search/AuctionItemSearchService.java b/src/main/java/megabrain/gyeongnamgyeongmae/auctionItem/service/Search/AuctionItemSearchService.java new file mode 100644 index 0000000..db68f67 --- /dev/null +++ b/src/main/java/megabrain/gyeongnamgyeongmae/auctionItem/service/Search/AuctionItemSearchService.java @@ -0,0 +1,15 @@ +package megabrain.gyeongnamgyeongmae.auctionItem.service.Search; + +import megabrain.gyeongnamgyeongmae.auctionItem.dto.AuctionItemFirstView; +import megabrain.gyeongnamgyeongmae.auctionItem.dto.SearchItem.SearchAuctionItemSortedRequest; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.Pageable; + +public interface AuctionItemSearchService { + + Page findAuctionItembyRequest( + SearchAuctionItemSortedRequest searchAuctionItemSortedRequest, Pageable pageable); + + // void CheckAuctionItemSortedRequest(SearchAuctionItemSortedRequest + // searchAuctionItemSortedRequest); +} diff --git a/src/main/java/megabrain/gyeongnamgyeongmae/auctionItem/service/Search/IAuctionItemSearchService.java b/src/main/java/megabrain/gyeongnamgyeongmae/auctionItem/service/Search/IAuctionItemSearchService.java deleted file mode 100644 index dcc56ff..0000000 --- a/src/main/java/megabrain/gyeongnamgyeongmae/auctionItem/service/Search/IAuctionItemSearchService.java +++ /dev/null @@ -1,16 +0,0 @@ -package megabrain.gyeongnamgyeongmae.auctionItem.service.Search; - -import java.awt.print.Pageable; -import megabrain.gyeongnamgyeongmae.auctionItem.domain.entity.AuctionItem; -import megabrain.gyeongnamgyeongmae.auctionItem.domain.repostiory.AuctionItemRepository; -import megabrain.gyeongnamgyeongmae.member.domain.entity.Member; -import org.springframework.data.domain.Page; - -public interface IAuctionItemSearchService { - - public AuctionItemRepository findAllByMemberAddress(Member member, Pageable pageable); - - public AuctionItemRepository findAllByCategory(String category, Pageable pageable); - - public Page findAllByTimeLine(Pageable pageable); -} From 20f63204db7faf1125f44a2373a99927bba449fe Mon Sep 17 00:00:00 2001 From: haroya01 Date: Mon, 4 Sep 2023 20:11:22 +0900 Subject: [PATCH 02/22] =?UTF-8?q?feat=20:=20querydsl=ED=99=98=EA=B2=BD=20?= =?UTF-8?q?=EC=84=A4=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- build.gradle.kts | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) diff --git a/build.gradle.kts b/build.gradle.kts index e365b18..b64ee3d 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -1,12 +1,18 @@ +import com.ewerk.gradle.plugins.tasks.QuerydslCompile + plugins { java id("org.springframework.boot") version "2.7.14" id("io.spring.dependency-management") version "1.0.15.RELEASE" + id("com.ewerk.gradle.plugins.querydsl") version "1.0.10" + } group = "megabrain" version = "0.0.1-SNAPSHOT" +val queryDslVersion = "5.0.0" + java { sourceCompatibility = JavaVersion.VERSION_1_8 } @@ -16,6 +22,12 @@ repositories { mavenCentral() } +configurations { + compileOnly { + extendsFrom(configurations.annotationProcessor.get()) + } +} + dependencies { implementation("org.springframework.boot:spring-boot-starter-data-jpa") implementation("org.springframework.boot:spring-boot-starter-web") @@ -29,8 +41,42 @@ dependencies { annotationProcessor("org.projectlombok:lombok") testAnnotationProcessor("org.projectlombok:lombok") testImplementation("org.springframework.boot:spring-boot-starter-test") + + + + implementation("com.querydsl:querydsl-jpa:${queryDslVersion}") + annotationProcessor("com.querydsl:querydsl-apt:${queryDslVersion}") + + annotationProcessor("org.springframework.boot:spring-boot-configuration-processor") } tasks.withType { useJUnitPlatform() } + +val querydslDir = "$buildDir/generated/querydsl" // + +querydsl { + jpa = true + querydslSourcesDir = querydslDir +} +// 소스 루트 지정 +sourceSets { + main { + java { + srcDir(querydslDir) + + } + } +} + +configurations { + named("querydsl") { + extendsFrom(configurations.compileClasspath.get()) + } +} + +tasks.withType { + options.annotationProcessorPath = configurations.querydsl.get() +} + From 03b5a55508bfdf8ede53c13c8fa14390090aac7d Mon Sep 17 00:00:00 2001 From: haroya01 Date: Tue, 5 Sep 2023 15:00:37 +0900 Subject: [PATCH 03/22] =?UTF-8?q?fix=20:=20category,AuctionItem=EA=B0=84?= =?UTF-8?q?=EC=9D=98=20=EA=B4=80=EA=B3=84=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../auctionItem/domain/entity/AuctionItem.java | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/main/java/megabrain/gyeongnamgyeongmae/auctionItem/domain/entity/AuctionItem.java b/src/main/java/megabrain/gyeongnamgyeongmae/auctionItem/domain/entity/AuctionItem.java index 44c3787..af7b89a 100644 --- a/src/main/java/megabrain/gyeongnamgyeongmae/auctionItem/domain/entity/AuctionItem.java +++ b/src/main/java/megabrain/gyeongnamgyeongmae/auctionItem/domain/entity/AuctionItem.java @@ -13,7 +13,7 @@ @Entity @Table(name = "AuctionItem") @NoArgsConstructor(access = AccessLevel.PROTECTED) -public class AuctionItem extends BaseTimeEntity { +public class AuctionItem extends BaseTimeEntity { @Id @GeneratedValue(strategy = GenerationType.IDENTITY) @@ -32,7 +32,7 @@ public class AuctionItem extends BaseTimeEntity { @Embedded private Content content; - @OneToOne(fetch = FetchType.EAGER) + @ManyToOne(fetch = FetchType.EAGER) @JoinColumn(name = "category_id") private Category category; @@ -48,6 +48,13 @@ public class AuctionItem extends BaseTimeEntity { @Column(name = "auction_status") @Enumerated(EnumType.STRING) private AuctionStatus status = AuctionStatus.ONGOING; +// +// @OneToOne(fetch = FetchType.EAGER) +// @JoinColumn(name = "location_id") +// private Location location; + + @Column + private Long temperature; @Builder public AuctionItem(Long id, String name, int price, Content content, LocalDateTime closedTime) { From 044150b3771a0212d34f66c49b181270d479bb69 Mon Sep 17 00:00:00 2001 From: haroya01 Date: Tue, 5 Sep 2023 16:39:32 +0900 Subject: [PATCH 04/22] =?UTF-8?q?feat=20:=20=EA=B2=8C=EC=8B=9C=EA=B8=80=20?= =?UTF-8?q?Category=EB=A1=9C=20=EC=A1=B0=ED=9A=8C=20=EA=B8=B0=EB=8A=A5=20?= =?UTF-8?q?=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/AuctionItemSearch.java | 38 ++++++++++++++ .../AuctionItemRepositoryCustom.java | 12 +++++ .../AuctionItemRepositoryCustomImpl.java | 43 ++++++++++++++++ .../auctionItem/dto/AuctionItemFirstView.java | 50 +++++++++++++++++++ .../SearchAuctionItemSortedRequest.java | 32 ++++++++++++ .../dto/SearchItem/SearchPrice.java | 7 +++ .../dto/SearchItem/SearchStatus.java | 7 +++ .../dto/SearchItem/SearchTime.java | 7 +++ .../Search/AuctionItemSearchServiceImpl.java | 29 +++++++++++ .../commons/config/QueryDslConfig.java | 18 +++++++ 10 files changed, 243 insertions(+) create mode 100644 src/main/java/megabrain/gyeongnamgyeongmae/auctionItem/controller/AuctionItemSearch.java create mode 100644 src/main/java/megabrain/gyeongnamgyeongmae/auctionItem/domain/repostiory/AuctionItemRepositoryCustom.java create mode 100644 src/main/java/megabrain/gyeongnamgyeongmae/auctionItem/domain/repostiory/AuctionItemRepositoryCustomImpl.java create mode 100644 src/main/java/megabrain/gyeongnamgyeongmae/auctionItem/dto/AuctionItemFirstView.java create mode 100644 src/main/java/megabrain/gyeongnamgyeongmae/auctionItem/dto/SearchItem/SearchAuctionItemSortedRequest.java create mode 100644 src/main/java/megabrain/gyeongnamgyeongmae/auctionItem/dto/SearchItem/SearchPrice.java create mode 100644 src/main/java/megabrain/gyeongnamgyeongmae/auctionItem/dto/SearchItem/SearchStatus.java create mode 100644 src/main/java/megabrain/gyeongnamgyeongmae/auctionItem/dto/SearchItem/SearchTime.java create mode 100644 src/main/java/megabrain/gyeongnamgyeongmae/auctionItem/service/Search/AuctionItemSearchServiceImpl.java create mode 100644 src/main/java/megabrain/gyeongnamgyeongmae/commons/config/QueryDslConfig.java diff --git a/src/main/java/megabrain/gyeongnamgyeongmae/auctionItem/controller/AuctionItemSearch.java b/src/main/java/megabrain/gyeongnamgyeongmae/auctionItem/controller/AuctionItemSearch.java new file mode 100644 index 0000000..8badf02 --- /dev/null +++ b/src/main/java/megabrain/gyeongnamgyeongmae/auctionItem/controller/AuctionItemSearch.java @@ -0,0 +1,38 @@ +package megabrain.gyeongnamgyeongmae.auctionItem.controller; + +import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.tags.Tag; +import javax.validation.Valid; +import lombok.RequiredArgsConstructor; +import megabrain.gyeongnamgyeongmae.auctionItem.domain.repostiory.AuctionItemRepository; +import megabrain.gyeongnamgyeongmae.auctionItem.dto.AuctionItemFirstView; +import megabrain.gyeongnamgyeongmae.auctionItem.dto.SearchItem.SearchAuctionItemSortedRequest; +import megabrain.gyeongnamgyeongmae.auctionItem.service.Search.AuctionItemSearchServiceImpl; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.Pageable; +import org.springframework.http.ResponseEntity; +import org.springframework.transaction.annotation.Transactional; +import org.springframework.web.bind.annotation.*; + +@Tag(name = "경매품 검색", description = "경매품 검색 관련 API") +@RequestMapping("api/auctions/search") +@RestController +@RequiredArgsConstructor +public class AuctionItemSearch { + + private final AuctionItemSearchServiceImpl auctionItemSearchServiceImpl; + private final AuctionItemRepository auctionItemRepository; + + @Operation(summary = "Search AuctionItem", description = "경매품 검색하기") + @PostMapping("") + @Transactional(readOnly = true) + public ResponseEntity> findItemCategory( + @RequestBody @Valid SearchAuctionItemSortedRequest searchAuctionItemSortedRequest, + Pageable pageable) { + Page result = + auctionItemSearchServiceImpl.findAuctionItembyRequest( + searchAuctionItemSortedRequest, pageable); + + return ResponseEntity.ok(result); + } +} diff --git a/src/main/java/megabrain/gyeongnamgyeongmae/auctionItem/domain/repostiory/AuctionItemRepositoryCustom.java b/src/main/java/megabrain/gyeongnamgyeongmae/auctionItem/domain/repostiory/AuctionItemRepositoryCustom.java new file mode 100644 index 0000000..9e18cdf --- /dev/null +++ b/src/main/java/megabrain/gyeongnamgyeongmae/auctionItem/domain/repostiory/AuctionItemRepositoryCustom.java @@ -0,0 +1,12 @@ +package megabrain.gyeongnamgyeongmae.auctionItem.domain.repostiory; + +import megabrain.gyeongnamgyeongmae.auctionItem.domain.entity.AuctionItem; +import megabrain.gyeongnamgyeongmae.auctionItem.dto.SearchItem.SearchAuctionItemSortedRequest; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.Pageable; + +public interface AuctionItemRepositoryCustom { + + Page searchAuctionItemPage( + SearchAuctionItemSortedRequest searchAuctionItemSortedRequest, Pageable pageable); +} diff --git a/src/main/java/megabrain/gyeongnamgyeongmae/auctionItem/domain/repostiory/AuctionItemRepositoryCustomImpl.java b/src/main/java/megabrain/gyeongnamgyeongmae/auctionItem/domain/repostiory/AuctionItemRepositoryCustomImpl.java new file mode 100644 index 0000000..b0ca9c2 --- /dev/null +++ b/src/main/java/megabrain/gyeongnamgyeongmae/auctionItem/domain/repostiory/AuctionItemRepositoryCustomImpl.java @@ -0,0 +1,43 @@ +package megabrain.gyeongnamgyeongmae.auctionItem.domain.repostiory; + +import static megabrain.gyeongnamgyeongmae.Category.domain.entity.QCategory.category; +import static megabrain.gyeongnamgyeongmae.auctionItem.domain.entity.QAuctionItem.auctionItem; + +import com.querydsl.jpa.impl.JPAQueryFactory; +import java.util.List; +import javax.persistence.EntityManager; +import megabrain.gyeongnamgyeongmae.Category.domain.entity.QCategory; +import megabrain.gyeongnamgyeongmae.auctionItem.domain.entity.AuctionItem; +import megabrain.gyeongnamgyeongmae.auctionItem.domain.entity.QAuctionItem; +import megabrain.gyeongnamgyeongmae.auctionItem.dto.SearchItem.SearchAuctionItemSortedRequest; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.PageImpl; +import org.springframework.data.domain.Pageable; + +public class AuctionItemRepositoryCustomImpl implements AuctionItemRepositoryCustom { + + private final JPAQueryFactory queryFactory; + + public AuctionItemRepositoryCustomImpl(EntityManager em) { + this.queryFactory = new JPAQueryFactory(em); + } + + @Override + public Page searchAuctionItemPage( + SearchAuctionItemSortedRequest searchAuctionItemSortedRequest, Pageable pageable) { + + QAuctionItem auctionItem = QAuctionItem.auctionItem; + QCategory category = QCategory.category; + + List results = + queryFactory + .selectFrom(auctionItem) + .innerJoin(auctionItem.category, category) + .where(category.name.eq(searchAuctionItemSortedRequest.getCategory())) + .offset(pageable.getOffset()) + .limit(pageable.getPageSize()) + .fetch(); + + return new PageImpl<>(results, pageable, results.size()); + } +} diff --git a/src/main/java/megabrain/gyeongnamgyeongmae/auctionItem/dto/AuctionItemFirstView.java b/src/main/java/megabrain/gyeongnamgyeongmae/auctionItem/dto/AuctionItemFirstView.java new file mode 100644 index 0000000..ea92417 --- /dev/null +++ b/src/main/java/megabrain/gyeongnamgyeongmae/auctionItem/dto/AuctionItemFirstView.java @@ -0,0 +1,50 @@ +package megabrain.gyeongnamgyeongmae.auctionItem.dto; + +import java.time.LocalDateTime; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Getter; +import lombok.NoArgsConstructor; +import megabrain.gyeongnamgyeongmae.auctionItem.domain.entity.AuctionItem; +import megabrain.gyeongnamgyeongmae.auctionItem.domain.entity.AuctionItemStatus; +import megabrain.gyeongnamgyeongmae.auctionItem.domain.entity.AuctionStatus; +import megabrain.gyeongnamgyeongmae.member.domain.entity.Address; + +@Builder +@Getter +@NoArgsConstructor +@AllArgsConstructor +public class AuctionItemFirstView { + + private Long id; + + private String name; + + private LocalDateTime closedTime; + + private AuctionItemStatus auctionItemStatus; + + private AuctionStatus status; + + private Address address; + + private int like_count; + + private int view_count; + + private int price; + + public static AuctionItemFirstView of(AuctionItem auctionItem) { + return AuctionItemFirstView.builder() + .id(auctionItem.getId()) + .name(auctionItem.getName()) + .address(auctionItem.getMember().getAddress()) + .like_count(auctionItem.getLike_count()) + .view_count(auctionItem.getView_count()) + .price(auctionItem.getPrice()) + .closedTime(auctionItem.getClosedTime()) + .auctionItemStatus(auctionItem.getContent().getStatus()) + .status(auctionItem.getStatus()) + .build(); + } +} diff --git a/src/main/java/megabrain/gyeongnamgyeongmae/auctionItem/dto/SearchItem/SearchAuctionItemSortedRequest.java b/src/main/java/megabrain/gyeongnamgyeongmae/auctionItem/dto/SearchItem/SearchAuctionItemSortedRequest.java new file mode 100644 index 0000000..9d6c740 --- /dev/null +++ b/src/main/java/megabrain/gyeongnamgyeongmae/auctionItem/dto/SearchItem/SearchAuctionItemSortedRequest.java @@ -0,0 +1,32 @@ +package megabrain.gyeongnamgyeongmae.auctionItem.dto.SearchItem; + +import javax.validation.constraints.NotNull; +import lombok.Getter; + +@Getter +public class SearchAuctionItemSortedRequest { + + // @NotNull private SearchStatus search_status; // 신품 중고품 전체 + + // @NotNull private boolean closed; // 이미 경매가 끝낸 개시글도 보기 + + // @NotNull private SearchTime search_time; // 마감시간 근접, 멀리 + + // @NotNull private Location my_location; // 나의 현재 위치 + + // @NotNull private int km; // 몇키로 반경 게시글 조회 + // + // @NotNull private int town; // 몇개의 마을 조회 + + @NotNull private String category; // 카테고리 + + // private String member; // 이름 검색 + // + // private boolean like; // 좋아요 정렬 기준 + // + // private boolean comment; // 댓글수 정렬 기준 + // + // private boolean temperature; // 온도별 정렬 기준 + + // @NotNull private SearchPrice search_price; // 가격순 정렬 +} diff --git a/src/main/java/megabrain/gyeongnamgyeongmae/auctionItem/dto/SearchItem/SearchPrice.java b/src/main/java/megabrain/gyeongnamgyeongmae/auctionItem/dto/SearchItem/SearchPrice.java new file mode 100644 index 0000000..d684e19 --- /dev/null +++ b/src/main/java/megabrain/gyeongnamgyeongmae/auctionItem/dto/SearchItem/SearchPrice.java @@ -0,0 +1,7 @@ +package megabrain.gyeongnamgyeongmae.auctionItem.dto.SearchItem; + +public enum SearchPrice { + LOW, + HIGH, + ALL +} diff --git a/src/main/java/megabrain/gyeongnamgyeongmae/auctionItem/dto/SearchItem/SearchStatus.java b/src/main/java/megabrain/gyeongnamgyeongmae/auctionItem/dto/SearchItem/SearchStatus.java new file mode 100644 index 0000000..4b28c81 --- /dev/null +++ b/src/main/java/megabrain/gyeongnamgyeongmae/auctionItem/dto/SearchItem/SearchStatus.java @@ -0,0 +1,7 @@ +package megabrain.gyeongnamgyeongmae.auctionItem.dto.SearchItem; + +public enum SearchStatus { + NEW, + USED, + ALL +} diff --git a/src/main/java/megabrain/gyeongnamgyeongmae/auctionItem/dto/SearchItem/SearchTime.java b/src/main/java/megabrain/gyeongnamgyeongmae/auctionItem/dto/SearchItem/SearchTime.java new file mode 100644 index 0000000..21406b2 --- /dev/null +++ b/src/main/java/megabrain/gyeongnamgyeongmae/auctionItem/dto/SearchItem/SearchTime.java @@ -0,0 +1,7 @@ +package megabrain.gyeongnamgyeongmae.auctionItem.dto.SearchItem; + +public enum SearchTime { + NEAR, + FAR, + ALL +} diff --git a/src/main/java/megabrain/gyeongnamgyeongmae/auctionItem/service/Search/AuctionItemSearchServiceImpl.java b/src/main/java/megabrain/gyeongnamgyeongmae/auctionItem/service/Search/AuctionItemSearchServiceImpl.java new file mode 100644 index 0000000..83e4070 --- /dev/null +++ b/src/main/java/megabrain/gyeongnamgyeongmae/auctionItem/service/Search/AuctionItemSearchServiceImpl.java @@ -0,0 +1,29 @@ +package megabrain.gyeongnamgyeongmae.auctionItem.service.Search; + +import lombok.RequiredArgsConstructor; +import megabrain.gyeongnamgyeongmae.Category.service.CategoryService; +import megabrain.gyeongnamgyeongmae.auctionItem.domain.entity.AuctionItem; +import megabrain.gyeongnamgyeongmae.auctionItem.domain.repostiory.AuctionItemRepository; +import megabrain.gyeongnamgyeongmae.auctionItem.dto.AuctionItemFirstView; +import megabrain.gyeongnamgyeongmae.auctionItem.dto.SearchItem.SearchAuctionItemSortedRequest; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.Pageable; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +@Service +@RequiredArgsConstructor +public class AuctionItemSearchServiceImpl implements AuctionItemSearchService { + + private final CategoryService categoryService; + private final AuctionItemRepository auctionItemRepository; + + @Override + @Transactional(readOnly = true) + public Page findAuctionItembyRequest( + SearchAuctionItemSortedRequest searchAuctionItemSortedRequest, Pageable pageable) { + Page auctionItemEntityList = + auctionItemRepository.searchAuctionItemPage(searchAuctionItemSortedRequest, pageable); + return auctionItemEntityList.map(AuctionItemFirstView::of); + } +} diff --git a/src/main/java/megabrain/gyeongnamgyeongmae/commons/config/QueryDslConfig.java b/src/main/java/megabrain/gyeongnamgyeongmae/commons/config/QueryDslConfig.java new file mode 100644 index 0000000..f219b4a --- /dev/null +++ b/src/main/java/megabrain/gyeongnamgyeongmae/commons/config/QueryDslConfig.java @@ -0,0 +1,18 @@ +package megabrain.gyeongnamgyeongmae.commons.config; + +import com.querydsl.jpa.impl.JPAQueryFactory; +import javax.persistence.EntityManager; +import javax.persistence.PersistenceContext; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; + +@Configuration +public class QueryDslConfig { + + @PersistenceContext private EntityManager entityManager; + + @Bean + public JPAQueryFactory JPAQueryFactory() { + return new JPAQueryFactory(entityManager); + } +} From 294a2b20401404fc88b2f87d864efd1b7c813a70 Mon Sep 17 00:00:00 2001 From: haroya01 Date: Tue, 5 Sep 2023 20:23:02 +0900 Subject: [PATCH 05/22] =?UTF-8?q?feat=20:=20=EA=B2=8C=EC=8B=9C=EA=B8=80=20?= =?UTF-8?q?=EC=A0=95=EB=A0=AC=20=EC=A1=B0=EA=B1=B4=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/AuctionItemController.java | 16 ++-- .../repostiory/AuctionItemRepository.java | 25 +----- .../AuctionItemRepositoryCustomImpl.java | 39 +++++++++- .../SearchAuctionItemSortedRequest.java | 25 +++--- .../service/Item/AuctionItemService.java | 70 ++--------------- .../service/Item/AuctionItemServiceImpl.java | 78 +++++++++++++++++++ .../controller/AuctionControllerTest.java | 10 +-- 7 files changed, 148 insertions(+), 115 deletions(-) create mode 100644 src/main/java/megabrain/gyeongnamgyeongmae/auctionItem/service/Item/AuctionItemServiceImpl.java diff --git a/src/main/java/megabrain/gyeongnamgyeongmae/auctionItem/controller/AuctionItemController.java b/src/main/java/megabrain/gyeongnamgyeongmae/auctionItem/controller/AuctionItemController.java index be912ba..b9c911b 100644 --- a/src/main/java/megabrain/gyeongnamgyeongmae/auctionItem/controller/AuctionItemController.java +++ b/src/main/java/megabrain/gyeongnamgyeongmae/auctionItem/controller/AuctionItemController.java @@ -2,14 +2,11 @@ import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.tags.Tag; -import javax.transaction.Transactional; import javax.validation.Valid; import lombok.RequiredArgsConstructor; import megabrain.gyeongnamgyeongmae.Category.service.CategoryService; -import megabrain.gyeongnamgyeongmae.auctionItem.dto.AuctionItemResponse; -import megabrain.gyeongnamgyeongmae.auctionItem.dto.CreateAuctionItemRequest; -import megabrain.gyeongnamgyeongmae.auctionItem.dto.UpdateAuctionItemRequest; -import megabrain.gyeongnamgyeongmae.auctionItem.service.Item.AuctionItemService; +import megabrain.gyeongnamgyeongmae.auctionItem.dto.*; +import megabrain.gyeongnamgyeongmae.auctionItem.service.Item.AuctionItemServiceImpl; import megabrain.gyeongnamgyeongmae.member.service.MemberService; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; @@ -21,7 +18,7 @@ @RequiredArgsConstructor public class AuctionItemController { - private final AuctionItemService auctionItemService; + private final AuctionItemServiceImpl auctionItemServiceImpl; private final CategoryService categoryService; private final MemberService memberService; @@ -30,23 +27,22 @@ public class AuctionItemController { @PostMapping() public ResponseEntity createAuctionItem( @RequestBody @Valid CreateAuctionItemRequest createAuctionItemRequest) { - auctionItemService.createAuctionItem(createAuctionItemRequest); + auctionItemServiceImpl.createAuctionItem(createAuctionItemRequest); return ResponseEntity.status(HttpStatus.CREATED).build(); } @Operation(summary = "Show AuctionItem", description = "경매품 상세보기") @GetMapping("{id}") public ResponseEntity findAuctionItemById(@PathVariable Long id) { - AuctionItemResponse auctionItemResponse = auctionItemService.findAuctionItemById(id); + AuctionItemResponse auctionItemResponse = auctionItemServiceImpl.findAuctionItemById(id); return ResponseEntity.ok(auctionItemResponse); } @Operation(summary = "Update AuctionItem", description = "경매품 수정하기") @PutMapping() - @Transactional public ResponseEntity updateAuctionItemById( @RequestBody @Valid UpdateAuctionItemRequest upDateAuctionItemRequest) { - auctionItemService.updateAuctionItem(upDateAuctionItemRequest); + auctionItemServiceImpl.updateAuctionItem(upDateAuctionItemRequest); return ResponseEntity.status(HttpStatus.OK).build(); } } diff --git a/src/main/java/megabrain/gyeongnamgyeongmae/auctionItem/domain/repostiory/AuctionItemRepository.java b/src/main/java/megabrain/gyeongnamgyeongmae/auctionItem/domain/repostiory/AuctionItemRepository.java index e9f0f64..f553d7b 100644 --- a/src/main/java/megabrain/gyeongnamgyeongmae/auctionItem/domain/repostiory/AuctionItemRepository.java +++ b/src/main/java/megabrain/gyeongnamgyeongmae/auctionItem/domain/repostiory/AuctionItemRepository.java @@ -1,28 +1,7 @@ package megabrain.gyeongnamgyeongmae.auctionItem.domain.repostiory; import megabrain.gyeongnamgyeongmae.auctionItem.domain.entity.AuctionItem; -import org.springframework.data.domain.Page; -import org.springframework.data.domain.Pageable; import org.springframework.data.jpa.repository.JpaRepository; -import org.springframework.data.jpa.repository.Query; -public interface AuctionItemRepository extends JpaRepository { - - // - @Query( - value = - "SELECT auctionItem FROM AuctionItem auctionItem WHERE auctionItem.category.id = :category") - Page searchAuctionItem( - // String searchStatus, - // boolean auctionStatus, - // String searchPrice, - // String searchTime, - // double latitude, - // double longitude, - // int km, - Long category, - // boolean like, - // boolean comment, - // boolean temperature, - Pageable pageable); -} +public interface AuctionItemRepository + extends JpaRepository, AuctionItemRepositoryCustom {} diff --git a/src/main/java/megabrain/gyeongnamgyeongmae/auctionItem/domain/repostiory/AuctionItemRepositoryCustomImpl.java b/src/main/java/megabrain/gyeongnamgyeongmae/auctionItem/domain/repostiory/AuctionItemRepositoryCustomImpl.java index b0ca9c2..84fe85b 100644 --- a/src/main/java/megabrain/gyeongnamgyeongmae/auctionItem/domain/repostiory/AuctionItemRepositoryCustomImpl.java +++ b/src/main/java/megabrain/gyeongnamgyeongmae/auctionItem/domain/repostiory/AuctionItemRepositoryCustomImpl.java @@ -1,9 +1,11 @@ package megabrain.gyeongnamgyeongmae.auctionItem.domain.repostiory; -import static megabrain.gyeongnamgyeongmae.Category.domain.entity.QCategory.category; import static megabrain.gyeongnamgyeongmae.auctionItem.domain.entity.QAuctionItem.auctionItem; +import com.querydsl.core.types.OrderSpecifier; +import com.querydsl.jpa.impl.JPAQuery; import com.querydsl.jpa.impl.JPAQueryFactory; +import java.util.ArrayList; import java.util.List; import javax.persistence.EntityManager; import megabrain.gyeongnamgyeongmae.Category.domain.entity.QCategory; @@ -29,15 +31,46 @@ public Page searchAuctionItemPage( QAuctionItem auctionItem = QAuctionItem.auctionItem; QCategory category = QCategory.category; - List results = + List> orderSpecifiers = new ArrayList<>(); + + if (searchAuctionItemSortedRequest.isLike()) { + orderSpecifiers.add(auctionItem.like_count.desc()); + } + if (searchAuctionItemSortedRequest.isView_count()) { + orderSpecifiers.add(auctionItem.view_count.desc()); + } + if (searchAuctionItemSortedRequest.isSearch_price()) { + orderSpecifiers.add(auctionItem.price.desc()); + } + JPAQuery query = queryFactory .selectFrom(auctionItem) .innerJoin(auctionItem.category, category) - .where(category.name.eq(searchAuctionItemSortedRequest.getCategory())) + .where(category.name.eq(searchAuctionItemSortedRequest.getCategory())); + + List results = + query + .orderBy(orderSpecifiers.toArray(new OrderSpecifier[0])) .offset(pageable.getOffset()) .limit(pageable.getPageSize()) .fetch(); return new PageImpl<>(results, pageable, results.size()); } + + // public checkSort(SearchAuctionItemSortedRequest.Sort sort) { + } + +// SearchAuctionItemSortedRequest.Sort a = searchAuctionItemSortedRequest.getSort(); +// List results = +// queryFactory +// .selectFrom(auctionItem) +// .innerJoin(auctionItem.category, category) +// .where(category.name.eq(searchAuctionItemSortedRequest.getCategory())) +// .orderBy(sort) +// .offset(pageable.getOffset()) +// .limit(pageable.getPageSize()) +// .fetch(); + +// .orderBy(auctionItem.like_count.asc()) diff --git a/src/main/java/megabrain/gyeongnamgyeongmae/auctionItem/dto/SearchItem/SearchAuctionItemSortedRequest.java b/src/main/java/megabrain/gyeongnamgyeongmae/auctionItem/dto/SearchItem/SearchAuctionItemSortedRequest.java index 9d6c740..e2f4a85 100644 --- a/src/main/java/megabrain/gyeongnamgyeongmae/auctionItem/dto/SearchItem/SearchAuctionItemSortedRequest.java +++ b/src/main/java/megabrain/gyeongnamgyeongmae/auctionItem/dto/SearchItem/SearchAuctionItemSortedRequest.java @@ -10,7 +10,7 @@ public class SearchAuctionItemSortedRequest { // @NotNull private boolean closed; // 이미 경매가 끝낸 개시글도 보기 - // @NotNull private SearchTime search_time; // 마감시간 근접, 멀리 + // @ NotNull private SearchTime search_time; // 마감시간 근접, 멀리 // @NotNull private Location my_location; // 나의 현재 위치 @@ -18,15 +18,20 @@ public class SearchAuctionItemSortedRequest { // // @NotNull private int town; // 몇개의 마을 조회 - @NotNull private String category; // 카테고리 + @NotNull private String category; // 카테고리 검색 - // private String member; // 이름 검색 - // - // private boolean like; // 좋아요 정렬 기준 - // - // private boolean comment; // 댓글수 정렬 기준 - // - // private boolean temperature; // 온도별 정렬 기준 + @NotNull private boolean like; // 좋아요 정렬 기준 + + @NotNull private boolean search_price; // 가격순 정렬 + + @NotNull private boolean comment; // 댓글수 정렬 기준 + + @NotNull private boolean view_count; // 조회수 정렬 기준 + + // @NotNull private String member; // 이름 검색 + + // @NotNull private boolean temperature; // 온도별 정렬 기준 + + // 기본값 오름차순 정렬 - // @NotNull private SearchPrice search_price; // 가격순 정렬 } diff --git a/src/main/java/megabrain/gyeongnamgyeongmae/auctionItem/service/Item/AuctionItemService.java b/src/main/java/megabrain/gyeongnamgyeongmae/auctionItem/service/Item/AuctionItemService.java index a66873d..ae3fbb7 100644 --- a/src/main/java/megabrain/gyeongnamgyeongmae/auctionItem/service/Item/AuctionItemService.java +++ b/src/main/java/megabrain/gyeongnamgyeongmae/auctionItem/service/Item/AuctionItemService.java @@ -1,78 +1,20 @@ package megabrain.gyeongnamgyeongmae.auctionItem.service.Item; import java.time.LocalDateTime; -import lombok.RequiredArgsConstructor; -import megabrain.gyeongnamgyeongmae.Category.domain.entity.Category; -import megabrain.gyeongnamgyeongmae.Category.domain.repository.CategoryRepository; -import megabrain.gyeongnamgyeongmae.Category.service.CategoryService; import megabrain.gyeongnamgyeongmae.auctionItem.domain.entity.AuctionItem; -import megabrain.gyeongnamgyeongmae.auctionItem.domain.repostiory.AuctionItemRepository; import megabrain.gyeongnamgyeongmae.auctionItem.dto.AuctionItemResponse; import megabrain.gyeongnamgyeongmae.auctionItem.dto.CreateAuctionItemRequest; import megabrain.gyeongnamgyeongmae.auctionItem.dto.UpdateAuctionItemRequest; -import megabrain.gyeongnamgyeongmae.member.domain.entity.Member; -import megabrain.gyeongnamgyeongmae.member.domain.repository.MemberRepository; -import megabrain.gyeongnamgyeongmae.member.service.MemberService; -import org.springframework.stereotype.Service; -import org.springframework.transaction.annotation.Transactional; -@Service -@RequiredArgsConstructor -public class AuctionItemService implements IAuctionItemService { +public interface AuctionItemService { - private final AuctionItemRepository auctionItemRepository; - private final CategoryService categoryService; - private final MemberRepository memberRepository; - private final CategoryRepository categoryRepository; - private final MemberService memberService; + void createAuctionItem(CreateAuctionItemRequest createAuctionItemRequest); - @Override - @Transactional - public void createAuctionItem(CreateAuctionItemRequest createAuctionItemRequest) { - checkClosedTime(createAuctionItemRequest.getClosedTime()); - Member memberEntity = memberService.findMemberById(createAuctionItemRequest.getMember()); - Category categoryEntity = - categoryService.findCategoryByName(createAuctionItemRequest.getCategory()); - AuctionItem auctionItem = createAuctionItemRequest.toEntity(); - auctionItem.setMember(memberEntity); - auctionItem.setCategory(categoryEntity); - auctionItemRepository.save(auctionItem); - } + AuctionItemResponse findAuctionItemById(Long id); - @Override - @Transactional - public AuctionItemResponse findAuctionItemById(Long id) { - AuctionItem auctionItem = auctionItemRepository.findById(id).orElseThrow(RuntimeException::new); - updateAuctionItemViewCount(auctionItem); - return AuctionItemResponse.of(auctionItem); - } + void updateAuctionItemViewCount(AuctionItem auctionItem); - @Override - public void updateAuctionItemViewCount(AuctionItem auctionItem) { - auctionItem.setView_count(auctionItem.getView_count() + 1); - auctionItemRepository.save(auctionItem); - } + void updateAuctionItem(UpdateAuctionItemRequest upDateAuctionItemRequest); - @Override - @Transactional - public void updateAuctionItem(UpdateAuctionItemRequest upDateAuctionItemRequest) { - checkClosedTime(upDateAuctionItemRequest.getClosedTime()); - Category categoryEntity = - categoryService.findCategoryByName(upDateAuctionItemRequest.getCategory()); - AuctionItem auctionItem = - auctionItemRepository - .findById(upDateAuctionItemRequest.getId()) - .orElseThrow(RuntimeException::new); - auctionItem.updateAuctionItem(upDateAuctionItemRequest); - auctionItem.setCategory(categoryEntity); - auctionItemRepository.save(auctionItem); - } - - @Override - public void checkClosedTime(LocalDateTime closedTime) { - LocalDateTime now = LocalDateTime.now(); - if (closedTime.isBefore(now.plusHours(24))) { - throw new RuntimeException("경매 종료 시간은 현재 시간보다 24시간 이후여야 합니다."); - } - } + void checkClosedTime(LocalDateTime closedTime); } diff --git a/src/main/java/megabrain/gyeongnamgyeongmae/auctionItem/service/Item/AuctionItemServiceImpl.java b/src/main/java/megabrain/gyeongnamgyeongmae/auctionItem/service/Item/AuctionItemServiceImpl.java new file mode 100644 index 0000000..5424ac4 --- /dev/null +++ b/src/main/java/megabrain/gyeongnamgyeongmae/auctionItem/service/Item/AuctionItemServiceImpl.java @@ -0,0 +1,78 @@ +package megabrain.gyeongnamgyeongmae.auctionItem.service.Item; + +import java.time.LocalDateTime; +import lombok.RequiredArgsConstructor; +import megabrain.gyeongnamgyeongmae.Category.domain.entity.Category; +import megabrain.gyeongnamgyeongmae.Category.domain.repository.CategoryRepository; +import megabrain.gyeongnamgyeongmae.Category.service.CategoryService; +import megabrain.gyeongnamgyeongmae.auctionItem.domain.entity.AuctionItem; +import megabrain.gyeongnamgyeongmae.auctionItem.domain.repostiory.AuctionItemRepository; +import megabrain.gyeongnamgyeongmae.auctionItem.dto.AuctionItemResponse; +import megabrain.gyeongnamgyeongmae.auctionItem.dto.CreateAuctionItemRequest; +import megabrain.gyeongnamgyeongmae.auctionItem.dto.UpdateAuctionItemRequest; +import megabrain.gyeongnamgyeongmae.member.domain.entity.Member; +import megabrain.gyeongnamgyeongmae.member.domain.repository.MemberRepository; +import megabrain.gyeongnamgyeongmae.member.service.MemberService; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +@Service +@RequiredArgsConstructor +public class AuctionItemServiceImpl implements AuctionItemService { + + private final AuctionItemRepository auctionItemRepository; + private final CategoryService categoryService; + private final MemberRepository memberRepository; + private final CategoryRepository categoryRepository; + private final MemberService memberService; + + @Override + @Transactional + public void createAuctionItem(CreateAuctionItemRequest createAuctionItemRequest) { + checkClosedTime(createAuctionItemRequest.getClosedTime()); + Member memberEntity = memberService.findMemberById(createAuctionItemRequest.getMember()); + Category categoryEntity = + categoryService.findCategoryByName(createAuctionItemRequest.getCategory()); + AuctionItem auctionItem = createAuctionItemRequest.toEntity(); + auctionItem.setMember(memberEntity); + auctionItem.setCategory(categoryEntity); + auctionItemRepository.save(auctionItem); + } + + @Override + @Transactional + public AuctionItemResponse findAuctionItemById(Long id) { + AuctionItem auctionItem = auctionItemRepository.findById(id).orElseThrow(RuntimeException::new); + updateAuctionItemViewCount(auctionItem); + return AuctionItemResponse.of(auctionItem); + } + + @Override + public void updateAuctionItemViewCount(AuctionItem auctionItem) { + auctionItem.setView_count(auctionItem.getView_count() + 1); + auctionItemRepository.save(auctionItem); + } + + @Override + @Transactional + public void updateAuctionItem(UpdateAuctionItemRequest upDateAuctionItemRequest) { + checkClosedTime(upDateAuctionItemRequest.getClosedTime()); + Category categoryEntity = + categoryService.findCategoryByName(upDateAuctionItemRequest.getCategory()); + AuctionItem auctionItem = + auctionItemRepository + .findById(upDateAuctionItemRequest.getId()) + .orElseThrow(RuntimeException::new); + auctionItem.updateAuctionItem(upDateAuctionItemRequest); + auctionItem.setCategory(categoryEntity); + auctionItemRepository.save(auctionItem); + } + + @Override + public void checkClosedTime(LocalDateTime closedTime) { + LocalDateTime now = LocalDateTime.now(); + if (closedTime.isBefore(now.plusHours(24))) { + throw new RuntimeException("경매 종료 시간은 현재 시간보다 24시간 이후여야 합니다."); + } + } +} diff --git a/src/test/java/megabrain/gyeongnamgyeongmae/auctionItem/controller/AuctionControllerTest.java b/src/test/java/megabrain/gyeongnamgyeongmae/auctionItem/controller/AuctionControllerTest.java index e73f6bb..33d8418 100644 --- a/src/test/java/megabrain/gyeongnamgyeongmae/auctionItem/controller/AuctionControllerTest.java +++ b/src/test/java/megabrain/gyeongnamgyeongmae/auctionItem/controller/AuctionControllerTest.java @@ -20,7 +20,7 @@ import megabrain.gyeongnamgyeongmae.auctionItem.domain.repostiory.AuctionItemRepository; import megabrain.gyeongnamgyeongmae.auctionItem.dto.AuctionItemResponse; import megabrain.gyeongnamgyeongmae.auctionItem.dto.UpdateAuctionItemRequest; -import megabrain.gyeongnamgyeongmae.auctionItem.service.Item.AuctionItemService; +import megabrain.gyeongnamgyeongmae.auctionItem.service.Item.AuctionItemServiceImpl; import megabrain.gyeongnamgyeongmae.member.service.MemberService; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.DisplayName; @@ -43,7 +43,7 @@ public class AuctionControllerTest { @MockBean private CategoryService categoryService; - @MockBean private AuctionItemService auctionItemService; + @MockBean private AuctionItemServiceImpl auctionItemServiceImpl; @Autowired private ObjectMapper objectMapper; @@ -87,7 +87,7 @@ void createAuctionItemTest() throws Exception { @DisplayName("경매상품 조회 성공 케이스") void getAuctionItemTest() throws Exception { - when(auctionItemService.findAuctionItemById(1L)) + when(auctionItemServiceImpl.findAuctionItemById(1L)) .thenReturn((AuctionItemResponse.of(AUCTION_ITEM))); doAnswer( invocation -> { @@ -95,7 +95,7 @@ void getAuctionItemTest() throws Exception { arg.setView_count(1); return null; }) - .when(auctionItemService) + .when(auctionItemServiceImpl) .updateAuctionItemViewCount(AUCTION_ITEM); AuctionItemResponse expectedResponse = AuctionItemResponse.of(AUCTION_ITEM); @@ -142,7 +142,7 @@ void upDateAuctionItem() throws Exception { ArgumentCaptor captor = forClass(UpdateAuctionItemRequest.class); - verify(auctionItemService, times(1)).updateAuctionItem(captor.capture()); + verify(auctionItemServiceImpl, times(1)).updateAuctionItem(captor.capture()); UpdateAuctionItemRequest capturedAuctionItem = captor.getValue(); From 0ec7b1df78fa5751ebd57e4c6bc8985b12eb839f Mon Sep 17 00:00:00 2001 From: haroya01 Date: Tue, 5 Sep 2023 22:12:25 +0900 Subject: [PATCH 06/22] =?UTF-8?q?feat=20:=20=EA=B2=8C=EC=8B=9C=EA=B8=80=20?= =?UTF-8?q?=EC=A0=95=EB=A0=AC=20=EC=A1=B0=EA=B1=B4=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/entity/AuctionItem.java | 10 +++--- .../AuctionItemRepositoryCustomImpl.java | 33 +++++++++++++++---- .../auctionItem/dto/AuctionItemFirstView.java | 6 ++-- .../auctionItem/dto/AuctionItemResponse.java | 6 ++-- .../Search/AuctionItemSearchService.java | 2 -- 5 files changed, 38 insertions(+), 19 deletions(-) diff --git a/src/main/java/megabrain/gyeongnamgyeongmae/auctionItem/domain/entity/AuctionItem.java b/src/main/java/megabrain/gyeongnamgyeongmae/auctionItem/domain/entity/AuctionItem.java index af7b89a..84e20e2 100644 --- a/src/main/java/megabrain/gyeongnamgyeongmae/auctionItem/domain/entity/AuctionItem.java +++ b/src/main/java/megabrain/gyeongnamgyeongmae/auctionItem/domain/entity/AuctionItem.java @@ -28,7 +28,7 @@ public class AuctionItem extends BaseTimeEntity { private String name; @Column(name = "highest_price") - private int price; + private Long price; @Embedded private Content content; @@ -40,10 +40,10 @@ public class AuctionItem extends BaseTimeEntity { protected LocalDateTime closedTime; @Column(name = "like_count") - private int like_count = 0; + private Long like_count = 0L; @Column(name = "view_count") - private int view_count = 0; + private Long view_count = 0L; @Column(name = "auction_status") @Enumerated(EnumType.STRING) @@ -57,7 +57,7 @@ public class AuctionItem extends BaseTimeEntity { private Long temperature; @Builder - public AuctionItem(Long id, String name, int price, Content content, LocalDateTime closedTime) { + public AuctionItem(Long id, String name, long price, Content content, LocalDateTime closedTime) { this.id = id; this.name = name; @@ -70,7 +70,7 @@ public AuctionItem(Long id, String name, int price, Content content, LocalDateTi public AuctionItem( Long id, String name, - int price, + long price, Content content, LocalDateTime closedTime, Category category, diff --git a/src/main/java/megabrain/gyeongnamgyeongmae/auctionItem/domain/repostiory/AuctionItemRepositoryCustomImpl.java b/src/main/java/megabrain/gyeongnamgyeongmae/auctionItem/domain/repostiory/AuctionItemRepositoryCustomImpl.java index 84fe85b..299f0a7 100644 --- a/src/main/java/megabrain/gyeongnamgyeongmae/auctionItem/domain/repostiory/AuctionItemRepositoryCustomImpl.java +++ b/src/main/java/megabrain/gyeongnamgyeongmae/auctionItem/domain/repostiory/AuctionItemRepositoryCustomImpl.java @@ -2,6 +2,7 @@ import static megabrain.gyeongnamgyeongmae.auctionItem.domain.entity.QAuctionItem.auctionItem; +import com.querydsl.core.BooleanBuilder; import com.querydsl.core.types.OrderSpecifier; import com.querydsl.jpa.impl.JPAQuery; import com.querydsl.jpa.impl.JPAQueryFactory; @@ -10,8 +11,10 @@ import javax.persistence.EntityManager; import megabrain.gyeongnamgyeongmae.Category.domain.entity.QCategory; import megabrain.gyeongnamgyeongmae.auctionItem.domain.entity.AuctionItem; +import megabrain.gyeongnamgyeongmae.auctionItem.domain.entity.AuctionItemStatus; import megabrain.gyeongnamgyeongmae.auctionItem.domain.entity.QAuctionItem; import megabrain.gyeongnamgyeongmae.auctionItem.dto.SearchItem.SearchAuctionItemSortedRequest; +import megabrain.gyeongnamgyeongmae.auctionItem.dto.SearchItem.SearchStatus; import org.springframework.data.domain.Page; import org.springframework.data.domain.PageImpl; import org.springframework.data.domain.Pageable; @@ -32,21 +35,42 @@ public Page searchAuctionItemPage( QCategory category = QCategory.category; List> orderSpecifiers = new ArrayList<>(); + BooleanBuilder builder = new BooleanBuilder(); + if (SearchStatus.NEW.equals(searchAuctionItemSortedRequest.getSearch_status())) { + builder.and(auctionItem.content.status.eq(AuctionItemStatus.NEW)); + } + if (SearchStatus.USED.equals(searchAuctionItemSortedRequest.getSearch_status())) { + builder.and(auctionItem.content.status.eq(AuctionItemStatus.USED)); + } + if (SearchStatus.ALL.equals(searchAuctionItemSortedRequest.getSearch_status())) { + builder.and(auctionItem.content.status.in(AuctionItemStatus.NEW, AuctionItemStatus.USED)); + } + + if (searchAuctionItemSortedRequest.isSearch_price()) { + orderSpecifiers.add(auctionItem.price.desc()); + } + if (!searchAuctionItemSortedRequest.isSearch_price()) { + orderSpecifiers.add(auctionItem.price.asc()); + } if (searchAuctionItemSortedRequest.isLike()) { orderSpecifiers.add(auctionItem.like_count.desc()); } + if (!searchAuctionItemSortedRequest.isLike()) { + orderSpecifiers.add(auctionItem.like_count.asc()); + } if (searchAuctionItemSortedRequest.isView_count()) { orderSpecifiers.add(auctionItem.view_count.desc()); } - if (searchAuctionItemSortedRequest.isSearch_price()) { - orderSpecifiers.add(auctionItem.price.desc()); + if (!searchAuctionItemSortedRequest.isView_count()) { + orderSpecifiers.add(auctionItem.view_count.asc()); } + JPAQuery query = queryFactory .selectFrom(auctionItem) .innerJoin(auctionItem.category, category) - .where(category.name.eq(searchAuctionItemSortedRequest.getCategory())); + .where(category.name.eq(searchAuctionItemSortedRequest.getCategory()), builder); List results = query @@ -57,9 +81,6 @@ public Page searchAuctionItemPage( return new PageImpl<>(results, pageable, results.size()); } - - // public checkSort(SearchAuctionItemSortedRequest.Sort sort) { - } // SearchAuctionItemSortedRequest.Sort a = searchAuctionItemSortedRequest.getSort(); diff --git a/src/main/java/megabrain/gyeongnamgyeongmae/auctionItem/dto/AuctionItemFirstView.java b/src/main/java/megabrain/gyeongnamgyeongmae/auctionItem/dto/AuctionItemFirstView.java index ea92417..0a00228 100644 --- a/src/main/java/megabrain/gyeongnamgyeongmae/auctionItem/dto/AuctionItemFirstView.java +++ b/src/main/java/megabrain/gyeongnamgyeongmae/auctionItem/dto/AuctionItemFirstView.java @@ -28,11 +28,11 @@ public class AuctionItemFirstView { private Address address; - private int like_count; + private Long like_count; - private int view_count; + private Long view_count; - private int price; + private Long price; public static AuctionItemFirstView of(AuctionItem auctionItem) { return AuctionItemFirstView.builder() diff --git a/src/main/java/megabrain/gyeongnamgyeongmae/auctionItem/dto/AuctionItemResponse.java b/src/main/java/megabrain/gyeongnamgyeongmae/auctionItem/dto/AuctionItemResponse.java index 1ef0707..52b4699 100644 --- a/src/main/java/megabrain/gyeongnamgyeongmae/auctionItem/dto/AuctionItemResponse.java +++ b/src/main/java/megabrain/gyeongnamgyeongmae/auctionItem/dto/AuctionItemResponse.java @@ -21,7 +21,7 @@ public class AuctionItemResponse { private String name; private String nickname; - private int price; + private Long price; private AuctionItemStatus itemStatus; private AuctionStatus auctionStatus; @@ -35,8 +35,8 @@ public class AuctionItemResponse { private String content; - private int likeCount; - private int viewCount; + private Long likeCount; + private Long viewCount; public static AuctionItemResponse of(AuctionItem auctionItem) { return AuctionItemResponse.builder() diff --git a/src/main/java/megabrain/gyeongnamgyeongmae/auctionItem/service/Search/AuctionItemSearchService.java b/src/main/java/megabrain/gyeongnamgyeongmae/auctionItem/service/Search/AuctionItemSearchService.java index db68f67..00bc766 100644 --- a/src/main/java/megabrain/gyeongnamgyeongmae/auctionItem/service/Search/AuctionItemSearchService.java +++ b/src/main/java/megabrain/gyeongnamgyeongmae/auctionItem/service/Search/AuctionItemSearchService.java @@ -10,6 +10,4 @@ public interface AuctionItemSearchService { Page findAuctionItembyRequest( SearchAuctionItemSortedRequest searchAuctionItemSortedRequest, Pageable pageable); - // void CheckAuctionItemSortedRequest(SearchAuctionItemSortedRequest - // searchAuctionItemSortedRequest); } From 1b6994c8c126e5e92a34085a3b5911cf577d0c22 Mon Sep 17 00:00:00 2001 From: haroya01 Date: Tue, 5 Sep 2023 22:31:16 +0900 Subject: [PATCH 07/22] =?UTF-8?q?feat=20:=20=EA=B2=8C=EC=8B=9C=EA=B8=80=20?= =?UTF-8?q?=EC=A0=95=EB=A0=AC=20=EC=A1=B0=EA=B1=B4=20=EC=B6=94=EA=B0=80=20?= =?UTF-8?q?=EB=B0=8F=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../AuctionItemRepositoryCustomImpl.java | 33 ++++++++++++++++--- .../SearchAuctionItemSortedRequest.java | 12 +++---- .../dto/UpdateAuctionItemRequest.java | 2 +- 3 files changed, 34 insertions(+), 13 deletions(-) diff --git a/src/main/java/megabrain/gyeongnamgyeongmae/auctionItem/domain/repostiory/AuctionItemRepositoryCustomImpl.java b/src/main/java/megabrain/gyeongnamgyeongmae/auctionItem/domain/repostiory/AuctionItemRepositoryCustomImpl.java index 299f0a7..1a55dd8 100644 --- a/src/main/java/megabrain/gyeongnamgyeongmae/auctionItem/domain/repostiory/AuctionItemRepositoryCustomImpl.java +++ b/src/main/java/megabrain/gyeongnamgyeongmae/auctionItem/domain/repostiory/AuctionItemRepositoryCustomImpl.java @@ -12,6 +12,7 @@ import megabrain.gyeongnamgyeongmae.Category.domain.entity.QCategory; import megabrain.gyeongnamgyeongmae.auctionItem.domain.entity.AuctionItem; import megabrain.gyeongnamgyeongmae.auctionItem.domain.entity.AuctionItemStatus; +import megabrain.gyeongnamgyeongmae.auctionItem.domain.entity.AuctionStatus; import megabrain.gyeongnamgyeongmae.auctionItem.domain.entity.QAuctionItem; import megabrain.gyeongnamgyeongmae.auctionItem.dto.SearchItem.SearchAuctionItemSortedRequest; import megabrain.gyeongnamgyeongmae.auctionItem.dto.SearchItem.SearchStatus; @@ -35,16 +36,18 @@ public Page searchAuctionItemPage( QCategory category = QCategory.category; List> orderSpecifiers = new ArrayList<>(); - BooleanBuilder builder = new BooleanBuilder(); + BooleanBuilder statusBuilder = new BooleanBuilder(); + BooleanBuilder sellStatus = new BooleanBuilder(); if (SearchStatus.NEW.equals(searchAuctionItemSortedRequest.getSearch_status())) { - builder.and(auctionItem.content.status.eq(AuctionItemStatus.NEW)); + statusBuilder.and(auctionItem.content.status.eq(AuctionItemStatus.NEW)); } if (SearchStatus.USED.equals(searchAuctionItemSortedRequest.getSearch_status())) { - builder.and(auctionItem.content.status.eq(AuctionItemStatus.USED)); + statusBuilder.and(auctionItem.content.status.eq(AuctionItemStatus.USED)); } if (SearchStatus.ALL.equals(searchAuctionItemSortedRequest.getSearch_status())) { - builder.and(auctionItem.content.status.in(AuctionItemStatus.NEW, AuctionItemStatus.USED)); + statusBuilder.and( + auctionItem.content.status.in(AuctionItemStatus.NEW, AuctionItemStatus.USED)); } if (searchAuctionItemSortedRequest.isSearch_price()) { @@ -65,12 +68,32 @@ public Page searchAuctionItemPage( if (!searchAuctionItemSortedRequest.isView_count()) { orderSpecifiers.add(auctionItem.view_count.asc()); } + if (searchAuctionItemSortedRequest.isClosed()) { + sellStatus.and(auctionItem.status.eq(AuctionStatus.ONGOING)); + } + if (!searchAuctionItemSortedRequest.isClosed()) { + sellStatus.and( + auctionItem.status.in( + AuctionStatus.ONGOING, AuctionStatus.CLOSED, AuctionStatus.BIDDING)); + } + if (searchAuctionItemSortedRequest.isClosed()) { + sellStatus.and(auctionItem.status.eq(AuctionStatus.ONGOING)); + } + if (searchAuctionItemSortedRequest.isSearch_time()) { + orderSpecifiers.add(auctionItem.closedTime.asc()); + } + if (!searchAuctionItemSortedRequest.isSearch_time()) { + orderSpecifiers.add(auctionItem.closedTime.desc()); + } JPAQuery query = queryFactory .selectFrom(auctionItem) .innerJoin(auctionItem.category, category) - .where(category.name.eq(searchAuctionItemSortedRequest.getCategory()), builder); + .where( + category.name.eq(searchAuctionItemSortedRequest.getCategory()), + statusBuilder, + sellStatus); List results = query diff --git a/src/main/java/megabrain/gyeongnamgyeongmae/auctionItem/dto/SearchItem/SearchAuctionItemSortedRequest.java b/src/main/java/megabrain/gyeongnamgyeongmae/auctionItem/dto/SearchItem/SearchAuctionItemSortedRequest.java index e2f4a85..a9d502e 100644 --- a/src/main/java/megabrain/gyeongnamgyeongmae/auctionItem/dto/SearchItem/SearchAuctionItemSortedRequest.java +++ b/src/main/java/megabrain/gyeongnamgyeongmae/auctionItem/dto/SearchItem/SearchAuctionItemSortedRequest.java @@ -6,16 +6,16 @@ @Getter public class SearchAuctionItemSortedRequest { - // @NotNull private SearchStatus search_status; // 신품 중고품 전체 + @NotNull private SearchStatus search_status; // 신품 중고품 전체 - // @NotNull private boolean closed; // 이미 경매가 끝낸 개시글도 보기 + @NotNull private boolean closed; // 이미 경매가 끝낸 개시글도 보기 - // @ NotNull private SearchTime search_time; // 마감시간 근접, 멀리 + @NotNull private boolean search_time; // 마감시간 근접 // @NotNull private Location my_location; // 나의 현재 위치 // @NotNull private int km; // 몇키로 반경 게시글 조회 - // + // @NotNull private int town; // 몇개의 마을 조회 @NotNull private String category; // 카테고리 검색 @@ -24,7 +24,7 @@ public class SearchAuctionItemSortedRequest { @NotNull private boolean search_price; // 가격순 정렬 - @NotNull private boolean comment; // 댓글수 정렬 기준 + // @NotNull private boolean comment; // 댓글수 정렬 기준 @NotNull private boolean view_count; // 조회수 정렬 기준 @@ -32,6 +32,4 @@ public class SearchAuctionItemSortedRequest { // @NotNull private boolean temperature; // 온도별 정렬 기준 - // 기본값 오름차순 정렬 - } diff --git a/src/main/java/megabrain/gyeongnamgyeongmae/auctionItem/dto/UpdateAuctionItemRequest.java b/src/main/java/megabrain/gyeongnamgyeongmae/auctionItem/dto/UpdateAuctionItemRequest.java index 1529274..1b91bbc 100644 --- a/src/main/java/megabrain/gyeongnamgyeongmae/auctionItem/dto/UpdateAuctionItemRequest.java +++ b/src/main/java/megabrain/gyeongnamgyeongmae/auctionItem/dto/UpdateAuctionItemRequest.java @@ -20,7 +20,7 @@ public class UpdateAuctionItemRequest { @NotEmpty private String name; @Min(1) - private Integer price; + private Long price; @NotEmpty private String category; From d18e2a59f073b7a307c3c82e33aa44422ca5744e Mon Sep 17 00:00:00 2001 From: haroya01 Date: Tue, 5 Sep 2023 22:35:38 +0900 Subject: [PATCH 08/22] =?UTF-8?q?test=20:=20test=EC=BC=80=EC=9D=B4?= =?UTF-8?q?=EC=8A=A4=20=EC=98=A4=EB=A5=98=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../auctionItem/controller/AuctionControllerTest.java | 2 +- .../gyeongnamgyeongmae/fixture/AuctionItemFixture.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/test/java/megabrain/gyeongnamgyeongmae/auctionItem/controller/AuctionControllerTest.java b/src/test/java/megabrain/gyeongnamgyeongmae/auctionItem/controller/AuctionControllerTest.java index 33d8418..bc4ed29 100644 --- a/src/test/java/megabrain/gyeongnamgyeongmae/auctionItem/controller/AuctionControllerTest.java +++ b/src/test/java/megabrain/gyeongnamgyeongmae/auctionItem/controller/AuctionControllerTest.java @@ -92,7 +92,7 @@ void getAuctionItemTest() throws Exception { doAnswer( invocation -> { AuctionItem arg = invocation.getArgument(0); - arg.setView_count(1); + arg.setView_count(1L); return null; }) .when(auctionItemServiceImpl) diff --git a/src/test/java/megabrain/gyeongnamgyeongmae/fixture/AuctionItemFixture.java b/src/test/java/megabrain/gyeongnamgyeongmae/fixture/AuctionItemFixture.java index 103b150..553a595 100644 --- a/src/test/java/megabrain/gyeongnamgyeongmae/fixture/AuctionItemFixture.java +++ b/src/test/java/megabrain/gyeongnamgyeongmae/fixture/AuctionItemFixture.java @@ -21,7 +21,7 @@ public class AuctionItemFixture { new UpdateAuctionItemRequest( 1L, "마우스 팝니다", - 1000, + 1000L, "mouse", new Content("update content", AuctionItemStatus.USED), LocalDateTime.parse("2066-12-31T12:00"), From a810cf36351f3f59456c08bac24c4651bd346177 Mon Sep 17 00:00:00 2001 From: haroya01 Date: Wed, 6 Sep 2023 15:11:53 +0900 Subject: [PATCH 09/22] =?UTF-8?q?refactor=20:=20body=EC=97=90=EC=84=9C=20p?= =?UTF-8?q?aram=EC=9C=BC=EB=A1=9C=20=EC=A0=95=EB=A0=AC=EA=B0=92=20?= =?UTF-8?q?=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ....java => AuctionItemSearchController.java} | 10 ++---- .../AuctionItemRepositoryCustomImpl.java | 35 ++++++------------- .../SearchAuctionItemSortedRequest.java | 27 +++++++------- .../Search/AuctionItemSearchServiceImpl.java | 4 ++- 4 files changed, 31 insertions(+), 45 deletions(-) rename src/main/java/megabrain/gyeongnamgyeongmae/auctionItem/controller/{AuctionItemSearch.java => AuctionItemSearchController.java} (83%) diff --git a/src/main/java/megabrain/gyeongnamgyeongmae/auctionItem/controller/AuctionItemSearch.java b/src/main/java/megabrain/gyeongnamgyeongmae/auctionItem/controller/AuctionItemSearchController.java similarity index 83% rename from src/main/java/megabrain/gyeongnamgyeongmae/auctionItem/controller/AuctionItemSearch.java rename to src/main/java/megabrain/gyeongnamgyeongmae/auctionItem/controller/AuctionItemSearchController.java index 8badf02..c7d8a02 100644 --- a/src/main/java/megabrain/gyeongnamgyeongmae/auctionItem/controller/AuctionItemSearch.java +++ b/src/main/java/megabrain/gyeongnamgyeongmae/auctionItem/controller/AuctionItemSearchController.java @@ -2,7 +2,6 @@ import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.tags.Tag; -import javax.validation.Valid; import lombok.RequiredArgsConstructor; import megabrain.gyeongnamgyeongmae.auctionItem.domain.repostiory.AuctionItemRepository; import megabrain.gyeongnamgyeongmae.auctionItem.dto.AuctionItemFirstView; @@ -11,28 +10,25 @@ import org.springframework.data.domain.Page; import org.springframework.data.domain.Pageable; import org.springframework.http.ResponseEntity; -import org.springframework.transaction.annotation.Transactional; import org.springframework.web.bind.annotation.*; @Tag(name = "경매품 검색", description = "경매품 검색 관련 API") @RequestMapping("api/auctions/search") @RestController @RequiredArgsConstructor -public class AuctionItemSearch { +public class AuctionItemSearchController { private final AuctionItemSearchServiceImpl auctionItemSearchServiceImpl; private final AuctionItemRepository auctionItemRepository; @Operation(summary = "Search AuctionItem", description = "경매품 검색하기") - @PostMapping("") - @Transactional(readOnly = true) + @GetMapping("") public ResponseEntity> findItemCategory( - @RequestBody @Valid SearchAuctionItemSortedRequest searchAuctionItemSortedRequest, + @ModelAttribute SearchAuctionItemSortedRequest searchAuctionItemSortedRequest, Pageable pageable) { Page result = auctionItemSearchServiceImpl.findAuctionItembyRequest( searchAuctionItemSortedRequest, pageable); - return ResponseEntity.ok(result); } } diff --git a/src/main/java/megabrain/gyeongnamgyeongmae/auctionItem/domain/repostiory/AuctionItemRepositoryCustomImpl.java b/src/main/java/megabrain/gyeongnamgyeongmae/auctionItem/domain/repostiory/AuctionItemRepositoryCustomImpl.java index 1a55dd8..acb3b8c 100644 --- a/src/main/java/megabrain/gyeongnamgyeongmae/auctionItem/domain/repostiory/AuctionItemRepositoryCustomImpl.java +++ b/src/main/java/megabrain/gyeongnamgyeongmae/auctionItem/domain/repostiory/AuctionItemRepositoryCustomImpl.java @@ -50,39 +50,39 @@ public Page searchAuctionItemPage( auctionItem.content.status.in(AuctionItemStatus.NEW, AuctionItemStatus.USED)); } - if (searchAuctionItemSortedRequest.isSearch_price()) { + if (searchAuctionItemSortedRequest.getSearch_price()) { orderSpecifiers.add(auctionItem.price.desc()); } - if (!searchAuctionItemSortedRequest.isSearch_price()) { + if (!searchAuctionItemSortedRequest.getSearch_price()) { orderSpecifiers.add(auctionItem.price.asc()); } - if (searchAuctionItemSortedRequest.isLike()) { + if (searchAuctionItemSortedRequest.getLike()) { orderSpecifiers.add(auctionItem.like_count.desc()); } - if (!searchAuctionItemSortedRequest.isLike()) { + if (!searchAuctionItemSortedRequest.getLike()) { orderSpecifiers.add(auctionItem.like_count.asc()); } - if (searchAuctionItemSortedRequest.isView_count()) { + if (searchAuctionItemSortedRequest.getView_count()) { orderSpecifiers.add(auctionItem.view_count.desc()); } - if (!searchAuctionItemSortedRequest.isView_count()) { + if (!searchAuctionItemSortedRequest.getView_count()) { orderSpecifiers.add(auctionItem.view_count.asc()); } - if (searchAuctionItemSortedRequest.isClosed()) { + if (searchAuctionItemSortedRequest.getClosed()) { sellStatus.and(auctionItem.status.eq(AuctionStatus.ONGOING)); } - if (!searchAuctionItemSortedRequest.isClosed()) { + if (!searchAuctionItemSortedRequest.getClosed()) { sellStatus.and( auctionItem.status.in( AuctionStatus.ONGOING, AuctionStatus.CLOSED, AuctionStatus.BIDDING)); } - if (searchAuctionItemSortedRequest.isClosed()) { + if (searchAuctionItemSortedRequest.getClosed()) { sellStatus.and(auctionItem.status.eq(AuctionStatus.ONGOING)); } - if (searchAuctionItemSortedRequest.isSearch_time()) { + if (searchAuctionItemSortedRequest.getSearch_time()) { orderSpecifiers.add(auctionItem.closedTime.asc()); } - if (!searchAuctionItemSortedRequest.isSearch_time()) { + if (!searchAuctionItemSortedRequest.getSearch_time()) { orderSpecifiers.add(auctionItem.closedTime.desc()); } @@ -105,16 +105,3 @@ public Page searchAuctionItemPage( return new PageImpl<>(results, pageable, results.size()); } } - -// SearchAuctionItemSortedRequest.Sort a = searchAuctionItemSortedRequest.getSort(); -// List results = -// queryFactory -// .selectFrom(auctionItem) -// .innerJoin(auctionItem.category, category) -// .where(category.name.eq(searchAuctionItemSortedRequest.getCategory())) -// .orderBy(sort) -// .offset(pageable.getOffset()) -// .limit(pageable.getPageSize()) -// .fetch(); - -// .orderBy(auctionItem.like_count.asc()) diff --git a/src/main/java/megabrain/gyeongnamgyeongmae/auctionItem/dto/SearchItem/SearchAuctionItemSortedRequest.java b/src/main/java/megabrain/gyeongnamgyeongmae/auctionItem/dto/SearchItem/SearchAuctionItemSortedRequest.java index a9d502e..1dcbc56 100644 --- a/src/main/java/megabrain/gyeongnamgyeongmae/auctionItem/dto/SearchItem/SearchAuctionItemSortedRequest.java +++ b/src/main/java/megabrain/gyeongnamgyeongmae/auctionItem/dto/SearchItem/SearchAuctionItemSortedRequest.java @@ -1,33 +1,34 @@ package megabrain.gyeongnamgyeongmae.auctionItem.dto.SearchItem; -import javax.validation.constraints.NotNull; -import lombok.Getter; +import lombok.*; +@Data @Getter +@Setter public class SearchAuctionItemSortedRequest { - @NotNull private SearchStatus search_status; // 신품 중고품 전체 + private String category; - @NotNull private boolean closed; // 이미 경매가 끝낸 개시글도 보기 + private SearchStatus search_status = SearchStatus.ALL; // 신품 중고품 전체 - @NotNull private boolean search_time; // 마감시간 근접 + private Boolean closed = Boolean.FALSE; // 이미 경매가 끝낸 개시글도 보기 - // @NotNull private Location my_location; // 나의 현재 위치 + private Boolean search_time = Boolean.FALSE; // 마감시간 근접 - // @NotNull private int km; // 몇키로 반경 게시글 조회 + private Boolean like = Boolean.FALSE; // 좋아요 정렬 기준 - // @NotNull private int town; // 몇개의 마을 조회 + private Boolean search_price = Boolean.FALSE; // 가격순 정렬 + + private Boolean view_count = Boolean.FALSE; // 조회수 정렬 기준 - @NotNull private String category; // 카테고리 검색 + // @NotNull private Location my_location; // 나의 현재 위치 - @NotNull private boolean like; // 좋아요 정렬 기준 + // @NotNull private int km; // 몇키로 반경 게시글 조회 - @NotNull private boolean search_price; // 가격순 정렬 + // @NotNull private int town; // 몇개의 마을 조회 // @NotNull private boolean comment; // 댓글수 정렬 기준 - @NotNull private boolean view_count; // 조회수 정렬 기준 - // @NotNull private String member; // 이름 검색 // @NotNull private boolean temperature; // 온도별 정렬 기준 diff --git a/src/main/java/megabrain/gyeongnamgyeongmae/auctionItem/service/Search/AuctionItemSearchServiceImpl.java b/src/main/java/megabrain/gyeongnamgyeongmae/auctionItem/service/Search/AuctionItemSearchServiceImpl.java index 83e4070..e95f498 100644 --- a/src/main/java/megabrain/gyeongnamgyeongmae/auctionItem/service/Search/AuctionItemSearchServiceImpl.java +++ b/src/main/java/megabrain/gyeongnamgyeongmae/auctionItem/service/Search/AuctionItemSearchServiceImpl.java @@ -10,6 +10,7 @@ import org.springframework.data.domain.Pageable; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; +import org.springframework.web.bind.annotation.RequestParam; @Service @RequiredArgsConstructor @@ -21,7 +22,8 @@ public class AuctionItemSearchServiceImpl implements AuctionItemSearchService { @Override @Transactional(readOnly = true) public Page findAuctionItembyRequest( - SearchAuctionItemSortedRequest searchAuctionItemSortedRequest, Pageable pageable) { + @RequestParam(required = false) SearchAuctionItemSortedRequest searchAuctionItemSortedRequest, + @RequestParam Pageable pageable) { Page auctionItemEntityList = auctionItemRepository.searchAuctionItemPage(searchAuctionItemSortedRequest, pageable); return auctionItemEntityList.map(AuctionItemFirstView::of); From 5944562e65a02da31667650e062b9cbcf2eee423 Mon Sep 17 00:00:00 2001 From: haroya01 Date: Wed, 6 Sep 2023 18:28:56 +0900 Subject: [PATCH 10/22] =?UTF-8?q?refactor=20:=20=EC=A0=95=EB=A0=AC=20?= =?UTF-8?q?=EC=BD=94=EB=93=9C=20=EA=B0=84=EC=86=8C=ED=99=94?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../AuctionItemRepositoryCustomImpl.java | 55 ++--------------- .../SearchAuctionItemSortedRequest.java | 61 ++++++++++++++++++- 2 files changed, 65 insertions(+), 51 deletions(-) diff --git a/src/main/java/megabrain/gyeongnamgyeongmae/auctionItem/domain/repostiory/AuctionItemRepositoryCustomImpl.java b/src/main/java/megabrain/gyeongnamgyeongmae/auctionItem/domain/repostiory/AuctionItemRepositoryCustomImpl.java index acb3b8c..3395349 100644 --- a/src/main/java/megabrain/gyeongnamgyeongmae/auctionItem/domain/repostiory/AuctionItemRepositoryCustomImpl.java +++ b/src/main/java/megabrain/gyeongnamgyeongmae/auctionItem/domain/repostiory/AuctionItemRepositoryCustomImpl.java @@ -11,11 +11,8 @@ import javax.persistence.EntityManager; import megabrain.gyeongnamgyeongmae.Category.domain.entity.QCategory; import megabrain.gyeongnamgyeongmae.auctionItem.domain.entity.AuctionItem; -import megabrain.gyeongnamgyeongmae.auctionItem.domain.entity.AuctionItemStatus; -import megabrain.gyeongnamgyeongmae.auctionItem.domain.entity.AuctionStatus; import megabrain.gyeongnamgyeongmae.auctionItem.domain.entity.QAuctionItem; import megabrain.gyeongnamgyeongmae.auctionItem.dto.SearchItem.SearchAuctionItemSortedRequest; -import megabrain.gyeongnamgyeongmae.auctionItem.dto.SearchItem.SearchStatus; import org.springframework.data.domain.Page; import org.springframework.data.domain.PageImpl; import org.springframework.data.domain.Pageable; @@ -39,52 +36,12 @@ public Page searchAuctionItemPage( BooleanBuilder statusBuilder = new BooleanBuilder(); BooleanBuilder sellStatus = new BooleanBuilder(); - if (SearchStatus.NEW.equals(searchAuctionItemSortedRequest.getSearch_status())) { - statusBuilder.and(auctionItem.content.status.eq(AuctionItemStatus.NEW)); - } - if (SearchStatus.USED.equals(searchAuctionItemSortedRequest.getSearch_status())) { - statusBuilder.and(auctionItem.content.status.eq(AuctionItemStatus.USED)); - } - if (SearchStatus.ALL.equals(searchAuctionItemSortedRequest.getSearch_status())) { - statusBuilder.and( - auctionItem.content.status.in(AuctionItemStatus.NEW, AuctionItemStatus.USED)); - } - - if (searchAuctionItemSortedRequest.getSearch_price()) { - orderSpecifiers.add(auctionItem.price.desc()); - } - if (!searchAuctionItemSortedRequest.getSearch_price()) { - orderSpecifiers.add(auctionItem.price.asc()); - } - if (searchAuctionItemSortedRequest.getLike()) { - orderSpecifiers.add(auctionItem.like_count.desc()); - } - if (!searchAuctionItemSortedRequest.getLike()) { - orderSpecifiers.add(auctionItem.like_count.asc()); - } - if (searchAuctionItemSortedRequest.getView_count()) { - orderSpecifiers.add(auctionItem.view_count.desc()); - } - if (!searchAuctionItemSortedRequest.getView_count()) { - orderSpecifiers.add(auctionItem.view_count.asc()); - } - if (searchAuctionItemSortedRequest.getClosed()) { - sellStatus.and(auctionItem.status.eq(AuctionStatus.ONGOING)); - } - if (!searchAuctionItemSortedRequest.getClosed()) { - sellStatus.and( - auctionItem.status.in( - AuctionStatus.ONGOING, AuctionStatus.CLOSED, AuctionStatus.BIDDING)); - } - if (searchAuctionItemSortedRequest.getClosed()) { - sellStatus.and(auctionItem.status.eq(AuctionStatus.ONGOING)); - } - if (searchAuctionItemSortedRequest.getSearch_time()) { - orderSpecifiers.add(auctionItem.closedTime.asc()); - } - if (!searchAuctionItemSortedRequest.getSearch_time()) { - orderSpecifiers.add(auctionItem.closedTime.desc()); - } + searchAuctionItemSortedRequest.applySearchStatus(statusBuilder, auctionItem); + searchAuctionItemSortedRequest.applySearchPrice(orderSpecifiers, auctionItem); + searchAuctionItemSortedRequest.applySearchLike(orderSpecifiers, auctionItem); + searchAuctionItemSortedRequest.applySearchView(orderSpecifiers, auctionItem); + searchAuctionItemSortedRequest.applySearchTime(orderSpecifiers, auctionItem); + searchAuctionItemSortedRequest.applySearchClosed(sellStatus, auctionItem); JPAQuery query = queryFactory diff --git a/src/main/java/megabrain/gyeongnamgyeongmae/auctionItem/dto/SearchItem/SearchAuctionItemSortedRequest.java b/src/main/java/megabrain/gyeongnamgyeongmae/auctionItem/dto/SearchItem/SearchAuctionItemSortedRequest.java index 1dcbc56..fddef4f 100644 --- a/src/main/java/megabrain/gyeongnamgyeongmae/auctionItem/dto/SearchItem/SearchAuctionItemSortedRequest.java +++ b/src/main/java/megabrain/gyeongnamgyeongmae/auctionItem/dto/SearchItem/SearchAuctionItemSortedRequest.java @@ -1,10 +1,14 @@ package megabrain.gyeongnamgyeongmae.auctionItem.dto.SearchItem; +import com.querydsl.core.BooleanBuilder; +import com.querydsl.core.types.OrderSpecifier; +import java.util.List; import lombok.*; +import megabrain.gyeongnamgyeongmae.auctionItem.domain.entity.AuctionItemStatus; +import megabrain.gyeongnamgyeongmae.auctionItem.domain.entity.AuctionStatus; +import megabrain.gyeongnamgyeongmae.auctionItem.domain.entity.QAuctionItem; @Data -@Getter -@Setter public class SearchAuctionItemSortedRequest { private String category; @@ -33,4 +37,57 @@ public class SearchAuctionItemSortedRequest { // @NotNull private boolean temperature; // 온도별 정렬 기준 + // 이 함수에 매개변수 인자로 + + public void applySearchStatus(BooleanBuilder status, QAuctionItem item) { + if (this.search_status == SearchStatus.NEW) { + status.and(item.content.status.eq(AuctionItemStatus.NEW)); + return; + } + if (this.search_status == SearchStatus.USED) { + status.and(item.content.status.eq(AuctionItemStatus.USED)); + return; + } + status.and(item.content.status.in(AuctionItemStatus.NEW, AuctionItemStatus.USED)); + } + + public void applySearchPrice(List> order, QAuctionItem item) { + if (this.search_price) { + order.add(item.price.desc()); + return; + } + order.add(item.price.asc()); + } + + public void applySearchLike(List> order, QAuctionItem item) { + if (this.like) { + order.add(item.like_count.desc()); + return; + } + order.add(item.like_count.asc()); + } + + public void applySearchView(List> order, QAuctionItem item) { + if (this.view_count) { + order.add(item.view_count.desc()); + return; + } + order.add(item.view_count.asc()); + } + + public void applySearchTime(List> order, QAuctionItem item) { + if (this.search_time) { + order.add(item.closedTime.desc()); + return; + } + order.add(item.closedTime.asc()); + } + + public void applySearchClosed(BooleanBuilder builder, QAuctionItem item) { + if (this.closed) { + builder.and(item.status.eq(AuctionStatus.ONGOING)); + return; + } + builder.and(item.status.in(AuctionStatus.ONGOING, AuctionStatus.CLOSED, AuctionStatus.BIDDING)); + } } From eccc80bbb30a77f0e8470ccb796bca879acd793d Mon Sep 17 00:00:00 2001 From: haroya01 Date: Wed, 6 Sep 2023 20:55:09 +0900 Subject: [PATCH 11/22] =?UTF-8?q?feat=20:=20keyword=EB=A5=BC=20=ED=86=B5?= =?UTF-8?q?=ED=95=9C=20=EA=B2=80=EC=83=89=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../repostiory/AuctionItemRepositoryCustomImpl.java | 10 ++++++---- .../dto/SearchItem/SearchAuctionItemSortedRequest.java | 9 +++++++++ .../service/Search/AuctionItemSearchService.java | 1 - .../service/Search/AuctionItemSearchServiceImpl.java | 4 +--- 4 files changed, 16 insertions(+), 8 deletions(-) diff --git a/src/main/java/megabrain/gyeongnamgyeongmae/auctionItem/domain/repostiory/AuctionItemRepositoryCustomImpl.java b/src/main/java/megabrain/gyeongnamgyeongmae/auctionItem/domain/repostiory/AuctionItemRepositoryCustomImpl.java index 3395349..c768e9a 100644 --- a/src/main/java/megabrain/gyeongnamgyeongmae/auctionItem/domain/repostiory/AuctionItemRepositoryCustomImpl.java +++ b/src/main/java/megabrain/gyeongnamgyeongmae/auctionItem/domain/repostiory/AuctionItemRepositoryCustomImpl.java @@ -34,14 +34,15 @@ public Page searchAuctionItemPage( List> orderSpecifiers = new ArrayList<>(); BooleanBuilder statusBuilder = new BooleanBuilder(); - BooleanBuilder sellStatus = new BooleanBuilder(); + BooleanBuilder sellBuilder = new BooleanBuilder(); + BooleanBuilder keywordStatus = new BooleanBuilder(); - searchAuctionItemSortedRequest.applySearchStatus(statusBuilder, auctionItem); + searchAuctionItemSortedRequest.applyKeyWordStatus(keywordStatus, auctionItem); searchAuctionItemSortedRequest.applySearchPrice(orderSpecifiers, auctionItem); searchAuctionItemSortedRequest.applySearchLike(orderSpecifiers, auctionItem); searchAuctionItemSortedRequest.applySearchView(orderSpecifiers, auctionItem); searchAuctionItemSortedRequest.applySearchTime(orderSpecifiers, auctionItem); - searchAuctionItemSortedRequest.applySearchClosed(sellStatus, auctionItem); + searchAuctionItemSortedRequest.applySearchClosed(sellBuilder, auctionItem); JPAQuery query = queryFactory @@ -50,7 +51,8 @@ public Page searchAuctionItemPage( .where( category.name.eq(searchAuctionItemSortedRequest.getCategory()), statusBuilder, - sellStatus); + sellBuilder, + keywordStatus); List results = query diff --git a/src/main/java/megabrain/gyeongnamgyeongmae/auctionItem/dto/SearchItem/SearchAuctionItemSortedRequest.java b/src/main/java/megabrain/gyeongnamgyeongmae/auctionItem/dto/SearchItem/SearchAuctionItemSortedRequest.java index fddef4f..e22a888 100644 --- a/src/main/java/megabrain/gyeongnamgyeongmae/auctionItem/dto/SearchItem/SearchAuctionItemSortedRequest.java +++ b/src/main/java/megabrain/gyeongnamgyeongmae/auctionItem/dto/SearchItem/SearchAuctionItemSortedRequest.java @@ -11,6 +11,8 @@ @Data public class SearchAuctionItemSortedRequest { + private String keyword = null; + private String category; private SearchStatus search_status = SearchStatus.ALL; // 신품 중고품 전체 @@ -39,6 +41,13 @@ public class SearchAuctionItemSortedRequest { // 이 함수에 매개변수 인자로 + public void applyKeyWordStatus(BooleanBuilder status, QAuctionItem item) { + if (this.keyword == null) { + return; + } + status.and(item.name.like("%" + keyword + "%")); + } + public void applySearchStatus(BooleanBuilder status, QAuctionItem item) { if (this.search_status == SearchStatus.NEW) { status.and(item.content.status.eq(AuctionItemStatus.NEW)); diff --git a/src/main/java/megabrain/gyeongnamgyeongmae/auctionItem/service/Search/AuctionItemSearchService.java b/src/main/java/megabrain/gyeongnamgyeongmae/auctionItem/service/Search/AuctionItemSearchService.java index 00bc766..0413f2f 100644 --- a/src/main/java/megabrain/gyeongnamgyeongmae/auctionItem/service/Search/AuctionItemSearchService.java +++ b/src/main/java/megabrain/gyeongnamgyeongmae/auctionItem/service/Search/AuctionItemSearchService.java @@ -9,5 +9,4 @@ public interface AuctionItemSearchService { Page findAuctionItembyRequest( SearchAuctionItemSortedRequest searchAuctionItemSortedRequest, Pageable pageable); - } diff --git a/src/main/java/megabrain/gyeongnamgyeongmae/auctionItem/service/Search/AuctionItemSearchServiceImpl.java b/src/main/java/megabrain/gyeongnamgyeongmae/auctionItem/service/Search/AuctionItemSearchServiceImpl.java index e95f498..83e4070 100644 --- a/src/main/java/megabrain/gyeongnamgyeongmae/auctionItem/service/Search/AuctionItemSearchServiceImpl.java +++ b/src/main/java/megabrain/gyeongnamgyeongmae/auctionItem/service/Search/AuctionItemSearchServiceImpl.java @@ -10,7 +10,6 @@ import org.springframework.data.domain.Pageable; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; -import org.springframework.web.bind.annotation.RequestParam; @Service @RequiredArgsConstructor @@ -22,8 +21,7 @@ public class AuctionItemSearchServiceImpl implements AuctionItemSearchService { @Override @Transactional(readOnly = true) public Page findAuctionItembyRequest( - @RequestParam(required = false) SearchAuctionItemSortedRequest searchAuctionItemSortedRequest, - @RequestParam Pageable pageable) { + SearchAuctionItemSortedRequest searchAuctionItemSortedRequest, Pageable pageable) { Page auctionItemEntityList = auctionItemRepository.searchAuctionItemPage(searchAuctionItemSortedRequest, pageable); return auctionItemEntityList.map(AuctionItemFirstView::of); From 5400a9ab90b8dfa31f7993268456c389f94d76a2 Mon Sep 17 00:00:00 2001 From: haroya01 Date: Thu, 7 Sep 2023 20:13:47 +0900 Subject: [PATCH 12/22] =?UTF-8?q?feat=20:=20=EC=B9=B4=ED=85=8C=EA=B3=A0?= =?UTF-8?q?=EB=A6=AC=20=EA=B8=B0=EB=B3=B8=EA=B0=92=20=EC=B6=94=EA=B0=80=20?= =?UTF-8?q?=EB=B0=8F=20=EC=A0=95=EB=A0=AC=EC=A1=B0=EA=B1=B4=20=EC=B6=94?= =?UTF-8?q?=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/AuctionItemController.java | 12 +++++++-- .../domain/entity/AuctionItem.java | 26 ++++++++++++++----- .../AuctionItemRepositoryCustomImpl.java | 8 +++--- .../SearchAuctionItemSortedRequest.java | 11 +++++--- .../dto/UpdateAuctionItemRequest.java | 2 -- .../service/Item/AuctionItemService.java | 4 ++- .../service/Item/AuctionItemServiceImpl.java | 17 ++++++++---- 7 files changed, 57 insertions(+), 23 deletions(-) diff --git a/src/main/java/megabrain/gyeongnamgyeongmae/auctionItem/controller/AuctionItemController.java b/src/main/java/megabrain/gyeongnamgyeongmae/auctionItem/controller/AuctionItemController.java index b9c911b..668cdd6 100644 --- a/src/main/java/megabrain/gyeongnamgyeongmae/auctionItem/controller/AuctionItemController.java +++ b/src/main/java/megabrain/gyeongnamgyeongmae/auctionItem/controller/AuctionItemController.java @@ -39,10 +39,18 @@ public ResponseEntity findAuctionItemById(@PathVariable Lon } @Operation(summary = "Update AuctionItem", description = "경매품 수정하기") - @PutMapping() + @PutMapping("{id}") public ResponseEntity updateAuctionItemById( + @PathVariable Long id, @RequestBody @Valid UpdateAuctionItemRequest upDateAuctionItemRequest) { - auctionItemServiceImpl.updateAuctionItem(upDateAuctionItemRequest); + auctionItemServiceImpl.updateAuctionItem(upDateAuctionItemRequest, id); + return ResponseEntity.status(HttpStatus.OK).build(); + } + + @Operation(summary = "Delete AuctionItem", description = "경매품 삭제하기") + @DeleteMapping({"{id}"}) + public ResponseEntity deleteAuctionItemById(@PathVariable Long id) { + auctionItemServiceImpl.deleteAuctionItemById(id); return ResponseEntity.status(HttpStatus.OK).build(); } } diff --git a/src/main/java/megabrain/gyeongnamgyeongmae/auctionItem/domain/entity/AuctionItem.java b/src/main/java/megabrain/gyeongnamgyeongmae/auctionItem/domain/entity/AuctionItem.java index 84e20e2..1bb8b72 100644 --- a/src/main/java/megabrain/gyeongnamgyeongmae/auctionItem/domain/entity/AuctionItem.java +++ b/src/main/java/megabrain/gyeongnamgyeongmae/auctionItem/domain/entity/AuctionItem.java @@ -13,13 +13,16 @@ @Entity @Table(name = "AuctionItem") @NoArgsConstructor(access = AccessLevel.PROTECTED) -public class AuctionItem extends BaseTimeEntity { +public class AuctionItem extends BaseTimeEntity { @Id @GeneratedValue(strategy = GenerationType.IDENTITY) @Column(name = "auction_id") private Long id; + @Column(name = "removed") + private boolean removed = false; + @ManyToOne(fetch = FetchType.LAZY) @JoinColumn(name = "member_id") private Member member; @@ -48,13 +51,12 @@ public class AuctionItem extends BaseTimeEntity { @Column(name = "auction_status") @Enumerated(EnumType.STRING) private AuctionStatus status = AuctionStatus.ONGOING; -// -// @OneToOne(fetch = FetchType.EAGER) -// @JoinColumn(name = "location_id") -// private Location location; + // + // @OneToOne(fetch = FetchType.EAGER) + // @JoinColumn(name = "location_id") + // private Location location; - @Column - private Long temperature; + @Column private Long temperature; @Builder public AuctionItem(Long id, String name, long price, Content content, LocalDateTime closedTime) { @@ -95,4 +97,14 @@ public void updateAuctionItem(UpdateAuctionItemRequest upDateAuctionItemRequest) this.closedTime = upDateAuctionItemRequest.getClosedTime(); this.status = upDateAuctionItemRequest.getAuctionStatus(); } + + public void removeAuctionItem(AuctionItem auctionItem) { + this.removed = true; + } + + public void checkShowAuctionItem(AuctionItem auctionItem) { + if (this.removed) { + throw new RuntimeException("삭제된 상품입니다."); + } + } } diff --git a/src/main/java/megabrain/gyeongnamgyeongmae/auctionItem/domain/repostiory/AuctionItemRepositoryCustomImpl.java b/src/main/java/megabrain/gyeongnamgyeongmae/auctionItem/domain/repostiory/AuctionItemRepositoryCustomImpl.java index c768e9a..ccf277c 100644 --- a/src/main/java/megabrain/gyeongnamgyeongmae/auctionItem/domain/repostiory/AuctionItemRepositoryCustomImpl.java +++ b/src/main/java/megabrain/gyeongnamgyeongmae/auctionItem/domain/repostiory/AuctionItemRepositoryCustomImpl.java @@ -1,7 +1,5 @@ package megabrain.gyeongnamgyeongmae.auctionItem.domain.repostiory; -import static megabrain.gyeongnamgyeongmae.auctionItem.domain.entity.QAuctionItem.auctionItem; - import com.querydsl.core.BooleanBuilder; import com.querydsl.core.types.OrderSpecifier; import com.querydsl.jpa.impl.JPAQuery; @@ -36,7 +34,10 @@ public Page searchAuctionItemPage( BooleanBuilder statusBuilder = new BooleanBuilder(); BooleanBuilder sellBuilder = new BooleanBuilder(); BooleanBuilder keywordStatus = new BooleanBuilder(); + BooleanBuilder categoryStatus = new BooleanBuilder(); + searchAuctionItemSortedRequest.applySearchCategory(categoryStatus, auctionItem); + searchAuctionItemSortedRequest.applySearchStatus(statusBuilder, auctionItem); searchAuctionItemSortedRequest.applyKeyWordStatus(keywordStatus, auctionItem); searchAuctionItemSortedRequest.applySearchPrice(orderSpecifiers, auctionItem); searchAuctionItemSortedRequest.applySearchLike(orderSpecifiers, auctionItem); @@ -49,7 +50,8 @@ public Page searchAuctionItemPage( .selectFrom(auctionItem) .innerJoin(auctionItem.category, category) .where( - category.name.eq(searchAuctionItemSortedRequest.getCategory()), + auctionItem.removed.eq(false), + categoryStatus, statusBuilder, sellBuilder, keywordStatus); diff --git a/src/main/java/megabrain/gyeongnamgyeongmae/auctionItem/dto/SearchItem/SearchAuctionItemSortedRequest.java b/src/main/java/megabrain/gyeongnamgyeongmae/auctionItem/dto/SearchItem/SearchAuctionItemSortedRequest.java index e22a888..45aa055 100644 --- a/src/main/java/megabrain/gyeongnamgyeongmae/auctionItem/dto/SearchItem/SearchAuctionItemSortedRequest.java +++ b/src/main/java/megabrain/gyeongnamgyeongmae/auctionItem/dto/SearchItem/SearchAuctionItemSortedRequest.java @@ -13,7 +13,7 @@ public class SearchAuctionItemSortedRequest { private String keyword = null; - private String category; + private String category = null; private SearchStatus search_status = SearchStatus.ALL; // 신품 중고품 전체 @@ -39,8 +39,6 @@ public class SearchAuctionItemSortedRequest { // @NotNull private boolean temperature; // 온도별 정렬 기준 - // 이 함수에 매개변수 인자로 - public void applyKeyWordStatus(BooleanBuilder status, QAuctionItem item) { if (this.keyword == null) { return; @@ -48,6 +46,13 @@ public void applyKeyWordStatus(BooleanBuilder status, QAuctionItem item) { status.and(item.name.like("%" + keyword + "%")); } + public void applySearchCategory(BooleanBuilder status, QAuctionItem item) { + if (this.category == null) { + return; + } + status.and(item.category.name.eq(category)); + } + public void applySearchStatus(BooleanBuilder status, QAuctionItem item) { if (this.search_status == SearchStatus.NEW) { status.and(item.content.status.eq(AuctionItemStatus.NEW)); diff --git a/src/main/java/megabrain/gyeongnamgyeongmae/auctionItem/dto/UpdateAuctionItemRequest.java b/src/main/java/megabrain/gyeongnamgyeongmae/auctionItem/dto/UpdateAuctionItemRequest.java index 1b91bbc..421f81e 100644 --- a/src/main/java/megabrain/gyeongnamgyeongmae/auctionItem/dto/UpdateAuctionItemRequest.java +++ b/src/main/java/megabrain/gyeongnamgyeongmae/auctionItem/dto/UpdateAuctionItemRequest.java @@ -15,8 +15,6 @@ @AllArgsConstructor public class UpdateAuctionItemRequest { - @NotNull private Long id; - @NotEmpty private String name; @Min(1) diff --git a/src/main/java/megabrain/gyeongnamgyeongmae/auctionItem/service/Item/AuctionItemService.java b/src/main/java/megabrain/gyeongnamgyeongmae/auctionItem/service/Item/AuctionItemService.java index ae3fbb7..6e9ff38 100644 --- a/src/main/java/megabrain/gyeongnamgyeongmae/auctionItem/service/Item/AuctionItemService.java +++ b/src/main/java/megabrain/gyeongnamgyeongmae/auctionItem/service/Item/AuctionItemService.java @@ -14,7 +14,9 @@ public interface AuctionItemService { void updateAuctionItemViewCount(AuctionItem auctionItem); - void updateAuctionItem(UpdateAuctionItemRequest upDateAuctionItemRequest); + void updateAuctionItem(UpdateAuctionItemRequest upDateAuctionItemRequest, Long id); void checkClosedTime(LocalDateTime closedTime); + + void deleteAuctionItemById(Long id); } diff --git a/src/main/java/megabrain/gyeongnamgyeongmae/auctionItem/service/Item/AuctionItemServiceImpl.java b/src/main/java/megabrain/gyeongnamgyeongmae/auctionItem/service/Item/AuctionItemServiceImpl.java index 5424ac4..9ea1629 100644 --- a/src/main/java/megabrain/gyeongnamgyeongmae/auctionItem/service/Item/AuctionItemServiceImpl.java +++ b/src/main/java/megabrain/gyeongnamgyeongmae/auctionItem/service/Item/AuctionItemServiceImpl.java @@ -43,6 +43,7 @@ public void createAuctionItem(CreateAuctionItemRequest createAuctionItemRequest) @Transactional public AuctionItemResponse findAuctionItemById(Long id) { AuctionItem auctionItem = auctionItemRepository.findById(id).orElseThrow(RuntimeException::new); + auctionItem.checkShowAuctionItem(auctionItem); updateAuctionItemViewCount(auctionItem); return AuctionItemResponse.of(auctionItem); } @@ -55,14 +56,12 @@ public void updateAuctionItemViewCount(AuctionItem auctionItem) { @Override @Transactional - public void updateAuctionItem(UpdateAuctionItemRequest upDateAuctionItemRequest) { + public void updateAuctionItem(UpdateAuctionItemRequest upDateAuctionItemRequest, Long id) { checkClosedTime(upDateAuctionItemRequest.getClosedTime()); Category categoryEntity = categoryService.findCategoryByName(upDateAuctionItemRequest.getCategory()); - AuctionItem auctionItem = - auctionItemRepository - .findById(upDateAuctionItemRequest.getId()) - .orElseThrow(RuntimeException::new); + AuctionItem auctionItem = auctionItemRepository.findById(id).orElseThrow(RuntimeException::new); + auctionItem.checkShowAuctionItem(auctionItem); auctionItem.updateAuctionItem(upDateAuctionItemRequest); auctionItem.setCategory(categoryEntity); auctionItemRepository.save(auctionItem); @@ -75,4 +74,12 @@ public void checkClosedTime(LocalDateTime closedTime) { throw new RuntimeException("경매 종료 시간은 현재 시간보다 24시간 이후여야 합니다."); } } + + @Override + @Transactional + public void deleteAuctionItemById(Long id) { + AuctionItem auctionItem = auctionItemRepository.findById(id).orElseThrow(RuntimeException::new); + auctionItem.removeAuctionItem(auctionItem); + auctionItemRepository.save(auctionItem); + } } From 32169711ce6458120c390ce91bd94edfe0bc66d9 Mon Sep 17 00:00:00 2001 From: haroya01 Date: Wed, 13 Sep 2023 20:06:38 +0900 Subject: [PATCH 13/22] =?UTF-8?q?.env=20gitignore=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index 9a64ffb..6dac8d7 100644 --- a/.gitignore +++ b/.gitignore @@ -4,6 +4,7 @@ build/ !gradle/wrapper/gradle-wrapper.jar !**/src/main/**/build/ !**/src/test/**/build/ +.env ### IntelliJ IDEA ### .idea From 68d957c17120ea6acb5702fea18b5cdd1ecfec0b Mon Sep 17 00:00:00 2001 From: haroya01 Date: Thu, 14 Sep 2023 14:14:01 +0900 Subject: [PATCH 14/22] =?UTF-8?q?fix:=20=EC=9D=B4=EC=A0=84=20=EC=9E=91?= =?UTF-8?q?=EC=97=85=20=ED=8C=8C=EC=9D=BC=20=EB=B3=B5=EA=B5=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gradle/buildOutputCleanup/cache.properties | 2 + docker-compose.yml | 32 ++ .../domain/repository/ImageRepository.java | 6 - .../controller/AuctionItemController.java | 56 ---- .../AuctionItemSearchController.java | 34 -- .../domain/entity/AuctionItem.java | 110 ------ .../auctionItem/domain/entity/Content.java | 20 -- .../repostiory/AuctionItemRepository.java | 7 - .../AuctionItemRepositoryCustom.java | 12 - .../AuctionItemRepositoryCustomImpl.java | 68 ---- .../auctionItem/dto/AuctionItemFirstView.java | 50 --- .../dto/CreateAuctionItemRequest.java | 41 --- .../auctionItem/dto/CreateItemRequest.java | 43 --- .../SearchAuctionItemSortedRequest.java | 107 ------ .../dto/SearchItem/SearchPrice.java | 7 - .../dto/SearchItem/SearchStatus.java | 7 - .../dto/SearchItem/SearchTime.java | 7 - .../dto/UpdateAuctionItemRequest.java | 30 -- .../service/Item/AuctionItemServiceImpl.java | 85 ----- .../service/Item/IAuctionItemService.java | 20 -- .../Search/AuctionItemSearchService.java | 12 - .../commons/config/ObjectMapperConfig.java | 11 - .../commons/config/SecurityConfig.java | 39 --- .../commons/config/SwaggerConfig.java | 17 - .../AuctionItemCommentController.java | 59 ++++ .../controller/AuctionItemController.java | 57 ++++ .../AuctionItemSearchController.java | 35 ++ .../domain/entity/AuctionItem.java | 125 +++++++ .../domain/entity/AuctionItemStatus.java | 2 +- .../domain/entity/AuctionStatus.java | 2 +- .../auctionItem/domain/entity/Comment.java | 64 ++++ .../AuctionItemCommentRepository.java | 7 + .../AuctionItemCommentRepositoryCustom.java | 9 + ...uctionItemCommentRepositoryCustomImpl.java | 38 +++ .../repostiory/AuctionItemRepository.java | 6 + .../AuctionItemRepositoryCustom.java | 10 + .../AuctionItemRepositoryCustomImpl.java | 67 ++++ .../dto/AuctionItemCommentDeleteRequest.java | 13 + .../dto/AuctionItemCommentRequest.java | 14 + .../dto/AuctionItemCommentUpdateRequest.java | 14 + .../auctionItem/dto/AuctionItemFirstView.java | 53 +++ .../auctionItem/dto/AuctionItemResponse.java | 14 +- .../Comment/AuctionItemCommentChildDto.java | 58 ++++ .../Comment/AuctionItemCommentParentDto.java | 48 +++ .../dto/CreateAuctionItemRequest.java | 46 +++ .../SearchAuctionItemSortedRequest.java | 98 ++++++ .../dto/SearchItem/SearchStatus.java | 7 + .../dto/UpdateAuctionItemRequest.java | 42 +++ .../Comment/AuctionItemCommentService.java | 19 ++ .../AuctionItemCommentServiceImpl.java | 88 +++++ .../service/Item/AuctionItemService.java | 11 +- .../service/Item/AuctionItemServiceImpl.java | 92 +++++ .../Search/AuctionItemSearchService.java | 10 + .../Search/AuctionItemSearchServiceImpl.java | 15 +- .../controller/CategoryController.java | 6 +- .../category}/domain/entity/Category.java | 3 +- .../domain/repository/CategoryRepository.java | 4 +- .../category}/dto/CreateCategoryRequest.java | 4 +- .../category}/service/CategoryService.java | 6 +- .../category}/service/ICategoryService.java | 4 +- .../entity => domain/domain}/Image.java | 18 +- .../member/controller/MemberController.java | 8 +- .../member/domain/entity/Address.java | 2 +- .../member/domain/entity/Member.java | 4 +- .../domain/repository/MemberRepository.java | 4 +- .../member/dto/MemberCreateRequest.java | 4 +- .../member/service/GeneralMemberService.java | 6 +- .../member/service/MemberService.java | 4 +- .../{ => global}/commons/BaseTimeEntity.java | 2 +- .../resolver/LoginMemberArgumentResolver.java | 2 +- .../config/JpaAuditingConfig.java | 2 +- .../global/config/ObjectMapperConfig.java | 11 + .../config/QueryDslConfig.java | 17 +- .../global/config/SecurityConfig.java | 39 +++ .../global/config/SwaggerConfig.java | 17 + .../application-postgresql.properties | 6 - src/main/resources/application-postgresql.yml | 17 + src/main/resources/application.properties | 1 - src/main/resources/application.yml | 3 + .../controller/AuctionControllerTest.java | 315 +++++++++--------- .../fixture/AuctionItemFixture.java | 100 +++--- .../member/MemberServiceTest.java | 128 +++---- .../controller/MemberControllerTest.java | 170 +++++----- 83 files changed, 1632 insertions(+), 1221 deletions(-) create mode 100644 .gradle/buildOutputCleanup/cache.properties create mode 100755 docker-compose.yml delete mode 100644 src/main/java/megabrain/gyeongnamgyeongmae/Image/domain/repository/ImageRepository.java delete mode 100644 src/main/java/megabrain/gyeongnamgyeongmae/auctionItem/controller/AuctionItemController.java delete mode 100644 src/main/java/megabrain/gyeongnamgyeongmae/auctionItem/controller/AuctionItemSearchController.java delete mode 100644 src/main/java/megabrain/gyeongnamgyeongmae/auctionItem/domain/entity/AuctionItem.java delete mode 100644 src/main/java/megabrain/gyeongnamgyeongmae/auctionItem/domain/entity/Content.java delete mode 100644 src/main/java/megabrain/gyeongnamgyeongmae/auctionItem/domain/repostiory/AuctionItemRepository.java delete mode 100644 src/main/java/megabrain/gyeongnamgyeongmae/auctionItem/domain/repostiory/AuctionItemRepositoryCustom.java delete mode 100644 src/main/java/megabrain/gyeongnamgyeongmae/auctionItem/domain/repostiory/AuctionItemRepositoryCustomImpl.java delete mode 100644 src/main/java/megabrain/gyeongnamgyeongmae/auctionItem/dto/AuctionItemFirstView.java delete mode 100644 src/main/java/megabrain/gyeongnamgyeongmae/auctionItem/dto/CreateAuctionItemRequest.java delete mode 100644 src/main/java/megabrain/gyeongnamgyeongmae/auctionItem/dto/CreateItemRequest.java delete mode 100644 src/main/java/megabrain/gyeongnamgyeongmae/auctionItem/dto/SearchItem/SearchAuctionItemSortedRequest.java delete mode 100644 src/main/java/megabrain/gyeongnamgyeongmae/auctionItem/dto/SearchItem/SearchPrice.java delete mode 100644 src/main/java/megabrain/gyeongnamgyeongmae/auctionItem/dto/SearchItem/SearchStatus.java delete mode 100644 src/main/java/megabrain/gyeongnamgyeongmae/auctionItem/dto/SearchItem/SearchTime.java delete mode 100644 src/main/java/megabrain/gyeongnamgyeongmae/auctionItem/dto/UpdateAuctionItemRequest.java delete mode 100644 src/main/java/megabrain/gyeongnamgyeongmae/auctionItem/service/Item/AuctionItemServiceImpl.java delete mode 100644 src/main/java/megabrain/gyeongnamgyeongmae/auctionItem/service/Item/IAuctionItemService.java delete mode 100644 src/main/java/megabrain/gyeongnamgyeongmae/auctionItem/service/Search/AuctionItemSearchService.java delete mode 100644 src/main/java/megabrain/gyeongnamgyeongmae/commons/config/ObjectMapperConfig.java delete mode 100644 src/main/java/megabrain/gyeongnamgyeongmae/commons/config/SecurityConfig.java delete mode 100644 src/main/java/megabrain/gyeongnamgyeongmae/commons/config/SwaggerConfig.java create mode 100644 src/main/java/megabrain/gyeongnamgyeongmae/domain/auctionItem/controller/AuctionItemCommentController.java create mode 100644 src/main/java/megabrain/gyeongnamgyeongmae/domain/auctionItem/controller/AuctionItemController.java create mode 100644 src/main/java/megabrain/gyeongnamgyeongmae/domain/auctionItem/controller/AuctionItemSearchController.java create mode 100644 src/main/java/megabrain/gyeongnamgyeongmae/domain/auctionItem/domain/entity/AuctionItem.java rename src/main/java/megabrain/gyeongnamgyeongmae/{ => domain}/auctionItem/domain/entity/AuctionItemStatus.java (77%) rename src/main/java/megabrain/gyeongnamgyeongmae/{ => domain}/auctionItem/domain/entity/AuctionStatus.java (78%) create mode 100644 src/main/java/megabrain/gyeongnamgyeongmae/domain/auctionItem/domain/entity/Comment.java create mode 100644 src/main/java/megabrain/gyeongnamgyeongmae/domain/auctionItem/domain/repostiory/AuctionItemCommentRepository.java create mode 100644 src/main/java/megabrain/gyeongnamgyeongmae/domain/auctionItem/domain/repostiory/AuctionItemCommentRepositoryCustom.java create mode 100644 src/main/java/megabrain/gyeongnamgyeongmae/domain/auctionItem/domain/repostiory/AuctionItemCommentRepositoryCustomImpl.java create mode 100644 src/main/java/megabrain/gyeongnamgyeongmae/domain/auctionItem/domain/repostiory/AuctionItemRepository.java create mode 100644 src/main/java/megabrain/gyeongnamgyeongmae/domain/auctionItem/domain/repostiory/AuctionItemRepositoryCustom.java create mode 100644 src/main/java/megabrain/gyeongnamgyeongmae/domain/auctionItem/domain/repostiory/AuctionItemRepositoryCustomImpl.java create mode 100644 src/main/java/megabrain/gyeongnamgyeongmae/domain/auctionItem/dto/AuctionItemCommentDeleteRequest.java create mode 100644 src/main/java/megabrain/gyeongnamgyeongmae/domain/auctionItem/dto/AuctionItemCommentRequest.java create mode 100644 src/main/java/megabrain/gyeongnamgyeongmae/domain/auctionItem/dto/AuctionItemCommentUpdateRequest.java create mode 100644 src/main/java/megabrain/gyeongnamgyeongmae/domain/auctionItem/dto/AuctionItemFirstView.java rename src/main/java/megabrain/gyeongnamgyeongmae/{ => domain}/auctionItem/dto/AuctionItemResponse.java (74%) create mode 100644 src/main/java/megabrain/gyeongnamgyeongmae/domain/auctionItem/dto/Comment/AuctionItemCommentChildDto.java create mode 100644 src/main/java/megabrain/gyeongnamgyeongmae/domain/auctionItem/dto/Comment/AuctionItemCommentParentDto.java create mode 100644 src/main/java/megabrain/gyeongnamgyeongmae/domain/auctionItem/dto/CreateAuctionItemRequest.java create mode 100644 src/main/java/megabrain/gyeongnamgyeongmae/domain/auctionItem/dto/SearchItem/SearchAuctionItemSortedRequest.java create mode 100644 src/main/java/megabrain/gyeongnamgyeongmae/domain/auctionItem/dto/SearchItem/SearchStatus.java create mode 100644 src/main/java/megabrain/gyeongnamgyeongmae/domain/auctionItem/dto/UpdateAuctionItemRequest.java create mode 100644 src/main/java/megabrain/gyeongnamgyeongmae/domain/auctionItem/service/Comment/AuctionItemCommentService.java create mode 100644 src/main/java/megabrain/gyeongnamgyeongmae/domain/auctionItem/service/Comment/AuctionItemCommentServiceImpl.java rename src/main/java/megabrain/gyeongnamgyeongmae/{ => domain}/auctionItem/service/Item/AuctionItemService.java (52%) create mode 100644 src/main/java/megabrain/gyeongnamgyeongmae/domain/auctionItem/service/Item/AuctionItemServiceImpl.java create mode 100644 src/main/java/megabrain/gyeongnamgyeongmae/domain/auctionItem/service/Search/AuctionItemSearchService.java rename src/main/java/megabrain/gyeongnamgyeongmae/{ => domain}/auctionItem/service/Search/AuctionItemSearchServiceImpl.java (56%) rename src/main/java/megabrain/gyeongnamgyeongmae/{Category => domain/category}/controller/CategoryController.java (79%) rename src/main/java/megabrain/gyeongnamgyeongmae/{Category => domain/category}/domain/entity/Category.java (83%) rename src/main/java/megabrain/gyeongnamgyeongmae/{Category => domain/category}/domain/repository/CategoryRepository.java (60%) rename src/main/java/megabrain/gyeongnamgyeongmae/{Category => domain/category}/dto/CreateCategoryRequest.java (78%) rename src/main/java/megabrain/gyeongnamgyeongmae/{Category => domain/category}/service/CategoryService.java (72%) rename src/main/java/megabrain/gyeongnamgyeongmae/{Category => domain/category}/service/ICategoryService.java (50%) rename src/main/java/megabrain/gyeongnamgyeongmae/{Image/domain/entity => domain/domain}/Image.java (59%) rename src/main/java/megabrain/gyeongnamgyeongmae/{ => domain}/member/controller/MemberController.java (81%) rename src/main/java/megabrain/gyeongnamgyeongmae/{ => domain}/member/domain/entity/Address.java (68%) rename src/main/java/megabrain/gyeongnamgyeongmae/{ => domain}/member/domain/entity/Member.java (85%) rename src/main/java/megabrain/gyeongnamgyeongmae/{ => domain}/member/domain/repository/MemberRepository.java (56%) rename src/main/java/megabrain/gyeongnamgyeongmae/{ => domain}/member/dto/MemberCreateRequest.java (89%) rename src/main/java/megabrain/gyeongnamgyeongmae/{ => domain}/member/service/GeneralMemberService.java (75%) rename src/main/java/megabrain/gyeongnamgyeongmae/{ => domain}/member/service/MemberService.java (53%) rename src/main/java/megabrain/gyeongnamgyeongmae/{ => global}/commons/BaseTimeEntity.java (91%) rename src/main/java/megabrain/gyeongnamgyeongmae/{ => global}/commons/resolver/LoginMemberArgumentResolver.java (93%) rename src/main/java/megabrain/gyeongnamgyeongmae/{commons => global}/config/JpaAuditingConfig.java (79%) create mode 100644 src/main/java/megabrain/gyeongnamgyeongmae/global/config/ObjectMapperConfig.java rename src/main/java/megabrain/gyeongnamgyeongmae/{commons => global}/config/QueryDslConfig.java (55%) create mode 100644 src/main/java/megabrain/gyeongnamgyeongmae/global/config/SecurityConfig.java create mode 100644 src/main/java/megabrain/gyeongnamgyeongmae/global/config/SwaggerConfig.java delete mode 100644 src/main/resources/application-postgresql.properties create mode 100644 src/main/resources/application-postgresql.yml delete mode 100644 src/main/resources/application.properties create mode 100644 src/main/resources/application.yml diff --git a/.gradle/buildOutputCleanup/cache.properties b/.gradle/buildOutputCleanup/cache.properties new file mode 100644 index 0000000..1643a5f --- /dev/null +++ b/.gradle/buildOutputCleanup/cache.properties @@ -0,0 +1,2 @@ +#Wed Sep 13 19:18:33 KST 2023 +gradle.version=8.2.1 diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100755 index 0000000..74fefe4 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,32 @@ +version: '3.6' + +services: + backend: + container_name: gg-backend + image: ghcr.io/gyeongnam-gyeongmae/gyeongnam-gyeongmae-api:latest + env_file: + - .env + ports: + - 12000:12000 + networks: + - gg-backend + postgres: + container_name: gg-postgres + image: postgres:14.1 + environment: + - POSTGRES_USER=${POSTGRES_USER} + - POSTGRES_PASSWORD=${POSTGRES_PASSWORD} + - POSTGRES_DB=${POSTGRES_DB} + ports: + - 15432:5432 + networks: + - gg-backend + volumes: + - postgres-data:/var/lib/postgresql/data + - ./install-extensions.sql:/docker-entrypoint-initdb.d/initialize.sql + +volumes: + postgres-data: + +networks: + gg-backend: diff --git a/src/main/java/megabrain/gyeongnamgyeongmae/Image/domain/repository/ImageRepository.java b/src/main/java/megabrain/gyeongnamgyeongmae/Image/domain/repository/ImageRepository.java deleted file mode 100644 index c59172f..0000000 --- a/src/main/java/megabrain/gyeongnamgyeongmae/Image/domain/repository/ImageRepository.java +++ /dev/null @@ -1,6 +0,0 @@ -package megabrain.gyeongnamgyeongmae.Image.domain.repository; - -import megabrain.gyeongnamgyeongmae.Image.domain.entity.Image; -import org.springframework.data.jpa.repository.JpaRepository; - -public interface ImageRepository extends JpaRepository {} diff --git a/src/main/java/megabrain/gyeongnamgyeongmae/auctionItem/controller/AuctionItemController.java b/src/main/java/megabrain/gyeongnamgyeongmae/auctionItem/controller/AuctionItemController.java deleted file mode 100644 index 668cdd6..0000000 --- a/src/main/java/megabrain/gyeongnamgyeongmae/auctionItem/controller/AuctionItemController.java +++ /dev/null @@ -1,56 +0,0 @@ -package megabrain.gyeongnamgyeongmae.auctionItem.controller; - -import io.swagger.v3.oas.annotations.Operation; -import io.swagger.v3.oas.annotations.tags.Tag; -import javax.validation.Valid; -import lombok.RequiredArgsConstructor; -import megabrain.gyeongnamgyeongmae.Category.service.CategoryService; -import megabrain.gyeongnamgyeongmae.auctionItem.dto.*; -import megabrain.gyeongnamgyeongmae.auctionItem.service.Item.AuctionItemServiceImpl; -import megabrain.gyeongnamgyeongmae.member.service.MemberService; -import org.springframework.http.HttpStatus; -import org.springframework.http.ResponseEntity; -import org.springframework.web.bind.annotation.*; - -@Tag(name = "경매품 게시", description = "경매품 게시 관련 API") -@RequestMapping("api/auctions") -@RestController -@RequiredArgsConstructor -public class AuctionItemController { - - private final AuctionItemServiceImpl auctionItemServiceImpl; - private final CategoryService categoryService; - private final MemberService memberService; - - @Operation(summary = "Post AuctionItem", description = "경매품 올리기") - @ResponseStatus(HttpStatus.CREATED) - @PostMapping() - public ResponseEntity createAuctionItem( - @RequestBody @Valid CreateAuctionItemRequest createAuctionItemRequest) { - auctionItemServiceImpl.createAuctionItem(createAuctionItemRequest); - return ResponseEntity.status(HttpStatus.CREATED).build(); - } - - @Operation(summary = "Show AuctionItem", description = "경매품 상세보기") - @GetMapping("{id}") - public ResponseEntity findAuctionItemById(@PathVariable Long id) { - AuctionItemResponse auctionItemResponse = auctionItemServiceImpl.findAuctionItemById(id); - return ResponseEntity.ok(auctionItemResponse); - } - - @Operation(summary = "Update AuctionItem", description = "경매품 수정하기") - @PutMapping("{id}") - public ResponseEntity updateAuctionItemById( - @PathVariable Long id, - @RequestBody @Valid UpdateAuctionItemRequest upDateAuctionItemRequest) { - auctionItemServiceImpl.updateAuctionItem(upDateAuctionItemRequest, id); - return ResponseEntity.status(HttpStatus.OK).build(); - } - - @Operation(summary = "Delete AuctionItem", description = "경매품 삭제하기") - @DeleteMapping({"{id}"}) - public ResponseEntity deleteAuctionItemById(@PathVariable Long id) { - auctionItemServiceImpl.deleteAuctionItemById(id); - return ResponseEntity.status(HttpStatus.OK).build(); - } -} diff --git a/src/main/java/megabrain/gyeongnamgyeongmae/auctionItem/controller/AuctionItemSearchController.java b/src/main/java/megabrain/gyeongnamgyeongmae/auctionItem/controller/AuctionItemSearchController.java deleted file mode 100644 index c7d8a02..0000000 --- a/src/main/java/megabrain/gyeongnamgyeongmae/auctionItem/controller/AuctionItemSearchController.java +++ /dev/null @@ -1,34 +0,0 @@ -package megabrain.gyeongnamgyeongmae.auctionItem.controller; - -import io.swagger.v3.oas.annotations.Operation; -import io.swagger.v3.oas.annotations.tags.Tag; -import lombok.RequiredArgsConstructor; -import megabrain.gyeongnamgyeongmae.auctionItem.domain.repostiory.AuctionItemRepository; -import megabrain.gyeongnamgyeongmae.auctionItem.dto.AuctionItemFirstView; -import megabrain.gyeongnamgyeongmae.auctionItem.dto.SearchItem.SearchAuctionItemSortedRequest; -import megabrain.gyeongnamgyeongmae.auctionItem.service.Search.AuctionItemSearchServiceImpl; -import org.springframework.data.domain.Page; -import org.springframework.data.domain.Pageable; -import org.springframework.http.ResponseEntity; -import org.springframework.web.bind.annotation.*; - -@Tag(name = "경매품 검색", description = "경매품 검색 관련 API") -@RequestMapping("api/auctions/search") -@RestController -@RequiredArgsConstructor -public class AuctionItemSearchController { - - private final AuctionItemSearchServiceImpl auctionItemSearchServiceImpl; - private final AuctionItemRepository auctionItemRepository; - - @Operation(summary = "Search AuctionItem", description = "경매품 검색하기") - @GetMapping("") - public ResponseEntity> findItemCategory( - @ModelAttribute SearchAuctionItemSortedRequest searchAuctionItemSortedRequest, - Pageable pageable) { - Page result = - auctionItemSearchServiceImpl.findAuctionItembyRequest( - searchAuctionItemSortedRequest, pageable); - return ResponseEntity.ok(result); - } -} diff --git a/src/main/java/megabrain/gyeongnamgyeongmae/auctionItem/domain/entity/AuctionItem.java b/src/main/java/megabrain/gyeongnamgyeongmae/auctionItem/domain/entity/AuctionItem.java deleted file mode 100644 index 1bb8b72..0000000 --- a/src/main/java/megabrain/gyeongnamgyeongmae/auctionItem/domain/entity/AuctionItem.java +++ /dev/null @@ -1,110 +0,0 @@ -package megabrain.gyeongnamgyeongmae.auctionItem.domain.entity; - -import java.time.LocalDateTime; -import javax.persistence.*; -import lombok.*; -import megabrain.gyeongnamgyeongmae.Category.domain.entity.Category; -import megabrain.gyeongnamgyeongmae.auctionItem.dto.UpdateAuctionItemRequest; -import megabrain.gyeongnamgyeongmae.commons.BaseTimeEntity; -import megabrain.gyeongnamgyeongmae.member.domain.entity.Member; - -@Getter -@Setter -@Entity -@Table(name = "AuctionItem") -@NoArgsConstructor(access = AccessLevel.PROTECTED) -public class AuctionItem extends BaseTimeEntity { - - @Id - @GeneratedValue(strategy = GenerationType.IDENTITY) - @Column(name = "auction_id") - private Long id; - - @Column(name = "removed") - private boolean removed = false; - - @ManyToOne(fetch = FetchType.LAZY) - @JoinColumn(name = "member_id") - private Member member; - - @Column(name = "name") - private String name; - - @Column(name = "highest_price") - private Long price; - - @Embedded private Content content; - - @ManyToOne(fetch = FetchType.EAGER) - @JoinColumn(name = "category_id") - private Category category; - - @Column(name = "close_at") - protected LocalDateTime closedTime; - - @Column(name = "like_count") - private Long like_count = 0L; - - @Column(name = "view_count") - private Long view_count = 0L; - - @Column(name = "auction_status") - @Enumerated(EnumType.STRING) - private AuctionStatus status = AuctionStatus.ONGOING; - // - // @OneToOne(fetch = FetchType.EAGER) - // @JoinColumn(name = "location_id") - // private Location location; - - @Column private Long temperature; - - @Builder - public AuctionItem(Long id, String name, long price, Content content, LocalDateTime closedTime) { - - this.id = id; - this.name = name; - this.price = price; - this.content = content; - this.closedTime = closedTime; - } - - @Builder - public AuctionItem( - Long id, - String name, - long price, - Content content, - LocalDateTime closedTime, - Category category, - Member member, - LocalDateTime createdAt, - LocalDateTime updatedAt) { - this.id = id; - this.name = name; - this.price = price; - this.content = content; - this.closedTime = closedTime; - this.category = category; - this.member = member; - this.createdAt = createdAt; - this.updatedAt = updatedAt; - } - - public void updateAuctionItem(UpdateAuctionItemRequest upDateAuctionItemRequest) { - this.name = upDateAuctionItemRequest.getName(); - this.price = upDateAuctionItemRequest.getPrice(); - this.content = upDateAuctionItemRequest.getContent(); - this.closedTime = upDateAuctionItemRequest.getClosedTime(); - this.status = upDateAuctionItemRequest.getAuctionStatus(); - } - - public void removeAuctionItem(AuctionItem auctionItem) { - this.removed = true; - } - - public void checkShowAuctionItem(AuctionItem auctionItem) { - if (this.removed) { - throw new RuntimeException("삭제된 상품입니다."); - } - } -} diff --git a/src/main/java/megabrain/gyeongnamgyeongmae/auctionItem/domain/entity/Content.java b/src/main/java/megabrain/gyeongnamgyeongmae/auctionItem/domain/entity/Content.java deleted file mode 100644 index a9a5a17..0000000 --- a/src/main/java/megabrain/gyeongnamgyeongmae/auctionItem/domain/entity/Content.java +++ /dev/null @@ -1,20 +0,0 @@ -package megabrain.gyeongnamgyeongmae.auctionItem.domain.entity; - -import javax.persistence.Embeddable; -import javax.persistence.Lob; -import lombok.AllArgsConstructor; -import lombok.Builder; -import lombok.Getter; -import lombok.NoArgsConstructor; - -@Builder -@Getter -@NoArgsConstructor -@AllArgsConstructor -@Embeddable -public class Content { - - @Lob private String content; - - private AuctionItemStatus status; -} diff --git a/src/main/java/megabrain/gyeongnamgyeongmae/auctionItem/domain/repostiory/AuctionItemRepository.java b/src/main/java/megabrain/gyeongnamgyeongmae/auctionItem/domain/repostiory/AuctionItemRepository.java deleted file mode 100644 index f553d7b..0000000 --- a/src/main/java/megabrain/gyeongnamgyeongmae/auctionItem/domain/repostiory/AuctionItemRepository.java +++ /dev/null @@ -1,7 +0,0 @@ -package megabrain.gyeongnamgyeongmae.auctionItem.domain.repostiory; - -import megabrain.gyeongnamgyeongmae.auctionItem.domain.entity.AuctionItem; -import org.springframework.data.jpa.repository.JpaRepository; - -public interface AuctionItemRepository - extends JpaRepository, AuctionItemRepositoryCustom {} diff --git a/src/main/java/megabrain/gyeongnamgyeongmae/auctionItem/domain/repostiory/AuctionItemRepositoryCustom.java b/src/main/java/megabrain/gyeongnamgyeongmae/auctionItem/domain/repostiory/AuctionItemRepositoryCustom.java deleted file mode 100644 index 9e18cdf..0000000 --- a/src/main/java/megabrain/gyeongnamgyeongmae/auctionItem/domain/repostiory/AuctionItemRepositoryCustom.java +++ /dev/null @@ -1,12 +0,0 @@ -package megabrain.gyeongnamgyeongmae.auctionItem.domain.repostiory; - -import megabrain.gyeongnamgyeongmae.auctionItem.domain.entity.AuctionItem; -import megabrain.gyeongnamgyeongmae.auctionItem.dto.SearchItem.SearchAuctionItemSortedRequest; -import org.springframework.data.domain.Page; -import org.springframework.data.domain.Pageable; - -public interface AuctionItemRepositoryCustom { - - Page searchAuctionItemPage( - SearchAuctionItemSortedRequest searchAuctionItemSortedRequest, Pageable pageable); -} diff --git a/src/main/java/megabrain/gyeongnamgyeongmae/auctionItem/domain/repostiory/AuctionItemRepositoryCustomImpl.java b/src/main/java/megabrain/gyeongnamgyeongmae/auctionItem/domain/repostiory/AuctionItemRepositoryCustomImpl.java deleted file mode 100644 index ccf277c..0000000 --- a/src/main/java/megabrain/gyeongnamgyeongmae/auctionItem/domain/repostiory/AuctionItemRepositoryCustomImpl.java +++ /dev/null @@ -1,68 +0,0 @@ -package megabrain.gyeongnamgyeongmae.auctionItem.domain.repostiory; - -import com.querydsl.core.BooleanBuilder; -import com.querydsl.core.types.OrderSpecifier; -import com.querydsl.jpa.impl.JPAQuery; -import com.querydsl.jpa.impl.JPAQueryFactory; -import java.util.ArrayList; -import java.util.List; -import javax.persistence.EntityManager; -import megabrain.gyeongnamgyeongmae.Category.domain.entity.QCategory; -import megabrain.gyeongnamgyeongmae.auctionItem.domain.entity.AuctionItem; -import megabrain.gyeongnamgyeongmae.auctionItem.domain.entity.QAuctionItem; -import megabrain.gyeongnamgyeongmae.auctionItem.dto.SearchItem.SearchAuctionItemSortedRequest; -import org.springframework.data.domain.Page; -import org.springframework.data.domain.PageImpl; -import org.springframework.data.domain.Pageable; - -public class AuctionItemRepositoryCustomImpl implements AuctionItemRepositoryCustom { - - private final JPAQueryFactory queryFactory; - - public AuctionItemRepositoryCustomImpl(EntityManager em) { - this.queryFactory = new JPAQueryFactory(em); - } - - @Override - public Page searchAuctionItemPage( - SearchAuctionItemSortedRequest searchAuctionItemSortedRequest, Pageable pageable) { - - QAuctionItem auctionItem = QAuctionItem.auctionItem; - QCategory category = QCategory.category; - - List> orderSpecifiers = new ArrayList<>(); - BooleanBuilder statusBuilder = new BooleanBuilder(); - BooleanBuilder sellBuilder = new BooleanBuilder(); - BooleanBuilder keywordStatus = new BooleanBuilder(); - BooleanBuilder categoryStatus = new BooleanBuilder(); - - searchAuctionItemSortedRequest.applySearchCategory(categoryStatus, auctionItem); - searchAuctionItemSortedRequest.applySearchStatus(statusBuilder, auctionItem); - searchAuctionItemSortedRequest.applyKeyWordStatus(keywordStatus, auctionItem); - searchAuctionItemSortedRequest.applySearchPrice(orderSpecifiers, auctionItem); - searchAuctionItemSortedRequest.applySearchLike(orderSpecifiers, auctionItem); - searchAuctionItemSortedRequest.applySearchView(orderSpecifiers, auctionItem); - searchAuctionItemSortedRequest.applySearchTime(orderSpecifiers, auctionItem); - searchAuctionItemSortedRequest.applySearchClosed(sellBuilder, auctionItem); - - JPAQuery query = - queryFactory - .selectFrom(auctionItem) - .innerJoin(auctionItem.category, category) - .where( - auctionItem.removed.eq(false), - categoryStatus, - statusBuilder, - sellBuilder, - keywordStatus); - - List results = - query - .orderBy(orderSpecifiers.toArray(new OrderSpecifier[0])) - .offset(pageable.getOffset()) - .limit(pageable.getPageSize()) - .fetch(); - - return new PageImpl<>(results, pageable, results.size()); - } -} diff --git a/src/main/java/megabrain/gyeongnamgyeongmae/auctionItem/dto/AuctionItemFirstView.java b/src/main/java/megabrain/gyeongnamgyeongmae/auctionItem/dto/AuctionItemFirstView.java deleted file mode 100644 index 0a00228..0000000 --- a/src/main/java/megabrain/gyeongnamgyeongmae/auctionItem/dto/AuctionItemFirstView.java +++ /dev/null @@ -1,50 +0,0 @@ -package megabrain.gyeongnamgyeongmae.auctionItem.dto; - -import java.time.LocalDateTime; -import lombok.AllArgsConstructor; -import lombok.Builder; -import lombok.Getter; -import lombok.NoArgsConstructor; -import megabrain.gyeongnamgyeongmae.auctionItem.domain.entity.AuctionItem; -import megabrain.gyeongnamgyeongmae.auctionItem.domain.entity.AuctionItemStatus; -import megabrain.gyeongnamgyeongmae.auctionItem.domain.entity.AuctionStatus; -import megabrain.gyeongnamgyeongmae.member.domain.entity.Address; - -@Builder -@Getter -@NoArgsConstructor -@AllArgsConstructor -public class AuctionItemFirstView { - - private Long id; - - private String name; - - private LocalDateTime closedTime; - - private AuctionItemStatus auctionItemStatus; - - private AuctionStatus status; - - private Address address; - - private Long like_count; - - private Long view_count; - - private Long price; - - public static AuctionItemFirstView of(AuctionItem auctionItem) { - return AuctionItemFirstView.builder() - .id(auctionItem.getId()) - .name(auctionItem.getName()) - .address(auctionItem.getMember().getAddress()) - .like_count(auctionItem.getLike_count()) - .view_count(auctionItem.getView_count()) - .price(auctionItem.getPrice()) - .closedTime(auctionItem.getClosedTime()) - .auctionItemStatus(auctionItem.getContent().getStatus()) - .status(auctionItem.getStatus()) - .build(); - } -} diff --git a/src/main/java/megabrain/gyeongnamgyeongmae/auctionItem/dto/CreateAuctionItemRequest.java b/src/main/java/megabrain/gyeongnamgyeongmae/auctionItem/dto/CreateAuctionItemRequest.java deleted file mode 100644 index b843e49..0000000 --- a/src/main/java/megabrain/gyeongnamgyeongmae/auctionItem/dto/CreateAuctionItemRequest.java +++ /dev/null @@ -1,41 +0,0 @@ -package megabrain.gyeongnamgyeongmae.auctionItem.dto; - -import java.time.LocalDateTime; -import javax.validation.constraints.NotNull; -import lombok.*; -import megabrain.gyeongnamgyeongmae.auctionItem.domain.entity.AuctionItem; -import megabrain.gyeongnamgyeongmae.auctionItem.domain.entity.Content; - -@Builder -@Getter -@NoArgsConstructor(access = AccessLevel.PRIVATE) -@AllArgsConstructor -public class CreateAuctionItemRequest { - - @NotNull private String name; - - @NotNull private Integer price; - - @NotNull private String category; - - @NotNull private Content content; - - @NotNull private LocalDateTime closedTime; - - @NotNull private Long member; - - public AuctionItem toEntity() { - Content content = - Content.builder() - .content(this.content.getContent()) - .status(this.content.getStatus()) - .build(); - - return AuctionItem.builder() - .name(name) - .price(price) - .content(content) - .closedTime(closedTime) - .build(); - } -} diff --git a/src/main/java/megabrain/gyeongnamgyeongmae/auctionItem/dto/CreateItemRequest.java b/src/main/java/megabrain/gyeongnamgyeongmae/auctionItem/dto/CreateItemRequest.java deleted file mode 100644 index 61cdfe1..0000000 --- a/src/main/java/megabrain/gyeongnamgyeongmae/auctionItem/dto/CreateItemRequest.java +++ /dev/null @@ -1,43 +0,0 @@ -package megabrain.gyeongnamgyeongmae.auctionItem.dto; - -import java.time.LocalDateTime; -import javax.validation.constraints.NotNull; -import lombok.*; -import megabrain.gyeongnamgyeongmae.auctionItem.domain.entity.AuctionItem; -import megabrain.gyeongnamgyeongmae.auctionItem.domain.entity.AuctionItemStatus; -import megabrain.gyeongnamgyeongmae.auctionItem.domain.entity.Content; - -@Builder -@Getter -@NoArgsConstructor(access = AccessLevel.PRIVATE) -@AllArgsConstructor -public class CreateItemRequest { - - @NotNull private String name; - - @NotNull private Integer price; - - @NotNull private String category; - - @NotNull private Content content; - - @NotNull private LocalDateTime closedTime; - - @NotNull private Long member; - - public AuctionItem toEntity(CreateItemRequest createItemRequest) { - Content content = - Content.builder() - .content(String.valueOf(createItemRequest.content.getContent())) - .status( - AuctionItemStatus.valueOf(String.valueOf(createItemRequest.content.getStatus()))) - .build(); - - return AuctionItem.builder() - .name(name) - .price(price) - .content(content) - .closedTime(closedTime) - .build(); - } -} diff --git a/src/main/java/megabrain/gyeongnamgyeongmae/auctionItem/dto/SearchItem/SearchAuctionItemSortedRequest.java b/src/main/java/megabrain/gyeongnamgyeongmae/auctionItem/dto/SearchItem/SearchAuctionItemSortedRequest.java deleted file mode 100644 index 45aa055..0000000 --- a/src/main/java/megabrain/gyeongnamgyeongmae/auctionItem/dto/SearchItem/SearchAuctionItemSortedRequest.java +++ /dev/null @@ -1,107 +0,0 @@ -package megabrain.gyeongnamgyeongmae.auctionItem.dto.SearchItem; - -import com.querydsl.core.BooleanBuilder; -import com.querydsl.core.types.OrderSpecifier; -import java.util.List; -import lombok.*; -import megabrain.gyeongnamgyeongmae.auctionItem.domain.entity.AuctionItemStatus; -import megabrain.gyeongnamgyeongmae.auctionItem.domain.entity.AuctionStatus; -import megabrain.gyeongnamgyeongmae.auctionItem.domain.entity.QAuctionItem; - -@Data -public class SearchAuctionItemSortedRequest { - - private String keyword = null; - - private String category = null; - - private SearchStatus search_status = SearchStatus.ALL; // 신품 중고품 전체 - - private Boolean closed = Boolean.FALSE; // 이미 경매가 끝낸 개시글도 보기 - - private Boolean search_time = Boolean.FALSE; // 마감시간 근접 - - private Boolean like = Boolean.FALSE; // 좋아요 정렬 기준 - - private Boolean search_price = Boolean.FALSE; // 가격순 정렬 - - private Boolean view_count = Boolean.FALSE; // 조회수 정렬 기준 - - // @NotNull private Location my_location; // 나의 현재 위치 - - // @NotNull private int km; // 몇키로 반경 게시글 조회 - - // @NotNull private int town; // 몇개의 마을 조회 - - // @NotNull private boolean comment; // 댓글수 정렬 기준 - - // @NotNull private String member; // 이름 검색 - - // @NotNull private boolean temperature; // 온도별 정렬 기준 - - public void applyKeyWordStatus(BooleanBuilder status, QAuctionItem item) { - if (this.keyword == null) { - return; - } - status.and(item.name.like("%" + keyword + "%")); - } - - public void applySearchCategory(BooleanBuilder status, QAuctionItem item) { - if (this.category == null) { - return; - } - status.and(item.category.name.eq(category)); - } - - public void applySearchStatus(BooleanBuilder status, QAuctionItem item) { - if (this.search_status == SearchStatus.NEW) { - status.and(item.content.status.eq(AuctionItemStatus.NEW)); - return; - } - if (this.search_status == SearchStatus.USED) { - status.and(item.content.status.eq(AuctionItemStatus.USED)); - return; - } - status.and(item.content.status.in(AuctionItemStatus.NEW, AuctionItemStatus.USED)); - } - - public void applySearchPrice(List> order, QAuctionItem item) { - if (this.search_price) { - order.add(item.price.desc()); - return; - } - order.add(item.price.asc()); - } - - public void applySearchLike(List> order, QAuctionItem item) { - if (this.like) { - order.add(item.like_count.desc()); - return; - } - order.add(item.like_count.asc()); - } - - public void applySearchView(List> order, QAuctionItem item) { - if (this.view_count) { - order.add(item.view_count.desc()); - return; - } - order.add(item.view_count.asc()); - } - - public void applySearchTime(List> order, QAuctionItem item) { - if (this.search_time) { - order.add(item.closedTime.desc()); - return; - } - order.add(item.closedTime.asc()); - } - - public void applySearchClosed(BooleanBuilder builder, QAuctionItem item) { - if (this.closed) { - builder.and(item.status.eq(AuctionStatus.ONGOING)); - return; - } - builder.and(item.status.in(AuctionStatus.ONGOING, AuctionStatus.CLOSED, AuctionStatus.BIDDING)); - } -} diff --git a/src/main/java/megabrain/gyeongnamgyeongmae/auctionItem/dto/SearchItem/SearchPrice.java b/src/main/java/megabrain/gyeongnamgyeongmae/auctionItem/dto/SearchItem/SearchPrice.java deleted file mode 100644 index d684e19..0000000 --- a/src/main/java/megabrain/gyeongnamgyeongmae/auctionItem/dto/SearchItem/SearchPrice.java +++ /dev/null @@ -1,7 +0,0 @@ -package megabrain.gyeongnamgyeongmae.auctionItem.dto.SearchItem; - -public enum SearchPrice { - LOW, - HIGH, - ALL -} diff --git a/src/main/java/megabrain/gyeongnamgyeongmae/auctionItem/dto/SearchItem/SearchStatus.java b/src/main/java/megabrain/gyeongnamgyeongmae/auctionItem/dto/SearchItem/SearchStatus.java deleted file mode 100644 index 4b28c81..0000000 --- a/src/main/java/megabrain/gyeongnamgyeongmae/auctionItem/dto/SearchItem/SearchStatus.java +++ /dev/null @@ -1,7 +0,0 @@ -package megabrain.gyeongnamgyeongmae.auctionItem.dto.SearchItem; - -public enum SearchStatus { - NEW, - USED, - ALL -} diff --git a/src/main/java/megabrain/gyeongnamgyeongmae/auctionItem/dto/SearchItem/SearchTime.java b/src/main/java/megabrain/gyeongnamgyeongmae/auctionItem/dto/SearchItem/SearchTime.java deleted file mode 100644 index 21406b2..0000000 --- a/src/main/java/megabrain/gyeongnamgyeongmae/auctionItem/dto/SearchItem/SearchTime.java +++ /dev/null @@ -1,7 +0,0 @@ -package megabrain.gyeongnamgyeongmae.auctionItem.dto.SearchItem; - -public enum SearchTime { - NEAR, - FAR, - ALL -} diff --git a/src/main/java/megabrain/gyeongnamgyeongmae/auctionItem/dto/UpdateAuctionItemRequest.java b/src/main/java/megabrain/gyeongnamgyeongmae/auctionItem/dto/UpdateAuctionItemRequest.java deleted file mode 100644 index 421f81e..0000000 --- a/src/main/java/megabrain/gyeongnamgyeongmae/auctionItem/dto/UpdateAuctionItemRequest.java +++ /dev/null @@ -1,30 +0,0 @@ -package megabrain.gyeongnamgyeongmae.auctionItem.dto; - -import java.time.LocalDateTime; -import javax.validation.constraints.Min; -import javax.validation.constraints.NotEmpty; -import javax.validation.constraints.NotNull; -import lombok.*; -import megabrain.gyeongnamgyeongmae.auctionItem.domain.entity.AuctionStatus; -import megabrain.gyeongnamgyeongmae.auctionItem.domain.entity.Content; - -@Builder -@Getter -@Setter -@NoArgsConstructor(access = AccessLevel.PRIVATE) -@AllArgsConstructor -public class UpdateAuctionItemRequest { - - @NotEmpty private String name; - - @Min(1) - private Long price; - - @NotEmpty private String category; - - @NotNull private Content content; - - @NotNull private LocalDateTime closedTime; - - @NotNull private AuctionStatus auctionStatus; -} diff --git a/src/main/java/megabrain/gyeongnamgyeongmae/auctionItem/service/Item/AuctionItemServiceImpl.java b/src/main/java/megabrain/gyeongnamgyeongmae/auctionItem/service/Item/AuctionItemServiceImpl.java deleted file mode 100644 index 9ea1629..0000000 --- a/src/main/java/megabrain/gyeongnamgyeongmae/auctionItem/service/Item/AuctionItemServiceImpl.java +++ /dev/null @@ -1,85 +0,0 @@ -package megabrain.gyeongnamgyeongmae.auctionItem.service.Item; - -import java.time.LocalDateTime; -import lombok.RequiredArgsConstructor; -import megabrain.gyeongnamgyeongmae.Category.domain.entity.Category; -import megabrain.gyeongnamgyeongmae.Category.domain.repository.CategoryRepository; -import megabrain.gyeongnamgyeongmae.Category.service.CategoryService; -import megabrain.gyeongnamgyeongmae.auctionItem.domain.entity.AuctionItem; -import megabrain.gyeongnamgyeongmae.auctionItem.domain.repostiory.AuctionItemRepository; -import megabrain.gyeongnamgyeongmae.auctionItem.dto.AuctionItemResponse; -import megabrain.gyeongnamgyeongmae.auctionItem.dto.CreateAuctionItemRequest; -import megabrain.gyeongnamgyeongmae.auctionItem.dto.UpdateAuctionItemRequest; -import megabrain.gyeongnamgyeongmae.member.domain.entity.Member; -import megabrain.gyeongnamgyeongmae.member.domain.repository.MemberRepository; -import megabrain.gyeongnamgyeongmae.member.service.MemberService; -import org.springframework.stereotype.Service; -import org.springframework.transaction.annotation.Transactional; - -@Service -@RequiredArgsConstructor -public class AuctionItemServiceImpl implements AuctionItemService { - - private final AuctionItemRepository auctionItemRepository; - private final CategoryService categoryService; - private final MemberRepository memberRepository; - private final CategoryRepository categoryRepository; - private final MemberService memberService; - - @Override - @Transactional - public void createAuctionItem(CreateAuctionItemRequest createAuctionItemRequest) { - checkClosedTime(createAuctionItemRequest.getClosedTime()); - Member memberEntity = memberService.findMemberById(createAuctionItemRequest.getMember()); - Category categoryEntity = - categoryService.findCategoryByName(createAuctionItemRequest.getCategory()); - AuctionItem auctionItem = createAuctionItemRequest.toEntity(); - auctionItem.setMember(memberEntity); - auctionItem.setCategory(categoryEntity); - auctionItemRepository.save(auctionItem); - } - - @Override - @Transactional - public AuctionItemResponse findAuctionItemById(Long id) { - AuctionItem auctionItem = auctionItemRepository.findById(id).orElseThrow(RuntimeException::new); - auctionItem.checkShowAuctionItem(auctionItem); - updateAuctionItemViewCount(auctionItem); - return AuctionItemResponse.of(auctionItem); - } - - @Override - public void updateAuctionItemViewCount(AuctionItem auctionItem) { - auctionItem.setView_count(auctionItem.getView_count() + 1); - auctionItemRepository.save(auctionItem); - } - - @Override - @Transactional - public void updateAuctionItem(UpdateAuctionItemRequest upDateAuctionItemRequest, Long id) { - checkClosedTime(upDateAuctionItemRequest.getClosedTime()); - Category categoryEntity = - categoryService.findCategoryByName(upDateAuctionItemRequest.getCategory()); - AuctionItem auctionItem = auctionItemRepository.findById(id).orElseThrow(RuntimeException::new); - auctionItem.checkShowAuctionItem(auctionItem); - auctionItem.updateAuctionItem(upDateAuctionItemRequest); - auctionItem.setCategory(categoryEntity); - auctionItemRepository.save(auctionItem); - } - - @Override - public void checkClosedTime(LocalDateTime closedTime) { - LocalDateTime now = LocalDateTime.now(); - if (closedTime.isBefore(now.plusHours(24))) { - throw new RuntimeException("경매 종료 시간은 현재 시간보다 24시간 이후여야 합니다."); - } - } - - @Override - @Transactional - public void deleteAuctionItemById(Long id) { - AuctionItem auctionItem = auctionItemRepository.findById(id).orElseThrow(RuntimeException::new); - auctionItem.removeAuctionItem(auctionItem); - auctionItemRepository.save(auctionItem); - } -} diff --git a/src/main/java/megabrain/gyeongnamgyeongmae/auctionItem/service/Item/IAuctionItemService.java b/src/main/java/megabrain/gyeongnamgyeongmae/auctionItem/service/Item/IAuctionItemService.java deleted file mode 100644 index 740143b..0000000 --- a/src/main/java/megabrain/gyeongnamgyeongmae/auctionItem/service/Item/IAuctionItemService.java +++ /dev/null @@ -1,20 +0,0 @@ -package megabrain.gyeongnamgyeongmae.auctionItem.service.Item; - -import java.time.LocalDateTime; -import megabrain.gyeongnamgyeongmae.auctionItem.domain.entity.AuctionItem; -import megabrain.gyeongnamgyeongmae.auctionItem.dto.AuctionItemResponse; -import megabrain.gyeongnamgyeongmae.auctionItem.dto.CreateAuctionItemRequest; -import megabrain.gyeongnamgyeongmae.auctionItem.dto.UpdateAuctionItemRequest; - -public interface IAuctionItemService { - - void createAuctionItem(CreateAuctionItemRequest createAuctionItemRequest); - - AuctionItemResponse findAuctionItemById(Long id); - - void updateAuctionItemViewCount(AuctionItem auctionItem); - - void updateAuctionItem(UpdateAuctionItemRequest upDateAuctionItemRequest); - - void checkClosedTime(LocalDateTime closedTime); -} diff --git a/src/main/java/megabrain/gyeongnamgyeongmae/auctionItem/service/Search/AuctionItemSearchService.java b/src/main/java/megabrain/gyeongnamgyeongmae/auctionItem/service/Search/AuctionItemSearchService.java deleted file mode 100644 index 0413f2f..0000000 --- a/src/main/java/megabrain/gyeongnamgyeongmae/auctionItem/service/Search/AuctionItemSearchService.java +++ /dev/null @@ -1,12 +0,0 @@ -package megabrain.gyeongnamgyeongmae.auctionItem.service.Search; - -import megabrain.gyeongnamgyeongmae.auctionItem.dto.AuctionItemFirstView; -import megabrain.gyeongnamgyeongmae.auctionItem.dto.SearchItem.SearchAuctionItemSortedRequest; -import org.springframework.data.domain.Page; -import org.springframework.data.domain.Pageable; - -public interface AuctionItemSearchService { - - Page findAuctionItembyRequest( - SearchAuctionItemSortedRequest searchAuctionItemSortedRequest, Pageable pageable); -} diff --git a/src/main/java/megabrain/gyeongnamgyeongmae/commons/config/ObjectMapperConfig.java b/src/main/java/megabrain/gyeongnamgyeongmae/commons/config/ObjectMapperConfig.java deleted file mode 100644 index 903f95e..0000000 --- a/src/main/java/megabrain/gyeongnamgyeongmae/commons/config/ObjectMapperConfig.java +++ /dev/null @@ -1,11 +0,0 @@ -package megabrain.gyeongnamgyeongmae.commons.config; - -import com.fasterxml.jackson.databind.ObjectMapper; -import org.springframework.context.annotation.Bean; - -public class ObjectMapperConfig { - @Bean - public ObjectMapper objectMapper() { - return new ObjectMapper(); - } -} diff --git a/src/main/java/megabrain/gyeongnamgyeongmae/commons/config/SecurityConfig.java b/src/main/java/megabrain/gyeongnamgyeongmae/commons/config/SecurityConfig.java deleted file mode 100644 index 3b8e15d..0000000 --- a/src/main/java/megabrain/gyeongnamgyeongmae/commons/config/SecurityConfig.java +++ /dev/null @@ -1,39 +0,0 @@ -package megabrain.gyeongnamgyeongmae.commons.config; - -import lombok.RequiredArgsConstructor; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; -import org.springframework.security.config.annotation.web.builders.HttpSecurity; -import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder; -import org.springframework.security.crypto.password.PasswordEncoder; -import org.springframework.security.web.SecurityFilterChain; - -@Configuration -@RequiredArgsConstructor -public class SecurityConfig { - - @Bean - public PasswordEncoder passwordEncoder() { - return new BCryptPasswordEncoder(); - } - - @Bean - public SecurityFilterChain securityFilterChain(HttpSecurity httpSecurity) throws Exception { - return httpSecurity - .httpBasic() - .disable() - .csrf() - .disable() - .cors() - .and() - .headers() - .frameOptions() - .disable() - .and() - .authorizeRequests() - .antMatchers("*") - .permitAll() - .and() - .build(); - } -} diff --git a/src/main/java/megabrain/gyeongnamgyeongmae/commons/config/SwaggerConfig.java b/src/main/java/megabrain/gyeongnamgyeongmae/commons/config/SwaggerConfig.java deleted file mode 100644 index 2f4ec8d..0000000 --- a/src/main/java/megabrain/gyeongnamgyeongmae/commons/config/SwaggerConfig.java +++ /dev/null @@ -1,17 +0,0 @@ -package megabrain.gyeongnamgyeongmae.commons.config; - -import io.swagger.v3.oas.models.OpenAPI; -import io.swagger.v3.oas.models.info.Info; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; - -@Configuration -public class SwaggerConfig { - @Bean - public OpenAPI openAPI() { - - Info info = - new Info().version("v1.0.0").title("GyeongnamGyeongmae API").description("경남경매 API "); - return new OpenAPI().info(info); - } -} diff --git a/src/main/java/megabrain/gyeongnamgyeongmae/domain/auctionItem/controller/AuctionItemCommentController.java b/src/main/java/megabrain/gyeongnamgyeongmae/domain/auctionItem/controller/AuctionItemCommentController.java new file mode 100644 index 0000000..e572086 --- /dev/null +++ b/src/main/java/megabrain/gyeongnamgyeongmae/domain/auctionItem/controller/AuctionItemCommentController.java @@ -0,0 +1,59 @@ +package megabrain.gyeongnamgyeongmae.domain.auctionItem.controller; + +import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.tags.Tag; +import lombok.RequiredArgsConstructor; +import megabrain.gyeongnamgyeongmae.domain.auctionItem.domain.repostiory.AuctionItemCommentRepository; +import megabrain.gyeongnamgyeongmae.domain.auctionItem.dto.AuctionItemCommentDeleteRequest; +import megabrain.gyeongnamgyeongmae.domain.auctionItem.dto.Comment.AuctionItemCommentParentDto; +import megabrain.gyeongnamgyeongmae.domain.auctionItem.dto.AuctionItemCommentRequest; +import megabrain.gyeongnamgyeongmae.domain.auctionItem.dto.AuctionItemCommentUpdateRequest; +import megabrain.gyeongnamgyeongmae.domain.auctionItem.service.Comment.AuctionItemCommentServiceImpl; +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.*; + +import java.util.List; + +@Tag(name = "경매품에 답글 작성", description = "경매품 댓글 관련 API") +@RequestMapping({"api/auctions/comments"}) +@RestController +@RequiredArgsConstructor +public class AuctionItemCommentController { + + private final AuctionItemCommentRepository auctionItemCommentRepository; + private final AuctionItemCommentServiceImpl auctionItemCommentServiceImpl; + + @Operation(summary = "댓글 쓰기 ", description = "경매품 댓글 쓰기") + @ResponseStatus(HttpStatus.CREATED) + @PostMapping({"{id}"}) + public ResponseEntity createAuctionItemComment(@PathVariable Long id, @RequestBody AuctionItemCommentRequest auctionItemCommentRequest) { + Long memberId = auctionItemCommentRequest.getUserId(); + this.auctionItemCommentServiceImpl.createAuctionItemComment(auctionItemCommentRequest, id, memberId); + return ResponseEntity.status(HttpStatus.CREATED).build(); + } + + @Operation(summary = "경매품에 대한 댓글 보기", description = "경매품에 대한 경매품 댓글 보기") + @GetMapping({"{id}"}) + public ResponseEntity> findAuctionItemCommentById(@PathVariable Long id) { + List commentViews = this.auctionItemCommentServiceImpl.findAuctionItemCommentById(id); + return ResponseEntity.ok(commentViews); + } + + + @Operation(summary = "경매품 댓글 수정 ", description = "경매품 댓글 수정") + @PutMapping({""}) + public ResponseEntity updateAuctionItemComment(@RequestBody AuctionItemCommentUpdateRequest auctionItemCommentUpdateRequest) { + this.auctionItemCommentServiceImpl.updateAuctionItemComment(auctionItemCommentUpdateRequest); + return ResponseEntity.status(HttpStatus.OK).build(); + } + + @Operation(summary = "경매품 댓글 삭제",description = "경매품 댓글 삭제") + @DeleteMapping({""}) + public ResponseEntity deleteAuctionItemComment(AuctionItemCommentDeleteRequest auctionItemCommentDeleteRequest) { + this.auctionItemCommentServiceImpl.deleteAuctionItemComment(auctionItemCommentDeleteRequest); + return ResponseEntity.status(HttpStatus.OK).build(); + } +} + + diff --git a/src/main/java/megabrain/gyeongnamgyeongmae/domain/auctionItem/controller/AuctionItemController.java b/src/main/java/megabrain/gyeongnamgyeongmae/domain/auctionItem/controller/AuctionItemController.java new file mode 100644 index 0000000..484dabe --- /dev/null +++ b/src/main/java/megabrain/gyeongnamgyeongmae/domain/auctionItem/controller/AuctionItemController.java @@ -0,0 +1,57 @@ +package megabrain.gyeongnamgyeongmae.domain.auctionItem.controller; + +import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.tags.Tag; +import lombok.RequiredArgsConstructor; +import megabrain.gyeongnamgyeongmae.domain.auctionItem.dto.AuctionItemResponse; +import megabrain.gyeongnamgyeongmae.domain.auctionItem.dto.CreateAuctionItemRequest; +import megabrain.gyeongnamgyeongmae.domain.auctionItem.dto.UpdateAuctionItemRequest; +import megabrain.gyeongnamgyeongmae.domain.auctionItem.service.Item.AuctionItemServiceImpl; +import megabrain.gyeongnamgyeongmae.domain.category.service.CategoryService; +import megabrain.gyeongnamgyeongmae.domain.member.service.MemberService; +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.*; + +import javax.validation.Valid; + +@Tag(name = "경매품 업로드", description = "경매품 작성 관련 api") +@RequestMapping({"api/auctions/"}) +@RestController +@RequiredArgsConstructor +public class AuctionItemController { + + private final AuctionItemServiceImpl auctionItemServiceImpl; + private final CategoryService categoryService; + private final MemberService memberService; + + @Operation(summary = "Post AuctionItem", description = "경매품 올리기") + @ResponseStatus(HttpStatus.CREATED) + @PostMapping("") + public ResponseEntity createAuctionItem(@RequestBody @Valid CreateAuctionItemRequest createAuctionItemRequest) { + this.auctionItemServiceImpl.createAuctionItem(createAuctionItemRequest); + return ResponseEntity.status(HttpStatus.CREATED).build(); + } + + @Operation(summary = "Show AuctionItem", description = "경매품 상세보기") + @GetMapping("{id}") + public ResponseEntity findAuctionItemById(@PathVariable Long id) { + AuctionItemResponse auctionItemResponse = auctionItemServiceImpl.findAuctionItemById(id); + return ResponseEntity.ok(auctionItemResponse); + } + + @Operation(summary = "Update AuctionItem", description = "경매품 수정하기") + @PutMapping("{id}") + public ResponseEntity updateAuctionItemById(@PathVariable Long id, @RequestBody @Valid UpdateAuctionItemRequest upDateAuctionItemRequest) { + this.auctionItemServiceImpl.updateAuctionItem(upDateAuctionItemRequest, id); + return ResponseEntity.status(HttpStatus.OK).build(); + } + + + @Operation(summary = "Delete AuctionItem", description = "경매품 삭제하기") + @DeleteMapping("{id}") + public ResponseEntity deleteAuctionItemById(@PathVariable Long id) { + this.auctionItemServiceImpl.deleteAuctionItemById(id); + return ResponseEntity.status(HttpStatus.OK).build(); + } +} diff --git a/src/main/java/megabrain/gyeongnamgyeongmae/domain/auctionItem/controller/AuctionItemSearchController.java b/src/main/java/megabrain/gyeongnamgyeongmae/domain/auctionItem/controller/AuctionItemSearchController.java new file mode 100644 index 0000000..6251d79 --- /dev/null +++ b/src/main/java/megabrain/gyeongnamgyeongmae/domain/auctionItem/controller/AuctionItemSearchController.java @@ -0,0 +1,35 @@ +package megabrain.gyeongnamgyeongmae.domain.auctionItem.controller; + +import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.tags.Tag; +import lombok.RequiredArgsConstructor; +import megabrain.gyeongnamgyeongmae.domain.auctionItem.domain.repostiory.AuctionItemRepository; +import megabrain.gyeongnamgyeongmae.domain.auctionItem.dto.AuctionItemFirstView; +import megabrain.gyeongnamgyeongmae.domain.auctionItem.dto.SearchItem.SearchAuctionItemSortedRequest; +import megabrain.gyeongnamgyeongmae.domain.auctionItem.service.Item.AuctionItemServiceImpl; +import megabrain.gyeongnamgyeongmae.domain.auctionItem.service.Search.AuctionItemSearchServiceImpl; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.Pageable; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.ModelAttribute; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +@Tag(name = "경매품 검색", description = "경매품 검색 관련 API") +@RequestMapping({"api/auctions/search"}) +@RestController +@RequiredArgsConstructor +public class AuctionItemSearchController { + + private final AuctionItemServiceImpl auctionItemServiceImpl; + private final AuctionItemRepository AuctionItemRepository; + private final AuctionItemSearchServiceImpl auctionItemSearchServiceImpl; + + @Operation(summary = "Search AuctionItem", description = "경매품 검색하기") + @GetMapping("") + public ResponseEntity> findItemCategory(@ModelAttribute SearchAuctionItemSortedRequest searchAuctionItemSortedRequest, Pageable pageable) { + Page result = this.auctionItemSearchServiceImpl.findAuctionItembyRequest(searchAuctionItemSortedRequest, pageable); + return ResponseEntity.ok(result); + } +} \ No newline at end of file diff --git a/src/main/java/megabrain/gyeongnamgyeongmae/domain/auctionItem/domain/entity/AuctionItem.java b/src/main/java/megabrain/gyeongnamgyeongmae/domain/auctionItem/domain/entity/AuctionItem.java new file mode 100644 index 0000000..c358e11 --- /dev/null +++ b/src/main/java/megabrain/gyeongnamgyeongmae/domain/auctionItem/domain/entity/AuctionItem.java @@ -0,0 +1,125 @@ +package megabrain.gyeongnamgyeongmae.domain.auctionItem.domain.entity; + +import javax.persistence.*; + +import lombok.*; +import megabrain.gyeongnamgyeongmae.domain.auctionItem.dto.UpdateAuctionItemRequest; +import megabrain.gyeongnamgyeongmae.domain.category.domain.entity.Category; +import megabrain.gyeongnamgyeongmae.domain.member.domain.entity.Member; +import megabrain.gyeongnamgyeongmae.global.commons.BaseTimeEntity; + +import java.time.LocalDateTime; + +@Getter +@Setter +@Entity +@Table(name = "AuctionItem") +@NoArgsConstructor(access = AccessLevel.PROTECTED) +public class AuctionItem extends BaseTimeEntity { + + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + @Column(name = "auction_id") + private Long id; + + @Column(name = "removed") + private boolean removed = false; + + @ManyToOne(fetch = FetchType.LAZY) + @JoinColumn(name = "member_id") + private Member member; + + @Column(name = "name") + private String name; + + @Column(name = "highest_price") + private Long price; + + @Column(name = "content") + private String content; + + @Column(name = "item_status") + private AuctionItemStatus itemStatus; + + @ManyToOne(fetch = FetchType.LAZY) + @JoinColumn(name = "category_id") + private Category category; + + @Column(name = "close_at") + protected LocalDateTime closedTime; + + @Column(name = "like_count") + private Long like_count = 0L; + + @Column(name = "view_count") + private Long view_count = 0L; + + @Column(name = "auction_status") + @Enumerated(EnumType.STRING) + private AuctionStatus status; + + @Column(name = "comment_count") + private Long comment_count; + + @Column + private Long temperature; + + @Builder + public AuctionItem(Long id, String name, long price, String content, AuctionItemStatus itemStatus, LocalDateTime closedTime) { + this.status = AuctionStatus.ONGOING; + this.comment_count = 0L; + this.id = id; + this.name = name; + this.price = price; + this.content = content; + this.itemStatus = itemStatus; + this.closedTime = closedTime; + } + + @Builder + private AuctionItem(String name, long price, String content, AuctionItemStatus itemStatus, LocalDateTime localDateTime){ + this.name = name; + this.price = price; + this.content = content; + this.itemStatus = itemStatus; + this.closedTime = localDateTime; + this.status = AuctionStatus.ONGOING; + this.comment_count = 0L; + } + + + @Builder + public AuctionItem(Long id, String name, long price, String content, AuctionItemStatus itemStatus, LocalDateTime closedTime, Category category, Member member, LocalDateTime createdAt, LocalDateTime updatedAt) { + this.status = AuctionStatus.ONGOING; + this.comment_count = 0L; + this.id = id; + this.name = name; + this.price = price; + this.content = content; + this.itemStatus = itemStatus; + this.closedTime = closedTime; + this.category = category; + this.member = member; + this.createdAt = createdAt; + this.updatedAt = updatedAt; + } + + public void removeAuctionItem(AuctionItem auctionItem) { + this.removed = true; + } + + public void checkShowAuctionItem(AuctionItem auctionItem) { + if (this.removed) { + throw new RuntimeException("삭제된 상품입니다."); + } + } + + public void updateAuctionItem(UpdateAuctionItemRequest upDateAuctionItemRequest) { + this.name = upDateAuctionItemRequest.getName(); + this.price = upDateAuctionItemRequest.getPrice(); + this.content = upDateAuctionItemRequest.getContent(); + this.itemStatus = upDateAuctionItemRequest.getItemStatus(); + this.closedTime = upDateAuctionItemRequest.getClosedTime(); + this.status = upDateAuctionItemRequest.getAuctionStatus(); + } +} diff --git a/src/main/java/megabrain/gyeongnamgyeongmae/auctionItem/domain/entity/AuctionItemStatus.java b/src/main/java/megabrain/gyeongnamgyeongmae/domain/auctionItem/domain/entity/AuctionItemStatus.java similarity index 77% rename from src/main/java/megabrain/gyeongnamgyeongmae/auctionItem/domain/entity/AuctionItemStatus.java rename to src/main/java/megabrain/gyeongnamgyeongmae/domain/auctionItem/domain/entity/AuctionItemStatus.java index cf71103..01b4ceb 100644 --- a/src/main/java/megabrain/gyeongnamgyeongmae/auctionItem/domain/entity/AuctionItemStatus.java +++ b/src/main/java/megabrain/gyeongnamgyeongmae/domain/auctionItem/domain/entity/AuctionItemStatus.java @@ -1,4 +1,4 @@ -package megabrain.gyeongnamgyeongmae.auctionItem.domain.entity; +package megabrain.gyeongnamgyeongmae.domain.auctionItem.domain.entity; public enum AuctionItemStatus { NEW("신품"), diff --git a/src/main/java/megabrain/gyeongnamgyeongmae/auctionItem/domain/entity/AuctionStatus.java b/src/main/java/megabrain/gyeongnamgyeongmae/domain/auctionItem/domain/entity/AuctionStatus.java similarity index 78% rename from src/main/java/megabrain/gyeongnamgyeongmae/auctionItem/domain/entity/AuctionStatus.java rename to src/main/java/megabrain/gyeongnamgyeongmae/domain/auctionItem/domain/entity/AuctionStatus.java index 97e30bd..1a475d4 100644 --- a/src/main/java/megabrain/gyeongnamgyeongmae/auctionItem/domain/entity/AuctionStatus.java +++ b/src/main/java/megabrain/gyeongnamgyeongmae/domain/auctionItem/domain/entity/AuctionStatus.java @@ -1,4 +1,4 @@ -package megabrain.gyeongnamgyeongmae.auctionItem.domain.entity; +package megabrain.gyeongnamgyeongmae.domain.auctionItem.domain.entity; public enum AuctionStatus { ONGOING("진행중"), diff --git a/src/main/java/megabrain/gyeongnamgyeongmae/domain/auctionItem/domain/entity/Comment.java b/src/main/java/megabrain/gyeongnamgyeongmae/domain/auctionItem/domain/entity/Comment.java new file mode 100644 index 0000000..dce7c06 --- /dev/null +++ b/src/main/java/megabrain/gyeongnamgyeongmae/domain/auctionItem/domain/entity/Comment.java @@ -0,0 +1,64 @@ +package megabrain.gyeongnamgyeongmae.domain.auctionItem.domain.entity; + +import lombok.*; +import megabrain.gyeongnamgyeongmae.domain.member.domain.entity.Member; +import megabrain.gyeongnamgyeongmae.global.commons.BaseTimeEntity; + +import javax.persistence.*; +import java.util.ArrayList; +import java.util.List; + +@Getter +@Setter +@Entity +@Table(name = "comment") +@NoArgsConstructor(access = AccessLevel.PROTECTED) +public class Comment extends BaseTimeEntity { + + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + @Column(name = "comment_id") + private Long id; + + @Column(nullable = false, length = 800) + private String content; + + @Column(name = "removed") + private boolean removed = false; + + @ManyToOne(fetch = FetchType.LAZY) + @JoinColumn(name = "auction_id") + private AuctionItem auctionItem; + + @ManyToOne(fetch = FetchType.LAZY) + @JoinColumn(name = "member_id") + private Member member; + + @ManyToOne(fetch = FetchType.LAZY) + @JoinColumn(name = "parent_id") + private Comment parent; + + @OneToMany(mappedBy = "parent", orphanRemoval = true, fetch = FetchType.LAZY) + private List children = new ArrayList(); + + @Column(name = "like_count") + private Integer like_count = 0; + + public Comment(String content, AuctionItem auctionItem, Member member, Comment parent) { + this.content = content; + this.auctionItem = auctionItem; + this.member = member; + this.parent = parent; + } + + @Builder + public Comment(String content, AuctionItem auctionItem, Member member, Comment parent, List children, Integer like_count) { + this.content = content; + this.auctionItem = auctionItem; + this.member = member; + this.parent = parent; + this.children = children; + this.like_count = like_count; + } +} + diff --git a/src/main/java/megabrain/gyeongnamgyeongmae/domain/auctionItem/domain/repostiory/AuctionItemCommentRepository.java b/src/main/java/megabrain/gyeongnamgyeongmae/domain/auctionItem/domain/repostiory/AuctionItemCommentRepository.java new file mode 100644 index 0000000..9147fb0 --- /dev/null +++ b/src/main/java/megabrain/gyeongnamgyeongmae/domain/auctionItem/domain/repostiory/AuctionItemCommentRepository.java @@ -0,0 +1,7 @@ +package megabrain.gyeongnamgyeongmae.domain.auctionItem.domain.repostiory; + +import megabrain.gyeongnamgyeongmae.domain.auctionItem.domain.entity.Comment; +import org.springframework.data.jpa.repository.JpaRepository; + +public interface AuctionItemCommentRepository extends JpaRepository, AuctionItemCommentRepositoryCustom {} + diff --git a/src/main/java/megabrain/gyeongnamgyeongmae/domain/auctionItem/domain/repostiory/AuctionItemCommentRepositoryCustom.java b/src/main/java/megabrain/gyeongnamgyeongmae/domain/auctionItem/domain/repostiory/AuctionItemCommentRepositoryCustom.java new file mode 100644 index 0000000..9a1aa17 --- /dev/null +++ b/src/main/java/megabrain/gyeongnamgyeongmae/domain/auctionItem/domain/repostiory/AuctionItemCommentRepositoryCustom.java @@ -0,0 +1,9 @@ +package megabrain.gyeongnamgyeongmae.domain.auctionItem.domain.repostiory; + +import megabrain.gyeongnamgyeongmae.domain.auctionItem.domain.entity.Comment; + +import java.util.List; + +public interface AuctionItemCommentRepositoryCustom { + List findByAuctionItemCommentByAuctionId(Long id); +} diff --git a/src/main/java/megabrain/gyeongnamgyeongmae/domain/auctionItem/domain/repostiory/AuctionItemCommentRepositoryCustomImpl.java b/src/main/java/megabrain/gyeongnamgyeongmae/domain/auctionItem/domain/repostiory/AuctionItemCommentRepositoryCustomImpl.java new file mode 100644 index 0000000..673d5d3 --- /dev/null +++ b/src/main/java/megabrain/gyeongnamgyeongmae/domain/auctionItem/domain/repostiory/AuctionItemCommentRepositoryCustomImpl.java @@ -0,0 +1,38 @@ +package megabrain.gyeongnamgyeongmae.domain.auctionItem.domain.repostiory; +import static megabrain.gyeongnamgyeongmae.domain.auctionItem.domain.entity.QAuctionItem.auctionItem; + +import com.querydsl.core.BooleanBuilder; +import com.querydsl.jpa.impl.JPAQuery; +import com.querydsl.jpa.impl.JPAQueryFactory; +import megabrain.gyeongnamgyeongmae.domain.auctionItem.domain.entity.Comment; +import megabrain.gyeongnamgyeongmae.domain.auctionItem.domain.entity.QAuctionItem; +import megabrain.gyeongnamgyeongmae.domain.auctionItem.domain.entity.QComment; + +import javax.persistence.EntityManager; +import java.util.List; + +public class AuctionItemCommentRepositoryCustomImpl implements AuctionItemCommentRepositoryCustom { + private final JPAQueryFactory queryFactory; + + public AuctionItemCommentRepositoryCustomImpl(EntityManager em) { + this.queryFactory = new JPAQueryFactory(em); + } + + public List findByAuctionItemCommentByAuctionId(Long id) { + QAuctionItem auctionItem = QAuctionItem.auctionItem; + QComment comment = QComment.comment; + + BooleanBuilder whereClause = new BooleanBuilder(); + whereClause.and(comment.auctionItem.id.eq(id)) + .and(comment.parent.isNull()) + .and(comment.removed.eq(false)); + + JPAQuery query = queryFactory.select(comment) + .from(comment) + .where(whereClause) + .orderBy(comment.createdAt.asc()); + + return query.fetch(); + } +} + diff --git a/src/main/java/megabrain/gyeongnamgyeongmae/domain/auctionItem/domain/repostiory/AuctionItemRepository.java b/src/main/java/megabrain/gyeongnamgyeongmae/domain/auctionItem/domain/repostiory/AuctionItemRepository.java new file mode 100644 index 0000000..6529c91 --- /dev/null +++ b/src/main/java/megabrain/gyeongnamgyeongmae/domain/auctionItem/domain/repostiory/AuctionItemRepository.java @@ -0,0 +1,6 @@ +package megabrain.gyeongnamgyeongmae.domain.auctionItem.domain.repostiory; + +import megabrain.gyeongnamgyeongmae.domain.auctionItem.domain.entity.AuctionItem; +import org.springframework.data.jpa.repository.JpaRepository; + +public interface AuctionItemRepository extends JpaRepository,AuctionItemRepositoryCustom {} diff --git a/src/main/java/megabrain/gyeongnamgyeongmae/domain/auctionItem/domain/repostiory/AuctionItemRepositoryCustom.java b/src/main/java/megabrain/gyeongnamgyeongmae/domain/auctionItem/domain/repostiory/AuctionItemRepositoryCustom.java new file mode 100644 index 0000000..4427245 --- /dev/null +++ b/src/main/java/megabrain/gyeongnamgyeongmae/domain/auctionItem/domain/repostiory/AuctionItemRepositoryCustom.java @@ -0,0 +1,10 @@ +package megabrain.gyeongnamgyeongmae.domain.auctionItem.domain.repostiory; + +import megabrain.gyeongnamgyeongmae.domain.auctionItem.domain.entity.AuctionItem; +import megabrain.gyeongnamgyeongmae.domain.auctionItem.dto.SearchItem.SearchAuctionItemSortedRequest; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.Pageable; + +public interface AuctionItemRepositoryCustom { + Page searchAuctionItemPage(SearchAuctionItemSortedRequest searchAuctionItemSortedRequest, Pageable pageable); +} diff --git a/src/main/java/megabrain/gyeongnamgyeongmae/domain/auctionItem/domain/repostiory/AuctionItemRepositoryCustomImpl.java b/src/main/java/megabrain/gyeongnamgyeongmae/domain/auctionItem/domain/repostiory/AuctionItemRepositoryCustomImpl.java new file mode 100644 index 0000000..cc29af6 --- /dev/null +++ b/src/main/java/megabrain/gyeongnamgyeongmae/domain/auctionItem/domain/repostiory/AuctionItemRepositoryCustomImpl.java @@ -0,0 +1,67 @@ +package megabrain.gyeongnamgyeongmae.domain.auctionItem.domain.repostiory; + +import com.querydsl.core.BooleanBuilder; +import com.querydsl.core.types.OrderSpecifier; +import com.querydsl.jpa.impl.JPAQuery; +import com.querydsl.jpa.impl.JPAQueryFactory; +import megabrain.gyeongnamgyeongmae.domain.auctionItem.domain.entity.AuctionItem; +import megabrain.gyeongnamgyeongmae.domain.auctionItem.domain.entity.QAuctionItem; +import megabrain.gyeongnamgyeongmae.domain.auctionItem.dto.SearchItem.SearchAuctionItemSortedRequest; +import megabrain.gyeongnamgyeongmae.domain.category.domain.entity.QCategory; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.PageImpl; +import org.springframework.data.domain.Pageable; + +import javax.persistence.EntityManager; +import java.util.ArrayList; +import java.util.List; + +public class AuctionItemRepositoryCustomImpl implements AuctionItemRepositoryCustom{ + + public final JPAQueryFactory queryFactory; + + public AuctionItemRepositoryCustomImpl(EntityManager em){ + this.queryFactory = new JPAQueryFactory(em); + } + + public Page searchAuctionItemPage(SearchAuctionItemSortedRequest searchAuctionItemSortedRequest, Pageable pageable){ + + QAuctionItem auctionItem = QAuctionItem.auctionItem; + QCategory category = QCategory.category; + + List> orderSpecifiers = new ArrayList(); + BooleanBuilder statusBuilder = new BooleanBuilder(); + BooleanBuilder sellBuilder = new BooleanBuilder(); + BooleanBuilder keywordStatus = new BooleanBuilder(); + BooleanBuilder categoryStatus = new BooleanBuilder(); + + searchAuctionItemSortedRequest.applySearchCategory(categoryStatus, auctionItem); + searchAuctionItemSortedRequest.applySearchStatus(statusBuilder, auctionItem); + searchAuctionItemSortedRequest.applyKeyWordStatus(keywordStatus, auctionItem); + searchAuctionItemSortedRequest.applySearchPrice(orderSpecifiers, auctionItem); + searchAuctionItemSortedRequest.applySearchLike(orderSpecifiers, auctionItem); + searchAuctionItemSortedRequest.applySearchView(orderSpecifiers, auctionItem); + searchAuctionItemSortedRequest.applySearchTime(orderSpecifiers, auctionItem); + searchAuctionItemSortedRequest.applySearchClosed(sellBuilder, auctionItem); + + JPAQuery query = + queryFactory + .selectFrom(auctionItem) + .innerJoin(auctionItem.category, category) + .where( + auctionItem.removed.eq(false), + categoryStatus, + statusBuilder, + sellBuilder, + keywordStatus); + + List results = + query + .orderBy(orderSpecifiers.toArray(new OrderSpecifier[0])) + .offset(pageable.getOffset()) + .limit(pageable.getPageSize()) + .fetch(); + + return new PageImpl<>(results, pageable, results.size()); + } +} diff --git a/src/main/java/megabrain/gyeongnamgyeongmae/domain/auctionItem/dto/AuctionItemCommentDeleteRequest.java b/src/main/java/megabrain/gyeongnamgyeongmae/domain/auctionItem/dto/AuctionItemCommentDeleteRequest.java new file mode 100644 index 0000000..8022f31 --- /dev/null +++ b/src/main/java/megabrain/gyeongnamgyeongmae/domain/auctionItem/dto/AuctionItemCommentDeleteRequest.java @@ -0,0 +1,13 @@ +package megabrain.gyeongnamgyeongmae.domain.auctionItem.dto; + +import lombok.Data; +import lombok.Getter; + +import javax.validation.constraints.NotEmpty; + +@Data +public class AuctionItemCommentDeleteRequest { + + private @NotEmpty Long userId; + private @NotEmpty Long commentId; +} diff --git a/src/main/java/megabrain/gyeongnamgyeongmae/domain/auctionItem/dto/AuctionItemCommentRequest.java b/src/main/java/megabrain/gyeongnamgyeongmae/domain/auctionItem/dto/AuctionItemCommentRequest.java new file mode 100644 index 0000000..befae1e --- /dev/null +++ b/src/main/java/megabrain/gyeongnamgyeongmae/domain/auctionItem/dto/AuctionItemCommentRequest.java @@ -0,0 +1,14 @@ +package megabrain.gyeongnamgyeongmae.domain.auctionItem.dto; + +import lombok.Data; + +import javax.validation.constraints.NotEmpty; + +@Data +public class AuctionItemCommentRequest { + + private @NotEmpty String content; + private @NotEmpty Long userId; + private @NotEmpty Long parentCommentId; + +} diff --git a/src/main/java/megabrain/gyeongnamgyeongmae/domain/auctionItem/dto/AuctionItemCommentUpdateRequest.java b/src/main/java/megabrain/gyeongnamgyeongmae/domain/auctionItem/dto/AuctionItemCommentUpdateRequest.java new file mode 100644 index 0000000..f14e2e3 --- /dev/null +++ b/src/main/java/megabrain/gyeongnamgyeongmae/domain/auctionItem/dto/AuctionItemCommentUpdateRequest.java @@ -0,0 +1,14 @@ +package megabrain.gyeongnamgyeongmae.domain.auctionItem.dto; + + +import lombok.Getter; + +import javax.validation.constraints.NotEmpty; + +@Getter +public class AuctionItemCommentUpdateRequest { + private @NotEmpty String content; + private @NotEmpty Long userId; + private @NotEmpty Long commentId; + +} diff --git a/src/main/java/megabrain/gyeongnamgyeongmae/domain/auctionItem/dto/AuctionItemFirstView.java b/src/main/java/megabrain/gyeongnamgyeongmae/domain/auctionItem/dto/AuctionItemFirstView.java new file mode 100644 index 0000000..9714556 --- /dev/null +++ b/src/main/java/megabrain/gyeongnamgyeongmae/domain/auctionItem/dto/AuctionItemFirstView.java @@ -0,0 +1,53 @@ +package megabrain.gyeongnamgyeongmae.domain.auctionItem.dto; + +import java.time.LocalDateTime; + +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Getter; +import lombok.NoArgsConstructor; +import megabrain.gyeongnamgyeongmae.domain.auctionItem.domain.entity.AuctionItem; +import megabrain.gyeongnamgyeongmae.domain.auctionItem.domain.entity.AuctionItemStatus; +import megabrain.gyeongnamgyeongmae.domain.auctionItem.domain.entity.AuctionStatus; +import megabrain.gyeongnamgyeongmae.domain.member.domain.entity.Address; + +@Builder +@Getter +@NoArgsConstructor +@AllArgsConstructor +public class AuctionItemFirstView { + + private Long id; + + private String name; + + private LocalDateTime closedTime; + + private AuctionItemStatus auctionItemStatus; + + private AuctionStatus status; + + private Address address; + + private Long like_count; + + private Long view_count; + + private Long price; + + @Builder + public static AuctionItemFirstView of(AuctionItem auctionItem) { + return AuctionItemFirstView.builder() + .id(auctionItem.getId()) + .name(auctionItem.getName()) + .address(auctionItem.getMember().getAddress()) + .like_count(auctionItem.getLike_count()) + .view_count(auctionItem.getView_count()) + .price(auctionItem.getPrice()) + .closedTime(auctionItem.getClosedTime()) + .auctionItemStatus(auctionItem.getItemStatus()) + .status(auctionItem.getStatus()) + .build(); + } + +} diff --git a/src/main/java/megabrain/gyeongnamgyeongmae/auctionItem/dto/AuctionItemResponse.java b/src/main/java/megabrain/gyeongnamgyeongmae/domain/auctionItem/dto/AuctionItemResponse.java similarity index 74% rename from src/main/java/megabrain/gyeongnamgyeongmae/auctionItem/dto/AuctionItemResponse.java rename to src/main/java/megabrain/gyeongnamgyeongmae/domain/auctionItem/dto/AuctionItemResponse.java index 52b4699..8f61a22 100644 --- a/src/main/java/megabrain/gyeongnamgyeongmae/auctionItem/dto/AuctionItemResponse.java +++ b/src/main/java/megabrain/gyeongnamgyeongmae/domain/auctionItem/dto/AuctionItemResponse.java @@ -1,14 +1,14 @@ -package megabrain.gyeongnamgyeongmae.auctionItem.dto; +package megabrain.gyeongnamgyeongmae.domain.auctionItem.dto; import java.time.LocalDateTime; import lombok.AllArgsConstructor; import lombok.Builder; import lombok.Getter; import lombok.NoArgsConstructor; -import megabrain.gyeongnamgyeongmae.auctionItem.domain.entity.AuctionItem; -import megabrain.gyeongnamgyeongmae.auctionItem.domain.entity.AuctionItemStatus; -import megabrain.gyeongnamgyeongmae.auctionItem.domain.entity.AuctionStatus; -import megabrain.gyeongnamgyeongmae.member.domain.entity.Address; +import megabrain.gyeongnamgyeongmae.domain.auctionItem.domain.entity.AuctionItem; +import megabrain.gyeongnamgyeongmae.domain.auctionItem.domain.entity.AuctionItemStatus; +import megabrain.gyeongnamgyeongmae.domain.auctionItem.domain.entity.AuctionStatus; +import megabrain.gyeongnamgyeongmae.domain.member.domain.entity.Address; @Builder @Getter @@ -44,7 +44,7 @@ public static AuctionItemResponse of(AuctionItem auctionItem) { .nickname(auctionItem.getMember().getNickname()) .name(auctionItem.getName()) .price(auctionItem.getPrice()) - .itemStatus(auctionItem.getContent().getStatus()) + .itemStatus(auctionItem.getItemStatus()) .auctionStatus(auctionItem.getStatus()) .createdTime(auctionItem.getCreatedAt()) .modifiedTime(auctionItem.getUpdatedAt()) @@ -52,7 +52,7 @@ public static AuctionItemResponse of(AuctionItem auctionItem) { .address(auctionItem.getMember().getAddress()) .category(auctionItem.getCategory().getName()) .email(auctionItem.getMember().getEmail()) - .content(auctionItem.getContent().getContent()) + .content(auctionItem.getContent()) .likeCount(auctionItem.getLike_count()) .viewCount(auctionItem.getView_count()) .build(); diff --git a/src/main/java/megabrain/gyeongnamgyeongmae/domain/auctionItem/dto/Comment/AuctionItemCommentChildDto.java b/src/main/java/megabrain/gyeongnamgyeongmae/domain/auctionItem/dto/Comment/AuctionItemCommentChildDto.java new file mode 100644 index 0000000..d4fa267 --- /dev/null +++ b/src/main/java/megabrain/gyeongnamgyeongmae/domain/auctionItem/dto/Comment/AuctionItemCommentChildDto.java @@ -0,0 +1,58 @@ +package megabrain.gyeongnamgyeongmae.domain.auctionItem.dto.Comment; + +import lombok.Builder; +import lombok.Data; +import megabrain.gyeongnamgyeongmae.domain.auctionItem.domain.entity.Comment; + +import java.time.LocalDateTime; + +@Builder +@Data +public class AuctionItemCommentChildDto { + private Long id; + private String content; + private Long userId; + private String nickName; + private Integer likeCount; + private LocalDateTime createdAt; + private LocalDateTime updatedAt; + private Long parent; + + public static AuctionItemCommentChildDto of(Comment comment) { + return builder() + .id(comment.getId()) + .content(comment.getContent()) + .userId(comment.getMember().getId()) + .nickName(comment.getMember().getNickname()) + .likeCount(comment.getLike_count()) + .createdAt(comment.getCreatedAt()) + .updatedAt(comment.getUpdatedAt()) + .parent(comment.getParent().getId()) + .build(); + } + + + public AuctionItemCommentChildDto(final Long id, final String content, final Long userId, final String nickName, final Integer likeCount, final LocalDateTime createdAt, final LocalDateTime updatedAt, final Long parent) { + this.id = id; + this.content = content; + this.userId = userId; + this.nickName = nickName; + this.likeCount = likeCount; + this.createdAt = createdAt; + this.updatedAt = updatedAt; + this.parent = parent; + } + + public static class AuctionItemCommentChildDtoBuilder { + private Long id; + private String content; + private Long userId; + private String nickName; + private Integer likeCount; + private LocalDateTime createdAt; + private LocalDateTime updatedAt; + private Long parent; + + + } +} diff --git a/src/main/java/megabrain/gyeongnamgyeongmae/domain/auctionItem/dto/Comment/AuctionItemCommentParentDto.java b/src/main/java/megabrain/gyeongnamgyeongmae/domain/auctionItem/dto/Comment/AuctionItemCommentParentDto.java new file mode 100644 index 0000000..8ca3e5c --- /dev/null +++ b/src/main/java/megabrain/gyeongnamgyeongmae/domain/auctionItem/dto/Comment/AuctionItemCommentParentDto.java @@ -0,0 +1,48 @@ +package megabrain.gyeongnamgyeongmae.domain.auctionItem.dto.Comment; + + +import lombok.Builder; +import lombok.Data; +import megabrain.gyeongnamgyeongmae.domain.auctionItem.domain.entity.Comment; + +import java.time.LocalDateTime; +import java.util.List; +import java.util.stream.Collectors; + +@Data +@Builder +public class AuctionItemCommentParentDto { + private Long id; + private String content; + private Long userId; + private String nickName; + private Integer likeCount; + private LocalDateTime createdAt; + private LocalDateTime updatedAt; + private List children; + + public static AuctionItemCommentParentDto of(Comment comment) { + return builder() + .id(comment.getId()) + .content(comment.getContent()) + .userId(comment.getMember().getId()) + .nickName(comment.getMember().getNickname()) + .likeCount(comment.getLike_count()) + .createdAt(comment.getCreatedAt()) + .updatedAt(comment.getUpdatedAt()) + .children(comment.getChildren().stream().map(AuctionItemCommentChildDto::of).collect(Collectors.toList())) + .build(); + } + + public AuctionItemCommentParentDto(final Long id, final String content, final Long userId, final String nickName, final Integer likeCount, final LocalDateTime createdAt, final LocalDateTime updatedAt, final List children) { + this.id = id; + this.content = content; + this.userId = userId; + this.nickName = nickName; + this.likeCount = likeCount; + this.createdAt = createdAt; + this.updatedAt = updatedAt; + this.children = children; + } +} + diff --git a/src/main/java/megabrain/gyeongnamgyeongmae/domain/auctionItem/dto/CreateAuctionItemRequest.java b/src/main/java/megabrain/gyeongnamgyeongmae/domain/auctionItem/dto/CreateAuctionItemRequest.java new file mode 100644 index 0000000..7cdffca --- /dev/null +++ b/src/main/java/megabrain/gyeongnamgyeongmae/domain/auctionItem/dto/CreateAuctionItemRequest.java @@ -0,0 +1,46 @@ +package megabrain.gyeongnamgyeongmae.domain.auctionItem.dto; + +import java.time.LocalDateTime; +import javax.validation.constraints.NotNull; + +import lombok.*; +import megabrain.gyeongnamgyeongmae.domain.auctionItem.domain.entity.AuctionItem; +import megabrain.gyeongnamgyeongmae.domain.auctionItem.domain.entity.AuctionItemStatus; + +@Builder +@Getter +@NoArgsConstructor(access = AccessLevel.PRIVATE) +@AllArgsConstructor +public class CreateAuctionItemRequest { + + @NotNull + private String name; + + @NotNull + private Long price; + + @NotNull + private String category; + + @NotNull + private String content; + + @NotNull + private AuctionItemStatus status; + + @NotNull + private LocalDateTime closedTime; + + @NotNull + private Long member; + + public AuctionItem toEntity() { + return AuctionItem.builder() + .name(this.name) + .price(this.price) + .content(this.content) + .itemStatus(this.status) + .closedTime(this.closedTime) + .build(); + } +} diff --git a/src/main/java/megabrain/gyeongnamgyeongmae/domain/auctionItem/dto/SearchItem/SearchAuctionItemSortedRequest.java b/src/main/java/megabrain/gyeongnamgyeongmae/domain/auctionItem/dto/SearchItem/SearchAuctionItemSortedRequest.java new file mode 100644 index 0000000..de3212f --- /dev/null +++ b/src/main/java/megabrain/gyeongnamgyeongmae/domain/auctionItem/dto/SearchItem/SearchAuctionItemSortedRequest.java @@ -0,0 +1,98 @@ +package megabrain.gyeongnamgyeongmae.domain.auctionItem.dto.SearchItem; + +import com.querydsl.core.BooleanBuilder; +import com.querydsl.core.types.OrderSpecifier; + +import java.util.List; + +import lombok.*; +import megabrain.gyeongnamgyeongmae.domain.auctionItem.domain.entity.AuctionItemStatus; +import megabrain.gyeongnamgyeongmae.domain.auctionItem.domain.entity.AuctionStatus; +import megabrain.gyeongnamgyeongmae.domain.auctionItem.domain.entity.QAuctionItem; + + +@Getter +@Setter +public class SearchAuctionItemSortedRequest { + private String keyword = null; + private String category = null; + private SearchStatus search_status; + private Boolean closed; + private Boolean search_time; + private Boolean like; + private Boolean search_price; + private Boolean view_count; + + public void applyKeyWordStatus(BooleanBuilder status, QAuctionItem item) { + if (this.keyword != null) { + status.and(item.name.like("%" + this.keyword + "%")); + } + } + + public void applySearchCategory(BooleanBuilder status, QAuctionItem item) { + if (this.category != null) { + status.and(item.category.name.eq(this.category)); + } + } + + public void applySearchStatus(BooleanBuilder status, QAuctionItem item) { + if (this.search_status == SearchStatus.NEW) { + status.and(item.itemStatus.eq(AuctionItemStatus.NEW)); + } else if (this.search_status == SearchStatus.USED) { + status.and(item.itemStatus.eq(AuctionItemStatus.USED)); + } else { + status.and(item.itemStatus.in(new AuctionItemStatus[]{AuctionItemStatus.NEW, AuctionItemStatus.USED})); + } + } + + public void applySearchPrice(List> order, QAuctionItem item) { + if (this.search_price) { + order.add(item.price.desc()); + } else { + order.add(item.price.asc()); + } + } + + public void applySearchLike(List> order, QAuctionItem item) { + if (this.like) { + order.add(item.like_count.desc()); + } else { + order.add(item.like_count.asc()); + } + } + + public void applySearchView(List> order, QAuctionItem item) { + if (this.view_count) { + order.add(item.view_count.desc()); + } else { + order.add(item.view_count.asc()); + } + } + + public void applySearchTime(List> order, QAuctionItem item) { + if (this.search_time) { + order.add(item.closedTime.desc()); + } else { + order.add(item.closedTime.asc()); + } + } + + public void applySearchClosed(BooleanBuilder builder, QAuctionItem item) { + if (this.closed) { + builder.and(item.status.eq(AuctionStatus.ONGOING)); + } else { + builder.and(item.status.in(new AuctionStatus[]{AuctionStatus.ONGOING, AuctionStatus.CLOSED, AuctionStatus.BIDDING})); + } + } + + public SearchAuctionItemSortedRequest() { + this.search_status = SearchStatus.ALL; + this.closed = Boolean.FALSE; + this.search_time = Boolean.FALSE; + this.like = Boolean.FALSE; + this.search_price = Boolean.FALSE; + this.view_count = Boolean.FALSE; + } + +} + diff --git a/src/main/java/megabrain/gyeongnamgyeongmae/domain/auctionItem/dto/SearchItem/SearchStatus.java b/src/main/java/megabrain/gyeongnamgyeongmae/domain/auctionItem/dto/SearchItem/SearchStatus.java new file mode 100644 index 0000000..de2eaec --- /dev/null +++ b/src/main/java/megabrain/gyeongnamgyeongmae/domain/auctionItem/dto/SearchItem/SearchStatus.java @@ -0,0 +1,7 @@ +package megabrain.gyeongnamgyeongmae.domain.auctionItem.dto.SearchItem; + +public enum SearchStatus { + NEW, + USED, + ALL +} diff --git a/src/main/java/megabrain/gyeongnamgyeongmae/domain/auctionItem/dto/UpdateAuctionItemRequest.java b/src/main/java/megabrain/gyeongnamgyeongmae/domain/auctionItem/dto/UpdateAuctionItemRequest.java new file mode 100644 index 0000000..c2a3866 --- /dev/null +++ b/src/main/java/megabrain/gyeongnamgyeongmae/domain/auctionItem/dto/UpdateAuctionItemRequest.java @@ -0,0 +1,42 @@ +package megabrain.gyeongnamgyeongmae.domain.auctionItem.dto; + +import java.time.LocalDateTime; +import javax.validation.constraints.Min; +import javax.validation.constraints.NotEmpty; +import javax.validation.constraints.NotNull; + +import lombok.*; +import megabrain.gyeongnamgyeongmae.domain.auctionItem.domain.entity.AuctionItemStatus; +import megabrain.gyeongnamgyeongmae.domain.auctionItem.domain.entity.AuctionStatus; + +@Getter +@Setter +@NoArgsConstructor(access = AccessLevel.PRIVATE) +@AllArgsConstructor +public class UpdateAuctionItemRequest { + + @NotEmpty + private String name; + + @NotNull + private Long memberId; + + @Min(1) + private Long price; + + @NotEmpty + private String category; + + @NotEmpty + private String content; + + @NotNull + private AuctionItemStatus itemStatus; + + @NotNull + private LocalDateTime closedTime; + + @NotNull + private AuctionStatus auctionStatus; + +} diff --git a/src/main/java/megabrain/gyeongnamgyeongmae/domain/auctionItem/service/Comment/AuctionItemCommentService.java b/src/main/java/megabrain/gyeongnamgyeongmae/domain/auctionItem/service/Comment/AuctionItemCommentService.java new file mode 100644 index 0000000..2277942 --- /dev/null +++ b/src/main/java/megabrain/gyeongnamgyeongmae/domain/auctionItem/service/Comment/AuctionItemCommentService.java @@ -0,0 +1,19 @@ +package megabrain.gyeongnamgyeongmae.domain.auctionItem.service.Comment; + +import megabrain.gyeongnamgyeongmae.domain.auctionItem.dto.AuctionItemCommentDeleteRequest; +import megabrain.gyeongnamgyeongmae.domain.auctionItem.dto.Comment.AuctionItemCommentParentDto; +import megabrain.gyeongnamgyeongmae.domain.auctionItem.dto.AuctionItemCommentRequest; +import megabrain.gyeongnamgyeongmae.domain.auctionItem.dto.AuctionItemCommentUpdateRequest; + +import java.util.List; + +public interface AuctionItemCommentService { + + void createAuctionItemComment(AuctionItemCommentRequest auctionItemCommentRequest, Long id, Long memberId); + + List findAuctionItemCommentById(Long id); + + void updateAuctionItemComment(AuctionItemCommentUpdateRequest auctionItemCommentUpdateRequest); + + void deleteAuctionItemComment(AuctionItemCommentDeleteRequest auctionItemCommentDeleteRequest); +} diff --git a/src/main/java/megabrain/gyeongnamgyeongmae/domain/auctionItem/service/Comment/AuctionItemCommentServiceImpl.java b/src/main/java/megabrain/gyeongnamgyeongmae/domain/auctionItem/service/Comment/AuctionItemCommentServiceImpl.java new file mode 100644 index 0000000..cb61a9f --- /dev/null +++ b/src/main/java/megabrain/gyeongnamgyeongmae/domain/auctionItem/service/Comment/AuctionItemCommentServiceImpl.java @@ -0,0 +1,88 @@ +package megabrain.gyeongnamgyeongmae.domain.auctionItem.service.Comment; + +import lombok.RequiredArgsConstructor; +import megabrain.gyeongnamgyeongmae.domain.auctionItem.domain.entity.AuctionItem; +import megabrain.gyeongnamgyeongmae.domain.auctionItem.domain.entity.Comment; +import megabrain.gyeongnamgyeongmae.domain.auctionItem.domain.repostiory.AuctionItemCommentRepository; +import megabrain.gyeongnamgyeongmae.domain.auctionItem.domain.repostiory.AuctionItemRepository; +import megabrain.gyeongnamgyeongmae.domain.auctionItem.dto.AuctionItemCommentDeleteRequest; +import megabrain.gyeongnamgyeongmae.domain.auctionItem.dto.Comment.AuctionItemCommentParentDto; +import megabrain.gyeongnamgyeongmae.domain.auctionItem.dto.AuctionItemCommentRequest; +import megabrain.gyeongnamgyeongmae.domain.auctionItem.dto.AuctionItemCommentUpdateRequest; +import megabrain.gyeongnamgyeongmae.domain.member.domain.entity.Member; +import megabrain.gyeongnamgyeongmae.domain.member.domain.repository.MemberRepository; + +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +import java.util.List; +import java.util.Objects; +import java.util.stream.Collectors; + +import static java.util.Arrays.stream; + +@Service +@RequiredArgsConstructor +public class AuctionItemCommentServiceImpl implements AuctionItemCommentService { + + private final AuctionItemCommentRepository auctionItemCommentRepository; + private final MemberRepository memberRepository; + private final AuctionItemRepository auctionItemRepository; + + @Transactional + public void createAuctionItemComment(AuctionItemCommentRequest auctionItemCommentRequest, Long id, Long memberId) { + Member member = (Member) this.memberRepository.findById(memberId).orElseThrow(() -> { + return new RuntimeException("유저를 찾을수 없습니다"); + }); + AuctionItem auctionItem = (AuctionItem) this.auctionItemRepository.findById(id).orElseThrow(() -> { + return new RuntimeException("경매품을 찾을수 없습니다"); + }); + Comment parentComment = null; + Long parentCommentId = auctionItemCommentRequest.getParentCommentId(); + if (parentCommentId >= 1L) { + parentComment = (Comment) this.auctionItemCommentRepository.findById(parentCommentId).orElseThrow(() -> { + return new RuntimeException("부모 댓글을 찾을수 없습니다"); + }); + } + + Comment comment = Comment.builder().content(auctionItemCommentRequest.getContent()).member(member).auctionItem(auctionItem).parent(parentComment).build(); + this.auctionItemCommentRepository.save(comment); + auctionItem.setComment_count(auctionItem.getComment_count() + 1L); + this.auctionItemRepository.save(auctionItem); + } + + @Transactional(readOnly = true) + public List findAuctionItemCommentById(Long id) { + List commentEntityList = this.auctionItemCommentRepository.findByAuctionItemCommentByAuctionId(id); + return commentEntityList.stream().map(AuctionItemCommentParentDto::of).collect(Collectors.toList()); + } + + @Transactional + public void updateAuctionItemComment(AuctionItemCommentUpdateRequest auctionItemCommentUpdateRequest) { + Comment comment = (Comment) this.auctionItemCommentRepository.findById(auctionItemCommentUpdateRequest.getCommentId()).orElseThrow(() -> { + return new RuntimeException("댓글을 찾을수 없습니다"); + }); + if (!Objects.equals(comment.getMember().getId(), auctionItemCommentUpdateRequest.getUserId())) { + throw new RuntimeException("댓글 작성자가 아닙니다"); + } else { + comment.setContent(auctionItemCommentUpdateRequest.getContent()); + this.auctionItemCommentRepository.save(comment); + } + } + + @Transactional + public void deleteAuctionItemComment(AuctionItemCommentDeleteRequest auctionItemCommentDeleteRequest) { + System.out.println(auctionItemCommentDeleteRequest.getCommentId()); + System.out.println(auctionItemCommentDeleteRequest.getUserId()); + Comment comment = (Comment) this.auctionItemCommentRepository.findById(auctionItemCommentDeleteRequest.getCommentId()).orElseThrow(() -> { + return new RuntimeException("댓글을 찾을수 없습니다"); + }); + if (!Objects.equals(comment.getMember().getId(), auctionItemCommentDeleteRequest.getUserId())) { + throw new RuntimeException("댓글 작성자가 아닙니다"); + } else { + comment.setRemoved(true); + this.auctionItemCommentRepository.save(comment); + } + } + +} diff --git a/src/main/java/megabrain/gyeongnamgyeongmae/auctionItem/service/Item/AuctionItemService.java b/src/main/java/megabrain/gyeongnamgyeongmae/domain/auctionItem/service/Item/AuctionItemService.java similarity index 52% rename from src/main/java/megabrain/gyeongnamgyeongmae/auctionItem/service/Item/AuctionItemService.java rename to src/main/java/megabrain/gyeongnamgyeongmae/domain/auctionItem/service/Item/AuctionItemService.java index 6e9ff38..fadb1de 100644 --- a/src/main/java/megabrain/gyeongnamgyeongmae/auctionItem/service/Item/AuctionItemService.java +++ b/src/main/java/megabrain/gyeongnamgyeongmae/domain/auctionItem/service/Item/AuctionItemService.java @@ -1,10 +1,11 @@ -package megabrain.gyeongnamgyeongmae.auctionItem.service.Item; +package megabrain.gyeongnamgyeongmae.domain.auctionItem.service.Item; + +import megabrain.gyeongnamgyeongmae.domain.auctionItem.domain.entity.AuctionItem; +import megabrain.gyeongnamgyeongmae.domain.auctionItem.dto.AuctionItemResponse; +import megabrain.gyeongnamgyeongmae.domain.auctionItem.dto.CreateAuctionItemRequest; +import megabrain.gyeongnamgyeongmae.domain.auctionItem.dto.UpdateAuctionItemRequest; import java.time.LocalDateTime; -import megabrain.gyeongnamgyeongmae.auctionItem.domain.entity.AuctionItem; -import megabrain.gyeongnamgyeongmae.auctionItem.dto.AuctionItemResponse; -import megabrain.gyeongnamgyeongmae.auctionItem.dto.CreateAuctionItemRequest; -import megabrain.gyeongnamgyeongmae.auctionItem.dto.UpdateAuctionItemRequest; public interface AuctionItemService { diff --git a/src/main/java/megabrain/gyeongnamgyeongmae/domain/auctionItem/service/Item/AuctionItemServiceImpl.java b/src/main/java/megabrain/gyeongnamgyeongmae/domain/auctionItem/service/Item/AuctionItemServiceImpl.java new file mode 100644 index 0000000..909b07e --- /dev/null +++ b/src/main/java/megabrain/gyeongnamgyeongmae/domain/auctionItem/service/Item/AuctionItemServiceImpl.java @@ -0,0 +1,92 @@ +package megabrain.gyeongnamgyeongmae.domain.auctionItem.service.Item; + +import java.time.LocalDateTime; +import java.util.Objects; + +import lombok.RequiredArgsConstructor; +import megabrain.gyeongnamgyeongmae.domain.auctionItem.domain.entity.AuctionItem; +import megabrain.gyeongnamgyeongmae.domain.auctionItem.domain.repostiory.AuctionItemRepository; +import megabrain.gyeongnamgyeongmae.domain.auctionItem.dto.AuctionItemResponse; +import megabrain.gyeongnamgyeongmae.domain.auctionItem.dto.CreateAuctionItemRequest; +import megabrain.gyeongnamgyeongmae.domain.auctionItem.dto.UpdateAuctionItemRequest; +import megabrain.gyeongnamgyeongmae.domain.category.domain.entity.Category; +import megabrain.gyeongnamgyeongmae.domain.category.domain.repository.CategoryRepository; +import megabrain.gyeongnamgyeongmae.domain.category.service.CategoryService; +import megabrain.gyeongnamgyeongmae.domain.member.domain.entity.Member; +import megabrain.gyeongnamgyeongmae.domain.member.domain.repository.MemberRepository; +import megabrain.gyeongnamgyeongmae.domain.member.service.MemberService; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +@Service +@RequiredArgsConstructor +public class AuctionItemServiceImpl implements AuctionItemService { + + private final AuctionItemRepository auctionItemRepository; + private final CategoryService categoryService; + private final MemberRepository memberRepository; + private final CategoryRepository categoryRepository; + private final MemberService memberService; + + @Override + @Transactional + public void createAuctionItem(CreateAuctionItemRequest createAuctionItemRequest) { + checkClosedTime(createAuctionItemRequest.getClosedTime()); + Member memberEntity = memberService.findMemberById(createAuctionItemRequest.getMember()); + Category categoryEntity = + categoryService.findCategoryByName(createAuctionItemRequest.getCategory()); + AuctionItem auctionItem = createAuctionItemRequest.toEntity(); + auctionItem.setMember(memberEntity); + auctionItem.setCategory(categoryEntity); + auctionItemRepository.save(auctionItem); + } + + @Override + @Transactional + public AuctionItemResponse findAuctionItemById(Long id) { + AuctionItem auctionItem = auctionItemRepository.findById(id).orElseThrow(RuntimeException::new); + auctionItem.checkShowAuctionItem(auctionItem); + updateAuctionItemViewCount(auctionItem); + return AuctionItemResponse.of(auctionItem); + } + + @Override + public void updateAuctionItemViewCount(AuctionItem auctionItem) { + auctionItem.setView_count(auctionItem.getView_count() + 1); + auctionItemRepository.save(auctionItem); + } + + @Override + @Transactional + public void updateAuctionItem(UpdateAuctionItemRequest upDateAuctionItemRequest, Long id) { + checkClosedTime(upDateAuctionItemRequest.getClosedTime()); + Category categoryEntity = + categoryService.findCategoryByName(upDateAuctionItemRequest.getCategory()); + AuctionItem auctionItem = auctionItemRepository.findById(id).orElseThrow(RuntimeException::new); + + if (!(Objects.equals(auctionItem.getMember().getId(), upDateAuctionItemRequest.getMemberId()))) { + throw new RuntimeException("잘못된 회원입니다 "); + } + + auctionItem.checkShowAuctionItem(auctionItem); + auctionItem.updateAuctionItem(upDateAuctionItemRequest); + auctionItem.setCategory(categoryEntity); + auctionItemRepository.save(auctionItem); + } + + @Override + public void checkClosedTime(LocalDateTime closedTime) { + LocalDateTime now = LocalDateTime.now(); + if (closedTime.isBefore(now.plusHours(24))) { + throw new RuntimeException("경매 종료 시간은 현재 시간보다 24시간 이후여야 합니다."); + } + } + + @Override + @Transactional + public void deleteAuctionItemById(Long id) { + AuctionItem auctionItem = auctionItemRepository.findById(id).orElseThrow(RuntimeException::new); + auctionItem.removeAuctionItem(auctionItem); + auctionItemRepository.save(auctionItem); + } +} diff --git a/src/main/java/megabrain/gyeongnamgyeongmae/domain/auctionItem/service/Search/AuctionItemSearchService.java b/src/main/java/megabrain/gyeongnamgyeongmae/domain/auctionItem/service/Search/AuctionItemSearchService.java new file mode 100644 index 0000000..6e6dfec --- /dev/null +++ b/src/main/java/megabrain/gyeongnamgyeongmae/domain/auctionItem/service/Search/AuctionItemSearchService.java @@ -0,0 +1,10 @@ +package megabrain.gyeongnamgyeongmae.domain.auctionItem.service.Search; + +import megabrain.gyeongnamgyeongmae.domain.auctionItem.dto.AuctionItemFirstView; +import megabrain.gyeongnamgyeongmae.domain.auctionItem.dto.SearchItem.SearchAuctionItemSortedRequest; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.Pageable; + +public interface AuctionItemSearchService { + Page findAuctionItembyRequest(SearchAuctionItemSortedRequest searchAuctionItemSortedRequest, Pageable pageable); +} diff --git a/src/main/java/megabrain/gyeongnamgyeongmae/auctionItem/service/Search/AuctionItemSearchServiceImpl.java b/src/main/java/megabrain/gyeongnamgyeongmae/domain/auctionItem/service/Search/AuctionItemSearchServiceImpl.java similarity index 56% rename from src/main/java/megabrain/gyeongnamgyeongmae/auctionItem/service/Search/AuctionItemSearchServiceImpl.java rename to src/main/java/megabrain/gyeongnamgyeongmae/domain/auctionItem/service/Search/AuctionItemSearchServiceImpl.java index 83e4070..1800b1f 100644 --- a/src/main/java/megabrain/gyeongnamgyeongmae/auctionItem/service/Search/AuctionItemSearchServiceImpl.java +++ b/src/main/java/megabrain/gyeongnamgyeongmae/domain/auctionItem/service/Search/AuctionItemSearchServiceImpl.java @@ -1,11 +1,12 @@ -package megabrain.gyeongnamgyeongmae.auctionItem.service.Search; +package megabrain.gyeongnamgyeongmae.domain.auctionItem.service.Search; import lombok.RequiredArgsConstructor; -import megabrain.gyeongnamgyeongmae.Category.service.CategoryService; -import megabrain.gyeongnamgyeongmae.auctionItem.domain.entity.AuctionItem; -import megabrain.gyeongnamgyeongmae.auctionItem.domain.repostiory.AuctionItemRepository; -import megabrain.gyeongnamgyeongmae.auctionItem.dto.AuctionItemFirstView; -import megabrain.gyeongnamgyeongmae.auctionItem.dto.SearchItem.SearchAuctionItemSortedRequest; + +import megabrain.gyeongnamgyeongmae.domain.auctionItem.domain.entity.AuctionItem; +import megabrain.gyeongnamgyeongmae.domain.auctionItem.domain.repostiory.AuctionItemRepository; +import megabrain.gyeongnamgyeongmae.domain.auctionItem.dto.AuctionItemFirstView; +import megabrain.gyeongnamgyeongmae.domain.auctionItem.dto.SearchItem.SearchAuctionItemSortedRequest; +import megabrain.gyeongnamgyeongmae.domain.category.service.CategoryService; import org.springframework.data.domain.Page; import org.springframework.data.domain.Pageable; import org.springframework.stereotype.Service; @@ -21,7 +22,7 @@ public class AuctionItemSearchServiceImpl implements AuctionItemSearchService { @Override @Transactional(readOnly = true) public Page findAuctionItembyRequest( - SearchAuctionItemSortedRequest searchAuctionItemSortedRequest, Pageable pageable) { + SearchAuctionItemSortedRequest searchAuctionItemSortedRequest, Pageable pageable) { Page auctionItemEntityList = auctionItemRepository.searchAuctionItemPage(searchAuctionItemSortedRequest, pageable); return auctionItemEntityList.map(AuctionItemFirstView::of); diff --git a/src/main/java/megabrain/gyeongnamgyeongmae/Category/controller/CategoryController.java b/src/main/java/megabrain/gyeongnamgyeongmae/domain/category/controller/CategoryController.java similarity index 79% rename from src/main/java/megabrain/gyeongnamgyeongmae/Category/controller/CategoryController.java rename to src/main/java/megabrain/gyeongnamgyeongmae/domain/category/controller/CategoryController.java index b67b78d..361a1ee 100644 --- a/src/main/java/megabrain/gyeongnamgyeongmae/Category/controller/CategoryController.java +++ b/src/main/java/megabrain/gyeongnamgyeongmae/domain/category/controller/CategoryController.java @@ -1,9 +1,9 @@ -package megabrain.gyeongnamgyeongmae.Category.controller; +package megabrain.gyeongnamgyeongmae.domain.category.controller; import javax.validation.Valid; import lombok.RequiredArgsConstructor; -import megabrain.gyeongnamgyeongmae.Category.dto.CreateCategoryRequest; -import megabrain.gyeongnamgyeongmae.Category.service.CategoryService; +import megabrain.gyeongnamgyeongmae.domain.category.dto.CreateCategoryRequest; +import megabrain.gyeongnamgyeongmae.domain.category.service.CategoryService; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.PostMapping; diff --git a/src/main/java/megabrain/gyeongnamgyeongmae/Category/domain/entity/Category.java b/src/main/java/megabrain/gyeongnamgyeongmae/domain/category/domain/entity/Category.java similarity index 83% rename from src/main/java/megabrain/gyeongnamgyeongmae/Category/domain/entity/Category.java rename to src/main/java/megabrain/gyeongnamgyeongmae/domain/category/domain/entity/Category.java index 9752d8f..b973717 100644 --- a/src/main/java/megabrain/gyeongnamgyeongmae/Category/domain/entity/Category.java +++ b/src/main/java/megabrain/gyeongnamgyeongmae/domain/category/domain/entity/Category.java @@ -1,4 +1,4 @@ -package megabrain.gyeongnamgyeongmae.Category.domain.entity; +package megabrain.gyeongnamgyeongmae.domain.category.domain.entity; import javax.persistence.*; import lombok.AccessLevel; @@ -9,6 +9,7 @@ @Getter @Entity @NoArgsConstructor(access = AccessLevel.PROTECTED) +@Table(name = "categories") public class Category { @Id diff --git a/src/main/java/megabrain/gyeongnamgyeongmae/Category/domain/repository/CategoryRepository.java b/src/main/java/megabrain/gyeongnamgyeongmae/domain/category/domain/repository/CategoryRepository.java similarity index 60% rename from src/main/java/megabrain/gyeongnamgyeongmae/Category/domain/repository/CategoryRepository.java rename to src/main/java/megabrain/gyeongnamgyeongmae/domain/category/domain/repository/CategoryRepository.java index b232485..ef72c1d 100644 --- a/src/main/java/megabrain/gyeongnamgyeongmae/Category/domain/repository/CategoryRepository.java +++ b/src/main/java/megabrain/gyeongnamgyeongmae/domain/category/domain/repository/CategoryRepository.java @@ -1,7 +1,7 @@ -package megabrain.gyeongnamgyeongmae.Category.domain.repository; +package megabrain.gyeongnamgyeongmae.domain.category.domain.repository; import java.util.Optional; -import megabrain.gyeongnamgyeongmae.Category.domain.entity.Category; +import megabrain.gyeongnamgyeongmae.domain.category.domain.entity.Category; import org.springframework.data.jpa.repository.JpaRepository; public interface CategoryRepository extends JpaRepository { diff --git a/src/main/java/megabrain/gyeongnamgyeongmae/Category/dto/CreateCategoryRequest.java b/src/main/java/megabrain/gyeongnamgyeongmae/domain/category/dto/CreateCategoryRequest.java similarity index 78% rename from src/main/java/megabrain/gyeongnamgyeongmae/Category/dto/CreateCategoryRequest.java rename to src/main/java/megabrain/gyeongnamgyeongmae/domain/category/dto/CreateCategoryRequest.java index 04d8ec8..f466978 100644 --- a/src/main/java/megabrain/gyeongnamgyeongmae/Category/dto/CreateCategoryRequest.java +++ b/src/main/java/megabrain/gyeongnamgyeongmae/domain/category/dto/CreateCategoryRequest.java @@ -1,11 +1,11 @@ -package megabrain.gyeongnamgyeongmae.Category.dto; +package megabrain.gyeongnamgyeongmae.domain.category.dto; import javax.validation.constraints.NotNull; import lombok.AccessLevel; import lombok.Builder; import lombok.Getter; import lombok.NoArgsConstructor; -import megabrain.gyeongnamgyeongmae.Category.domain.entity.Category; +import megabrain.gyeongnamgyeongmae.domain.category.domain.entity.Category; @Getter @NoArgsConstructor(access = AccessLevel.PRIVATE) diff --git a/src/main/java/megabrain/gyeongnamgyeongmae/Category/service/CategoryService.java b/src/main/java/megabrain/gyeongnamgyeongmae/domain/category/service/CategoryService.java similarity index 72% rename from src/main/java/megabrain/gyeongnamgyeongmae/Category/service/CategoryService.java rename to src/main/java/megabrain/gyeongnamgyeongmae/domain/category/service/CategoryService.java index fdc0cd9..31f1a8b 100644 --- a/src/main/java/megabrain/gyeongnamgyeongmae/Category/service/CategoryService.java +++ b/src/main/java/megabrain/gyeongnamgyeongmae/domain/category/service/CategoryService.java @@ -1,8 +1,8 @@ -package megabrain.gyeongnamgyeongmae.Category.service; +package megabrain.gyeongnamgyeongmae.domain.category.service; import lombok.RequiredArgsConstructor; -import megabrain.gyeongnamgyeongmae.Category.domain.entity.Category; -import megabrain.gyeongnamgyeongmae.Category.domain.repository.CategoryRepository; +import megabrain.gyeongnamgyeongmae.domain.category.domain.entity.Category; +import megabrain.gyeongnamgyeongmae.domain.category.domain.repository.CategoryRepository; import org.springframework.stereotype.Service; @Service diff --git a/src/main/java/megabrain/gyeongnamgyeongmae/Category/service/ICategoryService.java b/src/main/java/megabrain/gyeongnamgyeongmae/domain/category/service/ICategoryService.java similarity index 50% rename from src/main/java/megabrain/gyeongnamgyeongmae/Category/service/ICategoryService.java rename to src/main/java/megabrain/gyeongnamgyeongmae/domain/category/service/ICategoryService.java index 0d55367..9088647 100644 --- a/src/main/java/megabrain/gyeongnamgyeongmae/Category/service/ICategoryService.java +++ b/src/main/java/megabrain/gyeongnamgyeongmae/domain/category/service/ICategoryService.java @@ -1,6 +1,6 @@ -package megabrain.gyeongnamgyeongmae.Category.service; +package megabrain.gyeongnamgyeongmae.domain.category.service; -import megabrain.gyeongnamgyeongmae.Category.domain.entity.Category; +import megabrain.gyeongnamgyeongmae.domain.category.domain.entity.Category; public interface ICategoryService { diff --git a/src/main/java/megabrain/gyeongnamgyeongmae/Image/domain/entity/Image.java b/src/main/java/megabrain/gyeongnamgyeongmae/domain/domain/Image.java similarity index 59% rename from src/main/java/megabrain/gyeongnamgyeongmae/Image/domain/entity/Image.java rename to src/main/java/megabrain/gyeongnamgyeongmae/domain/domain/Image.java index 1c6ed0c..6a58d9d 100644 --- a/src/main/java/megabrain/gyeongnamgyeongmae/Image/domain/entity/Image.java +++ b/src/main/java/megabrain/gyeongnamgyeongmae/domain/domain/Image.java @@ -1,4 +1,4 @@ -package megabrain.gyeongnamgyeongmae.Image.domain.entity; +package megabrain.gyeongnamgyeongmae.domain.domain; import javax.persistence.*; import javax.validation.constraints.NotNull; @@ -6,11 +6,11 @@ import lombok.Builder; import lombok.Getter; import lombok.NoArgsConstructor; -import megabrain.gyeongnamgyeongmae.auctionItem.domain.entity.AuctionItem; -import megabrain.gyeongnamgyeongmae.commons.BaseTimeEntity; +import megabrain.gyeongnamgyeongmae.domain.auctionItem.domain.entity.AuctionItem; +import megabrain.gyeongnamgyeongmae.global.commons.BaseTimeEntity; @Entity -@Table(name = "Image", indexes = @Index(name = "url", columnList = "image_url")) +@Table(name = "images", indexes = @Index(name = "url", columnList = "image_url")) @Getter @NoArgsConstructor(access = AccessLevel.PROTECTED) public class Image extends BaseTimeEntity { @@ -31,9 +31,9 @@ public class Image extends BaseTimeEntity { @JoinColumn(name = "auction_id") private AuctionItem auctionItem; - @Builder - public Image(String url, AuctionItem auctionItem) { - this.url = url; - this.auctionItem = auctionItem; - } +// @Builder +// public Image(String url, AuctionItem auctionItem) { +// this.url = url; +// this.auctionItem = auctionItem; +// } } diff --git a/src/main/java/megabrain/gyeongnamgyeongmae/member/controller/MemberController.java b/src/main/java/megabrain/gyeongnamgyeongmae/domain/member/controller/MemberController.java similarity index 81% rename from src/main/java/megabrain/gyeongnamgyeongmae/member/controller/MemberController.java rename to src/main/java/megabrain/gyeongnamgyeongmae/domain/member/controller/MemberController.java index a1bb803..dafac08 100644 --- a/src/main/java/megabrain/gyeongnamgyeongmae/member/controller/MemberController.java +++ b/src/main/java/megabrain/gyeongnamgyeongmae/domain/member/controller/MemberController.java @@ -1,10 +1,10 @@ -package megabrain.gyeongnamgyeongmae.member.controller; +package megabrain.gyeongnamgyeongmae.domain.member.controller; import javax.validation.Valid; import lombok.RequiredArgsConstructor; -import megabrain.gyeongnamgyeongmae.member.domain.entity.Member; -import megabrain.gyeongnamgyeongmae.member.dto.MemberCreateRequest; -import megabrain.gyeongnamgyeongmae.member.service.MemberService; +import megabrain.gyeongnamgyeongmae.domain.member.domain.entity.Member; +import megabrain.gyeongnamgyeongmae.domain.member.dto.MemberCreateRequest; +import megabrain.gyeongnamgyeongmae.domain.member.service.MemberService; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; import org.springframework.security.crypto.password.PasswordEncoder; diff --git a/src/main/java/megabrain/gyeongnamgyeongmae/member/domain/entity/Address.java b/src/main/java/megabrain/gyeongnamgyeongmae/domain/member/domain/entity/Address.java similarity index 68% rename from src/main/java/megabrain/gyeongnamgyeongmae/member/domain/entity/Address.java rename to src/main/java/megabrain/gyeongnamgyeongmae/domain/member/domain/entity/Address.java index 9faf78c..80a19c6 100644 --- a/src/main/java/megabrain/gyeongnamgyeongmae/member/domain/entity/Address.java +++ b/src/main/java/megabrain/gyeongnamgyeongmae/domain/member/domain/entity/Address.java @@ -1,4 +1,4 @@ -package megabrain.gyeongnamgyeongmae.member.domain.entity; +package megabrain.gyeongnamgyeongmae.domain.member.domain.entity; import javax.persistence.Embeddable; diff --git a/src/main/java/megabrain/gyeongnamgyeongmae/member/domain/entity/Member.java b/src/main/java/megabrain/gyeongnamgyeongmae/domain/member/domain/entity/Member.java similarity index 85% rename from src/main/java/megabrain/gyeongnamgyeongmae/member/domain/entity/Member.java rename to src/main/java/megabrain/gyeongnamgyeongmae/domain/member/domain/entity/Member.java index 475c6c6..23473fe 100644 --- a/src/main/java/megabrain/gyeongnamgyeongmae/member/domain/entity/Member.java +++ b/src/main/java/megabrain/gyeongnamgyeongmae/domain/member/domain/entity/Member.java @@ -1,9 +1,9 @@ -package megabrain.gyeongnamgyeongmae.member.domain.entity; +package megabrain.gyeongnamgyeongmae.domain.member.domain.entity; import javax.persistence.*; import lombok.*; import lombok.NoArgsConstructor; -import megabrain.gyeongnamgyeongmae.commons.BaseTimeEntity; +import megabrain.gyeongnamgyeongmae.global.commons.BaseTimeEntity; @Getter @Entity diff --git a/src/main/java/megabrain/gyeongnamgyeongmae/member/domain/repository/MemberRepository.java b/src/main/java/megabrain/gyeongnamgyeongmae/domain/member/domain/repository/MemberRepository.java similarity index 56% rename from src/main/java/megabrain/gyeongnamgyeongmae/member/domain/repository/MemberRepository.java rename to src/main/java/megabrain/gyeongnamgyeongmae/domain/member/domain/repository/MemberRepository.java index ae7437d..1b57bd8 100644 --- a/src/main/java/megabrain/gyeongnamgyeongmae/member/domain/repository/MemberRepository.java +++ b/src/main/java/megabrain/gyeongnamgyeongmae/domain/member/domain/repository/MemberRepository.java @@ -1,6 +1,6 @@ -package megabrain.gyeongnamgyeongmae.member.domain.repository; +package megabrain.gyeongnamgyeongmae.domain.member.domain.repository; -import megabrain.gyeongnamgyeongmae.member.domain.entity.Member; +import megabrain.gyeongnamgyeongmae.domain.member.domain.entity.Member; import org.springframework.data.jpa.repository.JpaRepository; public interface MemberRepository extends JpaRepository { diff --git a/src/main/java/megabrain/gyeongnamgyeongmae/member/dto/MemberCreateRequest.java b/src/main/java/megabrain/gyeongnamgyeongmae/domain/member/dto/MemberCreateRequest.java similarity index 89% rename from src/main/java/megabrain/gyeongnamgyeongmae/member/dto/MemberCreateRequest.java rename to src/main/java/megabrain/gyeongnamgyeongmae/domain/member/dto/MemberCreateRequest.java index 99bb6ec..9f5cf9e 100644 --- a/src/main/java/megabrain/gyeongnamgyeongmae/member/dto/MemberCreateRequest.java +++ b/src/main/java/megabrain/gyeongnamgyeongmae/domain/member/dto/MemberCreateRequest.java @@ -1,10 +1,10 @@ -package megabrain.gyeongnamgyeongmae.member.dto; +package megabrain.gyeongnamgyeongmae.domain.member.dto; import javax.validation.constraints.Email; import javax.validation.constraints.NotEmpty; import javax.validation.constraints.Pattern; import lombok.*; -import megabrain.gyeongnamgyeongmae.member.domain.entity.Member; +import megabrain.gyeongnamgyeongmae.domain.member.domain.entity.Member; import org.springframework.security.crypto.password.PasswordEncoder; @Getter diff --git a/src/main/java/megabrain/gyeongnamgyeongmae/member/service/GeneralMemberService.java b/src/main/java/megabrain/gyeongnamgyeongmae/domain/member/service/GeneralMemberService.java similarity index 75% rename from src/main/java/megabrain/gyeongnamgyeongmae/member/service/GeneralMemberService.java rename to src/main/java/megabrain/gyeongnamgyeongmae/domain/member/service/GeneralMemberService.java index 629558e..cdc12c2 100644 --- a/src/main/java/megabrain/gyeongnamgyeongmae/member/service/GeneralMemberService.java +++ b/src/main/java/megabrain/gyeongnamgyeongmae/domain/member/service/GeneralMemberService.java @@ -1,8 +1,8 @@ -package megabrain.gyeongnamgyeongmae.member.service; +package megabrain.gyeongnamgyeongmae.domain.member.service; import lombok.RequiredArgsConstructor; -import megabrain.gyeongnamgyeongmae.member.domain.entity.Member; -import megabrain.gyeongnamgyeongmae.member.domain.repository.MemberRepository; +import megabrain.gyeongnamgyeongmae.domain.member.domain.entity.Member; +import megabrain.gyeongnamgyeongmae.domain.member.domain.repository.MemberRepository; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; diff --git a/src/main/java/megabrain/gyeongnamgyeongmae/member/service/MemberService.java b/src/main/java/megabrain/gyeongnamgyeongmae/domain/member/service/MemberService.java similarity index 53% rename from src/main/java/megabrain/gyeongnamgyeongmae/member/service/MemberService.java rename to src/main/java/megabrain/gyeongnamgyeongmae/domain/member/service/MemberService.java index 3344be4..853ace1 100644 --- a/src/main/java/megabrain/gyeongnamgyeongmae/member/service/MemberService.java +++ b/src/main/java/megabrain/gyeongnamgyeongmae/domain/member/service/MemberService.java @@ -1,6 +1,6 @@ -package megabrain.gyeongnamgyeongmae.member.service; +package megabrain.gyeongnamgyeongmae.domain.member.service; -import megabrain.gyeongnamgyeongmae.member.domain.entity.Member; +import megabrain.gyeongnamgyeongmae.domain.member.domain.entity.Member; public interface MemberService { diff --git a/src/main/java/megabrain/gyeongnamgyeongmae/commons/BaseTimeEntity.java b/src/main/java/megabrain/gyeongnamgyeongmae/global/commons/BaseTimeEntity.java similarity index 91% rename from src/main/java/megabrain/gyeongnamgyeongmae/commons/BaseTimeEntity.java rename to src/main/java/megabrain/gyeongnamgyeongmae/global/commons/BaseTimeEntity.java index 2ce44d0..f306c10 100644 --- a/src/main/java/megabrain/gyeongnamgyeongmae/commons/BaseTimeEntity.java +++ b/src/main/java/megabrain/gyeongnamgyeongmae/global/commons/BaseTimeEntity.java @@ -1,4 +1,4 @@ -package megabrain.gyeongnamgyeongmae.commons; +package megabrain.gyeongnamgyeongmae.global.commons; import java.time.LocalDateTime; import javax.persistence.EntityListeners; diff --git a/src/main/java/megabrain/gyeongnamgyeongmae/commons/resolver/LoginMemberArgumentResolver.java b/src/main/java/megabrain/gyeongnamgyeongmae/global/commons/resolver/LoginMemberArgumentResolver.java similarity index 93% rename from src/main/java/megabrain/gyeongnamgyeongmae/commons/resolver/LoginMemberArgumentResolver.java rename to src/main/java/megabrain/gyeongnamgyeongmae/global/commons/resolver/LoginMemberArgumentResolver.java index 5daa267..878e4ed 100644 --- a/src/main/java/megabrain/gyeongnamgyeongmae/commons/resolver/LoginMemberArgumentResolver.java +++ b/src/main/java/megabrain/gyeongnamgyeongmae/global/commons/resolver/LoginMemberArgumentResolver.java @@ -1,4 +1,4 @@ -package megabrain.gyeongnamgyeongmae.commons.resolver; +package megabrain.gyeongnamgyeongmae.global.commons.resolver; import lombok.RequiredArgsConstructor; import org.springframework.core.MethodParameter; diff --git a/src/main/java/megabrain/gyeongnamgyeongmae/commons/config/JpaAuditingConfig.java b/src/main/java/megabrain/gyeongnamgyeongmae/global/config/JpaAuditingConfig.java similarity index 79% rename from src/main/java/megabrain/gyeongnamgyeongmae/commons/config/JpaAuditingConfig.java rename to src/main/java/megabrain/gyeongnamgyeongmae/global/config/JpaAuditingConfig.java index 53ddcb7..9caa521 100644 --- a/src/main/java/megabrain/gyeongnamgyeongmae/commons/config/JpaAuditingConfig.java +++ b/src/main/java/megabrain/gyeongnamgyeongmae/global/config/JpaAuditingConfig.java @@ -1,4 +1,4 @@ -package megabrain.gyeongnamgyeongmae.commons.config; +package megabrain.gyeongnamgyeongmae.global.config; import org.springframework.context.annotation.Configuration; import org.springframework.data.jpa.repository.config.EnableJpaAuditing; diff --git a/src/main/java/megabrain/gyeongnamgyeongmae/global/config/ObjectMapperConfig.java b/src/main/java/megabrain/gyeongnamgyeongmae/global/config/ObjectMapperConfig.java new file mode 100644 index 0000000..6be30ca --- /dev/null +++ b/src/main/java/megabrain/gyeongnamgyeongmae/global/config/ObjectMapperConfig.java @@ -0,0 +1,11 @@ +package megabrain.gyeongnamgyeongmae.global.config; + +import com.fasterxml.jackson.databind.ObjectMapper; +import org.springframework.context.annotation.Bean; + +public class ObjectMapperConfig { + @Bean + public ObjectMapper objectMapper() { + return new ObjectMapper(); + } +} diff --git a/src/main/java/megabrain/gyeongnamgyeongmae/commons/config/QueryDslConfig.java b/src/main/java/megabrain/gyeongnamgyeongmae/global/config/QueryDslConfig.java similarity index 55% rename from src/main/java/megabrain/gyeongnamgyeongmae/commons/config/QueryDslConfig.java rename to src/main/java/megabrain/gyeongnamgyeongmae/global/config/QueryDslConfig.java index f219b4a..243e685 100644 --- a/src/main/java/megabrain/gyeongnamgyeongmae/commons/config/QueryDslConfig.java +++ b/src/main/java/megabrain/gyeongnamgyeongmae/global/config/QueryDslConfig.java @@ -1,18 +1,21 @@ -package megabrain.gyeongnamgyeongmae.commons.config; +package megabrain.gyeongnamgyeongmae.global.config; import com.querydsl.jpa.impl.JPAQueryFactory; + import javax.persistence.EntityManager; import javax.persistence.PersistenceContext; + import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; @Configuration public class QueryDslConfig { - @PersistenceContext private EntityManager entityManager; + @PersistenceContext + private EntityManager entityManager; - @Bean - public JPAQueryFactory JPAQueryFactory() { - return new JPAQueryFactory(entityManager); - } -} + @Bean + public JPAQueryFactory JPAQueryFactory() { + return new JPAQueryFactory(entityManager); + } +} \ No newline at end of file diff --git a/src/main/java/megabrain/gyeongnamgyeongmae/global/config/SecurityConfig.java b/src/main/java/megabrain/gyeongnamgyeongmae/global/config/SecurityConfig.java new file mode 100644 index 0000000..48ca620 --- /dev/null +++ b/src/main/java/megabrain/gyeongnamgyeongmae/global/config/SecurityConfig.java @@ -0,0 +1,39 @@ +package megabrain.gyeongnamgyeongmae.global.config; + +import lombok.RequiredArgsConstructor; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.security.config.annotation.web.builders.HttpSecurity; +import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder; +import org.springframework.security.crypto.password.PasswordEncoder; +import org.springframework.security.web.SecurityFilterChain; + +@Configuration +@RequiredArgsConstructor +public class SecurityConfig { + + @Bean + public PasswordEncoder passwordEncoder() { + return new BCryptPasswordEncoder(); + } + + @Bean + public SecurityFilterChain securityFilterChain(HttpSecurity httpSecurity) throws Exception { + return httpSecurity + .httpBasic() + .disable() + .csrf() + .disable() + .cors() + .and() + .headers() + .frameOptions() + .disable() + .and() + .authorizeRequests() + .antMatchers("*") + .permitAll() + .and() + .build(); + } +} diff --git a/src/main/java/megabrain/gyeongnamgyeongmae/global/config/SwaggerConfig.java b/src/main/java/megabrain/gyeongnamgyeongmae/global/config/SwaggerConfig.java new file mode 100644 index 0000000..4ff6714 --- /dev/null +++ b/src/main/java/megabrain/gyeongnamgyeongmae/global/config/SwaggerConfig.java @@ -0,0 +1,17 @@ +package megabrain.gyeongnamgyeongmae.global.config; + +import io.swagger.v3.oas.models.OpenAPI; +import io.swagger.v3.oas.models.info.Info; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; + +@Configuration +public class SwaggerConfig { + @Bean + public OpenAPI openAPI() { + + Info info = + new Info().version("v1.0.0").title("GyeongnamGyeongmae API").description("경남경매 API "); + return new OpenAPI().info(info); + } +} diff --git a/src/main/resources/application-postgresql.properties b/src/main/resources/application-postgresql.properties deleted file mode 100644 index 61d46f8..0000000 --- a/src/main/resources/application-postgresql.properties +++ /dev/null @@ -1,6 +0,0 @@ -spring.datasource.url=jdbc:postgresql://localhost:5432/gyeongnam_gyeongmae_local -spring.datasource.driver-class-name=org.postgresql.Driver -spring.jpa.show-sql=true -spring.jpa.database=postgresql -spring.jpa.generate-ddl=true -spring.jpa.hibernate.ddl-auto=create \ No newline at end of file diff --git a/src/main/resources/application-postgresql.yml b/src/main/resources/application-postgresql.yml new file mode 100644 index 0000000..67a18fc --- /dev/null +++ b/src/main/resources/application-postgresql.yml @@ -0,0 +1,17 @@ +spring: + datasource: + url: ${POSTGRES_URL} + driver-class-name: org.postgresql.Driver + password: ${POSTGRES_PASSWORD} + username: ${POSTGRES_USER} + jpa: + show-sql: true + database: postgresql + generate-ddl: true + hibernate: + ddlAuto: update # craete + properties: + hibernate.jdbc.batch_size: 20 + hibernate.cache.use_query_cache: false + hibernate.cache.use_second_level_cache: false + hibernate.cache.use_structured_entries: false \ No newline at end of file diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties deleted file mode 100644 index 19b8908..0000000 --- a/src/main/resources/application.properties +++ /dev/null @@ -1 +0,0 @@ -spring.config.import=application-postgresql.properties diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml new file mode 100644 index 0000000..8c8bac8 --- /dev/null +++ b/src/main/resources/application.yml @@ -0,0 +1,3 @@ +server.port: ${PORT} +spring.config.import: + - application-postgresql.yml diff --git a/src/test/java/megabrain/gyeongnamgyeongmae/auctionItem/controller/AuctionControllerTest.java b/src/test/java/megabrain/gyeongnamgyeongmae/auctionItem/controller/AuctionControllerTest.java index bc4ed29..f438c0f 100644 --- a/src/test/java/megabrain/gyeongnamgyeongmae/auctionItem/controller/AuctionControllerTest.java +++ b/src/test/java/megabrain/gyeongnamgyeongmae/auctionItem/controller/AuctionControllerTest.java @@ -1,157 +1,158 @@ -package megabrain.gyeongnamgyeongmae.auctionItem.controller; - -import static megabrain.gyeongnamgyeongmae.fixture.AuctionItemFixture.*; -import static org.hamcrest.Matchers.startsWith; -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.mockito.ArgumentCaptor.forClass; -import static org.mockito.Mockito.*; -import static org.springframework.restdocs.mockmvc.MockMvcRestDocumentation.documentationConfiguration; -import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*; -import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.print; -import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath; -import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; - -import com.fasterxml.jackson.core.JsonProcessingException; -import com.fasterxml.jackson.databind.ObjectMapper; -import java.util.Optional; -import megabrain.gyeongnamgyeongmae.Category.service.CategoryService; -import megabrain.gyeongnamgyeongmae.auctionItem.domain.entity.AuctionItem; -import megabrain.gyeongnamgyeongmae.auctionItem.domain.entity.AuctionStatus; -import megabrain.gyeongnamgyeongmae.auctionItem.domain.repostiory.AuctionItemRepository; -import megabrain.gyeongnamgyeongmae.auctionItem.dto.AuctionItemResponse; -import megabrain.gyeongnamgyeongmae.auctionItem.dto.UpdateAuctionItemRequest; -import megabrain.gyeongnamgyeongmae.auctionItem.service.Item.AuctionItemServiceImpl; -import megabrain.gyeongnamgyeongmae.member.service.MemberService; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.DisplayName; -import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.extension.ExtendWith; -import org.mockito.ArgumentCaptor; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest; -import org.springframework.boot.test.mock.mockito.MockBean; -import org.springframework.http.MediaType; -import org.springframework.restdocs.RestDocumentationContextProvider; -import org.springframework.restdocs.RestDocumentationExtension; -import org.springframework.test.web.servlet.MockMvc; -import org.springframework.test.web.servlet.setup.MockMvcBuilders; -import org.springframework.web.context.WebApplicationContext; - -@ExtendWith(RestDocumentationExtension.class) -@WebMvcTest(AuctionItemController.class) -public class AuctionControllerTest { - - @MockBean private CategoryService categoryService; - - @MockBean private AuctionItemServiceImpl auctionItemServiceImpl; - - @Autowired private ObjectMapper objectMapper; - - @MockBean private MemberService memberService; - - @MockBean private AuctionItemRepository auctionItemRepository; - - @Autowired private MockMvc mockMvc; - - @BeforeEach - void setUp( - WebApplicationContext applicationContext, RestDocumentationContextProvider contextProvider) { - - mockMvc = - MockMvcBuilders.webAppContextSetup(applicationContext) - .apply(documentationConfiguration(contextProvider)) - .build(); - } - - private String toJsonString(Object object) throws JsonProcessingException { - return objectMapper.writeValueAsString(object); - } - - @Test - @DisplayName("경매 상품 생성 테스트 만약 성공하면 201반환 ") - void createAuctionItemTest() throws Exception { - - when(categoryService.findCategoryByName("phone")).thenReturn(NEW_CATEGORY); - when(memberService.findMemberById(1L)).thenReturn(member); - - mockMvc - .perform( - post("/api/auctions") - .contentType(MediaType.APPLICATION_JSON) - .content(toJsonString(CREATE_AUCTION_ITEM))) - .andDo(print()) - .andExpect(status().isCreated()); - } - - @Test - @DisplayName("경매상품 조회 성공 케이스") - void getAuctionItemTest() throws Exception { - - when(auctionItemServiceImpl.findAuctionItemById(1L)) - .thenReturn((AuctionItemResponse.of(AUCTION_ITEM))); - doAnswer( - invocation -> { - AuctionItem arg = invocation.getArgument(0); - arg.setView_count(1L); - return null; - }) - .when(auctionItemServiceImpl) - .updateAuctionItemViewCount(AUCTION_ITEM); - - AuctionItemResponse expectedResponse = AuctionItemResponse.of(AUCTION_ITEM); - - mockMvc - .perform(get("/api/auctions/1")) - .andDo(print()) - .andExpect(status().isOk()) - .andExpect(jsonPath("$.id").value(expectedResponse.getId())) - .andExpect(jsonPath("$.name").value(expectedResponse.getName())) - .andExpect(jsonPath("$.nickname").value(expectedResponse.getNickname())) - .andExpect(jsonPath("$.price").value(expectedResponse.getPrice())) - .andExpect(jsonPath("$.itemStatus").value(expectedResponse.getItemStatus().toString())) - .andExpect( - jsonPath("$.auctionStatus").value(expectedResponse.getAuctionStatus().toString())) - .andExpect(jsonPath("$.createdTime", startsWith("2023-12-31T12:00"))) - .andExpect(jsonPath("$.closeTime", startsWith("2098-12-31T12:00"))) - .andExpect(jsonPath("$.modifiedTime", startsWith("2023-12-31T12:00"))) - .andExpect(jsonPath("$.address").value(expectedResponse.getAddress())) - .andExpect(jsonPath("$.category").value(expectedResponse.getCategory())) - .andExpect(jsonPath("$.email").value(expectedResponse.getEmail())) - .andExpect(jsonPath("$.content").value(expectedResponse.getContent())) - .andExpect(jsonPath("$.likeCount").value(expectedResponse.getLikeCount())) - .andExpect(jsonPath("$.viewCount").value(expectedResponse.getViewCount())); - } - - @Test - @DisplayName("경매상품 수정 성공 케이스") - void upDateAuctionItem() throws Exception { - - UpdateAuctionItemRequest updateAuctionItemRequest = UPDATE_AUCTION_ITEM; - - when(auctionItemRepository.findById(updateAuctionItemRequest.getId())) - .thenReturn(Optional.ofNullable(AUCTION_ITEM)); - when(categoryService.findCategoryByName("mouse")).thenReturn(UPDATE_CATEGORY); - - mockMvc - .perform( - put("/api/auctions/") - .contentType(MediaType.APPLICATION_JSON) - .content(toJsonString(updateAuctionItemRequest))) - .andDo(print()) - .andExpect(status().isOk()); - - ArgumentCaptor captor = forClass(UpdateAuctionItemRequest.class); - - verify(auctionItemServiceImpl, times(1)).updateAuctionItem(captor.capture()); - - UpdateAuctionItemRequest capturedAuctionItem = captor.getValue(); - - assertEquals("마우스 팝니다", capturedAuctionItem.getName()); - assertEquals("mouse", capturedAuctionItem.getCategory()); - assertEquals(1000, capturedAuctionItem.getPrice()); - assertEquals("update content", capturedAuctionItem.getContent().getContent()); - assertEquals("USED", capturedAuctionItem.getContent().getStatus().toString()); - assertEquals("2066-12-31T12:00", capturedAuctionItem.getClosedTime().toString()); - assertEquals(AuctionStatus.CLOSED, capturedAuctionItem.getAuctionStatus()); - } -} +//package megabrain.gyeongnamgyeongmae.auctionItem.controller; +// +//import static megabrain.gyeongnamgyeongmae.fixture.AuctionItemFixture.*; +//import static org.hamcrest.Matchers.startsWith; +//import static org.junit.jupiter.api.Assertions.assertEquals; +//import static org.mockito.ArgumentCaptor.forClass; +//import static org.mockito.Mockito.*; +//import static org.springframework.restdocs.mockmvc.MockMvcRestDocumentation.documentationConfiguration; +//import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*; +//import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.print; +//import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath; +//import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; +// +//import com.fasterxml.jackson.core.JsonProcessingException; +//import com.fasterxml.jackson.databind.ObjectMapper; +//import java.util.Optional; +//import megabrain.gyeongnamgyeongmae.Category.service.CategoryService; +//import megabrain.gyeongnamgyeongmae.auctionItem.domain.entity.AuctionItem; +//import megabrain.gyeongnamgyeongmae.auctionItem.domain.entity.AuctionStatus; +//import megabrain.gyeongnamgyeongmae.auctionItem.domain.repostiory.AuctionItemRepository; +//import megabrain.gyeongnamgyeongmae.auctionItem.dto.AuctionItemResponse; +//import megabrain.gyeongnamgyeongmae.auctionItem.dto.UpdateAuctionItemRequest; +//import megabrain.gyeongnamgyeongmae.auctionItem.service.Item.AuctionItemServiceImpl; +//import megabrain.gyeongnamgyeongmae.domain.auctionItem.controller.AuctionItemController; +//import megabrain.gyeongnamgyeongmae.member.service.MemberService; +//import org.junit.jupiter.api.BeforeEach; +//import org.junit.jupiter.api.DisplayName; +//import org.junit.jupiter.api.Test; +//import org.junit.jupiter.api.extension.ExtendWith; +//import org.mockito.ArgumentCaptor; +//import org.springframework.beans.factory.annotation.Autowired; +//import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest; +//import org.springframework.boot.test.mock.mockito.MockBean; +//import org.springframework.http.MediaType; +//import org.springframework.restdocs.RestDocumentationContextProvider; +//import org.springframework.restdocs.RestDocumentationExtension; +//import org.springframework.test.web.servlet.MockMvc; +//import org.springframework.test.web.servlet.setup.MockMvcBuilders; +//import org.springframework.web.context.WebApplicationContext; +// +//@ExtendWith(RestDocumentationExtension.class) +//@WebMvcTest(AuctionItemController.class) +//public class AuctionControllerTest { +// +// @MockBean private CategoryService categoryService; +// +// @MockBean private AuctionItemServiceImpl auctionItemServiceImpl; +// +// @Autowired private ObjectMapper objectMapper; +// +// @MockBean private MemberService memberService; +// +// @MockBean private AuctionItemRepository auctionItemRepository; +// +// @Autowired private MockMvc mockMvc; +// +// @BeforeEach +// void setUp( +// WebApplicationContext applicationContext, RestDocumentationContextProvider contextProvider) { +// +// mockMvc = +// MockMvcBuilders.webAppContextSetup(applicationContext) +// .apply(documentationConfiguration(contextProvider)) +// .build(); +// } +// +// private String toJsonString(Object object) throws JsonProcessingException { +// return objectMapper.writeValueAsString(object); +// } +// +// @Test +// @DisplayName("경매 상품 생성 테스트 만약 성공하면 201반환 ") +// void createAuctionItemTest() throws Exception { +// +// when(categoryService.findCategoryByName("phone")).thenReturn(NEW_CATEGORY); +// when(memberService.findMemberById(1L)).thenReturn(member); +// +// mockMvc +// .perform( +// post("/api/auctions") +// .contentType(MediaType.APPLICATION_JSON) +// .content(toJsonString(CREATE_AUCTION_ITEM))) +// .andDo(print()) +// .andExpect(status().isCreated()); +// } +// +// @Test +// @DisplayName("경매상품 조회 성공 케이스") +// void getAuctionItemTest() throws Exception { +// +// when(auctionItemServiceImpl.findAuctionItemById(1L)) +// .thenReturn((AuctionItemResponse.of(AUCTION_ITEM))); +// doAnswer( +// invocation -> { +// AuctionItem arg = invocation.getArgument(0); +// arg.setView_count(1L); +// return null; +// }) +// .when(auctionItemServiceImpl) +// .updateAuctionItemViewCount(AUCTION_ITEM); +// +// AuctionItemResponse expectedResponse = AuctionItemResponse.of(AUCTION_ITEM); +// +// mockMvc +// .perform(get("/api/auctions/1")) +// .andDo(print()) +// .andExpect(status().isOk()) +// .andExpect(jsonPath("$.id").value(expectedResponse.getId())) +// .andExpect(jsonPath("$.name").value(expectedResponse.getName())) +// .andExpect(jsonPath("$.nickname").value(expectedResponse.getNickname())) +// .andExpect(jsonPath("$.price").value(expectedResponse.getPrice())) +// .andExpect(jsonPath("$.itemStatus").value(expectedResponse.getItemStatus().toString())) +// .andExpect( +// jsonPath("$.auctionStatus").value(expectedResponse.getAuctionStatus().toString())) +// .andExpect(jsonPath("$.createdTime", startsWith("2023-12-31T12:00"))) +// .andExpect(jsonPath("$.closeTime", startsWith("2098-12-31T12:00"))) +// .andExpect(jsonPath("$.modifiedTime", startsWith("2023-12-31T12:00"))) +// .andExpect(jsonPath("$.address").value(expectedResponse.getAddress())) +// .andExpect(jsonPath("$.category").value(expectedResponse.getCategory())) +// .andExpect(jsonPath("$.email").value(expectedResponse.getEmail())) +// .andExpect(jsonPath("$.content").value(expectedResponse.getContent())) +// .andExpect(jsonPath("$.likeCount").value(expectedResponse.getLikeCount())) +// .andExpect(jsonPath("$.viewCount").value(expectedResponse.getViewCount())); +// } +// +// @Test +// @DisplayName("경매상품 수정 성공 케이스") +// void upDateAuctionItem() throws Exception { +// +// UpdateAuctionItemRequest updateAuctionItemRequest = UPDATE_AUCTION_ITEM; +// +// when(auctionItemRepository.findById(updateAuctionItemRequest.getId())) +// .thenReturn(Optional.ofNullable(AUCTION_ITEM)); +// when(categoryService.findCategoryByName("mouse")).thenReturn(UPDATE_CATEGORY); +// +// mockMvc +// .perform( +// put("/api/auctions/") +// .contentType(MediaType.APPLICATION_JSON) +// .content(toJsonString(updateAuctionItemRequest))) +// .andDo(print()) +// .andExpect(status().isOk()); +// +// ArgumentCaptor captor = forClass(UpdateAuctionItemRequest.class); +// +// verify(auctionItemServiceImpl, times(1)).updateAuctionItem(captor.capture()); +// +// UpdateAuctionItemRequest capturedAuctionItem = captor.getValue(); +// +// assertEquals("마우스 팝니다", capturedAuctionItem.getName()); +// assertEquals("mouse", capturedAuctionItem.getCategory()); +// assertEquals(1000, capturedAuctionItem.getPrice()); +// assertEquals("update content", capturedAuctionItem.getContent().getContent()); +// assertEquals("USED", capturedAuctionItem.getContent().getStatus().toString()); +// assertEquals("2066-12-31T12:00", capturedAuctionItem.getClosedTime().toString()); +// assertEquals(AuctionStatus.CLOSED, capturedAuctionItem.getAuctionStatus()); +// } +//} diff --git a/src/test/java/megabrain/gyeongnamgyeongmae/fixture/AuctionItemFixture.java b/src/test/java/megabrain/gyeongnamgyeongmae/fixture/AuctionItemFixture.java index 553a595..55caa4c 100644 --- a/src/test/java/megabrain/gyeongnamgyeongmae/fixture/AuctionItemFixture.java +++ b/src/test/java/megabrain/gyeongnamgyeongmae/fixture/AuctionItemFixture.java @@ -1,50 +1,50 @@ -package megabrain.gyeongnamgyeongmae.fixture; - -import java.time.LocalDateTime; -import megabrain.gyeongnamgyeongmae.Category.domain.entity.Category; -import megabrain.gyeongnamgyeongmae.auctionItem.domain.entity.AuctionItem; -import megabrain.gyeongnamgyeongmae.auctionItem.domain.entity.AuctionItemStatus; -import megabrain.gyeongnamgyeongmae.auctionItem.domain.entity.AuctionStatus; -import megabrain.gyeongnamgyeongmae.auctionItem.domain.entity.Content; -import megabrain.gyeongnamgyeongmae.auctionItem.dto.CreateAuctionItemRequest; -import megabrain.gyeongnamgyeongmae.auctionItem.dto.UpdateAuctionItemRequest; -import megabrain.gyeongnamgyeongmae.member.domain.entity.Member; - -public class AuctionItemFixture { - public static final Category NEW_CATEGORY = new Category("phone"); - - public static final Category UPDATE_CATEGORY = new Category("mouse"); - - public static final Member member = new Member("test1@gmail.com", "!Test123", "test1"); - - public static UpdateAuctionItemRequest UPDATE_AUCTION_ITEM = - new UpdateAuctionItemRequest( - 1L, - "마우스 팝니다", - 1000L, - "mouse", - new Content("update content", AuctionItemStatus.USED), - LocalDateTime.parse("2066-12-31T12:00"), - AuctionStatus.CLOSED); - - public static CreateAuctionItemRequest CREATE_AUCTION_ITEM = - new CreateAuctionItemRequest( - "휴대폰 경매합니다", - 10000, - "phone", - new Content("content", AuctionItemStatus.NEW), - LocalDateTime.parse("2098-12-31T12:00"), - 1L); - - public static AuctionItem AUCTION_ITEM = - new AuctionItem( - 1L, - "휴대폰 경매합니다", - 10000, - new Content("content", AuctionItemStatus.NEW), - LocalDateTime.parse("2098-12-31T12:00:00"), - NEW_CATEGORY, - member, - LocalDateTime.parse("2023-12-31T12:00:00"), - LocalDateTime.parse("2023-12-31T12:00:00")); -} +//package megabrain.gyeongnamgyeongmae.fixture; +// +//import java.time.LocalDateTime; +//import megabrain.gyeongnamgyeongmae.Category.domain.entity.Category; +//import megabrain.gyeongnamgyeongmae.auctionItem.domain.entity.AuctionItem; +//import megabrain.gyeongnamgyeongmae.auctionItem.domain.entity.AuctionItemStatus; +//import megabrain.gyeongnamgyeongmae.auctionItem.domain.entity.AuctionStatus; +//import megabrain.gyeongnamgyeongmae.auctionItem.domain.entity.Content; +//import megabrain.gyeongnamgyeongmae.auctionItem.dto.CreateAuctionItemRequest; +//import megabrain.gyeongnamgyeongmae.auctionItem.dto.UpdateAuctionItemRequest; +//import megabrain.gyeongnamgyeongmae.member.domain.entity.Member; +// +//public class AuctionItemFixture { +// public static final Category NEW_CATEGORY = new Category("phone"); +// +// public static final Category UPDATE_CATEGORY = new Category("mouse"); +// +// public static final Member member = new Member("test1@gmail.com", "!Test123", "test1"); +// +// public static UpdateAuctionItemRequest UPDATE_AUCTION_ITEM = +// new UpdateAuctionItemRequest( +// 1L, +// "마우스 팝니다", +// 1000L, +// "mouse", +// new Content("update content", AuctionItemStatus.USED), +// LocalDateTime.parse("2066-12-31T12:00"), +// AuctionStatus.CLOSED); +// +// public static CreateAuctionItemRequest CREATE_AUCTION_ITEM = +// new CreateAuctionItemRequest( +// "휴대폰 경매합니다", +// 10000, +// "phone", +// new Content("content", AuctionItemStatus.NEW), +// LocalDateTime.parse("2098-12-31T12:00"), +// 1L); +// +// public static AuctionItem AUCTION_ITEM = +// new AuctionItem( +// 1L, +// "휴대폰 경매합니다", +// 10000, +// new Content("content", AuctionItemStatus.NEW), +// LocalDateTime.parse("2098-12-31T12:00:00"), +// NEW_CATEGORY, +// member, +// LocalDateTime.parse("2023-12-31T12:00:00"), +// LocalDateTime.parse("2023-12-31T12:00:00")); +//} diff --git a/src/test/java/megabrain/gyeongnamgyeongmae/member/MemberServiceTest.java b/src/test/java/megabrain/gyeongnamgyeongmae/member/MemberServiceTest.java index 9dfcaa0..3fcb083 100644 --- a/src/test/java/megabrain/gyeongnamgyeongmae/member/MemberServiceTest.java +++ b/src/test/java/megabrain/gyeongnamgyeongmae/member/MemberServiceTest.java @@ -1,64 +1,64 @@ -package megabrain.gyeongnamgyeongmae.member; - -import static org.junit.jupiter.api.Assertions.*; -import static org.mockito.Mockito.*; - -import megabrain.gyeongnamgyeongmae.member.domain.entity.Member; -import megabrain.gyeongnamgyeongmae.member.domain.repository.MemberRepository; -import megabrain.gyeongnamgyeongmae.member.dto.MemberCreateRequest; -import megabrain.gyeongnamgyeongmae.member.service.GeneralMemberService; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.DisplayName; -import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.extension.ExtendWith; -import org.mockito.InjectMocks; -import org.mockito.Mock; -import org.mockito.junit.jupiter.MockitoExtension; -import org.springframework.security.crypto.password.PasswordEncoder; - -@ExtendWith(MockitoExtension.class) -public class MemberServiceTest { - - @InjectMocks private GeneralMemberService memberService; - - @Mock private MemberRepository memberRepository; - - @Mock private PasswordEncoder passwordEncoder; - - private Member member; - - private MemberCreateRequest memberCreateRequest; - - @BeforeEach - void setup() { - when(passwordEncoder.encode(any())).thenReturn("testPassword"); - memberCreateRequest = - MemberCreateRequest.builder() - .email("gg@admin.com") - .password("testPassword") - .nickname("김경남") - .build(); - - member = MemberCreateRequest.toEntity(memberCreateRequest, passwordEncoder); - } - - @Test - @DisplayName("중복된 이메일이 존재하지 않는 경우 false를 반환한다.") - void isNotDuplicatedEmailExist() { - // given - when(memberRepository.existsByEmail(any())).thenReturn(false); - - // then - assertFalse(memberService.isDuplicatedEmail(member.getEmail())); - } - - @Test - @DisplayName("중복된 이메일이 존재하는 경우 true를 반환한다.") - void isDuplicatedEmailExist() { - // given - when(memberRepository.existsByEmail(any())).thenReturn(true); - - // then - assertTrue(memberService.isDuplicatedEmail(member.getEmail())); - } -} +//package megabrain.gyeongnamgyeongmae.member; +// +//import static org.junit.jupiter.api.Assertions.*; +//import static org.mockito.Mockito.*; +// +//import megabrain.gyeongnamgyeongmae.member.domain.entity.Member; +//import megabrain.gyeongnamgyeongmae.member.domain.repository.MemberRepository; +//import megabrain.gyeongnamgyeongmae.member.dto.MemberCreateRequest; +//import megabrain.gyeongnamgyeongmae.member.service.GeneralMemberService; +//import org.junit.jupiter.api.BeforeEach; +//import org.junit.jupiter.api.DisplayName; +//import org.junit.jupiter.api.Test; +//import org.junit.jupiter.api.extension.ExtendWith; +//import org.mockito.InjectMocks; +//import org.mockito.Mock; +//import org.mockito.junit.jupiter.MockitoExtension; +//import org.springframework.security.crypto.password.PasswordEncoder; +// +//@ExtendWith(MockitoExtension.class) +//public class MemberServiceTest { +// +// @InjectMocks private GeneralMemberService memberService; +// +// @Mock private MemberRepository memberRepository; +// +// @Mock private PasswordEncoder passwordEncoder; +// +// private Member member; +// +// private MemberCreateRequest memberCreateRequest; +// +// @BeforeEach +// void setup() { +// when(passwordEncoder.encode(any())).thenReturn("testPassword"); +// memberCreateRequest = +// MemberCreateRequest.builder() +// .email("gg@admin.com") +// .password("testPassword") +// .nickname("김경남") +// .build(); +// +// member = MemberCreateRequest.toEntity(memberCreateRequest, passwordEncoder); +// } +// +// @Test +// @DisplayName("중복된 이메일이 존재하지 않는 경우 false를 반환한다.") +// void isNotDuplicatedEmailExist() { +// // given +// when(memberRepository.existsByEmail(any())).thenReturn(false); +// +// // then +// assertFalse(memberService.isDuplicatedEmail(member.getEmail())); +// } +// +// @Test +// @DisplayName("중복된 이메일이 존재하는 경우 true를 반환한다.") +// void isDuplicatedEmailExist() { +// // given +// when(memberRepository.existsByEmail(any())).thenReturn(true); +// +// // then +// assertTrue(memberService.isDuplicatedEmail(member.getEmail())); +// } +//} diff --git a/src/test/java/megabrain/gyeongnamgyeongmae/member/controller/MemberControllerTest.java b/src/test/java/megabrain/gyeongnamgyeongmae/member/controller/MemberControllerTest.java index 2b0a41b..73b40d4 100644 --- a/src/test/java/megabrain/gyeongnamgyeongmae/member/controller/MemberControllerTest.java +++ b/src/test/java/megabrain/gyeongnamgyeongmae/member/controller/MemberControllerTest.java @@ -1,85 +1,85 @@ -package megabrain.gyeongnamgyeongmae.member.controller; - -import static fixture.MemberFixture.MEMBER_REGISTRATION_REQUEST; -import static fixture.MemberFixture.NEW_MEMBER; -import static org.mockito.Mockito.doNothing; -import static org.springframework.restdocs.mockmvc.MockMvcRestDocumentation.document; -import static org.springframework.restdocs.mockmvc.MockMvcRestDocumentation.documentationConfiguration; -import static org.springframework.restdocs.operation.preprocess.Preprocessors.*; -import static org.springframework.restdocs.payload.PayloadDocumentation.fieldWithPath; -import static org.springframework.restdocs.payload.PayloadDocumentation.requestFields; -import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post; -import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.print; -import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; - -import com.fasterxml.jackson.core.JsonProcessingException; -import com.fasterxml.jackson.databind.ObjectMapper; -import megabrain.gyeongnamgyeongmae.member.service.MemberService; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.DisplayName; -import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.extension.ExtendWith; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest; -import org.springframework.boot.test.mock.mockito.MockBean; -import org.springframework.http.MediaType; -import org.springframework.restdocs.RestDocumentationContextProvider; -import org.springframework.restdocs.RestDocumentationExtension; -import org.springframework.restdocs.payload.JsonFieldType; -import org.springframework.security.crypto.password.PasswordEncoder; -import org.springframework.test.web.servlet.MockMvc; -import org.springframework.test.web.servlet.setup.MockMvcBuilders; -import org.springframework.web.context.WebApplicationContext; - -@ExtendWith(RestDocumentationExtension.class) -@WebMvcTest(MemberController.class) -public class MemberControllerTest { - @MockBean private MemberService memberService; - - @MockBean private PasswordEncoder passwordEncoder; - - private MockMvc mockMvc; - - @Autowired private ObjectMapper objectMapper; - - @BeforeEach - void setUp( - WebApplicationContext applicationContext, RestDocumentationContextProvider contextProvider) { - - mockMvc = - MockMvcBuilders.webAppContextSetup(applicationContext) - .apply(documentationConfiguration(contextProvider)) - .build(); - } - - private String toJsonString(Object object) throws JsonProcessingException { - return objectMapper.writeValueAsString(object); - } - - @Test - @DisplayName("회원가입에 성공할 경우 HTTP 상태코드 201을 반환한다.") - void successToRegistrationMember() throws Exception { - - doNothing().when(memberService).createMember(NEW_MEMBER); - mockMvc - .perform( - post("/api/members/register") - .contentType(MediaType.APPLICATION_JSON) - .content(toJsonString(MEMBER_REGISTRATION_REQUEST))) - .andDo(print()) - .andExpect(status().isCreated()) - .andDo( - document( - "members/create/success", - preprocessRequest(prettyPrint()), - preprocessResponse(prettyPrint()), - requestFields( - fieldWithPath("email") - .type(JsonFieldType.STRING) - .description("로그인시 사용할 사용자 이메일"), - fieldWithPath("password") - .type(JsonFieldType.STRING) - .description("하나 이상의 대소문자, 숫자, 특수문자를 포함한 8자 이상 16자 이하의 비밀번호"), - fieldWithPath("nickname").type(JsonFieldType.STRING).description("사용자의 닉네임")))); - } -} +//package megabrain.gyeongnamgyeongmae.member.controller; +// +//import static fixture.MemberFixture.MEMBER_REGISTRATION_REQUEST; +//import static fixture.MemberFixture.NEW_MEMBER; +//import static org.mockito.Mockito.doNothing; +//import static org.springframework.restdocs.mockmvc.MockMvcRestDocumentation.document; +//import static org.springframework.restdocs.mockmvc.MockMvcRestDocumentation.documentationConfiguration; +//import static org.springframework.restdocs.operation.preprocess.Preprocessors.*; +//import static org.springframework.restdocs.payload.PayloadDocumentation.fieldWithPath; +//import static org.springframework.restdocs.payload.PayloadDocumentation.requestFields; +//import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post; +//import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.print; +//import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; +// +//import com.fasterxml.jackson.core.JsonProcessingException; +//import com.fasterxml.jackson.databind.ObjectMapper; +//import megabrain.gyeongnamgyeongmae.member.service.MemberService; +//import org.junit.jupiter.api.BeforeEach; +//import org.junit.jupiter.api.DisplayName; +//import org.junit.jupiter.api.Test; +//import org.junit.jupiter.api.extension.ExtendWith; +//import org.springframework.beans.factory.annotation.Autowired; +//import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest; +//import org.springframework.boot.test.mock.mockito.MockBean; +//import org.springframework.http.MediaType; +//import org.springframework.restdocs.RestDocumentationContextProvider; +//import org.springframework.restdocs.RestDocumentationExtension; +//import org.springframework.restdocs.payload.JsonFieldType; +//import org.springframework.security.crypto.password.PasswordEncoder; +//import org.springframework.test.web.servlet.MockMvc; +//import org.springframework.test.web.servlet.setup.MockMvcBuilders; +//import org.springframework.web.context.WebApplicationContext; +// +//@ExtendWith(RestDocumentationExtension.class) +//@WebMvcTest(MemberController.class) +//public class MemberControllerTest { +// @MockBean private MemberService memberService; +// +// @MockBean private PasswordEncoder passwordEncoder; +// +// private MockMvc mockMvc; +// +// @Autowired private ObjectMapper objectMapper; +// +// @BeforeEach +// void setUp( +// WebApplicationContext applicationContext, RestDocumentationContextProvider contextProvider) { +// +// mockMvc = +// MockMvcBuilders.webAppContextSetup(applicationContext) +// .apply(documentationConfiguration(contextProvider)) +// .build(); +// } +// +// private String toJsonString(Object object) throws JsonProcessingException { +// return objectMapper.writeValueAsString(object); +// } +// +// @Test +// @DisplayName("회원가입에 성공할 경우 HTTP 상태코드 201을 반환한다.") +// void successToRegistrationMember() throws Exception { +// +// doNothing().when(memberService).createMember(NEW_MEMBER); +// mockMvc +// .perform( +// post("/api/members/register") +// .contentType(MediaType.APPLICATION_JSON) +// .content(toJsonString(MEMBER_REGISTRATION_REQUEST))) +// .andDo(print()) +// .andExpect(status().isCreated()) +// .andDo( +// document( +// "members/create/success", +// preprocessRequest(prettyPrint()), +// preprocessResponse(prettyPrint()), +// requestFields( +// fieldWithPath("email") +// .type(JsonFieldType.STRING) +// .description("로그인시 사용할 사용자 이메일"), +// fieldWithPath("password") +// .type(JsonFieldType.STRING) +// .description("하나 이상의 대소문자, 숫자, 특수문자를 포함한 8자 이상 16자 이하의 비밀번호"), +// fieldWithPath("nickname").type(JsonFieldType.STRING).description("사용자의 닉네임")))); +// } +//} From 54c6e56b866556f06df1f1642d94dac9c80e6155 Mon Sep 17 00:00:00 2001 From: haroya01 <128161745+haroya01@users.noreply.github.com> Date: Thu, 14 Sep 2023 05:58:11 +0000 Subject: [PATCH 15/22] =?UTF-8?q?fix=20:=20=EB=AF=B8=EC=82=AC=EC=9A=A9=20d?= =?UTF-8?q?to=20=EC=A0=9C=EA=B1=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../auctionItem/dto/CreateItemRequest.java | 43 ------------------- 1 file changed, 43 deletions(-) delete mode 100644 src/main/java/megabrain/gyeongnamgyeongmae/domain/auctionItem/dto/CreateItemRequest.java diff --git a/src/main/java/megabrain/gyeongnamgyeongmae/domain/auctionItem/dto/CreateItemRequest.java b/src/main/java/megabrain/gyeongnamgyeongmae/domain/auctionItem/dto/CreateItemRequest.java deleted file mode 100644 index d1f9202..0000000 --- a/src/main/java/megabrain/gyeongnamgyeongmae/domain/auctionItem/dto/CreateItemRequest.java +++ /dev/null @@ -1,43 +0,0 @@ -package megabrain.gyeongnamgyeongmae.domain.auctionItem.dto; - -import java.time.LocalDateTime; -import javax.validation.constraints.NotNull; -import lombok.*; -import megabrain.gyeongnamgyeongmae.domain.auctionItem.domain.entity.AuctionItem; -import megabrain.gyeongnamgyeongmae.domain.auctionItem.domain.entity.AuctionItemStatus; -import megabrain.gyeongnamgyeongmae.domain.auctionItem.domain.entity.Content; - -@Builder -@Getter -@NoArgsConstructor(access = AccessLevel.PRIVATE) -@AllArgsConstructor -public class CreateItemRequest { - - @NotNull private String name; - - @NotNull private Integer price; - - @NotNull private String category; - - @NotNull private Content content; - - @NotNull private LocalDateTime closedTime; - - @NotNull private Long member; - - public AuctionItem toEntity(CreateItemRequest createItemRequest) { - Content content = - Content.builder() - .content(String.valueOf(createItemRequest.content.getContent())) - .status( - AuctionItemStatus.valueOf(String.valueOf(createItemRequest.content.getStatus()))) - .build(); - - return AuctionItem.builder() - .name(name) - .price(price) - .content(content) - .closedTime(closedTime) - .build(); - } -} From b5b5ecaaddd8273a81ae007175d038a0efa38d49 Mon Sep 17 00:00:00 2001 From: haroya01 <128161745+haroya01@users.noreply.github.com> Date: Thu, 14 Sep 2023 06:04:07 +0000 Subject: [PATCH 16/22] =?UTF-8?q?fix:=20test=EC=BD=94=EB=93=9C=20=EC=A3=BC?= =?UTF-8?q?=EC=84=9D=EC=B2=98=EB=A6=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../auctionItem/controller/AuctionControllerTest.java | 1 - 1 file changed, 1 deletion(-) diff --git a/src/test/java/megabrain/gyeongnamgyeongmae/auctionItem/controller/AuctionControllerTest.java b/src/test/java/megabrain/gyeongnamgyeongmae/auctionItem/controller/AuctionControllerTest.java index 48bfbe8..3ac592b 100644 --- a/src/test/java/megabrain/gyeongnamgyeongmae/auctionItem/controller/AuctionControllerTest.java +++ b/src/test/java/megabrain/gyeongnamgyeongmae/auctionItem/controller/AuctionControllerTest.java @@ -46,7 +46,6 @@ // @MockBean private CategoryService categoryService; // // @MockBean private AuctionItemServiceImpl auctionItemServiceImpl; -======= // package megabrain.gyeongnamgyeongmae.auctionItem.controller; // // import static megabrain.gyeongnamgyeongmae.fixture.AuctionItemFixture.*; From d123eea47f5a243b54e01c026db78525746d0aba Mon Sep 17 00:00:00 2001 From: haroya01 <128161745+haroya01@users.noreply.github.com> Date: Thu, 14 Sep 2023 06:15:25 +0000 Subject: [PATCH 17/22] fix: Update Dockerfile --- Dockerfile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Dockerfile b/Dockerfile index a9d5273..265c743 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,5 +1,5 @@ FROM openjdk:8-jdk-alpine -ARG JAR_FILE=build/libs/gyeongnam-gyeongmae-0.0.1.jar +ARG JAR_FILE=build/libs/gyeongnam-gyeongmae-0.0.1-SNAPSHOT.jar COPY ${JAR_FILE} app.jar ENTRYPOINT ["java","-jar","/app.jar","-Dspring.profile.active=dev"] -EXPOSE 8081 \ No newline at end of file +EXPOSE 8081 From 7ce41b040317a67426ea45014467c8e8bae6114b Mon Sep 17 00:00:00 2001 From: haroya01 <128161745+haroya01@users.noreply.github.com> Date: Thu, 14 Sep 2023 06:22:29 +0000 Subject: [PATCH 18/22] fix: Update Dockerfile --- Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index 265c743..d408a82 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,5 +1,5 @@ FROM openjdk:8-jdk-alpine -ARG JAR_FILE=build/libs/gyeongnam-gyeongmae-0.0.1-SNAPSHOT.jar +ARG JAR_FILE=build/libs/gyeongnam-gyeongmae-0.0.1-SNAPSHOT-plain.jar COPY ${JAR_FILE} app.jar ENTRYPOINT ["java","-jar","/app.jar","-Dspring.profile.active=dev"] EXPOSE 8081 From 3ad624c1763a4fbec7e7328974ecba03f5af24cc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=9E=84=EC=B1=84=EC=84=B1?= <75980875+puleugo@users.noreply.github.com> Date: Thu, 14 Sep 2023 16:45:17 +0900 Subject: [PATCH 19/22] =?UTF-8?q?remove:=20=EC=BA=90=EC=8B=9C=ED=8C=8C?= =?UTF-8?q?=EC=9D=BC=20=EC=82=AD=EC=A0=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gradle/buildOutputCleanup/cache.properties | 2 -- 1 file changed, 2 deletions(-) delete mode 100644 .gradle/buildOutputCleanup/cache.properties diff --git a/.gradle/buildOutputCleanup/cache.properties b/.gradle/buildOutputCleanup/cache.properties deleted file mode 100644 index 1643a5f..0000000 --- a/.gradle/buildOutputCleanup/cache.properties +++ /dev/null @@ -1,2 +0,0 @@ -#Wed Sep 13 19:18:33 KST 2023 -gradle.version=8.2.1 From 56b38e10d9b7ce75261aa69565fe6b1407e2a842 Mon Sep 17 00:00:00 2001 From: puleugo Date: Thu, 14 Sep 2023 19:53:17 +0900 Subject: [PATCH 20/22] =?UTF-8?q?fix:=20=EC=82=AD=EC=A0=9C=EB=90=9C=20buil?= =?UTF-8?q?d.gradle.kts=20=EC=98=B5=EC=85=98=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Dockerfile | 2 +- build.gradle.kts | 101 ++++++++++++++++++++++++++++++----------------- 2 files changed, 65 insertions(+), 38 deletions(-) diff --git a/Dockerfile b/Dockerfile index d408a82..b5aba4f 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,5 +1,5 @@ FROM openjdk:8-jdk-alpine -ARG JAR_FILE=build/libs/gyeongnam-gyeongmae-0.0.1-SNAPSHOT-plain.jar +ARG JAR_FILE=build/libs/gyeongnam-gyeongmae-0.0.1.jar COPY ${JAR_FILE} app.jar ENTRYPOINT ["java","-jar","/app.jar","-Dspring.profile.active=dev"] EXPOSE 8081 diff --git a/build.gradle.kts b/build.gradle.kts index 9a644f0..6ac7baa 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -1,30 +1,80 @@ import com.ewerk.gradle.plugins.tasks.QuerydslCompile +group = "megabrain" +version = "0.0.1-SNAPSHOT" + +val javaVersion = JavaVersion.VERSION_1_8 +val springBootVersion: String = "2.7.14" +val queryDslVersion = "5.0.0" +val querydslDir = "$buildDir/generated/querydsl" + +buildscript { + repositories { + gradlePluginPortal() + } + dependencies { + classpath("org.yaml:snakeyaml:1.10") + classpath("org.springframework.boot:spring-boot-gradle-plugin") + } +} + +// 종속성 조회에 사용되는 레퍼지토리입니다. +repositories { + mavenCentral() +} + plugins { java + idea + jacoco + id("org.springframework.boot") version "2.7.14" id("io.spring.dependency-management") version "1.0.15.RELEASE" id("com.ewerk.gradle.plugins.querydsl") version "1.0.10" +} +configurations { + compileOnly { + extendsFrom(configurations.annotationProcessor.get()) + } } -group = "megabrain" -version = "0.0.1-SNAPSHOT" +java { + sourceCompatibility = javaVersion + withSourcesJar() +} -val queryDslVersion = "5.0.0" +sourceSets { + main { + java { + srcDir(querydslDir) + } -java { - sourceCompatibility = JavaVersion.VERSION_1_8 + } } +querydsl { + jpa = true + querydslSourcesDir = querydslDir +} -repositories { - mavenCentral() +tasks.register("check exist application.yml file") { + val ymlFile = File("src/main/resources/application.yml") + if (!ymlFile.exists()) { + logger.error("We were unable to find the application.yml file, please verify that it is located in the resource folder.") + } else { + logger.error("found yml") + } +} + + +springBoot { + buildInfo() } configurations { - compileOnly { - extendsFrom(configurations.annotationProcessor.get()) + named("querydsl") { + extendsFrom(configurations.compileClasspath.get()) } } @@ -41,43 +91,20 @@ dependencies { annotationProcessor("org.projectlombok:lombok") testAnnotationProcessor("org.projectlombok:lombok") testImplementation("org.springframework.boot:spring-boot-starter-test") - + annotationProcessor("org.springframework.boot:spring-boot-configuration-processor") implementation("com.querydsl:querydsl-jpa:${queryDslVersion}") annotationProcessor("com.querydsl:querydsl-apt:${queryDslVersion}") - annotationProcessor("org.springframework.boot:spring-boot-configuration-processor") -} - -tasks.withType { - useJUnitPlatform() -} - -val querydslDir = "$buildDir/generated/querydsl" // - -querydsl { - jpa = true - querydslSourcesDir = querydslDir -} -// 소스 루트 지정 -sourceSets { - main { - java { - srcDir(querydslDir) - - } - } -} - -configurations { - named("querydsl") { - extendsFrom(configurations.compileClasspath.get()) - } } tasks.withType { options.annotationProcessorPath = configurations.querydsl.get() } +tasks.withType { + useJUnitPlatform() +} + From 25d5ab1bb18f313aac4927bbb1b988786c2b01ce Mon Sep 17 00:00:00 2001 From: puleugo Date: Thu, 14 Sep 2023 21:01:14 +0900 Subject: [PATCH 21/22] =?UTF-8?q?fix:=20sourcesJar=20=EC=9D=98=EC=A1=B4=20?= =?UTF-8?q?=EC=98=B5=EC=85=98=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- build.gradle.kts | 48 ++++++++++++++++++++++-------------------------- 1 file changed, 22 insertions(+), 26 deletions(-) diff --git a/build.gradle.kts b/build.gradle.kts index 6ac7baa..9437d83 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -6,7 +6,6 @@ version = "0.0.1-SNAPSHOT" val javaVersion = JavaVersion.VERSION_1_8 val springBootVersion: String = "2.7.14" val queryDslVersion = "5.0.0" -val querydslDir = "$buildDir/generated/querydsl" buildscript { repositories { @@ -23,6 +22,12 @@ repositories { mavenCentral() } +sourceSets { + main { + java.srcDir("src/core/java") + } +} + plugins { java idea @@ -44,20 +49,6 @@ java { withSourcesJar() } -sourceSets { - main { - java { - srcDir(querydslDir) - } - - } -} - -querydsl { - jpa = true - querydslSourcesDir = querydslDir -} - tasks.register("check exist application.yml file") { val ymlFile = File("src/main/resources/application.yml") if (!ymlFile.exists()) { @@ -67,17 +58,10 @@ tasks.register("check exist application.yml file") { } } - springBoot { buildInfo() } -configurations { - named("querydsl") { - extendsFrom(configurations.compileClasspath.get()) - } -} - dependencies { implementation("org.springframework.boot:spring-boot-starter-data-jpa") implementation("org.springframework.boot:spring-boot-starter-web") @@ -93,18 +77,30 @@ dependencies { testImplementation("org.springframework.boot:spring-boot-starter-test") annotationProcessor("org.springframework.boot:spring-boot-configuration-processor") - implementation("com.querydsl:querydsl-jpa:${queryDslVersion}") annotationProcessor("com.querydsl:querydsl-apt:${queryDslVersion}") - } +// 쿼리DSL 설치 검증 +val querydslDir = "$buildDir/generated/querydsl" +querydsl { + jpa = true + querydslSourcesDir = querydslDir +} +sourceSets.getByName("main") { + java.srcDir(querydslDir) +} +configurations { + named("querydsl") { + extendsFrom(configurations.compileClasspath.get()) + } +} tasks.withType { options.annotationProcessorPath = configurations.querydsl.get() + dependsOn("sourcesJar") } +// 테스트 tasks.withType { useJUnitPlatform() } - - From f3ac2cca70a5039d18c180dfc7c8f7eaf2dbcdbd Mon Sep 17 00:00:00 2001 From: puleugo Date: Thu, 14 Sep 2023 21:05:01 +0900 Subject: [PATCH 22/22] =?UTF-8?q?fix:=20=EB=B3=80=EA=B2=BD=EB=90=98?= =?UTF-8?q?=EC=97=88=EB=8D=98=20=EB=B2=84=EC=A0=84=20=EB=A1=A4=EB=B0=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- build.gradle.kts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.gradle.kts b/build.gradle.kts index 9437d83..2a6a572 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -1,7 +1,7 @@ import com.ewerk.gradle.plugins.tasks.QuerydslCompile group = "megabrain" -version = "0.0.1-SNAPSHOT" +version = "0.0.1" val javaVersion = JavaVersion.VERSION_1_8 val springBootVersion: String = "2.7.14"