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-314] ticketing 생성, 업데이트 EP 마이그레이션 #117

Merged
merged 4 commits into from
Jun 17, 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
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ public class GetMemberTicketingSalesResultDto {
private final LocalDateTime eventTime;
private final LocalDateTime saleStart;
private final LocalDateTime saleEnd;
private final long stock;
private final long remainStock;
private final int stock;
private final int remainStock;
private final LocalDateTime createdAt;
private final String category;
private final int runningMinutes;
Expand All @@ -35,8 +35,8 @@ public GetMemberTicketingSalesResultDto(
LocalDateTime eventTime,
LocalDateTime saleStart,
LocalDateTime saleEnd,
long stock,
long remainStock,
int stock,
int remainStock,
LocalDateTime createdAt,
String category,
int runningMinutes,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,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.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;
Expand Down Expand Up @@ -60,4 +61,14 @@ public void deleteAllByTicketIds(List<UUID> ticketIds) {
private Ticketing findTicketingById(UUID ticketingId) {
return ticketingRepository.findById(ticketingId).orElseThrow(TicketingNotFoundException::new);
}

@Transactional
public void updateTickets(UUID ticketingId, List<CreateTicketMetadata> tickets) {
var ticketing = findTicketingById(ticketingId);

ticketRepository.findAllByTicketing(ticketing)
.forEach(ticketRepository::delete);

createTickets(new CreateTicketCommandDto(ticketingId, tickets));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,6 @@ public class PatchTicketingRequestDto {
@NotNull
private final Integer runningMinutes;

@NotNull
private final Integer stock;

@NotNull
private final Long price;

@NotNull
@JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd'T'HH:mm:ss", timezone = "Asia/Seoul")
private final LocalDateTime eventTime;
Expand All @@ -56,8 +50,6 @@ public PatchTicketingRequestDto(
@NotBlank String location,
@NotBlank String category,
@NotNull Integer runningMinutes,
@NotNull Integer stock,
@NotNull Long price,
@NotNull LocalDateTime eventTime,
@NotNull LocalDateTime saleStart,
@NotNull LocalDateTime saleEnd) {
Expand All @@ -66,8 +58,6 @@ public PatchTicketingRequestDto(
this.location = location;
this.category = category;
this.runningMinutes = runningMinutes;
this.stock = stock;
this.price = price;
this.eventTime = eventTime;
this.saleStart = saleStart;
this.saleEnd = saleEnd;
Expand All @@ -83,8 +73,6 @@ public UpdateTicketingCommandDto convertToDto(String ticketingId, String memberE
.location(location)
.category(category)
.runningMinutes(runningMinutes)
.stock(stock)
.price(price)
.eventTime(eventTime)
.saleStart(saleStart)
.saleEnd(saleEnd)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
package com.tiketeer.Tiketeer.domain.ticketing.controller.dto;

import java.time.LocalDateTime;
import java.util.List;

import org.springframework.web.multipart.MultipartFile;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.tiketeer.Tiketeer.domain.ticket.usecase.dto.CreateTicketMetadata;
import com.tiketeer.Tiketeer.domain.ticketing.usecase.dto.CreateTicketingCommandDto;

import jakarta.validation.constraints.NotBlank;
Expand Down Expand Up @@ -32,14 +34,6 @@ public class PostTicketingRequestDto {
@Positive
private final Integer runningMinutes;

@NotNull
@Positive
private final Integer stock;

@NotNull
@Positive
private final Long price;

@NotNull
@JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd'T'HH:mm:ss", timezone = "Asia/Seoul")
private final LocalDateTime eventTime;
Expand All @@ -59,8 +53,6 @@ public PostTicketingRequestDto(
@NotBlank String location,
@NotBlank String category,
@NotNull Integer runningMinutes,
@NotNull Integer stock,
@NotNull Long price,
@NotNull LocalDateTime eventTime,
@NotNull LocalDateTime saleStart,
@NotNull LocalDateTime saleEnd) {
Expand All @@ -69,8 +61,6 @@ public PostTicketingRequestDto(
this.location = location;
this.category = category;
this.runningMinutes = runningMinutes;
this.stock = stock;
this.price = price;
this.eventTime = eventTime;
this.saleStart = saleStart;
this.saleEnd = saleEnd;
Expand All @@ -85,8 +75,6 @@ public CreateTicketingCommandDto convertToDto(String memberEmail, MultipartFile
.location(location)
.category(category)
.runningMinutes(runningMinutes)
.stock(stock)
.price(price)
.eventTime(eventTime)
.saleStart(saleStart)
.saleEnd(saleEnd)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.tiketeer.Tiketeer.domain.ticketing.service;

import java.util.List;
import java.util.UUID;

import org.springframework.beans.factory.annotation.Autowired;
Expand All @@ -9,6 +10,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;
import com.tiketeer.Tiketeer.domain.ticket.usecase.dto.CreateTicketMetadata;

@Service
@Transactional(readOnly = true)
Expand All @@ -23,23 +25,14 @@ public TicketingStockService(TicketCrudService ticketCrudService, TicketingServi
}

@Transactional
public void createStock(UUID ticketingId, int stock) {
public void createStock(UUID ticketingId, List<CreateTicketMetadata> tickets) {
var ticketing = ticketingService.findById(ticketingId);
//TODO 마이그레이션 반영 필요
ticketCrudService.createTickets(CreateTicketCommandDto.builder().build());
ticketCrudService.createTickets(new CreateTicketCommandDto(ticketing.getId(), tickets));
}

@Transactional
public void updateStock(UUID ticketingId, int newStock) {
var tickets = ticketCrudService.listTicketByTicketingId(ticketingId);

var numOfTickets = tickets.size();
if (numOfTickets > newStock) {
dropNumOfTicketsByTicketing(ticketingId, numOfTickets - newStock);

} else if (numOfTickets < newStock) {
createStock(ticketingId, newStock - numOfTickets);
}
public void updateStock(UUID ticketingId, List<CreateTicketMetadata> tickets) {
ticketCrudService.updateTickets(ticketingId, tickets);
}

@Transactional
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
import com.tiketeer.Tiketeer.domain.member.repository.MemberRepository;
import com.tiketeer.Tiketeer.domain.ticketing.Ticketing;
import com.tiketeer.Tiketeer.domain.ticketing.exception.EventTimeNotValidException;
import com.tiketeer.Tiketeer.domain.ticketing.exception.SaleDurationNotValidException;
import com.tiketeer.Tiketeer.domain.ticketing.service.TicketingService;
import com.tiketeer.Tiketeer.domain.ticketing.service.TicketingStockService;
import com.tiketeer.Tiketeer.domain.ticketing.usecase.dto.CreateTicketingCommandDto;
import com.tiketeer.Tiketeer.domain.ticketing.usecase.dto.CreateTicketingResultDto;
import com.tiketeer.Tiketeer.infra.storage.FileValidator;
Expand All @@ -29,18 +29,16 @@
@Service
public class CreateTicketingUseCase {
private final TicketingService ticketingService;
private final TicketingStockService ticketingStockService;
private final MemberRepository memberRepository;
private final FileStorageStrategy fileStorageStrategy;

@Value("${custom.policy.storage}")
private StorageEnum storageEnum;

@Autowired
public CreateTicketingUseCase(TicketingService ticketingService, TicketingStockService ticketingStockService,
public CreateTicketingUseCase(TicketingService ticketingService,
MemberRepository memberRepository, FileStorageStrategy fileStorageStrategy) {
this.ticketingService = ticketingService;
this.ticketingStockService = ticketingStockService;
this.memberRepository = memberRepository;
this.fileStorageStrategy = fileStorageStrategy;
}
Expand All @@ -56,9 +54,9 @@ public CreateTicketingResultDto createTicketing(CreateTicketingCommandDto comman
throw new EventTimeNotValidException();
}

// if (!isSaleDurationValid(now, saleStart, saleEnd)) {
// throw new SaleDurationNotValidException();
// }
if (!isSaleDurationValid(now, saleStart, saleEnd)) {
throw new SaleDurationNotValidException();
}

var member = memberRepository.findByEmail(command.getMemberEmail())
.orElseThrow(MemberNotFoundException::new);
Expand All @@ -81,8 +79,6 @@ public CreateTicketingResultDto createTicketing(CreateTicketingCommandDto comman
.storageEnum(storageEnum)
.build());

ticketingStockService.createStock(ticketing.getId(), command.getStock());

return CreateTicketingResultDto.builder()
.ticketingId(ticketing.getId())
.createdAt(ticketing.getCreatedAt())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
import com.tiketeer.Tiketeer.domain.ticketing.exception.SaleDurationNotValidException;
import com.tiketeer.Tiketeer.domain.ticketing.exception.UpdateTicketingAfterSaleStartException;
import com.tiketeer.Tiketeer.domain.ticketing.service.TicketingService;
import com.tiketeer.Tiketeer.domain.ticketing.service.TicketingStockService;
import com.tiketeer.Tiketeer.domain.ticketing.usecase.dto.UpdateTicketingCommandDto;
import com.tiketeer.Tiketeer.infra.storage.FileValidator;
import com.tiketeer.Tiketeer.infra.storage.StorageFile;
Expand All @@ -28,17 +27,15 @@
@Service
public class UpdateTicketingUseCase {
private final TicketingService ticketingService;
private final TicketingStockService ticketingStockService;
private final FileStorageStrategy fileStorageStrategy;

@Value("${custom.policy.storage}")
private StorageEnum storageEnum;

@Autowired
public UpdateTicketingUseCase(TicketingService ticketingService, TicketingStockService ticketingStockService,
public UpdateTicketingUseCase(TicketingService ticketingService,
FileStorageStrategy fileStorageStrategy) {
this.ticketingService = ticketingService;
this.ticketingStockService = ticketingStockService;
this.fileStorageStrategy = fileStorageStrategy;
}

Expand Down Expand Up @@ -78,7 +75,6 @@ public void updateTicketing(UpdateTicketingCommandDto command) {
ticketing.setSaleEnd(saleEnd);
ticketing.setCategory(command.getCategory());
ticketing.setRunningMinutes(command.getRunningMinutes());
ticketingStockService.updateStock(ticketing.getId(), command.getStock());
}

private boolean isEventTimeValid(LocalDateTime baseTime, LocalDateTime eventTime) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
package com.tiketeer.Tiketeer.domain.ticketing.usecase.dto;

import java.time.LocalDateTime;
import java.util.List;

import org.springframework.web.multipart.MultipartFile;

import com.tiketeer.Tiketeer.domain.ticket.usecase.dto.CreateTicketMetadata;

import lombok.Builder;
import lombok.Getter;
import lombok.ToString;
Expand All @@ -17,8 +20,6 @@ public class CreateTicketingCommandDto {
private final String location;
private final String category;
private final Integer runningMinutes;
private final Integer stock;
private final Long price;
private final LocalDateTime eventTime;
private final LocalDateTime saleStart;
private final LocalDateTime saleEnd;
Expand All @@ -33,8 +34,6 @@ public CreateTicketingCommandDto(
String location,
String category,
Integer runningMinutes,
Integer stock,
Long price,
MultipartFile thumbnail,
LocalDateTime eventTime,
LocalDateTime saleStart,
Expand All @@ -45,8 +44,6 @@ public CreateTicketingCommandDto(
this.location = location;
this.category = category;
this.runningMinutes = runningMinutes;
this.stock = stock;
this.price = price;
this.eventTime = eventTime;
this.saleStart = saleStart;
this.saleEnd = saleEnd;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
package com.tiketeer.Tiketeer.domain.ticketing.usecase.dto;

import java.time.LocalDateTime;
import java.util.List;
import java.util.UUID;

import org.springframework.web.multipart.MultipartFile;

import com.tiketeer.Tiketeer.domain.ticket.usecase.dto.CreateTicketMetadata;

import lombok.Builder;
import lombok.Getter;
import lombok.ToString;
Expand All @@ -19,8 +22,6 @@ public class UpdateTicketingCommandDto {
private final String location;
private final String category;
private final Integer runningMinutes;
private final Integer stock;
private final Long price;
private final LocalDateTime eventTime;
private final LocalDateTime saleStart;
private final LocalDateTime saleEnd;
Expand All @@ -36,8 +37,6 @@ public UpdateTicketingCommandDto(
String location,
String category,
Integer runningMinutes,
Integer stock,
Long price,
MultipartFile thumbnail,
LocalDateTime eventTime,
LocalDateTime saleStart,
Expand All @@ -50,8 +49,6 @@ public UpdateTicketingCommandDto(
this.location = location;
this.category = category;
this.runningMinutes = runningMinutes;
this.stock = stock;
this.price = price;
this.eventTime = eventTime;
this.thumbnail = thumbnail;
this.saleStart = saleStart;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@
import org.redisson.api.RedissonClient;
import org.redisson.config.Config;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.test.context.TestConfiguration;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Profile;
import org.springframework.data.redis.connection.RedisConnectionFactory;
import org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory;
import org.springframework.data.redis.core.RedisTemplate;
Expand All @@ -22,7 +23,8 @@

@Slf4j
@DisplayName("Embedded Redis 설정")
@TestConfiguration
@Configuration
@Profile("test")
@EnableRedisRepositories
public class EmbeddedRedisConfig {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import com.tiketeer.Tiketeer.domain.member.Member;
import com.tiketeer.Tiketeer.domain.purchase.usecase.dto.CreatePurchaseCommandDto;
import com.tiketeer.Tiketeer.domain.role.constant.RoleEnum;
import com.tiketeer.Tiketeer.domain.ticket.usecase.dto.CreateTicketMetadata;
import com.tiketeer.Tiketeer.domain.ticketing.Ticketing;
import com.tiketeer.Tiketeer.domain.ticketing.repository.TicketingRepository;
import com.tiketeer.Tiketeer.domain.ticketing.service.TicketingStockService;
Expand Down Expand Up @@ -66,7 +67,7 @@ public int makeConcurrency(int threadNums, List<Member> buyers, UUID ticketingId
return success.get();
}

public Ticketing createTicketing(Member member, int stock) {
public Ticketing createTicketing(Member member, List<CreateTicketMetadata> tickets) {
var now = LocalDateTime.now();
var ticketing = ticketingRepository.save(Ticketing.builder()
.member(member)
Expand All @@ -78,7 +79,7 @@ public Ticketing createTicketing(Member member, int stock) {
.saleEnd(now.plusMonths(6))
.eventTime(now.plusYears(1))
.build());
ticketingStockService.createStock(ticketing.getId(), stock);
ticketingStockService.createStock(ticketing.getId(), tickets);
return ticketing;
}

Expand Down
Loading
Loading