-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
6acae06
commit 4199b90
Showing
45 changed files
with
777 additions
and
137 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...llment/create/CreateEnrollmentOutput.java → ...t/core/create/CreateEnrollmentOutput.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...ment/create/ICreateEnrollmentUseCase.java → ...core/create/ICreateEnrollmentUseCase.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...enrollment/retrieve/EnrollmentOutput.java → ...lment/core/retrieve/EnrollmentOutput.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 2 additions & 2 deletions
4
...e/list/IListEnrollmentsByUserUseCase.java → ...e/list/IListEnrollmentsByUserUseCase.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 2 additions & 2 deletions
4
...ve/list/ListEnrollmentsByUserUseCase.java → ...ve/list/ListEnrollmentsByUserUseCase.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 22 additions & 0 deletions
22
...in/java/br/com/ifsp/tickets/app/enrollment/upsert/create/CreateUpsertEnrollmentInput.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package br.com.ifsp.tickets.app.enrollment.upsert.create; | ||
|
||
import br.com.ifsp.tickets.domain.ticket.TicketID; | ||
import br.com.ifsp.tickets.domain.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); | ||
} | ||
} |
109 changes: 109 additions & 0 deletions
109
...br/com/ifsp/tickets/app/enrollment/upsert/create/CreateUpsertUpsertEnrollmentUseCase.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
package br.com.ifsp.tickets.app.enrollment.upsert.create; | ||
|
||
import br.com.ifsp.tickets.app.enrollment.ITicketQRGenerator; | ||
import br.com.ifsp.tickets.app.enrollment.core.create.CreateEnrollmentOutput; | ||
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.company.Company; | ||
import br.com.ifsp.tickets.domain.company.ICompanyGateway; | ||
import br.com.ifsp.tickets.domain.enrollment.Enrollment; | ||
import br.com.ifsp.tickets.domain.enrollment.IEnrollmentGateway; | ||
import br.com.ifsp.tickets.domain.enrollment.upsert.IUpsertEnrollmentGateway; | ||
import br.com.ifsp.tickets.domain.enrollment.upsert.UpsertEnrollment; | ||
import br.com.ifsp.tickets.domain.event.Event; | ||
import br.com.ifsp.tickets.domain.event.EventID; | ||
import br.com.ifsp.tickets.domain.event.EventStatus; | ||
import br.com.ifsp.tickets.domain.event.IEventGateway; | ||
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.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.ticket.ITicketGateway; | ||
import br.com.ifsp.tickets.domain.ticket.Ticket; | ||
import br.com.ifsp.tickets.domain.ticket.TicketID; | ||
import br.com.ifsp.tickets.domain.user.User; | ||
import br.com.ifsp.tickets.domain.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").throwPossibleErrors(); | ||
|
||
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").throwPossibleErrors(); | ||
} | ||
final UserID userID = user != null ? user.getId() : new UserID(null); | ||
|
||
|
||
final UpsertEnrollment enrollment = UpsertEnrollment | ||
.newUpsertEnrollment(name, emailString, document, birthDate, userID, eventID, ticketSaleID, ticketID); | ||
|
||
final Message message = this.messageGateway.findBySubjectAndType(MessageSubject.PAYMENT_EMAIL, MessageType.HTML).orElseThrow(() -> NotFoundException.with("Email template not found")); | ||
final Notification notification = Notification.create(); | ||
enrollment.validate(notification); | ||
notification.throwPossibleErrors(); | ||
final UpsertEnrollment createdEnrollment = this.upsertEnrollmentGateway.create(enrollment); | ||
|
||
final Email email = Email.createDynamic(emailString, message, name, company.getName(), preference); | ||
email.validate(notification); | ||
notification.throwPossibleErrors(); | ||
final Email createdEmail = this.emailGateway.create(email); | ||
|
||
return createdEnrollment.getId().getValue().toString(); | ||
} | ||
} |
6 changes: 6 additions & 0 deletions
6
...java/br/com/ifsp/tickets/app/enrollment/upsert/create/ICreateUpsertEnrollmentUseCase.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
package br.com.ifsp.tickets.app.enrollment.upsert.create; | ||
|
||
import br.com.ifsp.tickets.app.IUseCase; | ||
|
||
public interface ICreateUpsertEnrollmentUseCase extends IUseCase<CreateUpsertEnrollmentInput, String> { | ||
} |
6 changes: 6 additions & 0 deletions
6
...ain/java/br/com/ifsp/tickets/app/enrollment/upsert/retrieve/GetUpsertEnrollmentInput.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
package br.com.ifsp.tickets.app.enrollment.upsert.retrieve; | ||
|
||
public record GetUpsertEnrollmentInput ( | ||
String ticketId | ||
){ | ||
} |
36 changes: 36 additions & 0 deletions
36
...in/java/br/com/ifsp/tickets/app/enrollment/upsert/retrieve/GetUpsertEnrollmentOutput.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package br.com.ifsp.tickets.app.enrollment.upsert.retrieve; | ||
|
||
import br.com.ifsp.tickets.domain.enrollment.EnrollmentStatus; | ||
import br.com.ifsp.tickets.domain.enrollment.upsert.UpsertEnrollment; | ||
import br.com.ifsp.tickets.domain.event.EventID; | ||
import br.com.ifsp.tickets.domain.event.sale.TicketSaleID; | ||
import br.com.ifsp.tickets.domain.ticket.TicketID; | ||
import br.com.ifsp.tickets.domain.user.UserID; | ||
|
||
import java.time.LocalDate; | ||
import java.time.LocalDateTime; | ||
|
||
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() | ||
); | ||
} | ||
} |
Oops, something went wrong.