From e76374507008b43ca3ff36298c2313210d088298 Mon Sep 17 00:00:00 2001 From: dla0510 Date: Tue, 11 Jun 2024 21:19:51 +0900 Subject: [PATCH] =?UTF-8?q?GetPurchaseTickets=20EP=20=EC=A0=9C=EA=B1=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/PurchaseController.java | 22 +--- .../usecase/GetPurchaseTicketsUseCase.java | 40 ------- .../dto/GetPurchaseTicketsCommandDto.java | 20 ---- .../dto/GetPurchaseTicketsResponseDto.java | 28 ----- .../dto/GetPurchaseTicketsResultDto.java | 20 ---- .../controller/PurchaseControllerTest.java | 40 ------- .../GetPurchaseTicketsUseCaseTest.java | 103 ------------------ 7 files changed, 1 insertion(+), 272 deletions(-) delete mode 100644 src/main/java/com/tiketeer/Tiketeer/domain/purchase/usecase/GetPurchaseTicketsUseCase.java delete mode 100644 src/main/java/com/tiketeer/Tiketeer/domain/purchase/usecase/dto/GetPurchaseTicketsCommandDto.java delete mode 100644 src/main/java/com/tiketeer/Tiketeer/domain/purchase/usecase/dto/GetPurchaseTicketsResponseDto.java delete mode 100644 src/main/java/com/tiketeer/Tiketeer/domain/purchase/usecase/dto/GetPurchaseTicketsResultDto.java delete mode 100644 src/test/java/com/tiketeer/Tiketeer/domain/purchase/usecase/GetPurchaseTicketsUseCaseTest.java diff --git a/src/main/java/com/tiketeer/Tiketeer/domain/purchase/controller/PurchaseController.java b/src/main/java/com/tiketeer/Tiketeer/domain/purchase/controller/PurchaseController.java index 0e45699c..12122579 100644 --- a/src/main/java/com/tiketeer/Tiketeer/domain/purchase/controller/PurchaseController.java +++ b/src/main/java/com/tiketeer/Tiketeer/domain/purchase/controller/PurchaseController.java @@ -6,7 +6,6 @@ import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.DeleteMapping; -import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestBody; @@ -20,9 +19,6 @@ import com.tiketeer.Tiketeer.domain.purchase.controller.dto.PostPurchaseResponseDto; import com.tiketeer.Tiketeer.domain.purchase.usecase.CreatePurchaseUseCase; import com.tiketeer.Tiketeer.domain.purchase.usecase.DeletePurchaseItemsUseCase; -import com.tiketeer.Tiketeer.domain.purchase.usecase.GetPurchaseTicketsUseCase; -import com.tiketeer.Tiketeer.domain.purchase.usecase.dto.GetPurchaseTicketsCommandDto; -import com.tiketeer.Tiketeer.domain.purchase.usecase.dto.GetPurchaseTicketsResponseDto; import com.tiketeer.Tiketeer.response.ApiResponse; import jakarta.validation.Valid; @@ -32,16 +28,13 @@ public class PurchaseController { private final CreatePurchaseUseCase createPurchaseUseCase; private final DeletePurchaseItemsUseCase deletePurchaseItemsUseCase; - private final GetPurchaseTicketsUseCase getPurchaseTicketsUseCase; private final SecurityContextHelper securityContextHelper; @Autowired PurchaseController(CreatePurchaseUseCase createPurchaseUseCase, - DeletePurchaseItemsUseCase deletePurchaseItemsUseCase, SecurityContextHelper securityContextHelper, - GetPurchaseTicketsUseCase getPurchaseTicketsUseCase) { + DeletePurchaseItemsUseCase deletePurchaseItemsUseCase, SecurityContextHelper securityContextHelper) { this.createPurchaseUseCase = createPurchaseUseCase; this.deletePurchaseItemsUseCase = deletePurchaseItemsUseCase; - this.getPurchaseTicketsUseCase = getPurchaseTicketsUseCase; this.securityContextHelper = securityContextHelper; } @@ -62,17 +55,4 @@ public ResponseEntity deletePurchaseItems(@PathVariable UUID purchaseId, deletePurchaseItemsUseCase.deletePurchaseItems(request.convertToDto(memberEmail, purchaseId)); return ResponseEntity.status(HttpStatus.OK).build(); } - - @GetMapping("/{purchaseId}/tickets") - public ResponseEntity> getPurchaseTickets( - @PathVariable UUID purchaseId) { - - var memberEmail = securityContextHelper.getEmailInToken(); - var result = getPurchaseTicketsUseCase.getPurchaseTickets( - new GetPurchaseTicketsCommandDto(purchaseId, memberEmail)); - var responseBody = ApiResponse.wrap(GetPurchaseTicketsResponseDto.convertFromDto(result)); - - return ResponseEntity.status(HttpStatus.OK).body(responseBody); - } - } \ No newline at end of file diff --git a/src/main/java/com/tiketeer/Tiketeer/domain/purchase/usecase/GetPurchaseTicketsUseCase.java b/src/main/java/com/tiketeer/Tiketeer/domain/purchase/usecase/GetPurchaseTicketsUseCase.java deleted file mode 100644 index 3b8bbcf9..00000000 --- a/src/main/java/com/tiketeer/Tiketeer/domain/purchase/usecase/GetPurchaseTicketsUseCase.java +++ /dev/null @@ -1,40 +0,0 @@ -package com.tiketeer.Tiketeer.domain.purchase.usecase; - -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Service; - -import com.tiketeer.Tiketeer.domain.purchase.exception.PurchaseNotFoundException; -import com.tiketeer.Tiketeer.domain.purchase.repository.PurchaseRepository; -import com.tiketeer.Tiketeer.domain.purchase.service.PurchaseService; -import com.tiketeer.Tiketeer.domain.purchase.usecase.dto.GetPurchaseTicketsCommandDto; -import com.tiketeer.Tiketeer.domain.purchase.usecase.dto.GetPurchaseTicketsResultDto; -import com.tiketeer.Tiketeer.domain.ticket.Ticket; -import com.tiketeer.Tiketeer.domain.ticket.repository.TicketRepository; - -@Service -public class GetPurchaseTicketsUseCase { - private final PurchaseRepository purchaseRepository; - private final TicketRepository ticketRepository; - private final PurchaseService purchaseService; - - @Autowired - GetPurchaseTicketsUseCase(PurchaseRepository purchaseRepository, - TicketRepository ticketRepository, PurchaseService purchaseService) { - this.purchaseRepository = purchaseRepository; - this.ticketRepository = ticketRepository; - this.purchaseService = purchaseService; - } - - public GetPurchaseTicketsResultDto getPurchaseTickets(GetPurchaseTicketsCommandDto command) { - - purchaseService.validatePurchaseOwnership(command.getPurchaseId(), command.getMemberEmail()); - - var purchase = purchaseRepository.findById(command.getPurchaseId()).orElseThrow(PurchaseNotFoundException::new); - var tickets = ticketRepository.findAll(); - - return GetPurchaseTicketsResultDto.builder() - .ticketIds(tickets.stream().map(Ticket::getId).toList()) - .build(); - } - -} diff --git a/src/main/java/com/tiketeer/Tiketeer/domain/purchase/usecase/dto/GetPurchaseTicketsCommandDto.java b/src/main/java/com/tiketeer/Tiketeer/domain/purchase/usecase/dto/GetPurchaseTicketsCommandDto.java deleted file mode 100644 index 6dfac4e6..00000000 --- a/src/main/java/com/tiketeer/Tiketeer/domain/purchase/usecase/dto/GetPurchaseTicketsCommandDto.java +++ /dev/null @@ -1,20 +0,0 @@ -package com.tiketeer.Tiketeer.domain.purchase.usecase.dto; - -import java.util.UUID; - -import lombok.Builder; -import lombok.Getter; -import lombok.ToString; - -@Getter -@ToString -public class GetPurchaseTicketsCommandDto { - private final UUID purchaseId; - private final String memberEmail; - - @Builder - public GetPurchaseTicketsCommandDto(UUID purchaseId, String memberEmail) { - this.purchaseId = purchaseId; - this.memberEmail = memberEmail; - } -} diff --git a/src/main/java/com/tiketeer/Tiketeer/domain/purchase/usecase/dto/GetPurchaseTicketsResponseDto.java b/src/main/java/com/tiketeer/Tiketeer/domain/purchase/usecase/dto/GetPurchaseTicketsResponseDto.java deleted file mode 100644 index f15ca963..00000000 --- a/src/main/java/com/tiketeer/Tiketeer/domain/purchase/usecase/dto/GetPurchaseTicketsResponseDto.java +++ /dev/null @@ -1,28 +0,0 @@ -package com.tiketeer.Tiketeer.domain.purchase.usecase.dto; - -import java.util.List; -import java.util.UUID; - -import lombok.Builder; -import lombok.Getter; -import lombok.NoArgsConstructor; -import lombok.ToString; - -@Getter -@ToString -@NoArgsConstructor(force = true) -public class GetPurchaseTicketsResponseDto { - - private final List ticketIds; - - @Builder - public GetPurchaseTicketsResponseDto(List ticketIds) { - this.ticketIds = ticketIds; - } - - public static GetPurchaseTicketsResponseDto convertFromDto(GetPurchaseTicketsResultDto dto) { - return GetPurchaseTicketsResponseDto.builder() - .ticketIds(dto.getTicketIds()) - .build(); - } -} diff --git a/src/main/java/com/tiketeer/Tiketeer/domain/purchase/usecase/dto/GetPurchaseTicketsResultDto.java b/src/main/java/com/tiketeer/Tiketeer/domain/purchase/usecase/dto/GetPurchaseTicketsResultDto.java deleted file mode 100644 index 86f70442..00000000 --- a/src/main/java/com/tiketeer/Tiketeer/domain/purchase/usecase/dto/GetPurchaseTicketsResultDto.java +++ /dev/null @@ -1,20 +0,0 @@ -package com.tiketeer.Tiketeer.domain.purchase.usecase.dto; - -import java.util.List; -import java.util.UUID; - -import lombok.Builder; -import lombok.Getter; -import lombok.ToString; - -@Getter -@ToString -public class GetPurchaseTicketsResultDto { - - private final List ticketIds; - - @Builder - public GetPurchaseTicketsResultDto(List ticketIds) { - this.ticketIds = ticketIds; - } -} diff --git a/src/test/java/com/tiketeer/Tiketeer/domain/purchase/controller/PurchaseControllerTest.java b/src/test/java/com/tiketeer/Tiketeer/domain/purchase/controller/PurchaseControllerTest.java index 7556f526..38f45994 100644 --- a/src/test/java/com/tiketeer/Tiketeer/domain/purchase/controller/PurchaseControllerTest.java +++ b/src/test/java/com/tiketeer/Tiketeer/domain/purchase/controller/PurchaseControllerTest.java @@ -35,12 +35,10 @@ import com.tiketeer.Tiketeer.domain.purchase.repository.PurchaseItemRepository; import com.tiketeer.Tiketeer.domain.purchase.repository.PurchaseRepository; import com.tiketeer.Tiketeer.domain.purchase.usecase.dto.CreatePurchaseCommandDto; -import com.tiketeer.Tiketeer.domain.purchase.usecase.dto.GetPurchaseTicketsResponseDto; import com.tiketeer.Tiketeer.domain.role.constant.RoleEnum; import com.tiketeer.Tiketeer.domain.ticket.repository.TicketRepository; import com.tiketeer.Tiketeer.domain.ticketing.TicketingTestHelper; import com.tiketeer.Tiketeer.infra.redis.RedisService; -import com.tiketeer.Tiketeer.response.ApiResponse; import com.tiketeer.Tiketeer.testhelper.RedisTestHelper; import com.tiketeer.Tiketeer.testhelper.TestHelper; @@ -402,42 +400,4 @@ void deletePurchaseAllTicketsSuccess() throws Exception { assertThat(purchaseRepository.findById(purchase.getId())).isEmpty(); assertThat(purchaseItemRepository.findAll().size()).isEqualTo(0); } - - @Test - @DisplayName("티켓팅 및 티켓 생성 및 구매 > 구매 하위 티켓 목록 조회 > 성공") - @Transactional - void getPurchaseTicketsSuccess() throws Exception { - //given - String token = testHelper.registerAndLoginAndReturnAccessToken("user@example.com", RoleEnum.SELLER); - Member member = memberRepository.findAll().getFirst(); - Cookie cookie = new Cookie(JwtMetadata.ACCESS_TOKEN, token); - var ticketing = ticketingTestHelper.createTicketing(member.getId(), 1, 1000, 4); - var ticketId = ticketRepository.findAll().getFirst().getId(); - var purchaseTicketPair = purchaseTestHelper.createPurchase(member.getId(), ticketId, 2); - var purchase = purchaseTicketPair.getFirst(); - var purchaseItems = purchaseTicketPair.getSecond(); - - // when - var result = mockMvc - .perform(get("/api/purchases/{purchaseId}/tickets", purchase.getId()) - .contextPath("/api") - .contentType(MediaType.APPLICATION_JSON) - .characterEncoding("utf-8") - .cookie(cookie) - ) - //then - .andExpect(status().isOk()); - //then - - ApiResponse response = testHelper.getDeserializedApiResponse( - result.andReturn().getResponse().getContentAsString(), - GetPurchaseTicketsResponseDto.class); - - var ticketIds = response.getData().getTicketIds(); - assertThat(ticketIds.size()).isEqualTo(2); - purchaseItems.forEach(ticket -> { - assertThat(ticketIds.contains(ticket.getId())).isTrue(); - }); - } - } diff --git a/src/test/java/com/tiketeer/Tiketeer/domain/purchase/usecase/GetPurchaseTicketsUseCaseTest.java b/src/test/java/com/tiketeer/Tiketeer/domain/purchase/usecase/GetPurchaseTicketsUseCaseTest.java deleted file mode 100644 index 7167d4a0..00000000 --- a/src/test/java/com/tiketeer/Tiketeer/domain/purchase/usecase/GetPurchaseTicketsUseCaseTest.java +++ /dev/null @@ -1,103 +0,0 @@ -package com.tiketeer.Tiketeer.domain.purchase.usecase; - -import static org.assertj.core.api.Assertions.*; - -import java.util.UUID; - -import org.junit.jupiter.api.AfterEach; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.DisplayName; -import org.junit.jupiter.api.Test; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.context.annotation.Import; -import org.springframework.transaction.annotation.Transactional; - -import com.tiketeer.Tiketeer.domain.purchase.PurchaseTestHelper; -import com.tiketeer.Tiketeer.domain.purchase.exception.AccessForNotOwnedPurchaseException; -import com.tiketeer.Tiketeer.domain.purchase.exception.PurchaseNotFoundException; -import com.tiketeer.Tiketeer.domain.purchase.usecase.dto.GetPurchaseTicketsCommandDto; -import com.tiketeer.Tiketeer.domain.ticketing.TicketingTestHelper; -import com.tiketeer.Tiketeer.testhelper.TestHelper; - -@Import({TestHelper.class, TicketingTestHelper.class, PurchaseTestHelper.class}) -@SpringBootTest -class GetPurchaseTicketsUseCaseTest { - @Autowired - private TestHelper testHelper; - @Autowired - private TicketingTestHelper ticketingTestHelper; - @Autowired - private PurchaseTestHelper purchaseTestHelper; - @Autowired - private GetPurchaseTicketsUseCase getPurchaseTicketsUseCase; - - @BeforeEach - void initTable() { - testHelper.initDB(); - } - - @AfterEach - void cleanTable() { - testHelper.cleanDB(); - } - - @Test - @DisplayName("티켓 구매 > 하나의 구매 하위 티켓 목록 조회 > 성공") - @Transactional - void getPurchaseTicketsSuccess() { - //given - var email = "test@test.com"; - var member = testHelper.createMember(email, "1q2w3e4r!!"); - var ticketing = ticketingTestHelper.createTicketing(member.getId(), 0, 10); - var purchaseTicketPair = purchaseTestHelper.createPurchase(member.getId(), ticketing.getId(), 5); - var purchase = purchaseTicketPair.getFirst(); - var tickets = purchaseTicketPair.getSecond(); - //when - var ticketIds = getPurchaseTicketsUseCase.getPurchaseTickets( - new GetPurchaseTicketsCommandDto(purchase.getId(), email)).getTicketIds(); - - //then - assertThat(ticketIds.size()).isEqualTo(5); - tickets.forEach(ticket -> { - assertThat(ticketIds.contains(ticket.getId())).isTrue(); - }); - - } - - @Test - @DisplayName("존재하지 않는 구매 > 하위 티켓 목록 조회 > 실패") - @Transactional - void getPurchaseTicketsFailNoSuchPurchase() { - //given - var email = "test@test.com"; - testHelper.createMember(email, "1q2w3e4r!!"); - - assertThatThrownBy(() -> { - //when - getPurchaseTicketsUseCase.getPurchaseTickets(new GetPurchaseTicketsCommandDto(UUID.randomUUID(), email)); - //then - }).isInstanceOf(PurchaseNotFoundException.class); - - } - - @Test - @DisplayName("구매 내역 소유자가 아님 > 티켓 조회 요청 > 실패") - @Transactional - void getPurchaseTicketsFailNotPurchaseOwner() { - //given - var email = "test@test.com"; - var member = testHelper.createMember(email, "1q2w3e4r!!"); - var ticketing = ticketingTestHelper.createTicketing(member.getId(), 0, 10); - var purchaseTicketPair = purchaseTestHelper.createPurchase(member.getId(), ticketing.getId(), 5); - var purchase = purchaseTicketPair.getFirst(); - - assertThatThrownBy(() -> { - //when - getPurchaseTicketsUseCase.getPurchaseTickets( - new GetPurchaseTicketsCommandDto(purchase.getId(), "malory@test.com")); - //then - }).isInstanceOf(AccessForNotOwnedPurchaseException.class); - - } -} \ No newline at end of file