Skip to content

Commit

Permalink
Merge branch 'develop' of https://github.com/MEME-UMC/MEME_SERVICE in…
Browse files Browse the repository at this point in the history
…to ci/#114
  • Loading branch information
sunwupark committed Feb 18, 2024
2 parents ad1ae39 + f526d18 commit 3bcff2c
Show file tree
Hide file tree
Showing 9 changed files with 183 additions and 131 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ public class ArtistDto {

private WorkExperience workExperience;

private String shopLocation; //샵 위치

private List<Region> region;

private List<Category> specialization;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,5 +91,6 @@ public void tempMethod(){
this.role="ARTIST";
this.userStatus = UserStatus.ACTIVE;
this.provider = Provider.KAKAO;
this.details = false;
}
}
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
package umc.meme.shop.domain.model.controller;

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;
import umc.meme.shop.domain.favorite.dto.request.FavoriteArtistDto;
import umc.meme.shop.domain.favorite.dto.request.FavoritePortfolioDto;
import umc.meme.shop.domain.model.dto.request.ModelProfileDto;
import umc.meme.shop.domain.model.service.ModelService;
import umc.meme.shop.global.enums.Category;
import umc.meme.shop.global.SuccessStatus;
import umc.meme.shop.global.response.ApiResponse;

Expand Down Expand Up @@ -85,53 +83,4 @@ public ApiResponse deleteFavoritePortfolio(@RequestBody FavoritePortfolioDto fav
return ApiResponse.SuccessResponse(SuccessStatus.FAVORITE_PORTFOLIO_DELETE);
}


/**search**/

@Operation(summary = "메이크업 검색", description = "메이크업을 검색/최근 검색어로 검색하는 API입니다.")
@GetMapping("/search")
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, modelService.search(query, page, sort));
}

@Operation(summary = "메이크업 검색 - 관심 아티스트", description = "관심 아티스트로 검색하는 API입니다.")
@GetMapping("/search/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, modelService.searchArtist(artistId, page, sort));
}

@Operation(summary = "메이크업 검색 - 카테고리", description = "메이크업 카테고리로 검색하는 API입니다.")
@GetMapping("/search/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, modelService.searchCategory(category, page, sort));
}

@Operation(summary = "메이크업 검색 - 전체", description = "메이크업 전체를 검색하는 API입니다.")
@GetMapping("/search/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, modelService.searchAll(page, sort));
}

/**recommend**/
@Operation(summary = "포트폴리오 추천 - 리뷰 순", description = "리뷰가 많은 순으로 포트폴리오를 추천하는 API입니다.")
@GetMapping("/recommend/review")
public ApiResponse recommendReview(){
return ApiResponse.SuccessResponse(SuccessStatus.RECOMMEND_REVIEW_GET, modelService.recommendReview());
}

@Operation(summary = "포트폴리오 추천 - 최신 순", description = "최근 등록된 순으로 포트폴리오를 추천하는 API입니다.")
@GetMapping("/recommend/recent")
public ApiResponse recommendRecent(){
return ApiResponse.SuccessResponse(SuccessStatus.RECOMMEND_RECENT_GET, modelService.recommendRecent());
}
}
75 changes: 0 additions & 75 deletions src/main/java/umc/meme/shop/domain/model/service/ModelService.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,7 @@
import umc.meme.shop.domain.model.dto.request.ModelProfileDto;
import umc.meme.shop.domain.model.entity.Model;
import umc.meme.shop.domain.model.repository.ModelRepository;
import umc.meme.shop.domain.portfolio.dto.response.PortfolioPageDto;
import umc.meme.shop.domain.portfolio.dto.response.SimplePortfolioDto;
import umc.meme.shop.domain.portfolio.entity.Portfolio;
import umc.meme.shop.global.enums.Category;
import umc.meme.shop.domain.portfolio.repository.PortfolioRepository;
import umc.meme.shop.global.ErrorStatus;
import umc.meme.shop.global.exception.GlobalException;
Expand Down Expand Up @@ -162,78 +159,6 @@ public void deleteFavoritePortfolio(FavoritePortfolioDto favoritePortfolioDto) {
favoritePortfolioRepository.delete(favoritePortfolio);
}


/**search**/
//검색
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);
}

/**recommend**/
//리뷰 많은 순 포트폴리오 추천
public List<SimplePortfolioDto> recommendReview(){
Pageable pageable = setPageRequest(0, "review");
Page<Portfolio> portfolioList = portfolioRepository.findAllNotBlocked(pageable);

return portfolioList.getContent().stream()
.map(SimplePortfolioDto::from)
.toList();
}

//최신 등록 순 포트폴리오 추천
public List<SimplePortfolioDto> recommendRecent(){
Pageable pageable = setPageRequest(0, "recent");
Page<Portfolio> portfolioList = portfolioRepository.findAllNotBlocked(pageable);

return portfolioList.getContent().stream()
.map(SimplePortfolioDto::from)
.toList();
}

//검색하기 정렬 기준 설정
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);
}

private Page getPage(int page, List list){
Pageable pageable = PageRequest.of(page, 30);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;
import umc.meme.shop.domain.portfolio.dto.request.CreatePortfolioDto;
import umc.meme.shop.domain.portfolio.dto.request.PortfolioDetailRequestDto;
import umc.meme.shop.domain.portfolio.dto.request.UpdatePortfolioDto;
import umc.meme.shop.domain.portfolio.service.PortfolioService;
import umc.meme.shop.global.SuccessStatus;
Expand Down Expand Up @@ -43,4 +42,17 @@ public ApiResponse updatePortfolio(@RequestBody UpdatePortfolioDto portfolioDto)
portfolioService.updatePortfolio(portfolioDto);
return ApiResponse.SuccessResponse(SuccessStatus.PORTFOLIO_UPDATE);
}

/**recommend**/
@Operation(summary = "포트폴리오 추천 - 리뷰 순", description = "리뷰가 많은 순으로 포트폴리오를 추천하는 API입니다.")
@GetMapping("/recommend/review")
public ApiResponse recommendReview(){
return ApiResponse.SuccessResponse(SuccessStatus.RECOMMEND_REVIEW_GET, portfolioService.recommendReview());
}

@Operation(summary = "포트폴리오 추천 - 최신 순", description = "최근 등록된 순으로 포트폴리오를 추천하는 API입니다.")
@GetMapping("/recommend/recent")
public ApiResponse recommendRecent(){
return ApiResponse.SuccessResponse(SuccessStatus.RECOMMEND_RECENT_GET, portfolioService.recommendRecent());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,7 @@

import jakarta.transaction.Transactional;
import lombok.RequiredArgsConstructor;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
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;
Expand All @@ -18,6 +15,7 @@
import umc.meme.shop.domain.portfolio.dto.response.PortfolioDetailDto;
import umc.meme.shop.domain.portfolio.dto.response.PortfolioImgDto;
import umc.meme.shop.domain.portfolio.dto.response.PortfolioPageDto;
import umc.meme.shop.domain.portfolio.dto.response.SimplePortfolioDto;
import umc.meme.shop.domain.portfolio.entity.Portfolio;
import umc.meme.shop.domain.portfolio.entity.PortfolioImg;
import umc.meme.shop.domain.portfolio.repository.PortfolioImgRepository;
Expand Down Expand Up @@ -146,6 +144,41 @@ private void updatePortfolioImg(Portfolio portfolio, List<PortfolioImgDto> portf
portfolio.getPortfolioImgList().addAll(updatedPortfolioImgs);
}

/**recommend**/
//리뷰 많은 순 포트폴리오 추천
public List<SimplePortfolioDto> recommendReview(){
Pageable pageable = setPageRequest(0, "review");
Page<Portfolio> portfolioList = portfolioRepository.findAllNotBlocked(pageable);

return portfolioList.getContent().stream()
.map(SimplePortfolioDto::from)
.toList();
}

//최신 등록 순 포트폴리오 추천
public List<SimplePortfolioDto> recommendRecent(){
Pageable pageable = setPageRequest(0, "recent");
Page<Portfolio> portfolioList = portfolioRepository.findAllNotBlocked(pageable);

return portfolioList.getContent().stream()
.map(SimplePortfolioDto::from)
.toList();
}

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);
}

private Page<Portfolio> getPage(int page, List<Portfolio> list){
Pageable pageable = PageRequest.of(page, 30);
Expand Down
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));
}

}
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);
}
}
Loading

0 comments on commit 3bcff2c

Please sign in to comment.