Skip to content

Commit

Permalink
Tidy model tag
Browse files Browse the repository at this point in the history
  • Loading branch information
slhmy committed Jun 22, 2024
1 parent a668ab9 commit 7742d53
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 13 deletions.
10 changes: 5 additions & 5 deletions models/problem/problem.go
Original file line number Diff line number Diff line change
Expand Up @@ -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...)
16 changes: 8 additions & 8 deletions models/user/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{} {
Expand Down

0 comments on commit 7742d53

Please sign in to comment.