actions

package
v1.0.3 Latest Latest
Warning

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

Go to latest
Published: Feb 22, 2024 License: MIT Imports: 11 Imported by: 4

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrFolderAlreadyExists        = errors.Conflict.New("folder already exists").T("folder.conflict")
	ErrFolderRecursiveAttachment  = errors.Conflict.New("folders recursion attaching").T("folder.recursion")
	ErrFolderAlreadyInThisFolder  = errors.BadRequest.New("folder already in this folder").T("folder.moving-same-folder")
	ErrFolderAlreadyHasSameName   = errors.BadRequest.New("folder already has the same name").T("folder.renaming-same-name")
	ErrMediaAlreadyHasSameName    = errors.BadRequest.New("media already has the same name").T("media.renaming-same-name")
	ErrMediaAlreadyHasSameFolder  = errors.BadRequest.New("media already in this folder").T("media.moving-same-folder")
	ErrMediaAlreadyExistsInFolder = errors.Conflict.New("folder with the same name already exists in this folder").T("media.conflict")
	ErrFolderNotFound             = errors.NotFound.New("folder not found").T("folder.not-found")
	ErrMediaNotFound              = errors.NotFound.New("media not found").T("media.not-found")
	ErrOneOfMediasNotExists       = errors.BadRequest.New("some medias do not exist").T("media.not-exists")
	ErrMaxFileSize                = errors.BadRequest.New("media file size too large").T("media.file.size")
)

Functions

This section is empty.

Types

type CreateFolder

type CreateFolder struct {
	Name           string     `json:"name" validate:"required,notBlank,min=3,max=50"`
	ParentFolderId *uuid.UUID `json:"parentFolderId,omitempty" validate:"omitempty,notBlank"`
}

type CreateMedia

type CreateMedia struct {
	Filename string        `validate:"required,min=3"`
	Size     int64         `validate:""`
	Alt      string        `validate:"omitempty,min=3,max=50"`
	Title    string        `validate:"omitempty,min=3,max=50"`
	FolderId *uuid.UUID    `validate:"omitempty,notBlank"`
	File     io.ReadSeeker `validate:"required"`
}

type CreateMediasList

type CreateMediasList struct {
	FolderId *uuid.UUID  `validate:"omitempty,notBlank"`
	Files    []MediaFile `validate:"required,min=1,max=10,unique=Filename,dive"`
}

type FileFields

type FileFields struct {
	Id   uuid.UUID      `json:"id"`
	Name string         `json:"name"`
	Size utils.Filesize `json:"size"`
	Url  string         `json:"url"`
	Ext  string         `json:"ext"`
}

type FileStorage

type FileStorage interface {
	Upload(ctx context.Context, media *UploadFile) error
	UploadList(ctx context.Context, media ...UploadFile) error
	Delete(ctx context.Context, keys ...string) error
	Move(ctx context.Context, oldKey string, newKey string) error
	GetSize(ctx context.Context, key string) (int64, error)
}

type Filter

type Filter struct {
	Name         string
	FolderId     *uuid.UUID `validate:"omitempty,notBlank"`
	WithFolderId bool
}

type FolderAndMedia

type FolderAndMedia struct {
	ResourceType string         `json:"resourceType"`
	Id           uuid.UUID      `json:"id"`
	Name         string         `json:"name"`
	Size         utils.Filesize `json:"size"`
	FolderId     *uuid.UUID     `json:"parentFolderId"`
	UpdatedAt    utils.Time     `json:"updatedAt"`
	Filepath     string         `json:"filepath,omitempty"`
	Ext          string         `json:"ext,omitempty"`
}

type FolderAndMedias

type FolderAndMedias struct {
	ResourceType string        `json:"resourceType"`
	FolderFields *FolderFields `json:"folderFields,omitempty"`
	FileFields   *FileFields   `json:"fileFields,omitempty"`
}

type FolderAndMediasList

type FolderAndMediasList struct {
	Total       int64              `json:"total"`
	Items       []FolderAndMedias  `json:"items"`
	Breadcrumbs []FolderBreadcrumb `json:"breadcrumbs"`
}

type FolderBreadcrumb

type FolderBreadcrumb struct {
	Name     string     `json:"name"`
	FolderId *uuid.UUID `json:"folderId"`
}

type FolderDetail

type FolderDetail struct {
	Id       uuid.UUID      `json:"id"`
	Name     string         `json:"name"`
	Size     utils.Filesize `json:"size"`
	FolderId *uuid.UUID     `json:"parentFolderId"`
}

