From 1c3b0e439d64e2fde7adde4effe731584b022a90 Mon Sep 17 00:00:00 2001 From: dla0510 Date: Wed, 29 May 2024 03:56:37 +0900 Subject: [PATCH 1/8] =?UTF-8?q?prod=20docker-compose=20=EB=B0=8F=20nginx?= =?UTF-8?q?=20=EC=84=A4=EC=A0=95=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docker-compose.prod.yml | 18 +++++++++++++++++- nginx.dev.conf | 10 +++++++++- nginx.prod.conf | 10 +++++++++- 3 files changed, 35 insertions(+), 3 deletions(-) diff --git a/docker-compose.prod.yml b/docker-compose.prod.yml index 877a70e2..a53956b1 100644 --- a/docker-compose.prod.yml +++ b/docker-compose.prod.yml @@ -14,7 +14,10 @@ services: environment: SPRING_CONFIG_LOCATION: file:///etc/additional.yml volumes: - - ./src/main/resources/application-prod.yml:/etc/additional.yml + - type: bind + source: ./src/main/resources/application-prod.yml + target: /etc/additional.yml + nginx: image: nginx:latest @@ -27,6 +30,7 @@ services: - was networks: - common-network + mysql: image: mysql:8.0.33 expose: @@ -43,6 +47,7 @@ services: restart: unless-stopped networks: - common-network + redis: image: redis:6.2-alpine expose: @@ -68,6 +73,17 @@ services: networks: - common-network + client: + image: tiketeer-fe + expose: + - 80 + depends_on: + - was + - waiting + restart: unless-stopped + networks: + - common-network + networks: common-network: driver: bridge diff --git a/nginx.dev.conf b/nginx.dev.conf index fc684dc9..7512981c 100644 --- a/nginx.dev.conf +++ b/nginx.dev.conf @@ -15,12 +15,20 @@ http { keepalive 10; } + upstream client { + zone upstream 64K; + server host.docker.internal:3000 fail_timeout=5s; + keepalive 10; + } + server { listen 8888; server_name tiketeer; location / { - return 200 "NginX Health Check"; + proxy_pass http://client; + proxy_http_version 1.1; + proxy_set_header Connection ""; } location /api/waiting { diff --git a/nginx.prod.conf b/nginx.prod.conf index 110dd5b2..f387c7b9 100644 --- a/nginx.prod.conf +++ b/nginx.prod.conf @@ -15,12 +15,20 @@ http { keepalive 10; } + upstream client { + zone upstream 64K; + server client:80 fail_timeout=5s; + keepalive 10; + } + server { listen 8888; server_name tiketeer; location / { - return 200 "NginX Health Check"; + proxy_pass http://client; + proxy_http_version 1.1; + proxy_set_header Connection ""; } location /api/waiting { From 8bfa9a7e1c612a36583d8f6e652d91844e13d4a5 Mon Sep 17 00:00:00 2001 From: dla0510 Date: Wed, 29 May 2024 04:11:47 +0900 Subject: [PATCH 2/8] =?UTF-8?q?redis=20docker=20compose=20=EC=84=A4?= =?UTF-8?q?=EC=A0=95=20dev=20=EC=84=A4=EC=A0=95=20=EC=95=88=EC=97=90=20?= =?UTF-8?q?=ED=8F=AC=ED=95=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docker-compose.dev.yml | 14 +++++++++++++- docker-compose.redis.yml | 12 ------------ 2 files changed, 13 insertions(+), 13 deletions(-) delete mode 100644 docker-compose.redis.yml diff --git a/docker-compose.dev.yml b/docker-compose.dev.yml index e66da889..0bf0e80d 100644 --- a/docker-compose.dev.yml +++ b/docker-compose.dev.yml @@ -11,4 +11,16 @@ services: - '--collation-server=utf8mb4_unicode_ci' environment: MYSQL_ROOT_PASSWORD: ${DB_PASSWORD} - MYSQL_DATABASE: ${DB_DATABASE} \ No newline at end of file + MYSQL_DATABASE: ${DB_DATABASE} + + redis: + image: redis:6.2-alpine + ports: + - ${REDIS_PORT}:6379 + environment: + REDIS_PASSWORD: '${REDIS_PASSWORD}' + command: redis-server /usr/local/etc/redis/redis.conf --save 20 1 --loglevel warning --requirepass $REDIS_PASSWORD + volumes: + - ./db/redis/data:/data + - ./redis.conf:/usr/local/etc/redis/redis.conf + restart: always \ No newline at end of file diff --git a/docker-compose.redis.yml b/docker-compose.redis.yml deleted file mode 100644 index df33ccec..00000000 --- a/docker-compose.redis.yml +++ /dev/null @@ -1,12 +0,0 @@ -services: - redis: - image: redis:6.2-alpine - ports: - - ${REDIS_PORT}:6379 - environment: - REDIS_PASSWORD: '${REDIS_PASSWORD}' - command: redis-server /usr/local/etc/redis/redis.conf --save 20 1 --loglevel warning --requirepass $REDIS_PASSWORD - volumes: - - ./db/redis/data:/data - - ./redis.conf:/usr/local/etc/redis/redis.conf - restart: always \ No newline at end of file From 9d0003d052af5d6b3d75e10ec4c385c86de869b3 Mon Sep 17 00:00:00 2001 From: dla0510 Date: Wed, 29 May 2024 09:56:24 +0900 Subject: [PATCH 3/8] =?UTF-8?q?nginx=20docker=20compose=20=EC=84=A4?= =?UTF-8?q?=EC=A0=95=20dev=20=EC=84=A4=EC=A0=95=20=EC=95=88=EC=97=90=20?= =?UTF-8?q?=ED=8F=AC=ED=95=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docker-compose.dev.yml | 12 +++++++++++- docker-compose.nginx.yml | 12 ------------ 2 files changed, 11 insertions(+), 13 deletions(-) delete mode 100644 docker-compose.nginx.yml diff --git a/docker-compose.dev.yml b/docker-compose.dev.yml index 0bf0e80d..9b442710 100644 --- a/docker-compose.dev.yml +++ b/docker-compose.dev.yml @@ -23,4 +23,14 @@ services: volumes: - ./db/redis/data:/data - ./redis.conf:/usr/local/etc/redis/redis.conf - restart: always \ No newline at end of file + restart: always + + nginx: + image: nginx:latest + restart: unless-stopped + extra_hosts: + - "host.docker.internal:host-gateway" + ports: + - 8888:8888 + volumes: + - ./nginx.dev.conf:/etc/nginx/nginx.conf \ No newline at end of file diff --git a/docker-compose.nginx.yml b/docker-compose.nginx.yml deleted file mode 100644 index 1ae9de98..00000000 --- a/docker-compose.nginx.yml +++ /dev/null @@ -1,12 +0,0 @@ -version: '3' - -services: - nginx: - image: nginx:latest - restart: unless-stopped - extra_hosts: - - "host.docker.internal:host-gateway" - ports: - - 8888:8888 - volumes: - - ./nginx.dev.conf:/etc/nginx/nginx.conf \ No newline at end of file From 4f9243303112afa9b128ffdea26ac96f450b1362 Mon Sep 17 00:00:00 2001 From: punkryn Date: Mon, 10 Jun 2024 16:21:40 +0900 Subject: [PATCH 4/8] =?UTF-8?q?ticketing=20repository=20=EB=A7=88=EC=9D=B4?= =?UTF-8?q?=EA=B7=B8=EB=A0=88=EC=9D=B4=EC=85=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../dto/GetMemberTicketingSalesResultDto.java | 28 ++++---- .../Tiketeer/domain/ticket/Ticket.java | 17 ++++- .../Tiketeer/domain/ticketing/Ticketing.java | 9 ++- .../dto/GetTicketingResponseDto.java | 19 ++---- .../repository/TicketingRepository.java | 30 ++++----- .../usecase/GetTicketingUseCase.java | 5 +- .../ticketing/usecase/dto/GetTicketing.java | 67 +++++++++++++++++++ .../usecase/dto/GetTicketingResultDto.java | 53 ++++++++++++--- .../controller/MemberControllerTest.java | 14 ++-- .../service/MemberTicketingServiceTest.java | 6 +- .../GetMemberPurchasesUseCaseTest.java | 8 +-- .../repository/PurchaseRepositoryTest.java | 8 +-- .../controller/TicketingControllerTest.java | 4 +- .../repository/TicketingRepositoryTest.java | 41 +++++++----- .../usecase/GetAllTicketingsUseCaseTest.java | 2 +- .../usecase/GetTicketingUseCaseTest.java | 4 +- 16 files changed, 215 insertions(+), 100 deletions(-) create mode 100644 src/main/java/com/tiketeer/Tiketeer/domain/ticketing/usecase/dto/GetTicketing.java diff --git a/src/main/java/com/tiketeer/Tiketeer/domain/member/usecase/dto/GetMemberTicketingSalesResultDto.java b/src/main/java/com/tiketeer/Tiketeer/domain/member/usecase/dto/GetMemberTicketingSalesResultDto.java index 1a40ad3e..c0d29871 100644 --- a/src/main/java/com/tiketeer/Tiketeer/domain/member/usecase/dto/GetMemberTicketingSalesResultDto.java +++ b/src/main/java/com/tiketeer/Tiketeer/domain/member/usecase/dto/GetMemberTicketingSalesResultDto.java @@ -12,6 +12,19 @@ @ToString @NoArgsConstructor(force = true) public class GetMemberTicketingSalesResultDto { + private final UUID ticketingId; + private final String title; + private final String description; + private final String location; + private final LocalDateTime eventTime; + private final LocalDateTime saleStart; + private final LocalDateTime saleEnd; + private final long stock; + private final long remainStock; + private final LocalDateTime createdAt; + private final String category; + private final int runningMinutes; + private final long price; @Builder public GetMemberTicketingSalesResultDto( @@ -43,19 +56,4 @@ public GetMemberTicketingSalesResultDto( this.runningMinutes = runningMinutes; this.price = price; } - - private final UUID ticketingId; - private final String title; - private final String description; - private final String location; - private final LocalDateTime eventTime; - private final LocalDateTime saleStart; - private final LocalDateTime saleEnd; - private final long stock; - private final long remainStock; - private final LocalDateTime createdAt; - private final String category; - private final int runningMinutes; - private final long price; - } diff --git a/src/main/java/com/tiketeer/Tiketeer/domain/ticket/Ticket.java b/src/main/java/com/tiketeer/Tiketeer/domain/ticket/Ticket.java index a25d9b38..b2c52052 100644 --- a/src/main/java/com/tiketeer/Tiketeer/domain/ticket/Ticket.java +++ b/src/main/java/com/tiketeer/Tiketeer/domain/ticket/Ticket.java @@ -73,11 +73,24 @@ public class Ticket { private Integer version; @Builder - public Ticket(long price, int stock, int remainingStock, Ticketing ticketing) { + public Ticket(long price, int stock, int remainingStock, String title, Ticketing ticketing) { this.price = price; this.stock = stock; this.remainingStock = remainingStock; - this.ticketing = ticketing; + this.title = title; + setTicketing(ticketing); } + public void setTicketing(Ticketing ticketing) { + if (this.ticketing != null) { + this.ticketing.getTickets().remove(this); + } + this.ticketing = ticketing; + + if (ticketing == null) { + return; + } + + this.ticketing.getTickets().add(this); + } } diff --git a/src/main/java/com/tiketeer/Tiketeer/domain/ticketing/Ticketing.java b/src/main/java/com/tiketeer/Tiketeer/domain/ticketing/Ticketing.java index c42ce907..22fdc74d 100644 --- a/src/main/java/com/tiketeer/Tiketeer/domain/ticketing/Ticketing.java +++ b/src/main/java/com/tiketeer/Tiketeer/domain/ticketing/Ticketing.java @@ -1,6 +1,8 @@ package com.tiketeer.Tiketeer.domain.ticketing; import java.time.LocalDateTime; +import java.util.ArrayList; +import java.util.List; import java.util.UUID; import org.hibernate.annotations.UuidGenerator; @@ -9,6 +11,7 @@ import com.tiketeer.Tiketeer.constant.StorageEnum; import com.tiketeer.Tiketeer.domain.member.Member; +import com.tiketeer.Tiketeer.domain.ticket.Ticket; import jakarta.persistence.Column; import jakarta.persistence.ConstraintMode; @@ -21,6 +24,7 @@ import jakarta.persistence.Id; import jakarta.persistence.JoinColumn; import jakarta.persistence.ManyToOne; +import jakarta.persistence.OneToMany; import jakarta.persistence.Table; import jakarta.persistence.Temporal; import jakarta.persistence.TemporalType; @@ -29,14 +33,12 @@ import lombok.Getter; import lombok.NoArgsConstructor; import lombok.Setter; -import lombok.ToString; @Entity @NoArgsConstructor(access = AccessLevel.PROTECTED) @Table(name = "ticketings") @EntityListeners(AuditingEntityListener.class) @Getter -@ToString public class Ticketing { @Id @UuidGenerator @@ -98,6 +100,9 @@ public class Ticketing { @Column(name = "created_at", nullable = false) private LocalDateTime createdAt; + @OneToMany(mappedBy = "ticketing") + private List tickets = new ArrayList<>(); + @Builder public Ticketing( Member member, diff --git a/src/main/java/com/tiketeer/Tiketeer/domain/ticketing/controller/dto/GetTicketingResponseDto.java b/src/main/java/com/tiketeer/Tiketeer/domain/ticketing/controller/dto/GetTicketingResponseDto.java index cb4a6b10..86e83206 100644 --- a/src/main/java/com/tiketeer/Tiketeer/domain/ticketing/controller/dto/GetTicketingResponseDto.java +++ b/src/main/java/com/tiketeer/Tiketeer/domain/ticketing/controller/dto/GetTicketingResponseDto.java @@ -1,6 +1,7 @@ package com.tiketeer.Tiketeer.domain.ticketing.controller.dto; import java.time.LocalDateTime; +import java.util.List; import java.util.UUID; import com.tiketeer.Tiketeer.domain.ticketing.usecase.dto.GetTicketingResultDto; @@ -18,15 +19,13 @@ public class GetTicketingResponseDto { private final String location; private final String category; private final Integer runningMinutes; - private final Long stock; - private final Long remainStock; - private final Long price; private final LocalDateTime eventTime; private final LocalDateTime saleStart; private final LocalDateTime saleEnd; private final LocalDateTime createdAt; private final String owner; private final String thumbnailPath; + private final List tickets; @Builder public GetTicketingResponseDto(UUID ticketingId, String title, @@ -34,28 +33,24 @@ public GetTicketingResponseDto(UUID ticketingId, String title, String location, String category, Integer runningMinutes, - Long stock, - Long remainStock, - Long price, LocalDateTime eventTime, LocalDateTime saleStart, LocalDateTime saleEnd, LocalDateTime createdAt, String owner, - String thumbnailPath) { + String thumbnailPath, + List tickets) { this.ticketingId = ticketingId; this.title = title; this.description = description; this.location = location; this.category = category; this.runningMinutes = runningMinutes; - this.stock = stock; - this.remainStock = remainStock; - this.price = price; this.eventTime = eventTime; this.saleStart = saleStart; this.saleEnd = saleEnd; this.createdAt = createdAt; this.owner = owner; this.thumbnailPath = thumbnailPath; + this.tickets = tickets; } public static GetTicketingResponseDto convertFromDto(GetTicketingResultDto dto) { @@ -66,15 +61,13 @@ public static GetTicketingResponseDto convertFromDto(GetTicketingResultDto dto) .location(dto.getLocation()) .category(dto.getCategory()) .runningMinutes(dto.getRunningMinutes()) - .stock(dto.getStock()) - .remainStock(dto.getRemainStock()) - .price(dto.getPrice()) .eventTime(dto.getEventTime()) .saleStart(dto.getSaleStart()) .saleEnd(dto.getSaleEnd()) .createdAt(dto.getCreatedAt()) .owner(dto.getOwner()) .thumbnailPath(dto.getThumbnailPath()) + .tickets(dto.getTickets()) .build(); } } diff --git a/src/main/java/com/tiketeer/Tiketeer/domain/ticketing/repository/TicketingRepository.java b/src/main/java/com/tiketeer/Tiketeer/domain/ticketing/repository/TicketingRepository.java index 788fe83f..d0eb35df 100644 --- a/src/main/java/com/tiketeer/Tiketeer/domain/ticketing/repository/TicketingRepository.java +++ b/src/main/java/com/tiketeer/Tiketeer/domain/ticketing/repository/TicketingRepository.java @@ -12,7 +12,7 @@ import com.tiketeer.Tiketeer.domain.member.usecase.dto.GetMemberTicketingSalesResultDto; import com.tiketeer.Tiketeer.domain.ticketing.Ticketing; import com.tiketeer.Tiketeer.domain.ticketing.usecase.dto.GetAllTicketingsResultDto; -import com.tiketeer.Tiketeer.domain.ticketing.usecase.dto.GetTicketingResultDto; +import com.tiketeer.Tiketeer.domain.ticketing.usecase.dto.GetTicketing; @Repository public interface TicketingRepository extends JpaRepository { @@ -20,9 +20,10 @@ public interface TicketingRepository extends JpaRepository { @Query(value = """ select new com.tiketeer.Tiketeer.domain.member.usecase.dto.GetMemberTicketingSalesResultDto( t.id, t.title, t.description, t.location, t.eventTime, t.saleStart, t.saleEnd, - (select count(tk) from Ticket tk where tk.ticketing = t), - (select count(tk) from Ticket tk where tk.ticketing = t), - t.createdAt, t.category, t.runningMinutes, 0 as price + (select SUM(tk.stock) from Ticket tk where tk.ticketing = t), + (select SUM(tk.remainingStock) from Ticket tk where tk.ticketing = t), + t.createdAt, t.category, t.runningMinutes, + (select SUM(tk.price) from Ticket tk where tk.ticketing = t) ) from Ticketing t where t.member.email = :email @@ -32,26 +33,21 @@ public interface TicketingRepository extends JpaRepository { @Query(value = """ SELECT new com.tiketeer.Tiketeer.domain.ticketing.usecase.dto.GetAllTicketingsResultDto( - t.id, t.title, t.location, t.category, t.runningMinutes, COUNT(*), 0 as price, t.eventTime, + t.id, t.title, t.location, t.category, t.runningMinutes, SUM(tk.remainingStock), MIN(tk.price), t.eventTime, t.saleStart, t.saleEnd, t.createdAt - ) - FROM Ticketing t - LEFT JOIN Ticket tk ON t = tk.ticketing + ) + FROM Ticketing t + LEFT JOIN Ticket tk ON t = tk.ticketing GROUP BY t.id """) List findAllTicketingsWithRemainStock(); @Query(value = """ - SELECT new com.tiketeer.Tiketeer.domain.ticketing.usecase.dto.GetTicketingResultDto( - t.id, t.title, t.description, t.location, t.category, t.runningMinutes, - count(*), count(*), - 0 as price, t.eventTime, - t.saleStart, t.saleEnd, t.createdAt, t.member.email, t.thumbnailPath - ) - FROM Ticketing t LEFT JOIN Ticket tk ON t = tk.ticketing - WHERE t.id = :ticketingId GROUP BY t.id + SELECT t + FROM Ticketing t LEFT JOIN FETCH t.tickets tk + WHERE t.id = :ticketingId """) - GetTicketingResultDto findTicketingWithRemainStock(@Param("ticketingId") UUID ticketingId); + GetTicketing findTicketingWithRemainStock(@Param("ticketingId") UUID ticketingId); List findAllByMember(Member member); } diff --git a/src/main/java/com/tiketeer/Tiketeer/domain/ticketing/usecase/GetTicketingUseCase.java b/src/main/java/com/tiketeer/Tiketeer/domain/ticketing/usecase/GetTicketingUseCase.java index cbe77f34..f7de1f79 100644 --- a/src/main/java/com/tiketeer/Tiketeer/domain/ticketing/usecase/GetTicketingUseCase.java +++ b/src/main/java/com/tiketeer/Tiketeer/domain/ticketing/usecase/GetTicketingUseCase.java @@ -6,6 +6,7 @@ import com.tiketeer.Tiketeer.domain.ticket.service.TicketCrudService; import com.tiketeer.Tiketeer.domain.ticketing.repository.TicketingRepository; +import com.tiketeer.Tiketeer.domain.ticketing.usecase.dto.GetTicketing; import com.tiketeer.Tiketeer.domain.ticketing.usecase.dto.GetTicketingCommandDto; import com.tiketeer.Tiketeer.domain.ticketing.usecase.dto.GetTicketingResultDto; @@ -22,6 +23,8 @@ public GetTicketingUseCase(TicketingRepository ticketingRepository, TicketCrudSe } public GetTicketingResultDto getTicketing(GetTicketingCommandDto command) { - return ticketingRepository.findTicketingWithRemainStock(command.getTicketingId()); + GetTicketing ticketingWithRemainStock = ticketingRepository.findTicketingWithRemainStock( + command.getTicketingId()); + return new GetTicketingResultDto(ticketingWithRemainStock); } } diff --git a/src/main/java/com/tiketeer/Tiketeer/domain/ticketing/usecase/dto/GetTicketing.java b/src/main/java/com/tiketeer/Tiketeer/domain/ticketing/usecase/dto/GetTicketing.java new file mode 100644 index 00000000..67ca7ea0 --- /dev/null +++ b/src/main/java/com/tiketeer/Tiketeer/domain/ticketing/usecase/dto/GetTicketing.java @@ -0,0 +1,67 @@ +package com.tiketeer.Tiketeer.domain.ticketing.usecase.dto; + +import java.time.LocalDateTime; +import java.util.List; +import java.util.UUID; + +import org.springframework.beans.factory.annotation.Value; + +public interface GetTicketing { + @Value("#{target.id}") + UUID getTicketingId(); + + @Value("#{target.title}") + String getTitle(); + + @Value("#{target.description}") + String getDescription(); + + @Value("#{target.location}") + String getLocation(); + + @Value("#{target.category}") + String getCategory(); + + @Value("#{target.runningMinutes}") + Integer getRunningMinutes(); + + @Value("#{target.eventTime}") + LocalDateTime getEventTime(); + + @Value("#{target.saleStart}") + LocalDateTime getSaleStart(); + + @Value("#{target.saleEnd}") + LocalDateTime getSaleEnd(); + + @Value("#{target.createdAt}") + LocalDateTime getCreatedAt(); + + @Value("#{target.owner}") + String getOwner(); + + @Value("#{target.thumbnailPath}") + String getThumbnailPath(); + + List getTickets(); + + interface GetTicketingTickets { + @Value("#{target.id}") + UUID getTicketId(); + + @Value("#{target.price}") + Long getPrice(); + + @Value("#{target.stock}") + Integer getStock(); + + @Value("#{target.remainingStock}") + Integer getRemainingStock(); + + @Value("#{target.title}") + String getTitle(); + + @Value("#{target.description}") + String getDescription(); + } +} diff --git a/src/main/java/com/tiketeer/Tiketeer/domain/ticketing/usecase/dto/GetTicketingResultDto.java b/src/main/java/com/tiketeer/Tiketeer/domain/ticketing/usecase/dto/GetTicketingResultDto.java index 4fea9673..6ccbbe5d 100644 --- a/src/main/java/com/tiketeer/Tiketeer/domain/ticketing/usecase/dto/GetTicketingResultDto.java +++ b/src/main/java/com/tiketeer/Tiketeer/domain/ticketing/usecase/dto/GetTicketingResultDto.java @@ -1,10 +1,12 @@ package com.tiketeer.Tiketeer.domain.ticketing.usecase.dto; import java.time.LocalDateTime; +import java.util.List; import java.util.UUID; import lombok.Builder; import lombok.Getter; +import lombok.NoArgsConstructor; import lombok.ToString; @ToString @@ -16,15 +18,13 @@ public class GetTicketingResultDto { private final String location; private final String category; private final Integer runningMinutes; - private final Long stock; - private final Long remainStock; - private final Long price; private final LocalDateTime eventTime; private final LocalDateTime saleStart; private final LocalDateTime saleEnd; private final LocalDateTime createdAt; private final String owner; private final String thumbnailPath; + private final List tickets; @Builder public GetTicketingResultDto(UUID ticketingId, String title, @@ -32,27 +32,60 @@ public GetTicketingResultDto(UUID ticketingId, String title, String location, String category, Integer runningMinutes, - Long stock, - Long remainStock, - Long price, LocalDateTime eventTime, LocalDateTime saleStart, LocalDateTime saleEnd, LocalDateTime createdAt, String owner, - String thumbnailPath) { + String thumbnailPath, + List tickets) { this.ticketingId = ticketingId; this.title = title; this.description = description; this.location = location; this.category = category; this.runningMinutes = runningMinutes; - this.stock = stock; - this.remainStock = remainStock; - this.price = price; this.eventTime = eventTime; this.saleStart = saleStart; this.saleEnd = saleEnd; this.createdAt = createdAt; this.owner = owner; this.thumbnailPath = thumbnailPath; + this.tickets = tickets; + } + + public GetTicketingResultDto(GetTicketing t) { + this.ticketingId = t.getTicketingId(); + this.title = t.getTitle(); + this.description = t.getDescription(); + this.location = t.getLocation(); + this.category = t.getCategory(); + this.runningMinutes = t.getRunningMinutes(); + this.eventTime = t.getEventTime(); + this.saleStart = t.getSaleStart(); + this.saleEnd = t.getSaleEnd(); + this.createdAt = t.getCreatedAt(); + this.owner = t.getOwner(); + this.thumbnailPath = t.getThumbnailPath(); + this.tickets = t.getTickets().stream().map(TicketingTicket::new).toList(); + } + + @Getter + @ToString + @NoArgsConstructor(force = true) + public static class TicketingTicket { + private final UUID id; + private long price; + private final Integer stock; + private final Integer remainingStock; + private final String title; + private final String description; + + public TicketingTicket(GetTicketing.GetTicketingTickets gtt) { + this.id = gtt.getTicketId(); + this.price = gtt.getPrice(); + this.stock = gtt.getStock(); + this.remainingStock = gtt.getRemainingStock(); + this.title = gtt.getTitle(); + this.description = gtt.getDescription(); + } } } diff --git a/src/test/java/com/tiketeer/Tiketeer/domain/member/controller/MemberControllerTest.java b/src/test/java/com/tiketeer/Tiketeer/domain/member/controller/MemberControllerTest.java index 8ad5aa52..b543de93 100644 --- a/src/test/java/com/tiketeer/Tiketeer/domain/member/controller/MemberControllerTest.java +++ b/src/test/java/com/tiketeer/Tiketeer/domain/member/controller/MemberControllerTest.java @@ -99,9 +99,9 @@ void getMemberTicketingSalesSuccess() throws Exception { .build() ); var purchase = purchaseRepository.save(new Purchase(member)); - ticketRepository.save(new Ticket(1000, 1, 1, ticketing)); - ticketRepository.save(new Ticket(1000, 1, 1, ticketing)); - ticketRepository.save(new Ticket(1000, 1, 1, ticketing)); + ticketRepository.save(new Ticket(1000, 1, 1, "title 1", ticketing)); + ticketRepository.save(new Ticket(1000, 1, 1, "title 1", ticketing)); + ticketRepository.save(new Ticket(1000, 1, 1, "title 1", ticketing)); //when - then MvcResult result = mockMvc.perform(get("/api/members/" + member.getId() + "/sale") @@ -364,10 +364,10 @@ void getMemberPurchasesSuccess() throws Exception { ); var purchase1 = purchaseRepository.save(new Purchase(member)); var purchase2 = purchaseRepository.save(new Purchase(member)); - ticketRepository.save(new Ticket(1000, 1, 1, ticketing1)); - ticketRepository.save(new Ticket(1000, 1, 1, ticketing1)); - ticketRepository.save(new Ticket(1000, 1, 1, ticketing1)); - ticketRepository.save(new Ticket(1000, 1, 1, ticketing2)); + ticketRepository.save(new Ticket(1000, 1, 1, "title 1", ticketing1)); + ticketRepository.save(new Ticket(1000, 1, 1, "title 1", ticketing1)); + ticketRepository.save(new Ticket(1000, 1, 1, "title 1", ticketing1)); + ticketRepository.save(new Ticket(1000, 1, 1, "title 1", ticketing2)); // when var result = mockMvc.perform(get("/api/members/{memberId}/purchases", member.getId()) diff --git a/src/test/java/com/tiketeer/Tiketeer/domain/member/service/MemberTicketingServiceTest.java b/src/test/java/com/tiketeer/Tiketeer/domain/member/service/MemberTicketingServiceTest.java index 7dc906c0..07a31874 100644 --- a/src/test/java/com/tiketeer/Tiketeer/domain/member/service/MemberTicketingServiceTest.java +++ b/src/test/java/com/tiketeer/Tiketeer/domain/member/service/MemberTicketingServiceTest.java @@ -69,9 +69,9 @@ void getMemberTicketingSalesSuccess() { .build() ); var purchase = purchaseRepository.save(new Purchase(member)); - ticketRepository.save(new Ticket(1000, 1, 1, ticketing)); - ticketRepository.save(new Ticket(1000, 1, 1, ticketing)); - ticketRepository.save(new Ticket(1000, 1, 1, ticketing)); + ticketRepository.save(new Ticket(1000, 1, 1, "title 1", ticketing)); + ticketRepository.save(new Ticket(1000, 1, 1, "title 1", ticketing)); + ticketRepository.save(new Ticket(1000, 1, 1, "title 1", ticketing)); //when var memberTicketingSale = getMemberTicketingSalesUseCase.getMemberTicketingSales( diff --git a/src/test/java/com/tiketeer/Tiketeer/domain/member/usecase/GetMemberPurchasesUseCaseTest.java b/src/test/java/com/tiketeer/Tiketeer/domain/member/usecase/GetMemberPurchasesUseCaseTest.java index 570541b3..55c5a655 100644 --- a/src/test/java/com/tiketeer/Tiketeer/domain/member/usecase/GetMemberPurchasesUseCaseTest.java +++ b/src/test/java/com/tiketeer/Tiketeer/domain/member/usecase/GetMemberPurchasesUseCaseTest.java @@ -84,10 +84,10 @@ void getMemberPurchases() { ); var purchase1 = purchaseRepository.save(new Purchase(member)); var purchase2 = purchaseRepository.save(new Purchase(member)); - ticketRepository.save(new Ticket(1000, 1, 1, ticketing1)); - ticketRepository.save(new Ticket(1000, 1, 1, ticketing1)); - ticketRepository.save(new Ticket(1000, 1, 1, ticketing1)); - ticketRepository.save(new Ticket(1000, 1, 1, ticketing2)); + ticketRepository.save(new Ticket(1000, 1, 1, "title 1", ticketing1)); + ticketRepository.save(new Ticket(1000, 1, 1, "title 1", ticketing1)); + ticketRepository.save(new Ticket(1000, 1, 1, "title 1", ticketing1)); + ticketRepository.save(new Ticket(1000, 1, 1, "title 1", ticketing2)); // when var results = getMemberPurchasesUseCase.getMemberPurchases( diff --git a/src/test/java/com/tiketeer/Tiketeer/domain/purchase/repository/PurchaseRepositoryTest.java b/src/test/java/com/tiketeer/Tiketeer/domain/purchase/repository/PurchaseRepositoryTest.java index 8f466e42..c7046f85 100644 --- a/src/test/java/com/tiketeer/Tiketeer/domain/purchase/repository/PurchaseRepositoryTest.java +++ b/src/test/java/com/tiketeer/Tiketeer/domain/purchase/repository/PurchaseRepositoryTest.java @@ -74,10 +74,10 @@ void findWithTicketingByMember() { ); var purchase1 = purchaseRepository.save(new Purchase(member)); var purchase2 = purchaseRepository.save(new Purchase(member)); - ticketRepository.save(new Ticket(1000, 1, 1, ticketing1)); - ticketRepository.save(new Ticket(1000, 1, 1, ticketing1)); - ticketRepository.save(new Ticket(1000, 1, 1, ticketing1)); - ticketRepository.save(new Ticket(1000, 1, 1, ticketing2)); + ticketRepository.save(new Ticket(1000, 1, 1, "title 1", ticketing1)); + ticketRepository.save(new Ticket(1000, 1, 1, "title 2", ticketing1)); + ticketRepository.save(new Ticket(1000, 1, 1, "title 3", ticketing1)); + ticketRepository.save(new Ticket(1000, 1, 1, "title 4", ticketing2)); // when var results = purchaseRepository.findWithTicketingByMember(member); diff --git a/src/test/java/com/tiketeer/Tiketeer/domain/ticketing/controller/TicketingControllerTest.java b/src/test/java/com/tiketeer/Tiketeer/domain/ticketing/controller/TicketingControllerTest.java index 2ead3a2d..5ada3655 100644 --- a/src/test/java/com/tiketeer/Tiketeer/domain/ticketing/controller/TicketingControllerTest.java +++ b/src/test/java/com/tiketeer/Tiketeer/domain/ticketing/controller/TicketingControllerTest.java @@ -162,8 +162,8 @@ void getTicketingSuccess() throws Exception { result.get().andReturn().getResponse().getContentAsString(), GetTicketingResponseDto.class); var ticketing = apiResponse.getData(); Assertions.assertThat(ticketing.getTitle()).isEqualTo("0"); - Assertions.assertThat(ticketing.getStock()).isEqualTo(stock); - Assertions.assertThat(ticketing.getRemainStock()).isEqualTo(stock); + // Assertions.assertThat(ticketing.getStock()).isEqualTo(stock); + // Assertions.assertThat(ticketing.getRemainStock()).isEqualTo(stock); Assertions.assertThat(ticketing.getOwner()).isEqualTo(member.getEmail()); } diff --git a/src/test/java/com/tiketeer/Tiketeer/domain/ticketing/repository/TicketingRepositoryTest.java b/src/test/java/com/tiketeer/Tiketeer/domain/ticketing/repository/TicketingRepositoryTest.java index c5188605..99c150bb 100644 --- a/src/test/java/com/tiketeer/Tiketeer/domain/ticketing/repository/TicketingRepositoryTest.java +++ b/src/test/java/com/tiketeer/Tiketeer/domain/ticketing/repository/TicketingRepositoryTest.java @@ -19,6 +19,7 @@ import com.tiketeer.Tiketeer.domain.ticket.Ticket; import com.tiketeer.Tiketeer.domain.ticket.repository.TicketRepository; import com.tiketeer.Tiketeer.domain.ticketing.Ticketing; +import com.tiketeer.Tiketeer.domain.ticketing.usecase.dto.GetTicketing; import com.tiketeer.Tiketeer.testhelper.TestHelper; @Import({TestHelper.class}) @@ -64,9 +65,9 @@ void findTicketingWithTicketStock() { .build() ); var purchase = purchaseRepository.save(new Purchase(member)); - ticketRepository.save(new Ticket(1000, 1, 1, ticketing)); - ticketRepository.save(new Ticket(1000, 1, 1, ticketing)); - ticketRepository.save(new Ticket(1000, 1, 1, ticketing)); + ticketRepository.save(new Ticket(1000, 1, 1, "title 1", ticketing)); + ticketRepository.save(new Ticket(2000, 2, 2, "title 2", ticketing)); + ticketRepository.save(new Ticket(3000, 3, 3, "title 3", ticketing)); //when var memberTicketingSale = ticketingRepository.findTicketingWithTicketStock(member.getEmail()).getFirst(); @@ -78,8 +79,9 @@ void findTicketingWithTicketStock() { assertThat(memberTicketingSale.getSaleStart()).isEqualTo(now); assertThat(memberTicketingSale.getSaleEnd()).isEqualTo(now); - assertThat(memberTicketingSale.getRemainStock()).isEqualTo(1); - assertThat(memberTicketingSale.getStock()).isEqualTo(3); + assertThat(memberTicketingSale.getRemainStock()).isEqualTo(6); + assertThat(memberTicketingSale.getStock()).isEqualTo(6); + assertThat(memberTicketingSale.getPrice()).isEqualTo(6000); } @@ -104,7 +106,7 @@ void findAllTicketingsWithRemainStockSuccess() { ); var stock1 = 3; for (int i = 0; i < stock1; i++) { - ticketRepository.save(new Ticket(1000, 1, 1, ticketing1)); + ticketRepository.save(new Ticket(1000 * (i + 1), i + 1, i + 1, "title " + i, ticketing1)); } var ticketing2 = ticketingRepository.save( Ticketing.builder() @@ -121,7 +123,7 @@ void findAllTicketingsWithRemainStockSuccess() { ); var stock2 = 1; for (int i = 0; i < stock2; i++) { - ticketRepository.save(new Ticket(1000, 1, 1, ticketing2)); + ticketRepository.save(new Ticket(1000 * (i + 1), i + 1, i + 1, "title " + i, ticketing2)); } //when @@ -138,16 +140,20 @@ void findAllTicketingsWithRemainStockSuccess() { .findFirst(); assertThat(ticketing1Opt).isPresent(); assertThat(ticketing2Opt).isPresent(); + assertThat(ticketing1Opt.get().getLocation()).isEqualTo("Seoul"); assertThat(ticketing1Opt.get().getRunningMinutes()).isEqualTo(600); assertThat(ticketing1Opt.get().getSaleStart()).isEqualTo(now); assertThat(ticketing1Opt.get().getSaleEnd()).isEqualTo(now); - assertThat(ticketing1Opt.get().getRemainStock()).isEqualTo(stock1); + assertThat(ticketing1Opt.get().getRemainStock()).isEqualTo((stock1 * (stock1 + 1)) / 2); + assertThat(ticketing1Opt.get().getPrice()).isEqualTo(1000); + assertThat(ticketing2Opt.get().getLocation()).isEqualTo("Seoul"); assertThat(ticketing2Opt.get().getRunningMinutes()).isEqualTo(600); assertThat(ticketing2Opt.get().getSaleStart()).isEqualTo(now); assertThat(ticketing2Opt.get().getSaleEnd()).isEqualTo(now); - assertThat(ticketing2Opt.get().getRemainStock()).isEqualTo(stock2); + assertThat(ticketing2Opt.get().getRemainStock()).isEqualTo((stock2 + (stock2 + 1)) / 2); + assertThat(ticketing2Opt.get().getPrice()).isEqualTo(1000); } @Test @@ -171,12 +177,8 @@ void findTicketingWithRemainStock() { ); var purchase = purchaseRepository.save(new Purchase(member)); var stock = 3; - var remainStock = 1; - for (int i = 0; i < stock - remainStock; i++) { - ticketRepository.save(new Ticket(1000, 1, 1, ticketing)); - } - for (int i = 0; i < remainStock; i++) { - ticketRepository.save(new Ticket(1000, 1, 1, ticketing)); + for (int i = 0; i < stock; i++) { + ticketRepository.save(new Ticket(1000 * (i + 1), i + 1, i, "title " + i, ticketing)); } //when @@ -189,7 +191,12 @@ void findTicketingWithRemainStock() { assertThat(result.getDescription()).isEqualTo(""); assertThat(result.getSaleStart()).isEqualTo(now); assertThat(result.getSaleEnd()).isEqualTo(now); - assertThat(result.getRemainStock()).isEqualTo(remainStock); - assertThat(result.getStock()).isEqualTo(stock); + + assertThat(result.getTickets().size()).isEqualTo(stock); + GetTicketing.GetTicketingTickets ticket = result.getTickets().getFirst(); + assertThat(ticket.getTitle()).isEqualTo("title 0"); + + assertThat(ticket.getRemainingStock()).isEqualTo(0); + assertThat(ticket.getStock()).isEqualTo(1); } } \ No newline at end of file diff --git a/src/test/java/com/tiketeer/Tiketeer/domain/ticketing/usecase/GetAllTicketingsUseCaseTest.java b/src/test/java/com/tiketeer/Tiketeer/domain/ticketing/usecase/GetAllTicketingsUseCaseTest.java index bd1d557c..f1921938 100644 --- a/src/test/java/com/tiketeer/Tiketeer/domain/ticketing/usecase/GetAllTicketingsUseCaseTest.java +++ b/src/test/java/com/tiketeer/Tiketeer/domain/ticketing/usecase/GetAllTicketingsUseCaseTest.java @@ -91,7 +91,7 @@ private List createTicketings(Member member, int count) { .build() ).toList(); ticketings.forEach(ticketing -> { - ticketRepository.save(new Ticket(1000, 1, 1, ticketing)); + ticketRepository.save(new Ticket(1000, 1, 1, "title 1", ticketing)); }); return ticketingRepository.saveAll(ticketings); } diff --git a/src/test/java/com/tiketeer/Tiketeer/domain/ticketing/usecase/GetTicketingUseCaseTest.java b/src/test/java/com/tiketeer/Tiketeer/domain/ticketing/usecase/GetTicketingUseCaseTest.java index 76ce358e..cc36ece3 100644 --- a/src/test/java/com/tiketeer/Tiketeer/domain/ticketing/usecase/GetTicketingUseCaseTest.java +++ b/src/test/java/com/tiketeer/Tiketeer/domain/ticketing/usecase/GetTicketingUseCaseTest.java @@ -74,8 +74,8 @@ void getTicketingSuccess() { // then Assertions.assertThat(result.getTitle()).isEqualTo("0"); - Assertions.assertThat(result.getStock()).isEqualTo(stock); - Assertions.assertThat(result.getRemainStock()).isEqualTo(stock - purchasedStock); + // Assertions.assertThat(result.getStock()).isEqualTo(stock); + // Assertions.assertThat(result.getRemainStock()).isEqualTo(stock - purchasedStock); Assertions.assertThat(result.getOwner()).isEqualTo(member.getEmail()); } From cc5d1c70477d96f97f8ef1b11f66c6044cc92384 Mon Sep 17 00:00:00 2001 From: dla0510 Date: Tue, 11 Jun 2024 19:10:42 +0900 Subject: [PATCH 5/8] =?UTF-8?q?=ED=85=8C=EC=8A=A4=ED=8A=B8=20=EC=BD=94?= =?UTF-8?q?=EB=93=9C=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../repository/PurchaseRepositoryTest.java | 88 ++++++++----------- 1 file changed, 38 insertions(+), 50 deletions(-) diff --git a/src/test/java/com/tiketeer/Tiketeer/domain/purchase/repository/PurchaseRepositoryTest.java b/src/test/java/com/tiketeer/Tiketeer/domain/purchase/repository/PurchaseRepositoryTest.java index dec32909..ab8f903c 100644 --- a/src/test/java/com/tiketeer/Tiketeer/domain/purchase/repository/PurchaseRepositoryTest.java +++ b/src/test/java/com/tiketeer/Tiketeer/domain/purchase/repository/PurchaseRepositoryTest.java @@ -1,8 +1,7 @@ package com.tiketeer.Tiketeer.domain.purchase.repository; -import java.lang.reflect.Method; import java.time.LocalDateTime; -import java.util.Arrays; +import java.util.function.Function; import org.assertj.core.api.Assertions; import org.junit.jupiter.api.DisplayName; @@ -13,6 +12,7 @@ import com.tiketeer.Tiketeer.domain.member.Member; import com.tiketeer.Tiketeer.domain.member.repository.MemberRepository; +import com.tiketeer.Tiketeer.domain.member.usecase.dto.GetMemberPurchase; import com.tiketeer.Tiketeer.domain.purchase.Purchase; import com.tiketeer.Tiketeer.domain.purchase.PurchaseItem; import com.tiketeer.Tiketeer.domain.role.Role; @@ -101,68 +101,56 @@ void findWithTicketingByMember() throws Throwable { Assertions.assertThat(results.get(0).getPurchaseId()).isEqualTo(purchase1.getId()); Assertions.assertThat(results.get(1).getPurchaseId()).isEqualTo(purchase2.getId()); - var purchasePropertyNames = Arrays.asList("ticketingId", "title", "location", "eventTime", - "createdAt", "category", "runningMinutes"); for (int i = 0; i < 2; i++) { var purchase = results.get(i); var ticketing = i == 0 ? ticketing1 : ticketing2; - for (var p : purchasePropertyNames) { - var comparablePropertyName = p.equals("ticketingId") ? "id" : p; - checkObjectProperty(purchase, p, ticketing, comparablePropertyName); - } + checkProperty(purchase, GetMemberPurchase::getTicketingId, ticketing.getId()); + checkProperty(purchase, GetMemberPurchase::getTitle, ticketing.getTitle()); + checkProperty(purchase, GetMemberPurchase::getLocation, ticketing.getLocation()); + checkProperty(purchase, GetMemberPurchase::getEventTime, ticketing.getEventTime()); + checkProperty(purchase, GetMemberPurchase::getCreatedAt, ticketing.getCreatedAt()); + checkProperty(purchase, GetMemberPurchase::getCategory, ticketing.getCategory()); + checkProperty(purchase, GetMemberPurchase::getRunningMinutes, ticketing.getRunningMinutes()); } - Assertions.assertThat(results.get(0).getPurchaseItems().size()).isEqualTo(2); - if (results.get(0).getPurchaseItems().getFirst().getPurchaseItemId().compareTo(purchaseItem1.getId()) == 0) { - Assertions.assertThat(results.getFirst().getPurchaseItems().get(1).getPurchaseItemId()) - .isEqualTo(purchaseItem2.getId()); - } else { - Assertions.assertThat(results.getFirst().getPurchaseItems().get(0).getPurchaseItemId()) - .isEqualTo(purchaseItem2.getId()); - Assertions.assertThat(results.getFirst().getPurchaseItems().get(1).getPurchaseItemId()) - .isEqualTo(purchaseItem1.getId()); - } - Assertions.assertThat(results.get(1).getPurchaseItems().getFirst().getPurchaseItemId()) - .isEqualTo(purchaseItem3.getId()); + Assertions.assertThat(results.get(0).getPurchaseItems()) + .extracting("purchaseItemId") + .containsExactlyInAnyOrder(purchaseItem1.getId(), purchaseItem2.getId()); + Assertions.assertThat(results.get(1).getPurchaseItems()) + .extracting("purchaseItemId") + .containsExactly(purchaseItem3.getId()); - var purchaseItemPropertyNames = Arrays.asList("ticketId", "title", "description", "price"); for (int i = 0; i < 2; i++) { var purchase = results.get(i); var ticket = i == 0 ? ticket1 : ticket2; - for (var p : purchaseItemPropertyNames) { - var comparablePropertyName = p.equals("ticketId") ? "id" : p; - checkObjectProperty(purchase.getPurchaseItems().getFirst(), p, ticket, comparablePropertyName); - if (i == 0) { - checkObjectProperty(purchase.getPurchaseItems().get(1), p, ticket, comparablePropertyName); - } + checkProperty(purchase.getPurchaseItems().getFirst(), + GetMemberPurchase.GetMemberPurchaseItems::getTicketId, ticket.getId()); + checkProperty(purchase.getPurchaseItems().getFirst(), + GetMemberPurchase.GetMemberPurchaseItems::getTitle, ticket.getTitle()); + checkProperty(purchase.getPurchaseItems().getFirst(), + GetMemberPurchase.GetMemberPurchaseItems::getDescription, ticket.getDescription()); + checkProperty(purchase.getPurchaseItems().getFirst(), + GetMemberPurchase.GetMemberPurchaseItems::getPrice, ticket.getPrice()); + if (i == 0) { + checkProperty(purchase.getPurchaseItems().get(1), + GetMemberPurchase.GetMemberPurchaseItems::getTicketId, ticket.getId()); + checkProperty(purchase.getPurchaseItems().get(1), + GetMemberPurchase.GetMemberPurchaseItems::getTitle, ticket.getTitle()); + checkProperty(purchase.getPurchaseItems().get(1), + GetMemberPurchase.GetMemberPurchaseItems::getDescription, ticket.getDescription()); + checkProperty(purchase.getPurchaseItems().get(1), + GetMemberPurchase.GetMemberPurchaseItems::getPrice, ticket.getPrice()); } } } - private void checkObjectProperty(Object object, String propertyName, Object comparableObj, - String comparablePropertyName) throws Throwable { - if (propertyName.isEmpty() || comparablePropertyName.isEmpty()) { - throw new Error("no property name"); - } - var methodName = "get" + propertyName.substring(0, 1).toUpperCase() + propertyName.substring(1); - Method method = object - .getClass() - .getMethod(methodName); - - var methodName2 = propertyName.equals(comparablePropertyName) ? methodName : - "get" + comparablePropertyName.substring(0, 1).toUpperCase() + comparablePropertyName.substring(1); - Method method2 = comparableObj.getClass().getMethod(methodName2); - - // 메소드 호출 - Object property = method.invoke(object); - Object comparableProperty = method2.invoke(comparableObj); - log.debug( - "checkObjectProperty : " + property + "(" + methodName + "), " + comparableProperty + "(" + methodName2 - + ")"); - if (property instanceof LocalDateTime time && comparableProperty instanceof LocalDateTime comparableTime) { - Assertions.assertThat(time).isEqualToIgnoringNanos(comparableTime); + private void checkProperty(T object, Function propertyGetter, R expectedValue) { + if (propertyGetter.apply(object) instanceof LocalDateTime time + && expectedValue instanceof LocalDateTime expectedTime) { + Assertions.assertThat(time).isEqualToIgnoringNanos(expectedTime); } else { - Assertions.assertThat(property).isEqualTo(comparableProperty); + Assertions.assertThat(propertyGetter.apply(object)).isEqualTo(expectedValue); } + } } From e49380ba1ed042e3b2b84ad46a2920830ea61693 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=B0=B0=ED=9D=99=EA=B3=A0=EC=96=91=EC=9D=B4?= Date: Tue, 11 Jun 2024 19:47:24 +0900 Subject: [PATCH 6/8] =?UTF-8?q?TicketingCrudService=20=EB=A7=88=EC=9D=B4?= =?UTF-8?q?=EA=B7=B8=EB=A0=88=EC=9D=B4=EC=85=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Tiketeer/domain/ticket/Ticket.java | 18 ++++++++- .../ticket/service/TicketCrudService.java | 21 +++++++--- .../usecase/dto/CreateTicketCommandDto.java | 13 +++---- .../usecase/dto/CreateTicketMetadata.java | 25 ++++++++++++ .../Tiketeer/domain/ticketing/Ticketing.java | 9 ++++- .../ticketing/service/TicketingService.java | 10 +---- .../service/TicketingStockService.java | 4 +- .../ticket/service/TicketCrudServiceTest.java | 38 ++++++++++--------- 8 files changed, 92 insertions(+), 46 deletions(-) create mode 100644 src/main/java/com/tiketeer/Tiketeer/domain/ticket/usecase/dto/CreateTicketMetadata.java diff --git a/src/main/java/com/tiketeer/Tiketeer/domain/ticket/Ticket.java b/src/main/java/com/tiketeer/Tiketeer/domain/ticket/Ticket.java index a25d9b38..e1d4f29c 100644 --- a/src/main/java/com/tiketeer/Tiketeer/domain/ticket/Ticket.java +++ b/src/main/java/com/tiketeer/Tiketeer/domain/ticket/Ticket.java @@ -73,11 +73,25 @@ public class Ticket { private Integer version; @Builder - public Ticket(long price, int stock, int remainingStock, Ticketing ticketing) { + public Ticket(long price, int stock, int remainingStock, String title, String description, Ticketing ticketing) { this.price = price; this.stock = stock; this.remainingStock = remainingStock; - this.ticketing = ticketing; + this.title = title; + this.description = description; + setTicketing(ticketing); } + public void setTicketing(Ticketing ticketing) { + if (this.ticketing != null) { + this.ticketing.getTickets().remove(this); + } + this.ticketing = ticketing; + + if (ticketing == null) { + return; + } + + this.ticketing.getTickets().add(this); + } } diff --git a/src/main/java/com/tiketeer/Tiketeer/domain/ticket/service/TicketCrudService.java b/src/main/java/com/tiketeer/Tiketeer/domain/ticket/service/TicketCrudService.java index 91100696..221a273a 100644 --- a/src/main/java/com/tiketeer/Tiketeer/domain/ticket/service/TicketCrudService.java +++ b/src/main/java/com/tiketeer/Tiketeer/domain/ticket/service/TicketCrudService.java @@ -1,6 +1,5 @@ package com.tiketeer.Tiketeer.domain.ticket.service; -import java.util.Arrays; import java.util.List; import java.util.UUID; @@ -10,6 +9,7 @@ import com.tiketeer.Tiketeer.domain.ticket.Ticket; import com.tiketeer.Tiketeer.domain.ticket.repository.TicketRepository; +import com.tiketeer.Tiketeer.domain.ticket.usecase.dto.CreateTicketCommandDto; import com.tiketeer.Tiketeer.domain.ticketing.Ticketing; import com.tiketeer.Tiketeer.domain.ticketing.exception.TicketingNotFoundException; import com.tiketeer.Tiketeer.domain.ticketing.repository.TicketingRepository; @@ -32,12 +32,21 @@ public List listTicketByTicketingId(UUID ticketingId) { } @Transactional - public void createTickets(UUID ticketingId, int numOfTickets) { - var ticketing = findTicketingById(ticketingId); - - ticketRepository.saveAll(Arrays.stream(new int[numOfTickets]) - .mapToObj(i -> Ticket.builder().ticketing(ticketing).build()) + public void createTickets(CreateTicketCommandDto dto) { + var ticketing = findTicketingById(dto.getTicketingId()); + + ticketRepository.saveAll(dto.getCreateTicketMetadataList().stream() + .map(meta -> Ticket.builder() + .ticketing(ticketing) + .price(meta.getPrice()) + .stock(meta.getStock()) + .remainingStock(meta.getRemainingStock()) + .title(meta.getTitle()) + .description(meta.getDescription()) + .build() + ) .toList()); + } @Transactional diff --git a/src/main/java/com/tiketeer/Tiketeer/domain/ticket/usecase/dto/CreateTicketCommandDto.java b/src/main/java/com/tiketeer/Tiketeer/domain/ticket/usecase/dto/CreateTicketCommandDto.java index 683479ba..9b5139ff 100644 --- a/src/main/java/com/tiketeer/Tiketeer/domain/ticket/usecase/dto/CreateTicketCommandDto.java +++ b/src/main/java/com/tiketeer/Tiketeer/domain/ticket/usecase/dto/CreateTicketCommandDto.java @@ -1,6 +1,6 @@ package com.tiketeer.Tiketeer.domain.ticket.usecase.dto; -import java.time.LocalDateTime; +import java.util.List; import java.util.UUID; import lombok.Builder; @@ -11,15 +11,12 @@ @ToString public class CreateTicketCommandDto { private final UUID ticketingId; - private final int numOfTickets; - private LocalDateTime commandCreatedAt = LocalDateTime.now(); + + private final List createTicketMetadataList; @Builder - public CreateTicketCommandDto(UUID ticketingId, int numOfTickets, LocalDateTime commandCreatedAt) { + public CreateTicketCommandDto(UUID ticketingId, List createTicketMetadataList) { this.ticketingId = ticketingId; - this.numOfTickets = numOfTickets; - if (commandCreatedAt != null) { - this.commandCreatedAt = commandCreatedAt; - } + this.createTicketMetadataList = createTicketMetadataList; } } diff --git a/src/main/java/com/tiketeer/Tiketeer/domain/ticket/usecase/dto/CreateTicketMetadata.java b/src/main/java/com/tiketeer/Tiketeer/domain/ticket/usecase/dto/CreateTicketMetadata.java new file mode 100644 index 00000000..edc7c9c1 --- /dev/null +++ b/src/main/java/com/tiketeer/Tiketeer/domain/ticket/usecase/dto/CreateTicketMetadata.java @@ -0,0 +1,25 @@ +package com.tiketeer.Tiketeer.domain.ticket.usecase.dto; + +import lombok.Builder; +import lombok.Getter; +import lombok.ToString; + +@Getter +@ToString +public class CreateTicketMetadata { + + private final int stock; + private final int remainingStock; + private final String title; + private final String description; + private final long price; + + @Builder + public CreateTicketMetadata(int stock, int remainingStock, String title, String description, long price) { + this.stock = stock; + this.remainingStock = remainingStock; + this.title = title; + this.description = description; + this.price = price; + } +} diff --git a/src/main/java/com/tiketeer/Tiketeer/domain/ticketing/Ticketing.java b/src/main/java/com/tiketeer/Tiketeer/domain/ticketing/Ticketing.java index c42ce907..22fdc74d 100644 --- a/src/main/java/com/tiketeer/Tiketeer/domain/ticketing/Ticketing.java +++ b/src/main/java/com/tiketeer/Tiketeer/domain/ticketing/Ticketing.java @@ -1,6 +1,8 @@ package com.tiketeer.Tiketeer.domain.ticketing; import java.time.LocalDateTime; +import java.util.ArrayList; +import java.util.List; import java.util.UUID; import org.hibernate.annotations.UuidGenerator; @@ -9,6 +11,7 @@ import com.tiketeer.Tiketeer.constant.StorageEnum; import com.tiketeer.Tiketeer.domain.member.Member; +import com.tiketeer.Tiketeer.domain.ticket.Ticket; import jakarta.persistence.Column; import jakarta.persistence.ConstraintMode; @@ -21,6 +24,7 @@ import jakarta.persistence.Id; import jakarta.persistence.JoinColumn; import jakarta.persistence.ManyToOne; +import jakarta.persistence.OneToMany; import jakarta.persistence.Table; import jakarta.persistence.Temporal; import jakarta.persistence.TemporalType; @@ -29,14 +33,12 @@ import lombok.Getter; import lombok.NoArgsConstructor; import lombok.Setter; -import lombok.ToString; @Entity @NoArgsConstructor(access = AccessLevel.PROTECTED) @Table(name = "ticketings") @EntityListeners(AuditingEntityListener.class) @Getter -@ToString public class Ticketing { @Id @UuidGenerator @@ -98,6 +100,9 @@ public class Ticketing { @Column(name = "created_at", nullable = false) private LocalDateTime createdAt; + @OneToMany(mappedBy = "ticketing") + private List tickets = new ArrayList<>(); + @Builder public Ticketing( Member member, diff --git a/src/main/java/com/tiketeer/Tiketeer/domain/ticketing/service/TicketingService.java b/src/main/java/com/tiketeer/Tiketeer/domain/ticketing/service/TicketingService.java index fc9eddfa..60c778b0 100644 --- a/src/main/java/com/tiketeer/Tiketeer/domain/ticketing/service/TicketingService.java +++ b/src/main/java/com/tiketeer/Tiketeer/domain/ticketing/service/TicketingService.java @@ -8,8 +8,6 @@ import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; -import com.tiketeer.Tiketeer.domain.ticket.repository.TicketRepository; -import com.tiketeer.Tiketeer.domain.ticket.service.TicketCrudService; import com.tiketeer.Tiketeer.domain.ticketing.Ticketing; import com.tiketeer.Tiketeer.domain.ticketing.exception.EventTimeNotValidException; import com.tiketeer.Tiketeer.domain.ticketing.exception.ModifyForNotOwnedTicketingException; @@ -21,15 +19,10 @@ @Transactional(readOnly = true) public class TicketingService { private final TicketingRepository ticketingRepository; - private final TicketCrudService ticketCrudService; - private final TicketRepository ticketRepository; @Autowired - public TicketingService(TicketingRepository ticketingRepository, TicketCrudService ticketCrudService, - TicketRepository ticketRepository) { + public TicketingService(TicketingRepository ticketingRepository) { this.ticketingRepository = ticketingRepository; - this.ticketCrudService = ticketCrudService; - this.ticketRepository = ticketRepository; } public Ticketing findById(UUID ticketingId) { @@ -77,6 +70,5 @@ public void validateTicketingOwnership(Ticketing ticketing, String email) { if (!ticketing.getMember().getEmail().equals(email)) { throw new ModifyForNotOwnedTicketingException(); } - return; } } diff --git a/src/main/java/com/tiketeer/Tiketeer/domain/ticketing/service/TicketingStockService.java b/src/main/java/com/tiketeer/Tiketeer/domain/ticketing/service/TicketingStockService.java index 511e20fd..cae8cd82 100644 --- a/src/main/java/com/tiketeer/Tiketeer/domain/ticketing/service/TicketingStockService.java +++ b/src/main/java/com/tiketeer/Tiketeer/domain/ticketing/service/TicketingStockService.java @@ -8,6 +8,7 @@ import com.tiketeer.Tiketeer.domain.ticket.Ticket; import com.tiketeer.Tiketeer.domain.ticket.service.TicketCrudService; +import com.tiketeer.Tiketeer.domain.ticket.usecase.dto.CreateTicketCommandDto; @Service @Transactional(readOnly = true) @@ -24,7 +25,8 @@ public TicketingStockService(TicketCrudService ticketCrudService, TicketingServi @Transactional public void createStock(UUID ticketingId, int stock) { var ticketing = ticketingService.findById(ticketingId); - ticketCrudService.createTickets(ticketing.getId(), stock); + //TODO 마이그레이션 반영 필요 + ticketCrudService.createTickets(CreateTicketCommandDto.builder().build()); } @Transactional diff --git a/src/test/java/com/tiketeer/Tiketeer/domain/ticket/service/TicketCrudServiceTest.java b/src/test/java/com/tiketeer/Tiketeer/domain/ticket/service/TicketCrudServiceTest.java index a4f31b61..ccc45e99 100644 --- a/src/test/java/com/tiketeer/Tiketeer/domain/ticket/service/TicketCrudServiceTest.java +++ b/src/test/java/com/tiketeer/Tiketeer/domain/ticket/service/TicketCrudServiceTest.java @@ -15,14 +15,11 @@ import org.springframework.transaction.annotation.Transactional; import com.tiketeer.Tiketeer.domain.member.Member; -import com.tiketeer.Tiketeer.domain.member.repository.MemberRepository; -import com.tiketeer.Tiketeer.domain.role.repository.RoleRepository; import com.tiketeer.Tiketeer.domain.ticket.Ticket; import com.tiketeer.Tiketeer.domain.ticket.repository.TicketRepository; import com.tiketeer.Tiketeer.domain.ticketing.Ticketing; import com.tiketeer.Tiketeer.domain.ticketing.exception.TicketingNotFoundException; import com.tiketeer.Tiketeer.domain.ticketing.repository.TicketingRepository; -import com.tiketeer.Tiketeer.domain.ticketing.service.TicketingService; import com.tiketeer.Tiketeer.testhelper.TestHelper; @Import({TestHelper.class}) @@ -34,12 +31,6 @@ public class TicketCrudServiceTest { @Autowired private TicketCrudService ticketCrudService; @Autowired - private TicketingService ticketingService; - @Autowired - private MemberRepository memberRepository; - @Autowired - private RoleRepository roleRepository; - @Autowired private TicketRepository ticketRepository; @Autowired private TicketingRepository ticketingRepository; @@ -79,11 +70,11 @@ void listTicketByTicketingSuccess() { var mockStock = 30; - var ticketingId = createTicketingAndReturnId(member, mockStock, now.plusYears(1), now.plusYears(2), - now.plusYears(3)); + var ticketing = createTicketing(member, now.plusYears(1), now.plusYears(2), now.plusYears(3)); + createTickets(ticketing, mockStock, mockStock, "", "", 1000); // when - var tickets = ticketCrudService.listTicketByTicketingId(ticketingId); + var tickets = ticketCrudService.listTicketByTicketingId(ticketing.getId()); // then Assertions.assertThat(tickets.size()).isEqualTo(mockStock); @@ -112,8 +103,8 @@ void createTicketsSuccess() { var member = testHelper.createMember(mockEmail); var mockStock = 10; - var ticketingId = createTicketingAndReturnId(member, mockStock, now.plusYears(1), now.plusYears(2), - now.plusYears(3)); + var ticketing = createTicketing(member, now.plusYears(1), now.plusYears(2), now.plusYears(3)); + createTickets(ticketing, mockStock, mockStock, "", "", 1000); var addTickets = 20; @@ -125,9 +116,10 @@ void createTicketsSuccess() { Assertions.assertThat(tickets.size()).isEqualTo(mockStock + addTickets); } - private UUID createTicketingAndReturnId(Member member, int stock, LocalDateTime saleStart, LocalDateTime saleEnd, + private Ticketing createTicketing(Member member, LocalDateTime saleStart, + LocalDateTime saleEnd, LocalDateTime eventTime) { - var ticketing = ticketingRepository.save(Ticketing.builder() + return ticketingRepository.save(Ticketing.builder() .member(member) .title("음악회") .location("서울 강남역 8번 출구") @@ -136,9 +128,19 @@ private UUID createTicketingAndReturnId(Member member, int stock, LocalDateTime .saleStart(saleStart) .saleEnd(saleEnd) .eventTime(eventTime).build()); + + } + + private void createTickets(Ticketing ticketing, int stock, int remainingStock, String title, String description, + long price) { ticketRepository.saveAll(Arrays.stream(new int[stock]) - .mapToObj(i -> Ticket.builder().ticketing(ticketing).build()) + .mapToObj(i -> Ticket.builder() + .ticketing(ticketing) + .price(price) + .title(title) + .description(description) + .remainingStock(remainingStock) + .build()) .toList()); - return ticketing.getId(); } } From 90e7601b716549035a7ab5d27c6d784533e10467 Mon Sep 17 00:00:00 2001 From: dla0510 Date: Tue, 11 Jun 2024 19:53:11 +0900 Subject: [PATCH 7/8] =?UTF-8?q?GetMemberPurchase=20EP=20->=20GetMemberAllP?= =?UTF-8?q?urcahses,=20GetMemberPurcahse=20EP=EB=A1=9C=20=EB=B6=84?= =?UTF-8?q?=EB=A6=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../member/controller/MemberController.java | 34 +++-- .../dto/GetMemberAllPurchasesResponseDto.java | 51 +++++++ ...java => GetMemberPurchaseResponseDto.java} | 14 +- ...java => GetMemberAllPurchasesUseCase.java} | 12 +- .../usecase/GetMemberPurchaseUseCase.java | 34 +++++ ...a => GetMemberAllPurchasesCommandDto.java} | 4 +- .../dto/GetMemberAllPurchasesResultDto.java | 78 ++++++++++ .../member/usecase/dto/GetMemberPurchase.java | 3 + .../dto/GetMemberPurchaseCommandDto.java | 20 +++ ...o.java => GetMemberPurchaseResultDto.java} | 11 +- .../controller/MemberControllerTest.java | 79 +++++++++- ... => GetMemberAllPurchasesUseCaseTest.java} | 14 +- .../usecase/GetMemberPurchaseUseCaseTest.java | 143 ++++++++++++++++++ 13 files changed, 457 insertions(+), 40 deletions(-) create mode 100644 src/main/java/com/tiketeer/Tiketeer/domain/member/controller/dto/GetMemberAllPurchasesResponseDto.java rename src/main/java/com/tiketeer/Tiketeer/domain/member/controller/dto/{GetMemberPurchasesResponseDto.java => GetMemberPurchaseResponseDto.java} (73%) rename src/main/java/com/tiketeer/Tiketeer/domain/member/usecase/{GetMemberPurchasesUseCase.java => GetMemberAllPurchasesUseCase.java} (73%) create mode 100644 src/main/java/com/tiketeer/Tiketeer/domain/member/usecase/GetMemberPurchaseUseCase.java rename src/main/java/com/tiketeer/Tiketeer/domain/member/usecase/dto/{GetMemberPurchasesCommandDto.java => GetMemberAllPurchasesCommandDto.java} (67%) create mode 100644 src/main/java/com/tiketeer/Tiketeer/domain/member/usecase/dto/GetMemberAllPurchasesResultDto.java create mode 100644 src/main/java/com/tiketeer/Tiketeer/domain/member/usecase/dto/GetMemberPurchaseCommandDto.java rename src/main/java/com/tiketeer/Tiketeer/domain/member/usecase/dto/{GetMemberPurchasesResultDto.java => GetMemberPurchaseResultDto.java} (84%) rename src/test/java/com/tiketeer/Tiketeer/domain/member/usecase/{GetMemberPurchasesUseCaseTest.java => GetMemberAllPurchasesUseCaseTest.java} (90%) create mode 100644 src/test/java/com/tiketeer/Tiketeer/domain/member/usecase/GetMemberPurchaseUseCaseTest.java diff --git a/src/main/java/com/tiketeer/Tiketeer/domain/member/controller/MemberController.java b/src/main/java/com/tiketeer/Tiketeer/domain/member/controller/MemberController.java index 0aa273c7..e3eedeed 100644 --- a/src/main/java/com/tiketeer/Tiketeer/domain/member/controller/MemberController.java +++ b/src/main/java/com/tiketeer/Tiketeer/domain/member/controller/MemberController.java @@ -18,7 +18,8 @@ import com.tiketeer.Tiketeer.auth.SecurityContextHelper; import com.tiketeer.Tiketeer.domain.member.controller.dto.ChargePointRequestDto; import com.tiketeer.Tiketeer.domain.member.controller.dto.ChargePointResponseDto; -import com.tiketeer.Tiketeer.domain.member.controller.dto.GetMemberPurchasesResponseDto; +import com.tiketeer.Tiketeer.domain.member.controller.dto.GetMemberAllPurchasesResponseDto; +import com.tiketeer.Tiketeer.domain.member.controller.dto.GetMemberPurchaseResponseDto; import com.tiketeer.Tiketeer.domain.member.controller.dto.GetMemberResponseDto; import com.tiketeer.Tiketeer.domain.member.controller.dto.GetMemberTicketingSalesResponseDto; import com.tiketeer.Tiketeer.domain.member.controller.dto.MemberRegisterRequestDto; @@ -26,15 +27,17 @@ import com.tiketeer.Tiketeer.domain.member.controller.dto.ResetPasswordRequestDto; import com.tiketeer.Tiketeer.domain.member.usecase.ChargeMemberPointUseCase; import com.tiketeer.Tiketeer.domain.member.usecase.DeleteMemberUseCase; -import com.tiketeer.Tiketeer.domain.member.usecase.GetMemberPurchasesUseCase; +import com.tiketeer.Tiketeer.domain.member.usecase.GetMemberAllPurchasesUseCase; +import com.tiketeer.Tiketeer.domain.member.usecase.GetMemberPurchaseUseCase; import com.tiketeer.Tiketeer.domain.member.usecase.GetMemberTicketingSalesUseCase; import com.tiketeer.Tiketeer.domain.member.usecase.GetMemberUseCase; import com.tiketeer.Tiketeer.domain.member.usecase.MemberRegisterUseCase; import com.tiketeer.Tiketeer.domain.member.usecase.ResetPasswordUseCase; import com.tiketeer.Tiketeer.domain.member.usecase.SendPasswordChangeEmailUseCase; import com.tiketeer.Tiketeer.domain.member.usecase.dto.DeleteMemberCommandDto; +import com.tiketeer.Tiketeer.domain.member.usecase.dto.GetMemberAllPurchasesCommandDto; import com.tiketeer.Tiketeer.domain.member.usecase.dto.GetMemberCommandDto; -import com.tiketeer.Tiketeer.domain.member.usecase.dto.GetMemberPurchasesCommandDto; +import com.tiketeer.Tiketeer.domain.member.usecase.dto.GetMemberPurchaseCommandDto; import com.tiketeer.Tiketeer.domain.member.usecase.dto.GetMemberTicketingSalesCommandDto; import com.tiketeer.Tiketeer.domain.member.usecase.dto.MemberRegisterCommandDto; import com.tiketeer.Tiketeer.domain.member.usecase.dto.SendPwdChangeEmailCommandDto; @@ -49,7 +52,8 @@ public class MemberController { private final ChargeMemberPointUseCase chargeMemberPointUseCase; private final GetMemberTicketingSalesUseCase getMemberTicketingSalesUseCase; private final GetMemberUseCase getMemberUseCase; - private final GetMemberPurchasesUseCase getMemberPurchasesUseCase; + private final GetMemberAllPurchasesUseCase getMemberAllPurchasesUseCase; + private final GetMemberPurchaseUseCase getMemberPurchasesUseCase; private final ResetPasswordUseCase resetPasswordUseCase; private final SendPasswordChangeEmailUseCase sendPasswordChangeEmailUseCase; private final DeleteMemberUseCase deleteMemberUseCase; @@ -59,7 +63,8 @@ public class MemberController { public MemberController(MemberRegisterUseCase memberRegisterUseCase, ChargeMemberPointUseCase chargeMemberPointUseCase, ResetPasswordUseCase resetPasswordUseCase, GetMemberTicketingSalesUseCase getMemberTicketingSalesUseCase, - GetMemberUseCase getMemberUseCase, GetMemberPurchasesUseCase getMemberPurchasesUseCase, + GetMemberUseCase getMemberUseCase, GetMemberAllPurchasesUseCase getMemberAllPurchasesUseCase, + GetMemberPurchaseUseCase getMemberPurchasesUseCase, SendPasswordChangeEmailUseCase sendPasswordChangeEmailUseCase, DeleteMemberUseCase deleteMemberUseCase, SecurityContextHelper securityContextHelper) { @@ -68,6 +73,7 @@ public MemberController(MemberRegisterUseCase memberRegisterUseCase, this.getMemberTicketingSalesUseCase = getMemberTicketingSalesUseCase; this.getMemberUseCase = getMemberUseCase; this.resetPasswordUseCase = resetPasswordUseCase; + this.getMemberAllPurchasesUseCase = getMemberAllPurchasesUseCase; this.getMemberPurchasesUseCase = getMemberPurchasesUseCase; this.sendPasswordChangeEmailUseCase = sendPasswordChangeEmailUseCase; this.deleteMemberUseCase = deleteMemberUseCase; @@ -105,13 +111,23 @@ public ResponseEntity> chargePoint(@PathVari } @GetMapping("/{memberId}/purchases") - public ResponseEntity>> getMemberPurchases( + public ResponseEntity>> getMemberAllPurchases( @PathVariable UUID memberId) { var email = securityContextHelper.getEmailInToken(); - var results = getMemberPurchasesUseCase.getMemberPurchases( - GetMemberPurchasesCommandDto.builder().memberEmail(email).build()); + var results = getMemberAllPurchasesUseCase.getMemberPurchases( + GetMemberAllPurchasesCommandDto.builder().memberEmail(email).build()); var responseBody = ApiResponse.wrap( - results.stream().map(GetMemberPurchasesResponseDto::convertFromDto).toList()); + results.stream().map(GetMemberAllPurchasesResponseDto::convertFromDto).toList()); + return ResponseEntity.status(HttpStatus.OK).body(responseBody); + } + + @GetMapping("/{memberId}/purchases/{purchaseId}") + public ResponseEntity> getMemberPurchase( + @PathVariable UUID memberId, @PathVariable UUID purchaseId) { + var email = securityContextHelper.getEmailInToken(); + var result = getMemberPurchasesUseCase.getMemberPurchases( + GetMemberPurchaseCommandDto.builder().memberEmail(email).purchaseId(purchaseId).build()); + var responseBody = ApiResponse.wrap(GetMemberPurchaseResponseDto.convertFromDto(result)); return ResponseEntity.status(HttpStatus.OK).body(responseBody); } diff --git a/src/main/java/com/tiketeer/Tiketeer/domain/member/controller/dto/GetMemberAllPurchasesResponseDto.java b/src/main/java/com/tiketeer/Tiketeer/domain/member/controller/dto/GetMemberAllPurchasesResponseDto.java new file mode 100644 index 00000000..c9a9628d --- /dev/null +++ b/src/main/java/com/tiketeer/Tiketeer/domain/member/controller/dto/GetMemberAllPurchasesResponseDto.java @@ -0,0 +1,51 @@ +package com.tiketeer.Tiketeer.domain.member.controller.dto; + +import java.time.LocalDateTime; +import java.util.List; +import java.util.UUID; + +import com.tiketeer.Tiketeer.domain.member.usecase.dto.GetMemberAllPurchasesResultDto; + +import lombok.Builder; +import lombok.Getter; +import lombok.ToString; + +@Getter +@ToString +public final class GetMemberAllPurchasesResponseDto { + private final UUID purchaseId; + private final UUID ticketingId; + private final String title; + private final LocalDateTime eventTime; + private final LocalDateTime createdAt; + private final String category; + private final String thumbnailPath; + private final List purchaseItems; + + @Builder + public GetMemberAllPurchasesResponseDto(UUID purchaseId, UUID ticketingId, String title, + LocalDateTime eventTime, LocalDateTime createdAt, String category, String thumbnailPath, + List purchaseItems) { + this.purchaseId = purchaseId; + this.ticketingId = ticketingId; + this.title = title; + this.eventTime = eventTime; + this.createdAt = createdAt; + this.category = category; + this.thumbnailPath = thumbnailPath; + this.purchaseItems = purchaseItems; + } + + public static GetMemberAllPurchasesResponseDto convertFromDto(GetMemberAllPurchasesResultDto dto) { + return GetMemberAllPurchasesResponseDto.builder() + .purchaseId(dto.getPurchaseId()) + .ticketingId(dto.getTicketingId()) + .title(dto.getTitle()) + .eventTime(dto.getEventTime()) + .createdAt(dto.getCreatedAt()) + .category(dto.getCategory()) + .thumbnailPath(dto.getThumbnailPath()) + .purchaseItems(dto.getPurchaseItems()) + .build(); + } +} diff --git a/src/main/java/com/tiketeer/Tiketeer/domain/member/controller/dto/GetMemberPurchasesResponseDto.java b/src/main/java/com/tiketeer/Tiketeer/domain/member/controller/dto/GetMemberPurchaseResponseDto.java similarity index 73% rename from src/main/java/com/tiketeer/Tiketeer/domain/member/controller/dto/GetMemberPurchasesResponseDto.java rename to src/main/java/com/tiketeer/Tiketeer/domain/member/controller/dto/GetMemberPurchaseResponseDto.java index ab7423ba..31039e75 100644 --- a/src/main/java/com/tiketeer/Tiketeer/domain/member/controller/dto/GetMemberPurchasesResponseDto.java +++ b/src/main/java/com/tiketeer/Tiketeer/domain/member/controller/dto/GetMemberPurchaseResponseDto.java @@ -4,7 +4,7 @@ import java.util.List; import java.util.UUID; -import com.tiketeer.Tiketeer.domain.member.usecase.dto.GetMemberPurchasesResultDto; +import com.tiketeer.Tiketeer.domain.member.usecase.dto.GetMemberPurchaseResultDto; import lombok.Builder; import lombok.Getter; @@ -12,7 +12,7 @@ @Getter @ToString -public final class GetMemberPurchasesResponseDto { +public final class GetMemberPurchaseResponseDto { private final UUID purchaseId; private final UUID ticketingId; private final String title; @@ -21,13 +21,13 @@ public final class GetMemberPurchasesResponseDto { private final LocalDateTime createdAt; private final String category; private final int runningMinute; - private final List purchaseItems; + private final List purchaseItems; @Builder - public GetMemberPurchasesResponseDto(UUID purchaseId, UUID ticketingId, String title, String location, + public GetMemberPurchaseResponseDto(UUID purchaseId, UUID ticketingId, String title, String location, LocalDateTime eventTime, LocalDateTime createdAt, String category, int runningMinute, - List purchaseItems) { + List purchaseItems) { this.purchaseId = purchaseId; this.ticketingId = ticketingId; this.title = title; @@ -39,8 +39,8 @@ public GetMemberPurchasesResponseDto(UUID purchaseId, UUID ticketingId, String t this.purchaseItems = purchaseItems; } - public static GetMemberPurchasesResponseDto convertFromDto(GetMemberPurchasesResultDto dto) { - return GetMemberPurchasesResponseDto.builder() + public static GetMemberPurchaseResponseDto convertFromDto(GetMemberPurchaseResultDto dto) { + return GetMemberPurchaseResponseDto.builder() .purchaseId(dto.getPurchaseId()) .ticketingId(dto.getTicketingId()) .title(dto.getTitle()) diff --git a/src/main/java/com/tiketeer/Tiketeer/domain/member/usecase/GetMemberPurchasesUseCase.java b/src/main/java/com/tiketeer/Tiketeer/domain/member/usecase/GetMemberAllPurchasesUseCase.java similarity index 73% rename from src/main/java/com/tiketeer/Tiketeer/domain/member/usecase/GetMemberPurchasesUseCase.java rename to src/main/java/com/tiketeer/Tiketeer/domain/member/usecase/GetMemberAllPurchasesUseCase.java index baec92e9..6bf33c4a 100644 --- a/src/main/java/com/tiketeer/Tiketeer/domain/member/usecase/GetMemberPurchasesUseCase.java +++ b/src/main/java/com/tiketeer/Tiketeer/domain/member/usecase/GetMemberAllPurchasesUseCase.java @@ -8,25 +8,25 @@ import com.tiketeer.Tiketeer.domain.member.exception.MemberNotFoundException; import com.tiketeer.Tiketeer.domain.member.repository.MemberRepository; -import com.tiketeer.Tiketeer.domain.member.usecase.dto.GetMemberPurchasesCommandDto; -import com.tiketeer.Tiketeer.domain.member.usecase.dto.GetMemberPurchasesResultDto; +import com.tiketeer.Tiketeer.domain.member.usecase.dto.GetMemberAllPurchasesCommandDto; +import com.tiketeer.Tiketeer.domain.member.usecase.dto.GetMemberAllPurchasesResultDto; import com.tiketeer.Tiketeer.domain.purchase.repository.PurchaseRepository; @Service @Transactional(readOnly = true) -public class GetMemberPurchasesUseCase { +public class GetMemberAllPurchasesUseCase { private final MemberRepository memberRepository; private final PurchaseRepository purchaseRepository; @Autowired - public GetMemberPurchasesUseCase(MemberRepository memberRepository, PurchaseRepository purchaseRepository) { + public GetMemberAllPurchasesUseCase(MemberRepository memberRepository, PurchaseRepository purchaseRepository) { this.memberRepository = memberRepository; this.purchaseRepository = purchaseRepository; } - public List getMemberPurchases(GetMemberPurchasesCommandDto command) { + public List getMemberPurchases(GetMemberAllPurchasesCommandDto command) { var member = memberRepository.findByEmail(command.getMemberEmail()).orElseThrow(MemberNotFoundException::new); var results = purchaseRepository.findWithTicketingByMember(member); - return results.stream().map(GetMemberPurchasesResultDto::new).toList(); + return results.stream().map(GetMemberAllPurchasesResultDto::new).toList(); } } diff --git a/src/main/java/com/tiketeer/Tiketeer/domain/member/usecase/GetMemberPurchaseUseCase.java b/src/main/java/com/tiketeer/Tiketeer/domain/member/usecase/GetMemberPurchaseUseCase.java new file mode 100644 index 00000000..26585f48 --- /dev/null +++ b/src/main/java/com/tiketeer/Tiketeer/domain/member/usecase/GetMemberPurchaseUseCase.java @@ -0,0 +1,34 @@ +package com.tiketeer.Tiketeer.domain.member.usecase; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +import com.tiketeer.Tiketeer.domain.member.exception.MemberNotFoundException; +import com.tiketeer.Tiketeer.domain.member.repository.MemberRepository; +import com.tiketeer.Tiketeer.domain.member.usecase.dto.GetMemberPurchaseCommandDto; +import com.tiketeer.Tiketeer.domain.member.usecase.dto.GetMemberPurchaseResultDto; +import com.tiketeer.Tiketeer.domain.purchase.exception.PurchaseNotFoundException; +import com.tiketeer.Tiketeer.domain.purchase.repository.PurchaseRepository; + +@Service +@Transactional(readOnly = true) +public class GetMemberPurchaseUseCase { + private final MemberRepository memberRepository; + private final PurchaseRepository purchaseRepository; + + @Autowired + public GetMemberPurchaseUseCase(MemberRepository memberRepository, PurchaseRepository purchaseRepository) { + this.memberRepository = memberRepository; + this.purchaseRepository = purchaseRepository; + } + + public GetMemberPurchaseResultDto getMemberPurchases(GetMemberPurchaseCommandDto command) { + var member = memberRepository.findByEmail(command.getMemberEmail()).orElseThrow(MemberNotFoundException::new); + var results = purchaseRepository.findWithTicketingByMember(member); + if (results.isEmpty()) { + throw new PurchaseNotFoundException(); + } + return new GetMemberPurchaseResultDto(results.getFirst()); + } +} diff --git a/src/main/java/com/tiketeer/Tiketeer/domain/member/usecase/dto/GetMemberPurchasesCommandDto.java b/src/main/java/com/tiketeer/Tiketeer/domain/member/usecase/dto/GetMemberAllPurchasesCommandDto.java similarity index 67% rename from src/main/java/com/tiketeer/Tiketeer/domain/member/usecase/dto/GetMemberPurchasesCommandDto.java rename to src/main/java/com/tiketeer/Tiketeer/domain/member/usecase/dto/GetMemberAllPurchasesCommandDto.java index 6fd2d0d2..649822f8 100644 --- a/src/main/java/com/tiketeer/Tiketeer/domain/member/usecase/dto/GetMemberPurchasesCommandDto.java +++ b/src/main/java/com/tiketeer/Tiketeer/domain/member/usecase/dto/GetMemberAllPurchasesCommandDto.java @@ -6,11 +6,11 @@ @Getter @ToString -public class GetMemberPurchasesCommandDto { +public class GetMemberAllPurchasesCommandDto { private final String memberEmail; @Builder - public GetMemberPurchasesCommandDto(String memberEmail) { + public GetMemberAllPurchasesCommandDto(String memberEmail) { this.memberEmail = memberEmail; } } diff --git a/src/main/java/com/tiketeer/Tiketeer/domain/member/usecase/dto/GetMemberAllPurchasesResultDto.java b/src/main/java/com/tiketeer/Tiketeer/domain/member/usecase/dto/GetMemberAllPurchasesResultDto.java new file mode 100644 index 00000000..ab4bb10b --- /dev/null +++ b/src/main/java/com/tiketeer/Tiketeer/domain/member/usecase/dto/GetMemberAllPurchasesResultDto.java @@ -0,0 +1,78 @@ +package com.tiketeer.Tiketeer.domain.member.usecase.dto; + +import java.time.LocalDateTime; +import java.util.List; +import java.util.UUID; + +import lombok.Builder; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.ToString; + +@Getter +@ToString +public final class GetMemberAllPurchasesResultDto { + private final UUID purchaseId; + private final UUID ticketingId; + private final String title; + private final LocalDateTime eventTime; + private final LocalDateTime createdAt; + private final String category; + private final String thumbnailPath; + private final List purchaseItems; + + @Builder + public GetMemberAllPurchasesResultDto(UUID purchaseId, UUID ticketingId, String title, String location, + LocalDateTime eventTime, LocalDateTime createdAt, String category, + String thumbnailPath, List purchaseItems) { + this.purchaseId = purchaseId; + this.ticketingId = ticketingId; + this.title = title; + this.eventTime = eventTime; + this.createdAt = createdAt; + this.category = category; + this.thumbnailPath = thumbnailPath; + this.purchaseItems = purchaseItems; + } + + @Builder + public GetMemberAllPurchasesResultDto(GetMemberPurchase purchase) { + this.purchaseId = purchase.getPurchaseId(); + this.ticketingId = purchase.getTicketingId(); + this.title = purchase.getTitle(); + this.eventTime = purchase.getEventTime(); + this.category = purchase.getCategory(); + this.createdAt = purchase.getCreatedAt(); + this.thumbnailPath = purchase.getThumbnailPath(); + this.purchaseItems = purchase.getPurchaseItems().stream().map(PurchaseItem::new).toList(); + + } + + @Getter + @ToString + @NoArgsConstructor(force = true) + public static class PurchaseItem { + private final UUID purchaseItemId; + private final UUID ticketId; + private final String title; + private final Long price; + + @Builder + public PurchaseItem(UUID purchaseItemId, UUID ticketId, String title, Long price) { + this.purchaseItemId = purchaseItemId; + this.ticketId = ticketId; + this.title = title; + this.price = price; + } + + @Builder + public PurchaseItem(GetMemberPurchase.GetMemberPurchaseItems pi) { + this.purchaseItemId = pi.getPurchaseItemId(); + this.ticketId = pi.getTicketId(); + this.title = pi.getTitle(); + this.price = pi.getPrice(); + } + } + +} + diff --git a/src/main/java/com/tiketeer/Tiketeer/domain/member/usecase/dto/GetMemberPurchase.java b/src/main/java/com/tiketeer/Tiketeer/domain/member/usecase/dto/GetMemberPurchase.java index 5810ce5e..dc528632 100644 --- a/src/main/java/com/tiketeer/Tiketeer/domain/member/usecase/dto/GetMemberPurchase.java +++ b/src/main/java/com/tiketeer/Tiketeer/domain/member/usecase/dto/GetMemberPurchase.java @@ -31,6 +31,9 @@ public interface GetMemberPurchase { @Value("#{target.purchaseItems[0].ticket.ticketing.runningMinutes}") int getRunningMinutes(); + @Value("#{target.purchaseItems[0].ticket.ticketing.thumbnailPath}") + String getThumbnailPath(); + List getPurchaseItems(); interface GetMemberPurchaseItems { diff --git a/src/main/java/com/tiketeer/Tiketeer/domain/member/usecase/dto/GetMemberPurchaseCommandDto.java b/src/main/java/com/tiketeer/Tiketeer/domain/member/usecase/dto/GetMemberPurchaseCommandDto.java new file mode 100644 index 00000000..2fa65ad9 --- /dev/null +++ b/src/main/java/com/tiketeer/Tiketeer/domain/member/usecase/dto/GetMemberPurchaseCommandDto.java @@ -0,0 +1,20 @@ +package com.tiketeer.Tiketeer.domain.member.usecase.dto; + +import java.util.UUID; + +import lombok.Builder; +import lombok.Getter; +import lombok.ToString; + +@Getter +@ToString +public class GetMemberPurchaseCommandDto { + private final String memberEmail; + private final UUID purchaseId; + + @Builder + public GetMemberPurchaseCommandDto(String memberEmail, UUID purchaseId) { + this.memberEmail = memberEmail; + this.purchaseId = purchaseId; + } +} diff --git a/src/main/java/com/tiketeer/Tiketeer/domain/member/usecase/dto/GetMemberPurchasesResultDto.java b/src/main/java/com/tiketeer/Tiketeer/domain/member/usecase/dto/GetMemberPurchaseResultDto.java similarity index 84% rename from src/main/java/com/tiketeer/Tiketeer/domain/member/usecase/dto/GetMemberPurchasesResultDto.java rename to src/main/java/com/tiketeer/Tiketeer/domain/member/usecase/dto/GetMemberPurchaseResultDto.java index 5dac3b9f..5fbad686 100644 --- a/src/main/java/com/tiketeer/Tiketeer/domain/member/usecase/dto/GetMemberPurchasesResultDto.java +++ b/src/main/java/com/tiketeer/Tiketeer/domain/member/usecase/dto/GetMemberPurchaseResultDto.java @@ -11,7 +11,7 @@ @Getter @ToString -public final class GetMemberPurchasesResultDto { +public final class GetMemberPurchaseResultDto { private final UUID purchaseId; private final UUID ticketingId; private final String title; @@ -20,12 +20,13 @@ public final class GetMemberPurchasesResultDto { private final LocalDateTime createdAt; private final String category; private final int runningMinutes; + private final String thumbnailPath; private final List purchaseItems; @Builder - public GetMemberPurchasesResultDto(UUID purchaseId, UUID ticketingId, String title, String location, + public GetMemberPurchaseResultDto(UUID purchaseId, UUID ticketingId, String title, String location, LocalDateTime eventTime, LocalDateTime createdAt, String category, - int runningMinutes, List purchaseItems) { + int runningMinutes, String thumbnailPath, List purchaseItems) { this.purchaseId = purchaseId; this.ticketingId = ticketingId; this.title = title; @@ -34,11 +35,12 @@ public GetMemberPurchasesResultDto(UUID purchaseId, UUID ticketingId, String tit this.createdAt = createdAt; this.category = category; this.runningMinutes = runningMinutes; + this.thumbnailPath = thumbnailPath; this.purchaseItems = purchaseItems; } @Builder - public GetMemberPurchasesResultDto(GetMemberPurchase purchase) { + public GetMemberPurchaseResultDto(GetMemberPurchase purchase) { this.purchaseId = purchase.getPurchaseId(); this.ticketingId = purchase.getTicketingId(); this.title = purchase.getTitle(); @@ -47,6 +49,7 @@ public GetMemberPurchasesResultDto(GetMemberPurchase purchase) { this.category = purchase.getCategory(); this.createdAt = purchase.getCreatedAt(); this.runningMinutes = purchase.getRunningMinutes(); + this.thumbnailPath = purchase.getThumbnailPath(); this.purchaseItems = purchase.getPurchaseItems().stream().map(PurchaseItem::new).toList(); } diff --git a/src/test/java/com/tiketeer/Tiketeer/domain/member/controller/MemberControllerTest.java b/src/test/java/com/tiketeer/Tiketeer/domain/member/controller/MemberControllerTest.java index b472e935..184a4c88 100644 --- a/src/test/java/com/tiketeer/Tiketeer/domain/member/controller/MemberControllerTest.java +++ b/src/test/java/com/tiketeer/Tiketeer/domain/member/controller/MemberControllerTest.java @@ -30,7 +30,8 @@ import com.tiketeer.Tiketeer.domain.member.Member; import com.tiketeer.Tiketeer.domain.member.Otp; import com.tiketeer.Tiketeer.domain.member.controller.dto.ChargePointRequestDto; -import com.tiketeer.Tiketeer.domain.member.controller.dto.GetMemberPurchasesResponseDto; +import com.tiketeer.Tiketeer.domain.member.controller.dto.GetMemberAllPurchasesResponseDto; +import com.tiketeer.Tiketeer.domain.member.controller.dto.GetMemberPurchaseResponseDto; import com.tiketeer.Tiketeer.domain.member.controller.dto.GetMemberResponseDto; import com.tiketeer.Tiketeer.domain.member.controller.dto.GetMemberTicketingSalesResponseDto; import com.tiketeer.Tiketeer.domain.member.controller.dto.ResetPasswordRequestDto; @@ -332,9 +333,9 @@ void getMemberSuccess() throws Exception { } @Test - @DisplayName("정상 조건 > 멤버 구매 내역 조회 요청 > 성공") + @DisplayName("정상 조건 > 멤버 구매 내역 리스트 조회 요청 > 성공") @Transactional - void getMemberPurchasesSuccess() throws Exception { + void getMemberAllPurchasesSuccess() throws Exception { // given var now = LocalDateTime.of(2024, 1, 1, 1, 1, 1); String token = testHelper.registerAndLoginAndReturnAccessToken("user@example.com", RoleEnum.SELLER); @@ -388,8 +389,8 @@ void getMemberPurchasesSuccess() throws Exception { //then .andExpect(status().isOk()); - ApiResponse> apiResponse = testHelper.getDeserializedListApiResponse( - result.andReturn().getResponse().getContentAsString(), GetMemberPurchasesResponseDto.class); + ApiResponse> apiResponse = testHelper.getDeserializedListApiResponse( + result.andReturn().getResponse().getContentAsString(), GetMemberAllPurchasesResponseDto.class); var purchases = apiResponse.getData(); var findPurchase1 = purchases.stream() @@ -408,6 +409,74 @@ void getMemberPurchasesSuccess() throws Exception { Assertions.assertThat(findPurchase2.getFirst().getPurchaseItems().size()).isEqualTo(1); } + @Test + @DisplayName("정상 조건 > 멤버 구매 내역 단건 조회 요청 > 성공") + @Transactional + void getMemberPurchaseSuccess() throws Exception { + // given + var now = LocalDateTime.of(2024, 1, 1, 1, 1, 1); + String token = testHelper.registerAndLoginAndReturnAccessToken("user@example.com", RoleEnum.SELLER); + Member member = memberRepository.findAll().getFirst(); + Cookie cookie = new Cookie(JwtMetadata.ACCESS_TOKEN, token); + + var ticketing1 = ticketingRepository.save( + Ticketing.builder() + .member(member) + .description("") + .title("test1") + .location("Seoul") + .eventTime(now) + .category("") + .runningMinutes(600) + .saleStart(now) + .saleEnd(now) + .build() + ); + var ticketing2 = ticketingRepository.save( + Ticketing.builder() + .member(member) + .description("") + .title("test2") + .location("Seoul") + .eventTime(now) + .category("") + .runningMinutes(600) + .saleStart(now) + .saleEnd(now) + .build() + ); + var purchase1 = purchaseRepository.save(new Purchase(member)); + var purchase2 = purchaseRepository.save(new Purchase(member)); + var ticket1 = ticketRepository.save(new Ticket(1000, 1, 1, "ticket1", "", ticketing1)); + var ticket2 = ticketRepository.save(new Ticket(1000, 1, 1, "ticket2", "", ticketing1)); + var ticket3 = ticketRepository.save(new Ticket(1000, 2, 2, "ticket3", "", ticketing2)); + + purchaseItemRepository.save(new PurchaseItem(purchase1, ticket1)); + purchaseItemRepository.save(new PurchaseItem(purchase1, ticket2)); + purchaseItemRepository.save(new PurchaseItem(purchase2, ticket3)); + + // when + var result = mockMvc.perform( + get("/api/members/{memberId}/purchases/{purchaseId}", member.getId(), purchase1.getId()) + .contextPath("/api") + .with(csrf()) + .contentType(MediaType.APPLICATION_JSON) + .characterEncoding("utf-8") + .cookie(cookie) + ) + //then + .andExpect(status().isOk()); + + ApiResponse apiResponse = testHelper.getDeserializedApiResponse( + result.andReturn().getResponse().getContentAsString(), GetMemberPurchaseResponseDto.class); + + var purchase = apiResponse.getData(); + Assertions.assertThat(purchase.getPurchaseId()).isEqualTo(purchase1.getId()); + Assertions.assertThat(purchase.getTicketingId()).isEqualTo(ticketing1.getId()); + Assertions.assertThat(purchase.getTitle()).isEqualTo(ticketing1.getTitle()); + Assertions.assertThat(purchase.getPurchaseItems().size()).isEqualTo(2); + } + @Test @DisplayName("존재하지 않는 멤버 > 삭제 요청 > NOT_FOUND") void deleteMemberFailBecauseNotExistMember() throws Exception { diff --git a/src/test/java/com/tiketeer/Tiketeer/domain/member/usecase/GetMemberPurchasesUseCaseTest.java b/src/test/java/com/tiketeer/Tiketeer/domain/member/usecase/GetMemberAllPurchasesUseCaseTest.java similarity index 90% rename from src/test/java/com/tiketeer/Tiketeer/domain/member/usecase/GetMemberPurchasesUseCaseTest.java rename to src/test/java/com/tiketeer/Tiketeer/domain/member/usecase/GetMemberAllPurchasesUseCaseTest.java index 3bdf1e6c..c25ef4c1 100644 --- a/src/test/java/com/tiketeer/Tiketeer/domain/member/usecase/GetMemberPurchasesUseCaseTest.java +++ b/src/test/java/com/tiketeer/Tiketeer/domain/member/usecase/GetMemberAllPurchasesUseCaseTest.java @@ -13,7 +13,7 @@ import org.springframework.transaction.annotation.Transactional; import com.tiketeer.Tiketeer.domain.member.exception.MemberNotFoundException; -import com.tiketeer.Tiketeer.domain.member.usecase.dto.GetMemberPurchasesCommandDto; +import com.tiketeer.Tiketeer.domain.member.usecase.dto.GetMemberAllPurchasesCommandDto; import com.tiketeer.Tiketeer.domain.purchase.Purchase; import com.tiketeer.Tiketeer.domain.purchase.PurchaseItem; import com.tiketeer.Tiketeer.domain.purchase.repository.PurchaseItemRepository; @@ -26,12 +26,12 @@ @Import({TestHelper.class}) @SpringBootTest -public class GetMemberPurchasesUseCaseTest { +public class GetMemberAllPurchasesUseCaseTest { @Autowired private TestHelper testHelper; @Autowired - private GetMemberPurchasesUseCase getMemberPurchasesUseCase; + private GetMemberAllPurchasesUseCase getMemberAllPurchasesUseCase; @Autowired private TicketingRepository ticketingRepository; @@ -99,8 +99,8 @@ void getMemberPurchases() { purchaseItemRepository.save(new PurchaseItem(purchase2, ticket3)); // when - var results = getMemberPurchasesUseCase.getMemberPurchases( - GetMemberPurchasesCommandDto.builder().memberEmail(mockEmail).build()); + var results = getMemberAllPurchasesUseCase.getMemberPurchases( + GetMemberAllPurchasesCommandDto.builder().memberEmail(mockEmail).build()); var findPurchase1 = results.stream() .filter(purchase -> purchase.getPurchaseId().equals(purchase1.getId())) .toList(); @@ -125,11 +125,11 @@ void getMemberPurchasesFailNotFoundMember() { // given var mockEmail = "test@test.com"; - var command = GetMemberPurchasesCommandDto.builder().memberEmail(mockEmail).build(); + var command = GetMemberAllPurchasesCommandDto.builder().memberEmail(mockEmail).build(); Assertions.assertThatThrownBy(() -> { // when - getMemberPurchasesUseCase.getMemberPurchases(command); + getMemberAllPurchasesUseCase.getMemberPurchases(command); // then }).isInstanceOf(MemberNotFoundException.class); } diff --git a/src/test/java/com/tiketeer/Tiketeer/domain/member/usecase/GetMemberPurchaseUseCaseTest.java b/src/test/java/com/tiketeer/Tiketeer/domain/member/usecase/GetMemberPurchaseUseCaseTest.java new file mode 100644 index 00000000..9036c591 --- /dev/null +++ b/src/test/java/com/tiketeer/Tiketeer/domain/member/usecase/GetMemberPurchaseUseCaseTest.java @@ -0,0 +1,143 @@ +package com.tiketeer.Tiketeer.domain.member.usecase; + +import java.time.LocalDateTime; +import java.util.UUID; + +import org.assertj.core.api.Assertions; +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.member.exception.MemberNotFoundException; +import com.tiketeer.Tiketeer.domain.member.usecase.dto.GetMemberPurchaseCommandDto; +import com.tiketeer.Tiketeer.domain.purchase.Purchase; +import com.tiketeer.Tiketeer.domain.purchase.PurchaseItem; +import com.tiketeer.Tiketeer.domain.purchase.repository.PurchaseItemRepository; +import com.tiketeer.Tiketeer.domain.purchase.repository.PurchaseRepository; +import com.tiketeer.Tiketeer.domain.ticket.Ticket; +import com.tiketeer.Tiketeer.domain.ticket.repository.TicketRepository; +import com.tiketeer.Tiketeer.domain.ticketing.Ticketing; +import com.tiketeer.Tiketeer.domain.ticketing.repository.TicketingRepository; +import com.tiketeer.Tiketeer.testhelper.TestHelper; + +@Import({TestHelper.class}) +@SpringBootTest +public class GetMemberPurchaseUseCaseTest { + @Autowired + private TestHelper testHelper; + + @Autowired + private GetMemberPurchaseUseCase getMemberPurchaseUseCase; + + @Autowired + private TicketingRepository ticketingRepository; + @Autowired + private PurchaseRepository purchaseRepository; + @Autowired + private TicketRepository ticketRepository; + + @Autowired + private PurchaseItemRepository purchaseItemRepository; + + @BeforeEach + void initTable() { + testHelper.initDB(); + } + + @AfterEach + void cleanTable() { + testHelper.cleanDB(); + } + + @Test + @DisplayName("정상 조건 > 멤버 구매 내역 조회 요청 > 성공") + @Transactional + void getMemberPurchases() { + // given + var mockEmail = "test@test.com"; + var member = testHelper.createMember(mockEmail); + var now = LocalDateTime.now(); + var ticketing1 = ticketingRepository.save( + Ticketing.builder() + .member(member) + .description("") + .title("test1") + .location("Seoul") + .eventTime(now) + .category("") + .runningMinutes(600) + .saleStart(now) + .saleEnd(now) + .build() + ); + var ticketing2 = ticketingRepository.save( + Ticketing.builder() + .member(member) + .description("") + .title("test2") + .location("Seoul") + .eventTime(now) + .category("") + .runningMinutes(600) + .saleStart(now) + .saleEnd(now) + .build() + ); + var purchase1 = purchaseRepository.save(new Purchase(member)); + var purchase2 = purchaseRepository.save(new Purchase(member)); + var ticket1 = ticketRepository.save(new Ticket(1000, 4, 4, "ticket1", "", ticketing1)); + var ticket2 = ticketRepository.save(new Ticket(1000, 3, 3, "ticket2", "", ticketing2)); + var ticket3 = ticketRepository.save(new Ticket(1000, 3, 3, "ticket3", "", ticketing2)); + + var purchaseItem1 = purchaseItemRepository.save(new PurchaseItem(purchase1, ticket1)); + var purchaseItem2 = purchaseItemRepository.save(new PurchaseItem(purchase1, ticket1)); + purchaseItemRepository.save(new PurchaseItem(purchase2, ticket2)); + purchaseItemRepository.save(new PurchaseItem(purchase2, ticket3)); + + // when + var result = getMemberPurchaseUseCase.getMemberPurchases( + GetMemberPurchaseCommandDto.builder().memberEmail(mockEmail).purchaseId(purchase1.getId()).build()); + + // then + Assertions.assertThat(result.getPurchaseId()).isEqualTo(purchase1.getId()); + Assertions.assertThat(result.getTicketingId()).isEqualTo(ticketing1.getId()); + Assertions.assertThat(result.getTitle()).isEqualTo(ticketing1.getTitle()); + Assertions.assertThat(result.getLocation()).isEqualTo(ticketing1.getLocation()); + Assertions.assertThat(result.getEventTime()).isEqualTo(ticketing1.getEventTime()); + Assertions.assertThat(result.getCreatedAt()).isEqualTo(ticketing1.getCreatedAt()); + Assertions.assertThat(result.getRunningMinutes()).isEqualTo(ticketing1.getRunningMinutes()); + Assertions.assertThat(result.getCategory()).isEqualTo(ticketing1.getCategory()); + Assertions.assertThat(result.getThumbnailPath()).isEqualTo(ticketing1.getThumbnailPath()); + Assertions.assertThat(result.getPurchaseItems()) + .extracting("purchaseItemId") + .containsExactlyInAnyOrder(purchaseItem1.getId(), purchaseItem2.getId()); + Assertions.assertThat(result.getPurchaseItems()) + .extracting("description") + .containsExactlyInAnyOrder(purchaseItem1.getTicket().getDescription(), + purchaseItem2.getTicket().getDescription()); + } + + @Test + @DisplayName("멤버가 존재하지 않음 > 멤버 조회 > 실패") + @Transactional(readOnly = true) + void getMemberPurchasesFailNotFoundMember() { + // given + var mockEmail = "test@test.com"; + + var command = GetMemberPurchaseCommandDto.builder() + .memberEmail(mockEmail) + .purchaseId(UUID.randomUUID()) + .build(); + + Assertions.assertThatThrownBy(() -> { + // when + getMemberPurchaseUseCase.getMemberPurchases(command); + // then + }).isInstanceOf(MemberNotFoundException.class); + } +} From 8c6a462da67ea411809f799b769a76f84c874aa8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=B0=B0=ED=9D=99=EA=B3=A0=EC=96=91=EC=9D=B4?= Date: Tue, 11 Jun 2024 20:12:05 +0900 Subject: [PATCH 8/8] ticket crudservice migration --- .../Tiketeer/domain/ticket/Ticket.java | 7 ---- .../controller/MemberControllerTest.java | 8 ++-- .../service/MemberTicketingServiceTest.java | 6 +-- .../GetMemberPurchasesUseCaseTest.java | 8 ++-- .../repository/PurchaseRepositoryTest.java | 8 ++-- .../ticket/service/TicketCrudServiceTest.java | 41 +++++++++++++++---- .../repository/TicketingRepositoryTest.java | 14 ++++--- .../usecase/GetAllTicketingsUseCaseTest.java | 2 +- 8 files changed, 56 insertions(+), 38 deletions(-) diff --git a/src/main/java/com/tiketeer/Tiketeer/domain/ticket/Ticket.java b/src/main/java/com/tiketeer/Tiketeer/domain/ticket/Ticket.java index 15149c30..e1d4f29c 100644 --- a/src/main/java/com/tiketeer/Tiketeer/domain/ticket/Ticket.java +++ b/src/main/java/com/tiketeer/Tiketeer/domain/ticket/Ticket.java @@ -73,19 +73,12 @@ public class Ticket { private Integer version; @Builder -<<<<<<< HEAD public Ticket(long price, int stock, int remainingStock, String title, String description, Ticketing ticketing) { -======= - public Ticket(long price, int stock, int remainingStock, String title, Ticketing ticketing) { ->>>>>>> 75566d5e58e0182701ef477488ef370d31b8fb50 this.price = price; this.stock = stock; this.remainingStock = remainingStock; this.title = title; -<<<<<<< HEAD this.description = description; -======= ->>>>>>> 75566d5e58e0182701ef477488ef370d31b8fb50 setTicketing(ticketing); } diff --git a/src/test/java/com/tiketeer/Tiketeer/domain/member/controller/MemberControllerTest.java b/src/test/java/com/tiketeer/Tiketeer/domain/member/controller/MemberControllerTest.java index 7a568c50..788f4c7e 100644 --- a/src/test/java/com/tiketeer/Tiketeer/domain/member/controller/MemberControllerTest.java +++ b/src/test/java/com/tiketeer/Tiketeer/domain/member/controller/MemberControllerTest.java @@ -364,10 +364,10 @@ void getMemberPurchasesSuccess() throws Exception { ); var purchase1 = purchaseRepository.save(new Purchase(member)); var purchase2 = purchaseRepository.save(new Purchase(member)); - ticketRepository.save(new Ticket(1000, 1, 1, "title 1", ticketing1)); - ticketRepository.save(new Ticket(1000, 1, 1, "title 1", ticketing1)); - ticketRepository.save(new Ticket(1000, 1, 1, "title 1", ticketing1)); - ticketRepository.save(new Ticket(1000, 1, 1, "title 1", ticketing2)); + ticketRepository.save(new Ticket(1000, 1, 1, "title 1", "description 1", ticketing1)); + ticketRepository.save(new Ticket(1000, 1, 1, "title 1", "description 1", ticketing1)); + ticketRepository.save(new Ticket(1000, 1, 1, "title 1", "description 1", ticketing1)); + ticketRepository.save(new Ticket(1000, 1, 1, "title 1", "description 1", ticketing2)); // when var result = mockMvc.perform(get("/api/members/{memberId}/purchases", member.getId()) diff --git a/src/test/java/com/tiketeer/Tiketeer/domain/member/service/MemberTicketingServiceTest.java b/src/test/java/com/tiketeer/Tiketeer/domain/member/service/MemberTicketingServiceTest.java index 07a31874..462743ab 100644 --- a/src/test/java/com/tiketeer/Tiketeer/domain/member/service/MemberTicketingServiceTest.java +++ b/src/test/java/com/tiketeer/Tiketeer/domain/member/service/MemberTicketingServiceTest.java @@ -69,9 +69,9 @@ void getMemberTicketingSalesSuccess() { .build() ); var purchase = purchaseRepository.save(new Purchase(member)); - ticketRepository.save(new Ticket(1000, 1, 1, "title 1", ticketing)); - ticketRepository.save(new Ticket(1000, 1, 1, "title 1", ticketing)); - ticketRepository.save(new Ticket(1000, 1, 1, "title 1", ticketing)); + ticketRepository.save(new Ticket(1000, 1, 1, "title 1", "description 1", ticketing)); + ticketRepository.save(new Ticket(1000, 1, 1, "title 1", "description 1", ticketing)); + ticketRepository.save(new Ticket(1000, 1, 1, "title 1", "description 1", ticketing)); //when var memberTicketingSale = getMemberTicketingSalesUseCase.getMemberTicketingSales( diff --git a/src/test/java/com/tiketeer/Tiketeer/domain/member/usecase/GetMemberPurchasesUseCaseTest.java b/src/test/java/com/tiketeer/Tiketeer/domain/member/usecase/GetMemberPurchasesUseCaseTest.java index 55c5a655..90263605 100644 --- a/src/test/java/com/tiketeer/Tiketeer/domain/member/usecase/GetMemberPurchasesUseCaseTest.java +++ b/src/test/java/com/tiketeer/Tiketeer/domain/member/usecase/GetMemberPurchasesUseCaseTest.java @@ -84,10 +84,10 @@ void getMemberPurchases() { ); var purchase1 = purchaseRepository.save(new Purchase(member)); var purchase2 = purchaseRepository.save(new Purchase(member)); - ticketRepository.save(new Ticket(1000, 1, 1, "title 1", ticketing1)); - ticketRepository.save(new Ticket(1000, 1, 1, "title 1", ticketing1)); - ticketRepository.save(new Ticket(1000, 1, 1, "title 1", ticketing1)); - ticketRepository.save(new Ticket(1000, 1, 1, "title 1", ticketing2)); + ticketRepository.save(new Ticket(1000, 1, 1, "title 1", "description 1", ticketing1)); + ticketRepository.save(new Ticket(1000, 1, 1, "title 1", "description 1", ticketing1)); + ticketRepository.save(new Ticket(1000, 1, 1, "title 1", "description 1", ticketing1)); + ticketRepository.save(new Ticket(1000, 1, 1, "title 1", "description 1", ticketing2)); // when var results = getMemberPurchasesUseCase.getMemberPurchases( diff --git a/src/test/java/com/tiketeer/Tiketeer/domain/purchase/repository/PurchaseRepositoryTest.java b/src/test/java/com/tiketeer/Tiketeer/domain/purchase/repository/PurchaseRepositoryTest.java index c7046f85..84a0d7f1 100644 --- a/src/test/java/com/tiketeer/Tiketeer/domain/purchase/repository/PurchaseRepositoryTest.java +++ b/src/test/java/com/tiketeer/Tiketeer/domain/purchase/repository/PurchaseRepositoryTest.java @@ -74,10 +74,10 @@ void findWithTicketingByMember() { ); var purchase1 = purchaseRepository.save(new Purchase(member)); var purchase2 = purchaseRepository.save(new Purchase(member)); - ticketRepository.save(new Ticket(1000, 1, 1, "title 1", ticketing1)); - ticketRepository.save(new Ticket(1000, 1, 1, "title 2", ticketing1)); - ticketRepository.save(new Ticket(1000, 1, 1, "title 3", ticketing1)); - ticketRepository.save(new Ticket(1000, 1, 1, "title 4", ticketing2)); + ticketRepository.save(new Ticket(1000, 1, 1, "title 1", "description 1", ticketing1)); + ticketRepository.save(new Ticket(1000, 1, 1, "title 2", "description 1", ticketing1)); + ticketRepository.save(new Ticket(1000, 1, 1, "title 3", "description 1", ticketing1)); + ticketRepository.save(new Ticket(1000, 1, 1, "title 4", "description 1", ticketing2)); // when var results = purchaseRepository.findWithTicketingByMember(member); diff --git a/src/test/java/com/tiketeer/Tiketeer/domain/ticket/service/TicketCrudServiceTest.java b/src/test/java/com/tiketeer/Tiketeer/domain/ticket/service/TicketCrudServiceTest.java index ccc45e99..2be4e80f 100644 --- a/src/test/java/com/tiketeer/Tiketeer/domain/ticket/service/TicketCrudServiceTest.java +++ b/src/test/java/com/tiketeer/Tiketeer/domain/ticket/service/TicketCrudServiceTest.java @@ -1,7 +1,9 @@ package com.tiketeer.Tiketeer.domain.ticket.service; import java.time.LocalDateTime; +import java.util.ArrayList; import java.util.Arrays; +import java.util.Collections; import java.util.UUID; import org.assertj.core.api.Assertions; @@ -17,6 +19,8 @@ import com.tiketeer.Tiketeer.domain.member.Member; import com.tiketeer.Tiketeer.domain.ticket.Ticket; import com.tiketeer.Tiketeer.domain.ticket.repository.TicketRepository; +import com.tiketeer.Tiketeer.domain.ticket.usecase.dto.CreateTicketCommandDto; +import com.tiketeer.Tiketeer.domain.ticket.usecase.dto.CreateTicketMetadata; import com.tiketeer.Tiketeer.domain.ticketing.Ticketing; import com.tiketeer.Tiketeer.domain.ticketing.exception.TicketingNotFoundException; import com.tiketeer.Tiketeer.domain.ticketing.repository.TicketingRepository; @@ -71,7 +75,7 @@ void listTicketByTicketingSuccess() { var mockStock = 30; var ticketing = createTicketing(member, now.plusYears(1), now.plusYears(2), now.plusYears(3)); - createTickets(ticketing, mockStock, mockStock, "", "", 1000); + createTickets(ticketing, 5, mockStock, mockStock, "", "", 1000); // when var tickets = ticketCrudService.listTicketByTicketingId(ticketing.getId()); @@ -88,13 +92,16 @@ void createTicketsFailBecauseNotExistTicketing() { Assertions.assertThatThrownBy(() -> { // when - ticketCrudService.createTickets(invalidTicketingId, 100); + ticketCrudService.createTickets(CreateTicketCommandDto.builder() + .ticketingId(invalidTicketingId) + .createTicketMetadataList(new ArrayList<>()) + .build()); // then }).isInstanceOf(TicketingNotFoundException.class); } @Test - @DisplayName("유효한 티케팅 (기존 티켓 10) > 추가 하위 티켓 생성 요청 (20) > 성공 및 총 재고 10 + 20") + @DisplayName("유효한 티케팅 (티켓 10종류 * 10장) > 추가 하위 티켓 생성 요청 (1종류 20장) > 성공 및 총 재고 10*10 + 20") void createTicketsSuccess() { // given var now = LocalDateTime.now(); @@ -104,16 +111,30 @@ void createTicketsSuccess() { var mockStock = 10; var ticketing = createTicketing(member, now.plusYears(1), now.plusYears(2), now.plusYears(3)); - createTickets(ticketing, mockStock, mockStock, "", "", 1000); + createTickets(ticketing, 10, mockStock, mockStock, "", "", 1000); var addTickets = 20; // when - ticketCrudService.createTickets(ticketingId, addTickets); + ticketCrudService.createTickets(CreateTicketCommandDto.builder() + .ticketingId(ticketing.getId()) + .createTicketMetadataList(Collections.singletonList( + CreateTicketMetadata.builder() + .stock(addTickets) + .remainingStock(addTickets) + .title("") + .description("") + .price(2000) + .build() + )) + .build()); // then - var tickets = ticketCrudService.listTicketByTicketingId(ticketingId); - Assertions.assertThat(tickets.size()).isEqualTo(mockStock + addTickets); + var tickets = ticketCrudService.listTicketByTicketingId(ticketing.getId()); + Assertions.assertThat(tickets.size()).isEqualTo(mockStock + 1); + + var ticketCount = tickets.stream().mapToInt(Ticket::getStock).sum(); + Assertions.assertThat(ticketCount).isEqualTo(120); } private Ticketing createTicketing(Member member, LocalDateTime saleStart, @@ -131,14 +152,16 @@ private Ticketing createTicketing(Member member, LocalDateTime saleStart, } - private void createTickets(Ticketing ticketing, int stock, int remainingStock, String title, String description, + private void createTickets(Ticketing ticketing, int distinct, int stock, int remainingStock, String title, + String description, long price) { - ticketRepository.saveAll(Arrays.stream(new int[stock]) + ticketRepository.saveAll(Arrays.stream(new int[distinct]) .mapToObj(i -> Ticket.builder() .ticketing(ticketing) .price(price) .title(title) .description(description) + .stock(stock) .remainingStock(remainingStock) .build()) .toList()); diff --git a/src/test/java/com/tiketeer/Tiketeer/domain/ticketing/repository/TicketingRepositoryTest.java b/src/test/java/com/tiketeer/Tiketeer/domain/ticketing/repository/TicketingRepositoryTest.java index 99c150bb..5913f3ee 100644 --- a/src/test/java/com/tiketeer/Tiketeer/domain/ticketing/repository/TicketingRepositoryTest.java +++ b/src/test/java/com/tiketeer/Tiketeer/domain/ticketing/repository/TicketingRepositoryTest.java @@ -65,9 +65,9 @@ void findTicketingWithTicketStock() { .build() ); var purchase = purchaseRepository.save(new Purchase(member)); - ticketRepository.save(new Ticket(1000, 1, 1, "title 1", ticketing)); - ticketRepository.save(new Ticket(2000, 2, 2, "title 2", ticketing)); - ticketRepository.save(new Ticket(3000, 3, 3, "title 3", ticketing)); + ticketRepository.save(new Ticket(1000, 1, 1, "title 1", "description 1", ticketing)); + ticketRepository.save(new Ticket(2000, 2, 2, "title 2", "description 1", ticketing)); + ticketRepository.save(new Ticket(3000, 3, 3, "title 3", "description 1", ticketing)); //when var memberTicketingSale = ticketingRepository.findTicketingWithTicketStock(member.getEmail()).getFirst(); @@ -106,7 +106,8 @@ void findAllTicketingsWithRemainStockSuccess() { ); var stock1 = 3; for (int i = 0; i < stock1; i++) { - ticketRepository.save(new Ticket(1000 * (i + 1), i + 1, i + 1, "title " + i, ticketing1)); + ticketRepository.save( + new Ticket(1000 * (i + 1), i + 1, i + 1, "title " + i, "description " + i, ticketing1)); } var ticketing2 = ticketingRepository.save( Ticketing.builder() @@ -123,7 +124,8 @@ void findAllTicketingsWithRemainStockSuccess() { ); var stock2 = 1; for (int i = 0; i < stock2; i++) { - ticketRepository.save(new Ticket(1000 * (i + 1), i + 1, i + 1, "title " + i, ticketing2)); + ticketRepository.save( + new Ticket(1000 * (i + 1), i + 1, i + 1, "title " + i, "description " + i, ticketing2)); } //when @@ -178,7 +180,7 @@ void findTicketingWithRemainStock() { var purchase = purchaseRepository.save(new Purchase(member)); var stock = 3; for (int i = 0; i < stock; i++) { - ticketRepository.save(new Ticket(1000 * (i + 1), i + 1, i, "title " + i, ticketing)); + ticketRepository.save(new Ticket(1000 * (i + 1), i + 1, i, "title " + i, "description " + i, ticketing)); } //when diff --git a/src/test/java/com/tiketeer/Tiketeer/domain/ticketing/usecase/GetAllTicketingsUseCaseTest.java b/src/test/java/com/tiketeer/Tiketeer/domain/ticketing/usecase/GetAllTicketingsUseCaseTest.java index f1921938..0d5fae11 100644 --- a/src/test/java/com/tiketeer/Tiketeer/domain/ticketing/usecase/GetAllTicketingsUseCaseTest.java +++ b/src/test/java/com/tiketeer/Tiketeer/domain/ticketing/usecase/GetAllTicketingsUseCaseTest.java @@ -91,7 +91,7 @@ private List createTicketings(Member member, int count) { .build() ).toList(); ticketings.forEach(ticketing -> { - ticketRepository.save(new Ticket(1000, 1, 1, "title 1", ticketing)); + ticketRepository.save(new Ticket(1000, 1, 1, "title 1", "description 1", ticketing)); }); return ticketingRepository.saveAll(ticketings); }