place

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[NewPlace, Place, FindFilters]

NewMemoryStore returns a new in memory store.

func Router

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

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

func URLFromID

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

URLFromID takes a base url an a place id and constructs an url pointing to the place 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, newPlace *NewPlace) (*Place, 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]) ([]*Place, int, error)

func (*Authorizer) FindByID

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

func (*Authorizer) Update

func (a *Authorizer) Update(ctx context.Context, place *Place) (*Place, 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 {
	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

func (*NewPlace) IsOwned

func (p *NewPlace) IsOwned(id string) bool

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

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 PlaceFromNewPlace(newPlace *NewPlace, id string) *Place

func (*Place) Coordinates

func (p *Place) Coordinates() (float64, float64)

func (Place) Identifier

func (p Place) Identifier() string

func (*Place) Indexable

func (p *Place) Indexable() bool

Indexable indicates wether a place should be added to the search index.

func (*Place) IsOwned

func (p *Place) IsOwned(id string) bool

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

func (*Place) Listable

func (p *Place) Listable() bool

Listable indicates wether a place should be shown on the list page.

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

func NewOperator

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

func NewService

func NewService(store Storer) Service

NewService returns a new place 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 place store.

func (*SqlStore) Create

func (s *SqlStore) Create(ctx context.Context, newPlace *NewPlace) (*Place, 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]) ([]*Place, int, error)

func (*SqlStore) FindByID

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

func (*SqlStore) Update

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

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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