memos/api/user.go

76 lines
1.5 KiB
Go
Raw Normal View History

2021-12-08 23:43:14 +08:00
package api
// Role is the type of a role.
type Role string
const (
// Host is the HOST role.
Host Role = "HOST"
// NormalUser is the USER role.
NormalUser Role = "USER"
)
2022-05-19 18:32:04 +08:00
func (e Role) String() string {
switch e {
case Host:
return "HOST"
2022-05-19 18:32:04 +08:00
case NormalUser:
return "USER"
}
return "USER"
}
2022-02-03 15:32:03 +08:00
type User struct {
2022-05-03 11:49:10 +08:00
ID int `json:"id"`
// Standard fields
2022-05-19 18:32:04 +08:00
RowStatus RowStatus `json:"rowStatus"`
CreatedTs int64 `json:"createdTs"`
UpdatedTs int64 `json:"updatedTs"`
2022-02-03 15:32:03 +08:00
2022-05-03 11:49:10 +08:00
// Domain specific fields
Email string `json:"email"`
Role Role `json:"role"`
2022-02-06 16:19:20 +08:00
Name string `json:"name"`
PasswordHash string `json:"-"`
OpenID string `json:"openId"`
2021-12-08 23:43:14 +08:00
}
2022-02-03 15:32:03 +08:00
type UserCreate struct {
2022-05-03 11:49:10 +08:00
// Domain specific fields
Email string `json:"email"`
Role Role `json:"role"`
Name string `json:"name"`
Password string `json:"password"`
2022-02-06 16:19:20 +08:00
PasswordHash string
OpenID string
2021-12-09 22:02:57 +08:00
}
2022-02-03 15:32:03 +08:00
type UserPatch struct {
2022-05-03 02:05:43 +08:00
ID int
2021-12-14 20:40:24 +08:00
2022-05-19 18:32:04 +08:00
// Standard fields
RowStatus *RowStatus `json:"rowStatus"`
2022-05-03 11:49:10 +08:00
// Domain specific fields
Email *string `json:"email"`
2022-05-03 11:49:10 +08:00
Name *string `json:"name"`
Password *string `json:"password"`
ResetOpenID *bool `json:"resetOpenId"`
PasswordHash *string
OpenID *string
2021-12-14 20:40:24 +08:00
}
2022-02-03 15:32:03 +08:00
type UserFind struct {
2022-05-03 02:05:43 +08:00
ID *int `json:"id"`
2021-12-09 22:02:57 +08:00
2022-05-19 18:32:04 +08:00
// Standard fields
RowStatus *RowStatus `json:"rowStatus"`
2022-05-03 11:49:10 +08:00
// Domain specific fields
Email *string `json:"email"`
Role *Role
2022-02-06 16:19:20 +08:00
Name *string `json:"name"`
2022-05-03 02:05:43 +08:00
OpenID *string
2021-12-08 23:43:14 +08:00
}