Skip to content

Commit

Permalink
mov: 포트폴리오 추천 위치 변경
Browse files Browse the repository at this point in the history
  • Loading branch information
daeun084 committed Feb 18, 2024
1 parent 6f30342 commit d901fa7
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 40 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
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;
Expand Down Expand Up @@ -122,16 +121,5 @@ public ApiResponse searchAll( @RequestParam(value = "page", defaultValue = "0",
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());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
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;
Expand Down Expand Up @@ -191,33 +190,12 @@ public PortfolioPageDto searchArtist(Long artistId, int page, String sortBy){
}

//전체 조회
public PortfolioPageDto searchAll(int page, String sortBy){
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){

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

0 comments on commit d901fa7

Please sign in to comment.