Documentation ¶
Index ¶
- Constants
- Variables
- func NewMemoryStore() *crud.MemoryStore[NewPlace, Place, FindFilters]
- 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, newPlace *NewPlace) (*Place, error)
- func (a *Authorizer) Delete(ctx context.Context, id string) error
- func (a *Authorizer) Find(ctx context.Context, params *crud.FindParams[FindFilters]) ([]*Place, int, error)
- func (a *Authorizer) FindByID(ctx context.Context, id string) (*Place, error)
- func (a *Authorizer) Update(ctx context.Context, place *Place) (*Place, error)
- type CreateOperation
- type DeleteOperation
- type FindFilters
- type NewPlace
- type Place
- type Service
- type SortOrder
- type SqlStore
- func (s *SqlStore) Create(ctx context.Context, newPlace *NewPlace) (*Place, error)
- func (s *SqlStore) Delete(ctx context.Context, id string) error
- func (s *SqlStore) Find(ctx context.Context, params *crud.FindParams[FindFilters]) ([]*Place, int, error)
- func (s *SqlStore) FindByID(ctx context.Context, id string) (*Place, error)
- func (s *SqlStore) Update(ctx context.Context, place *Place) (*Place, 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[NewPlace, Place, 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]) ([]*Place, int, error)
type CreateOperation ¶
type CreateOperation struct { Place *Place // 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:"notID"` Deactivated *bool `json:"deactivated"` Published *bool `json:"published"` Name *string `json:"name"` LikeName *string `json:"likeName"` Description *string `json:"description"` OwnedBy []string `json:"ownedBy"` }
FindFilters defines the possible filters for the find method.
type NewPlace ¶
type NewPlace struct { Published bool `json:"published"` Name string `json:"name"` Address string `json:"address"` Lat float64 `json:"lat"` Lng float64 `json:"lng"` Link string `json:"link"` Email string `json:"email"` Description string `json:"description"` Image string `json:"image"` OwnedBy []string `json:"ownedBy" db:"owned_by"` }
Place defines a place entity
type Place ¶
type Place 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"` Description string `json:"description" db:"description"` Email string `json:"email" db:"email"` Image string `json:"image" db:"image"` Link string `json:"link" db:"link"` Address string `json:"address" db:"address"` Lat float64 `json:"lat" db:"lat"` Lng float64 `json:"lng" db:"lng"` OwnedBy []string `json:"ownedBy" db:"owned_by"` }
Place defines a place entity It implements indexo.Coppyable.
func PlaceFromNewPlace ¶
func (*Place) Coordinates ¶
func (Place) Identifier ¶
type Service ¶
type Service interface { Storer }
Service defines the crud service to manage places. -go:generate go run github.com/petergtz/pegomock/pegomock generate eintopf.info/service/place Service --output=../../internal/mock/place_service.go --package=mock --mock-name=PlaceService
type SqlStore ¶
type SqlStore struct {
// contains filtered or unexported fields
}
func NewSqlStore ¶
NewSqlStore returns a new sql db place store.
func (*SqlStore) Find ¶
func (s *SqlStore) Find(ctx context.Context, params *crud.FindParams[FindFilters]) ([]*Place, int, error)
type Storer ¶
type Storer interface { Create(ctx context.Context, newPlace *NewPlace) (*Place, error) Update(ctx context.Context, place *Place) (*Place, error) Delete(ctx context.Context, id string) error FindByID(ctx context.Context, id string) (*Place, error) Find(ctx context.Context, params *crud.FindParams[FindFilters]) ([]*Place, 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/place Storer --output=../../internal/mock/place_store.go --package=mock --mock-name=PlaceStore
type UpdateOperation ¶
type UpdateOperation struct { Place *Place // contains filtered or unexported fields }
func (UpdateOperation) UserID ¶
func (o UpdateOperation) UserID() string