package ratchet import ( "context" "time" ) type User struct { ID int `json:"id"` // User prefered name and email Name string `json:"name"` Email string `json:"email"` // Randomly generated API key for use with the API // "-" omits the key from serialization APIKey string `json:"-"` // Timestamps for user creatation and last update CreatedAt time.Time `json:"createdAt"` UpdatedAt time.Time `json:"updatedAt"` // List of associated Oauth authentication Objects // Not yet implemented // Auths []*Auth `json:"auths"` } func (u *User) Validate() error { if u.Name == "" { return Errorf(EINVALID, "User name required.") } return nil } // UserService represents a service for managing users. type UserService interface { // Retrieves a user by ID along with their associated auth objects // Returns ENOTFOUND if user does not exist. FindUserByID(ctx context.Context, id int) (*User, error) // Retrieves a list of users by filter. Also returns total count of matching users // which may differ from retruned results if filter.Limit is specified. FindUsers(ctc context.Context, filter UserFilter) ([]*User, int, error) // Creates a new use. This is only used for testing since users are typically // cretaed during the OAuth creation process in the AuthService.CreateAuth(). CreateUser(ctx context.Context, user *User) error // Updates a user object. Returns EUNAUTHORIZED if current user is not // the user that is being updated. Returns ENOTFOUND if the user does not exist. UpdateUser(ctx context.Context, id int, upd UserUpdate) (*User, error) // Permanently deletes a user and all owned application resources. Returns EUNAUTHORIZED // if current user is not the user being deleted. Returns ENOTFOUND if the user // does not exist. DeleteUser(ctx context.Context, id int) error } // UserFilter respresents a filter passed to FindUsers(). type UserFilter struct { ID *int `json:"id"` Email *string `json:"email"` APIKey *string `json:"apiKey"` // Restrict to subset of results Offset int `json:"offset"` Limit int `json:"limit"` } type UserUpdate struct { Name *string `json:"name"` Email *string `json:"email"` }