Documentation ¶
Index ¶
- Constants
- Variables
- func NewMemoryStore() *crud.MemoryStore[NewGroup, Group, FindFilters]
- func NewService(store Storer) *service
- func Router(service Service, authService auth.Service) func(chi.Router)
- func URLFromID(baseURL string, id string) (string, error)
- type Authorizer
- func (a *Authorizer) Create(ctx context.Context, newGroup *NewGroup) (*Group, error)
- func (a *Authorizer) Delete(ctx context.Context, id string) error
- func (a *Authorizer) Find(ctx context.Context, params *crud.FindParams[FindFilters]) ([]*Group, int, error)
- func (a *Authorizer) FindByID(ctx context.Context, id string) (*Group, error)
- func (a *Authorizer) IsOwned(ctx context.Context, groupID string, userID string) bool
- func (a *Authorizer) Owners(ctx context.Context, groupID string) ([]string, error)
- func (a *Authorizer) Update(ctx context.Context, group *Group) (*Group, error)
- type CreateOperation
- type DeleteOperation
- type FindFilters
- type Group
- type NewGroup
- type Service
- type SortOrder
- type SqlStore
- func (s *SqlStore) Create(ctx context.Context, newGroup *NewGroup) (*Group, error)
- func (s *SqlStore) Delete(ctx context.Context, id string) error
- func (s *SqlStore) Find(ctx context.Context, params *crud.FindParams[FindFilters]) ([]*Group, int, error)
- func (s *SqlStore) FindByID(ctx context.Context, id string) (*Group, error)
- func (s *SqlStore) Update(ctx context.Context, group *Group) (*Group, error)
- type Storer
- type UpdateOperation
Constants ¶
const ( OrderAsc = SortOrder("ASC") OrderDesc = SortOrder("DESC") )
Possible values for SortOrder.
Variables ¶
var ErrNameAlreadyExists = xerror.BadInputError{Err: fmt.Errorf("name already exists")}
Functions ¶
func NewMemoryStore ¶
func NewMemoryStore() *crud.MemoryStore[NewGroup, Group, FindFilters]
NewMemoryStore returns a new in memory store.
Types ¶
type Authorizer ¶
type Authorizer struct {
// contains filtered or unexported fields
}
func NewAuthorizer ¶
func NewAuthorizer(service Service) *Authorizer
func (*Authorizer) Delete ¶
func (a *Authorizer) Delete(ctx context.Context, id string) error
Update can only be called - if the loggedin user is in the OwnedBy field - if the loggedin user is an admin
func (*Authorizer) Find ¶
func (a *Authorizer) Find(ctx context.Context, params *crud.FindParams[FindFilters]) ([]*Group, int, error)
type CreateOperation ¶
type CreateOperation struct { Group *Group // contains filtered or unexported fields }
func (CreateOperation) UserID ¶
func (o CreateOperation) UserID() string
type DeleteOperation ¶
type DeleteOperation struct { ID string // contains filtered or unexported fields }
func (DeleteOperation) UserID ¶
func (o DeleteOperation) UserID() string
type FindFilters ¶
type FindFilters struct { ID *string `json:"id"` NotID *string `json:"not_id"` Deactivated *bool `json:"deactivated"` Published *bool `json:"published"` Name *string `json:"name"` LikeName *string `json:"likeName"` Link *string `json:"link"` Email *string `json:"email"` Description *string `json:"description"` OwnedBy []string `json:"ownedBy"` }
FindFilters defines the possible filters for the find method.
type Group ¶
type Group struct { ID string `json:"id" db:"id"` Deactivated bool `json:"deactivated" db:"deactivated"` Published bool `json:"published" db:"published"` Name string `json:"name" db:"name"` Link string `json:"link" db:"link"` Email string `json:"email" db:"email"` Description string `json:"description" db:"description"` Image string `json:"image" db:"image"` OwnedBy []string `json:"ownedBy" db:"owned_by"` }
Group defines a group entity It implements indexo.Coppyable.
func GroupFromNewGroup ¶
func (Group) Identifier ¶
type NewGroup ¶
type NewGroup struct { Published bool `json:"published"` Name string `json:"name"` Link string `json:"link"` Email string `json:"email"` Description string `json:"description"` Image string `json:"image"` OwnedBy []string `json:"ownedBy" db:"owned_by"` }
Group defines a group entity
type Service ¶
type Service interface { Storer }
Service defines the crud service to manage groups. -go:generate go run github.com/petergtz/pegomock/pegomock generate eintopf.info/service/group Service --output=../../internal/mock/group_service.go --package=mock --mock-name=GroupService
type SqlStore ¶
type SqlStore struct {
// contains filtered or unexported fields
}
func NewSqlStore ¶
NewSqlStore returns a new sql db group store.
func (*SqlStore) Find ¶
func (s *SqlStore) Find(ctx context.Context, params *crud.FindParams[FindFilters]) ([]*Group, int, error)
type Storer ¶
type Storer interface { Create(ctx context.Context, newGroup *NewGroup) (*Group, error) Update(ctx context.Context, group *Group) (*Group, error) Delete(ctx context.Context, id string) error FindByID(ctx context.Context, id string) (*Group, error) Find(ctx context.Context, params *crud.FindParams[FindFilters]) ([]*Group, int, error) }
Storer defines a service for CRUD operations on the event model. -go:generate go run github.com/petergtz/pegomock/pegomock generate eintopf.info/service/group Storer --output=../../internal/mock/group_store.go --package=mock --mock-name=GroupStore
type UpdateOperation ¶
type UpdateOperation struct { Group *Group // contains filtered or unexported fields }
func (UpdateOperation) UserID ¶
func (o UpdateOperation) UserID() string