org 模块: - tenants 表 (UUID PK, name, slug, status, settings) - 完整 CRUD API: /api/v1/org/tenants - 多租户隔离 audit 模块: - audit_logs 表 (actor, action, resource, IP, 时间) - 查询 API: /api/v1/audit/logs (支持分页+筛选) - 按 tenant_id/user_id/action/resource 过滤
49 lines
1.2 KiB
Go
49 lines
1.2 KiB
Go
package domain
|
|
|
|
import "time"
|
|
|
|
type Tenant struct {
|
|
ID string `json:"id" gorm:"type:uuid;primaryKey;default:gen_random_uuid()"`
|
|
Name string `json:"name" gorm:"size:128;not null"`
|
|
Slug string `json:"slug" gorm:"uniqueIndex;size:64;not null"`
|
|
Status int `json:"status" gorm:"default:1"`
|
|
Settings string `json:"settings" gorm:"type:text"`
|
|
CreatedAt time.Time `json:"created_at"`
|
|
UpdatedAt time.Time `json:"updated_at"`
|
|
}
|
|
|
|
func (Tenant) TableName() string {
|
|
return "tenants"
|
|
}
|
|
|
|
type TenantDTO struct {
|
|
ID string `json:"id"`
|
|
Name string `json:"name"`
|
|
Slug string `json:"slug"`
|
|
Status int `json:"status"`
|
|
CreatedAt time.Time `json:"created_at"`
|
|
UpdatedAt time.Time `json:"updated_at"`
|
|
}
|
|
|
|
func ToTenantDTO(t *Tenant) TenantDTO {
|
|
return TenantDTO{
|
|
ID: t.ID,
|
|
Name: t.Name,
|
|
Slug: t.Slug,
|
|
Status: t.Status,
|
|
CreatedAt: t.CreatedAt,
|
|
UpdatedAt: t.UpdatedAt,
|
|
}
|
|
}
|
|
|
|
type CreateTenantRequest struct {
|
|
Name string `json:"name" binding:"required"`
|
|
Slug string `json:"slug" binding:"required"`
|
|
}
|
|
|
|
type UpdateTenantRequest struct {
|
|
Name string `json:"name"`
|
|
Slug string `json:"slug"`
|
|
Status *int `json:"status"`
|
|
}
|