-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUpdateSpotDetailRequest.java
More file actions
103 lines (78 loc) · 3.75 KB
/
UpdateSpotDetailRequest.java
File metadata and controls
103 lines (78 loc) · 3.75 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
package com.acon.server.admin.api.request;
import com.acon.server.global.exception.BusinessException;
import com.acon.server.global.exception.ErrorType;
import com.acon.server.spot.domain.enums.SpotType;
import jakarta.validation.Valid;
import jakarta.validation.constraints.Min;
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotNull;
import jakarta.validation.constraints.Size;
import java.time.DayOfWeek;
import java.time.LocalTime;
import java.util.List;
import org.springframework.util.StringUtils;
public record UpdateSpotDetailRequest(
@Size(min = 1, max = 20, message = "spotName은 1자 이상 20자 이하이어야 합니다.")
String spotName,
@Size(min = 1, max = 100, message = "address는 1자 이상 100자 이하이어야 합니다.")
String address,
@Min(value = 0, message = "localAcornCount는 0 이상이어야 합니다.")
Integer localAcornCount,
@Min(value = 0, message = "basicAcornCount는 0 이상이어야 합니다.")
Integer basicAcornCount,
SpotType spotType,
List<@NotBlank(message = "spotFeature는 공백일 수 없습니다.") String> spotFeatureList,
@Size(min = 7, max = 7, message = "영업 시간은 7일 모두 입력해야 합니다.")
List<@Valid OpeningHourItem> openingHourList,
@Size(min = 1, message = "대표 메뉴는 최소 1개 이상 입력해야 합니다.")
List<@Valid SignatureMenu> signatureMenuList,
String priceFeature,
@Size(max = 10, message = "image는 최대 10장까지 업로드 가능합니다.")
List<@NotBlank(message = "imageUrl은 공백일 수 없습니다.") String> menuboardImageList,
@Size(max = 10, message = "image는 최대 10장까지 업로드 가능합니다.")
List<@NotBlank(message = "imageUrl은 공백일 수 없습니다.") String> spotImageList
) {
// Restaurant로 변경하는 경우 spotFeatureList와 priceFeature 필수 검증
public UpdateSpotDetailRequest {
if (spotType == SpotType.RESTAURANT) {
if (spotFeatureList == null || spotFeatureList.isEmpty()) {
throw new BusinessException(ErrorType.MISSING_REQUIRED_FIELDS_ERROR);
}
if (!StringUtils.hasText(priceFeature)) {
throw new BusinessException(ErrorType.MISSING_REQUIRED_FIELDS_ERROR);
}
}
}
public record OpeningHourItem(
@NotNull(message = "dayOfWeek는 필수입니다.")
DayOfWeek dayOfWeek,
@NotNull(message = "closed는 필수입니다.")
Boolean closed,
LocalTime startTime,
LocalTime endTime,
LocalTime breakStartTime,
LocalTime breakEndTime
) {
public OpeningHourItem {
if (!Boolean.TRUE.equals(closed)) {
// 휴무일이 아닌 경우 startTime과 endTime 필수 검증
if (startTime == null || endTime == null) {
throw new BusinessException(ErrorType.MISSING_REQUIRED_FIELDS_ERROR);
}
// break time 검증 (둘 다 있거나 둘 다 없어야 함)
if ((breakStartTime == null && breakEndTime != null) ||
(breakStartTime != null && breakEndTime == null)) {
throw new BusinessException(ErrorType.MISSING_REQUIRED_FIELDS_ERROR);
}
}
}
}
public record SignatureMenu(
@NotBlank(message = "name은 공백일 수 없습니다.")
String name,
@NotNull(message = "price는 필수입니다.")
@Min(value = -1, message = "price는 -1 이상이어야 합니다.")
Integer price
) {
}
}