Skip to content

Commit

Permalink
Merge pull request #114 from MEME-UMC/chore/#113
Browse files Browse the repository at this point in the history
[Chore] 관심 포트폴리오, 관심 아티스트 설정 여부 리턴
  • Loading branch information
daeun084 authored Feb 15, 2024
2 parents 88495a4 + 59a6b12 commit dc1dd85
Show file tree
Hide file tree
Showing 10 changed files with 175 additions and 34 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import io.swagger.v3.oas.annotations.Operation;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;
import umc.meme.shop.domain.artist.dto.request.ArtistProfileDetailDto;
import umc.meme.shop.domain.artist.dto.request.ArtistProfileDto;
import umc.meme.shop.domain.artist.service.ArtistService;
import umc.meme.shop.global.SuccessStatus;
Expand All @@ -22,9 +23,9 @@ public ApiResponse updateProfile(@RequestBody ArtistProfileDto profileDto){
}

@Operation(summary = "아티스트 프로필 조회")
@GetMapping("/profile/{artistId}")
public ApiResponse getArtistProfile(@PathVariable Long artistId){
return ApiResponse.SuccessResponse(SuccessStatus.ARTIST_PROFILE_GET, artistService.getArtistProfile(artistId));
@GetMapping("/profile")
public ApiResponse getArtistProfile(@RequestBody ArtistProfileDetailDto profileDetailDto){
return ApiResponse.SuccessResponse(SuccessStatus.ARTIST_PROFILE_GET, artistService.getArtistProfile(profileDetailDto));
}

//temp method for Artist create
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package umc.meme.shop.domain.artist.dto.request;

import jakarta.validation.constraints.NotNull;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

@Data
@NoArgsConstructor
@AllArgsConstructor
public class ArtistProfileDetailDto{
@NotNull
private Long userId;
@NotNull
private Long artistId;
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import lombok.Getter;
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.*;

Expand All @@ -17,7 +16,9 @@
@NoArgsConstructor
@AllArgsConstructor
public class ArtistDto {
private Long artistId;
private Long artistId; //관심 등록 여부

private Boolean isFavorite;

private Gender gender;

Expand All @@ -41,14 +42,15 @@ public class ArtistDto {



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

return ArtistDto.builder()
.artistId(artist.getUserId())
.isFavorite(isFavorite)
.gender(artist.getGender())
.nickname(artist.getNickname())
.profileImg(artist.getProfileImg())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,27 @@
import jakarta.transaction.Transactional;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import umc.meme.shop.domain.artist.dto.request.ArtistProfileDetailDto;
import umc.meme.shop.domain.artist.dto.request.ArtistProfileDto;
import umc.meme.shop.domain.artist.dto.response.ArtistDto;
import umc.meme.shop.domain.artist.entity.Artist;
import umc.meme.shop.domain.artist.repository.ArtistRepository;
import umc.meme.shop.domain.favorite.entity.FavoriteArtist;
import umc.meme.shop.domain.favorite.repository.FavoriteArtistRepository;
import umc.meme.shop.domain.model.entity.Model;
import umc.meme.shop.domain.model.repository.ModelRepository;
import umc.meme.shop.global.ErrorStatus;
import umc.meme.shop.global.exception.GlobalException;

import java.util.Optional;


@Service
@RequiredArgsConstructor
public class ArtistService {
private final ArtistRepository artistRepository;
private final ModelRepository modelRepository;
private final FavoriteArtistRepository favoriteArtistRepository;

//아티스트 프로필 관리/수정
@Transactional
Expand All @@ -25,10 +34,21 @@ public void updateArtistProfile(ArtistProfileDto profileDto){
}

//아티스트 프로필 조회
public ArtistDto getArtistProfile(Long artistId){
public ArtistDto getArtistProfile(ArtistProfileDetailDto profileDetailDto){
Long userId = profileDetailDto.getUserId();
Long artistId = profileDetailDto.getArtistId();

Model model = modelRepository.findById(userId)
.orElseThrow(() -> new GlobalException(ErrorStatus.NOT_EXIST_MODEL));
Artist artist = artistRepository.findById(artistId)
.orElseThrow(() -> new GlobalException(ErrorStatus.NOT_EXIST_ARTIST));
return ArtistDto.from(artist);

boolean isFavorite = false;
Optional<FavoriteArtist> favoriteArtist = favoriteArtistRepository.findByModelAndArtistId(model, artistId);
if(favoriteArtist.isPresent())
isFavorite = true;

return ArtistDto.from(artist, isFavorite);
}

//temp method for create Artist
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,6 @@ private Pageable setPageRequest(int page, String sortBy){
return PageRequest.of(page, 30, finalSort);
}

//TODO: change List -> Page
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 @@ -2,11 +2,9 @@

import io.swagger.v3.oas.annotations.Operation;
import lombok.RequiredArgsConstructor;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
import org.springframework.data.web.PageableDefault;
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 @@ -34,9 +32,9 @@ public ApiResponse getPortfolio(@PathVariable Long artistId,
}

@Operation(summary = "포트폴리오 조회", description = "특정 포트폴리오를 조회하는 API입니다.")
@GetMapping("/{portfolioId}/details")
public ApiResponse getPortfolioDetails(@PathVariable Long portfolioId) {
return ApiResponse.SuccessResponse(SuccessStatus.PORTFOLIO_GET, portfolioService.getPortfolioDetails(portfolioId));
@GetMapping("/details")
public ApiResponse getPortfolioDetails(@RequestBody PortfolioDetailRequestDto detailDto) {
return ApiResponse.SuccessResponse(SuccessStatus.PORTFOLIO_GET, portfolioService.getPortfolioDetails(detailDto));
}

@Operation(summary = "포트폴리오 수정/삭제", description = "포트폴리오를 수정/삭제하는 API입니다.")
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package umc.meme.shop.domain.portfolio.dto.request;

import jakarta.validation.constraints.NotNull;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

@Data
@NoArgsConstructor
@AllArgsConstructor
public class PortfolioDetailRequestDto {
@NotNull
private Long userId;
@NotNull
private Long portfolioId;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
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.portfolio.entity.Portfolio;
import umc.meme.shop.global.enums.Category;
import umc.meme.shop.global.enums.MakeupLocation;
import umc.meme.shop.global.enums.Region;

import java.util.List;

@Getter
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class PortfolioDetailDto {
private Long portfolioId;

private Boolean isFavorite;

private Category category;

private String artistNickName;

private String makeupName;

private int price;

private String info;

private MakeupLocation makeupLocation; //샵 재직 여부

private String shopLocation; //샵 위치

private List<Region> region; //활동 가능 지역

private Boolean isBlock;

private String averageStars;

private int reviewCount; //리뷰 개수

private List<PortfolioImgDto> portfolioImgDtoList;

public static PortfolioDetailDto from(Portfolio portfolio, boolean isFavorite) {
Artist artist = portfolio.getArtist();

// PortfolioImg 리스트를 PortfolioImgDto 리스트로 변환
List<PortfolioImgDto> portfolioImgDtoList = portfolio.getPortfolioImgList()
.stream()
.map(PortfolioImgDto::from)
.toList();

return PortfolioDetailDto.builder()
.portfolioId(portfolio.getPortfolioId())
.isFavorite(isFavorite)
.category(portfolio.getCategory())
.artistNickName(artist.getNickname())
.makeupName(portfolio.getMakeupName())
.price(portfolio.getPrice())
.info(portfolio.getInfo())
.makeupLocation(artist.getMakeupLocation())
.shopLocation(artist.getShopLocation())
.region(artist.getRegion())
.isBlock(portfolio.isBlock())
.portfolioImgDtoList(portfolioImgDtoList)
.averageStars(portfolio.getAverageStars())
.reviewCount(portfolio.getReviewList().size())
.build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,6 @@ public class PortfolioDto {

private int price;

private String info;

private MakeupLocation makeupLocation; //샵 재직 여부

private String shopLocation; //샵 위치
Expand Down Expand Up @@ -60,7 +58,6 @@ public static PortfolioDto from(Portfolio portfolio) {
.artistNickName(artist.getNickname())
.makeupName(portfolio.getMakeupName())
.price(portfolio.getPrice())
.info(portfolio.getInfo())
.makeupLocation(artist.getMakeupLocation())
.shopLocation(artist.getShopLocation())
.region(artist.getRegion())
Expand All @@ -79,7 +76,6 @@ public static PortfolioDto from(FavoritePortfolio favoritePortfolio){
.category(portfolio.getCategory())
.makeupName(portfolio.getMakeupName())
.price(portfolio.getPrice())
.info(portfolio.getInfo())
.isBlock(portfolio.isBlock())
.averageStars(portfolio.getAverageStars())
.reviewCount(portfolio.getReviewList().size())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,14 @@
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.favorite.entity.FavoritePortfolio;
import umc.meme.shop.domain.favorite.repository.FavoritePortfolioRepository;
import umc.meme.shop.domain.model.entity.Model;
import umc.meme.shop.domain.model.repository.ModelRepository;
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.dto.response.PortfolioDto;
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.entity.Portfolio;
Expand All @@ -23,30 +28,32 @@

import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;
import java.util.Optional;

@Service
@RequiredArgsConstructor
public class PortfolioService {
private final ArtistRepository artistRepository;
private final PortfolioRepository portfolioRepository;
private final PortfolioImgRepository portfolioImgRepository;
private final ModelRepository modelRepository;
private final FavoritePortfolioRepository favoritePortfolioRepository;

//포트폴리오 생성
@Transactional
public void createPortfolio(CreatePortfolioDto portfolioDto) {
Artist artist = artistRepository.findById(portfolioDto.getArtistId())
public void createPortfolio(CreatePortfolioDto dto) {
Artist artist = artistRepository.findById(dto.getArtistId())
.orElseThrow(() -> new GlobalException(ErrorStatus.NOT_EXIST_ARTIST));

//포트폴리오 이름이 이미 존재할 시
if(portfolioRepository.existsByMakeupName(portfolioDto.getMakeupName()))
if(portfolioRepository.existsByMakeupName(dto.getMakeupName()))
throw new GlobalException(ErrorStatus.ALREADY_EXIST_PORTFOLIO);

List<PortfolioImg> portfolioImgList = portfolioDto.getPortfolioImgSrc().stream()
List<PortfolioImg> portfolioImgList = dto.getPortfolioImgSrc().stream()
.map(PortfolioImg::new)
.toList();

Portfolio portfolio = Portfolio.from(artist, portfolioDto);
Portfolio portfolio = Portfolio.from(artist, dto);
portfolioImgList.forEach(portfolio::addPortfolioImg);

artist.updatePortfolioList(portfolio);
Expand All @@ -71,33 +78,45 @@ public PortfolioPageDto getPortfolio(Long artistId, int page) {
}

// 포트폴리오 하나만 조회
public PortfolioDto getPortfolioDetails(Long portfolioId) {
public PortfolioDetailDto getPortfolioDetails(PortfolioDetailRequestDto dto) {
Long userId = dto.getUserId();
Long portfolioId = dto.getPortfolioId();

Model model = modelRepository.findById(userId)
.orElseThrow(() -> new GlobalException(ErrorStatus.NOT_EXIST_MODEL));
Portfolio portfolio = portfolioRepository.findById(portfolioId)
.orElseThrow(() -> new GlobalException(ErrorStatus.NOT_EXIST_PORTFOLIO));

if(portfolio.isBlock())
throw new GlobalException(ErrorStatus.BLOCKED_PORTFOLIO);

return PortfolioDto.from(portfolio);
boolean isFavorite = false;
Optional<FavoritePortfolio> favoritePortfolio = favoritePortfolioRepository.findByModelAndPortfolio(model, portfolio);
if(favoritePortfolio.isPresent())
isFavorite = true;

return PortfolioDetailDto.from(portfolio, false);
}

// 포트폴리오 수정/삭제
@Transactional
public void updatePortfolio(UpdatePortfolioDto request) {
Artist artist = artistRepository.findById(request.getArtistId())
public void updatePortfolio(UpdatePortfolioDto dto) {
Artist artist = artistRepository.findById(dto.getArtistId())
.orElseThrow(() -> new GlobalException(ErrorStatus.NOT_EXIST_ARTIST));

PortfolioDto portfolioDto = getPortfolioDetails(request.getPortfolioId());
Portfolio portfolio = portfolioRepository.findById(portfolioDto.getPortfolioId())
Portfolio portfolio = portfolioRepository.findById(dto.getPortfolioId())
.orElseThrow(() -> new GlobalException(ErrorStatus.NOT_EXIST_PORTFOLIO));

if(portfolio.isBlock() && !dto.getIsBlock())
throw new GlobalException(ErrorStatus.BLOCKED_PORTFOLIO);

if (!portfolio.getArtist().equals(artist)) {
throw new GlobalException(ErrorStatus.NOT_AUTHORIZED_PORTFOLIO);
}

updatePortfolioImg(portfolio, request.getPortfolioImgList()); // 수정
updatePortfolioImg(portfolio, dto.getPortfolioImgList()); // 수정

portfolio.updatePortfolio(request);
portfolio.updatePortfolio(dto);
}

private void updatePortfolioImg(Portfolio portfolio, List<PortfolioImgDto> portfolioImgDtoList) {
Expand Down

0 comments on commit dc1dd85

Please sign in to comment.