I'm working on a project with the task of creating a route to checkout ticket purchases for events. In this scenario, I have a controller that receives the request with order data, client information, tickets, and payment details. Subsequently, I pass this request to my use cases to perform the tasks.
However, I have a use case where I create an Order, which is an entity, and I need another use case to receive the Order to validate the tickets using the Tickets entity. Later, if the validation is successful, the Order is passed to the payment use case, creating the Transaction entity. All of this is done in the same controller, somewhat like in the code below:
export class CheckoutController implements Controller {
constructor(
private createOrder: CreateOrder,
private makeTicketValidate: MakeTicketValidate,
private makePayment: MakePayment,
){}
async handle (request: CheckoutController.Request): Promise<HttpResponse> {
const order: Order = this.createOrder(request)
// Here i receive the Order entity and step to the next use case
const isValid: boolean = await this.makeTicketValidate(order)
if(!isValid) {
return badRequest()
}
const transactionId = await this.makePayment(order)
if(!transactionId) {
return internalServerError()
}
return ok({transactionId})
}
}
Is passing the Order entity through the controller from one use case to another a code smell?
Thank you in advance to everyone who responded!
I've been considering using a data access object for the 'orders' entity to transfer data between the use cases.
Alternatively, I could separate the controllers to divide the responsibilities.