Documentation ¶
Overview ¶
Pakcage user contains usecases for CRUD operations.
Index ¶
- Variables
- type NewUser
- type UpdateUser
- type User
- type UserService
- func (us UserService) Authenticate(ctx context.Context, traceID string, now time.Time, email, password string) (auth.Claims, error)
- func (us UserService) Create(ctx context.Context, traceID string, nu NewUser, now time.Time) (User, error)
- func (us UserService) Delete(ctx context.Context, traceID string, id string) error
- func (us UserService) GetByEmail(ctx context.Context, traceID string, claims auth.Claims, email string) (User, error)
- func (us UserService) GetById(ctx context.Context, traceID string, claims auth.Claims, userID string) (User, error)
- func (us UserService) List(ctx context.Context, traceID string, pageNumber int, rowsPerPage int) ([]User, error)
- func (us UserService) Update(ctx context.Context, traceID string, claims auth.Claims, id string, ...) error
Constants ¶
This section is empty.
Variables ¶
var ( // ErrNotFound is used when a specific User is requested but does not exist. ErrNotFound = errors.New("not found") // ErrInvalidID occurs when an ID is not in a valid form (UUID). ErrInvalidID = errors.New("ID is not in its proper form") // ErrAuthenticationFailure occurs when a user attempts to authenticate but // anything goes wrong. ErrAuthenticationFailure = errors.New("authentication failed") // ErrForbidden occurs when a user tries to do something that is forbidden to them according to our access control policies. ErrForbidden = errors.New("attempted action is not allowed") )
Functions ¶
This section is empty.
Types ¶
type NewUser ¶
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"` }
NewUser contains information needed to create a new User.
type UpdateUser ¶
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"` }
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 to change. It uses pointer semantics for having nil values facilitating comparison against it.
type User ¶
type User struct { ID string `db:"user_id" json:"id"` Name string `db:"name" json:"name"` Email string `db:"email" json:"email"` Roles pq.StringArray `db:"roles" json:"roles"` PasswordHash []byte `db:"password_hash" json:"-"` DateCreated time.Time `db:"date_created" json:"date_created"` DateUpdated time.Time `db:"date_updated" json:"date_updated"` }
User represents an individual user.
type UserService ¶
type UserService struct {
// contains filtered or unexported fields
}
func New ¶
func New(log *zap.SugaredLogger, sqlxDB *sqlx.DB) UserService
New is a factory method for constructing user service.
func (UserService) Authenticate ¶
func (us UserService) Authenticate(ctx context.Context, traceID string, now time.Time, email, password string) (auth.Claims, error)
Authenticate finds a user by their email and verifies their password. On success it returns a Claims value representing this user. The claims can be used to generate a token for future authentication.
func (UserService) Create ¶
func (us UserService) Create(ctx context.Context, traceID string, nu NewUser, now time.Time) (User, error)
Create inserts a new user into the database.
func (UserService) GetByEmail ¶
func (us UserService) GetByEmail(ctx context.Context, traceID string, claims auth.Claims, email string) (User, error)
GetByEmail gets the specified user from the database.
func (UserService) GetById ¶
func (us UserService) GetById(ctx context.Context, traceID string, claims auth.Claims, userID string) (User, error)
GetById gets the specified user from the database.