Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 14 additions & 13 deletions docs/상세 API 명세.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

- Base path: `/api/v1`
- 요청·응답 본문은 JSON을 사용합니다.
- 요청 본문의 `integer` 필드에 소수점이 있는 숫자(예: `1.5`, `1.0`)를 보내면 `400`으로 거절합니다.

### 1.1. 오류 응답

Expand Down Expand Up @@ -127,7 +128,7 @@ Authorization: Bearer {accessToken}

| 필드 | 타입 | 설명 |
|---|---|---|
| `id` | number | 회원 식별자 |
| `id` | integer | 회원 식별자 |
| `email` | string | 정규화된 이메일 (4.1.2) |
| `role` | string | 회원 권한 (`USER`) |

Expand Down Expand Up @@ -172,7 +173,7 @@ Authorization: Bearer {accessToken}
|---|---|---|
| `tokenType` | string | 항상 `Bearer` |
| `accessToken` | string | 액세스 토큰 (JWT). 회원 식별자(`sub`)와 권한(`role`)을 포함 |
| `expiresIn` | number | 액세스 토큰 유효 시간(초), `1800` |
| `expiresIn` | integer | 액세스 토큰 유효 시간(초), `1800` |
| `refreshToken` | string | 리프레시 토큰 (불투명 난수 문자열, 유효기간 7일) |

```json
Expand Down Expand Up @@ -259,8 +260,8 @@ Authorization: Bearer {accessToken}
| `title` | string | O | 공연명 (공백만으로 구성할 수 없음, 100자 이하) |
| `venue` | string | O | 공연 장소 (공백만으로 구성할 수 없음, 100자 이하) |
| `performanceAt` | string | O | 공연 일시 |
| `price` | number | O | 티켓 가격 (0 이상, 4.4.1.2.1) |
| `totalQuantity` | number | O | 총 판매 수량 (1 이상, 4.4.1.2.2) |
| `price` | integer | O | 티켓 가격 (0 이상, 4.4.1.2.1) |
| `totalQuantity` | integer | O | 총 판매 수량 (1 이상, 4.4.1.2.2) |
| `saleStartAt` | string | O | 판매 시작 일시 (4.4.1.2.3) |
| `saleEndAt` | string | O | 판매 종료 일시 (4.4.1.2.4, 4.4.1.2.5) |

Expand Down Expand Up @@ -288,13 +289,13 @@ Authorization: Bearer {accessToken}

| 필드 | 타입 | 설명 |
|---|---|---|
| `id` | number | 공연 식별자 |
| `id` | integer | 공연 식별자 |
| `title` | string | 공연명 |
| `venue` | string | 공연 장소 |
| `performanceAt` | string | 공연 일시 |
| `price` | number | 티켓 가격 |
| `totalQuantity` | number | 총 판매 수량 |
| `remainingQuantity` | number | 잔여 판매 수량 (등록 시 총 판매 수량과 같음, 4.4.1.3) |
| `price` | integer | 티켓 가격 |
| `totalQuantity` | integer | 총 판매 수량 |
| `remainingQuantity` | integer | 잔여 판매 수량 (등록 시 총 판매 수량과 같음, 4.4.1.3) |
| `saleStartAt` | string | 판매 시작 일시 |
| `saleEndAt` | string | 판매 종료 일시 |

Expand Down Expand Up @@ -335,7 +336,7 @@ ETag: "0"

| 파라미터 | 위치 | 타입 | 필수 | 설명 |
|---|---|---|---|---|
| `performanceId` | path | number | O | 공연 식별자 |
| `performanceId` | path | integer | O | 공연 식별자 |

#### 응답: `200 OK`

Expand Down Expand Up @@ -375,12 +376,12 @@ ETag: "0"
| 필드 | 타입 | 설명 |
|---|---|---|
| `performances` | array | 공연 목록. 조건에 맞는 공연이 없으면 빈 배열 |
| `performances[].id` | number | 공연 식별자 |
| `performances[].id` | integer | 공연 식별자 |
| `performances[].title` | string | 공연명 |
| `performances[].venue` | string | 공연 장소 |
| `performances[].performanceAt` | string | 공연 일시 |
| `performances[].price` | number | 티켓 가격 |
| `performances[].remainingQuantity` | number | 잔여 판매 수량 |
| `performances[].price` | integer | 티켓 가격 |
| `performances[].remainingQuantity` | integer | 잔여 판매 수량 |

```json
{
Expand Down Expand Up @@ -411,7 +412,7 @@ ETag: "0"

| 필드 | 위치 | 타입 | 필수 | 설명 |
|---|---|---|---|---|
| `performanceId` | path | number | O | 공연 식별자 |
| `performanceId` | path | integer | O | 공연 식별자 |
| `If-Match` | header | string | O | 수정의 기준이 된 공연 정보의 `ETag`. 공연 상세 조회(4.2) 응답의 `ETag`를 그대로 보냅니다(4.8.1.5). |

본문은 공연 등록 요청(4.1)과 같습니다. 바꾸지 않는 항목도 기존 값으로 모두 보냅니다.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,9 @@ public PerformanceController(PerformanceService performanceService) {
@PostMapping
public ResponseEntity<PerformanceDetailResponse> register(
@Valid @RequestBody PerformanceRequest request) {
return withETag(HttpStatus.CREATED, performanceService.register(request));
return withETag(
HttpStatus.CREATED,
performanceService.register(request.toPerformanceInfo(), request.totalQuantity()));
}

@GetMapping("/{performanceId}")
Expand All @@ -50,7 +52,11 @@ public ResponseEntity<PerformanceDetailResponse> update(
@Valid @RequestBody PerformanceRequest request) {
return ResponseEntity.ok(
PerformanceDetailResponse.from(
performanceService.update(performanceId, request, IfMatch.parse(ifMatch))));
performanceService.update(
performanceId,
request.toPerformanceInfo(),
request.totalQuantity(),
IfMatch.parse(ifMatch))));
}

@GetMapping
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,16 +42,12 @@ private Performance(
this.salePeriod = salePeriod;
}

public static Performance create(
String title,
String venue,
LocalDateTime performanceAt,
int price,
SalePeriod salePeriod,
LocalDateTime now) {
public static Performance create(PerformanceInfo info, LocalDateTime now) {
SalePeriod salePeriod = new SalePeriod(info.saleStartAt(), info.saleEndAt());
validateSaleStartAt(salePeriod, now);
validateSaleEndBeforePerformance(salePeriod, performanceAt);
return new Performance(title, venue, performanceAt, price, salePeriod);
validateSaleEndBeforePerformance(salePeriod, info.performanceAt());
return new Performance(
info.title(), info.venue(), info.performanceAt(), info.price(), salePeriod);
}

private void validateUpdatable(
Expand All @@ -70,7 +66,7 @@ private void validateUpdatable(
}
}

public void update(PerformanceUpdate changes, boolean hasReservation, LocalDateTime now) {
public void update(PerformanceInfo changes, boolean hasReservation, LocalDateTime now) {
validateUpdatable(changes.performanceAt(), changes.saleStartAt(), hasReservation, now);

SalePeriod newSalePeriod = new SalePeriod(changes.saleStartAt(), changes.saleEndAt());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import java.time.LocalDateTime;

public record PerformanceUpdate(
public record PerformanceInfo(
String title,
String venue,
LocalDateTime performanceAt,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import com.fasterxml.jackson.annotation.JsonFormat;
import com.ticketing.reservation.performance.domain.Performance;
import com.ticketing.reservation.performance.domain.PerformanceUpdate;
import com.ticketing.reservation.performance.domain.PerformanceInfo;
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotNull;
import jakarta.validation.constraints.Positive;
Expand All @@ -21,7 +21,7 @@ public record PerformanceRequest(

private static final String DATE_TIME_PATTERN = "uuuu-MM-dd'T'HH:mm:ss";

public PerformanceUpdate toPerformanceUpdate() {
return new PerformanceUpdate(title, venue, performanceAt, price, saleStartAt, saleEndAt);
public PerformanceInfo toPerformanceInfo() {
return new PerformanceInfo(title, venue, performanceAt, price, saleStartAt, saleEndAt);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,8 @@
import com.ticketing.reservation.global.web.IfMatch;
import com.ticketing.reservation.performance.domain.Performance;
import com.ticketing.reservation.performance.domain.PerformanceDetail;
import com.ticketing.reservation.performance.domain.PerformanceInfo;
import com.ticketing.reservation.performance.domain.PerformanceStock;
import com.ticketing.reservation.performance.domain.SalePeriod;
import com.ticketing.reservation.performance.dto.PerformanceRequest;
import com.ticketing.reservation.performance.repository.PerformanceRepository;
import com.ticketing.reservation.performance.repository.PerformanceStockRepository;
import java.time.Clock;
Expand Down Expand Up @@ -37,23 +36,17 @@ public PerformanceService(
}

@Transactional
public PerformanceDetail register(PerformanceRequest request) {
public PerformanceDetail register(PerformanceInfo info, int totalQuantity) {
Performance performance =
performanceRepository.save(
Performance.create(
request.title(),
request.venue(),
request.performanceAt(),
request.price(),
new SalePeriod(request.saleStartAt(), request.saleEndAt()),
LocalDateTime.now(clock)));
performanceRepository.save(Performance.create(info, LocalDateTime.now(clock)));
PerformanceStock stock =
stockRepository.save(PerformanceStock.create(performance.getId(), request.totalQuantity()));
stockRepository.save(PerformanceStock.create(performance.getId(), totalQuantity));
return new PerformanceDetail(performance, stock);
}

@Transactional
public PerformanceDetail update(Long performanceId, PerformanceRequest request, IfMatch ifMatch) {
public PerformanceDetail update(
Long performanceId, PerformanceInfo info, int totalQuantity, IfMatch ifMatch) {
Performance performance =
performanceRepository
.findByIdForUpdate(performanceId)
Expand All @@ -62,9 +55,8 @@ public PerformanceDetail update(Long performanceId, PerformanceRequest request,
throw new BusinessException(ErrorCode.PERFORMANCE_MODIFIED);
}
PerformanceStock stock = findStock(performanceId);
performance.update(
request.toPerformanceUpdate(), stock.hasReservation(), LocalDateTime.now(clock));
stock.changeTotalQuantity(request.totalQuantity());
performance.update(info, stock.hasReservation(), LocalDateTime.now(clock));
stock.changeTotalQuantity(totalQuantity);
return new PerformanceDetail(performance, stock);
}

Expand Down
3 changes: 3 additions & 0 deletions src/main/resources/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ spring:
url: ${DB_URL:jdbc:mysql://localhost:3307/ticketing}
username: ${DB_USERNAME:ticketing_app}
password: ${DB_PASSWORD:local-app-password}
jackson:
deserialization:
accept-float-as-int: false
jpa:
hibernate:
# 스키마는 Flyway 마이그레이션(db/migration)으로 관리하고, Hibernate는 엔티티와 일치하는지만 검증한다.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@

import com.ticketing.reservation.integration.TestcontainersConfiguration;
import com.ticketing.reservation.performance.domain.Performance;
import com.ticketing.reservation.performance.domain.PerformanceInfo;
import com.ticketing.reservation.performance.domain.PerformanceStock;
import com.ticketing.reservation.performance.domain.SalePeriod;
import com.ticketing.reservation.performance.repository.PerformanceRepository;
import com.ticketing.reservation.performance.repository.PerformanceStockRepository;
import java.time.LocalDateTime;
Expand Down Expand Up @@ -110,11 +110,7 @@ private void save(
Performance performance =
performanceRepository.save(
Performance.create(
title,
"공연장",
performanceAt,
50_000,
new SalePeriod(saleStartAt, saleEndAt),
new PerformanceInfo(title, "공연장", performanceAt, 50_000, saleStartAt, saleEndAt),
saleStartAt.minusDays(1)));
PerformanceStock stock = PerformanceStock.create(performance.getId(), 100);
ReflectionTestUtils.setField(stock, "reservedQuantity", reservedQuantity);
Expand Down
Loading
Loading