Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Usecase as step #89

Open
jhomarolo opened this issue Jan 2, 2023 · 2 comments
Open

Usecase as step #89

jhomarolo opened this issue Jan 2, 2023 · 2 comments
Labels
enhancement New feature or request

Comments

@jhomarolo
Copy link
Contributor

Is your feature request related to a problem? Please describe.
Today, it is very common to nest usecases to resolve a complete application flow.

When we call one usecase inside another, we end up calling it as a method and not natively as a usecase step.

This functionality will help to have a cleaner code, more metadata about the use of nested use cases, in addition to opening up possibilities to have an even richer audit trail

@jhomarolo jhomarolo added the enhancement New feature or request label Jan 2, 2023
@dalssoft
Copy link
Member

dalssoft commented Jan 2, 2023

Suggested code:

    'Save the User': usecaseStep(saveUser, {
        
        user: (ctx) => ctx.user,  // optional, with the default value of ctx.user
        
        request: (ctx) => ({
            // optional, with the default values comming from the context
            // - read all the request metadata from the use case
            // - try to find the expected fields in the context
            // or, in case of a custom request, you can define the request as below
            name: ctx..name1,
            email: ctx.email2,
            password: ctx.password3,
        }),

        response: (ret) => ({
            // optional, with the default value of ret
            // once the use case is executed, the response is returned
            // and merged with the context
            // for example, the user id can be returned and used in the next step
            userId: ret.id,
            // this is the same as:
            // ctx.saveUser.userId = ret.id
            // I think it is important to have a isolation variable with the name of the use case (saveUser)
        }),
    }),

I'm still not sure if the function name usecaseStep is the best name, but I think it is a good start.

@jhomarolo
Copy link
Contributor Author

jhomarolo commented Jan 3, 2023

I believe that a use case can be passed as a variable, so I agree with your sugestion

And also a basic validation to check if that ucStep is in fact a valid usecase.

@jhomarolo jhomarolo moved this to More discussion is needed in Herbs enterprise roadmap 2023 Jan 6, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
Status: More discussion is needed
Development

No branches or pull requests

2 participants