From 1c3b0e439d64e2fde7adde4effe731584b022a90 Mon Sep 17 00:00:00 2001 From: dla0510 Date: Wed, 29 May 2024 03:56:37 +0900 Subject: [PATCH 1/4] =?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/4] =?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/4] =?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/4] =?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()); }