Skip to content

Commit

Permalink
fix: UserId on create enrollment
Browse files Browse the repository at this point in the history
  • Loading branch information
gustavofg1pontes committed Oct 7, 2024
1 parent 72137b9 commit 22004a0
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import java.time.LocalDate;

public record CreateEnrollmentInput(
User user,
String userId,
String name,
String email,
String document,
Expand All @@ -14,7 +14,7 @@ public record CreateEnrollmentInput(
String ticketSaleId,
String ticketId
) {
public static CreateEnrollmentInput of(User aggregate, String name, String email, String document, LocalDate birthDate, String eventId, String ticketSaleId, String ticketId) {
return new CreateEnrollmentInput(aggregate, 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, String ticketId) {
return new CreateEnrollmentInput(userId, name, email, document, birthDate, eventId, ticketSaleId, ticketId);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public CreateEnrollmentUseCase(IEventGateway eventGateway, IEnrollmentGateway en

@Override
public CreateEnrollmentOutput execute(CreateEnrollmentInput anIn) {
final User user = anIn.user();
final UserID userID = UserID.with(anIn.userId());
String name = anIn.name();
String emailString = anIn.email();
LocalDate birthDate = anIn.birthDate();
Expand All @@ -71,18 +71,11 @@ public CreateEnrollmentOutput execute(CreateEnrollmentInput anIn) {
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);
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 Enrollment enrollment = Enrollment
.newEnrollment(name, emailString, document, birthDate,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public class EnrollmentController implements EnrollmentAPI {
public ResponseEntity<String> create(CreateEnrollmentRequest request) {
final UserJpaEntity authenticatedUser = (UserJpaEntity) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
final CreateEnrollmentInput input = CreateEnrollmentInput.of(
authenticatedUser.toAggregate(),
authenticatedUser.toAggregate().getId().getValue().toString(),
request.name(),
request.email(),
request.document(),
Expand Down Expand Up @@ -96,7 +96,7 @@ public ResponseEntity<Void> webhook(CreatePaymentRequest request) {

GetUpsertEnrollmentOutput output = this.enrollmentService.getUpsertEnrollment(in);
final CreateEnrollmentInput input = CreateEnrollmentInput.of(
null,
output.userID(),
output.name(),
output.email(),
output.document(),
Expand Down

0 comments on commit 22004a0

Please sign in to comment.