-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: TicketingCommandService 인터페이스 제거 및 구체 클래스 사용
- Loading branch information
1 parent
c5ec08d
commit 7c82096
Showing
4 changed files
with
75 additions
and
74 deletions.
There are no files selected for viewing
48 changes: 46 additions & 2 deletions
48
backend/src/main/java/com/festago/ticketing/application/command/TicketingCommandService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,53 @@ | ||
package com.festago.ticketing.application.command; | ||
|
||
import com.festago.common.exception.BadRequestException; | ||
import com.festago.common.exception.ErrorCode; | ||
import com.festago.ticket.domain.NewTicket; | ||
import com.festago.ticket.domain.NewTicketType; | ||
import com.festago.ticket.repository.NewTicketDao; | ||
import com.festago.ticketing.domain.Booker; | ||
import com.festago.ticketing.domain.ReserveTicket; | ||
import com.festago.ticketing.domain.TicketingSequenceGenerator; | ||
import com.festago.ticketing.domain.validator.TicketingValidator; | ||
import com.festago.ticketing.dto.TicketingResult; | ||
import com.festago.ticketing.dto.command.TicketingCommand; | ||
import com.festago.ticketing.repository.ReserveTicketRepository; | ||
import java.time.Clock; | ||
import java.time.LocalDateTime; | ||
import java.util.List; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.stereotype.Service; | ||
import org.springframework.transaction.annotation.Transactional; | ||
|
||
public interface TicketingCommandService { | ||
@Service | ||
@Transactional | ||
@RequiredArgsConstructor | ||
public class TicketingCommandService { | ||
|
||
TicketingResult reserveTicket(TicketingCommand command); | ||
private final NewTicketDao ticketDao; | ||
private final ReserveTicketRepository reserveTicketRepository; | ||
private final TicketingSequenceGenerator sequenceGenerator; | ||
private final List<TicketingValidator> validators; | ||
private final Clock clock; | ||
|
||
public TicketingResult reserveTicket(TicketingCommand command) { | ||
Long ticketId = command.ticketId(); | ||
NewTicketType ticketType = command.ticketType(); | ||
NewTicket ticket = ticketDao.findByIdWithTicketTypeAndFetch(ticketId, ticketType); | ||
Booker booker = command.booker(); | ||
ticket.validateReserve(booker, LocalDateTime.now(clock)); | ||
validators.forEach(validator -> validator.validate(ticket, booker)); | ||
validate(ticket, booker); | ||
int sequence = sequenceGenerator.generate(ticketId); | ||
ReserveTicket reserveTicket = ticket.reserve(booker, sequence); | ||
reserveTicketRepository.save(ticket.reserve(booker, sequence)); | ||
return new TicketingResult(reserveTicket.getTicketId()); | ||
} | ||
|
||
private void validate(NewTicket ticket, Booker booker) { | ||
long reserveCount = reserveTicketRepository.countByMemberIdAndTicketId(booker.getMemberId(), ticket.getId()); | ||
if (reserveCount >= ticket.getMaxReserveAmount()) { | ||
throw new BadRequestException(ErrorCode.RESERVE_TICKET_OVER_AMOUNT); | ||
} | ||
} | ||
} |
54 changes: 0 additions & 54 deletions
54
.../src/main/java/com/festago/ticketing/application/command/TicketingCommandServiceImpl.java
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters