组织初始化接口 GET /api/auth/organizations 现在为每项授权公司附带
warehouse 摘要({id, name, status, location: {id, name, status} | null} | null),
结构与切换接口一致,供普通用户在公司切换器直接展示,无需放开管理员仓库配置接口。
- model:新增 WarehouseSummary/LocationSummary/OrganizationSummary,
OrganizationAccess 每项改为内嵌公司资料再加 warehouse 摘要。
- repository:新增 WarehouseRepository.Summary 复用切换接口的解析规则;
ListAccessible 逐公司补齐摘要,仓库或库位配置不唯一时报错而非随意取第一条,
无仓库、无库位或已停用如实返回,不回退旧公司数据。
- service:Switch 复用 List 已解析的摘要,响应格式保持不变。
- 测试:新增服务层 sqlmock 用例与仓储层 MySQL 集成用例,
覆盖启用唯一仓库加启用库位、无仓库、仓库停用三类。
77 lines
2.5 KiB
Go
77 lines
2.5 KiB
Go
package model
|
||
|
||
import (
|
||
"encoding/json"
|
||
"time"
|
||
)
|
||
|
||
// LocationSummary 是仓库摘要里的最小库位信息,字段与切换接口一致。
|
||
type LocationSummary struct {
|
||
ID int64 `json:"id"`
|
||
Name string `json:"name"`
|
||
Status string `json:"status"`
|
||
}
|
||
|
||
// WarehouseSummary 是组织初始化接口为每家公司附带的最小仓库摘要,结构与切换
|
||
// 接口一致。普通用户据此在公司切换器展示仓库、库位,无需调用管理员仓库配置接口。
|
||
type WarehouseSummary struct {
|
||
ID int64 `json:"id"`
|
||
Name string `json:"name"`
|
||
Status string `json:"status"`
|
||
Location *LocationSummary `json:"location"`
|
||
}
|
||
|
||
// OrganizationSummary 是授权公司列表项:公司资料加当前仓库摘要。内嵌
|
||
// Organization 让 JSON 中公司字段保持扁平,warehouse 无配置时为 null。
|
||
type OrganizationSummary struct {
|
||
Organization
|
||
Warehouse *WarehouseSummary `json:"warehouse"`
|
||
}
|
||
|
||
type OrganizationAccess struct {
|
||
Organizations []OrganizationSummary `json:"organizations"`
|
||
DefaultOrganizationID *int64 `json:"default_organization_id"`
|
||
}
|
||
|
||
type OrganizationAuditLog struct {
|
||
ID int64 `json:"id"`
|
||
ActorUserID int64 `json:"actor_user_id"`
|
||
OrganizationID *int64 `json:"organization_id"`
|
||
Action string `json:"action"`
|
||
OldValue json.RawMessage `json:"old_value"`
|
||
NewValue json.RawMessage `json:"new_value"`
|
||
CreatedAt time.Time `json:"created_at"`
|
||
}
|
||
|
||
type Organization struct {
|
||
ID int64 `json:"id"`
|
||
Code string `json:"code"`
|
||
Name string `json:"name"`
|
||
Status string `json:"status"`
|
||
DefaultTimezone string `json:"default_timezone"`
|
||
CreatedAt time.Time `json:"created_at"`
|
||
UpdatedAt time.Time `json:"updated_at"`
|
||
}
|
||
|
||
type Role struct {
|
||
ID int64 `json:"id"`
|
||
Code string `json:"code"`
|
||
Name string `json:"name"`
|
||
Enabled bool `json:"enabled"`
|
||
Permissions []Permission `json:"permissions"`
|
||
CreatedAt time.Time `json:"created_at"`
|
||
UpdatedAt time.Time `json:"updated_at"`
|
||
}
|
||
|
||
type Permission struct {
|
||
ID int64 `json:"id"`
|
||
Code string `json:"code"`
|
||
Name string `json:"name"`
|
||
}
|
||
|
||
type UpdateRoleRequest struct {
|
||
Name string `json:"name" binding:"required"`
|
||
Enabled bool `json:"enabled"`
|
||
PermissionCodes []string `json:"permission_codes"`
|
||
}
|