actions

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Nov 10, 2023 License: MIT Imports: 8 Imported by: 3

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrMenuAlreadyExists = errors.Conflict.New("menu with the same code already exists").T("menu.conflict")
	ErrMaxPosition       = errors.BadRequest.New("position of menu item too large").T("menu-item.position-too-large")
	ErrFieldNotUpdatable = errors.BadRequest.New("field is not updatable")
	ErrMaxDepthExceeded  = errors.BadRequest.New("the maximum depth level for menu items has been reached").T("menu-item.max-depth-exceeded")
	ErrMenuNotFound      = errors.NotFound.New("menu not found").T("menu.not-found")
	ErrMenuItemNotFound  = errors.NotFound.New("menu item does not exist").T("menu-item.not-found")
)

Functions

This section is empty.

Types

type AdditionalField

type AdditionalField struct {
	Code  string `json:"code" validate:"required,min=3,max=50"`
	Value string `json:"value" validate:"required,min=1"`
}

type CreateDomain

type CreateDomain struct {
	Domain string `json:"domain" validate:"required,url"`
}

type CreateMenu

type CreateMenu struct {
	Name string `json:"name" validate:"required,notBlank,min=3,max=50"`
	Code string `json:"code" validate:"required,min=3,max=50,sluggable"`
}

type CreateMenuItem

type CreateMenuItem struct {
	MenuId           uuid.UUID         `json:"menuId" validate:"required,notBlank"`
	Name             string            `json:"name" validate:"required,notBlank,min=3,max=50"`
	DomainId         *uuid.UUID        `json:"domainId" validate:"omitempty,notBlank"`
	Url              string            `json:"url" validate:"omitempty,slashedSluggable"`
	AdditionalFields []AdditionalField `json:"additionalFields" validate:"omitempty,unique=Code,dive"`
	ParentMenuItemId *uuid.UUID        `json:"parentMenuItemId" validate:"omitempty,notBlank"`
}

type Domains

type Domains struct {
	// contains filtered or unexported fields
}

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

func NewDomains

func NewDomains(domainRepository DomainsRepository) *Domains

NewDomains конструктор

func (Domains) Create

func (d Domains) Create(ctx context.Context, action CreateDomain) (*uuid.UUID, error)

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

func (Domains) List

func (d Domains) List(ctx context.Context, action ListDomains) (*DomainsList, error)

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

type DomainsList

type DomainsList struct {
	Total int64           `json:"total"`
	Items []entity.Domain `json:"items"`
}

type DomainsListQuery

type DomainsListQuery struct {
	Pagination
}

type DomainsRepository

type DomainsRepository interface {
	Has(ctx context.Context, domain string) (bool, error)
	Create(ctx context.Context, domain entity.Domain) error
	List(ctx context.Context, query DomainsListQuery) ([]entity.Domain, error)
	Count(ctx context.Context) (int64, error)
}

type GetMenu

type GetMenu struct {
	MenuId uuid.UUID `json:"menuId" validate:"required,notBlank"`
}

type GetMenuByCode

type GetMenuByCode struct {
	MenuCode string `json:"menuCode" validate:"required,min=3,max=50"`
}

type GetMenuItem

type GetMenuItem struct {
	MenuId     uuid.UUID `json:"menuId" validate:"required,notBlank"`
	MenuItemId uuid.UUID `json:"menuItemId" validate:"required,notBlank"`
}

type ListDomains

type ListDomains struct {
	Pagination
}

type ListMenuItems

type ListMenuItems struct {
	Sort   string         `json:"sort" validate:"omitempty,oneof=id name position"`
	Order  string         `json:"order" validate:"omitempty,oneof=asc desc"`
	Filter MenuItemFilter `json:"filter"`
}

type ListMenus

type ListMenus struct {
	Pagination
	Sort  string `json:"sort" validate:"omitempty,oneof=name"`
	Order string `json:"order" validate:"omitempty,oneof=asc desc"`
}
type MenuFilter struct {
	Offset int
	Limit  int
	Sort   string
	Order  string
}
type MenuItemFilter struct {
	MenuId   uuid.UUID  `json:"menuId" validate:"required,notBlank"`
	ParentId *uuid.UUID `json:"parentId,omitempty" validate:"omitempty,notBlank"`
}
type MenuItemPreview struct {
	Id       uuid.UUID `json:"id"`
	Name     string    `json:"name"`
	Url      string    `json:"url"`
	Position int64     `json:"position"`
}
type MenuItemRepository interface {
	Has(ctx context.Context, menuId, menuItemId uuid.UUID) (bool, error)
	Create(ctx context.Context, menuItem entity.MenuItem) error
	Update(ctx context.Context, menuItem entity.MenuItem) error
	Move(ctx context.Context, move MoveMenuItemQuery) error
	Delete(ctx context.Context, Id uuid.UUID) error
	Get(ctx context.Context, Id uuid.UUID) (*entity.MenuItem, error)
	List(ctx context.Context, filter MenuItemsListFilter) ([]entity.MenuItem, error)
	Count(ctx context.Context, filter MenuItemFilter) (int64, error)
	GetAsTree(ctx context.Context, menuCode string) ([]*entity.MenuItem, error)
	GetDepthLevel(ctx context.Context, id uuid.UUID) (int, error)
	GetMaxDepthLevel(ctx context.Context, parentId uuid.UUID) (int, error)
}

