Skip to content

Commit

Permalink
Merge pull request #145 from MEME-UMC/develop
Browse files Browse the repository at this point in the history
[Develop] Reservation, Available Time Refactoring 내용 Main 반영
  • Loading branch information
daeun084 authored Apr 2, 2024
2 parents b8ce9d4 + e004924 commit 46da6ba
Show file tree
Hide file tree
Showing 23 changed files with 286 additions and 105 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;
import umc.meme.shop.domain.artist.dto.request.ArtistProfileDto;
import umc.meme.shop.domain.artist.dto.request.AvailableTimeRequestDto;
import umc.meme.shop.domain.artist.service.ArtistService;
import umc.meme.shop.global.SuccessStatus;
import umc.meme.shop.global.response.ApiResponse;
Expand Down Expand Up @@ -33,10 +34,18 @@ public ApiResponse getArtistProfile(@PathVariable(name = "userId") Long userId,
return ApiResponse.SuccessResponse(SuccessStatus.ARTIST_PROFILE_GET, artistService.getArtistProfile(userId, artistId));
}


@Operation(summary = "아티스트 예약 가능 시간 편집")
@PatchMapping("/availabletime")
public ApiResponse patchAvailableTime(@RequestBody AvailableTimeRequestDto timeRequestDto){
artistService.patchArtistAvailableTime(timeRequestDto);
return ApiResponse.SuccessResponse(SuccessStatus.ARTIST_AVAILABLE_TIME_PATCH);

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

}

//temp method for Artist create
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import umc.meme.shop.domain.artist.dto.response.AvailableTimeDto;
import umc.meme.shop.domain.artist.entity.Artist;
import umc.meme.shop.global.enums.*;

import java.util.List;
import java.util.Map;

