Skip to content

Commit

Permalink
#322 reafctor: 와인 검색 기능 페이징 인터페이스로 변경
Browse files Browse the repository at this point in the history
  • Loading branch information
jeongyun1206 committed Jan 13, 2025
1 parent 0179bec commit cabfd5e
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.servlet.http.HttpServletResponse;
import lombok.RequiredArgsConstructor;
import org.springframework.data.domain.Pageable;
import org.springframework.security.core.annotation.AuthenticationPrincipal;
import org.springframework.web.bind.annotation.*;

Expand All @@ -30,9 +31,9 @@ public class WineController {
// todo: 페이징 구현하기
@GetMapping
@Operation(summary = "와인 검색", description = "와인 이름 또는 영어 이름으로 검색하여 와인의 기본 정보를 조회한다.")
public ApiResponse<List<WinePreviewResponse>> searchWine(@RequestParam(defaultValue = "") String searchName) {
public ApiResponse<List<WinePreviewResponse>> searchWine(@RequestParam(defaultValue = "") String searchName, Pageable pageable) {

List<WinePreviewResponse> winePreviewResponses = wineService.searchWinesByName(searchName);
List<WinePreviewResponse> winePreviewResponses = wineService.searchWinesByName(searchName, pageable);

return ApiResponse.onSuccess(winePreviewResponses);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@


import com.drinkeg.drinkeg.domain.wine.domain.Wine;
import org.springframework.data.domain.Pageable;

import java.util.List;

Expand All @@ -10,5 +11,5 @@ public interface WineRepositoryCustom {

List<Wine> findMostLikedWines();

List<Wine> searchByName(String name);
List<Wine> searchByName(String name, Pageable pageable);
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,12 @@
import com.querydsl.core.types.dsl.Expressions;
import com.querydsl.jpa.impl.JPAQueryFactory;
import lombok.RequiredArgsConstructor;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

import static com.drinkeg.drinkeg.domain.member.domain.QMember.member;
import static com.drinkeg.drinkeg.domain.tastingNote.domain.QTastingNote.tastingNote;
import static com.drinkeg.drinkeg.domain.wine.domain.QWine.wine;
import static com.drinkeg.drinkeg.domain.wineWishlist.domain.QWineWishlist.wineWishlist;

Expand All @@ -33,7 +32,7 @@ public List<Wine> findMostLikedWines() {
}

@Override
public List<Wine> searchByName(String name) {
public List<Wine> searchByName(String name, Pageable pageable) {
return queryFactory.selectFrom(wine)
.where(
wine.name.containsIgnoreCase(name)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,14 @@
import com.drinkeg.drinkeg.domain.wine.dto.response.WineWithThreeReviewsResponse;
import com.drinkeg.drinkeg.domain.wine.dto.response.WineReviewResponse;
import com.opencsv.exceptions.CsvException;
import org.springframework.data.domain.Pageable;

import java.io.IOException;
import java.util.List;

public interface WineService {

public List<WinePreviewResponse> searchWinesByName(String searchName);
public List<WinePreviewResponse> searchWinesByName(String searchName, Pageable pageable);

public void updateWineNoteStatics(Long wineId);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import com.opencsv.CSVWriterBuilder;
import com.opencsv.exceptions.CsvException;
import lombok.RequiredArgsConstructor;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.multipart.MultipartFile;
Expand All @@ -46,8 +47,8 @@ public class WineServiceImpl implements WineService {
private final StorageService storageService;

@Override
public List<WinePreviewResponse> searchWinesByName(String searchName) {
List<Wine> searchWines = wineRepository.searchByName(searchName);
public List<WinePreviewResponse> searchWinesByName(String searchName, Pageable pageable) {
List<Wine> searchWines = wineRepository.searchByName(searchName, pageable);

return searchWines.stream()
.map(WinePreviewResponse::of)
Expand Down

0 comments on commit cabfd5e

Please sign in to comment.