carpool-service/interoperability/ocss/users.go

67 lines
1.4 KiB
Go

package ocss
import (
"bytes"
"encoding/json"
)
type Gender int64
const (
Female Gender = iota
Male
Other
)
var gendertoID = map[string]Gender{
"F": Female,
"M": Male,
"O": Other,
}
var gendertoString = map[Gender]string{
Female: "F",
Male: "M",
Other: "O",
}
func (s Gender) MarshalJSON() ([]byte, error) {
buffer := bytes.NewBufferString(`"`)
buffer.WriteString(gendertoString[s])
buffer.WriteString(`"`)
return buffer.Bytes(), nil
}
func (bs *Gender) UnmarshalJSON(b []byte) error {
var j string
err := json.Unmarshal(b, &j)
if err != nil {
return err
}
// Note that if the string cannot be found then it will be set to the zero value, 'Created' in this case.
*bs = gendertoID[j]
return nil
}
func (g *Gender) ToString() *string {
if g == nil {
return nil
}
res := gendertoString[*g]
return &res
}
type User struct {
ID string `json:"id"`
Operator string `json:"operator"`
Alias string `json:"alias"`
FirstName *string `json:"firstName,omitempty" bson:"firstName,omitempty"`
LastName *string `json:"lastName,omitempty" bson:"lastName,omitempty"`
Grade *int64 `json:"grade,omitempty" bson:"grade,omitempty"`
Picture *string `json:"picture,omitempty" bson:"picture,omitempty"`
Gender *Gender `json:"gender,omitempty" bson:"gender,omitempty"`
VerifiedIdentity *bool `json:"verifiedIdentity,omitempty" bson:"verifiedIdentity,omitempty"`
}