group

package
v0.0.2-rc-ci Latest Latest
Warning

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

Go to latest
Published: Feb 15, 2024 License: AGPL-3.0 Imports: 20 Imported by: 0

Documentation

Index

Constants

View Source
const (
	OrderAsc  = SortOrder("ASC")
	OrderDesc = SortOrder("DESC")
)

Possible values for SortOrder.

Variables

View Source
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.

func NewService

func NewService(store Storer) *service

NewService returns a new group service.

func Router

func Router(service Service, authService auth.Service) func(chi.Router)

Router returns a new http router that handles crud requests on the group model, that get forwarded to the given group service.

func URLFromID

func URLFromID(baseURL string, id string) (string, error)

URLFromID takes a base url an a group id and constructs an url pointing to the group on the web frontend.

Types

type Authorizer

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

func NewAuthorizer

func NewAuthorizer(service Service) *Authorizer

func (*Authorizer) Create

func (a *Authorizer) Create(ctx context.Context, newGroup *NewGroup) (*Group, error)

Create can only be called by loggedin users.

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)

func (*Authorizer) FindByID

func (a *Authorizer) FindByID(ctx context.Context, id string) (*Group, error)

func (*Authorizer) IsOwned

func (a *Authorizer) IsOwned(ctx context.Context, groupID string, userID string) bool

func (*Authorizer) Owners

func (a *Authorizer) Owners(ctx context.Context, groupID string) ([]string, error)

func (*Authorizer) Update

func (a *Authorizer) Update(ctx context.Context, group *Group) (*Group, error)

Update can only be called - if the loggedin user is in the OwnedBy field - if the loggedin user is a moderator or admin

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 GroupFromNewGroup(newGroup *NewGroup, id string) *Group

func (Group) Identifier

func (g Group) Identifier() string

func (*Group) Indexable

func (g *Group) Indexable() bool

Indexable indicates wether the group should be added to the search index.

func (*Group) IsOwned

func (g *Group) IsOwned(id string) bool

IsOwned returns true if the id is in the OwnedBy field.

func (*Group) Listable

func (g *Group) Listable() bool

Listed indicates wether the group should be shown on the list page.

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

func (*NewGroup) IsOwned

func (g *NewGroup) IsOwned(id string) bool

IsOwned returns true if the id is in the OwnedBy field.

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

func NewOperator

func NewOperator(service Service, queue *oqueue.Queue) Service

type SortOrder

type SortOrder string

SortOrder defines the order of sorting.

type SqlStore

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

func NewSqlStore

func NewSqlStore(db *sqlx.DB, migrationService dbmigration.Service) (*SqlStore, error)

NewSqlStore returns a new sql db group store.

func (*SqlStore) Create

func (s *SqlStore) Create(ctx context.Context, newGroup *NewGroup) (*Group, error)

func (*SqlStore) Delete

func (s *SqlStore) Delete(ctx context.Context, id string) error

func (*SqlStore) Find

func (s *SqlStore) Find(ctx context.Context, params *crud.FindParams[FindFilters]) ([]*Group, int, error)

func (*SqlStore) FindByID

func (s *SqlStore) FindByID(ctx context.Context, id string) (*Group, error)

func (*SqlStore) Update

func (s *SqlStore) Update(ctx context.Context, group *Group) (*Group, 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

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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