- ๐ Hi, Iโm Mukesh Yadav
- ๐ซ [email protected]
mukeshydv / vaporcleanarchitecture-swift Goto Github PK
View Code? Open in Web Editor NEWAn example of using Clean Architecture in Vapor swift server.
An example of using Clean Architecture in Vapor swift server.
Hello.
I had a question regarding why we are using both the Validatable
protocol that Vapor provides and the CreateProductUseCase
? From my understanding, in clean architecture, a use case lives in the domain layer that contains the business rules of the application. When reviewing CreateProductUseCase
, it first checks that the price of the product entity is greater than zero before it saves it to the repository. So the price of a product being greater than zero is a business rule that is part of the domain layer. Now in the App directory (which is the application layer), there is ProductRequest
. This object conforms to Validatable
and has the same business rule for the price of a product being greater than zero as well as another rule for the description of the product not being empty. In ProductController
, under the addProduct
method, try ProductRequest.validate(content: request)
is called before the use case is called. For clean architecture, shouldn't the validation being done in the use case since the validation contains business rules? Now I understand that in the Domain layer, we don't want to add external dependencies. So if we wanted to move the validations into the use case and leverage Validatable
, we would have to add Vapor
as a dependency for the Domain
package. But we could also consider maybe not having a use case since it seems to be a pass through and use try ProductRequest.validate(content: request)
and then call the repository. But I mainly want to understand the reasoning why we need a use case as it looks like we are duplicating validation code in both ProductRequest
and CreateProductUseCase
for checking if the price is greater than zero.
I was wondering how can the extension AnyUseCase can be changed to support a response with an array of models.
As of right now the AnyUseCase extension support only single objects, as expressed here...
extension AnyUseCase where Response: ResponseConvertible {
func executeResponse(from request: Vapor.Request, body: Request) -> EventLoopFuture<BaseResponse<Response.Response>> {
let response = try await execute(request: eventLoopRequest(body, eventLoop: request.eventLoop))
.map { BaseResponse(status: 200, message: "Success", data: $0.toResponse) }
}
}
But when you try to get an array of models when calling the executeReponse from a UseCase, this doesn't work since it expects a single model to be returned.
Do you have any ideas on how to do this?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.