package rest

import "hauru.club/x/okrzeja/service/rest"

Package rest provides HATEOS-compliant HTTP REST handlers and defines contracts used by those handlers.

Index

Constants

const FileMIMEDirectory = "inode/directory"

FileMIMEDirectory is MIME type for directories.

Variables

var ErrNoDirectory = errors.New("http: there is no such directory")

ErrNoDirectory is returned when DirectoryRead is requested with ID assigned to file, which isn't directory.

Functions

func ErrorHandler

func ErrorHandler(err error) http.Handler

ErrorHandler handles HTTP errors in a RESTful way.

func Handlers

func Handlers(deps HandlersDependencies) httpx.Handlers

Handlers are REST handlers that satisfy requirements described by the httpx.Handlers.

Types

type ActivitiesReadRequest

type ActivitiesReadRequest struct {
	// UserID is unique identifier of user who owns requested activities.
	UserID uuid.UUID

	// Last is identifier of the last activity from previous query.
	Last uuid.UUID
}

ActivitiesReadRequest holds arguments

type ActivitiesReadResponse

type ActivitiesReadResponse struct {
	// ID is unique id of new activity record.
	ID uuid.UUID

	// Type of activity record.
	Type string

	// CreatedAt points to the point in time when given activity
	// was created.
	CreatedAt time.Time

	// Details consist flat map of key/value records that will be
	// presented to user and system administrator, to provide useful
	// debug informations related to given action.
	Details map[string]any
}

ActivitiesReadResponse holds data stored for single activity entry.

type ActivitiesReader

type ActivitiesReader interface {
	// ActivitiesReadInit initializes querying user activities. It returns
	// limited number of user activities. You can use last user's activity ID
	// from given slice and ActivitiesReadFrom method to query for more entries.
	ActivitiesReadInit(ctx context.Context, userID uuid.UUID) ([]ActivitiesReadResponse, error)

	// ActivitiesRead returns list of activities owned by user with given user ID that were
	// created before activity with given last ID.
	ActivitiesRead(ctx context.Context, req ActivitiesReadRequest) ([]ActivitiesReadResponse, error)
}

ActivitiesReader implements querying group of activities for particular user.

type DirectoryCreator

type DirectoryCreator interface {
	// DirectoryCreate creates new directory with requested properties.
	DirectoryCreate(ctx context.Context, req NewDirectoryRequest) (*NewFileResponse, error)
}

DirectoryCreator creates directories on behalf of users.

type DirectoryReadResponse

type DirectoryReadResponse struct {
	// Name of directory.
	Name string

	// Parent of current directory. Can be null if it's root directory.
	Parent uuid.NullUUID

	// Children are filed stored in requested directory.
	Children []FileMetadata
}

DirectoryReadResponse holds response data from DirectoryRead method.

type DirectoryReader

type DirectoryReader interface {
	// DirectoryRead returns useful metadata of directory with given ID and
	// its children files.
	DirectoryRead(context.Context, uuid.UUID) (*DirectoryReadResponse, error)
}

DirectoryReader reads user's directories data.

type FileCommandService

type FileCommandService interface {
	FileSystemCreator
	FileContentUpdater
	FileNameUpdater
	FileDeleter
}

FileCommandService implements file's manipulation dependencies for REST handlers.

type FileContentUpdater

type FileContentUpdater interface {
	// FileUpdateContent updates content of the file with given unique ID.
	FileUpdateContent(ctx context.Context, req FileUpdateContentRequest) error
}

FileContentUpdater updates content of the file.

type FileCreator

type FileCreator interface {
	// FileCreate creates new file with requested properties.
	FileCreate(ctx context.Context, req NewFileRequest) (*NewFileResponse, error)
}

FileCreator creates files on behalf of users.

type FileDeleter

type FileDeleter interface {
	// FileDelete removes file or directory with given unique ID from
	// filesystem. All children of removed directory are also removed.
	//
	// It is impossible to delete any root file with this method.
	FileDelete(ctx context.Context, id uuid.UUID) error
}

FileDeleter removes files and directories from filesystem.

