Documentation ¶
Overview ¶
Package app contains business logic.
Index ¶
- Variables
- type App
- func (a *App) Auth(ctx context.Context, token string) (*dom.Session, error)
- func (a *App) CreateUser(ctx context.Context, email, username, fullName, password string) (userID uuid.UUID, err error)
- func (a *App) GetFile(ctx context.Context, _ dom.Session, fileID uuid.UUID) (*Avatar, error)
- func (a *App) GetUsersByIDs(ctx context.Context, _ dom.Session, ids []uuid.UUID) ([]User, error)
- func (a *App) ListUserAvatars(ctx context.Context, session dom.Session) ([]AvatarInfo, error)
- func (a *App) ListUserByFilters(ctx context.Context, _ dom.Session, filters SearchParams) ([]User, int, error)
- func (a *App) Login(ctx context.Context, email, password string, origin dom.Origin) (uuid.UUID, *dom.Token, error)
- func (a *App) Logout(ctx context.Context, session dom.Session) error
- func (a *App) Process(ctx context.Context) error
- func (a *App) RemoveAvatar(ctx context.Context, session dom.Session, fileID uuid.UUID) error
- func (a *App) SaveAvatar(ctx context.Context, session dom.Session, file Avatar) (avatarID uuid.UUID, err error)
- func (a *App) UpdatePassword(ctx context.Context, session dom.Session, oldPass, newPass string) error
- func (a *App) UpdateUser(ctx context.Context, session dom.Session, username string, avatarID uuid.UUID) error
- func (a *App) UserByID(ctx context.Context, session dom.Session, userID uuid.UUID) (*User, error)
- func (a *App) VerificationEmail(ctx context.Context, email string) error
- func (a *App) VerificationUsername(ctx context.Context, username string) error
- type Avatar
- type AvatarInfo
- type FileFormat
- type FileInfoRepo
- type FileStore
- type PasswordHash
- type Queue
- type Repo
- type SearchParams
- type SearchStatusUpdateRequest
- type Sessions
- type SolutionStatus
- type StatusUpdateRequest
- type Task
- type TaskKind
- type TaskRepo
- type User
Constants ¶
This section is empty.
Variables ¶
var ( ErrEmailExist = errors.New("email exist") ErrUsernameExist = errors.New("username exist") ErrNotFound = errors.New("not found") ErrInvalidArgument = errors.New("invalid argument") ErrNotDifferent = errors.New("the values must be different") ErrInvalidPassword = errors.New("invalid password") ErrInvalidAuth = errors.New("invalid auth") ErrUserIDAndFileIDExist = errors.New("user_id and file_id exist") ErrMaxFiles = errors.New("post can't save new file") ErrAccessDenied = errors.New("access denied") ErrInvalidImageFormat = errors.New("invalid image format") )
Errors.
Functions ¶
This section is empty.
Types ¶
type App ¶
type App struct {
// contains filtered or unexported fields
}
App manages business logic methods.
func (*App) CreateUser ¶
func (a *App) CreateUser(ctx context.Context, email, username, fullName, password string) (userID uuid.UUID, err error)
CreateUser create new user by params.
func (*App) GetUsersByIDs ¶
func (*App) ListUserAvatars ¶
ListUserAvatars get list user avatars.
func (*App) ListUserByFilters ¶
func (a *App) ListUserByFilters(ctx context.Context, _ dom.Session, filters SearchParams) ([]User, int, error)
ListUserByFilters get users by filters.
func (*App) Login ¶
func (a *App) Login(ctx context.Context, email, password string, origin dom.Origin) (uuid.UUID, *dom.Token, error)
Login make new session and returns sessions token.
func (*App) RemoveAvatar ¶
RemoveAvatar remove info about avatar.
func (*App) SaveAvatar ¶
func (a *App) SaveAvatar(ctx context.Context, session dom.Session, file Avatar) (avatarID uuid.UUID, err error)
SaveAvatar save info about avatar.
func (*App) UpdatePassword ¶
func (a *App) UpdatePassword(ctx context.Context, session dom.Session, oldPass, newPass string) error
UpdatePassword update user's password.
func (*App) UpdateUser ¶
func (a *App) UpdateUser(ctx context.Context, session dom.Session, username string, avatarID uuid.UUID) error
UpdateUser update user's profile.
func (*App) VerificationEmail ¶
VerificationEmail check exists or not user email.
type Avatar ¶
type Avatar struct { ID uuid.UUID Name string ContentType string Size int64 ModTime time.Time io.ReadSeekCloser }
Avatar contains file information.
type AvatarInfo ¶
type AvatarInfo struct { FileID uuid.UUID OwnerID uuid.UUID CreatedAt time.Time UpdatedAt time.Time }
AvatarInfo struct for caching info for finding file.
type FileFormat ¶
type FileFormat uint8
FileFormat represents format of file.
const ( FileFormatWebp FileFormat FileFormatPng FileFormatJpeg FileFormatGif FileFormatRaw FileFormatSvg )
func (FileFormat) String ¶
func (i FileFormat) String() string
type FileInfoRepo ¶
type FileInfoRepo interface { // SaveAvatar adds to the new cache about user avatar to repository. // Errors: ErrUserIDAndFileIDExist, ErrMaximumNumberOfStoredFilesReached, unknown. SaveAvatar(ctx context.Context, fileCache AvatarInfo) error // DeleteAvatar delete cache about user avatar info. // Errors: unknown. DeleteAvatar(ctx context.Context, userID, fileID uuid.UUID) error // GetAvatar returns cache about user avatar by id. // Errors: ErrNotFound, unknown. GetAvatar(ctx context.Context, fileID uuid.UUID) (*AvatarInfo, error) // ListAvatarByUserID returns list cache user file. // Errors: unknown. ListAvatarByUserID(ctx context.Context, userID uuid.UUID) ([]AvatarInfo, error) // GetCountAvatars returns count user avatars. // Errors: ErrNotFound, unknown. GetCountAvatars(ctx context.Context, ownerID uuid.UUID) (total int, err error) }
FileInfoRepo provides to file info repository
type FileStore ¶
type FileStore interface { // UploadFile save new file in database. // Errors: unknown. UploadFile(ctx context.Context, f Avatar) (uuid.UUID, error) // DownloadFile get file by id. // Errors: unknown. DownloadFile(ctx context.Context, id uuid.UUID) (*Avatar, error) // DeleteFile delete file by id. // Errors: unknown. DeleteFile(ctx context.Context, id uuid.UUID) error }
FileStore interface for saving and getting files.
type PasswordHash ¶
type PasswordHash interface { // Hashing returns the hashed version of the password. // Errors: unknown. Hashing(password string) ([]byte, error) // Compare compares two passwords for matches. Compare(hashedPassword []byte, password []byte) bool }
PasswordHash module responsible for hashing password.
type Queue ¶
type Queue interface { // AddUser sends event 'EventAdd' to queue. // Errors: unknown. AddUser(context.Context, uuid.UUID, User) error // DeleteUser sends event 'EventDel' to queue. // Errors: unknown. DeleteUser(context.Context, uuid.UUID, User) error // UpdateUser sends event 'EventUpdate' to queue. // Errors: unknown. UpdateUser(context.Context, uuid.UUID, User) error }
Queue sends events to queue.
type Repo ¶
type Repo interface { FileInfoRepo TaskRepo // Tx starts transaction in database. // Errors: unknown. Tx(ctx context.Context, f func(Repo) error) error // Save adds to the new user to repository. // Errors: ErrEmailExist, ErrUsernameExist, unknown. Save(context.Context, User) (uuid.UUID, error) // Update update user info. // Errors: ErrUsernameExist, ErrEmailExist, unknown. Update(context.Context, User) (*User, error) // ByID returns user info by id. // Errors: ErrNotFound, unknown. ByID(context.Context, uuid.UUID) (*User, error) // ByEmail returns user info by email. // Errors: ErrNotFound, unknown. ByEmail(context.Context, string) (*User, error) // ByUsername returns user info by username. // Errors: ErrNotFound, unknown. ByUsername(context.Context, string) (*User, error) // SearchUsers returns list user info. // Errors: unknown. SearchUsers(context.Context, SearchParams) ([]User, int, error) // UsersByIDs returns list of users. // Errors: ErrNotFound, unknown. UsersByIDs(ctx context.Context, ids []uuid.UUID) (users []User, err error) }
Repo interface for user data repository.
type SearchParams ¶
type SearchParams struct { OwnerID uuid.UUID Username string FullName string Statuses []dom.UserStatus Email string StartCreatedAt time.Time EndCreatedAt time.Time Limit uint64 Offset uint64 }
SearchParams params for search users.
type SearchStatusUpdateRequest ¶
type SearchStatusUpdateRequest struct { SolutionStatus SolutionStatus Limit uint Offset uint }
SearchStatusUpdateRequest params for search request for update.
type Sessions ¶
type Sessions interface { // Get returns user session by his token. // Errors: ErrNotFound, unknown. Get(context.Context, string) (*dom.Session, error) // Save new session for specific user. // Errors: unknown. Save(context.Context, uuid.UUID, dom.Origin, dom.UserStatus) (*dom.Token, error) // Delete removes session by id. // Errors: ErrNotFound, unknown. Delete(context.Context, uuid.UUID) error }
Sessions module for manager user's session.
type SolutionStatus ¶
type SolutionStatus uint8
SolutionStatus decision made at the time of the update.
const ( SolutionStatusNew SolutionStatus SolutionStatusApprove SolutionStatusCancel )
func (SolutionStatus) String ¶
func (i SolutionStatus) String() string
type StatusUpdateRequest ¶
type StatusUpdateRequest struct { ID uuid.UUID UserID uuid.UUID SolutionStatus SolutionStatus CreatedAt time.Time UpdatedAt time.Time }
StatusUpdateRequest user status update request.
type Task ¶
type Task struct { ID uuid.UUID User User Kind TaskKind CreatedAt time.Time UpdatedAt time.Time FinishedAt time.Time }
Task contains information for executing any deferred logic.
type TaskKind ¶
type TaskKind uint8
TaskKind represents kind of task.
const ( TaskKindEventAdd TaskKind TaskKindEventDel TaskKindEventUpdate )
type TaskRepo ¶
type TaskRepo interface { // SaveTask adds new task to repository. // Errors: unknown. SaveTask(context.Context, Task) (uuid.UUID, error) // FinishTask set column Task.FinishedAt task. // Errors: unknown. FinishTask(context.Context, uuid.UUID) error // ListActualTask returns list task by limit and ordered by created_at (ask). // Return tasks without Task.FinishedAt. // Errors: unknown. ListActualTask(context.Context, int) ([]Task, error) }
TaskRepo interface for saving tasks.