-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'develop' of https://github.com/MEME-UMC/MEME_SERVICE in…
…to ci/#114
- Loading branch information
Showing
9 changed files
with
183 additions
and
131 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
55 changes: 55 additions & 0 deletions
55
src/main/java/umc/meme/shop/domain/search/controller/SearchController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
package umc.meme.shop.domain.search.controller; | ||
|
||
import io.swagger.v3.oas.annotations.Operation; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.web.bind.annotation.GetMapping; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RequestParam; | ||
import org.springframework.web.bind.annotation.RestController; | ||
import umc.meme.shop.domain.search.service.SearchService; | ||
import umc.meme.shop.global.SuccessStatus; | ||
import umc.meme.shop.global.enums.Category; | ||
import umc.meme.shop.global.response.ApiResponse; | ||
|
||
@RestController | ||
@RequiredArgsConstructor | ||
@RequestMapping("/api/v1/search") | ||
public class SearchController { | ||
|
||
private final SearchService searchService; | ||
|
||
@Operation(summary = "메이크업 검색", description = "메이크업을 검색/최근 검색어로 검색하는 API입니다.") | ||
@GetMapping("") | ||
public ApiResponse search(@RequestParam(value = "query") String query, | ||
@RequestParam(value = "page", defaultValue = "0", required = false) int page, | ||
@RequestParam(value = "sort", defaultValue = "desc") String sort){ | ||
return ApiResponse.SuccessResponse(SuccessStatus.SEARCH_GET, searchService.search(query, page, sort)); | ||
} | ||
|
||
@Operation(summary = "메이크업 검색 - 관심 아티스트", description = "관심 아티스트로 검색하는 API입니다.") | ||
@GetMapping("/artist") | ||
public ApiResponse searchArtist(@RequestParam(value = "artistId") Long artistId, | ||
@RequestParam(value = "page", defaultValue = "0", required = false) int page, | ||
@RequestParam(value = "sort", defaultValue = "desc") String sort | ||
){ | ||
return ApiResponse.SuccessResponse(SuccessStatus.SEARCH_GET, searchService.searchArtist(artistId, page, sort)); | ||
} | ||
|
||
@Operation(summary = "메이크업 검색 - 카테고리", description = "메이크업 카테고리로 검색하는 API입니다.") | ||
@GetMapping("/category") | ||
public ApiResponse searchCategory(@RequestParam(value = "category") Category category, | ||
@RequestParam(value = "page", defaultValue = "0", required = false) int page, | ||
@RequestParam(value = "sort", defaultValue = "desc") String sort | ||
){ | ||
return ApiResponse.SuccessResponse(SuccessStatus.SEARCH_GET, searchService.searchCategory(category, page, sort)); | ||
} | ||
|
||
@Operation(summary = "메이크업 검색 - 전체", description = "메이크업 전체를 검색하는 API입니다.") | ||
@GetMapping("/all") | ||
public ApiResponse searchAll( @RequestParam(value = "page", defaultValue = "0", required = false) int page, | ||
@RequestParam(value = "sort", defaultValue = "desc") String sort | ||
){ | ||
return ApiResponse.SuccessResponse(SuccessStatus.SEARCH_GET, searchService.searchAll(page, sort)); | ||
} | ||
|
||
} |
72 changes: 72 additions & 0 deletions
72
src/main/java/umc/meme/shop/domain/search/service/SearchService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
package umc.meme.shop.domain.search.service; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.data.domain.*; | ||
import org.springframework.stereotype.Service; | ||
import umc.meme.shop.domain.artist.entity.Artist; | ||
import umc.meme.shop.domain.artist.repository.ArtistRepository; | ||
import umc.meme.shop.domain.portfolio.dto.response.PortfolioPageDto; | ||
import umc.meme.shop.domain.portfolio.entity.Portfolio; | ||
import umc.meme.shop.domain.portfolio.repository.PortfolioRepository; | ||
import umc.meme.shop.global.ErrorStatus; | ||
import umc.meme.shop.global.enums.Category; | ||
import umc.meme.shop.global.exception.GlobalException; | ||
|
||
import java.util.List; | ||
|
||
@Service | ||
@RequiredArgsConstructor | ||
public class SearchService { | ||
|
||
private final PortfolioRepository portfolioRepository; | ||
private final ArtistRepository artistRepository; | ||
|
||
//검색 | ||
public PortfolioPageDto search(String query, int page, String sortBy){ | ||
Pageable pageable = setPageRequest(page, sortBy); | ||
|
||
//query 검색 | ||
Page<Portfolio> portfolioPage = portfolioRepository.search(query, pageable); | ||
return PortfolioPageDto.from(portfolioPage); | ||
} | ||
|
||
//카테고리 검색 | ||
public PortfolioPageDto searchCategory(Category category, int page, String sortBy){ | ||
Pageable pageable = setPageRequest(page, sortBy); | ||
Page<Portfolio> portfolioPage = portfolioRepository.findByCategory(category, pageable); | ||
return PortfolioPageDto.from(portfolioPage); | ||
} | ||
|
||
//관심 아티스트 검색 | ||
public PortfolioPageDto searchArtist(Long artistId, int page, String sortBy){ | ||
Artist artist = artistRepository.findById(artistId) | ||
.orElseThrow(() -> new GlobalException(ErrorStatus.NOT_EXIST_ARTIST)); | ||
|
||
Pageable pageable = setPageRequest(page, sortBy); | ||
Page<Portfolio> portfolioPage = portfolioRepository.findByArtist(artist, pageable); | ||
return PortfolioPageDto.from(portfolioPage); | ||
} | ||
|
||
//전체 조회 | ||
public PortfolioPageDto searchAll(int page, String sortBy) { | ||
Pageable pageable = setPageRequest(page, sortBy); | ||
Page<Portfolio> portfolioPage = portfolioRepository.findAllNotBlocked(pageable); | ||
return PortfolioPageDto.from(portfolioPage); | ||
} | ||
|
||
//검색하기 정렬 기준 설정 | ||
private Pageable setPageRequest(int page, String sortBy){ | ||
|
||
Sort sort = switch (sortBy) { | ||
case "desc" -> Sort.by("price").descending(); | ||
case "asc" -> Sort.by("price").ascending(); | ||
case "review" -> Sort.by("averageStars").descending(); | ||
case "recent" -> Sort.by("createdAt").descending(); | ||
default -> throw new GlobalException(ErrorStatus.INVALID_SORT_CRITERIA); | ||
}; | ||
|
||
//별점 높은 순 정렬 추가 | ||
Sort finalSort = sort.and(Sort.by("averageStars").descending()); | ||
return PageRequest.of(page, 30, finalSort); | ||
} | ||
} |
Oops, something went wrong.