-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgramCommandService.java
More file actions
602 lines (517 loc) · 25.4 KB
/
Copy pathProgramCommandService.java
File metadata and controls
602 lines (517 loc) · 25.4 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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
package com.firstticket.programservice.application.service;
import java.time.LocalDateTime;
import java.util.List;
import java.util.Map;
import java.util.UUID;
import java.util.stream.Collectors;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import com.firstticket.common.exception.BusinessException;
import com.firstticket.common.response.CommonErrorCode;
import com.firstticket.programservice.application.dto.command.AddPriceGradeCommand;
import com.firstticket.programservice.application.dto.command.AddSectionCapacityCommand;
import com.firstticket.programservice.application.dto.command.CreateProgramCommand;
import com.firstticket.programservice.application.dto.command.CreateScheduleCommand;
import com.firstticket.programservice.application.dto.command.UpdateProgramDraftCommand;
import com.firstticket.programservice.application.dto.command.UpdateProgramOnSaleCommand;
import com.firstticket.programservice.application.dto.command.UpdateScheduleCommand;
import com.firstticket.programservice.application.dto.result.ProgramResult;
import com.firstticket.programservice.domain.PriceGrade;
import com.firstticket.programservice.domain.Program;
import com.firstticket.programservice.domain.ProgramRepository;
import com.firstticket.programservice.domain.ProgramStatus;
import com.firstticket.programservice.domain.ProgramType;
import com.firstticket.programservice.domain.Schedule;
import com.firstticket.programservice.domain.ScheduleRepository;
import com.firstticket.programservice.domain.event.ProgramEventPublisher;
import com.firstticket.programservice.domain.event.ScheduleCreatedEventData;
import com.firstticket.programservice.domain.exception.ProgramErrorCode;
import com.firstticket.programservice.domain.exception.ProgramException;
import com.firstticket.programservice.domain.service.VenueProvider;
import com.firstticket.programservice.domain.service.dto.SectionValidationData;
import com.firstticket.programservice.domain.service.dto.VenueValidationData;
import lombok.RequiredArgsConstructor;
/**
* 프로그램 도메인 커맨드 서비스.
* 트랜잭션·흐름을 조율하며 도메인 메서드를 호출한다.
* 도메인 로직은 도메인 객체에 위임하고, 이 서비스는 흐름만 조율한다.
*
* 권한 검증:
* HOST·ADMIN 역할 검증은 Controller 계층(AuthContext)에서 처리한다.
* 이 서비스에서는 프로그램 소유자(createdBy) 검증만 담당한다.
*/
@Service
@RequiredArgsConstructor
@Transactional
public class ProgramCommandService {
private final ProgramRepository programRepository;
private final ScheduleRepository scheduleRepository;
private final VenueProvider venueProvider;
private final ProgramEventPublisher programEventPublisher;
// ----- 프로그램 생성 -------------------------------
/**
* 프로그램 생성 (P-01).
* 초기 상태는 항상 DRAFT.
* 새로 생성된 Program은 schedules가 빈 리스트로 초기화되므로
* findByIdWithSchedules() 없이 바로 반환한다.
*
* 프로그램 생성 후 ProgramCreatedEvent를 발행한다.
* 대기열 서비스가 수신하여 프로그램 대기열을 초기화한다.
* 생성 시점에는 스케줄이 없으므로 openAt·closeAt은 null로 발행한다.
*/
public ProgramResult createProgram(CreateProgramCommand command) {
validateCreateProgramCommand(command);
// String → ProgramType 변환 — 잘못된 값이면 400 반환
ProgramType type;
try {
type = ProgramType.valueOf(command.type());
} catch (IllegalArgumentException e) {
throw new ProgramException(ProgramErrorCode.INVALID_PROGRAM_TYPE);
}
Program program = Program.create(command.title(), command.category(), command.theme(), type,
command.region(), command.posterUrl(), command.description());
Program saved = programRepository.save(program);
programEventPublisher.publishProgramCreated(saved);
return ProgramResult.from(saved);
}
// --- 프로그램 수정 -------------------------------------
/**
* DRAFT 상태 프로그램 정보 수정 (P-02).
* 제목·카테고리·테마·포스터·설명 수정 가능.
* ProgramResult에 schedules가 포함되므로
* findByIdWithSchedules()로 조회한다.
*/
public ProgramResult updateProgramDraft(UUID requesterId, UpdateProgramDraftCommand command) {
Program program = findProgramWithSchedulesOrThrow(command.programId());
checkOwner(program, requesterId);
program.updateDraft(command.title(), command.category(), command.theme(), command.posterUrl(),
command.description());
return ProgramResult.from(program);
}
/**
* ON_SALE 상태 프로그램 정보 수정 (P-02).
* 포스터·설명만 수정 가능.
* ProgramResult에 schedules가 포함되므로
* findByIdWithSchedules()로 조회한다.
*/
public ProgramResult updateProgramOnSale(UUID requesterId, UpdateProgramOnSaleCommand command) {
Program program = findProgramWithSchedulesOrThrow(command.programId());
checkOwner(program, requesterId);
program.updateOnSale(command.posterUrl(), command.description());
return ProgramResult.from(program);
}
// --- 프로그램 상태 전이 -------------------------------------
/**
* 프로그램 판매 시작 (P-06).
* DRAFT → ON_SALE 전이.
* 최소 1개의 스케줄이 있어야 하므로 schedules 로딩이 필요하다.
*
* 이 시점에 모든 스케줄·가격 등급·구역 수용량이 확정되므로
* schedule.created와 program.time.updated를 함께 발행한다.
*
* schedule.created: 좌석 서비스가 수신하여 BookingSeat 생성
* → createSchedule() 시점이 아닌 여기서 발행하는 이유:
* PriceGrade는 addPriceGrade()로 별도 등록되므로
* createSchedule() 시점에는 price가 확정되지 않는다.
*
* program.time.updated: 대기열 서비스가 수신하여 openAt·closeAt 등록
*/
public void publishProgram(UUID requesterId, UUID programId) {
Program program = findProgramWithSchedulesOrThrow(programId);
checkOwner(program, requesterId);
program.publish();
// venueId → VenueValidationData 캐시
// 동일 venueId를 가진 스케줄이 여러 개여도 Feign 호출은 1번만
Map<UUID, VenueValidationData> venueValidationCache = program.getSchedules().stream()
.map(Schedule::getVenueId)
.distinct()
.collect(Collectors.toMap(
venueId -> venueId,
venueId -> venueProvider.validateVenue(venueId, program.getType())
));
program.getSchedules().forEach(schedule -> {
// venue 구역 정보 조회 — seatTemplates 구성용
VenueValidationData venueValidation =
venueValidationCache.get(schedule.getVenueId());
// sectionId → price 맵 구성
Map<UUID, Integer> sectionPriceMap = schedule.getPriceGrades().stream()
.filter(pg -> pg.getSectionId() != null)
.collect(Collectors.toMap(
PriceGrade::getSectionId,
PriceGrade::getPrice,
(existing, incoming) -> existing
));
List<ScheduleCreatedEventData.SeatTemplate> seatTemplates =
venueValidation.sections().stream()
.map(section -> ScheduleCreatedEventData.SeatTemplate.from(
section,
sectionPriceMap.getOrDefault(section.sectionId(), 0)
))
.toList();
// schedule.created 발행 — 좌석 서비스 BookingSeat 생성
programEventPublisher.publishScheduleCreated(program, schedule, seatTemplates);
// program.time.updated 발행 — 대기열 서비스 openAt·closeAt 등록
programEventPublisher.publishProgramTimeUpdated(program, schedule);
});
}
/**
* 프로그램 취소 (P-03).
* scheduleIds 수집이 필요하므로 schedules 로딩이 필요하다.
* 반환값이 없으므로 findProgramWithSchedulesOrThrow() 사용.
*
* program.cancelled 발행 — 대기열 서비스 대기열 종료
*/
public void cancelProgram(UUID requesterId, UUID programId) {
Program program = findProgramWithSchedulesOrThrow(programId);
checkOwner(program, requesterId);
program.cancel();
// program.cancelled 발행
programEventPublisher.publishProgramCancelled(program);
}
/**
* 프로그램 종료 (P-06).
* ON_SALE·SOLD_OUT → CLOSED 전이.
* 모든 스케줄의 공연 종료 시각이 현재 시각 이전인지 확인한다.
* 하나라도 아직 끝나지 않은 스케줄이 있으면 CLOSED 전환을 차단한다.
*/
public void closeProgram(UUID requesterId, UUID programId) {
Program program = findProgramWithSchedulesOrThrow(programId);
checkOwner(program, requesterId);
// now()를 도메인 메서드에 주입
program.close(LocalDateTime.now());
}
/**
* 프로그램 삭제 (P-03).
* 예매 내역이 없는 DRAFT 상태에서만 물리 삭제.
* 상태 확인 후 삭제하고 반환값이 없으므로 findProgramOrThrow() 사용.
*
* DRAFT 이외 상태별 차단 정책:
* - ON_SALE·CANCELLED·CLOSED : 판매가 시작된 이후이므로 삭제 불가
* - SOLD_OUT : 매진 상태이므로 삭제 불가
*/
public void deleteProgram(UUID requesterId, UUID programId) {
Program program = findProgramOrThrow(programId);
checkOwner(program, requesterId);
if (program.getStatus() != ProgramStatus.DRAFT) {
// SOLD_OUT: 매진 처리된 프로그램은 삭제 불가
if (program.getStatus() == ProgramStatus.SOLD_OUT) {
throw new ProgramException(ProgramErrorCode.PROGRAM_NOT_DELETABLE);
}
// ON_SALE·CANCELLED·CLOSED: 판매가 시작된 이후 삭제 불가
throw new ProgramException(ProgramErrorCode.PROGRAM_NOT_DELETABLE_IN_PROCESS);
}
programRepository.delete(program);
}
// ------ 스케줄 관련 --------------------------------------
/**
* 스케줄 등록 (P-07).
* 처리 순서:
* 1. 공연장 존재 여부 확인 (VenueProvider)
* 2. 공연장 시간 겹침 검증 (비관적 락 — V-04)
* 3. 스케줄 생성
*/
public ProgramResult createSchedule(UUID requesterId, CreateScheduleCommand command) {
validateCreateScheduleCommand(command);
Program program = findProgramWithSchedulesOrThrow(command.programId());
checkOwner(program, requesterId);
// 기존: venueProvider.validateVenueExists(command.venueId());
// 변경: venue 존재 확인 + totalCapacity 상한 검증을 한 번에 처리
VenueValidationData venueValidation =
venueProvider.validateVenue(command.venueId(), program.getType());
// 2. 공연장 시간 겹침 검증
// 비관적 락으로 동시 요청 간 TOCTOU 방지 (V-04)
// DB 레벨 exclusion constraint(tsrange)와 이중 방어
boolean hasOverlap = !scheduleRepository.findOverlappingSchedulesWithLock(command.venueId(),
command.eventStartAt(), command.eventEndAt()).isEmpty();
if (hasOverlap) {
throw new ProgramException(ProgramErrorCode.VENUE_TIME_CONFLICT);
}
// 3. 스케줄 생성
program.addSchedule(command.venueId(), command.eventStartAt(), command.eventEndAt(), command.saleStartAt(),
command.saleEndAt(), venueValidation.totalCapacity(), LocalDateTime.now());
programRepository.save(program);
return ProgramResult.from(program);
}
/**
* 스케줄 수정.
* - DRAFT: 전체 필드 수정 가능
* - ON_SALE·SOLD_OUT: eventStartAt, eventEndAt, totalCapacity만 수정 가능
* - CANCELLED·CLOSED: 수정 불가
*/
public ProgramResult updateSchedule(UUID requesterId, UpdateScheduleCommand command) {
validateUpdateScheduleCommand(command);
Program program = findProgramWithSchedulesOrThrow(command.programId());
checkOwner(program, requesterId);
Schedule schedule = findScheduleInProgram(program, command.scheduleId());
Integer newTotalCapacity = null;
// venueId가 변경되는 경우에만 존재 여부 확인
if (command.venueId() != null) {
VenueValidationData venueValidation =
venueProvider.validateVenue(command.venueId(), program.getType());
newTotalCapacity = venueValidation.totalCapacity();
// 변경된 venueId 기준으로 시간 겹침 검증
// 자기 자신은 제외하고 검증
UUID targetVenueId = command.venueId();
LocalDateTime targetStart = command.eventStartAt() != null
? command.eventStartAt() : schedule.getEventStartAt();
LocalDateTime targetEnd = command.eventEndAt() != null
? command.eventEndAt() : schedule.getEventEndAt();
boolean hasOverlap = scheduleRepository
.findOverlappingSchedulesWithLock(targetVenueId, targetStart, targetEnd)
.stream()
.anyMatch(s -> !s.getId().equals(command.scheduleId())); // 자기 자신 제외
if (hasOverlap) {
throw new ProgramException(ProgramErrorCode.VENUE_TIME_CONFLICT);
}
}
// schedule.update() 단일 호출
// totalCapacity: venueId 변경 시 → venue 계산값, 미변경 시 → null (기존 값 유지)
schedule.update(
command.eventStartAt(), command.eventEndAt(),
command.saleStartAt(), command.saleEndAt(),
command.venueId(), newTotalCapacity,
LocalDateTime.now()
);
// 판매 기간이 변경된 경우에만 발행
boolean salePeriodChanged =
command.saleStartAt() != null || command.saleEndAt() != null;
if (salePeriodChanged) {
programEventPublisher.publishProgramTimeUpdated(program, schedule);
}
return ProgramResult.from(program);
}
/**
* 스케줄 삭제.
* DRAFT 상태에서만 삭제 가능.
* 반환값이 없으므로 findProgramWithSchedulesOrThrow() 사용
* (removeSchedule()이 schedules 컬렉션을 직접 수정하기 때문).
*
*/
public void deleteSchedule(UUID requesterId, UUID programId, UUID scheduleId) {
Program program = findProgramWithSchedulesOrThrow(programId);
checkOwner(program, requesterId);
program.removeSchedule(scheduleId);
}
// ---- 가격 등급 관련 --------------------------------------
/**
* 가격 등급 추가.
* - SEATED·STANDING: sectionId 필수
* - FREE: sectionId null
* PriceGrade는 Schedule 하위이므로
* findByIdWithSchedules()로 schedules 컬렉션을 로딩해야 한다.
*
* now()를 도메인 메서드에 주입하여 예매 시작 전 여부를 도메인에서 검증한다.
* LocalDateTime.now()는 Application 계층의 책임으로 한정한다.
*/
public ProgramResult addPriceGrade(UUID requesterId, AddPriceGradeCommand command) {
validateAddPriceGradeCommand(command);
Program program = findProgramWithSchedulesOrThrow(command.programId());
checkOwner(program, requesterId);
Schedule schedule = findScheduleInProgram(program, command.scheduleId());
if (command.sectionId() != null) {
SectionValidationData sectionValidation =
venueProvider.validateSection(schedule.getVenueId(), command.sectionId());
if (!sectionValidation.seatType().equals(program.getType().name())) {
throw new ProgramException(ProgramErrorCode.SECTION_TYPE_MISMATCH);
}
}
// now()를 도메인 메서드에 주입 — 도메인이 직접 now()를 참조하지 않도록 한다
schedule.addPriceGrade(
command.sectionId(),
command.gradeLabel(),
command.price(),
LocalDateTime.now()
);
return ProgramResult.from(program);
}
/**
* 가격 등급 삭제.
* 삭제 후 재등록 방식으로 처리한다.
*/
public void removePriceGrade(UUID requesterId, UUID programId, UUID scheduleId, String gradeLabel) {
Program program = findProgramWithSchedulesOrThrow(programId);
checkOwner(program, requesterId);
Schedule schedule = findScheduleInProgram(program, scheduleId);
schedule.removePriceGrade(gradeLabel, LocalDateTime.now());
ProgramResult.from(program);
}
// ---- 구역별 인원 관련 ---------------------------------------
/**
* 구역별 인원 추가 (STANDING·FREE 전용).
*
* 처리 순서:
* 1. 소유자 검증
* 2. VenueProvider로 Section.capacity 상한 검증
* 3. 비관적 락으로 Schedule 조회 — 합계 불변식(sum ≤ totalCapacity) 보호
* 4. 구역별 인원 추가
*
* 비관적 락 사용 이유:
* 동시 요청이 메모리 중복 검사를 통과한 뒤 합계를 초과하는 race condition 방지.
* @Version 낙관적 락과 이중 방어 구조.
*/
public ProgramResult addSectionCapacity(UUID requesterId, AddSectionCapacityCommand command) {
validateAddSectionCapacityCommand(command);
Program program = findProgramWithSchedulesOrThrow(command.programId());
checkOwner(program, requesterId);
// 비관적 락으로 합계 불변식(sum ≤ totalCapacity) 보호
// findProgramWithSchedulesOrThrow()와 별도로 락을 걸어야 하므로
// ScheduleRepository.findByIdWithLock() 사용
Schedule schedule = scheduleRepository.findByIdWithLock(command.scheduleId())
.orElseThrow(() -> new ProgramException(ProgramErrorCode.SCHEDULE_NOT_FOUND));
// Schedule이 해당 Program에 속하는지 검증
// 다른 Program의 Schedule을 수정하는 cross-program 수정 방지
if (!schedule.getProgram().getId().equals(program.getId())) {
throw new ProgramException(
ProgramErrorCode.SCHEDULE_DOES_NOT_BELONG_TO_PROGRAM);
}
SectionValidationData sectionValidation =
venueProvider.validateSection(schedule.getVenueId(), command.sectionId());
// section의 SeatType과 program의 ProgramType 일치 여부 검증
if (!sectionValidation.seatType().equals(program.getType().name())) {
throw new ProgramException(ProgramErrorCode.SECTION_TYPE_MISMATCH);
}
// Section.capacity 상한 검증 (기존 getSectionCapacity() 대체)
// sectionValidation.capacity()가 이미 SEATED→rowCount×colCount / STANDING·FREE→capacity 를 반환
if (command.capacity() > sectionValidation.capacity()) {
throw new ProgramException(ProgramErrorCode.SECTION_CAPACITY_EXCEEDS_VENUE_LIMIT);
}
schedule.addSectionCapacity(command.sectionId(), command.capacity(), LocalDateTime.now());
return ProgramResult.from(program);
}
/**
* 구역별 인원 삭제.
* 삭제 후 재등록 방식으로 처리한다.
*/
public ProgramResult removeSectionCapacity(UUID requesterId, UUID programId, UUID scheduleId, UUID sectionId) {
Program program = findProgramWithSchedulesOrThrow(programId);
checkOwner(program, requesterId);
Schedule schedule = findScheduleInProgram(program, scheduleId);
schedule.removeSectionCapacity(sectionId, LocalDateTime.now());
return ProgramResult.from(program);
}
// --- private 헬퍼 ---------------------------------------
/**
* 프로그램 단건 조회 — schedules 미로딩.
* 사용처: 반환값이 없고 schedules가 불필요한 경우
* - closeProgram: 상태만 변경
* - deleteProgram: 상태 확인 후 삭제
*/
private Program findProgramOrThrow(UUID programId) {
return programRepository.findById(programId)
.orElseThrow(() -> new ProgramException(ProgramErrorCode.PROGRAM_NOT_FOUND));
}
/**
* 프로그램 단건 조회 — schedules JOIN FETCH.
* 사용처:
* - ProgramResult 반환하는 모든 메서드 (schedules 포함)
* - schedules 컬렉션을 직접 수정하는 메서드
* (addSchedule, removeSchedule, addPriceGrade 등)
* - publish: schedules 비어있는지 확인 필요
* - cancel: scheduleIds 수집 필요
*/
private Program findProgramWithSchedulesOrThrow(UUID programId) {
return programRepository.findByIdWithSchedules(programId)
.orElseThrow(() -> new ProgramException(ProgramErrorCode.PROGRAM_NOT_FOUND));
}
/**
* Program 내에서 Schedule 단건 조회.
* schedules가 이미 로딩된 상태에서 호출해야 한다.
* findProgramWithSchedulesOrThrow() 호출 이후에만 사용한다.
*/
private Schedule findScheduleInProgram(Program program, UUID scheduleId) {
return program.getSchedules()
.stream()
.filter(s -> s.getId().equals(scheduleId))
.findFirst()
.orElseThrow(() -> new ProgramException(ProgramErrorCode.INVALID_SCHEDULE_ID));
}
/**
* 프로그램 소유자 검증.
* HOST는 자신이 생성한 프로그램만 수정·삭제할 수 있다.
* ADMIN은 Controller에서 이미 통과했으므로 여기선 createdBy만 비교한다.
*/
private void checkOwner(Program program, UUID requesterId) {
validateRequesterId(requesterId);
if (!program.getCreatedBy().equals(requesterId)) {
throw new BusinessException(CommonErrorCode.FORBIDDEN);
}
}
// ── private 검증 메서드 ───────────────────────────────────────────────
/**
* 프로그램 생성 커맨드 검증.
* Presentation 계층의 @Valid와 이중 방어.
* null·blank 검증은 도메인에서도 수행하지만
* Application 계층에서 먼저 차단하여 명확한 에러 메시지를 반환한다.
*/
private void validateCreateProgramCommand(CreateProgramCommand command) {
if (command.title() == null || command.title().isBlank()) {
throw new ProgramException(ProgramErrorCode.INVALID_TITLE);
}
if (command.category() == null || command.category().isBlank()) {
throw new ProgramException(ProgramErrorCode.INVALID_CATEGORY);
}
if (command.theme() == null || command.theme().isBlank()) {
throw new ProgramException(ProgramErrorCode.INVALID_THEME);
}
if (command.type() == null) {
throw new ProgramException(ProgramErrorCode.INVALID_PROGRAM_TYPE);
}
if (command.region() == null || command.region().isBlank()) {
throw new ProgramException(ProgramErrorCode.INVALID_REGION);
}
}
private void validateRequesterId(UUID requesterId) {
if (requesterId == null) {
throw new BusinessException(CommonErrorCode.UNAUTHORIZED);
}
}
/**
* 스케줄 생성 커맨드 검증.
* venueId, 기간 필드 null 검증 및 totalCapacity 범위 검증.
*/
private void validateCreateScheduleCommand(CreateScheduleCommand command) {
if (command.venueId() == null) {
throw new ProgramException(ProgramErrorCode.INVALID_VENUE_ID);
}
if (command.eventStartAt() == null || command.eventEndAt() == null) {
throw new ProgramException(ProgramErrorCode.INVALID_EVENT_PERIOD);
}
if (command.saleStartAt() == null || command.saleEndAt() == null) {
throw new ProgramException(ProgramErrorCode.INVALID_SALE_PERIOD);
}
}
/**
* 스케줄 수정 커맨드 검증.
* scheduleId null 검증 및 totalCapacity 범위 검증.
* 기간 필드는 부분 업데이트이므로 null 허용.
*/
private void validateUpdateScheduleCommand(UpdateScheduleCommand command) {
if (command.scheduleId() == null) {
throw new ProgramException(ProgramErrorCode.SCHEDULE_NOT_FOUND);
}
}
/**
* 가격 등급 추가 커맨드 검증.
* gradeLabel null·blank 검증 및 price 범위 검증.
*/
private void validateAddPriceGradeCommand(AddPriceGradeCommand command) {
if (command.gradeLabel() == null || command.gradeLabel().isBlank()) {
throw new ProgramException(ProgramErrorCode.INVALID_GRADE_LABEL);
}
if (command.price() < 0) {
throw new ProgramException(ProgramErrorCode.INVALID_PRICE);
}
}
/**
* 구역별 인원 추가 커맨드 검증.
* sectionId null 검증 및 capacity 범위 검증.
*/
private void validateAddSectionCapacityCommand(AddSectionCapacityCommand command) {
if (command.sectionId() == null) {
throw new ProgramException(ProgramErrorCode.INVALID_SECTION_ID);
}
if (command.capacity() <= 0) {
throw new ProgramException(ProgramErrorCode.INVALID_CAPACITY);
}
}
}