user

package
v0.1.9 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 17, 2023 License: Apache-2.0 Imports: 20 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrUserNotFound     = errors.New("user_not_found")
	ErrInvalidPassword  = errors.New("invalid_password")
	ErrInvalidRequest   = errors.New("invalid_request")
	ErrInvalidParameter = errors.New("invalid_parameter")
	ErrForbidden        = errors.New("forbidden")
)

Predefined errors.

Error codes map

View Source
var ErrorMessages = map[error]string{
	ErrUserNotFound:     "User not found",
	ErrInvalidPassword:  "Invalid current password",
	ErrInvalidRequest:   "Invalid request",
	ErrInvalidParameter: "Invalid parameter",
	ErrForbidden:        "Forbidden action",
}

Error messages

Functions

func MakeDeleteEndpoint

func MakeDeleteEndpoint(s Service) endpoint.Endpoint

MakeDeleteEndpoint returns an endpoint via the passed service.

func MakeGetByIDEndpoint

func MakeGetByIDEndpoint(s Service) endpoint.Endpoint

MakeGetByIDEndpoint returns an endpoint via the passed service.

func MakeGetProfileEndpoint

func MakeGetProfileEndpoint(s Service) endpoint.Endpoint

MakeGetProfileEndpoint returns an endpoint via the passed service.

func MakeHTTPHandler

func MakeHTTPHandler(e Endpoints, log logger) http.Handler

MakeHTTPHandler ...

func MakeUpdateEmailEndpoint

func MakeUpdateEmailEndpoint(s Service) endpoint.Endpoint

MakeUpdateEmailEndpoint returns an endpoint via the passed service.

func MakeUpdatePasswordEndpoint

func MakeUpdatePasswordEndpoint(s Service) endpoint.Endpoint

MakeUpdatePasswordEndpoint returns an endpoint via the passed service.

func NewError

func NewError(err error) *httpencoder.ErrorResponse

NewError creates a new error

Types

type Endpoints

type Endpoints struct {
	GetByID        endpoint.Endpoint
	GetProfile     endpoint.Endpoint
	UpdateEmail    endpoint.Endpoint
	UpdatePassword endpoint.Endpoint
	Delete         endpoint.Endpoint
}

Endpoints collects all of the endpoints that compose a user service. It's meant to be used as a helper struct, to collect all of the endpoints into a single parameter.

func MakeEndpoints

func MakeEndpoints(s Service, m ...endpoint.Middleware) Endpoints

MakeEndpoints returns an Endpoints struct where each endpoint invokes the corresponding method on the provided service. Primarily useful in a server.

type Service

type Service interface {
	// GetByID returns the user with the specified the user ID.
	GetByID(ctx context.Context, id string) (*User, error)
	// UpdateEmail updates the email address of the user with the specified ID.
	UpdateEmail(ctx context.Context, id, email string) (*User, error)
	// UpdatePassword updates the password of the user with the specified ID.
	UpdatePassword(ctx context.Context, id, oldPassword, newPassword string) error
	// Delete deletes the user with the specified ID.
	Delete(ctx context.Context, id string) error
}

func NewService

func NewService(repo userRepository, m mailer, db *sql.DB) Service

NewService creates a new user service. It is the concrete implementation of the Service interface.

type UpdateEmailRequest

type UpdateEmailRequest struct {
	Email string `` /* 137-byte string literal not displayed */
}

UpdateEmailRequest is the request type for the UpdateEmail endpoint.

type UpdatePasswordRequest

type UpdatePasswordRequest struct {
	Password    string `json:"password" validate:"required" filter:"trim" label:"Current password"`
	NewPassword string `json:"new_password" validate:"required|minLen:8|maxLen:50" filter:"trim" label:"New password"`
}

UpdatePasswordRequest is the request type for the UpdatePassword endpoint.

type User

type User struct {
	ID        string `json:"id"`
	Email     string `json:"email"`
	Verified  bool   `json:"verified"`
	CreatedAt string `json:"created_at"`
}

func NewUser

func NewUser(u repository.User) *User

NewUser casts a repository.User to a user.User.

type UserResponse

type UserResponse struct {
	User *User `json:"user"`
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL