Documentation
¶
Overview ¶
Package usecase coordinates system setting and dictionary workflows.
Index ¶
- type ConfigInput
- type Dictionary
- type DictionaryBundle
- type DictionaryInput
- type DictionaryItem
- type DictionaryItemInput
- type ExportVersionInput
- type Option
- type ParamInput
- type ParamListInput
- type ParamListOutput
- type Store
- type SystemConfig
- type SystemParam
- type SystemVersion
- type UpdateDictionaryInput
- type UpdateParamInput
- type UpdateVersionInput
- type Usecase
- func (u *Usecase) AddDictionaryItem(ctx context.Context, code string, input DictionaryItemInput) (Dictionary, error)
- func (u *Usecase) CreateDictionary(ctx context.Context, input DictionaryInput) (Dictionary, error)
- func (u *Usecase) CreateParam(ctx context.Context, input ParamInput) (SystemParam, error)
- func (u *Usecase) CreateVersion(ctx context.Context, input VersionInput) (SystemVersion, error)
- func (u *Usecase) DeleteConfig(ctx context.Context, key string) error
- func (u *Usecase) DeleteDictionary(ctx context.Context, code string) error
- func (u *Usecase) DeleteDictionaryItem(ctx context.Context, code string, itemID int64) (Dictionary, error)
- func (u *Usecase) DeleteParam(ctx context.Context, id int64) error
- func (u *Usecase) DeleteParams(ctx context.Context, ids []int64) error
- func (u *Usecase) DeleteVersion(ctx context.Context, id int64) error
- func (u *Usecase) DeleteVersions(ctx context.Context, ids []int64) error
- func (u *Usecase) DictionaryBundleJSON(ctx context.Context) ([]byte, error)
- func (u *Usecase) ExportDictionaries(ctx context.Context) (DictionaryBundle, error)
- func (u *Usecase) ExportVersion(ctx context.Context, input ExportVersionInput) (SystemVersion, error)
- func (u *Usecase) FindParam(ctx context.Context, id int64) (SystemParam, error)
- func (u *Usecase) FindParamByKey(ctx context.Context, key string) (SystemParam, error)
- func (u *Usecase) FindVersion(ctx context.Context, id int64) (SystemVersion, error)
- func (u *Usecase) ImportDictionaries(ctx context.Context, bundle DictionaryBundle) ([]Dictionary, error)
- func (u *Usecase) ImportVersion(ctx context.Context, bundle VersionBundle) (SystemVersion, error)
- func (u *Usecase) ListConfigs(ctx context.Context) ([]SystemConfig, error)
- func (u *Usecase) ListDictionaries(ctx context.Context) ([]Dictionary, error)
- func (u *Usecase) ListParams(ctx context.Context, input ParamListInput) (ParamListOutput, error)
- func (u *Usecase) ListVersions(ctx context.Context) ([]SystemVersion, error)
- func (u *Usecase) UpdateDictionary(ctx context.Context, input UpdateDictionaryInput) (Dictionary, error)
- func (u *Usecase) UpdateDictionaryItem(ctx context.Context, code string, input DictionaryItemInput) (Dictionary, error)
- func (u *Usecase) UpdateParam(ctx context.Context, input UpdateParamInput) (SystemParam, error)
- func (u *Usecase) UpdateVersion(ctx context.Context, input UpdateVersionInput) (SystemVersion, error)
- func (u *Usecase) UpsertConfig(ctx context.Context, input ConfigInput) (SystemConfig, error)
- func (u *Usecase) VersionJSON(ctx context.Context, id int64) ([]byte, SystemVersion, error)
- type VersionAPI
- type VersionBundle
- type VersionButton
- type VersionCatalog
- type VersionDictionary
- type VersionDictionaryItem
- type VersionInfo
- type VersionInput
- type VersionMenu
- type VersionMenuMeta
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type ConfigInput ¶
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 ¶
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 ¶
ParamInput carries mutable system parameter fields.
type ParamListInput ¶
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 ¶
UpdateDictionaryInput carries mutable dictionary fields.
type UpdateParamInput ¶
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 (*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 ¶
DeleteConfig removes one operator-managed config key.
func (*Usecase) DeleteDictionary ¶
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 ¶
DeleteParam removes one system parameter by id.
func (*Usecase) DeleteParams ¶
DeleteParams removes system parameters by id.
func (*Usecase) DeleteVersion ¶
DeleteVersion removes one release record.
func (*Usecase) DeleteVersions ¶
DeleteVersions removes release records by id.
func (*Usecase) DictionaryBundleJSON ¶
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) FindParamByKey ¶
FindParamByKey returns one system parameter by key.
func (*Usecase) FindVersion ¶
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 ¶
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 ¶
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.