From fcb0d417352db9b8ddc0b2171185036032588d18 Mon Sep 17 00:00:00 2001 From: seminchoi Date: Tue, 13 Aug 2024 17:21:14 +0900 Subject: [PATCH 01/13] =?UTF-8?q?feat:=20=EA=B5=AC=EC=97=AD=EC=9D=98=20?= =?UTF-8?q?=EC=A2=8C=EC=84=9D=20=EB=AA=A9=EB=A1=9D=EC=9D=84=20=EC=A1=B0?= =?UTF-8?q?=ED=9A=8C=ED=95=98=EB=8A=94=20API=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../seat/controller/SeatController.java | 26 ++++++++++++++++ .../domain/seat/dto/SeatElement.java | 23 ++++++++++++++ .../seat/repository/SeatRepository.java | 7 ++++- .../domain/seat/service/SeatService.java | 31 +++++++++++++++++++ 4 files changed, 86 insertions(+), 1 deletion(-) create mode 100644 src/main/java/com/thirdparty/ticketing/domain/seat/controller/SeatController.java create mode 100644 src/main/java/com/thirdparty/ticketing/domain/seat/dto/SeatElement.java create mode 100644 src/main/java/com/thirdparty/ticketing/domain/seat/service/SeatService.java diff --git a/src/main/java/com/thirdparty/ticketing/domain/seat/controller/SeatController.java b/src/main/java/com/thirdparty/ticketing/domain/seat/controller/SeatController.java new file mode 100644 index 00000000..5db75078 --- /dev/null +++ b/src/main/java/com/thirdparty/ticketing/domain/seat/controller/SeatController.java @@ -0,0 +1,26 @@ +package com.thirdparty.ticketing.domain.seat.controller; + +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +import com.thirdparty.ticketing.domain.ItemResult; +import com.thirdparty.ticketing.domain.seat.dto.SeatElement; +import com.thirdparty.ticketing.domain.seat.service.SeatService; + +import lombok.RequiredArgsConstructor; + +@RestController +@RequestMapping("/api") +@RequiredArgsConstructor +public class SeatController { + private final SeatService seatService; + + @GetMapping("/performances/{performanceId}/zones/{zoneId}/seats") + public ResponseEntity> getSeats(@PathVariable("zoneId") long zoneId) { + ItemResult seats = seatService.getSeats(zoneId); + return ResponseEntity.ok().body(seats); + } +} diff --git a/src/main/java/com/thirdparty/ticketing/domain/seat/dto/SeatElement.java b/src/main/java/com/thirdparty/ticketing/domain/seat/dto/SeatElement.java new file mode 100644 index 00000000..446353ae --- /dev/null +++ b/src/main/java/com/thirdparty/ticketing/domain/seat/dto/SeatElement.java @@ -0,0 +1,23 @@ +package com.thirdparty.ticketing.domain.seat.dto; + +import com.thirdparty.ticketing.domain.seat.Seat; +import com.thirdparty.ticketing.domain.seat.SeatStatus; + +import lombok.Builder; +import lombok.Data; + +@Data +@Builder +public class SeatElement { + private final long seatId; + private final String seatCode; + private final boolean isSeatAvailable; + + public static SeatElement of(Seat seat) { + return SeatElement.builder() + .seatId(seat.getSeatId()) + .seatCode(seat.getSeatCode()) + .isSeatAvailable(seat.getSeatStatus().equals(SeatStatus.AVAILABLE)) + .build(); + } +} diff --git a/src/main/java/com/thirdparty/ticketing/domain/seat/repository/SeatRepository.java b/src/main/java/com/thirdparty/ticketing/domain/seat/repository/SeatRepository.java index fec25441..5a24b9dc 100644 --- a/src/main/java/com/thirdparty/ticketing/domain/seat/repository/SeatRepository.java +++ b/src/main/java/com/thirdparty/ticketing/domain/seat/repository/SeatRepository.java @@ -1,9 +1,14 @@ package com.thirdparty.ticketing.domain.seat.repository; +import java.util.List; + import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.stereotype.Repository; import com.thirdparty.ticketing.domain.seat.Seat; +import com.thirdparty.ticketing.domain.zone.Zone; @Repository -public interface SeatRepository extends JpaRepository {} +public interface SeatRepository extends JpaRepository { + List findByZone(Zone zone); +} diff --git a/src/main/java/com/thirdparty/ticketing/domain/seat/service/SeatService.java b/src/main/java/com/thirdparty/ticketing/domain/seat/service/SeatService.java new file mode 100644 index 00000000..6007828c --- /dev/null +++ b/src/main/java/com/thirdparty/ticketing/domain/seat/service/SeatService.java @@ -0,0 +1,31 @@ +package com.thirdparty.ticketing.domain.seat.service; + +import java.util.List; + +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +import com.thirdparty.ticketing.domain.ItemResult; +import com.thirdparty.ticketing.domain.common.TicketingException; +import com.thirdparty.ticketing.domain.seat.dto.SeatElement; +import com.thirdparty.ticketing.domain.seat.repository.SeatRepository; +import com.thirdparty.ticketing.domain.zone.Zone; +import com.thirdparty.ticketing.domain.zone.repository.ZoneRepository; + +import lombok.RequiredArgsConstructor; + +@Service +@RequiredArgsConstructor +public class SeatService { + private final ZoneRepository zoneRepository; + private final SeatRepository seatRepository; + + @Transactional(readOnly = true) + public ItemResult getSeats(Long zoneId) { + Zone zone = zoneRepository.findById(zoneId).orElseThrow(() -> new TicketingException("")); + List seats = + seatRepository.findByZone(zone).stream().map(SeatElement::of).toList(); + + return ItemResult.of(seats); + } +} From ccf7d1202720afe07013af41f0da0c15a37d2eff Mon Sep 17 00:00:00 2001 From: seminchoi Date: Tue, 13 Aug 2024 17:21:37 +0900 Subject: [PATCH 02/13] =?UTF-8?q?test:=20=EA=B5=AC=EC=97=AD=EC=9D=98=20?= =?UTF-8?q?=EC=A2=8C=EC=84=9D=20=EB=AA=A9=EB=A1=9D=20=EC=A1=B0=ED=9A=8C=20?= =?UTF-8?q?=EA=B8=B0=EB=8A=A5=20=ED=85=8C=EC=8A=A4=ED=8A=B8=20=EC=9E=91?= =?UTF-8?q?=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/seat/service/SeatServiceTest.java | 152 ++++++++++++++++++ 1 file changed, 152 insertions(+) create mode 100644 src/test/java/com/thirdparty/ticketing/domain/seat/service/SeatServiceTest.java diff --git a/src/test/java/com/thirdparty/ticketing/domain/seat/service/SeatServiceTest.java b/src/test/java/com/thirdparty/ticketing/domain/seat/service/SeatServiceTest.java new file mode 100644 index 00000000..b8135ea7 --- /dev/null +++ b/src/test/java/com/thirdparty/ticketing/domain/seat/service/SeatServiceTest.java @@ -0,0 +1,152 @@ +package com.thirdparty.ticketing.domain.seat.service; + +import static org.assertj.core.api.Assertions.assertThat; + +import java.time.ZoneId; +import java.time.ZonedDateTime; +import java.util.List; + +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Nested; +import org.junit.jupiter.api.Test; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest; +import org.springframework.boot.test.autoconfigure.orm.jpa.TestEntityManager; + +import com.thirdparty.ticketing.domain.ItemResult; +import com.thirdparty.ticketing.domain.member.Member; +import com.thirdparty.ticketing.domain.member.MemberRole; +import com.thirdparty.ticketing.domain.performance.Performance; +import com.thirdparty.ticketing.domain.seat.Seat; +import com.thirdparty.ticketing.domain.seat.SeatGrade; +import com.thirdparty.ticketing.domain.seat.dto.SeatElement; +import com.thirdparty.ticketing.domain.seat.repository.SeatRepository; +import com.thirdparty.ticketing.domain.zone.Zone; +import com.thirdparty.ticketing.domain.zone.repository.ZoneRepository; + +@DataJpaTest +public class SeatServiceTest { + @Autowired private TestEntityManager testEntityManager; + @Autowired private SeatRepository seatRepository; + @Autowired private ZoneRepository zoneRepository; + + private SeatService seatService; + + private Member member; + private Performance performance; + private Zone zone; + private SeatGrade seatGrade1; + private SeatGrade seatGrade2; + + @BeforeEach + void setUpBase() { + seatService = new SeatService(zoneRepository, seatRepository); + setUpMember(); + setUpPerformance(); + setUpZone(); + setUpSeatGrades(); + } + + private void setUpMember() { + Member member = + Member.builder() + .email("test@gmail.com") + .password("testpassword") + .memberRole(MemberRole.USER) + .build(); + + testEntityManager.persist(member); + this.member = member; + } + + private void setUpPerformance() { + Performance performance = + Performance.builder() + .performanceName("공연") + .performancePlace("장소") + .performanceShowtime( + ZonedDateTime.of( + 2024, 8, 23, 14, 30, 0, 0, ZoneId.of("Asia/Seoul"))) + .build(); + testEntityManager.persistAndFlush(performance); + this.performance = performance; + } + + private void setUpZone() { + Zone zone = Zone.builder().zoneName("VIP").performance(performance).build(); + testEntityManager.persistAndFlush(zone); + this.zone = zone; + } + + private void setUpSeatGrades() { + SeatGrade seatGrade1 = + SeatGrade.builder() + .performance(performance) + .price(10000L) + .gradeName("Grade1") + .build(); + SeatGrade seatGrade2 = + SeatGrade.builder() + .performance(performance) + .price(20000L) + .gradeName("Grade2") + .build(); + testEntityManager.persistAndFlush(seatGrade1); + testEntityManager.persistAndFlush(seatGrade2); + + this.seatGrade1 = seatGrade1; + this.seatGrade2 = seatGrade2; + } + + @Nested + @DisplayName("getZones 메서드를 호출할 때") + class GetZonesTest { + private Seat seat1; + private Seat seat2; + + @BeforeEach + void setUp() { + seat1 = + Seat.builder() + .member(member) + .seatCode("A01") + .zone(zone) + .seatGrade(seatGrade1) + .build(); + + seat2 = + Seat.builder() + .member(member) + .seatCode("A01") + .zone(zone) + .seatGrade(seatGrade2) + .build(); + } + + @Test + @DisplayName("좌석 등급이 성공적으로 생성된다.") + void getZones_success() { + // Given + testEntityManager.persistAndFlush(seat1); + testEntityManager.persistAndFlush(seat2); + + // When + ItemResult seats = seatService.getSeats(zone.getZoneId()); + + // Then + List seatElements = seats.getItem(); + SeatElement seatElement1 = seatElements.get(0); + SeatElement seatElement2 = seatElements.get(1); + + assertThat(seatElements).hasSize(2); + assertSeatElement(seatElement1, seat1); + assertSeatElement(seatElement2, seat2); + } + + private void assertSeatElement(SeatElement seatElement, Seat expectedSeat) { + assertThat(seatElement.getSeatId()).isEqualTo(expectedSeat.getSeatId()); + assertThat(seatElement.getSeatCode()).isEqualTo(expectedSeat.getSeatCode()); + } + } +} From 69ab51cbbbf9ea9eb1e0c9c3eca03fd4ea6fb451 Mon Sep 17 00:00:00 2001 From: seminchoi Date: Tue, 13 Aug 2024 17:23:52 +0900 Subject: [PATCH 03/13] =?UTF-8?q?feat:=20=EC=A2=8C=EC=84=9D=EC=9D=84=20?= =?UTF-8?q?=EC=84=A0=EC=A0=90=ED=95=9C=20=EC=82=AC=EC=9A=A9=EC=9E=90?= =?UTF-8?q?=EB=A5=BC=20=EC=95=8C=20=EC=88=98=20=EC=9E=88=EB=8F=84=EB=A1=9D?= =?UTF-8?q?=20Seat=20=EC=97=94=ED=8B=B0=ED=8B=B0=EC=97=90=20Member=20?= =?UTF-8?q?=ED=95=84=EB=93=9C=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - DDL 옵션 추가 --- .../com/thirdparty/ticketing/domain/seat/Seat.java | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/thirdparty/ticketing/domain/seat/Seat.java b/src/main/java/com/thirdparty/ticketing/domain/seat/Seat.java index b881c20c..7578b6d0 100644 --- a/src/main/java/com/thirdparty/ticketing/domain/seat/Seat.java +++ b/src/main/java/com/thirdparty/ticketing/domain/seat/Seat.java @@ -3,6 +3,7 @@ import jakarta.persistence.*; import com.thirdparty.ticketing.domain.BaseEntity; +import com.thirdparty.ticketing.domain.member.Member; import com.thirdparty.ticketing.domain.zone.Zone; import lombok.AccessLevel; @@ -23,18 +24,23 @@ public class Seat extends BaseEntity { private Long seatId; @ManyToOne(fetch = FetchType.LAZY) - @JoinColumn(name = "zone_id") + @JoinColumn(name = "zone_id", nullable = false) private Zone zone; @ManyToOne(fetch = FetchType.LAZY) - @JoinColumn(name = "seat_Grade") + @JoinColumn(name = "seat_Grade", nullable = false) private SeatGrade seatGrade; - @Column(length = 32) + @ManyToOne(fetch = FetchType.LAZY) + @JoinColumn(name = "member_id") + private Member member; + + @Column(length = 32, nullable = false) private String seatCode; @Enumerated(EnumType.STRING) @Builder.Default + @Column(length = 16, nullable = false) private SeatStatus seatStatus = SeatStatus.AVAILABLE; public Seat(String seatCode, SeatStatus seatStatus) { From 67b5fd17f721a30648a1f934a07d0edd59a90ace Mon Sep 17 00:00:00 2001 From: seminchoi Date: Tue, 13 Aug 2024 17:25:02 +0900 Subject: [PATCH 04/13] =?UTF-8?q?refactor:=20=EA=B5=AC=EC=97=AD=20?= =?UTF-8?q?=EC=A1=B0=ED=9A=8C=20=EA=B8=B0=EB=8A=A5=20=ED=8A=B8=EB=9E=9C?= =?UTF-8?q?=EC=9E=AD=EC=85=98=20=EC=A0=81=EC=9A=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ticketing/domain/zone/service/UserZoneService.java | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/thirdparty/ticketing/domain/zone/service/UserZoneService.java b/src/main/java/com/thirdparty/ticketing/domain/zone/service/UserZoneService.java index bf417ac9..756d9b24 100644 --- a/src/main/java/com/thirdparty/ticketing/domain/zone/service/UserZoneService.java +++ b/src/main/java/com/thirdparty/ticketing/domain/zone/service/UserZoneService.java @@ -1,8 +1,10 @@ package com.thirdparty.ticketing.domain.zone.service; import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; import com.thirdparty.ticketing.domain.ItemResult; +import com.thirdparty.ticketing.domain.common.TicketingException; import com.thirdparty.ticketing.domain.performance.Performance; import com.thirdparty.ticketing.domain.performance.repository.PerformanceRepository; import com.thirdparty.ticketing.domain.zone.dto.ZoneElement; @@ -17,8 +19,12 @@ public class UserZoneService { private final ZoneRepository zoneRepository; private final PerformanceRepository performanceRepository; + @Transactional(readOnly = true) public ItemResult getZones(Long performanceId) { - Performance performance = performanceRepository.findById(performanceId).orElseThrow(); + Performance performance = + performanceRepository + .findById(performanceId) + .orElseThrow(() -> new TicketingException("")); return ItemResult.of( zoneRepository.findByPerformance(performance).stream() .map(ZoneElement::of) From 3c16734a4cefe90e5cf51d9d77ac701da7503097 Mon Sep 17 00:00:00 2001 From: seminchoi Date: Tue, 13 Aug 2024 18:56:26 +0900 Subject: [PATCH 05/13] =?UTF-8?q?refactor:=20BaseControllerTest=20?= =?UTF-8?q?=ED=81=B4=EB=9E=98=EC=8A=A4=EC=97=90=20ObjectMapper=20=ED=95=84?= =?UTF-8?q?=EB=93=9C=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/AdminPerformanceControllerTest.java | 4 ---- .../domain/seat/controller/AdminSeatControllerTest.java | 4 ---- .../domain/zone/controller/AdminZoneControllerTest.java | 4 ---- .../com/thirdparty/ticketing/support/BaseControllerTest.java | 3 +++ .../com/thirdparty/ticketing/support/DocumentationTest.java | 4 ---- 5 files changed, 3 insertions(+), 16 deletions(-) diff --git a/src/test/java/com/thirdparty/ticketing/domain/performance/controller/AdminPerformanceControllerTest.java b/src/test/java/com/thirdparty/ticketing/domain/performance/controller/AdminPerformanceControllerTest.java index 1a41c5f0..0e04ce5c 100644 --- a/src/test/java/com/thirdparty/ticketing/domain/performance/controller/AdminPerformanceControllerTest.java +++ b/src/test/java/com/thirdparty/ticketing/domain/performance/controller/AdminPerformanceControllerTest.java @@ -9,7 +9,6 @@ import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; -import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest; import org.springframework.boot.test.mock.mockito.MockBean; import org.springframework.context.annotation.Import; @@ -18,7 +17,6 @@ import org.springframework.test.web.servlet.ResultActions; import com.fasterxml.jackson.core.JsonProcessingException; -import com.fasterxml.jackson.databind.ObjectMapper; import com.thirdparty.ticketing.domain.performance.dto.request.PerformanceCreationRequest; import com.thirdparty.ticketing.domain.performance.service.AdminPerformanceService; import com.thirdparty.ticketing.support.BaseControllerTest; @@ -29,8 +27,6 @@ class AdminPerformanceControllerTest extends BaseControllerTest { @MockBean private AdminPerformanceService adminPerformanceService; - @Autowired private ObjectMapper objectMapper; - @Test @DisplayName("POST /api/performances") void createPerformance() throws Exception { diff --git a/src/test/java/com/thirdparty/ticketing/domain/seat/controller/AdminSeatControllerTest.java b/src/test/java/com/thirdparty/ticketing/domain/seat/controller/AdminSeatControllerTest.java index 683b5c09..d5b7adbf 100644 --- a/src/test/java/com/thirdparty/ticketing/domain/seat/controller/AdminSeatControllerTest.java +++ b/src/test/java/com/thirdparty/ticketing/domain/seat/controller/AdminSeatControllerTest.java @@ -11,7 +11,6 @@ import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; -import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest; import org.springframework.boot.test.mock.mockito.MockBean; import org.springframework.context.annotation.Import; @@ -20,7 +19,6 @@ import org.springframework.test.web.servlet.ResultActions; import com.fasterxml.jackson.core.JsonProcessingException; -import com.fasterxml.jackson.databind.ObjectMapper; import com.thirdparty.ticketing.domain.seat.dto.SeatCreationElement; import com.thirdparty.ticketing.domain.seat.dto.SeatCreationRequest; import com.thirdparty.ticketing.domain.seat.dto.SeatGradeCreationElement; @@ -34,8 +32,6 @@ public class AdminSeatControllerTest extends BaseControllerTest { @MockBean private AdminSeatService adminSeatService; - @Autowired private ObjectMapper objectMapper; - @Test @DisplayName("관리자 좌석 생성 API") void createSeats() throws Exception { diff --git a/src/test/java/com/thirdparty/ticketing/domain/zone/controller/AdminZoneControllerTest.java b/src/test/java/com/thirdparty/ticketing/domain/zone/controller/AdminZoneControllerTest.java index 3527cfa5..6f9fdb4f 100644 --- a/src/test/java/com/thirdparty/ticketing/domain/zone/controller/AdminZoneControllerTest.java +++ b/src/test/java/com/thirdparty/ticketing/domain/zone/controller/AdminZoneControllerTest.java @@ -11,7 +11,6 @@ import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; -import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest; import org.springframework.boot.test.mock.mockito.MockBean; import org.springframework.context.annotation.Import; @@ -20,7 +19,6 @@ import org.springframework.test.web.servlet.ResultActions; import com.fasterxml.jackson.core.JsonProcessingException; -import com.fasterxml.jackson.databind.ObjectMapper; import com.thirdparty.ticketing.domain.zone.contoller.AdminZoneController; import com.thirdparty.ticketing.domain.zone.dto.ZoneCreationElement; import com.thirdparty.ticketing.domain.zone.dto.ZoneCreationRequest; @@ -33,8 +31,6 @@ public class AdminZoneControllerTest extends BaseControllerTest { @MockBean private AdminZoneService adminZoneService; - @Autowired private ObjectMapper objectMapper; - @Test @DisplayName("POST /api/performances/{performanceId}/zones") void createZones() throws Exception { diff --git a/src/test/java/com/thirdparty/ticketing/support/BaseControllerTest.java b/src/test/java/com/thirdparty/ticketing/support/BaseControllerTest.java index 0c69c3ea..1556d426 100644 --- a/src/test/java/com/thirdparty/ticketing/support/BaseControllerTest.java +++ b/src/test/java/com/thirdparty/ticketing/support/BaseControllerTest.java @@ -21,6 +21,7 @@ import org.springframework.web.context.WebApplicationContext; import org.springframework.web.filter.CharacterEncodingFilter; +import com.fasterxml.jackson.databind.ObjectMapper; import com.thirdparty.ticketing.domain.member.Member; import com.thirdparty.ticketing.domain.member.MemberRole; import com.thirdparty.ticketing.domain.member.service.JwtProvider; @@ -36,6 +37,8 @@ public abstract class BaseControllerTest { @Autowired protected JwtProvider jwtProvider; + @Autowired protected ObjectMapper objectMapper; + protected String adminBearerToken; protected String userBearerToken; diff --git a/src/test/java/com/thirdparty/ticketing/support/DocumentationTest.java b/src/test/java/com/thirdparty/ticketing/support/DocumentationTest.java index 39501069..1441adc8 100644 --- a/src/test/java/com/thirdparty/ticketing/support/DocumentationTest.java +++ b/src/test/java/com/thirdparty/ticketing/support/DocumentationTest.java @@ -15,7 +15,6 @@ import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; -import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest; import org.springframework.context.annotation.Import; import org.springframework.http.MediaType; @@ -30,7 +29,6 @@ import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RestController; -import com.fasterxml.jackson.databind.ObjectMapper; import com.thirdparty.ticketing.support.DocumentationTest.DocsController; @WebMvcTest(controllers = DocumentationTest.class) @@ -38,8 +36,6 @@ @DisplayName("API 문서 테스트 코드 작성 시") public class DocumentationTest extends BaseControllerTest { - @Autowired ObjectMapper objectMapper; - public record HelloRequest(String name) {} @RestController From bdb6ca6128619e492235ac444e4fad40c3cb4bb4 Mon Sep 17 00:00:00 2001 From: seminchoi Date: Tue, 13 Aug 2024 19:23:22 +0900 Subject: [PATCH 06/13] =?UTF-8?q?feat:=20ItemResult=20=ED=95=84=EB=93=9C?= =?UTF-8?q?=20items=20=EB=A1=9C=20=EB=84=A4=EC=9D=B4=EB=B0=8D=20=EB=B3=80?= =?UTF-8?q?=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/thirdparty/ticketing/domain/ItemResult.java | 2 +- .../controller/UserPerformanceControllerTest.java | 10 +++++----- .../service/UserPerformanceServiceTest.java | 2 +- .../ticketing/domain/seat/service/SeatServiceTest.java | 2 +- .../domain/zone/controller/UserZoneControllerTest.java | 6 +++--- .../domain/zone/service/UserZoneServiceTest.java | 2 +- 6 files changed, 12 insertions(+), 12 deletions(-) diff --git a/src/main/java/com/thirdparty/ticketing/domain/ItemResult.java b/src/main/java/com/thirdparty/ticketing/domain/ItemResult.java index deed6d69..430e4ec5 100644 --- a/src/main/java/com/thirdparty/ticketing/domain/ItemResult.java +++ b/src/main/java/com/thirdparty/ticketing/domain/ItemResult.java @@ -9,7 +9,7 @@ @AllArgsConstructor public class ItemResult { - private List item; + private List items; public static ItemResult of(List items) { return new ItemResult(items); diff --git a/src/test/java/com/thirdparty/ticketing/domain/performance/controller/UserPerformanceControllerTest.java b/src/test/java/com/thirdparty/ticketing/domain/performance/controller/UserPerformanceControllerTest.java index 4183fda1..2b55ec0b 100644 --- a/src/test/java/com/thirdparty/ticketing/domain/performance/controller/UserPerformanceControllerTest.java +++ b/src/test/java/com/thirdparty/ticketing/domain/performance/controller/UserPerformanceControllerTest.java @@ -47,13 +47,13 @@ void getPerformances() throws Exception { .andDo( restDocs.document( responseFields( - fieldWithPath("item").description("공연 목록"), - fieldWithPath("item[].performanceId").description("공연 ID"), - fieldWithPath("item[].performanceName") + fieldWithPath("items").description("공연 목록"), + fieldWithPath("items[].performanceId").description("공연 ID"), + fieldWithPath("items[].performanceName") .description("공연 이름"), - fieldWithPath("item[].performancePlace") + fieldWithPath("items[].performancePlace") .description("공연 장소"), - fieldWithPath("item[].performanceShowtime") + fieldWithPath("items[].performanceShowtime") .description("공연 시간")))); } } diff --git a/src/test/java/com/thirdparty/ticketing/domain/performance/service/UserPerformanceServiceTest.java b/src/test/java/com/thirdparty/ticketing/domain/performance/service/UserPerformanceServiceTest.java index 4a3315ed..5e9f1158 100644 --- a/src/test/java/com/thirdparty/ticketing/domain/performance/service/UserPerformanceServiceTest.java +++ b/src/test/java/com/thirdparty/ticketing/domain/performance/service/UserPerformanceServiceTest.java @@ -68,7 +68,7 @@ void getPerformances_Success() { userPerformanceService.getPerformances(); // Then - assertThat(performanceElements.getItem()) + assertThat(performanceElements.getItems()) .isNotEmpty() .hasSize(2) .satisfies( diff --git a/src/test/java/com/thirdparty/ticketing/domain/seat/service/SeatServiceTest.java b/src/test/java/com/thirdparty/ticketing/domain/seat/service/SeatServiceTest.java index b8135ea7..9f195a3e 100644 --- a/src/test/java/com/thirdparty/ticketing/domain/seat/service/SeatServiceTest.java +++ b/src/test/java/com/thirdparty/ticketing/domain/seat/service/SeatServiceTest.java @@ -135,7 +135,7 @@ void getZones_success() { ItemResult seats = seatService.getSeats(zone.getZoneId()); // Then - List seatElements = seats.getItem(); + List seatElements = seats.getItems(); SeatElement seatElement1 = seatElements.get(0); SeatElement seatElement2 = seatElements.get(1); diff --git a/src/test/java/com/thirdparty/ticketing/domain/zone/controller/UserZoneControllerTest.java b/src/test/java/com/thirdparty/ticketing/domain/zone/controller/UserZoneControllerTest.java index 7ac19b62..bd5428b6 100644 --- a/src/test/java/com/thirdparty/ticketing/domain/zone/controller/UserZoneControllerTest.java +++ b/src/test/java/com/thirdparty/ticketing/domain/zone/controller/UserZoneControllerTest.java @@ -50,8 +50,8 @@ void getZones() throws Exception { pathParameters( parameterWithName("performanceId").description("공연 ID")), responseFields( - fieldWithPath("item").description("구역 목록"), - fieldWithPath("item[].zoneId").description("구역 ID"), - fieldWithPath("item[].zoneName").description("구역 이름")))); + fieldWithPath("items").description("구역 목록"), + fieldWithPath("items[].zoneId").description("구역 ID"), + fieldWithPath("items[].zoneName").description("구역 이름")))); } } diff --git a/src/test/java/com/thirdparty/ticketing/domain/zone/service/UserZoneServiceTest.java b/src/test/java/com/thirdparty/ticketing/domain/zone/service/UserZoneServiceTest.java index f3833dca..2bb828a3 100644 --- a/src/test/java/com/thirdparty/ticketing/domain/zone/service/UserZoneServiceTest.java +++ b/src/test/java/com/thirdparty/ticketing/domain/zone/service/UserZoneServiceTest.java @@ -66,7 +66,7 @@ void getZones_Success() { userZoneService.getZones(performance.getPerformanceId()); // Then - assertThat(zoneElements.getItem()) + assertThat(zoneElements.getItems()) .isNotEmpty() .hasSize(2) .satisfies( From da3657e882d5893957d8631d89388a1a08b55e27 Mon Sep 17 00:00:00 2001 From: seminchoi Date: Tue, 13 Aug 2024 19:23:57 +0900 Subject: [PATCH 07/13] =?UTF-8?q?feat:=20=EC=A2=8C=EC=84=9D=20=EC=83=81?= =?UTF-8?q?=ED=83=9C=EA=B0=80=20=EC=84=A0=ED=83=9D=20=EA=B0=80=EB=8A=A5?= =?UTF-8?q?=ED=95=9C=EC=A7=80=20=ED=99=95=EC=9D=B8=ED=95=98=EB=8A=94=20?= =?UTF-8?q?=EB=A9=94=EC=86=8C=EB=93=9C=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../thirdparty/ticketing/domain/seat/SeatStatus.java | 6 +++++- .../ticketing/domain/seat/dto/SeatElement.java | 12 +++--------- 2 files changed, 8 insertions(+), 10 deletions(-) diff --git a/src/main/java/com/thirdparty/ticketing/domain/seat/SeatStatus.java b/src/main/java/com/thirdparty/ticketing/domain/seat/SeatStatus.java index c9068122..98970932 100644 --- a/src/main/java/com/thirdparty/ticketing/domain/seat/SeatStatus.java +++ b/src/main/java/com/thirdparty/ticketing/domain/seat/SeatStatus.java @@ -4,5 +4,9 @@ public enum SeatStatus { AVAILABLE, SELECTED, PENDING_PAYMENT, - PAID + PAID; + + public boolean isAvailable() { + return this == AVAILABLE; + } } diff --git a/src/main/java/com/thirdparty/ticketing/domain/seat/dto/SeatElement.java b/src/main/java/com/thirdparty/ticketing/domain/seat/dto/SeatElement.java index 446353ae..193a97b4 100644 --- a/src/main/java/com/thirdparty/ticketing/domain/seat/dto/SeatElement.java +++ b/src/main/java/com/thirdparty/ticketing/domain/seat/dto/SeatElement.java @@ -1,23 +1,17 @@ package com.thirdparty.ticketing.domain.seat.dto; import com.thirdparty.ticketing.domain.seat.Seat; -import com.thirdparty.ticketing.domain.seat.SeatStatus; -import lombok.Builder; import lombok.Data; @Data -@Builder public class SeatElement { private final long seatId; private final String seatCode; - private final boolean isSeatAvailable; + private final boolean seatAvailable; public static SeatElement of(Seat seat) { - return SeatElement.builder() - .seatId(seat.getSeatId()) - .seatCode(seat.getSeatCode()) - .isSeatAvailable(seat.getSeatStatus().equals(SeatStatus.AVAILABLE)) - .build(); + boolean isSeatAvailable = seat.getSeatStatus().isAvailable(); + return new SeatElement(seat.getSeatId(), seat.getSeatCode(), isSeatAvailable); } } From f235e2bdb5e1c42f1a8e629b2cd1107409f69502 Mon Sep 17 00:00:00 2001 From: seminchoi Date: Tue, 13 Aug 2024 19:25:00 +0900 Subject: [PATCH 08/13] =?UTF-8?q?test:=20=EA=B5=AC=EC=97=AD=20=EC=A2=8C?= =?UTF-8?q?=EC=84=9D=20=EB=AA=A9=EB=A1=9D=20=EC=A1=B0=ED=9A=8C=20API=20Res?= =?UTF-8?q?t=20Docs=20=ED=85=8C=EC=8A=A4=ED=8A=B8=20=EC=BD=94=EB=93=9C=20?= =?UTF-8?q?=EC=9E=91=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../seat/controller/SeatControllerTest.java | 67 +++++++++++++++++++ 1 file changed, 67 insertions(+) create mode 100644 src/test/java/com/thirdparty/ticketing/domain/seat/controller/SeatControllerTest.java diff --git a/src/test/java/com/thirdparty/ticketing/domain/seat/controller/SeatControllerTest.java b/src/test/java/com/thirdparty/ticketing/domain/seat/controller/SeatControllerTest.java new file mode 100644 index 00000000..c79e381c --- /dev/null +++ b/src/test/java/com/thirdparty/ticketing/domain/seat/controller/SeatControllerTest.java @@ -0,0 +1,67 @@ +package com.thirdparty.ticketing.domain.seat.controller; + +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.BDDMockito.given; +import static org.springframework.restdocs.mockmvc.RestDocumentationRequestBuilders.get; +import static org.springframework.restdocs.payload.PayloadDocumentation.fieldWithPath; +import static org.springframework.restdocs.payload.PayloadDocumentation.responseFields; +import static org.springframework.restdocs.request.RequestDocumentation.parameterWithName; +import static org.springframework.restdocs.request.RequestDocumentation.pathParameters; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; + +import java.util.Collections; +import java.util.List; + +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; +import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest; +import org.springframework.boot.test.mock.mockito.MockBean; +import org.springframework.context.annotation.Import; +import org.springframework.test.web.servlet.ResultActions; + +import com.thirdparty.ticketing.domain.ItemResult; +import com.thirdparty.ticketing.domain.seat.dto.SeatElement; +import com.thirdparty.ticketing.domain.seat.service.SeatService; +import com.thirdparty.ticketing.support.BaseControllerTest; + +@WebMvcTest(SeatController.class) +@Import(SeatController.class) +public class SeatControllerTest extends BaseControllerTest { + @MockBean private SeatService seatService; + + @Test + @DisplayName("구역의 좌석 목록을 조회한다.") + void getZones() throws Exception { + // Given + long performanceId = 1L; + long zoneId = 2L; + + List seatElements = + Collections.singletonList(new SeatElement(1L, "A01", true)); + + given(seatService.getSeats(any())).willReturn(ItemResult.of(seatElements)); + + // When + ResultActions result = + mockMvc.perform( + get( + "/api/performances/{performanceId}/zones/{zoneId}/seats", + performanceId, + zoneId) + .header(AUTHORIZATION_HEADER, adminBearerToken)); + + // Then + result.andExpect(status().isOk()) + .andDo( + restDocs.document( + pathParameters( + parameterWithName("performanceId").description("공연 ID"), + parameterWithName("zoneId").description("구역 ID")), + responseFields( + fieldWithPath("items").description("좌석 목록"), + fieldWithPath("items[].seatId").description("좌석 ID"), + fieldWithPath("items[].seatCode").description("좌석 코드"), + fieldWithPath("items[].seatAvailable") + .description("좌석 선택 가능 여부")))); + } +} From 1dbcbf23b9d0839bc241eeca7a64f40665b667f0 Mon Sep 17 00:00:00 2001 From: seminchoi Date: Tue, 13 Aug 2024 19:27:18 +0900 Subject: [PATCH 09/13] =?UTF-8?q?refactor:=20=EC=A2=8C=EC=84=9D=20?= =?UTF-8?q?=EC=83=81=ED=83=9C=20AVAILABLE=20=EC=97=90=EC=84=9C=20SELECTABL?= =?UTF-8?q?E=20=EB=A1=9C=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 더 직관적으로 이해하기 쉽게 네이밍 변경 --- .../java/com/thirdparty/ticketing/domain/seat/Seat.java | 2 +- .../com/thirdparty/ticketing/domain/seat/SeatStatus.java | 6 +++--- .../thirdparty/ticketing/domain/seat/dto/SeatElement.java | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/main/java/com/thirdparty/ticketing/domain/seat/Seat.java b/src/main/java/com/thirdparty/ticketing/domain/seat/Seat.java index 7578b6d0..8b01967c 100644 --- a/src/main/java/com/thirdparty/ticketing/domain/seat/Seat.java +++ b/src/main/java/com/thirdparty/ticketing/domain/seat/Seat.java @@ -41,7 +41,7 @@ public class Seat extends BaseEntity { @Enumerated(EnumType.STRING) @Builder.Default @Column(length = 16, nullable = false) - private SeatStatus seatStatus = SeatStatus.AVAILABLE; + private SeatStatus seatStatus = SeatStatus.SELECTABLE; public Seat(String seatCode, SeatStatus seatStatus) { this.seatCode = seatCode; diff --git a/src/main/java/com/thirdparty/ticketing/domain/seat/SeatStatus.java b/src/main/java/com/thirdparty/ticketing/domain/seat/SeatStatus.java index 98970932..a0b26463 100644 --- a/src/main/java/com/thirdparty/ticketing/domain/seat/SeatStatus.java +++ b/src/main/java/com/thirdparty/ticketing/domain/seat/SeatStatus.java @@ -1,12 +1,12 @@ package com.thirdparty.ticketing.domain.seat; public enum SeatStatus { - AVAILABLE, + SELECTABLE, SELECTED, PENDING_PAYMENT, PAID; - public boolean isAvailable() { - return this == AVAILABLE; + public boolean isSelectable() { + return this == SELECTABLE; } } diff --git a/src/main/java/com/thirdparty/ticketing/domain/seat/dto/SeatElement.java b/src/main/java/com/thirdparty/ticketing/domain/seat/dto/SeatElement.java index 193a97b4..9a407bd7 100644 --- a/src/main/java/com/thirdparty/ticketing/domain/seat/dto/SeatElement.java +++ b/src/main/java/com/thirdparty/ticketing/domain/seat/dto/SeatElement.java @@ -11,7 +11,7 @@ public class SeatElement { private final boolean seatAvailable; public static SeatElement of(Seat seat) { - boolean isSeatAvailable = seat.getSeatStatus().isAvailable(); + boolean isSeatAvailable = seat.getSeatStatus().isSelectable(); return new SeatElement(seat.getSeatId(), seat.getSeatCode(), isSeatAvailable); } } From 970ddaf26d2cf0519a7466430cd000e843e9ef65 Mon Sep 17 00:00:00 2001 From: seminchoi Date: Tue, 13 Aug 2024 19:28:30 +0900 Subject: [PATCH 10/13] =?UTF-8?q?refactor:=20=EC=A2=8C=EC=84=9D=20?= =?UTF-8?q?=EA=B4=80=EB=A0=A8=20DTO=20=ED=8C=A8=ED=82=A4=EC=A7=80=20reques?= =?UTF-8?q?t,=20response=20=EB=B6=84=EB=A6=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/seat/controller/AdminSeatController.java | 4 ++-- .../ticketing/domain/seat/controller/SeatController.java | 2 +- .../seat/dto/{ => request}/SeatCreationElement.java | 2 +- .../seat/dto/{ => request}/SeatCreationRequest.java | 2 +- .../seat/dto/{ => request}/SeatGradeCreationElement.java | 2 +- .../seat/dto/{ => request}/SeatGradeCreationRequest.java | 2 +- .../domain/seat/dto/{ => response}/SeatElement.java | 2 +- .../ticketing/domain/seat/service/AdminSeatService.java | 6 +++--- .../ticketing/domain/seat/service/SeatService.java | 2 +- .../domain/seat/controller/AdminSeatControllerTest.java | 8 ++++---- .../domain/seat/controller/SeatControllerTest.java | 2 +- .../domain/seat/service/AdminSeatServiceTest.java | 8 ++++---- .../ticketing/domain/seat/service/SeatServiceTest.java | 2 +- 13 files changed, 22 insertions(+), 22 deletions(-) rename src/main/java/com/thirdparty/ticketing/domain/seat/dto/{ => request}/SeatCreationElement.java (89%) rename src/main/java/com/thirdparty/ticketing/domain/seat/dto/{ => request}/SeatCreationRequest.java (75%) rename src/main/java/com/thirdparty/ticketing/domain/seat/dto/{ => request}/SeatGradeCreationElement.java (91%) rename src/main/java/com/thirdparty/ticketing/domain/seat/dto/{ => request}/SeatGradeCreationRequest.java (76%) rename src/main/java/com/thirdparty/ticketing/domain/seat/dto/{ => response}/SeatElement.java (87%) diff --git a/src/main/java/com/thirdparty/ticketing/domain/seat/controller/AdminSeatController.java b/src/main/java/com/thirdparty/ticketing/domain/seat/controller/AdminSeatController.java index 7d7eb2e4..61a96dda 100644 --- a/src/main/java/com/thirdparty/ticketing/domain/seat/controller/AdminSeatController.java +++ b/src/main/java/com/thirdparty/ticketing/domain/seat/controller/AdminSeatController.java @@ -10,8 +10,8 @@ import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; -import com.thirdparty.ticketing.domain.seat.dto.SeatCreationRequest; -import com.thirdparty.ticketing.domain.seat.dto.SeatGradeCreationRequest; +import com.thirdparty.ticketing.domain.seat.dto.request.SeatCreationRequest; +import com.thirdparty.ticketing.domain.seat.dto.request.SeatGradeCreationRequest; import com.thirdparty.ticketing.domain.seat.service.AdminSeatService; import lombok.RequiredArgsConstructor; diff --git a/src/main/java/com/thirdparty/ticketing/domain/seat/controller/SeatController.java b/src/main/java/com/thirdparty/ticketing/domain/seat/controller/SeatController.java index 5db75078..4e0e9b73 100644 --- a/src/main/java/com/thirdparty/ticketing/domain/seat/controller/SeatController.java +++ b/src/main/java/com/thirdparty/ticketing/domain/seat/controller/SeatController.java @@ -7,7 +7,7 @@ import org.springframework.web.bind.annotation.RestController; import com.thirdparty.ticketing.domain.ItemResult; -import com.thirdparty.ticketing.domain.seat.dto.SeatElement; +import com.thirdparty.ticketing.domain.seat.dto.response.SeatElement; import com.thirdparty.ticketing.domain.seat.service.SeatService; import lombok.RequiredArgsConstructor; diff --git a/src/main/java/com/thirdparty/ticketing/domain/seat/dto/SeatCreationElement.java b/src/main/java/com/thirdparty/ticketing/domain/seat/dto/request/SeatCreationElement.java similarity index 89% rename from src/main/java/com/thirdparty/ticketing/domain/seat/dto/SeatCreationElement.java rename to src/main/java/com/thirdparty/ticketing/domain/seat/dto/request/SeatCreationElement.java index cb1aa07c..a987940d 100644 --- a/src/main/java/com/thirdparty/ticketing/domain/seat/dto/SeatCreationElement.java +++ b/src/main/java/com/thirdparty/ticketing/domain/seat/dto/request/SeatCreationElement.java @@ -1,4 +1,4 @@ -package com.thirdparty.ticketing.domain.seat.dto; +package com.thirdparty.ticketing.domain.seat.dto.request; import jakarta.validation.constraints.Min; import jakarta.validation.constraints.NotBlank; diff --git a/src/main/java/com/thirdparty/ticketing/domain/seat/dto/SeatCreationRequest.java b/src/main/java/com/thirdparty/ticketing/domain/seat/dto/request/SeatCreationRequest.java similarity index 75% rename from src/main/java/com/thirdparty/ticketing/domain/seat/dto/SeatCreationRequest.java rename to src/main/java/com/thirdparty/ticketing/domain/seat/dto/request/SeatCreationRequest.java index 7ca87132..6d99db9b 100644 --- a/src/main/java/com/thirdparty/ticketing/domain/seat/dto/SeatCreationRequest.java +++ b/src/main/java/com/thirdparty/ticketing/domain/seat/dto/request/SeatCreationRequest.java @@ -1,4 +1,4 @@ -package com.thirdparty.ticketing.domain.seat.dto; +package com.thirdparty.ticketing.domain.seat.dto.request; import java.util.List; diff --git a/src/main/java/com/thirdparty/ticketing/domain/seat/dto/SeatGradeCreationElement.java b/src/main/java/com/thirdparty/ticketing/domain/seat/dto/request/SeatGradeCreationElement.java similarity index 91% rename from src/main/java/com/thirdparty/ticketing/domain/seat/dto/SeatGradeCreationElement.java rename to src/main/java/com/thirdparty/ticketing/domain/seat/dto/request/SeatGradeCreationElement.java index acf365b6..772c7f7a 100644 --- a/src/main/java/com/thirdparty/ticketing/domain/seat/dto/SeatGradeCreationElement.java +++ b/src/main/java/com/thirdparty/ticketing/domain/seat/dto/request/SeatGradeCreationElement.java @@ -1,4 +1,4 @@ -package com.thirdparty.ticketing.domain.seat.dto; +package com.thirdparty.ticketing.domain.seat.dto.request; import jakarta.validation.constraints.Min; import jakarta.validation.constraints.NotBlank; diff --git a/src/main/java/com/thirdparty/ticketing/domain/seat/dto/SeatGradeCreationRequest.java b/src/main/java/com/thirdparty/ticketing/domain/seat/dto/request/SeatGradeCreationRequest.java similarity index 76% rename from src/main/java/com/thirdparty/ticketing/domain/seat/dto/SeatGradeCreationRequest.java rename to src/main/java/com/thirdparty/ticketing/domain/seat/dto/request/SeatGradeCreationRequest.java index b4091e12..8d14438b 100644 --- a/src/main/java/com/thirdparty/ticketing/domain/seat/dto/SeatGradeCreationRequest.java +++ b/src/main/java/com/thirdparty/ticketing/domain/seat/dto/request/SeatGradeCreationRequest.java @@ -1,4 +1,4 @@ -package com.thirdparty.ticketing.domain.seat.dto; +package com.thirdparty.ticketing.domain.seat.dto.request; import java.util.List; diff --git a/src/main/java/com/thirdparty/ticketing/domain/seat/dto/SeatElement.java b/src/main/java/com/thirdparty/ticketing/domain/seat/dto/response/SeatElement.java similarity index 87% rename from src/main/java/com/thirdparty/ticketing/domain/seat/dto/SeatElement.java rename to src/main/java/com/thirdparty/ticketing/domain/seat/dto/response/SeatElement.java index 9a407bd7..4b277497 100644 --- a/src/main/java/com/thirdparty/ticketing/domain/seat/dto/SeatElement.java +++ b/src/main/java/com/thirdparty/ticketing/domain/seat/dto/response/SeatElement.java @@ -1,4 +1,4 @@ -package com.thirdparty.ticketing.domain.seat.dto; +package com.thirdparty.ticketing.domain.seat.dto.response; import com.thirdparty.ticketing.domain.seat.Seat; diff --git a/src/main/java/com/thirdparty/ticketing/domain/seat/service/AdminSeatService.java b/src/main/java/com/thirdparty/ticketing/domain/seat/service/AdminSeatService.java index a3a52a69..55c08778 100644 --- a/src/main/java/com/thirdparty/ticketing/domain/seat/service/AdminSeatService.java +++ b/src/main/java/com/thirdparty/ticketing/domain/seat/service/AdminSeatService.java @@ -12,9 +12,9 @@ import com.thirdparty.ticketing.domain.performance.repository.PerformanceRepository; import com.thirdparty.ticketing.domain.seat.Seat; import com.thirdparty.ticketing.domain.seat.SeatGrade; -import com.thirdparty.ticketing.domain.seat.dto.SeatCreationElement; -import com.thirdparty.ticketing.domain.seat.dto.SeatCreationRequest; -import com.thirdparty.ticketing.domain.seat.dto.SeatGradeCreationRequest; +import com.thirdparty.ticketing.domain.seat.dto.request.SeatCreationElement; +import com.thirdparty.ticketing.domain.seat.dto.request.SeatCreationRequest; +import com.thirdparty.ticketing.domain.seat.dto.request.SeatGradeCreationRequest; import com.thirdparty.ticketing.domain.seat.repository.SeatGradeRepository; import com.thirdparty.ticketing.domain.seat.repository.SeatRepository; import com.thirdparty.ticketing.domain.zone.Zone; diff --git a/src/main/java/com/thirdparty/ticketing/domain/seat/service/SeatService.java b/src/main/java/com/thirdparty/ticketing/domain/seat/service/SeatService.java index 6007828c..179cf52f 100644 --- a/src/main/java/com/thirdparty/ticketing/domain/seat/service/SeatService.java +++ b/src/main/java/com/thirdparty/ticketing/domain/seat/service/SeatService.java @@ -7,7 +7,7 @@ import com.thirdparty.ticketing.domain.ItemResult; import com.thirdparty.ticketing.domain.common.TicketingException; -import com.thirdparty.ticketing.domain.seat.dto.SeatElement; +import com.thirdparty.ticketing.domain.seat.dto.response.SeatElement; import com.thirdparty.ticketing.domain.seat.repository.SeatRepository; import com.thirdparty.ticketing.domain.zone.Zone; import com.thirdparty.ticketing.domain.zone.repository.ZoneRepository; diff --git a/src/test/java/com/thirdparty/ticketing/domain/seat/controller/AdminSeatControllerTest.java b/src/test/java/com/thirdparty/ticketing/domain/seat/controller/AdminSeatControllerTest.java index d5b7adbf..3d3dd9ee 100644 --- a/src/test/java/com/thirdparty/ticketing/domain/seat/controller/AdminSeatControllerTest.java +++ b/src/test/java/com/thirdparty/ticketing/domain/seat/controller/AdminSeatControllerTest.java @@ -19,10 +19,10 @@ import org.springframework.test.web.servlet.ResultActions; import com.fasterxml.jackson.core.JsonProcessingException; -import com.thirdparty.ticketing.domain.seat.dto.SeatCreationElement; -import com.thirdparty.ticketing.domain.seat.dto.SeatCreationRequest; -import com.thirdparty.ticketing.domain.seat.dto.SeatGradeCreationElement; -import com.thirdparty.ticketing.domain.seat.dto.SeatGradeCreationRequest; +import com.thirdparty.ticketing.domain.seat.dto.request.SeatCreationElement; +import com.thirdparty.ticketing.domain.seat.dto.request.SeatCreationRequest; +import com.thirdparty.ticketing.domain.seat.dto.request.SeatGradeCreationElement; +import com.thirdparty.ticketing.domain.seat.dto.request.SeatGradeCreationRequest; import com.thirdparty.ticketing.domain.seat.service.AdminSeatService; import com.thirdparty.ticketing.support.BaseControllerTest; diff --git a/src/test/java/com/thirdparty/ticketing/domain/seat/controller/SeatControllerTest.java b/src/test/java/com/thirdparty/ticketing/domain/seat/controller/SeatControllerTest.java index c79e381c..97338064 100644 --- a/src/test/java/com/thirdparty/ticketing/domain/seat/controller/SeatControllerTest.java +++ b/src/test/java/com/thirdparty/ticketing/domain/seat/controller/SeatControllerTest.java @@ -20,7 +20,7 @@ import org.springframework.test.web.servlet.ResultActions; import com.thirdparty.ticketing.domain.ItemResult; -import com.thirdparty.ticketing.domain.seat.dto.SeatElement; +import com.thirdparty.ticketing.domain.seat.dto.response.SeatElement; import com.thirdparty.ticketing.domain.seat.service.SeatService; import com.thirdparty.ticketing.support.BaseControllerTest; diff --git a/src/test/java/com/thirdparty/ticketing/domain/seat/service/AdminSeatServiceTest.java b/src/test/java/com/thirdparty/ticketing/domain/seat/service/AdminSeatServiceTest.java index 205c86d7..678edae1 100644 --- a/src/test/java/com/thirdparty/ticketing/domain/seat/service/AdminSeatServiceTest.java +++ b/src/test/java/com/thirdparty/ticketing/domain/seat/service/AdminSeatServiceTest.java @@ -18,10 +18,10 @@ import com.thirdparty.ticketing.domain.performance.repository.PerformanceRepository; import com.thirdparty.ticketing.domain.seat.Seat; import com.thirdparty.ticketing.domain.seat.SeatGrade; -import com.thirdparty.ticketing.domain.seat.dto.SeatCreationElement; -import com.thirdparty.ticketing.domain.seat.dto.SeatCreationRequest; -import com.thirdparty.ticketing.domain.seat.dto.SeatGradeCreationElement; -import com.thirdparty.ticketing.domain.seat.dto.SeatGradeCreationRequest; +import com.thirdparty.ticketing.domain.seat.dto.request.SeatCreationElement; +import com.thirdparty.ticketing.domain.seat.dto.request.SeatCreationRequest; +import com.thirdparty.ticketing.domain.seat.dto.request.SeatGradeCreationElement; +import com.thirdparty.ticketing.domain.seat.dto.request.SeatGradeCreationRequest; import com.thirdparty.ticketing.domain.seat.repository.SeatGradeRepository; import com.thirdparty.ticketing.domain.seat.repository.SeatRepository; import com.thirdparty.ticketing.domain.zone.Zone; diff --git a/src/test/java/com/thirdparty/ticketing/domain/seat/service/SeatServiceTest.java b/src/test/java/com/thirdparty/ticketing/domain/seat/service/SeatServiceTest.java index 9f195a3e..0085f796 100644 --- a/src/test/java/com/thirdparty/ticketing/domain/seat/service/SeatServiceTest.java +++ b/src/test/java/com/thirdparty/ticketing/domain/seat/service/SeatServiceTest.java @@ -20,7 +20,7 @@ import com.thirdparty.ticketing.domain.performance.Performance; import com.thirdparty.ticketing.domain.seat.Seat; import com.thirdparty.ticketing.domain.seat.SeatGrade; -import com.thirdparty.ticketing.domain.seat.dto.SeatElement; +import com.thirdparty.ticketing.domain.seat.dto.response.SeatElement; import com.thirdparty.ticketing.domain.seat.repository.SeatRepository; import com.thirdparty.ticketing.domain.zone.Zone; import com.thirdparty.ticketing.domain.zone.repository.ZoneRepository; From c0d92370a87e8efba71834e21d8cdc146e210ac4 Mon Sep 17 00:00:00 2001 From: seminchoi Date: Tue, 13 Aug 2024 19:48:57 +0900 Subject: [PATCH 11/13] =?UTF-8?q?docs:=20=EC=A2=8C=EC=84=9D=20=EC=A1=B0?= =?UTF-8?q?=ED=9A=8C=20=EA=B8=B0=EB=8A=A5=20Rest=20Docs=20adoc=20=EC=9E=91?= =?UTF-8?q?=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/docs/asciidoc/index.adoc | 12 ++++++++++-- .../domain/seat/controller/SeatControllerTest.java | 14 +++++++++++--- 2 files changed, 21 insertions(+), 5 deletions(-) diff --git a/src/docs/asciidoc/index.adoc b/src/docs/asciidoc/index.adoc index 6ba7f28a..26ed4af9 100644 --- a/src/docs/asciidoc/index.adoc +++ b/src/docs/asciidoc/index.adoc @@ -19,8 +19,6 @@ operation::member-controller-test/create-member[snippets='http-response,response = 공연(Performance) -= 장소(Place) - = 좌석(Seat) == 관리자 좌석 등급 생성 API @@ -43,6 +41,16 @@ operation::admin-seat-controller-test/create-seats[snippets='http-request,path-p operation::admin-seat-controller-test/create-seat-grades[snippets='http-response'] +== 구역의 좌석 목록 조회 + +=== request + +operation::seat-controller-test/get-zones[snippets='http-request,path-parameters'] + +=== response + +operation::seat-controller-test/get-zones[snippets='http-response,response-fields'] + = 티켓(Ticket) = API 문서화 예시 diff --git a/src/test/java/com/thirdparty/ticketing/domain/seat/controller/SeatControllerTest.java b/src/test/java/com/thirdparty/ticketing/domain/seat/controller/SeatControllerTest.java index 97338064..0649a978 100644 --- a/src/test/java/com/thirdparty/ticketing/domain/seat/controller/SeatControllerTest.java +++ b/src/test/java/com/thirdparty/ticketing/domain/seat/controller/SeatControllerTest.java @@ -17,6 +17,7 @@ import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest; import org.springframework.boot.test.mock.mockito.MockBean; import org.springframework.context.annotation.Import; +import org.springframework.restdocs.payload.JsonFieldType; import org.springframework.test.web.servlet.ResultActions; import com.thirdparty.ticketing.domain.ItemResult; @@ -58,10 +59,17 @@ void getZones() throws Exception { parameterWithName("performanceId").description("공연 ID"), parameterWithName("zoneId").description("구역 ID")), responseFields( - fieldWithPath("items").description("좌석 목록"), - fieldWithPath("items[].seatId").description("좌석 ID"), - fieldWithPath("items[].seatCode").description("좌석 코드"), + fieldWithPath("items") + .type(JsonFieldType.ARRAY) + .description("좌석 목록"), + fieldWithPath("items[].seatId") + .type(JsonFieldType.NUMBER) + .description("좌석 ID"), + fieldWithPath("items[].seatCode") + .type(JsonFieldType.STRING) + .description("좌석 코드"), fieldWithPath("items[].seatAvailable") + .type(JsonFieldType.BOOLEAN) .description("좌석 선택 가능 여부")))); } } From 8577e6359816769d40a84b951686054be50153d7 Mon Sep 17 00:00:00 2001 From: seminchoi Date: Tue, 13 Aug 2024 21:02:03 +0900 Subject: [PATCH 12/13] =?UTF-8?q?refactor:=20Seat=20=EA=B0=9D=EC=B2=B4?= =?UTF-8?q?=EC=97=90=EA=B2=8C=20=EC=84=A0=ED=83=9D=20=EA=B0=80=EB=8A=A5?= =?UTF-8?q?=ED=95=9C=EC=A7=80=20=EB=A9=94=EC=84=B8=EC=A7=80=EB=A5=BC=20?= =?UTF-8?q?=EC=A7=81=EC=A0=91=20=EC=A0=84=EB=8B=AC=ED=95=A0=20=EC=88=98=20?= =?UTF-8?q?=EC=9E=88=EB=8F=84=EB=A1=9D=20=EB=A9=94=EC=86=8C=EB=93=9C=20?= =?UTF-8?q?=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 객체 지향적으로 메세지를 전달하기 위해 구현 --- src/main/java/com/thirdparty/ticketing/domain/seat/Seat.java | 4 ++++ .../ticketing/domain/seat/dto/response/SeatElement.java | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/thirdparty/ticketing/domain/seat/Seat.java b/src/main/java/com/thirdparty/ticketing/domain/seat/Seat.java index 8b01967c..363d6faf 100644 --- a/src/main/java/com/thirdparty/ticketing/domain/seat/Seat.java +++ b/src/main/java/com/thirdparty/ticketing/domain/seat/Seat.java @@ -47,4 +47,8 @@ public Seat(String seatCode, SeatStatus seatStatus) { this.seatCode = seatCode; this.seatStatus = seatStatus; } + + public boolean isSelectable() { + return seatStatus.isSelectable(); + } } diff --git a/src/main/java/com/thirdparty/ticketing/domain/seat/dto/response/SeatElement.java b/src/main/java/com/thirdparty/ticketing/domain/seat/dto/response/SeatElement.java index 4b277497..ce19833e 100644 --- a/src/main/java/com/thirdparty/ticketing/domain/seat/dto/response/SeatElement.java +++ b/src/main/java/com/thirdparty/ticketing/domain/seat/dto/response/SeatElement.java @@ -11,7 +11,7 @@ public class SeatElement { private final boolean seatAvailable; public static SeatElement of(Seat seat) { - boolean isSeatAvailable = seat.getSeatStatus().isSelectable(); + boolean isSeatAvailable = seat.isSelectable(); return new SeatElement(seat.getSeatId(), seat.getSeatCode(), isSeatAvailable); } } From cfd38015eef7b0f3c789ddbf421baf90f2aa8f5b Mon Sep 17 00:00:00 2001 From: seminchoi Date: Tue, 13 Aug 2024 21:04:03 +0900 Subject: [PATCH 13/13] =?UTF-8?q?test:=20Controller=20Test=20=ED=95=84?= =?UTF-8?q?=EC=9A=94=EC=97=86=EB=8A=94=20Import=20=EC=A3=BC=EC=84=9D=20?= =?UTF-8?q?=EC=A0=9C=EA=B1=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/AdminPerformanceControllerTest.java | 4 +--- .../performance/controller/UserPerformanceControllerTest.java | 4 +--- .../domain/seat/controller/AdminSeatControllerTest.java | 2 -- .../ticketing/domain/seat/controller/SeatControllerTest.java | 2 -- .../domain/zone/controller/AdminZoneControllerTest.java | 4 +--- .../domain/zone/controller/UserZoneControllerTest.java | 4 +--- 6 files changed, 4 insertions(+), 16 deletions(-) diff --git a/src/test/java/com/thirdparty/ticketing/domain/performance/controller/AdminPerformanceControllerTest.java b/src/test/java/com/thirdparty/ticketing/domain/performance/controller/AdminPerformanceControllerTest.java index 0e04ce5c..a1984354 100644 --- a/src/test/java/com/thirdparty/ticketing/domain/performance/controller/AdminPerformanceControllerTest.java +++ b/src/test/java/com/thirdparty/ticketing/domain/performance/controller/AdminPerformanceControllerTest.java @@ -11,7 +11,6 @@ import org.junit.jupiter.api.Test; import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest; import org.springframework.boot.test.mock.mockito.MockBean; -import org.springframework.context.annotation.Import; import org.springframework.http.MediaType; import org.springframework.restdocs.payload.JsonFieldType; import org.springframework.test.web.servlet.ResultActions; @@ -21,8 +20,7 @@ import com.thirdparty.ticketing.domain.performance.service.AdminPerformanceService; import com.thirdparty.ticketing.support.BaseControllerTest; -@WebMvcTest(AdminPerformanceControllerTest.class) -@Import(AdminPerformanceController.class) +@WebMvcTest(AdminPerformanceController.class) class AdminPerformanceControllerTest extends BaseControllerTest { @MockBean private AdminPerformanceService adminPerformanceService; diff --git a/src/test/java/com/thirdparty/ticketing/domain/performance/controller/UserPerformanceControllerTest.java b/src/test/java/com/thirdparty/ticketing/domain/performance/controller/UserPerformanceControllerTest.java index 2b55ec0b..f3a6e904 100644 --- a/src/test/java/com/thirdparty/ticketing/domain/performance/controller/UserPerformanceControllerTest.java +++ b/src/test/java/com/thirdparty/ticketing/domain/performance/controller/UserPerformanceControllerTest.java @@ -13,7 +13,6 @@ import org.junit.jupiter.api.Test; import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest; import org.springframework.boot.test.mock.mockito.MockBean; -import org.springframework.context.annotation.Import; import org.springframework.test.web.servlet.ResultActions; import com.thirdparty.ticketing.domain.ItemResult; @@ -21,8 +20,7 @@ import com.thirdparty.ticketing.domain.performance.service.UserPerformanceService; import com.thirdparty.ticketing.support.BaseControllerTest; -@WebMvcTest(UserPerformanceControllerTest.class) -@Import(UserPerformanceController.class) +@WebMvcTest(UserPerformanceController.class) class UserPerformanceControllerTest extends BaseControllerTest { @MockBean private UserPerformanceService userPerformanceService; diff --git a/src/test/java/com/thirdparty/ticketing/domain/seat/controller/AdminSeatControllerTest.java b/src/test/java/com/thirdparty/ticketing/domain/seat/controller/AdminSeatControllerTest.java index 3d3dd9ee..e81a0731 100644 --- a/src/test/java/com/thirdparty/ticketing/domain/seat/controller/AdminSeatControllerTest.java +++ b/src/test/java/com/thirdparty/ticketing/domain/seat/controller/AdminSeatControllerTest.java @@ -13,7 +13,6 @@ import org.junit.jupiter.api.Test; import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest; import org.springframework.boot.test.mock.mockito.MockBean; -import org.springframework.context.annotation.Import; import org.springframework.http.MediaType; import org.springframework.restdocs.payload.JsonFieldType; import org.springframework.test.web.servlet.ResultActions; @@ -27,7 +26,6 @@ import com.thirdparty.ticketing.support.BaseControllerTest; @WebMvcTest(AdminSeatController.class) -@Import(AdminSeatController.class) public class AdminSeatControllerTest extends BaseControllerTest { @MockBean private AdminSeatService adminSeatService; diff --git a/src/test/java/com/thirdparty/ticketing/domain/seat/controller/SeatControllerTest.java b/src/test/java/com/thirdparty/ticketing/domain/seat/controller/SeatControllerTest.java index 0649a978..eb5c10ae 100644 --- a/src/test/java/com/thirdparty/ticketing/domain/seat/controller/SeatControllerTest.java +++ b/src/test/java/com/thirdparty/ticketing/domain/seat/controller/SeatControllerTest.java @@ -16,7 +16,6 @@ import org.junit.jupiter.api.Test; import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest; import org.springframework.boot.test.mock.mockito.MockBean; -import org.springframework.context.annotation.Import; import org.springframework.restdocs.payload.JsonFieldType; import org.springframework.test.web.servlet.ResultActions; @@ -26,7 +25,6 @@ import com.thirdparty.ticketing.support.BaseControllerTest; @WebMvcTest(SeatController.class) -@Import(SeatController.class) public class SeatControllerTest extends BaseControllerTest { @MockBean private SeatService seatService; diff --git a/src/test/java/com/thirdparty/ticketing/domain/zone/controller/AdminZoneControllerTest.java b/src/test/java/com/thirdparty/ticketing/domain/zone/controller/AdminZoneControllerTest.java index 6f9fdb4f..09bdc6d7 100644 --- a/src/test/java/com/thirdparty/ticketing/domain/zone/controller/AdminZoneControllerTest.java +++ b/src/test/java/com/thirdparty/ticketing/domain/zone/controller/AdminZoneControllerTest.java @@ -13,7 +13,6 @@ import org.junit.jupiter.api.Test; import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest; import org.springframework.boot.test.mock.mockito.MockBean; -import org.springframework.context.annotation.Import; import org.springframework.http.MediaType; import org.springframework.restdocs.payload.JsonFieldType; import org.springframework.test.web.servlet.ResultActions; @@ -25,8 +24,7 @@ import com.thirdparty.ticketing.domain.zone.service.AdminZoneService; import com.thirdparty.ticketing.support.BaseControllerTest; -@WebMvcTest(AdminZoneControllerTest.class) -@Import(AdminZoneController.class) +@WebMvcTest(AdminZoneController.class) public class AdminZoneControllerTest extends BaseControllerTest { @MockBean private AdminZoneService adminZoneService; diff --git a/src/test/java/com/thirdparty/ticketing/domain/zone/controller/UserZoneControllerTest.java b/src/test/java/com/thirdparty/ticketing/domain/zone/controller/UserZoneControllerTest.java index bd5428b6..117930ac 100644 --- a/src/test/java/com/thirdparty/ticketing/domain/zone/controller/UserZoneControllerTest.java +++ b/src/test/java/com/thirdparty/ticketing/domain/zone/controller/UserZoneControllerTest.java @@ -12,7 +12,6 @@ import org.junit.jupiter.api.Test; import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest; import org.springframework.boot.test.mock.mockito.MockBean; -import org.springframework.context.annotation.Import; import org.springframework.test.web.servlet.ResultActions; import com.thirdparty.ticketing.domain.ItemResult; @@ -21,8 +20,7 @@ import com.thirdparty.ticketing.domain.zone.service.UserZoneService; import com.thirdparty.ticketing.support.BaseControllerTest; -@WebMvcTest(UserZoneControllerTest.class) -@Import(UserZoneController.class) +@WebMvcTest(UserZoneController.class) class UserZoneControllerTest extends BaseControllerTest { @MockBean private UserZoneService userZoneService;