internal

package
v0.0.0-...-9060cdc Latest Latest
Warning

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

Go to latest
Published: May 25, 2022 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrUserNotFound       = errors.New("user not found")
	ErrEmailAlreadyExists = errors.New("email already exists")
)

Functions

This section is empty.

Types

type CreateUserRequest

type CreateUserRequest struct {
	FirstName string `json:"first_name" validate:"required_without=LastName"`
	LastName  string `json:"last_name" validate:"required_without=FirstName"`
	Email     string `json:"email" validate:"required,email"`
}

type EmailDBModel

type EmailDBModel struct {
	ID      int    `gorm:"column:id;primaryKey"`
	Address string `gorm:"column:address;size:256;uniqueIndex"`
	Primary bool   `gorm:"column:primary"`
	UserID  int    `gorm:"column:user_id"`
}

func (EmailDBModel) TableName

func (EmailDBModel) TableName() string

type EmailResponse

type EmailResponse struct {
	Address string `json:"address"`
	Primary bool   `json:"primary"`
}

type UpdateUserRequest

type UpdateUserRequest struct {
	FirstName *string `json:"first_name" validate:"required_without=LastName"`
	LastName  *string `json:"last_name" validate:"required_without=FirstName"`
}

type UserDBModel

type UserDBModel struct {
	ID           int            `gorm:"column:id;primaryKey"`
	FirstName    string         `gorm:"column:first_name"`
	LastName     string         `gorm:"column:last_name"`
	Emails       []EmailDBModel `gorm:"foreignKey:UserID;constraint:OnDelete:CASCADE"`
	PasswordHash string         `gorm:"column:password_hash"`
	LastIP       string         `gorm:"column:last_ip"`
	CreatedAt    *time.Time     `gorm:"column:created_at"`
	UpdatedAt    *time.Time     `gorm:"column:updated_at"`
}

func (UserDBModel) TableName

func (UserDBModel) TableName() string

type UserHandler

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

func NewUserHandler

func NewUserHandler(storage UserStorage) UserHandler

func (UserHandler) DeleteUser

func (h UserHandler) DeleteUser(w http.ResponseWriter, r *http.Request)

func (UserHandler) GetUser

func (h UserHandler) GetUser(w http.ResponseWriter, r *http.Request)

func (UserHandler) GetUsers

func (h UserHandler) GetUsers(w http.ResponseWriter, r *http.Request)

func (UserHandler) PatchUser

func (h UserHandler) PatchUser(w http.ResponseWriter, r *http.Request)

func (UserHandler) PostUser

func (h UserHandler) PostUser(w http.ResponseWriter, r *http.Request)

type UserResponse

type UserResponse struct {
	ID          int             `json:"id"`
	FirstName   string          `json:"first_name"`
	LastName    string          `json:"last_name"`
	DisplayName string          `json:"display_name"`
	Emails      []EmailResponse `json:"emails"`
}

type UserStorage

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

func NewUserStorage

func NewUserStorage(db *gorm.DB) UserStorage

func (UserStorage) Add

func (s UserStorage) Add(user UserDBModel) error

func (UserStorage) All

func (s UserStorage) All() ([]UserDBModel, error)

func (UserStorage) ByID

func (s UserStorage) ByID(id int) (UserDBModel, error)

func (UserStorage) Delete

func (s UserStorage) Delete(id int) error

func (UserStorage) Update

func (s UserStorage) Update(user UserDBModel) error

Jump to

Keyboard shortcuts

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