users

package
v0.0.0-...-b9b4979 Latest Latest
Warning

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

Go to latest
Published: Nov 11, 2022 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func RegisterHandlers

func RegisterHandlers(mux *httprouter.Router, service Service, logger log.Logger)

RegisterHandlers registers handlers for Users API methods.

Types

type CreateUserRequest

type CreateUserRequest struct {
	Email    Email    `json:"email"`
	Nickname Nickname `json:"nickname"`
	Password Password `json:"password"`
}

CreateUserRequest represents the data for creating new User.

type Email

type Email entity.Email

Email represents email.

type Nickname

type Nickname entity.Nickname

Nickname represents user's nickname.

type Password

type Password entity.Password

Password represents plaintext password.

type Repository

type Repository interface {
	// Create saves new user in storage.
	Create(user *entity.User) error
	// Get returns User with specified id.
	Get(id int64) (entity.User, error)
	// Delete removes User with specified id.
	Delete(id int64) error
	// Update modifies User.
	Update(user *entity.User) error
	// InitUserInventory init the list of items for user with spec id.
	InitUserInventory(id int64) error
	// CleanUserInventory deletes the list of items for user with spec id.
	CleanUserInventory(id int64) error
}

Repository encapsulates the logic to access users from the data source.

func NewRepository

func NewRepository(db *sql.DB, logger log.Logger) Repository

NewRepository creates a new users repository.

type Service

type Service interface {
	Get(id int64) (User, error)
	Delete(id int64) (User, error)
	Create(input *CreateUserRequest) (User, error)
	Update(id int64, input *UpdateUserRequest) (User, error)
}

Service encapsulates usecase logic for users.

func NewService

func NewService(repo Repository) Service

NewService creates a new user service.

type UpdateUserRequest

type UpdateUserRequest struct {
	Email           *Email    `json:"email"`
	Nickname        *Nickname `json:"nickname"`
	NewPassword     *Password `json:"newPassword"`
	CurrentPassword Password  `json:"currentPassword"`
}

UpdateUserRequest represents the data for modifing User. Fields Email, Nickname and NewPassword are optional.

type User

type User struct {
	Id       int64    `json:"id"`
	Email    Email    `json:"email"`
	Nickname Nickname `json:"nickname"`
}

User represents the data about an API user.

Jump to

Keyboard shortcuts

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