# NAME

Mojolicious::Plugin::Fondation::Group - Group management plugin for Fondation

# VERSION

version 0.03

# SYNOPSIS

    # myapp.conf
    {
        'Fondation' => {
            dependencies => [
                'Fondation::User',
                'Fondation::Group',
            ],
        },
    }

# DESCRIPTION

[Mojolicious::Plugin::Fondation::Group](https://metacpan.org/pod/Mojolicious%3A%3APlugin%3A%3AFondation%3A%3AGroup) provides group management:
the `groups` and `user_group` (pivot) tables, REST controllers,
and automatic many-to-many relations with users and permissions.

## Many-to-many relations

When [Fondation::User](https://metacpan.org/pod/Fondation%3A%3AUser) is loaded, group↔user links are established
automatically in `fondation_finalyze` via
[DBIx::Class::Relationship::ManyToMany::Async](https://metacpan.org/pod/DBIx%3A%3AClass%3A%3ARelationship%3A%3AManyToMany%3A%3AAsync).

Similarly, when [Fondation::Perm](https://metacpan.org/pod/Fondation%3A%3APerm) is loaded, group↔perm links are
created in that plugin's `fondation_finalyze`.

## with() — many\_to\_many prefetch

    # Include perms (or users) in list/read responses
    GET /api/Group?with=perms
    GET /api/User?with=groups

    # Programmatically:
    $c->model('group')->with('perms')->TO_JSON->then(sub ($data) {
        $self->render(openapi => $data);
    });
    $c->model('user')->with('groups')->TO_JSON->then(sub ($data) {
        $self->render(openapi => $data);
    });

`with()` triggers a single-query prefetch via the pivot table.
Target objects are auto-included in the `TO_JSON` output by
[Mojolicious::Plugin::Fondation::Schema::Result::Base](https://metacpan.org/pod/Mojolicious%3A%3APlugin%3A%3AFondation%3A%3ASchema%3A%3AResult%3A%3ABase).

Without `with()`, m2m relationships are silently excluded.

## Controller

REST endpoints (routes generated by OpenAPI):

    GET    /api/Group           list all groups
    POST   /api/Group           create a group
    GET    /api/Group/:id       read a group
    PUT    /api/Group/:id       update a group
    DELETE /api/Group/:id       delete a group

    GET    /api/Group/:id/members      list members
    POST   /api/Group/:id/members      add a member
    DELETE /api/Group/:id/members/:uid remove a member

# SEE ALSO

- [Mojolicious::Plugin::Fondation::User](https://metacpan.org/pod/Mojolicious%3A%3APlugin%3A%3AFondation%3A%3AUser)
- [Mojolicious::Plugin::Fondation::Perm](https://metacpan.org/pod/Mojolicious%3A%3APlugin%3A%3AFondation%3A%3APerm)
- [DBIx::Class::Relationship::ManyToMany::Async](https://metacpan.org/pod/DBIx%3A%3AClass%3A%3ARelationship%3A%3AManyToMany%3A%3AAsync)
- [Mojolicious::Plugin::Fondation::Schema::Result::Base](https://metacpan.org/pod/Mojolicious%3A%3APlugin%3A%3AFondation%3A%3ASchema%3A%3AResult%3A%3ABase)

# AUTHOR

Daniel Brosseau <dab@cpan.org>

# COPYRIGHT AND LICENSE

This software is copyright (c) 2026 by Daniel Brosseau.

This is free software; you can redistribute it and/or modify it under
the same terms as the Perl 5 programming language system itself.