@Data
@NoArgsConstructor
Expand All @@ -25,7 +25,6 @@ public class ArtistProfileDto {
private List<Category> specialization;
private MakeupLocation makeupLocation;
private String shopLocation;
private Map<DayOfWeek, Times> availableDayOfWeek;

public static ArtistProfileDto from(Artist artist){
return ArtistProfileDto.builder()
Expand All @@ -39,7 +38,6 @@ public static ArtistProfileDto from(Artist artist){
.specialization(artist.getSpecialization())
.makeupLocation(artist.getMakeupLocation())
.shopLocation(artist.getShopLocation())
.availableDayOfWeek(artist.getAvailableDayOfWeekAndTime())
.build();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package umc.meme.shop.domain.artist.dto.request;

import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;
import umc.meme.shop.global.enums.DayOfWeek;
import umc.meme.shop.global.enums.Times;

import java.util.Date;
import java.util.List;

@Getter
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class AvailableTimeRequestDto {
private Long userId;
private List<AvailableTimeDto> availableTimeDtoList;

@Builder
@Getter
@NoArgsConstructor
@AllArgsConstructor
public static class AvailableTimeDto {
private Date date; //날짜
private DayOfWeek dayOfWeek; //요일
private Times times;

public static AvailableTimeDto from(Date date, DayOfWeek dayOfWeek, Times times){
return AvailableTimeDto.builder()
.date(date)
.dayOfWeek(dayOfWeek)
.times(times)
.build();
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;
import umc.meme.shop.domain.artist.dto.request.AvailableTimeRequestDto;
import umc.meme.shop.domain.artist.entity.Artist;
import umc.meme.shop.domain.portfolio.dto.response.SimplePortfolioDto;
import umc.meme.shop.global.enums.*;

import java.util.List;
import java.util.Map;

@Getter
@Builder
Expand All @@ -26,6 +26,8 @@ public class ArtistDto {

private String profileImg;

private String email;

private String introduction;

private WorkExperience workExperience;
Expand All @@ -38,13 +40,17 @@ public class ArtistDto {

private MakeupLocation makeupLocation;

private Map<DayOfWeek, Times> availableDayOfWeekAndTime;
private List<AvailableTimeDto> availableTimeList;

private List<SimplePortfolioDto> simplePortfolioDtoList;



public static ArtistDto from(Artist artist, boolean isFavorite){
List<AvailableTimeDto> availableTimeDtoList = artist.getAvailableTimeList()
.stream().map(AvailableTimeDto::from)
.toList();

List<SimplePortfolioDto> portfolioDtoList = artist.getPortfolioList()
.stream()
.map(SimplePortfolioDto::from)
Expand All @@ -56,12 +62,13 @@ public static ArtistDto from(Artist artist, boolean isFavorite){
.gender(artist.getGender())
.nickname(artist.getNickname())
.profileImg(artist.getProfileImg())
.email(artist.getEmail())
.introduction(artist.getIntroduction())
.workExperience(artist.getWorkExperience())
.region(artist.getRegion())
.specialization(artist.getSpecialization())
.makeupLocation(artist.getMakeupLocation())
.availableDayOfWeekAndTime(artist.getAvailableDayOfWeekAndTime())
.availableTimeList(availableTimeDtoList)
.simplePortfolioDtoList(portfolioDtoList)
.build();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package umc.meme.shop.domain.artist.dto.response;

import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;
import umc.meme.shop.domain.artist.entity.AvailableTime;
import umc.meme.shop.global.enums.DayOfWeek;
import umc.meme.shop.global.enums.Times;

import java.util.Date;

@Getter
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class AvailableTimeDto {
private Long availableTimeId;
private Date date; //날짜
private DayOfWeek dayOfWeek; //요일
private Times times;

static public AvailableTimeDto from(AvailableTime availableTime){
return AvailableTimeDto.builder()
.availableTimeId(availableTime.getAvailableTimeId())
.date(availableTime.getDate())
.dayOfWeek(availableTime.getDayOfWeek())
.times(availableTime.getTimes())
.build();
}
}
15 changes: 5 additions & 10 deletions src/main/java/umc/meme/shop/domain/artist/entity/Artist.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,8 @@ public class Artist extends User {
@Column(nullable = true)
private String shopLocation; //샵의 위치

@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;
@OneToMany(cascade = CascadeType.ALL, mappedBy = "artist")
private List<AvailableTime> availableTimeList;

@OneToMany(cascade = CascadeType.ALL, mappedBy = "artist")
private List<Portfolio> portfolioList;
Expand All @@ -76,20 +70,21 @@ public void updateArtist(ArtistProfileDto request) {
this.makeupLocation = request.getMakeupLocation();
if (request.getShopLocation() != null)
this.shopLocation = request.getShopLocation();
if (request.getAvailableDayOfWeek() != null)
this.availableDayOfWeekAndTime = request.getAvailableDayOfWeek();
}

public void updatePortfolioList(Portfolio portfolio){
this.portfolioList.add(portfolio);
}

public void updateAvailableTimeList(List<AvailableTime> availableTimeList){this.availableTimeList = availableTimeList;}

public void tempMethod(){
this.username = "name";
this.email="";
this.password="";
this.role="ARTIST";
this.userStatus = UserStatus.ACTIVE;
this.provider = Provider.KAKAO;
this.details = false;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
package umc.meme.shop.domain.artist.entity;

import jakarta.persistence.*;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;
import umc.meme.shop.domain.artist.dto.request.AvailableTimeRequestDto;
import umc.meme.shop.domain.reservation.entity.Reservation;
import umc.meme.shop.global.enums.DayOfWeek;
import umc.meme.shop.global.enums.Times;

import java.util.Date;

@Builder
@Getter
@AllArgsConstructor
@NoArgsConstructor
@Entity
public class AvailableTime {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "available_time_id")
private Long availableTimeId;

@Column(nullable = false)
private Date date; //날짜

@Enumerated(EnumType.STRING)
@Column(nullable = false)
private DayOfWeek dayOfWeek; //요일

@Enumerated(EnumType.STRING)
@Column(nullable = false)
private Times times; //시간

@Column(nullable = false, columnDefinition = "TINYINT(1) default 0")
private boolean isReservated; //해당 시간대 예약 여부

@ManyToOne
@JoinColumn(name = "user_id", nullable = false)
private Artist artist;

@OneToOne(mappedBy = "availableTime", fetch = FetchType.LAZY)
private Reservation reservation;

public void updateIsReservated(boolean isReservated){
this.isReservated = isReservated;
}

public void updateReservation(Reservation reservation){this.reservation = reservation;}

public void updateArtist(Artist artist){this.artist = artist;}

public static AvailableTime from(AvailableTimeRequestDto.AvailableTimeDto request){
return AvailableTime.builder()
.date(request.getDate())
.dayOfWeek(request.getDayOfWeek())
.times(request.getTimes())
.build();
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package umc.meme.shop.domain.artist.repository;

import org.springframework.data.jpa.repository.JpaRepository;
import umc.meme.shop.domain.artist.entity.AvailableTime;

public interface AvailableTimeRepository extends JpaRepository<AvailableTime, Long> {
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,23 @@
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import umc.meme.shop.domain.artist.dto.request.ArtistProfileDto;
import umc.meme.shop.domain.artist.dto.request.AvailableTimeRequestDto;
import umc.meme.shop.domain.artist.dto.response.ArtistDto;
import umc.meme.shop.domain.artist.entity.Artist;
import umc.meme.shop.domain.artist.entity.AvailableTime;
import umc.meme.shop.domain.artist.repository.ArtistRepository;
import umc.meme.shop.domain.artist.repository.AvailableTimeRepository;
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.enums.DayOfWeek;
import umc.meme.shop.global.enums.Times;
import umc.meme.shop.global.exception.GlobalException;

import java.util.Date;
import java.util.List;
import java.util.Optional;


Expand All @@ -23,6 +30,7 @@ public class ArtistService {
private final ArtistRepository artistRepository;
private final ModelRepository modelRepository;
private final FavoriteArtistRepository favoriteArtistRepository;
private final AvailableTimeRepository availableTimeRepository;

//아티스트 프로필 관리/수정
@Transactional
Expand Down Expand Up @@ -54,11 +62,28 @@ public ArtistDto getArtistProfile(Long userId, Long artistId){
return ArtistDto.from(artist, isFavorite);
}


//아티스트 예약 가능 시간 편집
@Transactional
public void patchArtistAvailableTime(AvailableTimeRequestDto dto){
Artist artist = artistRepository.findById(dto.getUserId())
.orElseThrow(() -> new GlobalException(ErrorStatus.NOT_EXIST_ARTIST));

//TODO: 기존 예약 시간 테이블 유치 여부 논의

//새로운 예약 시간 설정
List<AvailableTime> availableTimeList = dto.getAvailableTimeDtoList().stream()
.map(AvailableTime::from)
.peek(availableTime -> availableTime.updateArtist(artist))
.toList();
artist.updateAvailableTimeList(availableTimeList);

//아티스트 프로필 조회 (Artist Ver.)
public ArtistDto getArtistProfileFromArtist(Long artistId){
Artist artist = artistRepository.findById(artistId)
.orElseThrow(() -> new GlobalException(ErrorStatus.NOT_EXIST_ARTIST));
return ArtistDto.from(artist, true);

}

//temp method for create Artist
Expand All @@ -67,7 +92,12 @@ public void createArtist(ArtistProfileDto dto){
Artist artist = new Artist();
artist.updateArtist(dto);
artist.tempMethod();

artistRepository.save(artist);
AvailableTimeRequestDto.AvailableTimeDto timeDto = AvailableTimeRequestDto.AvailableTimeDto.from(new Date(), DayOfWeek.MON, Times._15_00);
AvailableTime availableTime = AvailableTime.from(timeDto);
availableTime.updateArtist(artist);
availableTimeRepository.save(availableTime);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,15 @@
import umc.meme.shop.global.enums.Times;

import java.util.Date;
import java.util.Map;

@Data
public class ReservationRequestDto {
@NotBlank(message = "modelId를 입력해주세요")
private Long modelId;
@NotBlank(message = "portfolioId를 입력해주세요")
private Long portfolioId;
@NotBlank(message = "예약날짜를 입력해주세요")
private Date reservationDate;
@NotNull(message = "예약시간을 입력해주세요")
private Map<DayOfWeek, Times> reservationDayOfWeekAndTime;
@NotBlank(message = "availableTimeId를 입력해주세요")
private Long availableTimeId;
@NotNull(message = "예약 장소를 입력해주세요")
private String location;
}
Loading

0 comments on commit 46da6ba

Please sign in to comment.