From 109cda37df5ad45180750bb1e624d480529ac68a Mon Sep 17 00:00:00 2001 From: gustavofg1pontes Date: Sun, 6 Oct 2024 22:11:13 -0300 Subject: [PATCH] Fix: MercadoPagoConfig --- .../domain/event/sale/ITicketSaleGateway.java | 2 -- .../infra/config/app/MercadoPagoConfig.java | 19 +++++++++++++ ...oConfiguration.java => PaymentConfig.java} | 22 ++++----------- .../payment/persistence/PaymentJpaEntity.java | 3 +- .../persistence/PaymentRepository.java | 3 +- .../event/sale/ticket/TicketSaleGateway.java | 28 +------------------ .../models/CreateTicketSaleRequest.java | 3 -- .../persistence/TicketSaleJpaEntity.java | 6 ++-- .../persistence/TicketSaleRepository.java | 6 ++-- infrastructure/src/main/resources/banner.txt | 3 +- 10 files changed, 36 insertions(+), 59 deletions(-) create mode 100644 infrastructure/src/main/java/br/com/ifsp/tickets/infra/config/app/MercadoPagoConfig.java rename infrastructure/src/main/java/br/com/ifsp/tickets/infra/config/app/{MercadoPagoConfiguration.java => PaymentConfig.java} (63%) diff --git a/domain/src/main/java/br/com/ifsp/tickets/domain/event/sale/ITicketSaleGateway.java b/domain/src/main/java/br/com/ifsp/tickets/domain/event/sale/ITicketSaleGateway.java index a795066..8340a27 100644 --- a/domain/src/main/java/br/com/ifsp/tickets/domain/event/sale/ITicketSaleGateway.java +++ b/domain/src/main/java/br/com/ifsp/tickets/domain/event/sale/ITicketSaleGateway.java @@ -15,8 +15,6 @@ public interface ITicketSaleGateway { Pagination findAllByEventID(EventID id, SearchQuery sq); - Pagination findAll(AdvancedSearchQuery sq); - TicketSale update(TicketSale event); void delete(TicketSale ticketSale); diff --git a/infrastructure/src/main/java/br/com/ifsp/tickets/infra/config/app/MercadoPagoConfig.java b/infrastructure/src/main/java/br/com/ifsp/tickets/infra/config/app/MercadoPagoConfig.java new file mode 100644 index 0000000..f37fc59 --- /dev/null +++ b/infrastructure/src/main/java/br/com/ifsp/tickets/infra/config/app/MercadoPagoConfig.java @@ -0,0 +1,19 @@ +package br.com.ifsp.tickets.infra.config.app; +import lombok.RequiredArgsConstructor; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.context.annotation.Configuration; + +import javax.annotation.PostConstruct; + +@Configuration +public class MercadoPagoConfig { + + @Value("${mercadopago.access.token}") + private String mercadoPagoAccessToken; + + @PostConstruct + public void initialize() { + com.mercadopago.MercadoPagoConfig.setAccessToken(mercadoPagoAccessToken); + } +} diff --git a/infrastructure/src/main/java/br/com/ifsp/tickets/infra/config/app/MercadoPagoConfiguration.java b/infrastructure/src/main/java/br/com/ifsp/tickets/infra/config/app/PaymentConfig.java similarity index 63% rename from infrastructure/src/main/java/br/com/ifsp/tickets/infra/config/app/MercadoPagoConfiguration.java rename to infrastructure/src/main/java/br/com/ifsp/tickets/infra/config/app/PaymentConfig.java index b5e0a6c..0f9a443 100644 --- a/infrastructure/src/main/java/br/com/ifsp/tickets/infra/config/app/MercadoPagoConfiguration.java +++ b/infrastructure/src/main/java/br/com/ifsp/tickets/infra/config/app/PaymentConfig.java @@ -1,36 +1,26 @@ package br.com.ifsp.tickets.infra.config.app; + +import br.com.ifsp.tickets.app.event.EventService; +import br.com.ifsp.tickets.app.event.EventServiceFactory; import br.com.ifsp.tickets.app.payment.PaymentService; import br.com.ifsp.tickets.app.payment.PaymentServiceFactory; import br.com.ifsp.tickets.domain.event.sale.ITicketSaleGateway; import br.com.ifsp.tickets.domain.ticket.ITicketGateway; import br.com.ifsp.tickets.domain.ticket.payment.IPaymentGateway; -import br.com.ifsp.tickets.infra.contexts.event.sale.payment.PaymentGateway; -import com.mercadopago.MercadoPagoConfig; import lombok.RequiredArgsConstructor; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.beans.factory.annotation.Value; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; -import javax.annotation.PostConstruct; - @Configuration @RequiredArgsConstructor(onConstructor_ = @__(@Autowired)) -public class MercadoPagoConfiguration { - private final ITicketSaleGateway ticketSaleGateway; +public class PaymentConfig { private final ITicketGateway ticketGateway; + private final ITicketSaleGateway ticketSaleGateway; private final IPaymentGateway paymentGateway; - @Value("${mercadopago.access.token}") - private String mercadoPagoAccessToken; - - @PostConstruct - public void initialize() { - MercadoPagoConfig.setAccessToken(mercadoPagoAccessToken); - } - @Bean - public PaymentService preferenceService() { + public PaymentService paymentService() { return PaymentServiceFactory.create(ticketGateway, ticketSaleGateway, paymentGateway); } } diff --git a/infrastructure/src/main/java/br/com/ifsp/tickets/infra/contexts/event/sale/payment/persistence/PaymentJpaEntity.java b/infrastructure/src/main/java/br/com/ifsp/tickets/infra/contexts/event/sale/payment/persistence/PaymentJpaEntity.java index 1f74c28..0772b08 100644 --- a/infrastructure/src/main/java/br/com/ifsp/tickets/infra/contexts/event/sale/payment/persistence/PaymentJpaEntity.java +++ b/infrastructure/src/main/java/br/com/ifsp/tickets/infra/contexts/event/sale/payment/persistence/PaymentJpaEntity.java @@ -10,13 +10,14 @@ import lombok.Getter; import lombok.NoArgsConstructor; +import java.io.Serializable; import java.time.LocalDateTime; @Entity @Table(name = "payments") @NoArgsConstructor @Getter -public class PaymentJpaEntity { +public class PaymentJpaEntity implements Serializable { @Id @Column(name = "id", nullable = false, unique = true, updatable = false) private Long id; diff --git a/infrastructure/src/main/java/br/com/ifsp/tickets/infra/contexts/event/sale/payment/persistence/PaymentRepository.java b/infrastructure/src/main/java/br/com/ifsp/tickets/infra/contexts/event/sale/payment/persistence/PaymentRepository.java index 1266dda..1344c8d 100644 --- a/infrastructure/src/main/java/br/com/ifsp/tickets/infra/contexts/event/sale/payment/persistence/PaymentRepository.java +++ b/infrastructure/src/main/java/br/com/ifsp/tickets/infra/contexts/event/sale/payment/persistence/PaymentRepository.java @@ -2,7 +2,6 @@ import org.springframework.data.jpa.repository.JpaRepository; -import java.util.UUID; -public interface PaymentRepository extends JpaRepository { +public interface PaymentRepository extends JpaRepository { } diff --git a/infrastructure/src/main/java/br/com/ifsp/tickets/infra/contexts/event/sale/ticket/TicketSaleGateway.java b/infrastructure/src/main/java/br/com/ifsp/tickets/infra/contexts/event/sale/ticket/TicketSaleGateway.java index eaa65c6..d636fde 100644 --- a/infrastructure/src/main/java/br/com/ifsp/tickets/infra/contexts/event/sale/ticket/TicketSaleGateway.java +++ b/infrastructure/src/main/java/br/com/ifsp/tickets/infra/contexts/event/sale/ticket/TicketSaleGateway.java @@ -4,18 +4,15 @@ import br.com.ifsp.tickets.domain.event.sale.ITicketSaleGateway; import br.com.ifsp.tickets.domain.event.sale.TicketSale; import br.com.ifsp.tickets.domain.event.sale.TicketSaleID; -import br.com.ifsp.tickets.domain.shared.search.AdvancedSearchQuery; import br.com.ifsp.tickets.domain.shared.search.Pagination; import br.com.ifsp.tickets.domain.shared.search.SearchQuery; import br.com.ifsp.tickets.infra.contexts.event.sale.ticket.persistence.TicketSaleJpaEntity; import br.com.ifsp.tickets.infra.contexts.event.sale.ticket.persistence.TicketSaleRepository; -import br.com.ifsp.tickets.infra.contexts.event.sale.ticket.persistence.spec.TicketSaleSpecificationBuilder; import lombok.RequiredArgsConstructor; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.data.domain.Page; import org.springframework.data.domain.PageRequest; import org.springframework.data.domain.Sort; -import org.springframework.data.jpa.domain.Specification; import org.springframework.stereotype.Component; import java.util.Optional; @@ -24,7 +21,6 @@ @RequiredArgsConstructor(onConstructor_ = @__(@Autowired)) public class TicketSaleGateway implements ITicketSaleGateway { private final TicketSaleRepository repository; - private final TicketSaleRepository ticketSaleRepository; @Override public TicketSale create(TicketSale ticketSale) { @@ -44,29 +40,7 @@ public Pagination findAllByEventID(EventID id, SearchQuery sq) { Sort.by(Sort.Direction.fromString(sq.direction()), sq.sort()) ); - final Page page = this.repository.findAllByEventID(id.getValue(), request).map(ticketSaleJpaEntity -> ticketSaleJpaEntity.toAggregate()); - - return Pagination.of( - page.getNumber(), - page.getSize(), - page.getTotalElements(), - page.getContent() - ); - } - - @Override - public Pagination findAll(AdvancedSearchQuery sq) { - final TicketSaleSpecificationBuilder specificationBuilder = new TicketSaleSpecificationBuilder(); - sq.filters().forEach(specificationBuilder::with); - final Specification specification = specificationBuilder.build(); - final Sort orders = sq.sorts().stream().map(sort -> Sort.by(Sort.Direction.fromString(sort.direction()), sort.sort())).reduce(Sort::and).orElse(Sort.by(Sort.Order.asc("id"))); - final PageRequest request = PageRequest.of( - sq.page(), - sq.perPage(), - orders - ); - - final Page page = this.repository.findAll(specification, request).map(ticketSaleJpaEntity -> ticketSaleJpaEntity.toAggregate()); + final Page page = this.repository.findAllByEventId(id.getValue(), request).map(TicketSaleJpaEntity::toAggregate); return Pagination.of( page.getNumber(), diff --git a/infrastructure/src/main/java/br/com/ifsp/tickets/infra/contexts/event/sale/ticket/models/CreateTicketSaleRequest.java b/infrastructure/src/main/java/br/com/ifsp/tickets/infra/contexts/event/sale/ticket/models/CreateTicketSaleRequest.java index b160b33..d9619d7 100644 --- a/infrastructure/src/main/java/br/com/ifsp/tickets/infra/contexts/event/sale/ticket/models/CreateTicketSaleRequest.java +++ b/infrastructure/src/main/java/br/com/ifsp/tickets/infra/contexts/event/sale/ticket/models/CreateTicketSaleRequest.java @@ -3,9 +3,6 @@ import com.fasterxml.jackson.annotation.JsonProperty; import java.math.BigDecimal; -import java.time.LocalDate; -import java.util.HashMap; - public record CreateTicketSaleRequest( @JsonProperty("name") String name, @JsonProperty("description") String description, diff --git a/infrastructure/src/main/java/br/com/ifsp/tickets/infra/contexts/event/sale/ticket/persistence/TicketSaleJpaEntity.java b/infrastructure/src/main/java/br/com/ifsp/tickets/infra/contexts/event/sale/ticket/persistence/TicketSaleJpaEntity.java index cd1c69b..091a5fa 100644 --- a/infrastructure/src/main/java/br/com/ifsp/tickets/infra/contexts/event/sale/ticket/persistence/TicketSaleJpaEntity.java +++ b/infrastructure/src/main/java/br/com/ifsp/tickets/infra/contexts/event/sale/ticket/persistence/TicketSaleJpaEntity.java @@ -23,7 +23,7 @@ public class TicketSaleJpaEntity implements Serializable { @Column(name = "id", nullable = false, unique = true, updatable = false) private UUID id; @Column(name = "event_id", nullable = false) - private UUID eventID; + private UUID eventId; @Column(name = "name", nullable = false) private String name; // example: Ingresso Unitário + Meia entrada @Column(name = "description", nullable = false) @@ -37,7 +37,7 @@ public class TicketSaleJpaEntity implements Serializable { public TicketSaleJpaEntity(UUID id, UUID eventID, String name, String description, BigDecimal price, int entries, boolean active) { this.id = id; - this.eventID = eventID; + this.eventId = eventID; this.name = name; this.description = description; this.price = price; @@ -60,7 +60,7 @@ public static TicketSaleJpaEntity from(TicketSale ticketSale) { public TicketSale toAggregate() { return new TicketSale( TicketSaleID.with(this.getId()), - EventID.with(this.getEventID()), + EventID.with(this.getEventId()), this.getName(), this.getDescription(), this.getPrice(), diff --git a/infrastructure/src/main/java/br/com/ifsp/tickets/infra/contexts/event/sale/ticket/persistence/TicketSaleRepository.java b/infrastructure/src/main/java/br/com/ifsp/tickets/infra/contexts/event/sale/ticket/persistence/TicketSaleRepository.java index a9c75dd..28a2029 100644 --- a/infrastructure/src/main/java/br/com/ifsp/tickets/infra/contexts/event/sale/ticket/persistence/TicketSaleRepository.java +++ b/infrastructure/src/main/java/br/com/ifsp/tickets/infra/contexts/event/sale/ticket/persistence/TicketSaleRepository.java @@ -1,13 +1,11 @@ package br.com.ifsp.tickets.infra.contexts.event.sale.ticket.persistence; import org.springframework.data.domain.Page; -import org.springframework.data.domain.PageRequest; -import org.springframework.data.jpa.domain.Specification; +import org.springframework.data.domain.Pageable; import org.springframework.data.jpa.repository.JpaRepository; import java.util.UUID; public interface TicketSaleRepository extends JpaRepository { - Page findAllByEventID(UUID eventID, PageRequest request); - Page findAll(Specification specification, PageRequest request); + Page findAllByEventId(UUID eventID, Pageable pageable); } diff --git a/infrastructure/src/main/resources/banner.txt b/infrastructure/src/main/resources/banner.txt index 16d3aa0..6a2d8a8 100644 --- a/infrastructure/src/main/resources/banner.txt +++ b/infrastructure/src/main/resources/banner.txt @@ -8,4 +8,5 @@ Application: TicketsIFSP-API Version: v1.0.0 Authors: - - Leonardo \ No newline at end of file + - Leonardo + - Gustavo \ No newline at end of file