-
Notifications
You must be signed in to change notification settings - Fork 0
/
models.go
39 lines (35 loc) · 1.59 KB
/
models.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
package user
import (
"time"
)
// Info represents an individual user.
type Info struct {
ID string `db:"user_id" json:"id"`
Name string `db:"name" json:"name"`
Email string `db:"email" json:"email"`
Roles []string `db:"roles" json:"roles"`
PasswordHash string `db:"password_hash" json:"-"`
DateCreated time.Time `db:"date_created" json:"date_created"`
DateUpdated time.Time `db:"date_updated" json:"date_updated"`
}
// NewUser contains information needed to create a new User.
type NewUser struct {
Name string `json:"name" validate:"required"`
Email string `json:"email" validate:"required,email"`
Roles []string `json:"roles" validate:"required"`
Password string `json:"password" validate:"required"`
PasswordConfirm string `json:"password_confirm" validate:"eqfield=Password"`
}
// UpdateUser defines what information may be provided to modify an existing
// User. All fields are optional so clients can send just the fields they want
// changed. It uses pointer fields so we can differentiate between a field that
// was not provided and a field that was provided as explicitly blank. Normally
// we do not want to use pointers to basic types but we make exceptions around
// marshalling/unmarshalling.
type UpdateUser struct {
Name *string `json:"name"`
Email *string `json:"email" validate:"omitempty,email"`
Roles []string `json:"roles"`
Password *string `json:"password"`
PasswordConfirm *string `json:"password_confirm" validate:"omitempty,eqfield=Password"`
}