-
Notifications
You must be signed in to change notification settings - Fork 6
/
user_model.go
79 lines (65 loc) · 2.11 KB
/
user_model.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
package model
import (
"fmt"
"time"
"github.com/golang-jwt/jwt"
enum "github.com/p-society/gc-server/enums/pkg"
"go.mongodb.org/mongo-driver/bson/primitive"
)
type Player struct {
ID primitive.ObjectID `json:"_id,omitempty" bson:"_id,omitempty"`
FirstName string `json:"firstName" bson:"firstName"`
LastName string `json:"lastName" bson:"lastName"`
Email string `json:"email" bson:"email"`
Password string `json:"password" bson:"password"`
Role string `json:"role" bson:"role"`
Branch string `json:"branch" bson:"branch"`
Year string `json:"year" bson:"year"`
ContactNo string `json:"contactNo" bson:"contactNo"`
Social []string `json:"socials,omitempty" bson:"socials,omitempty"`
IsDeleted bool `json:"isDeleted,omitempty" bson:"isDeleted,omitempty"`
DeletedBy primitive.ObjectID `json:"deletedBy,omitempty" bson:"deleteBy,omitempty"`
DeletedAt primitive.ObjectID `json:"deletedAt,omitempty" bson:"deletedAt,omitempty"`
CreatedAt time.Time `json:"createdAt" bson:"createdAt"`
OTP int `json:"otp,omitempty"`
jwt.StandardClaims `json:"claims,omitempty" bson:"claims,omitempty"`
}
func ValidateRole(p *Player) error {
for _, role := range enum.Roles {
if role == p.Role {
return nil
}
}
return fmt.Errorf("invalid role: %s", p.Role)
}
func ValidateBranch(p *Player) error {
for _, branch := range enum.Branches {
if branch == p.Branch {
return nil
}
}
return fmt.Errorf("invalid Branch: %s", p.Branch)
}
func ValidateYear(p *Player) error {
for _, year := range enum.Years {
if year == p.Year {
return nil
}
}
return fmt.Errorf("invalid Year: %s", p.Year)
}
func ValidatePlayer(p Player) error {
err := ValidateBranch(&p)
if err != nil {
return err
}
err = ValidateRole(&p)
if err != nil {
return err
}
err = ValidateYear(&p)
if err != nil {
return err
}
return nil
}