From 7742d530ddb9b0c889693e037a52a0986cb8c041 Mon Sep 17 00:00:00 2001 From: slhmy <1484836413@qq.com> Date: Sat, 22 Jun 2024 10:35:51 +0800 Subject: [PATCH] Tidy model tag --- models/problem/problem.go | 10 +++++----- models/user/user.go | 16 ++++++++-------- 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/models/problem/problem.go b/models/problem/problem.go index a710b81..6b67dea 100644 --- a/models/problem/problem.go +++ b/models/problem/problem.go @@ -4,16 +4,16 @@ import "github.com/oj-lab/oj-lab-platform/models" type Problem struct { models.MetaFields - Slug string `gorm:"primaryKey" json:"slug"` - Title string `gorm:"not null" json:"title"` + Slug string `json:"slug" gorm:"primaryKey"` + Title string `json:"title" gorm:"not null"` Description *string `json:"description,omitempty"` - Tags []*AlgorithmTag `gorm:"many2many:problem_algorithm_tags;" json:"tags"` + Tags []*AlgorithmTag `json:"tags" gorm:"many2many:problem_algorithm_tags;"` } type AlgorithmTag struct { models.MetaFields - Name string `gorm:"primaryKey" json:"name"` - Problems []*Problem `gorm:"many2many:problem_algorithm_tags;" json:"problems,omitempty"` + Name string `json:"name" gorm:"primaryKey"` + Problems []*Problem `json:"problems,omitempty" gorm:"many2many:problem_algorithm_tags;"` } var ProblemInfoSelection = append([]string{"slug", "title"}, models.MetaFieldsSelection...) diff --git a/models/user/user.go b/models/user/user.go index 0234e8b..a287836 100644 --- a/models/user/user.go +++ b/models/user/user.go @@ -4,21 +4,21 @@ import "github.com/oj-lab/oj-lab-platform/models" type User struct { models.MetaFields - Account string `gorm:"primaryKey" json:"account"` + Account string `json:"account" gorm:"primaryKey"` Name string `json:"name"` - Password *string `gorm:"-:all" json:"password,omitempty"` - HashedPassword string `gorm:"not null" json:"-"` - Roles []*Role `gorm:"many2many:user_roles;" json:"roles,omitempty"` - Email *string `gorm:"unique" json:"email,omitempty"` - Mobile *string `gorm:"unique" json:"mobile,omitempty"` + Password *string `json:"password,omitempty" gorm:"-:all"` + HashedPassword string `json:"-" gorm:"not null"` + Roles []*Role `json:"roles,omitempty" gorm:"many2many:user_roles;"` + Email *string `json:"email,omitempty" gorm:"unique"` + Mobile *string `json:"mobile,omitempty" gorm:"unique"` } var PublicUserSelection = append([]string{"account", "name"}, models.MetaFieldsSelection...) type Role struct { models.MetaFields - Name string `gorm:"primaryKey" json:"name"` - Users []*User `gorm:"many2many:user_roles" json:"users,omitempty"` + Name string `json:"name" gorm:"primaryKey"` + Users []*User `json:"users,omitempty" gorm:"many2many:user_roles"` } func (user User) GetRolesStringSet() map[string]struct{} {