Documentation
¶
Overview ¶
Package services provides the core business logic for the application.
Index ¶
- Variables
- func SetUserCtx(ctx context.Context, user *repo.UserOut, token string) context.Context
- func UseTokenCtx(ctx context.Context) string
- func UseUserCtx(ctx context.Context) *repo.UserOut
- func WithAutoIncrementAssetID(v bool) func(*options)
- func WithCurrencies(v []currencies.Currency) func(*options)
- type AllServices
- type BackgroundService
- type Context
- type GroupService
- type ItemService
- func (svc *ItemService) AttachmentAdd(ctx Context, itemID uuid.UUID, filename string, attachmentType attachment.Type, ...) (repo.ItemOut, error)
- func (svc *ItemService) AttachmentDelete(ctx context.Context, gid, itemID, attachmentID uuid.UUID) error
- func (svc *ItemService) AttachmentPath(ctx context.Context, attachmentID uuid.UUID) (*ent.Document, error)
- func (svc *ItemService) AttachmentUpdate(ctx Context, itemID uuid.UUID, data *repo.ItemAttachmentUpdate) (repo.ItemOut, error)
- func (svc *ItemService) Create(ctx Context, item repo.ItemCreate) (repo.ItemOut, error)
- func (svc *ItemService) CsvImport(ctx context.Context, GID uuid.UUID, data io.Reader) (int, error)
- func (svc *ItemService) EnsureAssetID(ctx context.Context, GID uuid.UUID) (int, error)
- func (svc *ItemService) EnsureImportRef(ctx context.Context, GID uuid.UUID) (int, error)
- func (svc *ItemService) ExportBillOfMaterialsTSV(ctx context.Context, GID uuid.UUID) ([]byte, error)
- func (svc *ItemService) ExportTSV(ctx context.Context, GID uuid.UUID) ([][]string, error)
- type LoginForm
- type OptionsFunc
- type UserAuthTokenDetail
- type UserRegistration
- type UserService
- func (svc *UserService) ChangePassword(ctx Context, current string, new string) (ok bool)
- func (svc *UserService) DeleteSelf(ctx context.Context, ID uuid.UUID) error
- func (svc *UserService) GetSelf(ctx context.Context, requestToken string) (repo.UserOut, error)
- func (svc *UserService) Login(ctx context.Context, username, password string, extendedSession bool) (UserAuthTokenDetail, error)
- func (svc *UserService) Logout(ctx context.Context, token string) error
- func (svc *UserService) RegisterUser(ctx context.Context, data UserRegistration) (repo.UserOut, error)
- func (svc *UserService) RenewToken(ctx context.Context, token string) (UserAuthTokenDetail, error)
- func (svc *UserService) UpdateSelf(ctx context.Context, ID uuid.UUID, data repo.UserUpdate) (repo.UserOut, error)
Constants ¶
This section is empty.
Variables ¶
var ( ContextUser = &contextKeys{name: "User"} ContextUserToken = &contextKeys{name: "UserToken"} )
var ( ErrNotFound = errors.New("not found") ErrFileNotFound = errors.New("file not found") )
Functions ¶
func SetUserCtx ¶
SetUserCtx is a helper function that sets the ContextUser and ContextUserToken values within the context of a web request (or any context).
func UseTokenCtx ¶
UseTokenCtx is a helper function that returns the user token from the context.
func UseUserCtx ¶
UseUserCtx is a helper function that returns the user from the context.
func WithAutoIncrementAssetID ¶
func WithAutoIncrementAssetID(v bool) func(*options)
func WithCurrencies ¶
func WithCurrencies(v []currencies.Currency) func(*options)
Types ¶
type AllServices ¶
type AllServices struct { User *UserService Group *GroupService Items *ItemService BackgroundService *BackgroundService Currencies *currencies.CurrencyRegistry }
func New ¶
func New(repos *repo.AllRepos, opts ...OptionsFunc) *AllServices
type BackgroundService ¶
type BackgroundService struct {
// contains filtered or unexported fields
}
func (*BackgroundService) SendNotifiersToday ¶
func (svc *BackgroundService) SendNotifiersToday(ctx context.Context) error
type Context ¶
type Context struct { context.Context // UID is a unique identifier for the acting user. UID uuid.UUID // GID is a unique identifier for the acting users group. GID uuid.UUID // User is the acting user. User *repo.UserOut }
func NewContext ¶
NewContext is a helper function that returns the service context from the context. This extracts the users from the context and embeds it into the ServiceContext struct
type GroupService ¶
type GroupService struct {
// contains filtered or unexported fields
}
func (*GroupService) NewInvitation ¶
func (*GroupService) UpdateGroup ¶
func (svc *GroupService) UpdateGroup(ctx Context, data repo.GroupUpdate) (repo.Group, error)
type ItemService ¶
type ItemService struct {
// contains filtered or unexported fields
}
func (*ItemService) AttachmentAdd ¶
func (svc *ItemService) AttachmentAdd(ctx Context, itemID uuid.UUID, filename string, attachmentType attachment.Type, file io.Reader) (repo.ItemOut, error)
AttachmentAdd adds an attachment to an item by creating an entry in the Documents table and linking it to the Attachment Table and Items table. The file provided via the reader is stored on the file system based on the provided relative path during construction of the service.
func (*ItemService) AttachmentDelete ¶
func (*ItemService) AttachmentPath ¶
func (*ItemService) AttachmentUpdate ¶
func (svc *ItemService) AttachmentUpdate(ctx Context, itemID uuid.UUID, data *repo.ItemAttachmentUpdate) (repo.ItemOut, error)
func (*ItemService) Create ¶
func (svc *ItemService) Create(ctx Context, item repo.ItemCreate) (repo.ItemOut, error)
func (*ItemService) CsvImport ¶
CsvImport imports items from a CSV file. using the standard defined format.
CsvImport applies the following rules/operations
- If the item does not exist, it is created.
- If the item has a ImportRef and it exists it is skipped
- Locations and Labels are created if they do not exist.
func (*ItemService) EnsureAssetID ¶
func (*ItemService) EnsureImportRef ¶
func (*ItemService) ExportBillOfMaterialsTSV ¶
type OptionsFunc ¶
type OptionsFunc func(*options)
type UserAuthTokenDetail ¶
type UserRegistration ¶
type UserService ¶
type UserService struct {
// contains filtered or unexported fields
}
func (*UserService) ChangePassword ¶
func (svc *UserService) ChangePassword(ctx Context, current string, new string) (ok bool)
func (*UserService) DeleteSelf ¶
DeleteSelf deletes the user that is currently logged based of the provided UUID There is _NO_ protection against deleting the wrong user, as such this should only be used when the identify of the user has been confirmed.
func (*UserService) GetSelf ¶
GetSelf returns the user that is currently logged in based of the token provided within
func (*UserService) Login ¶
func (svc *UserService) Login(ctx context.Context, username, password string, extendedSession bool) (UserAuthTokenDetail, error)
func (*UserService) Logout ¶
func (svc *UserService) Logout(ctx context.Context, token string) error
func (*UserService) RegisterUser ¶
func (svc *UserService) RegisterUser(ctx context.Context, data UserRegistration) (repo.UserOut, error)
RegisterUser creates a new user and group in the data with the provided data. It also bootstraps the user's group with default Labels and Locations.
func (*UserService) RenewToken ¶
func (svc *UserService) RenewToken(ctx context.Context, token string) (UserAuthTokenDetail, error)
func (*UserService) UpdateSelf ¶
func (svc *UserService) UpdateSelf(ctx context.Context, ID uuid.UUID, data repo.UserUpdate) (repo.UserOut, error)