Skip to content

feat: 상품 이름으로 검색하여 페이징 처리하는 API 구현#109

Open
whxogus215 wants to merge 3 commits into
mainfrom
feat/keyword-search
Open

feat: 상품 이름으로 검색하여 페이징 처리하는 API 구현#109
whxogus215 wants to merge 3 commits into
mainfrom
feat/keyword-search

Conversation

@whxogus215

Copy link
Copy Markdown
Contributor

요약

  • Pageable + Spring Data JPA 적용
  • 캠페인 검색 API : GET /campaigns/search?keyword=보약&size=10&page=0
    • 쿼리 파라미터로 keyword, size, page 입력 시, 해당 값을 토대로 페이징 처리

@gogo1414 gogo1414 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

고생하셨습니다!

사소한 코멘트 몇개 달았어용!

public List<ReadCampaignResponse> searchByProductName(String keyword, int page, int size) {
keyword = keyword.trim();
Pageable pageable = PageRequest.of(page, size, Sort.by("id").ascending());
Page<Product> pages = productRepository.findByNameContaining(keyword, pageable);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Page<Product> pages = productRepository.findByNameContaining(keyword, pageable);
Page<Product> pages = productRepository.findAllByNameContaining(keyword, pageable);

사소한건데 All 붙이기로 했었던걸로 기억하고 있어용

Comment on lines +139 to +153
return pages.getContent().stream()
.map(product -> {
Campaign campaign = product.getCampaign();
return new ReadCampaignResponse(
campaign.getId(),
campaign.getStartDate().toString(),
campaign.getEndDate().toString(),
campaign.getGoalQuantity(),
campaign.getSoldQuantity(),
product.getStock().getTotalQuantity(),
campaign.getState(),
new ProductResponse(product),
campaign.getMember().orElse(Member.createEmpty()).getId()
);
}).toList();

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
return pages.getContent().stream()
.map(product -> {
Campaign campaign = product.getCampaign();
return new ReadCampaignResponse(
campaign.getId(),
campaign.getStartDate().toString(),
campaign.getEndDate().toString(),
campaign.getGoalQuantity(),
campaign.getSoldQuantity(),
product.getStock().getTotalQuantity(),
campaign.getState(),
new ProductResponse(product),
campaign.getMember().orElse(Member.createEmpty()).getId()
);
}).toList();
return pages.getContent().stream()
.map(product -> {
Campaign campaign = product.getCampaign();
Member member = campaign.getMember().orElse(Member.createEmpty());
return new ReadCampaignResponse(
campaign.getId(),
campaign.getStartDate().toString(),
campaign.getEndDate().toString(),
campaign.getGoalQuantity(),
campaign.getSoldQuantity(),
product.getStock().getTotalQuantity(),
campaign.getState(),
new ProductResponse(product),
member.getId()
);
}).toList();

멤버는 바깥에서 분리하는건 어떤가용??

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants