Documentation ¶
Index ¶
- Constants
- Variables
- func CreateAdminAccount(s Service, email, password string) error
- func NewMemoryStore() *crud.MemoryStore[NewUser, User, FindFilters]
- func Router(storer Storer, authService auth.Service) func(chi.Router)
- type CreateOperation
- type DeleteOperation
- type FindFilters
- type FindParams
- type NewUser
- type Operator
- func (i *Operator) Create(ctx context.Context, newUser *NewUser) (*User, error)
- func (i *Operator) Delete(ctx context.Context, id string) error
- func (i *Operator) Find(ctx context.Context, params *crud.FindParams[FindFilters]) ([]*User, int, error)
- func (i *Operator) FindByID(ctx context.Context, id string) (*User, error)
- func (i *Operator) Update(ctx context.Context, user *User) (*User, error)
- type Service
- type SortOrder
- type SqlStore
- type Storer
- type UpdateOperation
- type User
Constants ¶
const ( OrderAsc = SortOrder("ASC") OrderDesc = SortOrder("DESC") )
Possible values for SortOrder.
Variables ¶
var ErrEmailAlreadyExists = xerror.BadInputError{Err: fmt.Errorf("email already exists")}
var ErrNicknameAlreadyExists = xerror.BadInputError{Err: fmt.Errorf("nickname already exists")}
Functions ¶
func CreateAdminAccount ¶
CreateAdminAccount creates a new admin account, if none exists with the given email address.
func NewMemoryStore ¶
func NewMemoryStore() *crud.MemoryStore[NewUser, User, FindFilters]
NewMemoryStore returns a new in memory store.
Types ¶
type CreateOperation ¶
type CreateOperation struct { User *User // contains filtered or unexported fields }
func NewCreateOperation ¶
func NewCreateOperation(user *User, userID string) CreateOperation
func (CreateOperation) UserID ¶
func (o CreateOperation) UserID() string
type DeleteOperation ¶
type DeleteOperation struct { ID string // contains filtered or unexported fields }
func NewDeleteOperation ¶
func NewDeleteOperation(id string, userID string) DeleteOperation
func (DeleteOperation) UserID ¶
func (o DeleteOperation) UserID() string
type FindFilters ¶
type FindFilters struct { ID *string `db:"id"` NotID *string `db:"id"` Deactivated *bool `db:"deactivated"` Email *string `db:"email"` Nickname *string `db:"nickname"` LikeNickname *string `db:"nickname"` Password *string `db:"password"` Role *auth.Role `db:"role"` }
FindFilters defines the possible filters for the find method.
type FindParams ¶
type FindParams struct { Offset int64 Limit int64 Sort string Order SortOrder Filters *FindFilters }
FindParams defines parameters used by the Find method.
type NewUser ¶
type NewUser struct { Email string `json:"email"` Nickname string `json:"nickname"` Password string `json:"password"` Role auth.Role `json:"role"` }
NewUser defines the data for a new user.
type Operator ¶
type Operator struct {
// contains filtered or unexported fields
}
func (*Operator) Find ¶
func (i *Operator) Find(ctx context.Context, params *crud.FindParams[FindFilters]) ([]*User, int, error)
type Service ¶
type Service interface { Storer auth.Authenticator auth.Authorizer }
Service defines a service to manage users. generate go run github.com/petergtz/pegomock/pegomock generate eintopf.info/service/user Service --output=../../internal/mock/user_service.go --package=mock --mock-name=UserService
type SqlStore ¶
type SqlStore struct { *crud.SqlStore[NewUser, User, FindFilters] // contains filtered or unexported fields }
func NewSqlStore ¶
NewSqlStore returns a new sql db user store.
type Storer ¶
type Storer = crud.Storer[NewUser, User, FindFilters]
Storer defines a service for CRUD operations on the user model.
func NewAuthorizer ¶
type UpdateOperation ¶
type UpdateOperation struct { User *User // contains filtered or unexported fields }
func NewUpdateOperation ¶
func NewUpdateOperation(user *User, userID string) UpdateOperation
func (UpdateOperation) UserID ¶
func (o UpdateOperation) UserID() string
type User ¶
type User struct { ID string `json:"id" db:"id"` Deactivated bool `json:"deactivated" db:"deactivated"` CreatedAt time.Time `json:"createdAt" db:"created_at"` Email string `json:"email" db:"email"` Nickname string `json:"nickname" db:"nickname"` Password string `json:"password" db:"password"` Role auth.Role `json:"role" db:"role"` }
User defines the user model by embedding NewUser along with additional fields, that can't be set by the user during creation.
func UserFromNewUser ¶
UserFromNewUser converts a NewUser to a User.