Skip to content

Commit

Permalink
Merge pull request #165 from MEME-UMC/chore/#164
Browse files Browse the repository at this point in the history
[Chore] 예약 가능 시간 조회 API 수정
  • Loading branch information
yeopyeop-82 authored May 28, 2024
2 parents 0405f65 + 6325133 commit 1100a5f
Show file tree
Hide file tree
Showing 12 changed files with 50 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import umc.meme.shop.global.enums.DayOfWeek;
import umc.meme.shop.global.enums.Times;

import java.time.LocalDate;
import java.util.Date;
import java.util.List;

Expand All @@ -23,11 +24,11 @@ public class AvailableTimeRequestDto {
@NoArgsConstructor
@AllArgsConstructor
public static class AvailableTimeDto {
private Date date; //날짜
private LocalDate date; //날짜
private DayOfWeek dayOfWeek; //요일
private Times times;

public static AvailableTimeDto from(Date date, DayOfWeek dayOfWeek, Times times){
public static AvailableTimeDto from(LocalDate date, DayOfWeek dayOfWeek, Times times){
return AvailableTimeDto.builder()
.date(date)
.dayOfWeek(dayOfWeek)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@
import umc.meme.shop.global.enums.DayOfWeek;
import umc.meme.shop.global.enums.Times;

import java.util.Date;
import java.time.LocalDate;

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import umc.meme.shop.global.enums.DayOfWeek;
import umc.meme.shop.global.enums.Times;

import java.util.Date;
import java.time.LocalDate;

@Builder
@Getter
Expand All @@ -24,7 +24,7 @@ public class AvailableTime {
private Long availableTimeId;

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

@Enumerated(EnumType.STRING)
@Column(nullable = false)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@
import umc.meme.shop.global.enums.Times;
import umc.meme.shop.global.exception.GlobalException;

import java.util.Date;
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.util.List;
import java.util.Optional;

Expand Down Expand Up @@ -93,7 +94,11 @@ public void createArtist(ArtistProfileDto dto){
artist.tempMethod();

artistRepository.save(artist);
AvailableTimeRequestDto.AvailableTimeDto timeDto = AvailableTimeRequestDto.AvailableTimeDto.from(new Date(), DayOfWeek.MON, Times._15_00);

DateTimeFormatter dateFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
LocalDate date = LocalDate.parse("2024-05-27", dateFormatter);

AvailableTimeRequestDto.AvailableTimeDto timeDto = AvailableTimeRequestDto.AvailableTimeDto.from(date, DayOfWeek.MON, Times._15_00);
AvailableTime availableTime = AvailableTime.from(timeDto);
availableTime.updateArtist(artist);
availableTimeRepository.save(availableTime);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import org.springframework.web.bind.annotation.*;
import umc.meme.shop.domain.reservation.dto.request.AlterReservationDto;
import umc.meme.shop.domain.reservation.dto.request.ReservationRequestDto;
import umc.meme.shop.domain.reservation.dto.request.ReservationTimeRequestDto;
import umc.meme.shop.domain.reservation.service.ReservationService;
import umc.meme.shop.global.SuccessStatus;
import umc.meme.shop.global.response.ApiResponse;
Expand Down Expand Up @@ -35,9 +36,9 @@ public ApiResponse getArtistLocation(@PathVariable(name = "artistId") Long artis
}

@Operation(summary = "예약가능 시간 조회", description = "예약가능 시간 조회 기능을 수행하는 API입니다.")
@GetMapping("/{artistId}/time")
public ApiResponse getArtistTime(@PathVariable(name = "artistId") Long artistId){
return ApiResponse.SuccessResponse(SuccessStatus.ARTIST_TIME_GET, reservationService.getArtistTime(artistId));
@GetMapping("/time")
public ApiResponse getArtistTime(@RequestBody ReservationTimeRequestDto reservationTimeRequestDto){
return ApiResponse.SuccessResponse(SuccessStatus.ARTIST_TIME_GET, reservationService.getArtistTime(reservationTimeRequestDto));
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,6 @@
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotNull;
import lombok.Data;
import umc.meme.shop.global.enums.DayOfWeek;
import umc.meme.shop.global.enums.Times;

import java.util.Date;

@Data
public class ReservationRequestDto {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package umc.meme.shop.domain.reservation.dto.request;

import jakarta.validation.constraints.NotBlank;
import lombok.Data;

@Data
public class ReservationTimeRequestDto {
@NotBlank(message = "artistId를 입력해주세요")
private Long artistId;
@NotBlank(message = "날짜를 입력해주세요")
private String date; //yyyy-MM-dd
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,7 @@
import umc.meme.shop.global.enums.DayOfWeek;
import umc.meme.shop.global.enums.Times;

import java.sql.Time;
import java.util.Date;
import java.util.Map;
import java.time.LocalDate;

@Getter
@Builder
Expand All @@ -23,7 +21,7 @@ public class ReservationCompleteDto {
private String makeupName;
private String artistNickName;
private String location; //장소
private Date reservationDate; //날짜
private LocalDate reservationDate; //날짜
private DayOfWeek dayOfWeek; //요일
private Times times; //시간

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import umc.meme.shop.domain.reservation.entity.Reservation;
import umc.meme.shop.global.enums.*;

import java.util.Date;
import java.time.LocalDate;

@Getter
@Builder
Expand All @@ -27,7 +27,7 @@ public class ReservationDetailDto {
//예약 정보
private String portfolioName;
private Category category;
private Date reservationDate;
private LocalDate reservationDate;
private Times reservationTime;
private String location;
private int price;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@
import umc.meme.shop.global.enums.Times;
import umc.meme.shop.global.exception.GlobalException;

import java.util.Date;
import java.util.Map;
import java.time.LocalDate;

@Getter
@Builder
Expand All @@ -29,7 +28,7 @@ public class ReservationResponseDto {
private String makeupName;
private int price;

private Date reservationDate;
private LocalDate reservationDate;
private DayOfWeek dayOfWeek;
private Times times;
private String shopLocation; //샵 위치
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,16 @@
import umc.meme.shop.domain.portfolio.repository.PortfolioRepository;
import umc.meme.shop.domain.reservation.dto.request.AlterReservationDto;
import umc.meme.shop.domain.reservation.dto.request.ReservationRequestDto;
import umc.meme.shop.domain.reservation.dto.request.ReservationTimeRequestDto;
import umc.meme.shop.domain.reservation.dto.response.*;
import umc.meme.shop.domain.reservation.entity.Reservation;
import umc.meme.shop.domain.user.User;
import umc.meme.shop.global.enums.Status;
import umc.meme.shop.domain.reservation.repository.ReservationRepository;
import umc.meme.shop.global.ErrorStatus;
import umc.meme.shop.global.exception.GlobalException;

import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.util.List;
import java.util.stream.Collectors;

Expand All @@ -43,14 +45,21 @@ public ArtistLocationDto getArtistLocation(Long artistId){
}

//아티스트 예약 가능 시간 조회
public List<AvailableTimeDto> getArtistTime(Long artistId) {
Artist artist = artistRepository.findById(artistId)
public List<AvailableTimeDto> getArtistTime(ReservationTimeRequestDto requestDto) {
Artist artist = artistRepository.findById(requestDto.getArtistId())
.orElseThrow(() -> new GlobalException(ErrorStatus.NOT_EXIST_ARTIST));

// parse date format
DateTimeFormatter dateFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
String date_str = requestDto.getDate();
LocalDate date = LocalDate.parse(date_str, dateFormatter);

List<AvailableTime> availableTimeList = artist.getAvailableTimeList();
availableTimeList.removeIf(AvailableTime::isReservated);

// 해당 날짜에 해당하는 테이블만 리턴
return availableTimeList.stream()
.filter(t -> t.getDate().equals(date))
.map(AvailableTimeDto::from)
.toList();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import lombok.NoArgsConstructor;
import umc.meme.shop.domain.reservation.entity.Reservation;

import java.util.Date;
import java.time.LocalDate;

@Data
@AllArgsConstructor
Expand All @@ -18,7 +18,7 @@ public class ReviewAvailableListDto {
private String artistNickName;
private String makeupName;
private String portfolioImg;
private Date reservationDate;
private LocalDate reservationDate;
private String shopLocation; //샵 위치

public static ReviewAvailableListDto from(Reservation reservation){
Expand Down

0 comments on commit 1100a5f

Please sign in to comment.