type FileDirectoryReader

type FileDirectoryReader interface {
	FileReader
	DirectoryReader
}

FileDirectoryReader reads directories and files from user file system.

type FileMetadata

type FileMetadata struct {
	// Name of the file.
	Name string

	// FileID is unique file's ID.
	FileID uuid.UUID

	// MIME is media type of the file.
	MIME string
}

FileMetadata contains metadata for single file.

type FileNameUpdater

type FileNameUpdater interface {
	// FileUpdateName updates name of the file with given unique ID.
	FileUpdateName(ctx context.Context, req FileUpdateNameRequest) error
}

FileNameUpdater updates name of the file.

type FileQueryService

type FileQueryService interface {
	RootDirectoryDiscoverer
	FileDirectoryReader
}

FileQueryService implements file's querying dependencies for REST handlers.

type FileReadResponse

type FileReadResponse struct {
	FileMetadata

	// Parent of the requested file.
	Parent uuid.NullUUID

	// Content of the file.
	Content []byte
}

FileReadResponse holds response data from reading file operation.

func (*FileReadResponse) IsDir

func (f *FileReadResponse) IsDir() bool

IsDir returns true only if file from response is the directory.

type FileReader

type FileReader interface {
	// FileRead returns metadata and content of the file with given ID.
	FileRead(context.Context, uuid.UUID) (*FileReadResponse, error)
}

FileReader reads user's files.

type FileService

type FileService struct {
	FileQueryService
	FileCommandService
}

FileService implements file's manipulation dependencies for REST handlers.

type FileSystemCreator

type FileSystemCreator interface {
	FileCreator
	DirectoryCreator
}

FileSystemCreator creates files and directories in the internal user filesystem.

type FileUpdateContentRequest

type FileUpdateContentRequest struct {
	// ID is unique identifier of file.
	ID uuid.UUID

	// Content is the new content of the file.
	Content []byte
}

FileUpdateContentRequest holds arguments for updating content of the already existing file.

type FileUpdateNameRequest

type FileUpdateNameRequest struct {
	// ID is unique identifier of file.
	ID uuid.UUID

	// Name is new file's name.
	Name string
}

FileUpdateContentRequest holds arguments for updating name of the already existing file or directory.

type HandlersDependencies

HandlersDependencies holds dependencies for REST handlers.

type NewDirectoryRequest

type NewDirectoryRequest struct {
	// Owner is unique identifier of owner user.
	Owner uuid.UUID

	// Parent is parent's unique identifier.
	Parent uuid.UUID

	// Name of new directory.
	Name string
}

NewDirectoryRequest holds arguments for creating new directory.

type NewFileRequest

type NewFileRequest struct {
	// Owner is unique identifier of owner user.
	Owner uuid.UUID

	// Parent is parent's unique identifier.
	Parent uuid.UUID

	// Filename is the name of new file.
	Filename string

	// FilenameExtension is the filename extension of new file.
	FilenameExtension string
}

NewFileRequest holds arguments for creating new file.

type NewFileResponse

type NewFileResponse struct {
	// ID is unique identifier of new file or directory.
	ID uuid.UUID
}

NewFileResponse holds properties of freshly created file or directory.

type RootDirectoryDiscoverer

type RootDirectoryDiscoverer interface {
	// RootDirectory returns unique identifier of root file for user
	// with given user ID.
	RootDirectory(context.Context, uuid.UUID) (uuid.UUID, error)
}

RootDirectoryDiscoverer discovers unique identifier of root directory.

type UserDeleter

type UserDeleter interface {
	// UserDelete removes user with given unique ID from the system.
	UserDelete(context.Context, uuid.UUID) error
}

UserDeleter removes user from the system.

type UserPasswordChangeRequest

type UserPasswordChangeRequest struct {
	// ID is unique user's identifier.
	ID uuid.UUID

	// NewPassword is new password for user.
	NewPassword string
}

UserPasswordChangeRequest holds arguments for changing password.

type UserPasswordChanger

type UserPasswordChanger interface {
	// UserChangePassword changes password of user with given user ID to the
	// provided new password.
	UserChangePassword(context.Context, UserPasswordChangeRequest) error
}

UserPasswordChanger changes password of user.

type UserPasswordUpdateRequest

type UserPasswordUpdateRequest struct {
	// ID is unique user's identifier.
	ID uuid.UUID

	// OldPassword is old user's password.
	OldPassword string

	// NewPassword is new password requested by the user.
	NewPassword string
}

UserPasswordUpdateRequest holds arguments for updating password on user's behalf.

type UserPasswordUpdater

type UserPasswordUpdater interface {
	// UserPasswordUpdate updates user's password on his/her behalf. It returns error if
	// authorization with old password fails or new password is invalid.
	UserPasswordUpdate(context.Context, UserPasswordUpdateRequest) error
}

UserPasswordUpdater updates password of the user on his/her behalf, so it requires to provide old password in order to authorize user.

type UserReadResponse

type UserReadResponse struct {
	// ID is unique user identifier.
	ID uuid.UUID

	// Username is unique login name.
	Username string

	// CreatedAt is time when user account was created.
	CreatedAt time.Time
}

UserReadResponse holds results for reading users.

type UserRegisterRequest

type UserRegisterRequest struct {
	// Username is unique login name.
	Username string

	// Password is secret phrase use to access user's account.
	Password string
}

UserRegisterRequest holds arguments for creating account for new user.

type UserRegisterResponse

type UserRegisterResponse struct {
	// ID is unique user's identifier.
	ID uuid.UUID

	// CreatedAt is time of account creation.
	CreatedAt time.Time
}

UserRegisterResponse is response of new account creation process.

type UserRegisterer

type UserRegisterer interface {
	// UserRegister creates new account for user.
	UserRegister(context.Context, UserRegisterRequest) (*UserRegisterResponse, error)
}

UserRegisterer service handles creation of new user account.

type UsersBatchRegisterer

type UsersBatchRegisterer interface {
	// UsersRegister creates multiple user accounts. It should fail if
	// creation of at least single user account also fails.
	UsersRegister(context.Context, []UserRegisterRequest) error
}

UsersBatchRegisterer service registers batch of users, the same way as UserRegisterer.

type UsersReadFromRequest

type UsersReadFromRequest struct {
	// ID is last user's unique identifier. UsersReadFrom returns slice
	// of users' informations, which were created after account with given
	// ID.
	ID uuid.UUID

	// Query is an optional query string. It can be prefix, suffix or substring
	// of username of user that you are looking for.
	Query string
}

UsersReadFromRequest holds arguments for UsersReadFrom method.

type UsersReadFromUsernameRequest

type UsersReadFromUsernameRequest struct {
	// Username is last user's unique username. UsersReadFromUsername returns slice
	// of users' informations, which were created after account with given
	// username.
	Username string

	// Query is an optional query string. It can be prefix, suffix or substring
	// of username of user that you are looking for.
	Query string
}

UsersReadFromUsernameRequest holds arguments for UsersReadFromUsername method.

type UsersReader

type UsersReader interface {
	// UsersReadInit initialize querying user accounts. It returns
	// limited number of user accounts. You can use last user ID from
	// given slice and UserReadFrom method to query for more entries.
	//
	// Query is optional query string. See UsersReadFromRequest for more
	// informations about query string.
	UsersReadInit(ctx context.Context, query string) ([]UserReadResponse, error)

	// UserReadFrom reads limited number of user accounts that
	// were created after account with given ID.
	UsersReadFrom(context.Context, UsersReadFromRequest) ([]UserReadResponse, error)

	// UsersReadFromUsername reads limited number of user accounts that
	// were created after account with given username.
	UsersReadFromUsername(context.Context, UsersReadFromUsernameRequest) ([]UserReadResponse, error)
}

UsersReader service handles querying group of users.

Source Files

commands.go error.go htmx.go rest.go ui.go views.go

Version
v0.0.0-20231010043146-4292577f982b (latest)
Published
Oct 10, 2023
Platform
linux/amd64
Imports
23 packages
Last checked
1 day ago

Tools for package owners.