Skip to content

Commit

Permalink
Merge pull request #110 from MEME-UMC/refactor/#106
Browse files Browse the repository at this point in the history
[Refactor] 코드 간소화
  • Loading branch information
daeun084 authored Feb 7, 2024
2 parents 685d46c + 0968496 commit 07327e6
Show file tree
Hide file tree
Showing 33 changed files with 293 additions and 319 deletions.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
@NoArgsConstructor
@AllArgsConstructor
public class ArtistProfileDto {
private Long artistId;
private Long userId;
private String profileImg;
private String nickname;
private Gender gender;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@ public class ArtistDto {

private WorkExperience workExperience;

private List<String> region;
private List<Region> region;

private List<String> specialization;
private List<Category> specialization;

private MakeupLocation makeupLocation;

Expand Down
51 changes: 21 additions & 30 deletions src/main/java/umc/meme/shop/domain/artist/entity/Artist.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@
import umc.meme.shop.domain.portfolio.entity.Portfolio;
import umc.meme.shop.global.enums.*;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;

Expand All @@ -22,33 +20,35 @@
@Entity
public class Artist extends User {

@Column(nullable = false, length = 500)
@Column(length = 500, nullable = true)
private String introduction;

@Enumerated(EnumType.STRING)
@Column(nullable = false)
@Column(nullable = true)
private WorkExperience workExperience;

@ElementCollection(fetch = FetchType.LAZY)
private List<String> region;
@Enumerated(EnumType.STRING)
@Column(nullable = true)
private List<Region> region;

@ElementCollection(fetch = FetchType.LAZY)
private List<String> specialization;
@Enumerated(EnumType.STRING)
@Column(nullable = true)
private List<Category> specialization;

@Enumerated(EnumType.STRING)
@Column(nullable = false)
@Column(nullable = true)
private MakeupLocation makeupLocation;

@Column(nullable = true)
private String shopLocation; //샵의 위치

@Column(nullable = true)
private Date inactiveDate;

@ElementCollection
@CollectionTable(name = "available_time_mapping",
joinColumns = {@JoinColumn(name = "user_id", referencedColumnName = "user_id")})
@MapKeyColumn(name = "day_of_week")
@MapKeyEnumerated(EnumType.STRING)
@Enumerated(EnumType.STRING)
@Column(nullable = true)
private Map<DayOfWeek, Times> availableDayOfWeekAndTime;
Expand All @@ -68,22 +68,10 @@ public void updateArtist(ArtistProfileDto request) {
this.introduction = request.getIntroduction();
if (request.getWorkExperience() != null)
this.workExperience = request.getWorkExperience();

//region mapping
if (request.getRegion() != null){
List<String> regionList = new ArrayList<>();
for(Region region : request.getRegion())
regionList.add(region.getValue());
this.region = regionList;
}

//specialization mapping
if (request.getSpecialization() != null){
List<String> specialization = new ArrayList<>();
for(Category category : request.getSpecialization())
specialization.add(category.getValue());
this.specialization = specialization;
}
if (request.getRegion() != null)
this.region = request.getRegion();
if (request.getSpecialization() != null)
this.specialization = request.getSpecialization();
if (request.getMakeupLocation() != null)
this.makeupLocation = request.getMakeupLocation();
if (request.getShopLocation() != null)
Expand All @@ -96,9 +84,12 @@ public void updatePortfolioList(Portfolio portfolio){
this.portfolioList.add(portfolio);
}

public void tempMethod(String email, String name, Provider provider){
this.email = email;
this.userName = name;
this.provider = provider;
public void tempMethod(){
this.username = "name";
this.email="";
this.password="";
this.role="ARTIST";
this.userStatus = UserStatus.ACTIVE;
this.provider = Provider.KAKAO;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,8 @@
import umc.meme.shop.domain.artist.entity.Artist;
import umc.meme.shop.domain.artist.repository.ArtistRepository;
import umc.meme.shop.global.ErrorStatus;
import umc.meme.shop.global.enums.Provider;
import umc.meme.shop.global.exception.GlobalException;

import java.util.List;


@Service
@RequiredArgsConstructor
Expand All @@ -22,7 +19,7 @@ public class ArtistService {
//아티스트 프로필 관리/수정
@Transactional
public void updateArtistProfile(ArtistProfileDto profileDto){
Artist artist = artistRepository.findById(profileDto.getArtistId())
Artist artist = artistRepository.findById(profileDto.getUserId())
.orElseThrow(() -> new GlobalException(ErrorStatus.NOT_EXIST_ARTIST));
artist.updateArtist(profileDto);
}
Expand All @@ -39,7 +36,7 @@ public ArtistDto getArtistProfile(Long artistId){
public void createArtist(ArtistProfileDto dto){
Artist artist = new Artist();
artist.updateArtist(dto);
artist.tempMethod("", "testName", Provider.KAKAO);
artist.tempMethod();
artistRepository.save(artist);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.springframework.data.domain.Page;
import umc.meme.shop.domain.artist.dto.response.SimpleArtistDto;
import umc.meme.shop.domain.favorite.entity.FavoriteArtist;

import java.util.List;

Expand All @@ -18,4 +20,14 @@ public class FavoriteArtistPageResponseDto {
private int pageSize; //페이지 크기
private int totalNumber; //전체 메이크업 개수
private int totalPage; //전체 페이지 개수

public static FavoriteArtistPageResponseDto from(Page<FavoriteArtist> page, List<SimpleArtistDto> content){
return FavoriteArtistPageResponseDto.builder()
.content(content)
.pageSize(page.getSize())
.currentPage(page.getNumber())
.totalNumber(page.getNumberOfElements())
.totalPage(page.getTotalPages())
.build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.springframework.data.domain.Page;
import umc.meme.shop.domain.favorite.entity.FavoritePortfolio;
import umc.meme.shop.domain.portfolio.dto.response.SimplePortfolioDto;

import java.util.List;
Expand All @@ -18,4 +20,18 @@ public class FavoritePortfolioResponsePageDto {
private int pageSize; //페이지 크기
private int totalNumber; //전체 메이크업 개수
private int totalPage; //전체 페이지 개수

public static FavoritePortfolioResponsePageDto from(Page<FavoritePortfolio> page){
List<SimplePortfolioDto> content = page.stream()
.map(SimplePortfolioDto::from)
.toList();

return FavoritePortfolioResponsePageDto.builder()
.content(content)
.pageSize(page.getSize())
.currentPage(page.getNumber())
.totalNumber(page.getNumberOfElements())
.totalPage(page.getTotalPages())
.build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

@Data
public class ModelProfileDto {
private Long modelId;
private Long userId;
private String profileImg;
private String nickname;
private Gender gender;
Expand Down
28 changes: 23 additions & 5 deletions src/main/java/umc/meme/shop/domain/model/entity/Model.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,12 @@
import umc.meme.shop.domain.favorite.entity.FavoritePortfolio;
import umc.meme.shop.domain.model.dto.request.ModelProfileDto;
import umc.meme.shop.global.enums.PersonalColor;
import umc.meme.shop.global.enums.Provider;
import umc.meme.shop.global.enums.SkinType;
import umc.meme.shop.domain.reservation.entity.Reservation;
import umc.meme.shop.domain.review.entity.Review;
import umc.meme.shop.domain.user.User;
import umc.meme.shop.global.enums.UserStatus;

import java.util.Date;
import java.util.List;
Expand All @@ -24,9 +26,6 @@
@Entity
public class Model extends User {

@Column(nullable = true, length = 500)
private String introduction;

@Enumerated(EnumType.STRING)
@Column(nullable = false)
private SkinType skinType;
Expand All @@ -35,8 +34,6 @@ public class Model extends User {
@Column(nullable = false)
private PersonalColor personalColor;

private Date inactive;

@OneToMany(cascade = CascadeType.ALL, mappedBy = "model")
private List<FavoritePortfolio> favoritePortfolioList;

Expand Down Expand Up @@ -81,4 +78,25 @@ public void updateReservationList(Reservation reservation){
public void updateReviewList(Review review){
this.reviewList.add(review);
}


//temp create model builder
public static Model from(ModelProfileDto dto){
return Model.builder()
.profileImg(dto.getProfileImg())
.nickname(dto.getNickname())
.gender(dto.getGender())
.skinType(dto.getSkinType())
.personalColor(dto.getPersonalColor())
.build();
}

public void tempMethod(){
this.username = "name";
this.email="";
this.password="";
this.role="ARTIST";
this.userStatus = UserStatus.ACTIVE;
this.provider = Provider.KAKAO;
}
}
Loading

0 comments on commit 07327e6

Please sign in to comment.