user

package
v0.0.0-...-3aec794 Latest Latest
Warning

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

Go to latest
Published: Apr 5, 2024 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrUserNotFound       = errors.New("user not found")
	ErrWrongPassword      = errors.New("wrong password")
	ErrEmailAlreadyExists = errors.New("email already exists")
	ErrValidationFailed   = errors.New("validation failed")
)

Functions

This section is empty.

Types

type CreateUserPayload

type CreateUserPayload struct {
	Email    string `json:"email"`
	Name     string `json:"name"`
	Password string `json:"password"`
}

func (CreateUserPayload) Validate

func (p CreateUserPayload) Validate() error

type Handler

type Handler struct {
	// contains filtered or unexported fields
}

func NewHandler

func NewHandler(service Service) *Handler

func (*Handler) CreateUser

func (h *Handler) CreateUser(w http.ResponseWriter, r *http.Request)

func (*Handler) Login

func (h *Handler) Login(w http.ResponseWriter, r *http.Request)

type LoginPayload

type LoginPayload struct {
	Email    string `json:"email"`
	Password string `json:"password"`
}

func (LoginPayload) Validate

func (p LoginPayload) Validate() error

type Repository

type Repository interface {
	Create(ctx context.Context, user *User) error
	GetByEmail(ctx context.Context, email string) (*User, error)
	GetByID(ctx context.Context, id uint64) (*User, error)
}

func NewRepository

func NewRepository(db *db.DB) Repository

type Service

type Service interface {
	Create(ctx context.Context, req CreateUserPayload) (*UserResponse, error)
	Login(ctx context.Context, req LoginPayload) (*UserResponse, error)
}

func NewService

func NewService(repository Repository) Service

type User

type User struct {
	ID             uint64
	Email          string
	Name           string
	HashedPassword string
}

type UserResponse

type UserResponse struct {
	Email       string `json:"email"`
	Name        string `json:"name"`
	AccessToken string `json:"accessToken"`
}

Jump to

Keyboard shortcuts

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