type FolderFields

type FolderFields struct {
	Id   uuid.UUID      `json:"id"`
	Name string         `json:"name"`
	Size utils.Filesize `json:"size"`
}

type FolderFilter

type FolderFilter struct {
	Limit  int    `validate:"required,min=10,max=100"`
	Offset int    `validate:"min=0"`
	Sort   string ``
	Order  string `validate:"omitempty,oneof=asc desc"`
	Filter Filter ``
}

type FolderRepository

type FolderRepository interface {
	Has(ctx context.Context, id uuid.UUID) bool
	HasByFilter(ctx context.Context, filter Filter) bool

	Get(ctx context.Context, u uuid.UUID) (*entity2.Folder, error)
	GetWithSize(ctx context.Context, u uuid.UUID) (*FolderDetail, error)
	Create(ctx context.Context, folders ...*entity2.Folder) error
	Update(ctx context.Context, folder *entity2.Folder) error
	Delete(ctx context.Context, id uuid.UUID) error
	List(ctx context.Context, filter Filter) ([]*entity2.Folder, error)

	HasSubFolder(ctx context.Context, id uuid.UUID, subFolderId *uuid.UUID) (bool, error)

	GetFolderPath(ctx context.Context, id uuid.UUID) (folderPath string, err error)
	GetFolderMediaFilePaths(ctx context.Context, id *uuid.UUID) (mediaFilepath []string, err error)
	GetAllFolderMedias(ctx context.Context, id uuid.UUID) ([]*UpdateMediaDto, error)
	GetFoldersTree(ctx context.Context) ([]*FolderResponse, error)
	GetFoldersAndMedias(ctx context.Context, filter FolderFilter) (*FoldersAndMediasList, error)
	GetFolderParents(ctx context.Context, filter Filter) ([]FolderResponse, error)
}

type FolderResponse

type FolderResponse struct {
	Id         uuid.UUID  `json:"id"`
	Name       string     `json:"name"`
	DepthLevel uint       `json:"depthLevel"`
	FolderId   *uuid.UUID `json:"parentFolderId"`
}

type Folders

type Folders struct {
	callbacks.Callbacks
	// contains filtered or unexported fields
}

Folders сервис работы с папками

func NewFolders

func NewFolders(
	folderRepository FolderRepository,
	mediaRepository MediaRepository,
	mediaStorage FileStorage,
	mediaProvider MediaProvider,
	callbacks callbacks.Callbacks,
) *Folders

NewFolders конструктор

func (Folders) Create

func (f Folders) Create(ctx context.Context, action CreateFolder) (*uuid.UUID, error)

Create создание папки

func (Folders) Delete

func (f Folders) Delete(ctx context.Context, action GetFolder) error

Delete удаление папко по id

func (Folders) Get

func (f Folders) Get(ctx context.Context, action GetFolder) (*FolderDetail, error)

Get получение папки

func (Folders) GetAll

func (f Folders) GetAll(ctx context.Context, filter FolderFilter) (*FolderAndMediasList, error)

GetAll получение папок и медиа, лежащих в одной папке

func (Folders) GetTree

func (f Folders) GetTree(ctx context.Context) ([]*FolderResponse, error)

GetTree получение дерева папок

func (Folders) Move

func (f Folders) Move(ctx context.Context, action MoveFolder) error

Move перемещение папки

func (Folders) Rename

func (f Folders) Rename(ctx context.Context, action RenameFolder) error

Rename переименование папки

type FoldersAndMediasList

type FoldersAndMediasList struct {
	Total int64
	Items []FolderAndMedia
}

type GetFolder

type GetFolder struct {
	Id uuid.UUID `json:"id" validate:"required,notBlank"`
}

type GetMedia

type GetMedia struct {
	Id uuid.UUID `json:"id" validate:"required,notBlank"`
}

type ListMediasShorts

type ListMediasShorts struct {
	Ids []uuid.UUID `json:"ids" validate:"required,min=1,max=1000"`
}

type MediaFile

type MediaFile struct {
	Filename string        `validate:"required,min=3"`
	Size     int64         `validate:""`
	File     io.ReadSeeker `validate:"required"`
}

type MediaFilter

type MediaFilter struct {
	FolderId     *uuid.UUID
	WithFolderId bool
	Filename     string
	Filenames    []string
	Name         string
	Ext          string
	Filepath     interface{}
	InIds        []uuid.UUID
}

type MediaPreview

