roles

package
v0.0.13 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 7, 2026 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

ValidOperations contains all valid operation names.

ValidResources contains all valid resource names.

Functions

This section is empty.

Types

type CreateRolePayload

type CreateRolePayload struct {
	Name        string            `json:"name" validate:"required,min=1,max=50"`
	Permissions []PermissionInput `json:"permissions"`
}

CreateRolePayload represents the request body for creating a role.

type ListOptions

type ListOptions struct {
	Limit  int
	Offset int
}

ListOptions contains options for listing roles.

type ListRolesQuery

type ListRolesQuery struct {
	Limit  int `query:"limit" default:"50"`
	Offset int `query:"offset" default:"0"`
}

ListRolesQuery represents the query parameters for listing roles.

type PermissionInput

type PermissionInput struct {
	Resource  string `json:"resource" validate:"required"`
	Operation string `json:"operation" validate:"required"`
}

PermissionInput represents a permission to grant to a role.

type Service

type Service struct {
	// contains filtered or unexported fields
}

Service handles role operations.

func NewService

func NewService(db *bun.DB) *Service

NewService creates a new roles service.

func RegisterRoutes

func RegisterRoutes(e *echo.Echo, db *bun.DB, authMiddleware *auth.Middleware) *Service

RegisterRoutes registers all role routes.

func (*Service) Create

func (s *Service) Create(ctx context.Context, name string, permissions []PermissionInput) (*models.Role, error)

Create creates a new role.

func (*Service) Delete

func (s *Service) Delete(ctx context.Context, id int) error

Delete deletes a non-system role.

func (*Service) List

func (s *Service) List(ctx context.Context, opts ListOptions) ([]*models.Role, int, error)

List returns a paginated list of roles.

func (*Service) Retrieve

func (s *Service) Retrieve(ctx context.Context, id int) (*models.Role, error)

Retrieve gets a role by ID.

func (*Service) Update

func (s *Service) Update(ctx context.Context, id int, name *string, permissions *[]PermissionInput) (*models.Role, error)

Update updates a role's name and/or permissions.

type UpdateRolePayload

type UpdateRolePayload struct {
	Name        *string           `json:"name" validate:"omitempty,min=1,max=50"`
	Permissions []PermissionInput `json:"permissions"` // Replaces all permissions if provided
}

UpdateRolePayload represents the request body for updating a role.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL