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

@ScaffoldContoller and @ScaffoldService support #114

Closed
wants to merge 5 commits into from

Conversation

codeconsole
Copy link
Contributor

@codeconsole codeconsole commented Aug 30, 2024

Adds support for the annotation@ScaffoldController which provides an alternative to the static scaffold = Domain approach.

@ScaffoldController(domain = User)
class UserController {}

It also empowers the developer to use their own base controller instead of being forced to use RestController which could be very limiting. RestController does not encapsulate all necessary business logic and is completely divergent from the Service MVC model that is generated by this plugin. With this annotation, developers can now use an extended RestController to fit their needs, or create an entirely different generic controller that is not related at all to RestController and more closely matches the type of controller that is generated by this plugin.

@ScaffoldController(GenericAsyncController)
class UserController {
    static scaffold = User
}
@ScaffoldController(value = SecuredGenericController, domain = User)
class UserController {}

@matrei
Copy link
Contributor

matrei commented Aug 30, 2024

As this is a new feature, I think it should probably go into 5.1.x or 6.0.x, not 5.0.x.

@codeconsole Do you want this functionality to be available in Grails 6?
Then we should create a 5.1.x branch.
Otherwise we should create a 6.0.x branch and also make it ready for Grails 7.

@matrei
Copy link
Contributor

matrei commented Aug 30, 2024

I see there are no tests in this repo.

There are some tests in https://github.com/grails/grails-functional-tests that tests scaffolding with the usage of static scaffold = Foo.

We could add tests there for using the @ScaffoldController annotation as well.
(But it would be nicer to have tests in this repo)

@codeconsole
Copy link
Contributor Author

codeconsole commented Aug 31, 2024

As this is a new feature, I think it should probably go into 5.1.x or 6.0.x, not 5.0.x.

@codeconsole Do you want this functionality to be available in Grails 6? Then we should create a 5.1.x branch. Otherwise we should create a 6.0.x branch and also make it ready for Grails 7.

yes, I would like it in 6.2. I agree 5.1.x

@matrei
Copy link
Contributor

matrei commented Aug 31, 2024

@codeconsole I have created a 5.1.x branch with pending PR to update the build and workflows.

@codeconsole
Copy link
Contributor Author

codeconsole commented Sep 2, 2024

@codeconsole I have created a 5.1.x branch with pending PR to update the build and workflows.

I don't think a new branch is warranted. No breaking features have been introduced. We shouldn't be maintaining point release branches. I don't know why we got rid of master. If there is to be a branch, it should be 5.x

@codeconsole
Copy link
Contributor Author

Introduced support for more concise annotations:

@ScaffoldController(value = SecuredGenericController, domain = User)
class UserController {}

can now be written as this

@ScaffoldController(SecuredGenericController<User>)
class UserController {}

@codeconsole codeconsole changed the title @ScaffoldContoller support @ScaffoldContoller and @ScaffoldService support Sep 2, 2024
@codeconsole
Copy link
Contributor Author

codeconsole commented Sep 2, 2024

Introduce @ScaffoldService support

It is very powerful if you have common business logic shared across multiple or all services and use a service layer. It works similar to how scaffold controllers work. You have a super class that you define (such are RestfulContoller for scaffold controllers) and then any Services with the annotation get that super class injected.

For example, let's create a GenericService that automatically updates Redis and ElasticSearch:

class GenericService<T> {

    T get(Long id) {
        // generic get logic
    }

    List<T> list(Map args) {
        // generic list logic
    }

    Long count(Map args) {
        // generic count logic.  (My implementation takes a map so counts can be done based on parameters)
    }

    void delete(Long id) {
        // generic delete logic
    }

    T save(T domain) {
        // generic save logic
    }
}

Now all I have to do is have define a Service with the annotation and all those methods become implemented. Unlike @Service, I can override individual methods and call super

@ScaffoldService(GenericService<User>)
class UserService {

    User save(User user) {
         user.modified = new Date()
         super.save(user)
    }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants