From 31da3b8e2a439140fdcf90ba6e999b6fa315330d Mon Sep 17 00:00:00 2001 From: gustavofg1pontes Date: Mon, 7 Oct 2024 20:49:09 -0300 Subject: [PATCH] ExistsByEmailAndEventId --- .../app/enrollment/core/create/CreateEnrollmentUseCase.java | 2 +- .../ifsp/tickets/domain/enrollment/IEnrollmentGateway.java | 1 + .../infra/contexts/enrollment/core/EnrollmentGateway.java | 5 +++++ .../enrollment/core/persistence/EnrollmentRepository.java | 1 + 4 files changed, 8 insertions(+), 1 deletion(-) diff --git a/application/src/main/java/br/com/ifsp/tickets/app/enrollment/core/create/CreateEnrollmentUseCase.java b/application/src/main/java/br/com/ifsp/tickets/app/enrollment/core/create/CreateEnrollmentUseCase.java index a659e78..3453446 100644 --- a/application/src/main/java/br/com/ifsp/tickets/app/enrollment/core/create/CreateEnrollmentUseCase.java +++ b/application/src/main/java/br/com/ifsp/tickets/app/enrollment/core/create/CreateEnrollmentUseCase.java @@ -71,7 +71,7 @@ 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(); - alreadyExists = this.enrollmentGateway.existsByDocumentAndEventID(document, eventID); + alreadyExists = this.enrollmentGateway.existsByEmailAndEventID(emailString, eventID); System.out.println(alreadyExists); if (alreadyExists) { Notification.create("Validation Error").append("User already enrolled in this event").throwPossibleErrors(); diff --git a/domain/src/main/java/br/com/ifsp/tickets/domain/enrollment/IEnrollmentGateway.java b/domain/src/main/java/br/com/ifsp/tickets/domain/enrollment/IEnrollmentGateway.java index 6523656..d60a768 100644 --- a/domain/src/main/java/br/com/ifsp/tickets/domain/enrollment/IEnrollmentGateway.java +++ b/domain/src/main/java/br/com/ifsp/tickets/domain/enrollment/IEnrollmentGateway.java @@ -21,6 +21,7 @@ public interface IEnrollmentGateway { boolean existsByUserIDAndEventID(UserID userID, EventID eventID); boolean existsByDocumentAndEventID(String document, EventID eventID); + boolean existsByEmailAndEventID(String document, EventID eventID); Enrollment update(Enrollment enrollment); diff --git a/infrastructure/src/main/java/br/com/ifsp/tickets/infra/contexts/enrollment/core/EnrollmentGateway.java b/infrastructure/src/main/java/br/com/ifsp/tickets/infra/contexts/enrollment/core/EnrollmentGateway.java index 8fb5d83..60bbe00 100644 --- a/infrastructure/src/main/java/br/com/ifsp/tickets/infra/contexts/enrollment/core/EnrollmentGateway.java +++ b/infrastructure/src/main/java/br/com/ifsp/tickets/infra/contexts/enrollment/core/EnrollmentGateway.java @@ -85,6 +85,11 @@ public boolean existsByDocumentAndEventID(String document, EventID eventID) { return this.enrollmentRepository.existsByDocumentAndEventID(document, eventID.getValue()); } + @Override + public boolean existsByEmailAndEventID(String document, EventID eventID) { + return this.enrollmentRepository.existsByEmailAndEventID(document, eventID.getValue()); + } + @Override public Enrollment update(Enrollment enrollment) { return this.enrollmentRepository.save(EnrollmentJpaEntity.from(enrollment)).toAggregate(); diff --git a/infrastructure/src/main/java/br/com/ifsp/tickets/infra/contexts/enrollment/core/persistence/EnrollmentRepository.java b/infrastructure/src/main/java/br/com/ifsp/tickets/infra/contexts/enrollment/core/persistence/EnrollmentRepository.java index efafe11..fe9d3c0 100644 --- a/infrastructure/src/main/java/br/com/ifsp/tickets/infra/contexts/enrollment/core/persistence/EnrollmentRepository.java +++ b/infrastructure/src/main/java/br/com/ifsp/tickets/infra/contexts/enrollment/core/persistence/EnrollmentRepository.java @@ -15,4 +15,5 @@ public interface EnrollmentRepository extends JpaRepository findByUserIDAndEventID(UUID userID, UUID eventID); boolean existsByUserIDAndEventID(UUID userID, UUID eventID); boolean existsByDocumentAndEventID(String document, UUID eventID); + boolean existsByEmailAndEventID(String email, UUID eventID); }