diff --git a/infrastructure/src/main/java/br/com/ifsp/tickets/infra/config/app/ProductConfig.java b/infrastructure/src/main/java/br/com/ifsp/tickets/infra/config/app/ProductConfig.java new file mode 100644 index 0000000..89a2b85 --- /dev/null +++ b/infrastructure/src/main/java/br/com/ifsp/tickets/infra/config/app/ProductConfig.java @@ -0,0 +1,26 @@ +package br.com.ifsp.tickets.infra.config.app; + +import br.com.ifsp.tickets.app.financial.product.ProductService; +import br.com.ifsp.tickets.app.financial.product.ProductServiceFactory; +import br.com.ifsp.tickets.domain.administrative.event.IEventGateway; +import br.com.ifsp.tickets.domain.financial.product.ITicketSaleGateway; +import lombok.RequiredArgsConstructor; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; + +@Configuration +@RequiredArgsConstructor(onConstructor_ = @__(@Autowired)) +public class ProductConfig { + + private final IEventGateway eventGateway; + private final ITicketSaleGateway ticketSaleGateway; + + @Bean + public ProductService productService() { + return ProductServiceFactory.create( + eventGateway, + ticketSaleGateway + ); + } +} diff --git a/infrastructure/src/main/java/br/com/ifsp/tickets/infra/contexts/administrative/ticket/TicketGateway.java b/infrastructure/src/main/java/br/com/ifsp/tickets/infra/contexts/administrative/ticket/TicketGateway.java index ec69f9e..53ef7db 100644 --- a/infrastructure/src/main/java/br/com/ifsp/tickets/infra/contexts/administrative/ticket/TicketGateway.java +++ b/infrastructure/src/main/java/br/com/ifsp/tickets/infra/contexts/administrative/ticket/TicketGateway.java @@ -17,6 +17,7 @@ import org.springframework.data.domain.Sort; import org.springframework.stereotype.Component; +import java.time.LocalDate; import java.util.Optional; @Component @@ -36,7 +37,7 @@ public Optional findById(TicketID id) { @Override public Ticket findByCodeAndNotExpired(TicketCode code) { - return this.repository.findByCodeAndExpiredInBefore(code.getCode(), new java.util.Date()) + return this.repository.findByCodeAndExpiredInBefore(code.getCode(), LocalDate.now()) .map(TicketJpaEntity::toAggregate).orElse(null); } @@ -48,7 +49,7 @@ public Pagination findAllByUserID(UserID id, SearchQuery sq) { Sort.by(Sort.Direction.fromString(sq.direction()), sq.sort()) ); - final Page page = this.repository.findAllByUserId(id.getValue(), request).map(TicketJpaEntity::toAggregate); + final Page page = this.repository.findAllByEnrollmentUserID(id.getValue(), request).map(TicketJpaEntity::toAggregate); return Pagination.of( page.getNumber(), @@ -66,7 +67,7 @@ public Pagination findAllByUserIDAndEventID(UserID userID, EventID event Sort.by(Sort.Direction.fromString(sq.direction()), sq.sort()) ); - final Page page = this.repository.findAllByUserIdAndEventId(userID.getValue(), eventID.getValue(), request) + final Page page = this.repository.findAllByEnrollmentUserIDAndEventId(userID.getValue(), eventID.getValue(), request) .map(TicketJpaEntity::toAggregate); return Pagination.of( diff --git a/infrastructure/src/main/java/br/com/ifsp/tickets/infra/contexts/administrative/ticket/persistence/TicketRepository.java b/infrastructure/src/main/java/br/com/ifsp/tickets/infra/contexts/administrative/ticket/persistence/TicketRepository.java index f9437fc..ef940ad 100644 --- a/infrastructure/src/main/java/br/com/ifsp/tickets/infra/contexts/administrative/ticket/persistence/TicketRepository.java +++ b/infrastructure/src/main/java/br/com/ifsp/tickets/infra/contexts/administrative/ticket/persistence/TicketRepository.java @@ -4,11 +4,16 @@ import org.springframework.data.domain.Pageable; import org.springframework.data.jpa.repository.JpaRepository; +import java.time.LocalDate; import java.util.Optional; import java.util.UUID; public interface TicketRepository extends JpaRepository { - Optional findByCodeAndExpiredInBefore(String code, java.util.Date date); - Page findAllByUserId(UUID userId, Pageable pageable); - Page findAllByUserIdAndEventId(UUID userId, UUID eventId, Pageable pageable); + + Optional findByCodeAndExpiredInBefore(String code, LocalDate date); + + Page findAllByEnrollmentUserID(UUID userId, Pageable pageable); + + Page findAllByEnrollmentUserIDAndEventId(UUID userId, UUID eventId, Pageable pageable); + }