[feature] migrate to monorepo
This commit is contained in:
commit
05ddc1f783
267 changed files with 75165 additions and 0 deletions
43
backend/ent/schema/contributorrole.go
Normal file
43
backend/ent/schema/contributorrole.go
Normal file
|
@ -0,0 +1,43 @@
|
|||
package schema
|
||||
|
||||
import (
|
||||
"entgo.io/ent"
|
||||
"entgo.io/ent/schema/field"
|
||||
"entgo.io/ent/schema/edge"
|
||||
"fmt"
|
||||
)
|
||||
|
||||
// ContributorRole holds the schema definition for the ContributorRole entity.
|
||||
type ContributorRole struct {
|
||||
ent.Schema
|
||||
}
|
||||
|
||||
// Fields of the ContributorRole.
|
||||
func (ContributorRole) Fields() []ent.Field {
|
||||
return []ent.Field{
|
||||
field.String("name").
|
||||
Unique().
|
||||
NotEmpty().
|
||||
Validate(func(s string) error {
|
||||
// 检查是否是默认角色之一
|
||||
validRoles := map[string]bool{
|
||||
"submitter": true,
|
||||
"author": true,
|
||||
"reviewer": true,
|
||||
"translator": true,
|
||||
"translation_reviewer": true,
|
||||
}
|
||||
if !validRoles[s] {
|
||||
return fmt.Errorf("invalid role name: %s", s)
|
||||
}
|
||||
return nil
|
||||
}),
|
||||
}
|
||||
}
|
||||
|
||||
// Edges of the ContributorRole.
|
||||
func (ContributorRole) Edges() []ent.Edge {
|
||||
return []ent.Edge{
|
||||
edge.To("post_contributors", PostContributor.Type),
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue