diff --git a/application/src/main/java/br/com/ifsp/tickets/app/administrative/enrollment/core/create/CreateEnrollmentInput.java b/application/src/main/java/br/com/ifsp/tickets/app/administrative/enrollment/core/create/CreateEnrollmentInput.java index e25fe24..85bc5e0 100644 --- a/application/src/main/java/br/com/ifsp/tickets/app/administrative/enrollment/core/create/CreateEnrollmentInput.java +++ b/application/src/main/java/br/com/ifsp/tickets/app/administrative/enrollment/core/create/CreateEnrollmentInput.java @@ -9,10 +9,9 @@ public record CreateEnrollmentInput( String document, LocalDate birthDate, String eventId, - String ticketSaleId, - String ticketId + String ticketSaleId ) { - public static CreateEnrollmentInput of(String userId, String name, String email, String document, LocalDate birthDate, String eventId, String ticketSaleId, String ticketId) { - return new CreateEnrollmentInput(userId, name, email, document, birthDate, eventId, ticketSaleId, ticketId); + public static CreateEnrollmentInput of(String userId, String name, String email, String document, LocalDate birthDate, String eventId, String ticketSaleId) { + return new CreateEnrollmentInput(userId, name, email, document, birthDate, eventId, ticketSaleId); } } diff --git a/application/src/main/java/br/com/ifsp/tickets/app/administrative/enrollment/core/create/CreateEnrollmentUseCase.java b/application/src/main/java/br/com/ifsp/tickets/app/administrative/enrollment/core/create/CreateEnrollmentUseCase.java index 4549b05..dd226cc 100644 --- a/application/src/main/java/br/com/ifsp/tickets/app/administrative/enrollment/core/create/CreateEnrollmentUseCase.java +++ b/application/src/main/java/br/com/ifsp/tickets/app/administrative/enrollment/core/create/CreateEnrollmentUseCase.java @@ -1,12 +1,6 @@ package br.com.ifsp.tickets.app.administrative.enrollment.core.create; import br.com.ifsp.tickets.app.administrative.enrollment.ITicketQRGenerator; -import br.com.ifsp.tickets.domain.communication.email.Email; -import br.com.ifsp.tickets.domain.communication.email.IEmailGateway; -import br.com.ifsp.tickets.domain.communication.message.IMessageGateway; -import br.com.ifsp.tickets.domain.communication.message.Message; -import br.com.ifsp.tickets.domain.communication.message.type.MessageSubject; -import br.com.ifsp.tickets.domain.communication.message.type.MessageType; import br.com.ifsp.tickets.domain.administrative.company.Company; import br.com.ifsp.tickets.domain.administrative.company.ICompanyGateway; import br.com.ifsp.tickets.domain.administrative.enrollment.Enrollment; @@ -15,16 +9,21 @@ import br.com.ifsp.tickets.domain.administrative.event.EventID; import br.com.ifsp.tickets.domain.administrative.event.EventStatus; import br.com.ifsp.tickets.domain.administrative.event.IEventGateway; +import br.com.ifsp.tickets.domain.administrative.ticket.ITicketGateway; +import br.com.ifsp.tickets.domain.administrative.ticket.Ticket; +import br.com.ifsp.tickets.domain.administrative.user.UserID; +import br.com.ifsp.tickets.domain.communication.email.Email; +import br.com.ifsp.tickets.domain.communication.email.IEmailGateway; +import br.com.ifsp.tickets.domain.communication.message.IMessageGateway; +import br.com.ifsp.tickets.domain.communication.message.Message; +import br.com.ifsp.tickets.domain.communication.message.type.MessageSubject; +import br.com.ifsp.tickets.domain.communication.message.type.MessageType; import br.com.ifsp.tickets.domain.financial.product.ITicketSaleGateway; import br.com.ifsp.tickets.domain.financial.product.TicketSale; import br.com.ifsp.tickets.domain.financial.product.TicketSaleID; import br.com.ifsp.tickets.domain.shared.exceptions.NotFoundException; import br.com.ifsp.tickets.domain.shared.file.IFileStorage; import br.com.ifsp.tickets.domain.shared.validation.handler.Notification; -import br.com.ifsp.tickets.domain.administrative.ticket.ITicketGateway; -import br.com.ifsp.tickets.domain.administrative.ticket.Ticket; -import br.com.ifsp.tickets.domain.administrative.ticket.TicketID; -import br.com.ifsp.tickets.domain.administrative.user.UserID; import java.time.LocalDate; @@ -59,7 +58,6 @@ public CreateEnrollmentOutput execute(CreateEnrollmentInput anIn) { final String emailString = anIn.email(); final LocalDate birthDate = anIn.birthDate(); final String document = anIn.document(); - final TicketID ticketID = TicketID.with(anIn.ticketId()); final EventID eventID = EventID.with(anIn.eventId()); final TicketSaleID ticketSaleID = TicketSaleID.with(anIn.ticketSaleId()); diff --git a/application/src/main/java/br/com/ifsp/tickets/app/administrative/enrollment/upsert/create/CreateUpsertEnrollmentInput.java b/application/src/main/java/br/com/ifsp/tickets/app/administrative/enrollment/upsert/create/CreateUpsertEnrollmentInput.java deleted file mode 100644 index f0eb00a..0000000 --- a/application/src/main/java/br/com/ifsp/tickets/app/administrative/enrollment/upsert/create/CreateUpsertEnrollmentInput.java +++ /dev/null @@ -1,21 +0,0 @@ -package br.com.ifsp.tickets.app.administrative.enrollment.upsert.create; - -import br.com.ifsp.tickets.domain.administrative.user.User; - -import java.time.LocalDate; - -public record CreateUpsertEnrollmentInput( - User user, - String name, - String email, - String document, - LocalDate birthDate, - String eventId, - String ticketSaleId, - String ticketID, - String preferenceURL -) { - public static CreateUpsertEnrollmentInput of(User aggregate, String name, String email, String document, LocalDate birthDate, String eventId, String ticketSaleId, String preferenceURL, String ticketID) { - return new CreateUpsertEnrollmentInput(aggregate, name, email, document, birthDate, eventId, ticketSaleId, ticketID, preferenceURL); - } -} diff --git a/application/src/main/java/br/com/ifsp/tickets/app/administrative/enrollment/upsert/create/CreateUpsertUpsertEnrollmentUseCase.java b/application/src/main/java/br/com/ifsp/tickets/app/administrative/enrollment/upsert/create/CreateUpsertUpsertEnrollmentUseCase.java deleted file mode 100644 index 0e213f1..0000000 --- a/application/src/main/java/br/com/ifsp/tickets/app/administrative/enrollment/upsert/create/CreateUpsertUpsertEnrollmentUseCase.java +++ /dev/null @@ -1,96 +0,0 @@ -package br.com.ifsp.tickets.app.administrative.enrollment.upsert.create; - -import br.com.ifsp.tickets.app.administrative.enrollment.ITicketQRGenerator; -import br.com.ifsp.tickets.domain.communication.email.IEmailGateway; -import br.com.ifsp.tickets.domain.communication.message.IMessageGateway; -import br.com.ifsp.tickets.domain.administrative.company.Company; -import br.com.ifsp.tickets.domain.administrative.company.ICompanyGateway; -import br.com.ifsp.tickets.domain.administrative.enrollment.IEnrollmentGateway; -import br.com.ifsp.tickets.domain.administrative.enrollment.upsert.IUpsertEnrollmentGateway; -import br.com.ifsp.tickets.domain.administrative.enrollment.upsert.UpsertEnrollment; -import br.com.ifsp.tickets.domain.administrative.event.Event; -import br.com.ifsp.tickets.domain.administrative.event.EventID; -import br.com.ifsp.tickets.domain.administrative.event.EventStatus; -import br.com.ifsp.tickets.domain.administrative.event.IEventGateway; -import br.com.ifsp.tickets.domain.financial.product.ITicketSaleGateway; -import br.com.ifsp.tickets.domain.financial.product.TicketSale; -import br.com.ifsp.tickets.domain.financial.product.TicketSaleID; -import br.com.ifsp.tickets.domain.shared.exceptions.NotFoundException; -import br.com.ifsp.tickets.domain.shared.file.IFileStorage; -import br.com.ifsp.tickets.domain.shared.validation.handler.Notification; -import br.com.ifsp.tickets.domain.administrative.ticket.ITicketGateway; -import br.com.ifsp.tickets.domain.administrative.ticket.TicketID; -import br.com.ifsp.tickets.domain.administrative.user.User; -import br.com.ifsp.tickets.domain.administrative.user.UserID; - -import java.time.LocalDate; - -public class CreateUpsertUpsertEnrollmentUseCase implements ICreateUpsertEnrollmentUseCase { - private final IEventGateway eventGateway; - private final IEnrollmentGateway enrollmentGateway; - private final IUpsertEnrollmentGateway upsertEnrollmentGateway; - private final ITicketGateway ticketGateway; - private final ITicketSaleGateway ticketSaleGateway; - private final IMessageGateway messageGateway; - private final ICompanyGateway companyGateway; - private final IEmailGateway emailGateway; - private final IFileStorage fileProvider; - private final ITicketQRGenerator ticketGenerator; - - public CreateUpsertUpsertEnrollmentUseCase(IEventGateway eventGateway, IEnrollmentGateway enrollmentGateway, IUpsertEnrollmentGateway upsertEnrollmentGateway, ITicketGateway ticketGateway, ITicketSaleGateway ticketSaleGateway, IMessageGateway messageGateway, ICompanyGateway companyGateway, IEmailGateway emailGateway, IFileStorage fileProvider, ITicketQRGenerator ticketGenerator) { - this.eventGateway = eventGateway; - this.enrollmentGateway = enrollmentGateway; - this.upsertEnrollmentGateway = upsertEnrollmentGateway; - this.ticketGateway = ticketGateway; - this.ticketSaleGateway = ticketSaleGateway; - this.messageGateway = messageGateway; - this.companyGateway = companyGateway; - this.emailGateway = emailGateway; - this.fileProvider = fileProvider; - this.ticketGenerator = ticketGenerator; - } - - @Override - public String execute(CreateUpsertEnrollmentInput anIn) { - final User user = anIn.user(); - String preference = anIn.preferenceURL(); - String name = anIn.name(); - String emailString = anIn.email(); - LocalDate birthDate = anIn.birthDate(); - String document = anIn.document(); - TicketID ticketID = TicketID.with(anIn.ticketID()); - final boolean alreadyExists; - final EventID eventID = EventID.with(anIn.eventId()); - final TicketSaleID ticketSaleID = TicketSaleID.with(anIn.ticketSaleId()); - final TicketSale ticketSale = this.ticketSaleGateway.findById(ticketSaleID).orElseThrow(() -> NotFoundException.with(TicketSale.class, ticketSaleID)); - final Event event = this.eventGateway.findById(eventID).orElseThrow(() -> NotFoundException.with(Event.class, eventID)); - final Company company = this.companyGateway.findById(event.getCompanyID()).orElseThrow(() -> NotFoundException.with(Company.class, event.getCompanyID())); - - if (!event.getStatus().equals(EventStatus.OPENED)) - Notification.create("Event is not opened").append("Event is not open for enrollment").throwAnyErrors(); - - if (user != null) { - name = user.getName(); - emailString = user.getEmail().getValue(); - birthDate = user.getBirthDate(); - document = user.getDocument().getValue(); - alreadyExists = this.enrollmentGateway.existsByUserIDAndEventID(user.getId(), eventID); - } else alreadyExists = this.enrollmentGateway.existsByDocumentAndEventID(document, eventID); - - if (alreadyExists) { - Notification.create("Validation Error").append("User already enrolled in this event").throwAnyErrors(); - } - final UserID userID = user != null ? user.getId() : new UserID(null); - - - final UpsertEnrollment enrollment = UpsertEnrollment - .newUpsertEnrollment(name, emailString, document, birthDate, userID, eventID, ticketSaleID, ticketID); - - final Notification notification = Notification.create("An error occurred while validating the enrollment"); - enrollment.validate(notification); - notification.throwAnyErrors(); - final UpsertEnrollment createdEnrollment = this.upsertEnrollmentGateway.create(enrollment); - - return createdEnrollment.getId().getValue().toString(); - } -} diff --git a/application/src/main/java/br/com/ifsp/tickets/app/administrative/enrollment/upsert/create/ICreateUpsertEnrollmentUseCase.java b/application/src/main/java/br/com/ifsp/tickets/app/administrative/enrollment/upsert/create/ICreateUpsertEnrollmentUseCase.java deleted file mode 100644 index a485cf6..0000000 --- a/application/src/main/java/br/com/ifsp/tickets/app/administrative/enrollment/upsert/create/ICreateUpsertEnrollmentUseCase.java +++ /dev/null @@ -1,6 +0,0 @@ -package br.com.ifsp.tickets.app.administrative.enrollment.upsert.create; - -import br.com.ifsp.tickets.app.IUseCase; - -public interface ICreateUpsertEnrollmentUseCase extends IUseCase { -} diff --git a/application/src/main/java/br/com/ifsp/tickets/app/administrative/enrollment/upsert/retrieve/GetUpsertEnrollmentInput.java b/application/src/main/java/br/com/ifsp/tickets/app/administrative/enrollment/upsert/retrieve/GetUpsertEnrollmentInput.java deleted file mode 100644 index 0dbe83c..0000000 --- a/application/src/main/java/br/com/ifsp/tickets/app/administrative/enrollment/upsert/retrieve/GetUpsertEnrollmentInput.java +++ /dev/null @@ -1,6 +0,0 @@ -package br.com.ifsp.tickets.app.administrative.enrollment.upsert.retrieve; - -public record GetUpsertEnrollmentInput ( - String ticketId -){ -} diff --git a/application/src/main/java/br/com/ifsp/tickets/app/administrative/enrollment/upsert/retrieve/GetUpsertEnrollmentOutput.java b/application/src/main/java/br/com/ifsp/tickets/app/administrative/enrollment/upsert/retrieve/GetUpsertEnrollmentOutput.java deleted file mode 100644 index dcae85e..0000000 --- a/application/src/main/java/br/com/ifsp/tickets/app/administrative/enrollment/upsert/retrieve/GetUpsertEnrollmentOutput.java +++ /dev/null @@ -1,30 +0,0 @@ -package br.com.ifsp.tickets.app.administrative.enrollment.upsert.retrieve; - -import br.com.ifsp.tickets.domain.administrative.enrollment.upsert.UpsertEnrollment; - -import java.time.LocalDate; - -public record GetUpsertEnrollmentOutput( - String userID, - String name, - String email, - String document, - LocalDate birthDate, - String eventId, - String ticketID, - String ticketSaleId -) { - - public static GetUpsertEnrollmentOutput from(UpsertEnrollment output) { - return new GetUpsertEnrollmentOutput( - output.getUserID().getValue().toString(), - output.getName(), - output.getEmail(), - output.getDocument(), - output.getBirthDate(), - output.getEventId().getValue().toString(), - output.getTicketID().getValue().toString(), - output.getTicketSaleId().getValue().toString() - ); - } -} diff --git a/application/src/main/java/br/com/ifsp/tickets/app/administrative/enrollment/upsert/retrieve/GetUpsertEnrollmentUseCase.java b/application/src/main/java/br/com/ifsp/tickets/app/administrative/enrollment/upsert/retrieve/GetUpsertEnrollmentUseCase.java deleted file mode 100644 index f98bf3c..0000000 --- a/application/src/main/java/br/com/ifsp/tickets/app/administrative/enrollment/upsert/retrieve/GetUpsertEnrollmentUseCase.java +++ /dev/null @@ -1,21 +0,0 @@ -package br.com.ifsp.tickets.app.administrative.enrollment.upsert.retrieve; - -import br.com.ifsp.tickets.domain.administrative.enrollment.upsert.IUpsertEnrollmentGateway; -import br.com.ifsp.tickets.domain.administrative.enrollment.upsert.UpsertEnrollment; -import br.com.ifsp.tickets.domain.shared.exceptions.NotFoundException; -import br.com.ifsp.tickets.domain.administrative.ticket.TicketID; - -public class GetUpsertEnrollmentUseCase implements IGetUpsertEnrollmentUseCase{ - private final IUpsertEnrollmentGateway upsertEnrollmentGateway; - - public GetUpsertEnrollmentUseCase(IUpsertEnrollmentGateway upsertEnrollmentGateway) { - this.upsertEnrollmentGateway = upsertEnrollmentGateway; - } - - @Override - public GetUpsertEnrollmentOutput execute(GetUpsertEnrollmentInput anIn) { - UpsertEnrollment upsertEnrollment = this.upsertEnrollmentGateway.getByTicketId(anIn.ticketId()).orElseThrow(() -> NotFoundException.with(UpsertEnrollment.class, TicketID.with(anIn.ticketId()))); - - return GetUpsertEnrollmentOutput.from(upsertEnrollment); - } -} diff --git a/application/src/main/java/br/com/ifsp/tickets/app/administrative/enrollment/upsert/retrieve/IGetUpsertEnrollmentUseCase.java b/application/src/main/java/br/com/ifsp/tickets/app/administrative/enrollment/upsert/retrieve/IGetUpsertEnrollmentUseCase.java deleted file mode 100644 index be4b57f..0000000 --- a/application/src/main/java/br/com/ifsp/tickets/app/administrative/enrollment/upsert/retrieve/IGetUpsertEnrollmentUseCase.java +++ /dev/null @@ -1,6 +0,0 @@ -package br.com.ifsp.tickets.app.administrative.enrollment.upsert.retrieve; - -import br.com.ifsp.tickets.app.IUseCase; - -public interface IGetUpsertEnrollmentUseCase extends IUseCase { -} diff --git a/application/src/main/java/br/com/ifsp/tickets/app/administrative/ticket/retrieve/get/GetTicketByIDUseCase.java b/application/src/main/java/br/com/ifsp/tickets/app/administrative/ticket/retrieve/get/GetTicketByIDUseCase.java index 4377654..60d4764 100644 --- a/application/src/main/java/br/com/ifsp/tickets/app/administrative/ticket/retrieve/get/GetTicketByIDUseCase.java +++ b/application/src/main/java/br/com/ifsp/tickets/app/administrative/ticket/retrieve/get/GetTicketByIDUseCase.java @@ -1,6 +1,7 @@ package br.com.ifsp.tickets.app.administrative.ticket.retrieve.get; import br.com.ifsp.tickets.app.administrative.ticket.retrieve.TicketOutput; +import br.com.ifsp.tickets.domain.administrative.enrollment.Enrollment; import br.com.ifsp.tickets.domain.administrative.event.Event; import br.com.ifsp.tickets.domain.administrative.event.IEventGateway; import br.com.ifsp.tickets.domain.shared.exceptions.IllegalResourceAccessException; @@ -25,7 +26,8 @@ public TicketOutput execute(GetTicketInput anIn) { final User user = anIn.user(); final TicketID ticketID = TicketID.with(anIn.ticketID()); final Ticket ticket = this.ticketGateway.findById(ticketID).orElseThrow(() -> NotFoundException.with(Ticket.class, ticketID)); - final boolean isUserTicket = ticket.getUserID().isPresent() ? ticket.getUserID().get().equals(user.getId()) : ticket.getDocument().equalsIgnoreCase(user.getDocument().getValue()); + final Enrollment enrollment = ticket.getEnrollment(); + final boolean isUserTicket = enrollment.getUserID().isPresent() ? enrollment.getUserID().get().equals(user.getId()) : enrollment.getDocument().equalsIgnoreCase(user.getDocument().getValue()); if (isUserTicket || user.canManageAnyTicket()) return TicketOutput.from(ticket); diff --git a/application/src/main/java/br/com/ifsp/tickets/app/financial/payment/handle/HandlePaymentOutput.java b/application/src/main/java/br/com/ifsp/tickets/app/financial/payment/handle/HandlePaymentOutput.java index 6d913f0..b0374cd 100644 --- a/application/src/main/java/br/com/ifsp/tickets/app/financial/payment/handle/HandlePaymentOutput.java +++ b/application/src/main/java/br/com/ifsp/tickets/app/financial/payment/handle/HandlePaymentOutput.java @@ -7,10 +7,10 @@ public record HandlePaymentOutput( String id, LocalDateTime paymentDate, - String externalReference + String externalId ) { public static HandlePaymentOutput from(Payment payment) { - return new HandlePaymentOutput(payment.getId().toString(), payment.getPaymentDate(), payment.getAction(), payment.getExternalReference()); + return new HandlePaymentOutput(payment.getId().toString(), payment.getApprovalDate(), payment.getExternalId()); } } diff --git a/domain/src/main/java/br/com/ifsp/tickets/domain/administrative/enrollment/upsert/IUpsertEnrollmentGateway.java b/domain/src/main/java/br/com/ifsp/tickets/domain/administrative/enrollment/upsert/IUpsertEnrollmentGateway.java deleted file mode 100644 index 155ceb7..0000000 --- a/domain/src/main/java/br/com/ifsp/tickets/domain/administrative/enrollment/upsert/IUpsertEnrollmentGateway.java +++ /dev/null @@ -1,9 +0,0 @@ -package br.com.ifsp.tickets.domain.administrative.enrollment.upsert; - - -import java.util.Optional; - -public interface IUpsertEnrollmentGateway { - UpsertEnrollment create(UpsertEnrollment enrollment); - Optional getByTicketId(String ticketId); -} diff --git a/domain/src/main/java/br/com/ifsp/tickets/domain/administrative/enrollment/upsert/UpsertEnrollment.java b/domain/src/main/java/br/com/ifsp/tickets/domain/administrative/enrollment/upsert/UpsertEnrollment.java deleted file mode 100644 index 0564da7..0000000 --- a/domain/src/main/java/br/com/ifsp/tickets/domain/administrative/enrollment/upsert/UpsertEnrollment.java +++ /dev/null @@ -1,49 +0,0 @@ -package br.com.ifsp.tickets.domain.administrative.enrollment.upsert; - -import br.com.ifsp.tickets.domain.administrative.event.EventID; -import br.com.ifsp.tickets.domain.financial.product.TicketSaleID; -import br.com.ifsp.tickets.domain.shared.Entity; -import br.com.ifsp.tickets.domain.shared.validation.IValidationHandler; -import br.com.ifsp.tickets.domain.administrative.ticket.TicketID; -import br.com.ifsp.tickets.domain.administrative.user.UserID; -import lombok.Getter; - -import java.time.LocalDate; - -@Getter -public class UpsertEnrollment extends Entity { - private final UserID userID; - private final String name; - private final String email; - private final String document; - private final LocalDate birthDate; - private final EventID eventId; - private final TicketID ticketID; - private final TicketSaleID ticketSaleId; - - - public UpsertEnrollment(UpsertEnrollmentID upsertEnrollmentID, UserID userID, String name, String email, String document, LocalDate birthDate, EventID eventId, TicketID ticketID, TicketSaleID ticketSaleId) { - super(upsertEnrollmentID); - this.userID = userID; - this.name = name; - this.email = email; - this.document = document; - this.birthDate = birthDate; - this.eventId = eventId; - this.ticketID = ticketID; - this.ticketSaleId = ticketSaleId; - } - - public static UpsertEnrollment with(UpsertEnrollmentID enrollmentID, UserID userID, String name, String email, String document, LocalDate birthDate, EventID eventId, TicketSaleID ticketSaleId, TicketID ticketID) { - return new UpsertEnrollment(enrollmentID, userID, name, email, document, birthDate, eventId, ticketID, ticketSaleId); - } - - public static UpsertEnrollment newUpsertEnrollment(String name, String email, String document, LocalDate birthDate, UserID userID, EventID eventID, TicketSaleID ticketSaleId, TicketID ticketID) { - return new UpsertEnrollment(UpsertEnrollmentID.unique(), userID, name, email, document, birthDate, eventID, ticketID, ticketSaleId); - } - - @Override - public void validate(IValidationHandler handler) { - - } -} diff --git a/domain/src/main/java/br/com/ifsp/tickets/domain/administrative/enrollment/upsert/UpsertEnrollmentID.java b/domain/src/main/java/br/com/ifsp/tickets/domain/administrative/enrollment/upsert/UpsertEnrollmentID.java deleted file mode 100644 index 6097913..0000000 --- a/domain/src/main/java/br/com/ifsp/tickets/domain/administrative/enrollment/upsert/UpsertEnrollmentID.java +++ /dev/null @@ -1,47 +0,0 @@ -package br.com.ifsp.tickets.domain.administrative.enrollment.upsert; - -import br.com.ifsp.tickets.domain.shared.Identifier; -import br.com.ifsp.tickets.domain.shared.utils.UUIDUtils; - -import java.util.Objects; -import java.util.UUID; - -public class UpsertEnrollmentID extends Identifier { - private final UUID value; - - public UpsertEnrollmentID(UUID value) { - this.value = value; - } - - public static UpsertEnrollmentID with(String value) { - return new UpsertEnrollmentID(UUIDUtils.getFromString(value)); - } - - public static UpsertEnrollmentID with(UUID value) { - return new UpsertEnrollmentID(value); - } - - public static UpsertEnrollmentID unique() { - return new UpsertEnrollmentID(UUID.randomUUID()); - } - - @Override - public UUID getValue() { - return this.value; - } - - @Override - public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; - - UpsertEnrollmentID that = (UpsertEnrollmentID) o; - - return Objects.equals(value, that.value); - } - - @Override - public int hashCode() { - return value != null ? value.hashCode() : 0; - } -} diff --git a/domain/src/main/java/br/com/ifsp/tickets/domain/financial/payment/Payment.java b/domain/src/main/java/br/com/ifsp/tickets/domain/financial/payment/Payment.java index 654826c..43ae69c 100644 --- a/domain/src/main/java/br/com/ifsp/tickets/domain/financial/payment/Payment.java +++ b/domain/src/main/java/br/com/ifsp/tickets/domain/financial/payment/Payment.java @@ -12,14 +12,14 @@ public class Payment extends AggregateRoot { private final String externalId; - private PaymentStatus status; + private final PaymentStatus status; private final OrderID orderId; private final String currency; private final BigDecimal amount; private final String paymentType; private final LocalDateTime createdAt; - private LocalDateTime updatedAt; - private LocalDateTime approvalDate; + private final LocalDateTime updatedAt; + private final LocalDateTime approvalDate; public Payment(PaymentID id, String externalId, PaymentStatus status, OrderID orderId, String currency, BigDecimal amount, String paymentType, LocalDateTime createdAt, LocalDateTime updatedAt, LocalDateTime approvalDate) { super(id); @@ -42,18 +42,6 @@ public static Payment newPayment(String externalId, PaymentStatus status, OrderI return new Payment(new PaymentID(null), externalId, status, orderId, currency, amount, paymentType, createdAt, updatedAt, approvalDate); } - public void changeStatus(PaymentStatus status) { - if (this.status == status) { - return; - } - this.status = status; - this.updatedAt = LocalDateTime.now(); - - if (status == PaymentStatus.APPROVED) { - this.approvalDate = LocalDateTime.now(); - } - } - @Override public void validate(IValidationHandler handler) { throw new UnsupportedOperationException("Not implemented yet"); diff --git a/infrastructure/src/main/java/br/com/ifsp/tickets/infra/api/BillingAPI.java b/infrastructure/src/main/java/br/com/ifsp/tickets/infra/api/BillingAPI.java new file mode 100644 index 0000000..0285712 --- /dev/null +++ b/infrastructure/src/main/java/br/com/ifsp/tickets/infra/api/BillingAPI.java @@ -0,0 +1,29 @@ +package br.com.ifsp.tickets.infra.api; + +import br.com.ifsp.tickets.infra.contexts.financial.payment.models.PaymentListenerRequest; +import br.com.ifsp.tickets.infra.shared.APIErrorResponse; +import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.media.Content; +import io.swagger.v3.oas.annotations.media.Schema; +import io.swagger.v3.oas.annotations.responses.ApiResponse; +import io.swagger.v3.oas.annotations.tags.Tag; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestMapping; + +@RequestMapping("/v1/billing") +@Tag(name = "Billing", description = "Billing API - manage user's billing") +public interface BillingAPI { + + @PostMapping(consumes = "application/json", value = "/listener") + @Operation( + summary = "Payment", + description = "Receive payment notification", + responses = { + @ApiResponse(responseCode = "201", description = "Notification received successfully"), + @ApiResponse(responseCode = "400", description = "Invalid request", content = @Content(schema = @Schema(implementation = APIErrorResponse.class), mediaType = "application/json")) + } + ) + ResponseEntity listener(PaymentListenerRequest request); + +} diff --git a/infrastructure/src/main/java/br/com/ifsp/tickets/infra/api/EnrollmentAPI.java b/infrastructure/src/main/java/br/com/ifsp/tickets/infra/api/EnrollmentAPI.java index dcd067c..8aa7544 100644 --- a/infrastructure/src/main/java/br/com/ifsp/tickets/infra/api/EnrollmentAPI.java +++ b/infrastructure/src/main/java/br/com/ifsp/tickets/infra/api/EnrollmentAPI.java @@ -3,7 +3,6 @@ import br.com.ifsp.tickets.domain.shared.search.Pagination; import br.com.ifsp.tickets.infra.contexts.administrative.enrollment.core.models.CreateEnrollmentRequest; import br.com.ifsp.tickets.infra.contexts.administrative.enrollment.core.models.EnrollmentResponse; -import br.com.ifsp.tickets.infra.contexts.financial.payment.models.CreatePaymentRequest; import br.com.ifsp.tickets.infra.shared.APIErrorResponse; import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.media.Content; @@ -44,15 +43,4 @@ public interface EnrollmentAPI { ) ResponseEntity> findByUser(); - - @PostMapping(consumes = "application/json", value = "/webhook") - @Operation( - summary = "Payment", - description = "Receive payment webhook", - responses = { - @ApiResponse(responseCode = "201", description = "Webhook received successfully"), - @ApiResponse(responseCode = "400", description = "Invalid request", content = @Content(schema = @Schema(implementation = APIErrorResponse.class), mediaType = "application/json")) - } - ) - ResponseEntity webhook(@RequestBody CreatePaymentRequest request); } diff --git a/infrastructure/src/main/java/br/com/ifsp/tickets/infra/api/OrderAPI.java b/infrastructure/src/main/java/br/com/ifsp/tickets/infra/api/OrderAPI.java new file mode 100644 index 0000000..bf017fe --- /dev/null +++ b/infrastructure/src/main/java/br/com/ifsp/tickets/infra/api/OrderAPI.java @@ -0,0 +1,70 @@ +package br.com.ifsp.tickets.infra.api; + +import br.com.ifsp.tickets.domain.shared.search.Pagination; +import br.com.ifsp.tickets.infra.contexts.financial.order.models.*; +import br.com.ifsp.tickets.infra.shared.APIErrorResponse; +import br.com.ifsp.tickets.infra.shared.search.AdvancedSearchRequest; +import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.media.Content; +import io.swagger.v3.oas.annotations.media.Schema; +import io.swagger.v3.oas.annotations.responses.ApiResponse; +import io.swagger.v3.oas.annotations.tags.Tag; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.*; + +@RequestMapping("/v1/order") +@Tag(name = "Order", description = "Order API - manage user's orders") +public interface OrderAPI { + + @PostMapping(consumes = "application/json", produces = "application/json", value = "/pay") + @Operation( + summary = "Payment", + description = "generate payment url", + responses = { + @ApiResponse(responseCode = "200", description = "Payment url generated successfully"), + @ApiResponse(responseCode = "400", description = "Invalid request", content = @Content(schema = @Schema(implementation = APIErrorResponse.class), mediaType = "application/json")) + } + + ) + ResponseEntity pay(CreateOrderRequest request); + + @PostMapping( + value = "/search", + produces = "application/json", + consumes = "application/json") + @Operation( + summary = "Search orders", + description = "Search orders with advanced filters", + responses = { + @ApiResponse(responseCode = "200", description = "Orders found"), + @ApiResponse(responseCode = "400", description = "Invalid request", content = @Content(schema = @Schema(implementation = APIErrorResponse.class))) + } + ) + ResponseEntity> search(@RequestParam(name = "page", required = false, defaultValue = "0") Integer page, + @RequestParam(name = "perPage", required = false, defaultValue = "10") Integer perPage, + @RequestBody AdvancedSearchRequest request); + + @GetMapping(value = "/{id}", produces = "application/json", consumes = "application/json") + @Operation( + summary = "Get order by id", + description = "Get order information by id", + responses = { + @ApiResponse(responseCode = "200", description = "Order found"), + @ApiResponse(responseCode = "404", description = "Order not found", content = @Content(schema = @Schema(implementation = APIErrorResponse.class))) + } + ) + ResponseEntity get(@PathVariable Long id, @RequestBody(required = false) GetOrderRequest request); + + @PostMapping(value = "/{id}/cancel") + @Operation( + summary = "Cancel order", + description = "Cancel order by id", + responses = { + @ApiResponse(responseCode = "204", description = "Order canceled"), + @ApiResponse(responseCode = "400", description = "Invalid request", content = @Content(schema = @Schema(implementation = APIErrorResponse.class))), + @ApiResponse(responseCode = "404", description = "Order not found", content = @Content(schema = @Schema(implementation = APIErrorResponse.class))) + } + ) + ResponseEntity cancel(@PathVariable Long id, @RequestBody(required = false) CancelOrderRequest request); + +} diff --git a/infrastructure/src/main/java/br/com/ifsp/tickets/infra/api/controllers/BillingController.java b/infrastructure/src/main/java/br/com/ifsp/tickets/infra/api/controllers/BillingController.java new file mode 100644 index 0000000..c56e0e4 --- /dev/null +++ b/infrastructure/src/main/java/br/com/ifsp/tickets/infra/api/controllers/BillingController.java @@ -0,0 +1,48 @@ +package br.com.ifsp.tickets.infra.api.controllers; + +import br.com.ifsp.tickets.app.financial.payment.PaymentService; +import br.com.ifsp.tickets.app.financial.payment.handle.HandlePaymentInput; +import br.com.ifsp.tickets.domain.financial.payment.PaymentStatus; +import br.com.ifsp.tickets.infra.api.BillingAPI; +import br.com.ifsp.tickets.infra.contexts.financial.payment.models.PaymentListenerRequest; +import com.mercadopago.client.payment.PaymentClient; +import com.mercadopago.exceptions.MPApiException; +import com.mercadopago.exceptions.MPException; +import com.mercadopago.resources.payment.Payment; +import lombok.RequiredArgsConstructor; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.RestController; + +@RestController +@RequiredArgsConstructor(onConstructor_ = @__(@Autowired)) +public class BillingController implements BillingAPI { + + private final PaymentService paymentService; + + @Override + public ResponseEntity listener(PaymentListenerRequest request) { + final PaymentClient paymentClient = new PaymentClient(); + final Payment payment; + try { + payment = paymentClient.get(request.data().id()); + } catch (MPException | MPApiException e) { + return ResponseEntity.badRequest().build(); + } + + final HandlePaymentInput input = HandlePaymentInput.of( + payment.getId().toString(), + Long.valueOf(payment.getExternalReference()), + PaymentStatus.valueOf(payment.getStatus().toUpperCase()), + payment.getCurrencyId(), + payment.getTransactionAmount(), + payment.getPaymentTypeId(), + payment.getDateCreated().toLocalDateTime(), + payment.getDateLastUpdated().toLocalDateTime(), + payment.getDateApproved() == null ? null : payment.getDateApproved().toLocalDateTime() + ); + + this.paymentService.handle(input); + return ResponseEntity.ok().build(); + } +} diff --git a/infrastructure/src/main/java/br/com/ifsp/tickets/infra/api/controllers/EnrollmentController.java b/infrastructure/src/main/java/br/com/ifsp/tickets/infra/api/controllers/EnrollmentController.java index d2bc0cc..a6447e8 100644 --- a/infrastructure/src/main/java/br/com/ifsp/tickets/infra/api/controllers/EnrollmentController.java +++ b/infrastructure/src/main/java/br/com/ifsp/tickets/infra/api/controllers/EnrollmentController.java @@ -3,20 +3,12 @@ import br.com.ifsp.tickets.app.administrative.enrollment.EnrollmentService; import br.com.ifsp.tickets.app.administrative.enrollment.core.create.CreateEnrollmentInput; import br.com.ifsp.tickets.app.administrative.enrollment.core.create.CreateEnrollmentOutput; -import br.com.ifsp.tickets.app.financial.payment.PaymentService; -import br.com.ifsp.tickets.app.financial.payment.handle.HandlePaymentInput; -import br.com.ifsp.tickets.domain.financial.payment.PaymentStatus; import br.com.ifsp.tickets.domain.shared.search.Pagination; import br.com.ifsp.tickets.infra.api.EnrollmentAPI; import br.com.ifsp.tickets.infra.contexts.administrative.enrollment.core.models.CreateEnrollmentRequest; import br.com.ifsp.tickets.infra.contexts.administrative.enrollment.core.models.EnrollmentResponse; import br.com.ifsp.tickets.infra.contexts.administrative.enrollment.core.presenters.EnrollmentApiPresenter; import br.com.ifsp.tickets.infra.contexts.administrative.user.persistence.UserJpaEntity; -import br.com.ifsp.tickets.infra.contexts.financial.payment.models.CreatePaymentRequest; -import com.mercadopago.client.payment.PaymentClient; -import com.mercadopago.exceptions.MPApiException; -import com.mercadopago.exceptions.MPException; -import com.mercadopago.resources.payment.Payment; import lombok.RequiredArgsConstructor; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.ResponseEntity; @@ -30,7 +22,6 @@ public class EnrollmentController implements EnrollmentAPI { private final EnrollmentService enrollmentService; - private final PaymentService paymentService; @Override public ResponseEntity create(CreateEnrollmentRequest request) { @@ -42,8 +33,7 @@ public ResponseEntity create(CreateEnrollmentRequest request) { request.document(), request.birthDate(), request.eventId(), - request.ticketSaleId(), - request.ticketId() + request.ticketSaleId() ); final CreateEnrollmentOutput out = this.enrollmentService.create(input); @@ -57,29 +47,4 @@ public ResponseEntity> findByUser() { return ResponseEntity.ok(enrollments); } - @Override - public ResponseEntity webhook(CreatePaymentRequest request) { - final PaymentClient paymentClient = new PaymentClient(); - final Payment payment; - try { - payment = paymentClient.get(request.data().id()); - } catch (MPException | MPApiException e) { - return ResponseEntity.badRequest().build(); - } - - final HandlePaymentInput input = HandlePaymentInput.of( - payment.getId().toString(), - Long.valueOf(payment.getExternalReference()), - PaymentStatus.valueOf(payment.getStatus().toUpperCase()), - payment.getCurrencyId(), - payment.getTransactionAmount(), - payment.getPaymentTypeId(), - payment.getDateCreated().toLocalDateTime(), - payment.getDateLastUpdated().toLocalDateTime(), - payment.getDateApproved() == null ? null : payment.getDateApproved().toLocalDateTime() - ); - - this.paymentService.handle(input); - return ResponseEntity.ok().build(); - } } diff --git a/infrastructure/src/main/java/br/com/ifsp/tickets/infra/api/controllers/OrderController.java b/infrastructure/src/main/java/br/com/ifsp/tickets/infra/api/controllers/OrderController.java new file mode 100644 index 0000000..dea5e44 --- /dev/null +++ b/infrastructure/src/main/java/br/com/ifsp/tickets/infra/api/controllers/OrderController.java @@ -0,0 +1,98 @@ +package br.com.ifsp.tickets.infra.api.controllers; + +import br.com.ifsp.tickets.app.financial.order.OrderService; +import br.com.ifsp.tickets.app.financial.order.cancel.CancelOrderInput; +import br.com.ifsp.tickets.app.financial.order.create.CreateOrderInput; +import br.com.ifsp.tickets.app.financial.order.create.CreateOrderOutput; +import br.com.ifsp.tickets.app.financial.order.retrieve.OrderOutput; +import br.com.ifsp.tickets.app.financial.order.retrieve.get.GetOrderByIDInput; +import br.com.ifsp.tickets.app.financial.order.retrieve.list.ListCustomerOrdersInput; +import br.com.ifsp.tickets.domain.administrative.user.User; +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.utils.UUIDUtils; +import br.com.ifsp.tickets.infra.api.OrderAPI; +import br.com.ifsp.tickets.infra.contexts.administrative.user.persistence.UserJpaEntity; +import br.com.ifsp.tickets.infra.contexts.financial.order.models.*; +import br.com.ifsp.tickets.infra.contexts.financial.order.presenters.OrderApiPresenter; +import br.com.ifsp.tickets.infra.shared.search.AdvancedSearchRequest; +import br.com.ifsp.tickets.infra.shared.search.SearchFilterRequest; +import br.com.ifsp.tickets.infra.shared.search.SortSearchRequest; +import lombok.RequiredArgsConstructor; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.http.ResponseEntity; +import org.springframework.security.core.context.SecurityContextHolder; +import org.springframework.web.bind.annotation.RestController; + +@RestController +@RequiredArgsConstructor(onConstructor_ = @__(@Autowired)) +public class OrderController implements OrderAPI { + + private final OrderService orderService; + + @Override + public ResponseEntity pay(CreateOrderRequest request) { + final Object principal = SecurityContextHolder.getContext().getAuthentication().getPrincipal(); + final User user = principal == null ? null : ((UserJpaEntity) principal).toAggregate(); + final CreateOrderInput input = CreateOrderInput.of( + user, + request.name(), + request.email(), + request.phone(), + request.document(), + request.birthDate(), + request.items().stream().map(i -> CreateOrderInput.OrderItemInput.of(UUIDUtils.getFromString(i.ticketSaleId()))).toList() + ); + + final CreateOrderOutput order = this.orderService.createOrder(input); + return ResponseEntity.ok(OrderApiPresenter.present(order)); + } + + @Override + public ResponseEntity> search(Integer page, Integer perPage, AdvancedSearchRequest request) { + final User user = ((UserJpaEntity) SecurityContextHolder.getContext().getAuthentication().getPrincipal()).toAggregate(); + final AdvancedSearchQuery advancedSearchQuery = AdvancedSearchQuery.of( + page, + perPage, + request.sorts().stream().map(SortSearchRequest::toSortSearch).toList(), + request.filters().stream().map(SearchFilterRequest::toSearchFilter).toList() + ); + + final ListCustomerOrdersInput input = ListCustomerOrdersInput.of(user, advancedSearchQuery); + final Pagination pagination = this.orderService.listCustomerOrders(input).map(OrderApiPresenter::present); + + return ResponseEntity.ok(pagination); + } + + @Override + public ResponseEntity get(Long id, GetOrderRequest request) { + final Object principal = SecurityContextHolder.getContext().getAuthentication().getPrincipal(); + final User user = principal == null ? null : ((UserJpaEntity) principal).toAggregate(); + final String document = request == null ? null : request.document(); + + final GetOrderByIDInput input = GetOrderByIDInput.of( + user, + document, + id + ); + + final OrderOutput output = this.orderService.getOrderByID(input); + return ResponseEntity.ok(OrderApiPresenter.present(output)); + } + + @Override + public ResponseEntity cancel(Long id, CancelOrderRequest request) { + final Object principal = SecurityContextHolder.getContext().getAuthentication().getPrincipal(); + final User user = principal == null ? null : ((UserJpaEntity) principal).toAggregate(); + final String document = request == null ? null : request.document(); + final CancelOrderInput input = CancelOrderInput.of( + user, + document, + id + ); + + this.orderService.cancelOrder(input); + + return ResponseEntity.noContent().build(); + } +} diff --git a/infrastructure/src/main/java/br/com/ifsp/tickets/infra/config/app/EnrollmentConfig.java b/infrastructure/src/main/java/br/com/ifsp/tickets/infra/config/app/EnrollmentConfig.java index 3b72e85..3dd494a 100644 --- a/infrastructure/src/main/java/br/com/ifsp/tickets/infra/config/app/EnrollmentConfig.java +++ b/infrastructure/src/main/java/br/com/ifsp/tickets/infra/config/app/EnrollmentConfig.java @@ -4,15 +4,14 @@ import br.com.ifsp.tickets.app.administrative.enrollment.EnrollmentService; import br.com.ifsp.tickets.app.administrative.enrollment.EnrollmentServiceFactory; import br.com.ifsp.tickets.app.administrative.enrollment.ITicketQRGenerator; -import br.com.ifsp.tickets.domain.communication.email.IEmailGateway; -import br.com.ifsp.tickets.domain.communication.message.IMessageGateway; import br.com.ifsp.tickets.domain.administrative.company.ICompanyGateway; import br.com.ifsp.tickets.domain.administrative.enrollment.IEnrollmentGateway; -import br.com.ifsp.tickets.domain.administrative.enrollment.upsert.IUpsertEnrollmentGateway; import br.com.ifsp.tickets.domain.administrative.event.IEventGateway; +import br.com.ifsp.tickets.domain.administrative.ticket.ITicketGateway; +import br.com.ifsp.tickets.domain.communication.email.IEmailGateway; +import br.com.ifsp.tickets.domain.communication.message.IMessageGateway; import br.com.ifsp.tickets.domain.financial.product.ITicketSaleGateway; import br.com.ifsp.tickets.domain.shared.file.IFileStorage; -import br.com.ifsp.tickets.domain.administrative.ticket.ITicketGateway; import lombok.RequiredArgsConstructor; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.Bean; @@ -26,7 +25,6 @@ public class EnrollmentConfig { private final IMessageGateway messageGateway; private final IEventGateway eventGateway; private final IEnrollmentGateway enrollmentGateway; - private final IUpsertEnrollmentGateway upsertEnrollmentGateway; private final ITicketGateway ticketGateway; private final ICompanyGateway companyGateway; private final IFileStorage fileProvider; @@ -35,6 +33,6 @@ public class EnrollmentConfig { @Bean public EnrollmentService enrollmentService() { - return EnrollmentServiceFactory.create(emailGateway, messageGateway, eventGateway, enrollmentGateway, ticketGateway, companyGateway, fileProvider, ticketQRGenerator, ticketSaleGateway, upsertEnrollmentGateway); + return EnrollmentServiceFactory.create(emailGateway, messageGateway, eventGateway, enrollmentGateway, ticketGateway, companyGateway, fileProvider, ticketQRGenerator, ticketSaleGateway); } } diff --git a/infrastructure/src/main/java/br/com/ifsp/tickets/infra/config/app/EventConfig.java b/infrastructure/src/main/java/br/com/ifsp/tickets/infra/config/app/EventConfig.java index 3ca2f4d..0bc9302 100644 --- a/infrastructure/src/main/java/br/com/ifsp/tickets/infra/config/app/EventConfig.java +++ b/infrastructure/src/main/java/br/com/ifsp/tickets/infra/config/app/EventConfig.java @@ -4,7 +4,6 @@ import br.com.ifsp.tickets.app.administrative.event.EventServiceFactory; import br.com.ifsp.tickets.domain.administrative.company.ICompanyGateway; import br.com.ifsp.tickets.domain.administrative.event.IEventGateway; -import br.com.ifsp.tickets.domain.financial.product.ITicketSaleGateway; import br.com.ifsp.tickets.domain.shared.IDomainEventPublisher; import br.com.ifsp.tickets.domain.shared.file.IFileStorage; import lombok.RequiredArgsConstructor; @@ -18,12 +17,11 @@ public class EventConfig { private final ICompanyGateway companyGateway; private final IEventGateway eventGateway; - private final ITicketSaleGateway ticketSaleGateway; private final IFileStorage fileStorage; private final IDomainEventPublisher eventPublisher; @Bean public EventService eventService() { - return EventServiceFactory.create(companyGateway, eventGateway, ticketSaleGateway, fileStorage, eventPublisher); + return EventServiceFactory.create(companyGateway, eventGateway, fileStorage, eventPublisher); } } diff --git a/infrastructure/src/main/java/br/com/ifsp/tickets/infra/config/app/OrderConfig.java b/infrastructure/src/main/java/br/com/ifsp/tickets/infra/config/app/OrderConfig.java new file mode 100644 index 0000000..8ee4a9b --- /dev/null +++ b/infrastructure/src/main/java/br/com/ifsp/tickets/infra/config/app/OrderConfig.java @@ -0,0 +1,32 @@ +package br.com.ifsp.tickets.infra.config.app; + +import br.com.ifsp.tickets.app.financial.order.OrderService; +import br.com.ifsp.tickets.app.financial.order.OrderServiceFactory; +import br.com.ifsp.tickets.domain.administrative.event.IEventGateway; +import br.com.ifsp.tickets.domain.financial.order.IOrderGateway; +import br.com.ifsp.tickets.domain.financial.order.IPaymentURLGenerator; +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 OrderConfig { + + private final IPaymentURLGenerator paymentURLGenerator; + private final IOrderGateway orderGateway; + private final IEventGateway eventGateway; + private final ITicketSaleGateway ticketSaleGateway; + + @Bean + public OrderService orderService() { + return OrderServiceFactory.create( + paymentURLGenerator, + eventGateway, + orderGateway, + ticketSaleGateway + ); + } +} diff --git a/infrastructure/src/main/java/br/com/ifsp/tickets/infra/config/app/PaymentConfig.java b/infrastructure/src/main/java/br/com/ifsp/tickets/infra/config/app/PaymentConfig.java index cd487c5..de16ecd 100644 --- a/infrastructure/src/main/java/br/com/ifsp/tickets/infra/config/app/PaymentConfig.java +++ b/infrastructure/src/main/java/br/com/ifsp/tickets/infra/config/app/PaymentConfig.java @@ -1,8 +1,18 @@ package br.com.ifsp.tickets.infra.config.app; +import br.com.ifsp.tickets.app.administrative.enrollment.ITicketQRGenerator; import br.com.ifsp.tickets.app.financial.payment.PaymentService; import br.com.ifsp.tickets.app.financial.payment.PaymentServiceFactory; +import br.com.ifsp.tickets.domain.administrative.company.ICompanyGateway; +import br.com.ifsp.tickets.domain.administrative.enrollment.IEnrollmentGateway; +import br.com.ifsp.tickets.domain.administrative.event.IEventGateway; +import br.com.ifsp.tickets.domain.administrative.ticket.ITicketGateway; +import br.com.ifsp.tickets.domain.communication.email.IEmailGateway; +import br.com.ifsp.tickets.domain.communication.message.IMessageGateway; +import br.com.ifsp.tickets.domain.financial.order.IOrderGateway; import br.com.ifsp.tickets.domain.financial.payment.IPaymentGateway; +import br.com.ifsp.tickets.domain.shared.IDomainEventPublisher; +import br.com.ifsp.tickets.domain.shared.file.IFileStorage; import lombok.RequiredArgsConstructor; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.Bean; @@ -13,9 +23,31 @@ public class PaymentConfig { private final IPaymentGateway paymentGateway; + private final IOrderGateway orderGateway; + private final IEventGateway eventGateway; + private final IEmailGateway emailGateway; + private final ICompanyGateway companyGateway; + private final IEnrollmentGateway enrollmentGateway; + private final IMessageGateway messageGateway; + private final ITicketGateway ticketGateway; + private final ITicketQRGenerator ticketQRGenerator; + private final IDomainEventPublisher eventPublisher; + private final IFileStorage fileStorage; @Bean public PaymentService paymentService() { - return PaymentServiceFactory.create(paymentGateway); + return PaymentServiceFactory.create( + paymentGateway, + orderGateway, + eventGateway, + ticketGateway, + companyGateway, + emailGateway, + enrollmentGateway, + messageGateway, + fileStorage, + ticketQRGenerator, + eventPublisher + ); } } diff --git a/infrastructure/src/main/java/br/com/ifsp/tickets/infra/contexts/administrative/enrollment/core/models/CreateEnrollmentRequest.java b/infrastructure/src/main/java/br/com/ifsp/tickets/infra/contexts/administrative/enrollment/core/models/CreateEnrollmentRequest.java index 48022f1..6974fb2 100644 --- a/infrastructure/src/main/java/br/com/ifsp/tickets/infra/contexts/administrative/enrollment/core/models/CreateEnrollmentRequest.java +++ b/infrastructure/src/main/java/br/com/ifsp/tickets/infra/contexts/administrative/enrollment/core/models/CreateEnrollmentRequest.java @@ -10,8 +10,6 @@ public record CreateEnrollmentRequest( @JsonProperty("email") String email, @JsonProperty("document") String document, @JsonProperty("birth_date") LocalDate birthDate, - @JsonProperty("ticket_sale_id") String ticketSaleId, - @JsonProperty("ticket_id") String ticketId - + @JsonProperty("ticket_sale_id") String ticketSaleId ) { } diff --git a/infrastructure/src/main/java/br/com/ifsp/tickets/infra/contexts/administrative/enrollment/upsert/UpsertEnrollmentGateway.java b/infrastructure/src/main/java/br/com/ifsp/tickets/infra/contexts/administrative/enrollment/upsert/UpsertEnrollmentGateway.java deleted file mode 100644 index f1da921..0000000 --- a/infrastructure/src/main/java/br/com/ifsp/tickets/infra/contexts/administrative/enrollment/upsert/UpsertEnrollmentGateway.java +++ /dev/null @@ -1,28 +0,0 @@ -package br.com.ifsp.tickets.infra.contexts.administrative.enrollment.upsert; - -import br.com.ifsp.tickets.domain.administrative.enrollment.upsert.IUpsertEnrollmentGateway; -import br.com.ifsp.tickets.domain.administrative.enrollment.upsert.UpsertEnrollment; -import br.com.ifsp.tickets.infra.contexts.administrative.enrollment.upsert.persistence.UpsertEnrollmentJpaEntity; -import br.com.ifsp.tickets.infra.contexts.administrative.enrollment.upsert.persistence.UpsertEnrollmentRepository; -import lombok.RequiredArgsConstructor; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Component; - -import java.util.Optional; -import java.util.UUID; - -@Component -@RequiredArgsConstructor(onConstructor_ = @__(@Autowired)) -public class UpsertEnrollmentGateway implements IUpsertEnrollmentGateway { - private final UpsertEnrollmentRepository enrollmentRepository; - - @Override - public UpsertEnrollment create(UpsertEnrollment enrollment) { - return this.enrollmentRepository.save(UpsertEnrollmentJpaEntity.from(enrollment)).toAggregate(); - } - - @Override - public Optional getByTicketId(String ticketId) { - return this.enrollmentRepository.findByTicketID(UUID.fromString(ticketId)).map(UpsertEnrollmentJpaEntity::toAggregate); - } -} diff --git a/infrastructure/src/main/java/br/com/ifsp/tickets/infra/contexts/administrative/enrollment/upsert/models/CreateUpsertEnrollmentRequest.java b/infrastructure/src/main/java/br/com/ifsp/tickets/infra/contexts/administrative/enrollment/upsert/models/CreateUpsertEnrollmentRequest.java deleted file mode 100644 index bd98ee7..0000000 --- a/infrastructure/src/main/java/br/com/ifsp/tickets/infra/contexts/administrative/enrollment/upsert/models/CreateUpsertEnrollmentRequest.java +++ /dev/null @@ -1,15 +0,0 @@ -package br.com.ifsp.tickets.infra.contexts.administrative.enrollment.upsert.models; - -import com.fasterxml.jackson.annotation.JsonProperty; - -import java.time.LocalDate; - -public record CreateUpsertEnrollmentRequest( - @JsonProperty("event_id") String eventId, - @JsonProperty("name") String name, - @JsonProperty("email") String email, - @JsonProperty("document") String document, - @JsonProperty("birth_date") LocalDate birthDate, - @JsonProperty("ticket_sale_id") String ticketSaleId -) { -} diff --git a/infrastructure/src/main/java/br/com/ifsp/tickets/infra/contexts/administrative/enrollment/upsert/persistence/UpsertEnrollmentJpaEntity.java b/infrastructure/src/main/java/br/com/ifsp/tickets/infra/contexts/administrative/enrollment/upsert/persistence/UpsertEnrollmentJpaEntity.java deleted file mode 100644 index ac85e39..0000000 --- a/infrastructure/src/main/java/br/com/ifsp/tickets/infra/contexts/administrative/enrollment/upsert/persistence/UpsertEnrollmentJpaEntity.java +++ /dev/null @@ -1,84 +0,0 @@ -package br.com.ifsp.tickets.infra.contexts.administrative.enrollment.upsert.persistence; - -import br.com.ifsp.tickets.domain.administrative.enrollment.upsert.UpsertEnrollment; -import br.com.ifsp.tickets.domain.administrative.enrollment.upsert.UpsertEnrollmentID; -import br.com.ifsp.tickets.domain.administrative.event.EventID; -import br.com.ifsp.tickets.domain.financial.product.TicketSaleID; -import br.com.ifsp.tickets.domain.administrative.ticket.TicketID; -import br.com.ifsp.tickets.domain.administrative.user.UserID; -import jakarta.persistence.Column; -import jakarta.persistence.Entity; -import jakarta.persistence.Id; -import jakarta.persistence.Table; -import lombok.Getter; -import lombok.NoArgsConstructor; - -import java.io.Serializable; -import java.time.LocalDate; -import java.util.UUID; - -@Entity -@Table(name = "upsert_enrollments") -@NoArgsConstructor -@Getter -public class UpsertEnrollmentJpaEntity implements Serializable { - @Id - @Column(name = "id", nullable = false, unique = true, updatable = false) - private UUID id; - @Column(name = "event_id", nullable = false) - private UUID eventID; - @Column(name = "name", nullable = false) - private String name; - @Column(name = "email", nullable = false) - private String email; - @Column(name = "birth_date", nullable = false) - private LocalDate birthDate; - @Column(name = "document", nullable = false) - private String document; - @Column(name = "ticket_sale_id", nullable = false) - private UUID ticketSaleID; - @Column(name = "ticket_id", nullable = false) - private UUID ticketID; - @Column(name = "user_id") - private UUID userID; - - public UpsertEnrollmentJpaEntity(UUID id, UUID eventID, String name, String email, LocalDate birthDate, String document, UUID ticketSaleID, UUID ticketID, UUID userID) { - this.id = id; - this.eventID = eventID; - this.name = name; - this.email = email; - this.birthDate = birthDate; - this.document = document; - this.ticketSaleID = ticketSaleID; - this.ticketID = ticketID; - this.userID = userID; - } - - public static UpsertEnrollmentJpaEntity from(UpsertEnrollment enrollment){ - return new UpsertEnrollmentJpaEntity( - enrollment.getId().getValue(), - enrollment.getEventId().getValue(), - enrollment.getName(), - enrollment.getEmail(), - enrollment.getBirthDate(), - enrollment.getDocument(), - enrollment.getTicketSaleId().getValue(), - enrollment.getTicketID().getValue(), - enrollment.getUserID().getValue() - ); - } - - public UpsertEnrollment toAggregate(){ - return new UpsertEnrollment( - UpsertEnrollmentID.with(this.getId()), - UserID.with(this.getUserID()), - this.getName(), - this.getEmail(), - this.getDocument(), - this.getBirthDate(), - EventID.with(this.getEventID()), - TicketID.with(this.getTicketID()), - TicketSaleID.with(this.getTicketSaleID()) - ); - } -} diff --git a/infrastructure/src/main/java/br/com/ifsp/tickets/infra/contexts/administrative/enrollment/upsert/persistence/UpsertEnrollmentRepository.java b/infrastructure/src/main/java/br/com/ifsp/tickets/infra/contexts/administrative/enrollment/upsert/persistence/UpsertEnrollmentRepository.java deleted file mode 100644 index db05161..0000000 --- a/infrastructure/src/main/java/br/com/ifsp/tickets/infra/contexts/administrative/enrollment/upsert/persistence/UpsertEnrollmentRepository.java +++ /dev/null @@ -1,10 +0,0 @@ -package br.com.ifsp.tickets.infra.contexts.administrative.enrollment.upsert.persistence; - -import org.springframework.data.jpa.repository.JpaRepository; - -import java.util.Optional; -import java.util.UUID; - -public interface UpsertEnrollmentRepository extends JpaRepository { - Optional findByTicketID(UUID uuid); -} diff --git a/infrastructure/src/main/java/br/com/ifsp/tickets/infra/contexts/financial/order/models/CancelOrderRequest.java b/infrastructure/src/main/java/br/com/ifsp/tickets/infra/contexts/financial/order/models/CancelOrderRequest.java new file mode 100644 index 0000000..b24fbf1 --- /dev/null +++ b/infrastructure/src/main/java/br/com/ifsp/tickets/infra/contexts/financial/order/models/CancelOrderRequest.java @@ -0,0 +1,9 @@ +package br.com.ifsp.tickets.infra.contexts.financial.order.models; + +import com.fasterxml.jackson.annotation.JsonProperty; + +public record CancelOrderRequest( + @JsonProperty("document") + String document +) { +} diff --git a/infrastructure/src/main/java/br/com/ifsp/tickets/infra/contexts/financial/order/models/CreateOrderRequest.java b/infrastructure/src/main/java/br/com/ifsp/tickets/infra/contexts/financial/order/models/CreateOrderRequest.java new file mode 100644 index 0000000..99ee6b1 --- /dev/null +++ b/infrastructure/src/main/java/br/com/ifsp/tickets/infra/contexts/financial/order/models/CreateOrderRequest.java @@ -0,0 +1,24 @@ +package br.com.ifsp.tickets.infra.contexts.financial.order.models; + +import com.fasterxml.jackson.annotation.JsonProperty; + +import java.time.LocalDate; +import java.util.List; + +public record CreateOrderRequest( + @JsonProperty("event_id") String eventId, + @JsonProperty("name") String name, + @JsonProperty("email") String email, + @JsonProperty("phone") String phone, + @JsonProperty("document") String document, + @JsonProperty("birth_date") LocalDate birthDate, + @JsonProperty("items") List items +) { + + public record OrderItemRequest( + @JsonProperty("ticket_sale_id") + String ticketSaleId + ) { + + } +} diff --git a/infrastructure/src/main/java/br/com/ifsp/tickets/infra/contexts/financial/order/models/CreateOrderResponse.java b/infrastructure/src/main/java/br/com/ifsp/tickets/infra/contexts/financial/order/models/CreateOrderResponse.java new file mode 100644 index 0000000..e55ef9d --- /dev/null +++ b/infrastructure/src/main/java/br/com/ifsp/tickets/infra/contexts/financial/order/models/CreateOrderResponse.java @@ -0,0 +1,11 @@ +package br.com.ifsp.tickets.infra.contexts.financial.order.models; + +import com.fasterxml.jackson.annotation.JsonProperty; + +public record CreateOrderResponse( + @JsonProperty("id") + String id, + @JsonProperty("payment_url") + String paymentUrl +) { +} diff --git a/infrastructure/src/main/java/br/com/ifsp/tickets/infra/contexts/financial/order/models/GetOrderRequest.java b/infrastructure/src/main/java/br/com/ifsp/tickets/infra/contexts/financial/order/models/GetOrderRequest.java new file mode 100644 index 0000000..771d301 --- /dev/null +++ b/infrastructure/src/main/java/br/com/ifsp/tickets/infra/contexts/financial/order/models/GetOrderRequest.java @@ -0,0 +1,9 @@ +package br.com.ifsp.tickets.infra.contexts.financial.order.models; + +import com.fasterxml.jackson.annotation.JsonProperty; + +public record GetOrderRequest( + @JsonProperty("document") + String document +) { +} diff --git a/infrastructure/src/main/java/br/com/ifsp/tickets/infra/contexts/financial/order/models/OrderItemResponse.java b/infrastructure/src/main/java/br/com/ifsp/tickets/infra/contexts/financial/order/models/OrderItemResponse.java new file mode 100644 index 0000000..49f35eb --- /dev/null +++ b/infrastructure/src/main/java/br/com/ifsp/tickets/infra/contexts/financial/order/models/OrderItemResponse.java @@ -0,0 +1,18 @@ +package br.com.ifsp.tickets.infra.contexts.financial.order.models; + +import br.com.ifsp.tickets.infra.contexts.financial.product.models.TicketSaleResponse; +import com.fasterxml.jackson.annotation.JsonProperty; + +import java.math.BigDecimal; + +public record OrderItemResponse( + @JsonProperty("id") + String id, + @JsonProperty("product") + TicketSaleResponse product, + @JsonProperty("quantity") + Integer quantity, + @JsonProperty("total") + BigDecimal total +) { +} diff --git a/infrastructure/src/main/java/br/com/ifsp/tickets/infra/contexts/financial/order/models/OrderResponse.java b/infrastructure/src/main/java/br/com/ifsp/tickets/infra/contexts/financial/order/models/OrderResponse.java new file mode 100644 index 0000000..fb3cc3d --- /dev/null +++ b/infrastructure/src/main/java/br/com/ifsp/tickets/infra/contexts/financial/order/models/OrderResponse.java @@ -0,0 +1,36 @@ +package br.com.ifsp.tickets.infra.contexts.financial.order.models; + +import br.com.ifsp.tickets.domain.financial.order.OrderStatus; +import com.fasterxml.jackson.annotation.JsonProperty; + +import java.time.LocalDate; +import java.time.LocalDateTime; +import java.util.List; + +public record OrderResponse( + @JsonProperty("id") + Long id, + @JsonProperty("customer_id") + String customerID, + @JsonProperty("name") + String name, + @JsonProperty("document") + String document, + @JsonProperty("email") + String email, + @JsonProperty("phone") + String phone, + @JsonProperty("birth_date") + LocalDate birthDate, + @JsonProperty("payment_url") + String paymentUrl, + @JsonProperty("status") + OrderStatus status, + @JsonProperty("created_at") + LocalDateTime createdAt, + @JsonProperty("updated_at") + LocalDateTime updatedAt, + @JsonProperty("items") + List items +) { +} diff --git a/infrastructure/src/main/java/br/com/ifsp/tickets/infra/contexts/financial/order/presenters/OrderApiPresenter.java b/infrastructure/src/main/java/br/com/ifsp/tickets/infra/contexts/financial/order/presenters/OrderApiPresenter.java new file mode 100644 index 0000000..b666d30 --- /dev/null +++ b/infrastructure/src/main/java/br/com/ifsp/tickets/infra/contexts/financial/order/presenters/OrderApiPresenter.java @@ -0,0 +1,59 @@ +package br.com.ifsp.tickets.infra.contexts.financial.order.presenters; + +import br.com.ifsp.tickets.app.financial.order.create.CreateOrderOutput; +import br.com.ifsp.tickets.app.financial.order.retrieve.OrderItemOutput; +import br.com.ifsp.tickets.app.financial.order.retrieve.OrderOutput; +import br.com.ifsp.tickets.app.financial.product.retrieve.Ticket2SellOutput; +import br.com.ifsp.tickets.infra.contexts.financial.order.models.CreateOrderResponse; +import br.com.ifsp.tickets.infra.contexts.financial.order.models.OrderItemResponse; +import br.com.ifsp.tickets.infra.contexts.financial.order.models.OrderResponse; +import br.com.ifsp.tickets.infra.contexts.financial.product.models.TicketSaleResponse; + +public interface OrderApiPresenter { + + static CreateOrderResponse present(CreateOrderOutput output) { + if (output == null) return null; + return new CreateOrderResponse(output.id(), output.paymentUrl()); + } + + static OrderResponse present(OrderOutput output) { + if (output == null) return null; + return new OrderResponse( + output.id(), + output.customerID(), + output.name(), + output.document(), + output.email(), + output.phone(), + output.birthDate(), + output.paymentUrl(), + output.status(), + output.createdAt(), + output.updatedAt(), + output.items().stream().map(OrderApiPresenter::present).toList() + ); + } + + static OrderItemResponse present(OrderItemOutput output) { + if (output == null) return null; + return new OrderItemResponse( + output.id(), + present(output.product()), + output.quantity(), + output.total() + ); + } + + static TicketSaleResponse present(Ticket2SellOutput output) { + return new TicketSaleResponse( + output.id(), + output.eventId(), + output.name(), + output.description(), + output.price(), + output.entries(), + output.active() + ); + } + +} diff --git a/infrastructure/src/main/java/br/com/ifsp/tickets/infra/contexts/financial/payment/PaymentGateway.java b/infrastructure/src/main/java/br/com/ifsp/tickets/infra/contexts/financial/payment/PaymentGateway.java index 952b419..90c2dd4 100644 --- a/infrastructure/src/main/java/br/com/ifsp/tickets/infra/contexts/financial/payment/PaymentGateway.java +++ b/infrastructure/src/main/java/br/com/ifsp/tickets/infra/contexts/financial/payment/PaymentGateway.java @@ -8,6 +8,8 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; +import java.util.Optional; + @Component @RequiredArgsConstructor(onConstructor_ = @__(@Autowired)) public class PaymentGateway implements IPaymentGateway { @@ -17,4 +19,14 @@ public class PaymentGateway implements IPaymentGateway { public Payment create(Payment payment) { return paymentRepository.save(PaymentJpaEntity.from(payment)).toAggregate(); } + + @Override + public Optional findByExternalId(String externalId) { + return paymentRepository.findByExternalId(externalId).map(PaymentJpaEntity::toAggregate); + } + + @Override + public Payment update(Payment payment) { + return paymentRepository.save(PaymentJpaEntity.from(payment)).toAggregate(); + } } diff --git a/infrastructure/src/main/java/br/com/ifsp/tickets/infra/contexts/financial/payment/models/CreatePaymentRequest.java b/infrastructure/src/main/java/br/com/ifsp/tickets/infra/contexts/financial/payment/models/PaymentListenerRequest.java similarity index 90% rename from infrastructure/src/main/java/br/com/ifsp/tickets/infra/contexts/financial/payment/models/CreatePaymentRequest.java rename to infrastructure/src/main/java/br/com/ifsp/tickets/infra/contexts/financial/payment/models/PaymentListenerRequest.java index 929f0d9..adf0d50 100644 --- a/infrastructure/src/main/java/br/com/ifsp/tickets/infra/contexts/financial/payment/models/CreatePaymentRequest.java +++ b/infrastructure/src/main/java/br/com/ifsp/tickets/infra/contexts/financial/payment/models/PaymentListenerRequest.java @@ -4,7 +4,7 @@ import java.time.LocalDateTime; -public record CreatePaymentRequest( +public record PaymentListenerRequest( @JsonProperty("data") DataModel data, @JsonProperty("date_created") LocalDateTime dateCreated, @JsonProperty("type") String type, diff --git a/infrastructure/src/main/java/br/com/ifsp/tickets/infra/contexts/financial/payment/persistence/PaymentJpaEntity.java b/infrastructure/src/main/java/br/com/ifsp/tickets/infra/contexts/financial/payment/persistence/PaymentJpaEntity.java index dae21df..790f8ff 100644 --- a/infrastructure/src/main/java/br/com/ifsp/tickets/infra/contexts/financial/payment/persistence/PaymentJpaEntity.java +++ b/infrastructure/src/main/java/br/com/ifsp/tickets/infra/contexts/financial/payment/persistence/PaymentJpaEntity.java @@ -1,16 +1,15 @@ package br.com.ifsp.tickets.infra.contexts.financial.payment.persistence; +import br.com.ifsp.tickets.domain.financial.order.OrderID; import br.com.ifsp.tickets.domain.financial.payment.Payment; import br.com.ifsp.tickets.domain.financial.payment.PaymentID; import br.com.ifsp.tickets.domain.financial.payment.PaymentStatus; -import jakarta.persistence.Column; -import jakarta.persistence.Entity; -import jakarta.persistence.Id; -import jakarta.persistence.Table; +import jakarta.persistence.*; import lombok.Getter; import lombok.NoArgsConstructor; import java.io.Serializable; +import java.math.BigDecimal; import java.time.LocalDateTime; @Entity @@ -21,36 +20,79 @@ public class PaymentJpaEntity implements Serializable { @Id @Column(name = "id", nullable = false, unique = true, updatable = false) private Long id; - @Column(name = "payment_date", nullable = false, updatable = false) - private LocalDateTime paymentDate; + @Column(name = "external_id", nullable = false, updatable = false) + private String externalId; @Column(name = "status", nullable = false, updatable = false) - private String status; - @Column(name = "external_reference", nullable = false) - private String externalReference; + @Enumerated(EnumType.STRING) + private PaymentStatus status; + @Column(name = "order_id", nullable = false, updatable = false) + private Long orderId; + @Column(name = "currency", nullable = false, updatable = false) + private String currency; + @Column(name = "amount", nullable = false, updatable = false) + private BigDecimal amount; + @Column(name = "payment_type", nullable = false, updatable = false) + private String paymentType; + @Column(name = "created_at", nullable = false, updatable = false) + private LocalDateTime createdAt; + @Column(name = "updated_at", nullable = false, updatable = false) + private LocalDateTime updatedAt; + @Column(name = "approval_date", nullable = false, updatable = false) + private LocalDateTime approvalDate; - public PaymentJpaEntity(Long id, LocalDateTime paymentDate, String status, String externalReference) { + public PaymentJpaEntity( + Long id, + String externalId, + PaymentStatus status, + Long orderId, + String currency, + BigDecimal amount, + String paymentType, + LocalDateTime createdAt, + LocalDateTime updatedAt, + LocalDateTime approvalDate + ) { this.id = id; - this.paymentDate = paymentDate; + this.externalId = externalId; this.status = status; - this.externalReference = externalReference; + this.orderId = orderId; + this.currency = currency; + this.amount = amount; + this.paymentType = paymentType; + this.createdAt = createdAt; + this.updatedAt = updatedAt; + this.approvalDate = approvalDate; } public static PaymentJpaEntity from(Payment payment) { return new PaymentJpaEntity( payment.getId().getValue(), - payment.getPaymentDate(), - payment.getAction(), - payment.getExternalReference() + payment.getExternalId(), + payment.getStatus(), + payment.getOrderId().getValue(), + payment.getCurrency(), + payment.getAmount(), + payment.getPaymentType(), + payment.getCreatedAt(), + payment.getUpdatedAt(), + payment.getApprovalDate() ); } public Payment toAggregate() { return new Payment( - PaymentID.with(this.getId()), - PaymentStatus.IN_PROCESS, - this.getPaymentDate(), - this.getStatus(), - this.getExternalReference() + new PaymentID(this.id), + this.externalId, + this.status, + new OrderID(this.orderId), + this.currency, + this.amount, + this.paymentType, + this.createdAt, + this.updatedAt, + this.approvalDate ); } + + } diff --git a/infrastructure/src/main/java/br/com/ifsp/tickets/infra/contexts/financial/payment/persistence/PaymentRepository.java b/infrastructure/src/main/java/br/com/ifsp/tickets/infra/contexts/financial/payment/persistence/PaymentRepository.java index 311ad8b..f74da65 100644 --- a/infrastructure/src/main/java/br/com/ifsp/tickets/infra/contexts/financial/payment/persistence/PaymentRepository.java +++ b/infrastructure/src/main/java/br/com/ifsp/tickets/infra/contexts/financial/payment/persistence/PaymentRepository.java @@ -2,6 +2,10 @@ import org.springframework.data.jpa.repository.JpaRepository; +import java.util.Optional; + public interface PaymentRepository extends JpaRepository { + + Optional findByExternalId(String externalId); } diff --git a/infrastructure/src/main/java/br/com/ifsp/tickets/infra/contexts/financial/product/persistence/TicketSaleJpaEntity.java b/infrastructure/src/main/java/br/com/ifsp/tickets/infra/contexts/financial/product/persistence/TicketSaleJpaEntity.java index 99b8c6b..e4ddfa0 100644 --- a/infrastructure/src/main/java/br/com/ifsp/tickets/infra/contexts/financial/product/persistence/TicketSaleJpaEntity.java +++ b/infrastructure/src/main/java/br/com/ifsp/tickets/infra/contexts/financial/product/persistence/TicketSaleJpaEntity.java @@ -30,17 +30,20 @@ public class TicketSaleJpaEntity implements Serializable { private String description; // example: válido para uma pessoa e uma criança de até 12 anos @Column(name = "price", nullable = false) private BigDecimal price; // example: 20.00 + @Column(name = "stock", nullable = false) + private int stock; @Column(name = "entries", nullable = false) private int entries; // example: 2 @Column(name = "active", nullable = false) private boolean active; - public TicketSaleJpaEntity(UUID id, UUID eventID, String name, String description, BigDecimal price, int entries, boolean active) { + public TicketSaleJpaEntity(UUID id, UUID eventID, String name, String description, BigDecimal price, int stock, int entries, boolean active) { this.id = id; this.eventId = eventID; this.name = name; this.description = description; this.price = price; + this.stock = stock; this.entries = entries; this.active = active; } @@ -52,9 +55,9 @@ public static TicketSaleJpaEntity from(TicketSale ticketSale) { ticketSale.getName(), ticketSale.getDescription(), ticketSale.getPrice(), + ticketSale.getStock(), ticketSale.getEntries(), - ticketSale.isActive() - ); + ticketSale.isActive()); } public TicketSale toAggregate() { @@ -63,7 +66,8 @@ public TicketSale toAggregate() { EventID.with(this.getEventId()), this.getName(), this.getDescription(), - this.getPrice(), , + this.getPrice(), + this.getStock(), this.getEntries(), this.isActive()); }