-
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.
- Loading branch information
1 parent
9503869
commit 29f42c5
Showing
18 changed files
with
599 additions
and
1 deletion.
There are no files selected for viewing
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
8 changes: 8 additions & 0 deletions
8
backend/src/main/java/com/festago/stage/domain/validator/StageDeleteValidator.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 |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package com.festago.stage.domain.validator; | ||
|
||
import com.festago.stage.domain.Stage; | ||
|
||
public interface StageDeleteValidator { | ||
|
||
void validate(Stage stage); | ||
} |
8 changes: 8 additions & 0 deletions
8
backend/src/main/java/com/festago/stage/domain/validator/StageUpdateValidator.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 |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package com.festago.stage.domain.validator; | ||
|
||
import com.festago.stage.domain.Stage; | ||
|
||
public interface StageUpdateValidator { | ||
|
||
void validate(Stage stage); | ||
} |
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
49 changes: 49 additions & 0 deletions
49
.../src/main/java/com/festago/ticket/application/command/stage/StageTicketCreateService.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 |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package com.festago.ticket.application.command.stage; | ||
|
||
import com.festago.common.exception.ErrorCode; | ||
import com.festago.common.exception.NotFoundException; | ||
import com.festago.stage.domain.Stage; | ||
import com.festago.stage.repository.StageRepository; | ||
import com.festago.ticket.domain.StageTicket; | ||
import com.festago.ticket.domain.TicketExclusive; | ||
import com.festago.ticket.dto.command.StageTicketCreateCommand; | ||
import com.festago.ticket.dto.event.TicketCreatedEvent; | ||
import com.festago.ticket.repository.StageTicketRepository; | ||
import java.time.Clock; | ||
import java.time.LocalDateTime; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.context.ApplicationEventPublisher; | ||
import org.springframework.stereotype.Service; | ||
import org.springframework.transaction.annotation.Transactional; | ||
|
||
@Service | ||
@Transactional | ||
@RequiredArgsConstructor | ||
public class StageTicketCreateService { | ||
|
||
private final StageTicketRepository stageTicketRepository; | ||
private final StageRepository stageRepository; | ||
private final ApplicationEventPublisher eventPublisher; | ||
private final Clock clock; | ||
|
||
public Long createStageTicket(StageTicketCreateCommand command) { | ||
Long schoolId = command.schoolId(); | ||
Long stageId = command.stageId(); | ||
TicketExclusive ticketType = command.ticketExclusive(); | ||
StageTicket stageTicket = stageTicketRepository.findByStageIdAndTicketExclusiveWithFetch(stageId, ticketType) | ||
.orElseGet(() -> { | ||
Stage stage = findStage(stageId); | ||
return stageTicketRepository.save(new StageTicket(schoolId, ticketType, stage)); | ||
}); | ||
LocalDateTime entryTime = command.entryTime(); | ||
int amount = command.amount(); | ||
stageTicket.addTicketEntryTime(schoolId, LocalDateTime.now(clock), entryTime, amount); | ||
eventPublisher.publishEvent(new TicketCreatedEvent(stageTicket)); | ||
return stageTicket.getId(); | ||
} | ||
|
||
private Stage findStage(Long stageId) { | ||
return stageRepository.findByIdWithFetchFestival(stageId) | ||
.orElseThrow(() -> new NotFoundException(ErrorCode.STAGE_NOT_FOUND)); | ||
} | ||
} |
40 changes: 40 additions & 0 deletions
40
.../src/main/java/com/festago/ticket/application/command/stage/StageTicketDeleteService.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 |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package com.festago.ticket.application.command.stage; | ||
|
||
import com.festago.common.exception.ErrorCode; | ||
import com.festago.common.exception.NotFoundException; | ||
import com.festago.ticket.domain.StageTicket; | ||
import com.festago.ticket.dto.command.StageTicketDeleteCommand; | ||
import com.festago.ticket.dto.event.TicketDeletedEvent; | ||
import com.festago.ticket.repository.StageTicketRepository; | ||
import java.time.Clock; | ||
import java.time.LocalDateTime; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.context.ApplicationEventPublisher; | ||
import org.springframework.stereotype.Service; | ||
import org.springframework.transaction.annotation.Transactional; | ||
|
||
@Service | ||
@RequiredArgsConstructor | ||
@Transactional | ||
public class StageTicketDeleteService { | ||
|
||
private final StageTicketRepository stageTicketRepository; | ||
private final ApplicationEventPublisher eventPublisher; | ||
private final Clock clock; | ||
|
||
public void deleteStageTicket(StageTicketDeleteCommand command) { | ||
Long ticketId = command.stageTicketId(); | ||
StageTicket stageTicket = stageTicketRepository.findByIdWithFetch(ticketId) | ||
.orElseThrow(() -> new NotFoundException(ErrorCode.TICKET_NOT_FOUND)); | ||
Long schoolId = command.schoolId(); | ||
LocalDateTime now = LocalDateTime.now(clock); | ||
LocalDateTime entryTime = command.entryTime(); | ||
boolean isDeleted = stageTicket.deleteTicketEntryTime(schoolId, now, entryTime); | ||
if (stageTicket.isEmptyAmount()) { | ||
stageTicketRepository.deleteById(ticketId); | ||
} | ||
if (isDeleted) { | ||
eventPublisher.publishEvent(new TicketDeletedEvent(stageTicket)); | ||
} | ||
} | ||
} |
16 changes: 16 additions & 0 deletions
16
backend/src/main/java/com/festago/ticket/dto/command/StageTicketCreateCommand.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 |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package com.festago.ticket.dto.command; | ||
|
||
import com.festago.ticket.domain.TicketExclusive; | ||
import java.time.LocalDateTime; | ||
import lombok.Builder; | ||
|
||
@Builder | ||
public record StageTicketCreateCommand( | ||
Long schoolId, | ||
Long stageId, | ||
TicketExclusive ticketExclusive, | ||
int amount, | ||
LocalDateTime entryTime | ||
) { | ||
|
||
} |
13 changes: 13 additions & 0 deletions
13
backend/src/main/java/com/festago/ticket/dto/command/StageTicketDeleteCommand.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 |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package com.festago.ticket.dto.command; | ||
|
||
import java.time.LocalDateTime; | ||
import lombok.Builder; | ||
|
||
@Builder | ||
public record StageTicketDeleteCommand( | ||
Long schoolId, | ||
Long stageTicketId, | ||
LocalDateTime entryTime | ||
) { | ||
|
||
} |
9 changes: 9 additions & 0 deletions
9
backend/src/main/java/com/festago/ticket/dto/event/TicketCreatedEvent.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 |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package com.festago.ticket.dto.event; | ||
|
||
import com.festago.ticket.domain.NewTicket; | ||
|
||
public record TicketCreatedEvent( | ||
NewTicket ticket | ||
) { | ||
|
||
} |
9 changes: 9 additions & 0 deletions
9
backend/src/main/java/com/festago/ticket/dto/event/TicketDeletedEvent.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 |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package com.festago.ticket.dto.event; | ||
|
||
import com.festago.ticket.domain.NewTicket; | ||
|
||
public record TicketDeletedEvent( | ||
NewTicket ticket | ||
) { | ||
|
||
} |
40 changes: 40 additions & 0 deletions
40
backend/src/main/java/com/festago/ticket/repository/StageTicketRepository.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 |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package com.festago.ticket.repository; | ||
|
||
import com.festago.ticket.domain.StageTicket; | ||
import com.festago.ticket.domain.TicketExclusive; | ||
import java.util.Optional; | ||
import org.springframework.data.jpa.repository.Query; | ||
import org.springframework.data.repository.Repository; | ||
import org.springframework.data.repository.query.Param; | ||
|
||
public interface StageTicketRepository extends Repository<StageTicket, Long> { | ||
|
||
StageTicket save(StageTicket stageTicket); | ||
|
||
Optional<StageTicket> findById(Long id); | ||
|
||
boolean existsByStageId(Long stageId); | ||
|
||
void deleteById(Long id); | ||
|
||
@Query(""" | ||
select st | ||
from StageTicket st | ||
join fetch st.stage | ||
join fetch st.ticketEntryTimes | ||
where st.id = :id | ||
""") | ||
Optional<StageTicket> findByIdWithFetch(@Param("id") Long id); | ||
|
||
@Query(""" | ||
select st | ||
from StageTicket st | ||
join fetch st.stage | ||
join fetch st.ticketEntryTimes | ||
where st.stage.id = :stageId and st.ticketExclusive = :ticketExclusive | ||
""") | ||
Optional<StageTicket> findByStageIdAndTicketExclusiveWithFetch( | ||
@Param("stageId") Long stageId, | ||
@Param("ticketExclusive") TicketExclusive ticketExclusive | ||
); | ||
} |
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
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
Oops, something went wrong.