Skip to content

Commit

Permalink
feat : auctionItemPaginationDto 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
haroya01 committed Sep 16, 2023
1 parent c656182 commit a6b29d3
Show file tree
Hide file tree
Showing 9 changed files with 98 additions and 29 deletions.
7 changes: 3 additions & 4 deletions .env
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
PORT='5000'
POSTGRES_URL='jdbc:postgresql://localhost:5432/gyeongnam_gyeongmae'
PORT='9000'
POSTGRES_URL='jdbc:postgresql://localhost:5432/gg'
POSTGRES_USER='gg_user'
POSTGRES_PASSWORD='rudskarudaodjemals'
POSTGRES_DB='gg'
POSTGRES_PASSWORD='rudskarudaodjemals'
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
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.AuctionItemPaginationDto;
import megabrain.gyeongnamgyeongmae.domain.auctionItem.dto.SearchItem.AuctionItemSearchResponse;
import megabrain.gyeongnamgyeongmae.domain.auctionItem.dto.SearchItem.SearchAuctionItemSortedRequest;
import megabrain.gyeongnamgyeongmae.domain.auctionItem.service.Item.AuctionItemServiceImpl;
import megabrain.gyeongnamgyeongmae.domain.auctionItem.service.Search.AuctionItemSearchServiceImpl;
Expand All @@ -28,8 +30,8 @@ public class AuctionItemSearchController {

@Operation(summary = "Search AuctionItem", description = "경매품 검색하기")
@GetMapping("")
public ResponseEntity<Page<AuctionItemFirstView>> findItemCategory(@ModelAttribute SearchAuctionItemSortedRequest searchAuctionItemSortedRequest, Pageable pageable) {
Page<AuctionItemFirstView> result = this.auctionItemSearchServiceImpl.findAuctionItembyRequest(searchAuctionItemSortedRequest, pageable);
public ResponseEntity<AuctionItemSearchResponse> findItemCategory(@ModelAttribute SearchAuctionItemSortedRequest searchAuctionItemSortedRequest){
AuctionItemSearchResponse result = this.auctionItemSearchServiceImpl.findAuctionItemByRequest(searchAuctionItemSortedRequest);
return ResponseEntity.ok(result);
}
}
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
package megabrain.gyeongnamgyeongmae.domain.auctionItem.domain.repostiory;

import megabrain.gyeongnamgyeongmae.domain.auctionItem.domain.entity.AuctionItem;
import megabrain.gyeongnamgyeongmae.domain.auctionItem.dto.SearchItem.AuctionItemPaginationDto;
import megabrain.gyeongnamgyeongmae.domain.auctionItem.dto.SearchItem.AuctionItemSearchResponse;
import megabrain.gyeongnamgyeongmae.domain.auctionItem.dto.SearchItem.SearchAuctionItemSortedRequest;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;

public interface AuctionItemRepositoryCustom {
Page<AuctionItem> searchAuctionItemPage(SearchAuctionItemSortedRequest searchAuctionItemSortedRequest, Pageable pageable);
AuctionItemSearchResponse searchAuctionItemPage(SearchAuctionItemSortedRequest searchAuctionItemSortedRequest);
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
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.AuctionItemFirstView;
import megabrain.gyeongnamgyeongmae.domain.auctionItem.dto.SearchItem.AuctionItemPaginationDto;
import megabrain.gyeongnamgyeongmae.domain.auctionItem.dto.SearchItem.AuctionItemSearchResponse;
import megabrain.gyeongnamgyeongmae.domain.auctionItem.dto.SearchItem.SearchAuctionItemSortedRequest;
import megabrain.gyeongnamgyeongmae.domain.category.domain.entity.QCategory;
import org.springframework.data.domain.Page;
Expand All @@ -15,6 +18,7 @@
import javax.persistence.EntityManager;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;

public class AuctionItemRepositoryCustomImpl implements AuctionItemRepositoryCustom{

Expand All @@ -24,12 +28,12 @@ public AuctionItemRepositoryCustomImpl(EntityManager em){
this.queryFactory = new JPAQueryFactory(em);
}

public Page<AuctionItem> searchAuctionItemPage(SearchAuctionItemSortedRequest searchAuctionItemSortedRequest, Pageable pageable){
public AuctionItemSearchResponse searchAuctionItemPage(SearchAuctionItemSortedRequest searchAuctionItemSortedRequest){

QAuctionItem auctionItem = QAuctionItem.auctionItem;
QCategory category = QCategory.category;

List<OrderSpecifier<?>> orderSpecifiers = new ArrayList();
List<OrderSpecifier<?>> orderSpecifiers = new ArrayList<>();
BooleanBuilder statusBuilder = new BooleanBuilder();
BooleanBuilder sellBuilder = new BooleanBuilder();
BooleanBuilder keywordStatus = new BooleanBuilder();
Expand All @@ -55,13 +59,34 @@ public Page<AuctionItem> searchAuctionItemPage(SearchAuctionItemSortedRequest se
sellBuilder,
keywordStatus);

Long page = searchAuctionItemSortedRequest.getPage(); // 1 부터
int itemsPerPage = 10;

List<AuctionItem> results =
query
.orderBy(orderSpecifiers.toArray(new OrderSpecifier[0]))
.offset(pageable.getOffset())
.limit(pageable.getPageSize())
.offset((page - 1) * itemsPerPage)
.limit(itemsPerPage)
.fetch();

return new PageImpl<>(results, pageable, results.size());
AuctionItemPaginationDto paginationInfo = new AuctionItemPaginationDto();
paginationInfo.setCurrentPage(page);
paginationInfo.setItemCount((long) results.size());
paginationInfo.setItemsPerPage((long) itemsPerPage);
paginationInfo.setTotalItems(query.fetchCount()); // 이거 왜이럼 ?
paginationInfo.setTotalPages((query.fetchCount()+itemsPerPage-1)/itemsPerPage);



List<AuctionItemFirstView> auctionItemFirstViews = results.stream()
.map(AuctionItemFirstView::of)
.collect(Collectors.toList());

AuctionItemSearchResponse auctionItemSearchResponse = new AuctionItemSearchResponse();
auctionItemSearchResponse.setAuctionItemPaginationDto(paginationInfo);
auctionItemSearchResponse.setAuctionItemFirstViewPage(auctionItemFirstViews);

return auctionItemSearchResponse;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package megabrain.gyeongnamgyeongmae.domain.auctionItem.dto.SearchItem;

import lombok.Data;

import javax.validation.constraints.NotEmpty;

@Data
public class AuctionItemPaginationDto {

private Long currentPage;

private Long itemCount;

@NotEmpty
private Long itemsPerPage = 10L;

private Long totalItems;

private Long totalPages;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package megabrain.gyeongnamgyeongmae.domain.auctionItem.dto.SearchItem;

import lombok.Data;
import megabrain.gyeongnamgyeongmae.domain.auctionItem.dto.AuctionItemFirstView;

import java.util.List;

@Data
public class AuctionItemSearchResponse {

private List<AuctionItemFirstView> auctionItemFirstViewPage;
private AuctionItemPaginationDto auctionItemPaginationDto;
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
import megabrain.gyeongnamgyeongmae.domain.auctionItem.domain.entity.AuctionStatus;
import megabrain.gyeongnamgyeongmae.domain.auctionItem.domain.entity.QAuctionItem;

import javax.validation.constraints.NotEmpty;


@Getter
@Setter
Expand All @@ -23,6 +25,9 @@ public class SearchAuctionItemSortedRequest {
private Boolean search_price;
private Boolean view_count;

@NotEmpty
private Long page;

public void applyKeyWordStatus(BooleanBuilder status, QAuctionItem item) {
if (this.keyword != null) {
status.and(item.name.like("%" + this.keyword + "%"));
Expand All @@ -41,7 +46,7 @@ public void applySearchStatus(BooleanBuilder status, QAuctionItem item) {
} 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}));
status.and(item.itemStatus.in(AuctionItemStatus.NEW, AuctionItemStatus.USED));
}
}

Expand Down Expand Up @@ -81,7 +86,7 @@ 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}));
builder.and(item.status.in(AuctionStatus.ONGOING, AuctionStatus.CLOSED, AuctionStatus.BIDDING));
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@
package megabrain.gyeongnamgyeongmae.domain.auctionItem.service.Search;

import megabrain.gyeongnamgyeongmae.domain.auctionItem.dto.AuctionItemFirstView;
import megabrain.gyeongnamgyeongmae.domain.auctionItem.dto.SearchItem.AuctionItemPaginationDto;
import megabrain.gyeongnamgyeongmae.domain.auctionItem.dto.SearchItem.AuctionItemSearchResponse;
import megabrain.gyeongnamgyeongmae.domain.auctionItem.dto.SearchItem.SearchAuctionItemSortedRequest;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.transaction.annotation.Transactional;

public interface AuctionItemSearchService {
Page<AuctionItemFirstView> findAuctionItembyRequest(SearchAuctionItemSortedRequest searchAuctionItemSortedRequest, Pageable pageable);

AuctionItemSearchResponse findAuctionItemByRequest(
SearchAuctionItemSortedRequest searchAuctionItemSortedRequest);

}
Original file line number Diff line number Diff line change
Expand Up @@ -2,29 +2,26 @@

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.AuctionItemFirstView;
import megabrain.gyeongnamgyeongmae.domain.auctionItem.dto.SearchItem.AuctionItemSearchResponse;
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;
import org.springframework.transaction.annotation.Transactional;

@Service
@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 Page<AuctionItemFirstView> findAuctionItembyRequest(
SearchAuctionItemSortedRequest searchAuctionItemSortedRequest, Pageable pageable) {
Page<AuctionItem> auctionItemEntityList =
auctionItemRepository.searchAuctionItemPage(searchAuctionItemSortedRequest, pageable);
return auctionItemEntityList.map(AuctionItemFirstView::of);
}
@Override
@Transactional(readOnly = true)
public AuctionItemSearchResponse findAuctionItemByRequest(
SearchAuctionItemSortedRequest searchAuctionItemSortedRequest) {
// return auctionItemEntityList.map(AuctionItemFirstView::of);
return auctionItemRepository.searchAuctionItemPage(searchAuctionItemSortedRequest);
}
}

0 comments on commit a6b29d3

Please sign in to comment.