services

package
v0.0.0-...-fbb17d6 Latest Latest
Warning

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

Go to latest
Published: Apr 28, 2024 License: AGPL-3.0 Imports: 18 Imported by: 0

Documentation

Overview

Package services provides the core business logic for the application.

Index

Constants

This section is empty.

Variables

View Source
var (
	ContextUser      = &contextKeys{name: "User"}
	ContextUserToken = &contextKeys{name: "UserToken"}
)
View Source
var (
	ErrNotFound     = errors.New("not found")
	ErrFileNotFound = errors.New("file not found")
)
View Source
var (
	ErrorInvalidLogin    = errors.New("invalid username or password")
	ErrorInvalidToken    = errors.New("invalid token")
	ErrorTokenIDMismatch = errors.New("token id mismatch")
)

Functions

func SetUserCtx

func SetUserCtx(ctx context.Context, user *repo.UserOut, token string) context.Context

SetUserCtx is a helper function that sets the ContextUser and ContextUserToken values within the context of a web request (or any context).

func UseTokenCtx

func UseTokenCtx(ctx context.Context) string

UseTokenCtx is a helper function that returns the user token from the context.

func UseUserCtx

func UseUserCtx(ctx context.Context) *repo.UserOut

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

func NewContext(ctx context.Context) Context

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 (svc *GroupService) NewInvitation(ctx Context, uses int, expiresAt time.Time) (string, error)

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 (svc *ItemService) AttachmentDelete(ctx context.Context, gid, itemID, attachmentID uuid.UUID) error

func (*ItemService) AttachmentPath

func (svc *ItemService) AttachmentPath(ctx context.Context, attachmentID uuid.UUID) (*ent.Document, error)

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

func (svc *ItemService) CsvImport(ctx context.Context, GID uuid.UUID, data io.Reader) (int, error)

CsvImport imports items from a CSV file. using the standard defined format.

CsvImport applies the following rules/operations

  1. If the item does not exist, it is created.
  2. If the item has a ImportRef and it exists it is skipped
  3. Locations and Labels are created if they do not exist.

func (*ItemService) EnsureAssetID

func (svc *ItemService) EnsureAssetID(ctx context.Context, GID uuid.UUID) (int, error)

func (*ItemService) EnsureImportRef

func (svc *ItemService) EnsureImportRef(ctx context.Context, GID uuid.UUID) (int, error)

func (*ItemService) ExportBillOfMaterialsTSV

func (svc *ItemService) ExportBillOfMaterialsTSV(ctx context.Context, GID uuid.UUID) ([]byte, error)

func (*ItemService) ExportTSV

func (svc *ItemService) ExportTSV(ctx context.Context, GID uuid.UUID) ([][]string, error)

type LoginForm

type LoginForm struct {
	Username string `json:"username"`
	Password string `json:"password"`
}

type OptionsFunc

type OptionsFunc func(*options)

type UserAuthTokenDetail

type UserAuthTokenDetail struct {
	Raw             string    `json:"raw"`
	AttachmentToken string    `json:"attachmentToken"`
	ExpiresAt       time.Time `json:"expiresAt"`
}

type UserRegistration

type UserRegistration struct {
	GroupToken string `json:"token"`
	Name       string `json:"name"`
	Email      string `json:"email"`
	Password   string `json:"password"`
}

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

func (svc *UserService) DeleteSelf(ctx context.Context, ID uuid.UUID) error

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

func (svc *UserService) GetSelf(ctx context.Context, requestToken string) (repo.UserOut, error)

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)

Directories

Path Synopsis
Package reporting provides a way to import CSV files into the database.
Package reporting provides a way to import CSV files into the database.
eventbus
Package eventbus provides an interface for event bus.
Package eventbus provides an interface for event bus.

Jump to

Keyboard shortcuts

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