type MediaPreview struct {
	Id          uuid.UUID      `json:"id"`
	Name        string         `json:"name"`
	Ext         string         `json:"ext"`
	Size        utils.Filesize `json:"size"`
	Alt         string         `json:"alt"`
	Title       string         `json:"title"`
	ContentType string         `json:"contentType"`
	Url         string         `json:"url"`
	UpdatedAt   utils.Time     `json:"updatedAt"`
	FolderId    *uuid.UUID     `json:"folderId"`
}

type MediaProvider

type MediaProvider interface {
	GetUrlByFilepath(mediaFilepath string) string
	GetUrlById(mediaId uuid.UUID) (string, error)
}

type MediaRepository

type MediaRepository interface {
	Has(ctx context.Context, id uuid.UUID) bool
	HasByFilter(ctx context.Context, filter MediaFilter) bool
	Create(ctx context.Context, medias ...entity2.Media) error
	Get(ctx context.Context, id uuid.UUID) (*entity2.Media, error)
	Update(ctx context.Context, medias ...*UpdateMediaDto) error
	Delete(ctx context.Context, ids ...uuid.UUID) error
	GetShortList(ctx context.Context, ids []uuid.UUID) ([]entity2.Media, error)
	Count(ctx context.Context, filter MediaFilter) (int, error)
}

type MediaShort

type MediaShort struct {
	Id    uuid.UUID `json:"id"`
	Alt   string    `json:"alt"`
	Title string    `json:"title"`
	Url   string    `json:"url"`
}

type MediaShortList

type MediaShortList struct {
	Items []MediaShort `json:"items"`
}

type Medias

type Medias struct {
	callbacks.Callbacks
	// contains filtered or unexported fields
}

Medias сервис работы с медиа

func NewMedias

func NewMedias(
	mediaRepository MediaRepository,
	folderRepository FolderRepository,
	storage FileStorage,
	mediaProvider MediaProvider,
	callbacks callbacks.Callbacks,
) *Medias

NewMedias конструктор

func (Medias) CheckIds

func (m Medias) CheckIds(ctx context.Context, ids ...uuid.UUID) error

CheckIds Проверяет существование медиа с такими id

func (Medias) Create

func (m Medias) Create(ctx context.Context, action CreateMedia) (*uuid.UUID, error)

Create создание медиа

func (Medias) Delete

func (m Medias) Delete(ctx context.Context, dto GetMedia) error

Delete удаление медиа по id

func (Medias) Get

func (m Medias) Get(ctx context.Context, dto GetMedia) (*MediaPreview, error)

Get получение медиа по id

func (Medias) List

List получение списка медиа превью

func (Medias) Move

func (m Medias) Move(ctx context.Context, dto MoveMedia) error

Move перемещение медиа

func (Medias) Rename

func (m Medias) Rename(ctx context.Context, dto RenameMedia) error

Rename переименование медиа

func (Medias) Upload

func (m Medias) Upload(ctx context.Context, dto CreateMedia) (string, error)

Upload загрузка нового медиа

func (Medias) UploadList

func (m Medias) UploadList(ctx context.Context, dto CreateMediasList) ([]uuid.UUID, error)

UploadList загрузка нескольких медиа

type MoveFolder

type MoveFolder struct {
	Id             uuid.UUID  `json:"id" validate:"required,notBlank"`
	ParentFolderId *uuid.UUID `json:"parentFolderId,omitempty" validate:"omitempty,notBlank"`
}

type MoveMedia

type MoveMedia struct {
	Id       uuid.UUID  `validate:"required,notBlank"`
	FolderId *uuid.UUID `validate:"omitempty,notBlank" json:"folderId"`
}

type RenameFolder

type RenameFolder struct {
	Id   uuid.UUID `json:"id" validate:"required,notBlank"`
	Name string    `json:"name" validate:"required,notBlank,min=3,max=50"`
}

type RenameMedia

type RenameMedia struct {
	Id   uuid.UUID `validate:"required,notBlank"`
	Name string    `validate:"required,notBlank,min=3,max=50" json:"name"`
}

type UpdateMediaDto

type UpdateMediaDto struct {
	Id          uuid.UUID  `gorm:"column:id"`
	Name        string     `gorm:"column:name"`
	Filename    string     `gorm:"column:filename"`
	Filepath    string     `gorm:"column:filepath"`
	FolderId    *uuid.UUID `gorm:"column:folder_id"`
	NewFilepath string     `gorm:"column:new_filepath"`
}

type UploadFile

type UploadFile struct {
	Key         string
	ContentType string
	File        io.ReadSeeker
}

Jump to

Keyboard shortcuts

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