usecase

package
v0.0.0-...-1f1dc5f Latest Latest
Warning

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

Go to latest
Published: Jun 30, 2026 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Overview

Package usecase coordinates system setting and dictionary workflows.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ConfigInput

type ConfigInput struct {
	Key    string
	Name   string
	Value  string
	Public bool
}

ConfigInput carries a system config value update.

type Dictionary

type Dictionary struct {
	ID        int64            `json:"id"`
	Code      string           `json:"code"`
	Name      string           `json:"name"`
	Items     []DictionaryItem `json:"items"`
	CreatedAt time.Time        `json:"created_at"`
	UpdatedAt time.Time        `json:"updated_at"`
}

Dictionary is the adapter-facing dictionary DTO.

type DictionaryBundle

type DictionaryBundle struct {
	ExportTime   string              `json:"export_time"`
	Dictionaries []VersionDictionary `json:"dictionaries"`
}

DictionaryBundle is the portable JSON shape for dictionary export and import.

type DictionaryInput

type DictionaryInput struct {
	Code string
	Name string
}

DictionaryInput carries dictionary creation fields.

type DictionaryItem

type DictionaryItem struct {
	ID       int64            `json:"id"`
	ParentID int64            `json:"parent_id"`
	Label    string           `json:"label"`
	Value    string           `json:"value"`
	Extend   string           `json:"extend"`
	Sort     int              `json:"sort"`
	Active   bool             `json:"active"`
	Level    int              `json:"level"`
	Path     string           `json:"path"`
	Children []DictionaryItem `json:"children"`
}

DictionaryItem is the adapter-facing dictionary item DTO.

type DictionaryItemInput

type DictionaryItemInput struct {
	ID       int64
	ParentID int64
	Label    string
	Value    string
	Extend   string
	Sort     int
	Active   bool
}

DictionaryItemInput carries dictionary item fields.

type ExportVersionInput

type ExportVersionInput struct {
	Version       string
	Name          string
	Description   string
	MenuIDs       []int64
	APIIDs        []int64
	DictionaryIDs []int64
}

ExportVersionInput selects resources to pack into a version bundle.

type Option

type Option func(*Usecase)

Option customizes settings usecase dependencies.

func WithVersionCatalog

func WithVersionCatalog(catalog VersionCatalog) Option

WithVersionCatalog installs the cross-module catalog used by version bundles.

type ParamInput

type ParamInput struct {
	Name  string
	Key   string
	Value string
	Desc  string
}

ParamInput carries mutable system parameter fields.

type ParamListInput

type ParamListInput struct {
	Page     int
	PageSize int
	Name     string
	Key      string
}

ParamListInput carries pagination and filters for parameter lists.

type ParamListOutput

type ParamListOutput struct {
	Items    []SystemParam
	Page     int
	PageSize int
	Total    int
}

ParamListOutput is a paginated parameter result.

type Store

type Store interface {
	ListConfigs(context.Context) ([]domain.SystemConfig, error)
	UpsertConfig(context.Context, domain.SystemConfig) (domain.SystemConfig, error)
	DeleteConfig(context.Context, string) error
	ListParams(context.Context) ([]domain.SystemParam, error)
	FindParamByID(context.Context, int64) (domain.SystemParam, error)
	FindParamByKey(context.Context, string) (domain.SystemParam, error)
	CreateParam(context.Context, domain.SystemParam) (domain.SystemParam, error)
	UpdateParam(context.Context, domain.SystemParam) (domain.SystemParam, error)
	DeleteParam(context.Context, int64) error
	DeleteParams(context.Context, []int64) error
	ListDictionaries(context.Context) ([]domain.Dictionary, error)
	CreateDictionary(context.Context, domain.Dictionary) (domain.Dictionary, error)
	UpdateDictionary(context.Context, domain.Dictionary) (domain.Dictionary, error)
	DeleteDictionary(context.Context, string) error
	AddDictionaryItem(context.Context, string, domain.DictionaryItem) (domain.Dictionary, error)
	UpdateDictionaryItem(context.Context, string, domain.DictionaryItem) (domain.Dictionary, error)
	FindDictionaryItem(context.Context, string, int64) (domain.DictionaryItem, error)
	DeleteDictionaryItem(context.Context, string, int64) (domain.Dictionary, error)
	ListVersions(context.Context) ([]domain.SystemVersion, error)
	FindVersionByID(context.Context, int64) (domain.SystemVersion, error)
	CreateVersion(context.Context, domain.SystemVersion) (domain.SystemVersion, error)
	UpdateVersion(context.Context, domain.SystemVersion) (domain.SystemVersion, error)
	DeleteVersion(context.Context, int64) error
	DeleteVersions(context.Context, []int64) error
}

Store persists system settings and dictionaries.

type SystemConfig

type SystemConfig struct {
	Key       string    `json:"key"`
	Name      string    `json:"name"`
	Value     string    `json:"value"`
	Public    bool      `json:"public"`
	UpdatedAt time.Time `json:"updated_at"`
}

SystemConfig is the adapter-facing config DTO.

type SystemParam

type SystemParam struct {
	ID        int64     `json:"id"`
	Name      string    `json:"name"`
	Key       string    `json:"key"`
	Value     string    `json:"value"`
	Desc      string    `json:"desc"`
	CreatedAt time.Time `json:"created_at"`
	UpdatedAt time.Time `json:"updated_at"`
}

SystemParam is the adapter-facing parameter DTO.

type SystemVersion

type SystemVersion struct {
	ID          int64     `json:"id"`
	Version     string    `json:"version"`
	Name        string    `json:"name"`
	Description string    `json:"description"`
	Data        string    `json:"-"`
	PublishedAt time.Time `json:"published_at"`
	CreatedAt   time.Time `json:"created_at"`
	UpdatedAt   time.Time `json:"updated_at"`
}

SystemVersion is the adapter-facing release record DTO.

type UpdateDictionaryInput

type UpdateDictionaryInput struct {
	Code string
	Name string
}

UpdateDictionaryInput carries mutable dictionary fields.

type UpdateParamInput

type UpdateParamInput struct {
	ID    int64
	Name  string
	Key   string
	Value string
	Desc  string
}

UpdateParamInput carries mutable parameter fields with the target id.

type UpdateVersionInput

type UpdateVersionInput struct {
	ID          int64
	Version     string
	Name        string
	Description string
	Data        string
	PublishedAt time.Time
}

UpdateVersionInput carries mutable release record fields.

type Usecase

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

Usecase coordinates system setting and dictionary rules.

func New

func New(store Store, opts ...Option) *Usecase

New creates a settings usecase.

func (*Usecase) AddDictionaryItem

func (u *Usecase) AddDictionaryItem(ctx context.Context, code string, input DictionaryItemInput) (Dictionary, error)

AddDictionaryItem appends one dictionary item.

func (*Usecase) CreateDictionary

func (u *Usecase) CreateDictionary(ctx context.Context, input DictionaryInput) (Dictionary, error)

CreateDictionary validates and stores a dictionary.

func (*Usecase) CreateParam

func (u *Usecase) CreateParam(ctx context.Context, input ParamInput) (SystemParam, error)

CreateParam validates and stores one system parameter.

func (*Usecase) CreateVersion

func (u *Usecase) CreateVersion(ctx context.Context, input VersionInput) (SystemVersion, error)

CreateVersion validates and stores one release record.

func (*Usecase) DeleteConfig

func (u *Usecase) DeleteConfig(ctx context.Context, key string) error

DeleteConfig removes one operator-managed config key.

func (*Usecase) DeleteDictionary

func (u *Usecase) DeleteDictionary(ctx context.Context, code string) error

DeleteDictionary removes a dictionary and its items unless it is a runtime seed invariant.

func (*Usecase) DeleteDictionaryItem

func (u *Usecase) DeleteDictionaryItem(ctx context.Context, code string, itemID int64) (Dictionary, error)

DeleteDictionaryItem removes one dictionary item under a dictionary.

func (*Usecase) DeleteParam

func (u *Usecase) DeleteParam(ctx context.Context, id int64) error

DeleteParam removes one system parameter by id.

func (*Usecase) DeleteParams

func (u *Usecase) DeleteParams(ctx context.Context, ids []int64) error

DeleteParams removes system parameters by id.

func (*Usecase) DeleteVersion

func (u *Usecase) DeleteVersion(ctx context.Context, id int64) error

DeleteVersion removes one release record.

func (*Usecase) DeleteVersions

func (u *Usecase) DeleteVersions(ctx context.Context, ids []int64) error

DeleteVersions removes release records by id.

func (*Usecase) DictionaryBundleJSON

func (u *Usecase) DictionaryBundleJSON(ctx context.Context) ([]byte, error)

DictionaryBundleJSON returns a stable JSON export for all dictionaries.

func (*Usecase) ExportDictionaries

func (u *Usecase) ExportDictionaries(ctx context.Context) (DictionaryBundle, error)

ExportDictionaries returns all dictionaries in a portable JSON bundle shape.

func (*Usecase) ExportVersion

func (u *Usecase) ExportVersion(ctx context.Context, input ExportVersionInput) (SystemVersion, error)

ExportVersion creates a version bundle from selected menus, APIs, and dictionaries.

func (*Usecase) FindParam

func (u *Usecase) FindParam(ctx context.Context, id int64) (SystemParam, error)

FindParam returns one system parameter by id.

func (*Usecase) FindParamByKey

func (u *Usecase) FindParamByKey(ctx context.Context, key string) (SystemParam, error)

FindParamByKey returns one system parameter by key.

func (*Usecase) FindVersion

func (u *Usecase) FindVersion(ctx context.Context, id int64) (SystemVersion, error)

FindVersion returns one release record by id.

func (*Usecase) ImportDictionaries

func (u *Usecase) ImportDictionaries(ctx context.Context, bundle DictionaryBundle) ([]Dictionary, error)

ImportDictionaries validates and imports a dictionary bundle.

func (*Usecase) ImportVersion

func (u *Usecase) ImportVersion(ctx context.Context, bundle VersionBundle) (SystemVersion, error)

ImportVersion imports a version bundle and records the import result.

func (*Usecase) ListConfigs

func (u *Usecase) ListConfigs(ctx context.Context) ([]SystemConfig, error)

ListConfigs returns system configs.

func (*Usecase) ListDictionaries

func (u *Usecase) ListDictionaries(ctx context.Context) ([]Dictionary, error)

ListDictionaries returns dictionaries with their items.

func (*Usecase) ListParams

func (u *Usecase) ListParams(ctx context.Context, input ParamListInput) (ParamListOutput, error)

ListParams returns paginated system parameters.

func (*Usecase) ListVersions

func (u *Usecase) ListVersions(ctx context.Context) ([]SystemVersion, error)

ListVersions returns release records ordered by publication time.

func (*Usecase) UpdateDictionary

func (u *Usecase) UpdateDictionary(ctx context.Context, input UpdateDictionaryInput) (Dictionary, error)

UpdateDictionary changes a dictionary name while keeping its stable code.

func (*Usecase) UpdateDictionaryItem

func (u *Usecase) UpdateDictionaryItem(ctx context.Context, code string, input DictionaryItemInput) (Dictionary, error)

UpdateDictionaryItem updates one dictionary item.

func (*Usecase) UpdateParam

func (u *Usecase) UpdateParam(ctx context.Context, input UpdateParamInput) (SystemParam, error)

UpdateParam replaces mutable fields for one system parameter.

func (*Usecase) UpdateVersion

func (u *Usecase) UpdateVersion(ctx context.Context, input UpdateVersionInput) (SystemVersion, error)

UpdateVersion changes one release record by id.

func (*Usecase) UpsertConfig

func (u *Usecase) UpsertConfig(ctx context.Context, input ConfigInput) (SystemConfig, error)

UpsertConfig creates or updates a system config.

func (*Usecase) VersionJSON

func (u *Usecase) VersionJSON(ctx context.Context, id int64) ([]byte, SystemVersion, error)

VersionJSON returns a stable JSON representation of one release record.

type VersionAPI

type VersionAPI struct {
	Method      string `json:"method"`
	Path        string `json:"path"`
	Description string `json:"description"`
	Group       string `json:"group"`
	Permission  string `json:"permission"`
	Public      bool   `json:"public"`
}

VersionAPI is an API route stored in a version bundle.

type VersionBundle

type VersionBundle struct {
	Version      VersionInfo         `json:"version"`
	Menus        []VersionMenu       `json:"menus"`
	APIs         []VersionAPI        `json:"apis"`
	Dictionaries []VersionDictionary `json:"dictionaries"`
}

VersionBundle is the portable JSON shape for version export and import.

type VersionButton

type VersionButton struct {
	Name        string `json:"name"`
	Description string `json:"description"`
}

VersionButton is a menu button stored in a version bundle.

type VersionCatalog

type VersionCatalog interface {
	ExportVersionMenus(context.Context, []int64) ([]VersionMenu, error)
	ExportVersionAPIs(context.Context, []int64) ([]VersionAPI, error)
	ImportVersionMenus(context.Context, []VersionMenu) error
	ImportVersionAPIs(context.Context, []VersionAPI) error
}

VersionCatalog imports and exports access-owned resources for version bundles.

type VersionDictionary

type VersionDictionary struct {
	Code  string                  `json:"code"`
	Name  string                  `json:"name"`
	Items []VersionDictionaryItem `json:"items"`
}

VersionDictionary is a dictionary stored in a version bundle.

type VersionDictionaryItem

type VersionDictionaryItem struct {
	ParentID int64  `json:"parent_id,omitempty"`
	Label    string `json:"label"`
	Value    string `json:"value"`
	Extend   string `json:"extend,omitempty"`
	Sort     int    `json:"sort"`
	Active   bool   `json:"active"`
	Level    int    `json:"level,omitempty"`
	Path     string `json:"path,omitempty"`
}

VersionDictionaryItem is a dictionary item stored in a version bundle.

type VersionInfo

type VersionInfo struct {
	Name        string `json:"name"`
	Code        string `json:"code"`
	Description string `json:"description"`
	ExportTime  string `json:"export_time"`
}

VersionInfo stores version metadata inside an exported bundle.

type VersionInput

type VersionInput struct {
	Version     string
	Name        string
	Description string
	Data        string
	PublishedAt time.Time
}

VersionInput carries release record fields.

type VersionMenu

type VersionMenu struct {
	Name       string          `json:"name"`
	Path       string          `json:"path"`
	Icon       string          `json:"icon"`
	Hidden     bool            `json:"hidden"`
	Component  string          `json:"component"`
	Meta       VersionMenuMeta `json:"meta"`
	Permission string          `json:"permission"`
	Sort       int             `json:"sort"`
	Active     bool            `json:"active"`
	Buttons    []VersionButton `json:"buttons"`
	Children   []VersionMenu   `json:"children,omitempty"`
}

VersionMenu is the menu shape stored in a version bundle.

type VersionMenuMeta

type VersionMenuMeta struct {
	ActiveName     string `json:"active_name"`
	KeepAlive      bool   `json:"keep_alive"`
	DefaultMenu    bool   `json:"default_menu"`
	CloseTab       bool   `json:"close_tab"`
	TransitionType string `json:"transition_type"`
}

VersionMenuMeta stores router metadata in a version bundle.

Jump to

Keyboard shortcuts

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