MenuItemRepository интерфейс репозитория работы с элементами меню

type MenuItemTree struct {
	Id               uuid.UUID       `json:"id"`
	ParentMenuItemId *uuid.UUID      `json:"-"`
	Name             string          `json:"name"`
	Url              string          `json:"url"`
	Position         int64           `json:"position"`
	AdditionalFields json.JSONB      `json:"additionalFields"`
	MenuItems        []*MenuItemTree `json:"menuItems,omitempty" gorm:"-"`
}
type MenuItems struct {
	callbacks.Callbacks
	// contains filtered or unexported fields
}

MenuItems сервис работы с элементами меню

func NewMenuItems

func NewMenuItems(
	menuRepository MenuRepository,
	menuItemRepository MenuItemRepository,
	maxMenuItemsDepth int,
	callbacks callbacks.Callbacks,
) *MenuItems

NewMenuItems конструктор

func (mi MenuItems) Create(ctx context.Context, action CreateMenuItem) (*uuid.UUID, error)

Create создание пункта меню

func (mi MenuItems) Delete(ctx context.Context, action GetMenuItem) error

Delete удаление пункта меню

func (mi MenuItems) Get(ctx context.Context, action GetMenuItem) (*entity.MenuItem, error)

Get получение пункта меню по id

func (mi MenuItems) GetTree(ctx context.Context, action GetMenuByCode) ([]*MenuItemTree, error)

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

func (mi MenuItems) List(ctx context.Context, action ListMenuItems) ([]MenuItemPreview, error)

List получение списка пунктов меню

func (mi MenuItems) Move(ctx context.Context, action MoveMenuItem) error

Move перемещение пункта меню

func (mi MenuItems) Update(ctx context.Context, action UpdateMenuItem) error

Update обновление пункта меню

type MenuItemsListFilter struct {
	Sort   string
	Order  string
	Filter MenuItemFilter
}
type MenuRepository interface {
	Has(ctx context.Context, id uuid.UUID) (bool, error)
	HasByCode(ctx context.Context, code string) (bool, error)
	Create(ctx context.Context, menu entity.Menu) error
	Update(ctx context.Context, menu *entity.Menu) error
	GetByCode(ctx context.Context, code string) (*entity.Menu, error)
	Get(ctx context.Context, Id uuid.UUID) (*entity.Menu, error)
	Delete(ctx context.Context, Id uuid.UUID) error
	List(ctx context.Context, filter MenuFilter) ([]entity.Menu, error)
	Count(ctx context.Context) (int64, error)
}

MenuRepository интерфейс репозитория работы с меню

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

Menus сервис работы с меню

func NewMenus

func NewMenus(
	menuRepository MenuRepository,
	callbacks callbacks.Callbacks,
) *Menus

NewMenus конструктор

func (m Menus) Create(ctx context.Context, action CreateMenu) (*uuid.UUID, error)

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

func (m Menus) Delete(ctx context.Context, action GetMenu) error

Delete удаление меню

func (m Menus) Get(ctx context.Context, action GetMenu) (*entity.Menu, error)

Get получение меня по id

func (m Menus) GetByCode(ctx context.Context, action GetMenuByCode) (*entity.Menu, error)

GetByCode получение меню по коду

func (m Menus) List(ctx context.Context, action ListMenus) (*MenusList, error)

List получение списка меню

func (m Menus) Update(ctx context.Context, action UpdateMenu) error

Update обновление меню

type MenusCallbacks struct {
	AfterCreate func(menu *entity.Menu)
	AfterUpdate func(oldMenu, newMenu *entity.Menu)
}

MenusCallbacks колбэки сервиса работы с меню

type MenusList struct {
	Total int64         `json:"total"`
	Items []entity.Menu `json:"items"`
}

type MoveMenuItem

type MoveMenuItem struct {
	MenuId           uuid.UUID  `json:"menuId" validate:"required,notBlank"`
	MenuItemId       uuid.UUID  `json:"menuItemId" validate:"required,notBlank"`
	ParentMenuItemId *uuid.UUID `json:"parentMenuItemId" validate:"omitempty,notBlank,nefield=MenuItemId"`
	Position         int64      `json:"position" validate:"required,min=1"`
}

type MoveMenuItemQuery

type MoveMenuItemQuery struct {
	MenuItemId          uuid.UUID
	OldParentMenuItemId *uuid.UUID
	NewParentMenuItemId *uuid.UUID
	OldPosition         int64
	NewPosition         int64
}

type Pagination

type Pagination struct {
	Offset int `json:"offset" validate:"min=0"`
	Limit  int `json:"limit" validate:"required,min=10,max=100"`
}

type UpdateMenu

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

type UpdateMenuItem

type UpdateMenuItem struct {
	MenuId           uuid.UUID         `json:"menuId" validate:"required,notBlank"`
	MenuItemId       uuid.UUID         `json:"menuItemId" validate:"required,notBlank"`
	Name             string            `json:"name" validate:"required,notBlank,min=3,max=50"`
	DomainId         *uuid.UUID        `json:"domainId" validate:"omitempty,notBlank"`
	Url              string            `json:"url" validate:"omitempty,slashedSluggable"`
	AdditionalFields []AdditionalField `json:"additionalFields" validate:"omitempty,unique=Code"`
}

Jump to

Keyboard shortcuts

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