Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[DEV-298] ticketing repository 마이그레이션 #114

Merged
merged 6 commits into from
Jun 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 23 additions & 1 deletion docker-compose.dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,26 @@ services:
- '--collation-server=utf8mb4_unicode_ci'
environment:
MYSQL_ROOT_PASSWORD: ${DB_PASSWORD}
MYSQL_DATABASE: ${DB_DATABASE}
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

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
12 changes: 0 additions & 12 deletions docker-compose.nginx.yml

This file was deleted.

18 changes: 17 additions & 1 deletion docker-compose.prod.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -27,6 +30,7 @@ services:
- was
networks:
- common-network

mysql:
image: mysql:8.0.33
expose:
Expand All @@ -43,6 +47,7 @@ services:
restart: unless-stopped
networks:
- common-network

redis:
image: redis:6.2-alpine
expose:
Expand All @@ -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
Expand Down
12 changes: 0 additions & 12 deletions docker-compose.redis.yml

This file was deleted.

10 changes: 9 additions & 1 deletion nginx.dev.conf
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
10 changes: 9 additions & 1 deletion nginx.prod.conf
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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;

}
17 changes: 15 additions & 2 deletions src/main/java/com/tiketeer/Tiketeer/domain/ticket/Ticket.java
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

title 뒤에 String description도 하나만 추가해주십셔

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

요거 다니엘이 작업해주실 검다

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);
}
}
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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;
Expand All @@ -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;
Expand All @@ -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
Expand Down Expand Up @@ -98,6 +100,9 @@ public class Ticketing {
@Column(name = "created_at", nullable = false)
private LocalDateTime createdAt;

@OneToMany(mappedBy = "ticketing")
private List<Ticket> tickets = new ArrayList<>();

@Builder
public Ticketing(
Member member,
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -18,44 +19,38 @@ 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<GetTicketingResultDto.TicketingTicket> tickets;

@Builder
public GetTicketingResponseDto(UUID ticketingId, String title,
String description,
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<GetTicketingResultDto.TicketingTicket> 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) {
Expand All @@ -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();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,18 @@
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<Ticketing, UUID> {

@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
Expand All @@ -32,26 +33,21 @@ public interface TicketingRepository extends JpaRepository<Ticketing, UUID> {

@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<GetAllTicketingsResultDto> 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<Ticketing> findAllByMember(Member member);
}
Loading
Loading