refactor platform account and access models
This commit is contained in:
@@ -2,8 +2,8 @@ package models
|
||||
|
||||
import "git.apinb.com/bsm-sdk/core/database"
|
||||
|
||||
// PlatfromAccount 对应 platfrom_account,表示平台总后台登录账号。
|
||||
type PlatfromAccount struct {
|
||||
// PlatformAccount 对应 platform_account,表示平台总后台登录账号。
|
||||
type PlatformAccount struct {
|
||||
Entity // 公共实体字段
|
||||
Username string `gorm:"column:username;type:varchar(64);uniqueIndex;not null" json:"username"` // 登录用户名
|
||||
DisplayName string `gorm:"column:display_name;type:varchar(64);not null;default:''" json:"display_name"` // 用户展示名称
|
||||
@@ -13,7 +13,7 @@ type PlatfromAccount struct {
|
||||
Phone string `gorm:"column:phone;type:varchar(32);uniqueIndex;not null;default:''" json:"phone"` // 手机号
|
||||
}
|
||||
|
||||
func init() { database.AppendMigrate(&PlatfromAccount{}) }
|
||||
func init() { database.AppendMigrate(&PlatformAccount{}) }
|
||||
|
||||
// TableName 返回与模型、文件名一致的单数数据表名。
|
||||
func (table *PlatfromAccount) TableName() string { return "platfrom_account" }
|
||||
func (table *PlatformAccount) TableName() string { return "platform_account" }
|
||||
23
backend/api/internal/models/platform_models_test.go
Normal file
23
backend/api/internal/models/platform_models_test.go
Normal file
@@ -0,0 +1,23 @@
|
||||
package models
|
||||
|
||||
import "testing"
|
||||
|
||||
func TestPlatformModelTableNames(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
table interface{ TableName() string }
|
||||
want string
|
||||
}{
|
||||
{name: "account", table: &PlatformAccount{}, want: "platform_account"},
|
||||
{name: "menu", table: &PlatformMenu{}, want: "platform_menu"},
|
||||
{name: "role", table: &PlatformRole{}, want: "platform_role"},
|
||||
{name: "role menu", table: &PlatformRoleMenu{}, want: "platform_role_menu"},
|
||||
}
|
||||
for _, test := range tests {
|
||||
t.Run(test.name, func(t *testing.T) {
|
||||
if got := test.table.TableName(); got != test.want {
|
||||
t.Fatalf("TableName() = %q, want %q", got, test.want)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
@@ -6,15 +6,15 @@ import (
|
||||
"git.apinb.com/bsm-sdk/core/database"
|
||||
)
|
||||
|
||||
// PlatformRoleMenuRelation 对应 platform_role_menu_relation,记录角色拥有的菜单权限。
|
||||
type PlatformRoleMenuRelation struct {
|
||||
// PlatformRoleMenu 对应 platform_role_menu,记录角色拥有的菜单权限。
|
||||
type PlatformRoleMenu struct {
|
||||
ID uint64 `gorm:"column:id;primaryKey;autoIncrement" json:"id"` // 数据库自增主键
|
||||
PlatformRoleID uint64 `gorm:"column:platform_role_id;not null;uniqueIndex:uk_platform_role_menu" json:"platform_role_id"` // 角色自增主键
|
||||
PlatformMenuID uint64 `gorm:"column:platform_menu_id;not null;uniqueIndex:uk_platform_role_menu" json:"platform_menu_id"` // 菜单自增主键
|
||||
CreatedAt time.Time `gorm:"column:created_at;type:timestamptz;not null" json:"created_at"` // 创建时间
|
||||
}
|
||||
|
||||
func init() { database.AppendMigrate(&PlatformRoleMenuRelation{}) }
|
||||
func init() { database.AppendMigrate(&PlatformRoleMenu{}) }
|
||||
|
||||
// TableName 返回与模型、文件名一致的单数数据表名。
|
||||
func (table *PlatformRoleMenuRelation) TableName() string { return "platform_role_menu_relation" }
|
||||
func (table *PlatformRoleMenu) TableName() string { return "platform_role_menu" }
|
||||
@@ -28,11 +28,11 @@ func GetDashboardOverview() (DashboardOverview, error) {
|
||||
return overview, nil
|
||||
}
|
||||
|
||||
// ListPlatfromAccount 返回平台账号分页列表,敏感字段由接口展示层脱敏。
|
||||
func ListPlatfromAccount(page, size int) ([]PlatfromAccount, int64, error) {
|
||||
var list []PlatfromAccount
|
||||
// ListPlatformAccount 返回平台账号分页列表,敏感字段由接口展示层脱敏。
|
||||
func ListPlatformAccount(page, size int) ([]PlatformAccount, int64, error) {
|
||||
var list []PlatformAccount
|
||||
var total int64
|
||||
databaseQuery := impl.DBService.Model(&PlatfromAccount{})
|
||||
databaseQuery := impl.DBService.Model(&PlatformAccount{})
|
||||
if err := databaseQuery.Count(&total).Error; err != nil {
|
||||
return nil, 0, err
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user