Skip to content

Commit

Permalink
refactor: AuctionItem검색 정렬 기준 수정
Browse files Browse the repository at this point in the history
  • Loading branch information
haroya01 committed Sep 22, 2023
1 parent eaf7149 commit b8e541f
Show file tree
Hide file tree
Showing 5 changed files with 74 additions and 50 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,11 @@ public AuctionItemSearchResponse searchAuctionItemPage(SearchAuctionItemSortedRe
BooleanBuilder categoryStatus = new BooleanBuilder();

searchAuctionItemSortedRequest.applySearchCategory(categoryStatus, auctionItem);
searchAuctionItemSortedRequest.applySearchStatus(statusBuilder, auctionItem);
// searchAuctionItemSortedRequest.applySearchStatus(statusBuilder, auctionItem);
searchAuctionItemSortedRequest.applyKeyWordStatus(keywordStatus, auctionItem);
searchAuctionItemSortedRequest.applySearchPrice(orderSpecifiers, auctionItem);
searchAuctionItemSortedRequest.applySearchLike(orderSpecifiers, auctionItem);
searchAuctionItemSortedRequest.applySearchView(orderSpecifiers, auctionItem);
// searchAuctionItemSortedRequest.applySearchLike(orderSpecifiers, auctionItem);
// searchAuctionItemSortedRequest.applySearchView(orderSpecifiers, auctionItem);
searchAuctionItemSortedRequest.applySearchTime(orderSpecifiers, auctionItem);
searchAuctionItemSortedRequest.applySearchClosed(sellBuilder, auctionItem);

Expand All @@ -56,8 +56,8 @@ public AuctionItemSearchResponse searchAuctionItemPage(SearchAuctionItemSortedRe
.where(auctionItem.removed.eq(false),
categoryStatus,
statusBuilder,
sellBuilder,
keywordStatus);
keywordStatus,
sellBuilder);

Long page = searchAuctionItemSortedRequest.getPage();
int itemsPerPage = 10;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package megabrain.gyeongnamgyeongmae.domain.auctionItem.dto;

import java.time.LocalDateTime;
import java.util.Optional;

import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;
Expand All @@ -24,7 +26,7 @@ public class AuctionItemFirstView {

private LocalDateTime closedTime;

private AuctionItemStatus auctionItemStatus;
// private AuctionItemStatus auctionItemStatus;

private AuctionStatus status;

Expand All @@ -51,10 +53,10 @@ public static AuctionItemFirstView of(AuctionItem auctionItem, Image image) {
.view_count(auctionItem.getView_count())
.price(auctionItem.getPrice())
.closedTime(auctionItem.getClosedTime())
.auctionItemStatus(auctionItem.getItemStatus())
// .auctionItemStatus(auctionItem.getItemStatus())
.status(auctionItem.getStatus())
.now_price(20000L)
.image_url(image.getImageUrl())
.image_url(Optional.ofNullable(image).map(Image::getImageUrl).orElse(null))
.build();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public class CreateAuctionItemRequest {

@NotNull private String content;

@NotNull private AuctionItemStatus status;
// @NotNull private AuctionItemStatus status;

@NotNull private LocalDateTime closedTime;

Expand All @@ -34,7 +34,7 @@ public AuctionItem toEntity() {
.name(this.name)
.price(this.price)
.content(this.content)
.itemStatus(this.status)
// .itemStatus(this.status)
.closedTime(this.closedTime)
.build();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,30 @@

@Data
public class SearchAuctionItemSortedRequest {

@NotEmpty
private String keyword = null;

@NotEmpty
private String category = null;
private SearchStatus search_status;

// @NotEmpty
// private SearchStatus search_status;

@NotEmpty
private Boolean closed;

@NotEmpty
private Boolean search_time;
private Boolean like;

// @NotEmpty
// private Boolean like;

@NotEmpty
private Boolean search_price;
private Boolean view_count;

// @NotEmpty
// private Boolean view_count;

@NotEmpty
private Long page;
Expand All @@ -39,15 +55,15 @@ public void applySearchCategory(BooleanBuilder status, QAuctionItem item) {
}
}

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(AuctionItemStatus.NEW, AuctionItemStatus.USED));
}
}
// 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(AuctionItemStatus.NEW, AuctionItemStatus.USED));
// }
// }

public void applySearchPrice(List<OrderSpecifier<?>> order, QAuctionItem item) {
if (this.search_price) {
Expand All @@ -57,27 +73,27 @@ public void applySearchPrice(List<OrderSpecifier<?>> order, QAuctionItem item) {
}
}

public void applySearchLike(List<OrderSpecifier<?>> order, QAuctionItem item) {
if (this.like) {
order.add(item.like_count.desc());
} else {
order.add(item.like_count.asc());
}
}

public void applySearchView(List<OrderSpecifier<?>> order, QAuctionItem item) {
if (this.view_count) {
order.add(item.view_count.desc());
} else {
order.add(item.view_count.asc());
}
}
// public void applySearchLike(List<OrderSpecifier<?>> order, QAuctionItem item) {
// if (this.like) {
// order.add(item.like_count.desc());
// } else {
// order.add(item.like_count.asc());
// }
// }

// public void applySearchView(List<OrderSpecifier<?>> order, QAuctionItem item) {
// if (this.view_count) {
// order.add(item.view_count.desc());
// } else {
// order.add(item.view_count.asc());
// }
// }

public void applySearchTime(List<OrderSpecifier<?>> order, QAuctionItem item) {
if (this.search_time) {
order.add(item.closedTime.desc());
order.add(item.createdAt.desc());
} else {
order.add(item.closedTime.asc());
order.add(item.createdAt.asc());
}
}

Expand All @@ -90,12 +106,12 @@ public void applySearchClosed(BooleanBuilder builder, QAuctionItem item) {
}

public SearchAuctionItemSortedRequest() {
this.search_status = SearchStatus.ALL;
// this.search_status = SearchStatus.ALL;
this.closed = Boolean.FALSE;
this.search_time = Boolean.FALSE;
this.like = Boolean.FALSE;
// this.like = Boolean.FALSE;
this.search_price = Boolean.FALSE;
this.view_count = Boolean.FALSE;
// this.view_count = Boolean.FALSE;
}

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,19 @@
@RequiredArgsConstructor
public class AuctionItemSearchServiceImpl implements AuctionItemSearchService {

private final CategoryService categoryService;
private final AuctionItemRepository auctionItemRepository;
private final CategoryService categoryService;
private final AuctionItemRepository auctionItemRepository;

@Override
@Transactional(readOnly = true)
public AuctionItemSearchResponse findAuctionItemByRequest(
SearchAuctionItemSortedRequest searchAuctionItemSortedRequest) {
return auctionItemRepository.searchAuctionItemPage(searchAuctionItemSortedRequest);
}
@Override
@Transactional(readOnly = true)
public AuctionItemSearchResponse findAuctionItemByRequest(
SearchAuctionItemSortedRequest searchAuctionItemSortedRequest) {
if (searchAuctionItemSortedRequest.getKeyword().equals("")) {
searchAuctionItemSortedRequest.setKeyword(null);
}
if (searchAuctionItemSortedRequest.getCategory().equals("")) {
searchAuctionItemSortedRequest.setCategory(null);
}
return auctionItemRepository.searchAuctionItemPage(searchAuctionItemSortedRequest);
}
}

0 comments on commit b8e541f

Please sign in to comment.