Giter VIP home page Giter VIP logo

vaporcleanarchitecture-swift's Introduction

vaporcleanarchitecture-swift's People

Contributors

mukeshydv avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

vaporcleanarchitecture-swift's Issues

Confusion with ProductRequest with Validatable vs, CreateProductUseCase

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.

Response with array of models

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?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.