Skip to content

Commit

Permalink
Merge pull request #48 from MEME-UMC/refactor/#45
Browse files Browse the repository at this point in the history
[Refactor] User-Artist/Model 연관관계 수정
  • Loading branch information
limjustin authored Oct 6, 2024
2 parents 3d0aa9e + 4a53698 commit 9babf63
Show file tree
Hide file tree
Showing 19 changed files with 106 additions and 72 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ public static ArtistResponse.ArtistDto toArtistDto(Artist artist, boolean isFavo
return ArtistResponse.ArtistDto.builder()
.artistId(artist.getUserId())
.isFavorite(isFavorite)
.gender(artist.getGender())
.nickname(artist.getNickname())
.profileImg(artist.getProfileImg())
.email(artist.getEmail())
.gender(artist.getUser().getGender())
.nickname(artist.getUser().getNickname())
.profileImg(artist.getUser().getProfileImg())
.email(artist.getUser().getEmail())
.phoneNumber(artist.getPhoneNumber())
.instagramId(artist.getInstagramId())
.introduction(artist.getIntroduction())
Expand All @@ -35,9 +35,9 @@ public static ArtistResponse.ArtistDto toArtistDto(Artist artist, boolean isFavo
public static ArtistResponse.ArtistSimpleDto toArtistSimpleDto(Artist artist, Long modelCount) {
return ArtistResponse.ArtistSimpleDto.builder()
.artistId(artist.getUserId())
.profileImg(artist.getProfileImg())
.artistNickName(artist.getNickname())
.email(artist.getEmail())
.profileImg(artist.getUser().getProfileImg())
.artistNickName(artist.getUser().getNickname())
.email(artist.getUser().getEmail())
.region(artist.getRegion().get(0).getValue())
.modelCount(modelCount)
.build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public class FavoriteConverter {
public static FavoriteArtist toFavoriteArtist(Artist artist, Model model){
return FavoriteArtist.builder()
.model(model)
.artistId(artist.getUserId())
.artist(artist)
.build();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ public class MypageConverter {
public static MypageResponse.ModelProfileDto toModelProfileDto(Model model){
return MypageResponse.ModelProfileDto.builder()
.userId(model.getUserId())
.profileImg(model.getProfileImg())
.nickname(model.getNickname())
.gender(model.getGender())
.profileImg(model.getUser().getProfileImg())
.nickname(model.getUser().getNickname())
.gender(model.getUser().getGender())
.skinType(model.getSkinType())
.personalColor(model.getPersonalColor())
.build();
Expand All @@ -22,9 +22,9 @@ public static MypageResponse.ModelProfileDto toModelProfileDto(Model model){
public static MypageResponse.ArtistProfileDto toArtistProfileDto(Artist artist){
return MypageResponse.ArtistProfileDto.builder()
.userId(artist.getUserId())
.profileImg(artist.getProfileImg())
.nickname(artist.getNickname())
.gender(artist.getGender())
.profileImg(artist.getUser().getProfileImg())
.nickname(artist.getUser().getNickname())
.gender(artist.getUser().getGender())
.introduction(artist.getIntroduction())
.phoneNumber(artist.getPhoneNumber())
.instagramId(artist.getInstagramId())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public static PortfolioResponse.PortfolioDto toPortfolioDto(Portfolio portfolio)
.portfolioId(portfolio.getPortfolioId())
.userId(portfolio.getArtist().getUserId())
.category(portfolio.getCategory())
.artistNickName(artist.getNickname())
.artistNickName(artist.getUser().getNickname())
.makeupName(portfolio.getMakeupName())
.price(portfolio.getPrice())
.makeupLocation(artist.getMakeupLocation())
Expand All @@ -66,8 +66,8 @@ public static PortfolioResponse.PortfolioDetailDto toPortfolioDetailDto(Portfoli
.userId(portfolio.getArtist().getUserId())
.isFavorite(isFavorite)
.category(portfolio.getCategory())
.artistProfileImg(artist.getProfileImg())
.artistNickName(artist.getNickname())
.artistProfileImg(artist.getUser().getProfileImg())
.artistNickName(artist.getUser().getNickname())
.makeupName(portfolio.getMakeupName())
.price(portfolio.getPrice())
.info(portfolio.getInfo())
Expand Down Expand Up @@ -118,8 +118,8 @@ public static PortfolioResponse.PortfolioSimpleDto toPortfolioSimpleDto(Portfoli
.portfolioImg(portfolio.getPortfolioImgList().get(0).getSrc())
.category(portfolio.getCategory())
.makeupName(portfolio.getMakeupName())
.artistName(artist.getNickname())
.artistEmail(artist.getEmail())
.artistName(artist.getUser().getNickname())
.artistEmail(artist.getUser().getEmail())
.price(portfolio.getPrice())
.makeupLocation(artist.getMakeupLocation())
.averageStars(portfolio.getAverageStars())
Expand All @@ -135,8 +135,8 @@ public static PortfolioResponse.PortfolioSimpleDto toPortfolioSimpleDto(Favorite
.portfolioImg(portfolio.getPortfolioImgList().get(0).getSrc())
.category(portfolio.getCategory())
.makeupName(portfolio.getMakeupName())
.artistName(artist.getNickname())
.artistEmail(artist.getEmail())
.artistName(artist.getUser().getNickname())
.artistEmail(artist.getUser().getEmail())
.price(portfolio.getPrice())
.makeupLocation(artist.getMakeupLocation())
.averageStars(portfolio.getAverageStars())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ public static ReviewResponse.ReviewDto toReviewDto(Review review){

return ReviewResponse.ReviewDto.builder()
.reviewId(review.getReviewId())
.modelNickName(review.getModel().getNickname())
.modelProfileImg(review.getModel().getProfileImg())
.modelNickName(review.getModel().getUser().getNickname())
.modelProfileImg(review.getModel().getUser().getProfileImg())
.star(review.getStar())
.comment(review.getComment())
.createdAt(review.getCreatedAt())
Expand All @@ -46,7 +46,7 @@ public static ReviewResponse.ReviewDetailsDto toReviewDetailDto(Review review){
.toList();

return ReviewResponse.ReviewDetailsDto.builder()
.artistNickName(review.getPortfolio().getArtist().getNickname())
.artistNickName(review.getPortfolio().getArtist().getUser().getNickname())
.makeupName(review.getPortfolio().getMakeupName())
.star(review.getStar())
.comment(review.getComment())
Expand All @@ -57,7 +57,7 @@ public static ReviewResponse.ReviewDetailsDto toReviewDetailDto(Review review){
public static ReviewResponse.MyReviewDto toMyReviewDto(Review review){
return ReviewResponse.MyReviewDto.builder()
.reviewId(review.getReviewId())
.artistNickName(review.getPortfolio().getArtist().getNickname())
.artistNickName(review.getPortfolio().getArtist().getUser().getNickname())
.makeupName(review.getPortfolio().getMakeupName())
.portfolioImg(review.getPortfolio().getPortfolioImgList().get(0).getSrc()) //첫 번째 포트폴리오 이미지
.location(review.getPortfolio().getArtist().getShopLocation())
Expand All @@ -69,7 +69,7 @@ public static ReviewResponse.ReviewAvailableListDto toReviewAvailableListDto(Res
return ReviewResponse.ReviewAvailableListDto.builder()
.reservationId(reservation.getReservationId())
.portfolioId(reservation.getReservationId())
.artistNickName(reservation.getPortfolio().getArtist().getNickname())
.artistNickName(reservation.getPortfolio().getArtist().getUser().getNickname())
.makeupName(reservation.getPortfolio().getMakeupName())
.portfolioImg(reservation.getPortfolio().getPortfolioImgList().get(0).getSrc())
.reservationYear(reservation.getYear())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,24 @@
import lombok.Setter;
import lombok.experimental.SuperBuilder;
import org.meme.service.domain.entity.Portfolio;
import org.meme.service.domain.enums.Category;
import org.meme.service.domain.enums.MakeupLocation;
import org.meme.service.domain.enums.Region;
import org.meme.service.domain.enums.WorkExperience;
import org.meme.service.domain.enums.*;

import java.util.List;

@SuperBuilder

@AllArgsConstructor
@NoArgsConstructor
@Getter @Setter
@Entity
public class Artist extends User{
public class Artist {

@Id
private Long userId;

@OneToOne
@MapsId
@JoinColumn(name = "user_id")
private User user;

@Column(length = 500, nullable = true)
private String introduction;
Expand Down Expand Up @@ -57,4 +62,16 @@ public class Artist extends User{
public void updatePortfolioList(Portfolio portfolio){
this.portfolioList.add(portfolio);
}

public void updateProfileImg(String profileimg){
this.user.updateProfileImg(profileimg);
}

public void updateNickname(String nickname){
this.user.updateNickname(nickname);
}

public void updateGender(Gender gender){
this.user.updateGender(gender);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ public class FavoriteArtist extends BaseEntity {
@JoinColumn(name="user_id", nullable = false)
private Model model;

private Long artistId;
@OneToOne
private Artist artist;

}
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public class FavoritePortfolio extends BaseEntity {

@ManyToOne
@JoinColumn(name="user_id", nullable = false)
private User model;
private Model model;

@ManyToOne
@JoinColumn(name="portfolio_id", nullable = false)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,26 @@
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import lombok.experimental.SuperBuilder;
import org.meme.service.domain.entity.Reservation;
import org.meme.service.domain.entity.*;
import org.meme.service.domain.enums.Gender;
import org.meme.service.domain.enums.PersonalColor;
import org.meme.service.domain.enums.SkinType;

import java.util.List;

@SuperBuilder
@Getter @Setter
@AllArgsConstructor
@NoArgsConstructor
@Entity
public class Model extends User {
public class Model {

@Id
private Long userId;

@OneToOne
@MapsId
@JoinColumn(name = "user_id")
private User user;

@Enumerated(EnumType.STRING)
@Column(nullable = false)
Expand Down Expand Up @@ -47,12 +53,21 @@ public void updateFavoriteArtistList(FavoriteArtist artist){
public void updateFavoritePortfolioList(FavoritePortfolio portfolio){
this.favoritePortfolioList.add(portfolio);
}
public void updateReservationList(Reservation reservation){
this.reservationList.add(reservation);
}

public void updateReviewList(Review review){
this.reviewList.add(review);
}

public void updateProfileImg(String profileimg){
this.user.updateProfileImg(profileimg);
}

public void updateNickname(String nickname){
this.user.updateNickname(nickname);
}

public void updateGender(Gender gender){
this.user.updateGender(gender);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public class Review extends BaseEntity {

@ManyToOne
@JoinColumn(name="user_id", nullable = false)
private User model;
private Model model;

@OneToMany(cascade = CascadeType.ALL, mappedBy = "review")
private List<ReviewImg> reviewImgList;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,7 @@

import jakarta.persistence.*;
import jakarta.validation.constraints.NotNull;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.experimental.SuperBuilder;
import lombok.*;
import org.meme.service.domain.entity.Inquiry;
import org.meme.service.domain.enums.Gender;
import org.meme.service.domain.enums.Provider;
Expand All @@ -18,10 +14,10 @@
import java.util.List;
import java.util.Set;

@SuperBuilder @Getter
@Getter
@NoArgsConstructor
@AllArgsConstructor
@Inheritance(strategy = InheritanceType.JOINED)
//@Inheritance(strategy = InheritanceType.JOINED)
@Entity
public class User {

Expand Down Expand Up @@ -68,7 +64,7 @@ public class User {
private Provider provider;

@ElementCollection
@Builder.Default
// @Builder.Default
private Set<String> deviceTokens = new HashSet<>();

@OneToMany(cascade = CascadeType.ALL, mappedBy = "user")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,5 @@

@Repository
public interface ArtistRepository extends JpaRepository<Artist, Long> {
Optional<Artist> findByEmail(String email);

}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.meme.service.domain.repository;

import org.meme.service.domain.entity.Artist;
import org.meme.service.domain.entity.FavoriteArtist;
import org.meme.service.domain.entity.Model;
import org.springframework.data.jpa.repository.JpaRepository;
Expand All @@ -11,7 +12,7 @@
@Repository
public interface FavoriteArtistRepository extends JpaRepository<FavoriteArtist, Long> {
List<FavoriteArtist> findByModel(Model model);
boolean existsByModelAndArtistId(Model model, Long userId);
Optional<FavoriteArtist> findByModelAndArtistId(Model model, Long userId);
Long countByArtistId(Long artistId);
boolean existsByModelAndArtist(Model model, Artist artist);
Optional<FavoriteArtist> findByModelAndArtist(Model model, Artist artist);
Long countByArtist(Artist artist);
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,4 @@
@Repository
public interface ModelRepository extends JpaRepository<Model, Long> {

Optional<Model> findByEmail(String email);
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,13 @@
import org.springframework.stereotype.Service;
import org.meme.service.domain.entity.Artist;
import org.meme.service.common.exception.GeneralException;
import org.springframework.transaction.annotation.Transactional;

import java.util.Optional;

@Service
@RequiredArgsConstructor
@Transactional(readOnly = true)
public class ArtistService {
private final ArtistRepository artistRepository;
private final ModelRepository modelRepository;
Expand All @@ -29,7 +31,7 @@ public ArtistResponse.ArtistDto getArtistProfile(Long userId, Long artistId){
Artist artist = findArtistById(artistId);

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

Expand Down
Loading

0 comments on commit 9babf63

Please sign in to comment.