Skip to content

Commit

Permalink
Merge pull request #104 from MEME-UMC/feat/#98
Browse files Browse the repository at this point in the history
[Feat] 포트폴리오 추천 (최신 순) 기능 구현
  • Loading branch information
daeun084 authored Feb 6, 2024
2 parents daca9fc + ee7a3a5 commit 1677b11
Show file tree
Hide file tree
Showing 11 changed files with 99 additions and 62 deletions.
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
package umc.meme.shop.domain.artist.converter;

import org.springframework.data.domain.Page;
import umc.meme.shop.domain.artist.dto.response.SimpleArtistDto;
import umc.meme.shop.domain.favorite.dto.response.FavoriteArtistPageResponseDto;
import umc.meme.shop.domain.favorite.dto.response.FavoriteArtistResponseDto;
import umc.meme.shop.domain.favorite.entity.FavoriteArtist;

import java.util.List;

public class ArtistConverter {
public static FavoriteArtistPageResponseDto favoriteArtistPageConverter(Page<FavoriteArtist> page, List<FavoriteArtistResponseDto> content) {
public static FavoriteArtistPageResponseDto favoriteArtistPageConverter(Page<FavoriteArtist> page, List<SimpleArtistDto> content) {

return FavoriteArtistPageResponseDto.builder()
.content(content)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import lombok.NoArgsConstructor;
import umc.meme.shop.domain.artist.entity.Artist;
import umc.meme.shop.domain.portfolio.dto.response.PortfolioDto;
import umc.meme.shop.domain.portfolio.dto.response.SimplePortfolioDto;
import umc.meme.shop.global.enums.*;

import java.util.List;
Expand Down Expand Up @@ -36,14 +37,14 @@ public class ArtistDto {

private Map<DayOfWeek, Times> availableDayOfWeekAndTime;

private List<PortfolioDto> portfolioDtoList;
private List<SimplePortfolioDto> simplePortfolioDtoList;



public static ArtistDto from(Artist artist){
List<PortfolioDto> portfolioDtoList = artist.getPortfolioList()
List<SimplePortfolioDto> portfolioDtoList = artist.getPortfolioList()
.stream()
.map(PortfolioDto::from)
.map(SimplePortfolioDto::from)
.toList();

return ArtistDto.builder()
Expand All @@ -57,7 +58,7 @@ public static ArtistDto from(Artist artist){
.specialization(artist.getSpecialization())
.makeupLocation(artist.getMakeupLocation())
.availableDayOfWeekAndTime(artist.getAvailableDayOfWeekAndTime())
.portfolioDtoList(portfolioDtoList)
.simplePortfolioDtoList(portfolioDtoList)
.build();
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,23 +1,22 @@
package umc.meme.shop.domain.favorite.dto.response;
package umc.meme.shop.domain.artist.dto.response;

import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.Getter;
import lombok.NoArgsConstructor;
import umc.meme.shop.domain.artist.entity.Artist;
import umc.meme.shop.domain.favorite.entity.FavoriteArtist;

@Data
@Getter
@Builder
@AllArgsConstructor
@NoArgsConstructor
public class FavoriteArtistResponseDto {
@AllArgsConstructor
public class SimpleArtistDto {
private Long artistId;
private String profileImg;
private String artistNickName;

public static FavoriteArtistResponseDto from(Artist artist) {
return FavoriteArtistResponseDto.builder()
public static SimpleArtistDto from(Artist artist) {
return SimpleArtistDto.builder()
.artistId(artist.getUserId())
.profileImg(artist.getProfileImg())
.artistNickName(artist.getNickname())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import umc.meme.shop.domain.favorite.entity.FavoriteArtist;
import umc.meme.shop.domain.artist.dto.response.SimpleArtistDto;

import java.util.List;

Expand All @@ -13,7 +13,7 @@
@NoArgsConstructor
@AllArgsConstructor
public class FavoriteArtistPageResponseDto {
private List<FavoriteArtistResponseDto> content;
private List<SimpleArtistDto> content;
private int currentPage; //현재 페이지 번호
private int pageSize; //페이지 크기
private int totalNumber; //전체 메이크업 개수
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import umc.meme.shop.domain.portfolio.dto.response.SimplePortfolioDto;

import java.util.List;

Expand All @@ -12,7 +13,7 @@
@NoArgsConstructor
@Builder
public class FavoritePortfolioResponsePageDto {
private List<FavoritePortfolioResponseDto> content;
private List<SimplePortfolioDto> content;
private int currentPage; //현재 페이지 번호
private int pageSize; //페이지 크기
private int totalNumber; //전체 메이크업 개수
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,4 +122,10 @@ public ApiResponse searchAll( @RequestParam(value = "page", defaultValue = "0",
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());
}
}
22 changes: 16 additions & 6 deletions src/main/java/umc/meme/shop/domain/model/service/ModelService.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@
import org.springframework.data.domain.*;
import org.springframework.stereotype.Service;
import umc.meme.shop.domain.artist.converter.ArtistConverter;
import umc.meme.shop.domain.artist.dto.response.SimpleArtistDto;
import umc.meme.shop.domain.artist.entity.Artist;
import umc.meme.shop.domain.artist.repository.ArtistRepository;
import umc.meme.shop.domain.favorite.dto.request.FavoriteArtistDto;
import umc.meme.shop.domain.favorite.dto.request.FavoritePortfolioDto;
import umc.meme.shop.domain.favorite.dto.response.FavoriteArtistPageResponseDto;
import umc.meme.shop.domain.favorite.dto.response.FavoriteArtistResponseDto;
import umc.meme.shop.domain.favorite.dto.response.FavoritePortfolioResponsePageDto;
import umc.meme.shop.domain.favorite.entity.FavoriteArtist;
import umc.meme.shop.domain.favorite.entity.FavoritePortfolio;
Expand All @@ -20,8 +20,8 @@
import umc.meme.shop.domain.model.entity.Model;
import umc.meme.shop.domain.model.repository.ModelRepository;
import umc.meme.shop.domain.portfolio.converter.PortfolioConverter;
import umc.meme.shop.domain.portfolio.dto.response.PortfolioDto;
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 @@ -83,12 +83,12 @@ public FavoriteArtistPageResponseDto getFavoriteArtist(Long modelId, int page){
Page<FavoriteArtist> favoriteArtistPage = new PageImpl<>(favoriteArtistList.subList(start, end),
pageable, favoriteArtistList.size());

List<FavoriteArtistResponseDto> content = new ArrayList<>();
List<SimpleArtistDto> content = new ArrayList<>();
for(int i=0; i<favoriteArtistPage.getContent().size(); i++){
FavoriteArtist favoriteArtist = favoriteArtistPage.getContent().get(i);
Artist artist = artistRepository.findById(favoriteArtist.getArtistId())
.orElseThrow(() -> new GlobalException(ErrorStatus.NOT_EXIST_ARTIST));
FavoriteArtistResponseDto dto = FavoriteArtistResponseDto.from(artist);
SimpleArtistDto dto = SimpleArtistDto.from(artist);
content.add(dto);
}

Expand Down Expand Up @@ -236,6 +236,8 @@ else if(sortBy.equals("asc"))
sort = Sort.by("price").ascending();
else if(sortBy.equals("review"))
sort = Sort.by("averageStars").descending();
else if(sortBy.equals("recent"))
sort = Sort.by("createdAt").descending();
else
throw new GlobalException(ErrorStatus.INVALID_SORT_CRITERIA);
Sort finalSort = sort.and(Sort.by("averageStars").descending());
Expand All @@ -244,11 +246,19 @@ else if(sortBy.equals("review"))
}

/**recommend**/
public List<PortfolioDto> recommendReview(){
public List<SimplePortfolioDto> recommendReview(){
Pageable pageable = setPageRequest(0, "review");
Page<Portfolio> portfolioList = portfolioRepository.findAllNotBlocked(pageable);
return portfolioList.getContent().stream()
.map(PortfolioDto::from)
.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();
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
package umc.meme.shop.domain.portfolio.converter;

import org.springframework.data.domain.Page;
import umc.meme.shop.domain.favorite.dto.response.FavoriteArtistResponseDto;
import umc.meme.shop.domain.favorite.dto.response.FavoritePortfolioResponseDto;
import umc.meme.shop.domain.favorite.dto.response.FavoritePortfolioResponsePageDto;
import umc.meme.shop.domain.favorite.entity.FavoritePortfolio;
import umc.meme.shop.domain.portfolio.dto.response.PortfolioDto;
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 java.util.List;
Expand All @@ -15,8 +14,8 @@ public class PortfolioConverter {

public static FavoritePortfolioResponsePageDto favoritePortfolioPageConverter(Page<FavoritePortfolio> page){

List<FavoritePortfolioResponseDto> content = page.stream()
.map(FavoritePortfolioResponseDto::from)
List<SimplePortfolioDto> content = page.stream()
.map(SimplePortfolioDto::from)
.toList();

return FavoritePortfolioResponsePageDto.builder()
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
package umc.meme.shop.domain.portfolio.dto.response;

import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;
import umc.meme.shop.domain.artist.entity.Artist;
import umc.meme.shop.domain.favorite.entity.FavoritePortfolio;
import umc.meme.shop.domain.portfolio.entity.Portfolio;
import umc.meme.shop.global.enums.Category;
import umc.meme.shop.global.enums.MakeupLocation;

@Getter
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class SimplePortfolioDto {
private Long portfolioId;
private String portfolioImg;
private Category category;
private String makeupName;
private String artistName;
private int price;
private MakeupLocation makeupLocation; //샵 재직 여부

public static SimplePortfolioDto from(FavoritePortfolio favoritePortfolio){
Portfolio portfolio = favoritePortfolio.getPortfolio();
Artist artist = portfolio.getArtist();

return SimplePortfolioDto.builder()
.portfolioId(portfolio.getPortfolioId())
.portfolioImg(portfolio.getPortfolioImgList().get(0).getSrc())
.category(portfolio.getCategory())
.makeupName(portfolio.getMakeupName())
.artistName(artist.getNickname())
.price(portfolio.getPrice())
.makeupLocation(artist.getMakeupLocation())
.build();
}

public static SimplePortfolioDto from(Portfolio portfolio){
Artist artist = portfolio.getArtist();

return SimplePortfolioDto.builder()
.portfolioId(portfolio.getPortfolioId())
.portfolioImg(portfolio.getPortfolioImgList().get(0).getSrc())
.category(portfolio.getCategory())
.makeupName(portfolio.getMakeupName())
.artistName(artist.getNickname())
.price(portfolio.getPrice())
.makeupLocation(artist.getMakeupLocation())
.build();
}

}
1 change: 1 addition & 0 deletions src/main/java/umc/meme/shop/global/SuccessStatus.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ public enum SuccessStatus {
SEARCH_GET(200, "조회가 완료되었습니다"),

RECOMMEND_REVIEW_GET(200, "리뷰 순 포트폴리오 추천이 완료되었습니다."),
RECOMMEND_RECENT_GET(200, "최신 순 포트폴리오 추천이 완료되었습니다."),

/**review**/
REVIEW_CREATE(200, "리뷰 작성이 완료되었습니다"),
Expand Down

0 comments on commit 1677b11

Please sign in to comment.