From 414804a1c023c6b8341761014907f085da70e783 Mon Sep 17 00:00:00 2001 From: daeun084 <030804jk@naver.com> Date: Tue, 1 Oct 2024 17:02:44 +0900 Subject: [PATCH 1/2] =?UTF-8?q?refactor:=20User=20-=20Artist/Model=20?= =?UTF-8?q?=EA=B4=80=EA=B3=84=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/converter/ArtistConverter.java | 14 ++++----- .../domain/converter/FavoriteConverter.java | 2 +- .../domain/converter/MypageConverter.java | 12 ++++---- .../domain/converter/PortfolioConverter.java | 14 ++++----- .../meme/service/domain/entity/Artist.java | 29 +++++++++++++++---- .../org/meme/service/domain/entity/Model.java | 29 ++++++++++++++----- .../org/meme/service/domain/entity/User.java | 12 +++----- 7 files changed, 70 insertions(+), 42 deletions(-) diff --git a/MEME-SERVICE/src/main/java/org/meme/service/domain/converter/ArtistConverter.java b/MEME-SERVICE/src/main/java/org/meme/service/domain/converter/ArtistConverter.java index 57f599d..9539d1c 100644 --- a/MEME-SERVICE/src/main/java/org/meme/service/domain/converter/ArtistConverter.java +++ b/MEME-SERVICE/src/main/java/org/meme/service/domain/converter/ArtistConverter.java @@ -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()) @@ -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(); diff --git a/MEME-SERVICE/src/main/java/org/meme/service/domain/converter/FavoriteConverter.java b/MEME-SERVICE/src/main/java/org/meme/service/domain/converter/FavoriteConverter.java index 79be7a9..527e149 100644 --- a/MEME-SERVICE/src/main/java/org/meme/service/domain/converter/FavoriteConverter.java +++ b/MEME-SERVICE/src/main/java/org/meme/service/domain/converter/FavoriteConverter.java @@ -31,7 +31,7 @@ public static FavoriteArtist toFavoriteArtist(Artist artist, Model model){ // favoritePortfolio public static FavoritePortfolio toFavoritePortfolio(Model model, Portfolio portfolio){ return FavoritePortfolio.builder() - .model(model) + .model(model.getUser()) .portfolio(portfolio) .build(); } diff --git a/MEME-SERVICE/src/main/java/org/meme/service/domain/converter/MypageConverter.java b/MEME-SERVICE/src/main/java/org/meme/service/domain/converter/MypageConverter.java index d53d197..434b8d9 100644 --- a/MEME-SERVICE/src/main/java/org/meme/service/domain/converter/MypageConverter.java +++ b/MEME-SERVICE/src/main/java/org/meme/service/domain/converter/MypageConverter.java @@ -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(); @@ -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()) diff --git a/MEME-SERVICE/src/main/java/org/meme/service/domain/converter/PortfolioConverter.java b/MEME-SERVICE/src/main/java/org/meme/service/domain/converter/PortfolioConverter.java index 1b40f97..f6afa2d 100644 --- a/MEME-SERVICE/src/main/java/org/meme/service/domain/converter/PortfolioConverter.java +++ b/MEME-SERVICE/src/main/java/org/meme/service/domain/converter/PortfolioConverter.java @@ -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()) @@ -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()) @@ -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()) @@ -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()) diff --git a/MEME-SERVICE/src/main/java/org/meme/service/domain/entity/Artist.java b/MEME-SERVICE/src/main/java/org/meme/service/domain/entity/Artist.java index 29f9c35..f5bc05f 100644 --- a/MEME-SERVICE/src/main/java/org/meme/service/domain/entity/Artist.java +++ b/MEME-SERVICE/src/main/java/org/meme/service/domain/entity/Artist.java @@ -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; @@ -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); + } } \ No newline at end of file diff --git a/MEME-SERVICE/src/main/java/org/meme/service/domain/entity/Model.java b/MEME-SERVICE/src/main/java/org/meme/service/domain/entity/Model.java index 09366c8..a115bfa 100644 --- a/MEME-SERVICE/src/main/java/org/meme/service/domain/entity/Model.java +++ b/MEME-SERVICE/src/main/java/org/meme/service/domain/entity/Model.java @@ -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) @@ -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); + } + } diff --git a/MEME-SERVICE/src/main/java/org/meme/service/domain/entity/User.java b/MEME-SERVICE/src/main/java/org/meme/service/domain/entity/User.java index 3fed211..c039e82 100644 --- a/MEME-SERVICE/src/main/java/org/meme/service/domain/entity/User.java +++ b/MEME-SERVICE/src/main/java/org/meme/service/domain/entity/User.java @@ -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; @@ -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 { @@ -68,7 +64,7 @@ public class User { private Provider provider; @ElementCollection - @Builder.Default +// @Builder.Default private Set deviceTokens = new HashSet<>(); @OneToMany(cascade = CascadeType.ALL, mappedBy = "user") From 4a5369871acb6348889aa5c3c8cc9a1bfc7d1192 Mon Sep 17 00:00:00 2001 From: daeun084 <030804jk@naver.com> Date: Fri, 4 Oct 2024 16:18:01 +0900 Subject: [PATCH 2/2] =?UTF-8?q?refactor:=20User=20-=20Favorite=20Artist/Po?= =?UTF-8?q?rtfolio=20=EC=97=B0=EA=B4=80=EA=B4=80=EA=B3=84=20=EC=88=98?= =?UTF-8?q?=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/converter/FavoriteConverter.java | 4 ++-- .../service/domain/converter/ReviewConverter.java | 10 +++++----- .../service/domain/entity/FavoriteArtist.java | 3 ++- .../service/domain/entity/FavoritePortfolio.java | 2 +- .../org/meme/service/domain/entity/Review.java | 2 +- .../domain/repository/ArtistRepository.java | 1 - .../repository/FavoriteArtistRepository.java | 7 ++++--- .../domain/repository/ModelRepository.java | 1 - .../service/domain/service/ArtistService.java | 4 +++- .../service/domain/service/FavoriteService.java | 15 ++++++++------- .../service/domain/service/MypageService.java | 3 ++- .../service/domain/service/PortfolioService.java | 3 ++- .../service/domain/service/ReviewService.java | 15 ++++++++------- 13 files changed, 38 insertions(+), 32 deletions(-) diff --git a/MEME-SERVICE/src/main/java/org/meme/service/domain/converter/FavoriteConverter.java b/MEME-SERVICE/src/main/java/org/meme/service/domain/converter/FavoriteConverter.java index 527e149..9507381 100644 --- a/MEME-SERVICE/src/main/java/org/meme/service/domain/converter/FavoriteConverter.java +++ b/MEME-SERVICE/src/main/java/org/meme/service/domain/converter/FavoriteConverter.java @@ -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(); } @@ -31,7 +31,7 @@ public static FavoriteArtist toFavoriteArtist(Artist artist, Model model){ // favoritePortfolio public static FavoritePortfolio toFavoritePortfolio(Model model, Portfolio portfolio){ return FavoritePortfolio.builder() - .model(model.getUser()) + .model(model) .portfolio(portfolio) .build(); } diff --git a/MEME-SERVICE/src/main/java/org/meme/service/domain/converter/ReviewConverter.java b/MEME-SERVICE/src/main/java/org/meme/service/domain/converter/ReviewConverter.java index 2bbd449..2edb9df 100644 --- a/MEME-SERVICE/src/main/java/org/meme/service/domain/converter/ReviewConverter.java +++ b/MEME-SERVICE/src/main/java/org/meme/service/domain/converter/ReviewConverter.java @@ -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()) @@ -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()) @@ -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()) @@ -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()) diff --git a/MEME-SERVICE/src/main/java/org/meme/service/domain/entity/FavoriteArtist.java b/MEME-SERVICE/src/main/java/org/meme/service/domain/entity/FavoriteArtist.java index 243d27d..491ca0f 100644 --- a/MEME-SERVICE/src/main/java/org/meme/service/domain/entity/FavoriteArtist.java +++ b/MEME-SERVICE/src/main/java/org/meme/service/domain/entity/FavoriteArtist.java @@ -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; } diff --git a/MEME-SERVICE/src/main/java/org/meme/service/domain/entity/FavoritePortfolio.java b/MEME-SERVICE/src/main/java/org/meme/service/domain/entity/FavoritePortfolio.java index ade0de1..e12d172 100644 --- a/MEME-SERVICE/src/main/java/org/meme/service/domain/entity/FavoritePortfolio.java +++ b/MEME-SERVICE/src/main/java/org/meme/service/domain/entity/FavoritePortfolio.java @@ -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) diff --git a/MEME-SERVICE/src/main/java/org/meme/service/domain/entity/Review.java b/MEME-SERVICE/src/main/java/org/meme/service/domain/entity/Review.java index 200510f..4b9bc90 100644 --- a/MEME-SERVICE/src/main/java/org/meme/service/domain/entity/Review.java +++ b/MEME-SERVICE/src/main/java/org/meme/service/domain/entity/Review.java @@ -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 reviewImgList; diff --git a/MEME-SERVICE/src/main/java/org/meme/service/domain/repository/ArtistRepository.java b/MEME-SERVICE/src/main/java/org/meme/service/domain/repository/ArtistRepository.java index c126b49..d39c4f8 100644 --- a/MEME-SERVICE/src/main/java/org/meme/service/domain/repository/ArtistRepository.java +++ b/MEME-SERVICE/src/main/java/org/meme/service/domain/repository/ArtistRepository.java @@ -8,6 +8,5 @@ @Repository public interface ArtistRepository extends JpaRepository { - Optional findByEmail(String email); } diff --git a/MEME-SERVICE/src/main/java/org/meme/service/domain/repository/FavoriteArtistRepository.java b/MEME-SERVICE/src/main/java/org/meme/service/domain/repository/FavoriteArtistRepository.java index b5e5cec..efec956 100644 --- a/MEME-SERVICE/src/main/java/org/meme/service/domain/repository/FavoriteArtistRepository.java +++ b/MEME-SERVICE/src/main/java/org/meme/service/domain/repository/FavoriteArtistRepository.java @@ -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; @@ -11,7 +12,7 @@ @Repository public interface FavoriteArtistRepository extends JpaRepository { List findByModel(Model model); - boolean existsByModelAndArtistId(Model model, Long userId); - Optional findByModelAndArtistId(Model model, Long userId); - Long countByArtistId(Long artistId); + boolean existsByModelAndArtist(Model model, Artist artist); + Optional findByModelAndArtist(Model model, Artist artist); + Long countByArtist(Artist artist); } diff --git a/MEME-SERVICE/src/main/java/org/meme/service/domain/repository/ModelRepository.java b/MEME-SERVICE/src/main/java/org/meme/service/domain/repository/ModelRepository.java index 8159b95..59a75c9 100644 --- a/MEME-SERVICE/src/main/java/org/meme/service/domain/repository/ModelRepository.java +++ b/MEME-SERVICE/src/main/java/org/meme/service/domain/repository/ModelRepository.java @@ -9,5 +9,4 @@ @Repository public interface ModelRepository extends JpaRepository { - Optional findByEmail(String email); } diff --git a/MEME-SERVICE/src/main/java/org/meme/service/domain/service/ArtistService.java b/MEME-SERVICE/src/main/java/org/meme/service/domain/service/ArtistService.java index 1c47207..8b7ff4b 100644 --- a/MEME-SERVICE/src/main/java/org/meme/service/domain/service/ArtistService.java +++ b/MEME-SERVICE/src/main/java/org/meme/service/domain/service/ArtistService.java @@ -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; @@ -29,7 +31,7 @@ public ArtistResponse.ArtistDto getArtistProfile(Long userId, Long artistId){ Artist artist = findArtistById(artistId); boolean isFavorite = false; - Optional favoriteArtist = favoriteArtistRepository.findByModelAndArtistId(model, artistId); + Optional favoriteArtist = favoriteArtistRepository.findByModelAndArtist(model, artist); if(favoriteArtist.isPresent()) isFavorite = true; diff --git a/MEME-SERVICE/src/main/java/org/meme/service/domain/service/FavoriteService.java b/MEME-SERVICE/src/main/java/org/meme/service/domain/service/FavoriteService.java index e4b1df4..6d788b9 100644 --- a/MEME-SERVICE/src/main/java/org/meme/service/domain/service/FavoriteService.java +++ b/MEME-SERVICE/src/main/java/org/meme/service/domain/service/FavoriteService.java @@ -1,6 +1,5 @@ package org.meme.service.domain.service; -import jakarta.transaction.Transactional; import lombok.RequiredArgsConstructor; import org.meme.service.common.exception.GeneralException; import org.meme.service.common.status.ErrorStatus; @@ -16,12 +15,14 @@ import org.springframework.data.domain.PageRequest; import org.springframework.data.domain.Pageable; import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; import java.util.List; import java.util.stream.Collectors; @Service @RequiredArgsConstructor +@Transactional(readOnly = true) public class FavoriteService { private final ModelRepository modelRepository; private final ArtistRepository artistRepository; @@ -42,9 +43,9 @@ public FavoriteResponse.FavoriteArtistPageDto getFavoriteArtist(Long modelId, in //관심 아티스트 리스트 List content = favoriteArtistPage.getContent().stream() .map(favoriteArtist -> { - Artist artist = findArtistById(favoriteArtist.getArtistId()); + Artist artist = favoriteArtist.getArtist(); //해당 아티스트를 관심 아티스트로 설정한 모델 수 카운트 - Long modelCount = favoriteArtistRepository.countByArtistId(artist.getUserId()); + Long modelCount = favoriteArtistRepository.countByArtist(artist); return ArtistConverter.toArtistSimpleDto(artist, modelCount); }) .collect(Collectors.toList()); @@ -71,7 +72,7 @@ public void addFavoriteArtist(FavoriteRequest.FavoriteArtistDto favoriteArtistDt Artist artist = findArtistById(favoriteArtistDto.getArtistId()); //이미 관심 아티스트가 존재하는 경우 - if (favoriteArtistRepository.existsByModelAndArtistId(model, artist.getUserId())) { + if (favoriteArtistRepository.existsByModelAndArtist(model, artist)) { throw new GeneralException(ErrorStatus.ALREADY_EXIST_FAVORITE_ARTIST); } @@ -102,7 +103,7 @@ public void deleteFavoriteArtist(FavoriteRequest.FavoriteArtistDto favoriteArtis Model model = findModelById(favoriteArtistDto.getModelId()); Artist artist = findArtistById(favoriteArtistDto.getArtistId()); - FavoriteArtist favoriteArtist = findFavoriteArtistByModelAndArtistId(model, artist.getUserId()); + FavoriteArtist favoriteArtist = findFavoriteArtistByModelAndArtist(model, artist); favoriteArtistRepository.delete(favoriteArtist); } @@ -136,8 +137,8 @@ private FavoritePortfolio findFavoritePortfolioByModelAndPortfolio(Model model, .orElseThrow(() -> new GeneralException(ErrorStatus.NOT_EXIST_FAVORITE_PORTFOLIO)); } - private FavoriteArtist findFavoriteArtistByModelAndArtistId(Model model, Long artistId){ - return favoriteArtistRepository.findByModelAndArtistId(model, artistId) + private FavoriteArtist findFavoriteArtistByModelAndArtist(Model model, Artist artist){ + return favoriteArtistRepository.findByModelAndArtist(model, artist) .orElseThrow(() -> new GeneralException(ErrorStatus.NOT_EXIST_FAVORITE_ARTIST)); } diff --git a/MEME-SERVICE/src/main/java/org/meme/service/domain/service/MypageService.java b/MEME-SERVICE/src/main/java/org/meme/service/domain/service/MypageService.java index 6982b85..f3b0cbc 100644 --- a/MEME-SERVICE/src/main/java/org/meme/service/domain/service/MypageService.java +++ b/MEME-SERVICE/src/main/java/org/meme/service/domain/service/MypageService.java @@ -1,6 +1,5 @@ package org.meme.service.domain.service; -import jakarta.transaction.Transactional; import lombok.RequiredArgsConstructor; import org.meme.service.common.exception.GeneralException; import org.meme.service.common.status.ErrorStatus; @@ -16,11 +15,13 @@ import org.meme.service.domain.dto.request.MypageRequest; import org.meme.service.domain.dto.response.MypageResponse; import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; import java.util.List; @Service @RequiredArgsConstructor +@Transactional(readOnly = true) public class MypageService { private final ModelRepository modelRepository; private final ArtistRepository artistRepository; diff --git a/MEME-SERVICE/src/main/java/org/meme/service/domain/service/PortfolioService.java b/MEME-SERVICE/src/main/java/org/meme/service/domain/service/PortfolioService.java index 018bc7f..a336681 100644 --- a/MEME-SERVICE/src/main/java/org/meme/service/domain/service/PortfolioService.java +++ b/MEME-SERVICE/src/main/java/org/meme/service/domain/service/PortfolioService.java @@ -1,6 +1,5 @@ package org.meme.service.domain.service; -import jakarta.transaction.Transactional; import lombok.RequiredArgsConstructor; import org.meme.service.domain.dto.request.PortfolioRequest; import org.meme.service.domain.dto.response.PortfolioResponse; @@ -15,6 +14,7 @@ import org.meme.service.domain.repository.PortfolioRepository; import org.meme.service.common.status.ErrorStatus; import org.meme.service.common.exception.GeneralException; +import org.springframework.transaction.annotation.Transactional; import java.util.ArrayList; @@ -23,6 +23,7 @@ @Service @RequiredArgsConstructor +@Transactional(readOnly = true) public class PortfolioService { private final ArtistRepository artistRepository; private final PortfolioRepository portfolioRepository; diff --git a/MEME-SERVICE/src/main/java/org/meme/service/domain/service/ReviewService.java b/MEME-SERVICE/src/main/java/org/meme/service/domain/service/ReviewService.java index f618efa..860971c 100644 --- a/MEME-SERVICE/src/main/java/org/meme/service/domain/service/ReviewService.java +++ b/MEME-SERVICE/src/main/java/org/meme/service/domain/service/ReviewService.java @@ -1,6 +1,5 @@ package org.meme.service.domain.service; -import jakarta.transaction.Transactional; import lombok.RequiredArgsConstructor; import org.meme.service.common.exception.GeneralException; import org.meme.service.domain.entity.*; @@ -16,13 +15,16 @@ import org.springframework.data.domain.Pageable; import org.springframework.stereotype.Service; import org.meme.service.common.status.ErrorStatus; +import org.springframework.transaction.annotation.Transactional; import java.util.ArrayList; import java.util.List; +import java.util.Objects; import java.util.Optional; @Service @RequiredArgsConstructor +@Transactional(readOnly = true) public class ReviewService { private final ModelRepository modelRepository; private final ReviewRepository reviewRepository; @@ -110,7 +112,7 @@ public ReviewResponse.ReviewDetailsDto updateReview(ReviewRequest.UpdateReviewDt Model model = findModelById(updateReviewDto.getModelId()); Review review = findReviewById(updateReviewDto.getReviewId()); - if (!review.getModel().equals(model)) + if (!review.getModel().getUserId().equals(model.getUserId())) throw new GeneralException(ErrorStatus.INVALID_MODEL_FOR_REVIEW); // 리뷰 이미지 수정 @@ -118,7 +120,7 @@ public ReviewResponse.ReviewDetailsDto updateReview(ReviewRequest.UpdateReviewDt updateReviewImgList(review, updateReviewDto.getReviewImgSrcList()); // 리뷰 수정 - updateReviewEntity(review, updateReviewDto); + updateReview(review, updateReviewDto); return ReviewConverter.toReviewDetailDto(review); } @@ -160,18 +162,17 @@ public void updateReviewImgList(Review review, List reviewImgSrcList){ public void deleteReview(ReviewRequest.DeleteReviewDto reviewDto){ Model model = findModelById(reviewDto.getModelId()); Review review = findReviewById(reviewDto.getReviewId()); - if(!review.getModel().equals(model)) + + if(!Objects.equals(review.getModel().getUserId(), model.getUserId())) throw new GeneralException(ErrorStatus.INVALID_MODEL_FOR_REVIEW); reviewRepository.delete(review); } private void validateReservationStatus(Reservation reservation) { - // 이미 리뷰 작성 완료 if (reservation.isReviewed()) throw new GeneralException(ErrorStatus.ALREADY_REVIEWED); - // 예약 미완료 if (!reservation.isCompleted()) throw new GeneralException(ErrorStatus.INVALID_REVIEW_REQUEST); } @@ -207,7 +208,7 @@ private Page getPage(int page, List list){ pageable, list.size()); } - private void updateReviewEntity(Review review, ReviewRequest.UpdateReviewDto updateReviewDto){ + private void updateReview(Review review, ReviewRequest.UpdateReviewDto updateReviewDto){ if(updateReviewDto.getStar() > 0) review.setStar(updateReviewDto.getStar()); if(updateReviewDto.getComment() != null)