Skip to content

Commit

Permalink
fix: remove ticket payment_status
Browse files Browse the repository at this point in the history
  • Loading branch information
gustavofg1pontes committed Oct 7, 2024
1 parent 22004a0 commit d040abd
Show file tree
Hide file tree
Showing 12 changed files with 8 additions and 81 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,17 @@

import br.com.ifsp.tickets.app.ticket.check.CheckTicketInput;
import br.com.ifsp.tickets.app.ticket.check.ICheckTicketUseCase;
import br.com.ifsp.tickets.app.ticket.payment.CheckPaymentInput;
import br.com.ifsp.tickets.app.ticket.payment.ICheckPaymentUseCase;
import br.com.ifsp.tickets.app.ticket.retrieve.get.GetTicketInput;
import br.com.ifsp.tickets.app.ticket.retrieve.get.IGetTicketByIDUseCase;
import br.com.ifsp.tickets.app.ticket.retrieve.get.TicketOutput;

public class TicketService {
private final ICheckTicketUseCase checkTicketUseCase;
private final IGetTicketByIDUseCase getTicketByIDUseCase;
private final ICheckPaymentUseCase checkPaymentUseCase;

public TicketService(ICheckTicketUseCase checkTicketUseCase, IGetTicketByIDUseCase getTicketByIDUseCase, ICheckPaymentUseCase checkPaymentUseCase) {
public TicketService(ICheckTicketUseCase checkTicketUseCase, IGetTicketByIDUseCase getTicketByIDUseCase) {
this.checkTicketUseCase = checkTicketUseCase;
this.getTicketByIDUseCase = getTicketByIDUseCase;
this.checkPaymentUseCase = checkPaymentUseCase;
}

public void checkTicket(CheckTicketInput input) {
Expand All @@ -27,7 +23,4 @@ public TicketOutput getTicket(GetTicketInput input) {
return this.getTicketByIDUseCase.execute(input);
}

public void changePaymentStatus(CheckPaymentInput input) {
this.checkPaymentUseCase.execute(input);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

import br.com.ifsp.tickets.app.ticket.check.CheckTicketUseCase;
import br.com.ifsp.tickets.app.ticket.check.ICheckTicketUseCase;
import br.com.ifsp.tickets.app.ticket.payment.CheckPaymentUseCase;
import br.com.ifsp.tickets.app.ticket.payment.ICheckPaymentUseCase;
import br.com.ifsp.tickets.app.ticket.retrieve.get.GetTicketByIDUseCase;
import br.com.ifsp.tickets.app.ticket.retrieve.get.IGetTicketByIDUseCase;
import br.com.ifsp.tickets.domain.event.IEventGateway;
Expand All @@ -19,8 +17,7 @@ public static TicketService create(
if (ticketService == null) {
final ICheckTicketUseCase checkTicketUseCase = new CheckTicketUseCase(ticketGateway, eventGateway);
final IGetTicketByIDUseCase getTicketByIDUseCase = new GetTicketByIDUseCase(ticketGateway, eventGateway);
final ICheckPaymentUseCase checkPaymentUseCase = new CheckPaymentUseCase(ticketGateway);
ticketService = new TicketService(checkTicketUseCase, getTicketByIDUseCase, checkPaymentUseCase);
ticketService = new TicketService(checkTicketUseCase, getTicketByIDUseCase);
}
return ticketService;
}
Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,4 @@ public interface ITicketGateway {
void delete(Ticket id);

boolean exists(TicketID id);

void checkPayment(TicketID id, PaymentStatus paymentStatus);
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,10 @@ public class Ticket extends Entity<TicketID> {
private final LocalDate expiredIn;
private final LocalDateTime createdAt;
private TicketStatus status;
private PaymentStatus paymentStatus; // TODO - atualizar conforme webhook
private TicketCode code;
private LocalDateTime lastTimeConsumed;

public Ticket(TicketID ticketID, String document, EventID eventID, TicketSaleID ticketSaleID, String description, TicketStatus status, PaymentStatus paymentStatus, TicketCode code, LocalDate validIn, LocalDate expiredIn, LocalDateTime createdAt, LocalDateTime lastTimeConsumed, UserID userID) {
public Ticket(TicketID ticketID, String document, EventID eventID, TicketSaleID ticketSaleID, String description, TicketStatus status, TicketCode code, LocalDate validIn, LocalDate expiredIn, LocalDateTime createdAt, LocalDateTime lastTimeConsumed, UserID userID) {
super(ticketID);
this.userID = userID;
this.document = document;
Expand All @@ -48,19 +47,18 @@ public Ticket(TicketID ticketID, String document, EventID eventID, TicketSaleID
this.expiredIn = expiredIn;
this.createdAt = createdAt;
this.lastTimeConsumed = lastTimeConsumed;
this.paymentStatus = paymentStatus;
}

public static Ticket with(TicketID ticketID, String document, EventID eventID, TicketSaleID ticketSaleID, String description, TicketStatus status, PaymentStatus paymentStatus, TicketCode code, LocalDate validIn, LocalDate expiredIn, LocalDateTime createdAt, LocalDateTime lastTimeConsumed, UserID userID) {
return new Ticket(ticketID, document, eventID, ticketSaleID, description, status, paymentStatus, code, validIn, expiredIn, createdAt, lastTimeConsumed, userID);
public static Ticket with(TicketID ticketID, String document, EventID eventID, TicketSaleID ticketSaleID, String description, TicketStatus status, TicketCode code, LocalDate validIn, LocalDate expiredIn, LocalDateTime createdAt, LocalDateTime lastTimeConsumed, UserID userID) {
return new Ticket(ticketID, document, eventID, ticketSaleID, description, status, code, validIn, expiredIn, createdAt, lastTimeConsumed, userID);
}

public static Ticket newTicket(UserID userID, String document, Event event, TicketSale ticketSale, String description, LocalDate validIn, LocalDate expiredIn) {
return new Ticket(TicketID.unique(), document, event.getId(), ticketSale.getId(), description, TicketStatus.AVAILABLE, PaymentStatus.IN_PROCESS, TicketCode.generate(), validIn, expiredIn, LocalDateTime.now(ZoneId.of("GMT-3")), null, userID);
return new Ticket(TicketID.unique(), document, event.getId(), ticketSale.getId(), description, TicketStatus.AVAILABLE, TicketCode.generate(), validIn, expiredIn, LocalDateTime.now(ZoneId.of("GMT-3")), null, userID);
}

public static Ticket newTicketWithId(TicketID ticketID, UserID userID, String document, Event event, TicketSale ticketSale, String description, LocalDate validIn, LocalDate expiredIn) {
return new Ticket(ticketID, document, event.getId(), ticketSale.getId(), description, TicketStatus.AVAILABLE, PaymentStatus.IN_PROCESS, TicketCode.generate(), validIn, expiredIn, LocalDateTime.now(ZoneId.of("GMT-3")), null, userID);
return new Ticket(ticketID, document, event.getId(), ticketSale.getId(), description, TicketStatus.AVAILABLE, TicketCode.generate(), validIn, expiredIn, LocalDateTime.now(ZoneId.of("GMT-3")), null, userID);
}

public Optional<UserID> getUserID() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,6 @@ public void validate() {
if(ticket.getEventID() == null)
error("Event ID is required");

if(ticket.getPaymentStatus() == null)
error("Payment Status is required");

if (ticket.getStatus() == null)
error("Status is required");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +89,7 @@ public ResponseEntity<String> createUpsertEnrollment(CreateUpsertEnrollmentReque

@Override
public ResponseEntity<Void> webhook(CreatePaymentRequest request) {
System.out.println(request.data().id());
PaymentOutput p = this.paymentService.getPayment(request.data().id());
System.out.println(p.externalReference());
GetUpsertEnrollmentInput in = new GetUpsertEnrollmentInput(p.externalReference());

GetUpsertEnrollmentOutput output = this.enrollmentService.getUpsertEnrollment(in);
Expand All @@ -106,7 +104,6 @@ public ResponseEntity<Void> webhook(CreatePaymentRequest request) {
output.ticketID()
);
CreateEnrollmentOutput out = this.enrollmentService.create(input);
System.out.println(out);
return ResponseEntity.created(URI.create("/v1/enrollment/" + out.enrollmentId())).build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -92,9 +92,4 @@ public void delete(Ticket id) {
public boolean exists(TicketID id) {
return this.repository.existsById(id.getValue());
}

@Override
public void checkPayment(TicketID id, PaymentStatus paymentStatus) {
this.repository.updatePaymentStatusById(id, paymentStatus);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,6 @@ public class TicketJpaEntity implements Serializable {
private String description;
@Column(name = "status", nullable = false)
private String status;
@Column(name = "payment_status", nullable = false)
private String paymentStatus;
@Column(name = "code", nullable = false)
private String code;
@Column(name = "valid_in", nullable = false)
Expand All @@ -55,14 +53,13 @@ public class TicketJpaEntity implements Serializable {
@Column(name = "last_time_consumed")
private LocalDateTime lastTimeConsumed;

public TicketJpaEntity(UUID id, String document, UUID userId, UUID eventId, UUID ticketSaleId, String description, String status, String paymentStatus, String code, LocalDate validIn, LocalDate expiredIn, LocalDateTime createdAt, LocalDateTime lastTimeConsumed) {
public TicketJpaEntity(UUID id, String document, UUID userId, UUID eventId, UUID ticketSaleId, String description, String status, String code, LocalDate validIn, LocalDate expiredIn, LocalDateTime createdAt, LocalDateTime lastTimeConsumed) {
this.id = id;
this.document = EncryptionService.encrypt(document);
this.userId = userId;
this.ticketSaleId = ticketSaleId;
this.description = description;
this.status = status;
this.paymentStatus = paymentStatus;
this.code = code;
this.eventId = eventId;
this.validIn = validIn;
Expand All @@ -80,7 +77,6 @@ public static TicketJpaEntity from(Ticket ticket) {
ticket.getTicketSaleID().getValue(),
ticket.getDescription(),
ticket.getStatus().name(),
ticket.getPaymentStatus().name(),
ticket.getCode().getCode(),
ticket.getValidIn(),
ticket.getExpiredIn(),
Expand All @@ -97,7 +93,6 @@ public Ticket toAggregate() {
TicketSaleID.with(this.ticketSaleId),
this.description,
TicketStatus.valueOf(this.status),
PaymentStatus.valueOf(this.paymentStatus),
new TicketCode(this.code),
this.validIn,
this.expiredIn,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,8 @@
package br.com.ifsp.tickets.infra.contexts.ticket.persistence;

import br.com.ifsp.tickets.domain.ticket.TicketID;
import br.com.ifsp.tickets.domain.ticket.payment.PaymentStatus;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

import java.util.Optional;
import java.util.UUID;
Expand All @@ -16,8 +11,4 @@ public interface TicketRepository extends JpaRepository<TicketJpaEntity, UUID> {
Optional<TicketJpaEntity> findByCodeAndExpiredInBefore(String code, java.util.Date date);
Page<TicketJpaEntity> findAllByUserId(UUID userId, Pageable pageable);
Page<TicketJpaEntity> findAllByUserIdAndEventId(UUID userId, UUID eventId, Pageable pageable);

@Modifying
@Query("UPDATE TicketJpaEntity p SET p.paymentStatus = :status WHERE p.id = :id")
void updatePaymentStatusById(@Param("id") TicketID id, @Param("status") PaymentStatus status);
}

0 comments on commit d040abd

Please sign in to comment.