user

package
v0.0.0-...-15895bd Latest Latest
Warning

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

Go to latest
Published: Nov 17, 2020 License: MIT Imports: 20 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AddUser

type AddUser struct {
	ID        string    `json:"id"`
	CartID    string    `json:"cart_id" db:"cart_id"`
	Username  string    `json:"username" validate:"required,max=25"`
	Email     string    `json:"email" validate:"email,required"`
	Password  string    `json:"password" validate:"required,min=6"`
	CreatedAt time.Time `json:"created_at" db:"created_at"`
	UpdatedAt time.Time `json:"updated_at" db:"updated_at"`
}

AddUser is used to create new users.

type Handler

type Handler struct {
	Service Service
}

Handler handles user endpoints.

func (*Handler) Create

func (h *Handler) Create() http.HandlerFunc

Create creates a new user and saves it.

func (*Handler) Delete

func (h *Handler) Delete(db *sqlx.DB, s auth.Session) http.HandlerFunc

Delete removes a user.

func (*Handler) Get

func (h *Handler) Get() http.HandlerFunc

Get lists all the users.

func (*Handler) GetByID

func (h *Handler) GetByID() http.HandlerFunc

GetByID lists the user with the id requested.

func (*Handler) QRCode

func (h *Handler) QRCode() http.HandlerFunc

QRCode shows the user id in a qrcode format.

func (*Handler) Search

func (h *Handler) Search() http.HandlerFunc

Search looks for the products with the given value.

func (*Handler) Update

func (h *Handler) Update() http.HandlerFunc

Update updates the user with the given id.

type ListUser

type ListUser struct {
	ID       string           `json:"id"`
	CartID   string           `json:"cart_id" db:"cart_id"`
	Username string           `json:"username"`
	Email    string           `json:"email" validate:"email"`
	Orders   []ordering.Order `json:"orders,omitempty"`
	Reviews  []review.Review  `json:"reviews,omitempty"`
}

ListUser is the structure used to list users.

func (*ListUser) QRCode

func (u *ListUser) QRCode() (image.Image, error)

QRCode creates a QRCode with the link to the user profile.

type Repository

type Repository interface {
	Create(ctx context.Context, user *AddUser) error
	Delete(ctx context.Context, id string) error
	Get(ctx context.Context) ([]ListUser, error)
	GetByEmail(ctx context.Context, email string) (User, error)
	GetByID(ctx context.Context, id string) (ListUser, error)
	Search(ctx context.Context, search string) ([]ListUser, error)
	Update(ctx context.Context, u *UpdateUser, id string) error
}

Repository provides access to the storage.

type Service

type Service interface {
	Create(ctx context.Context, user *AddUser) error
	Delete(ctx context.Context, id string) error
	Get(ctx context.Context) ([]ListUser, error)
	GetByEmail(ctx context.Context, email string) (User, error)
	GetByID(ctx context.Context, id string) (ListUser, error)
	Search(ctx context.Context, search string) ([]ListUser, error)
	Update(ctx context.Context, u *UpdateUser, id string) error
}

Service provides user operations.

func NewService

func NewService(r Repository, db *sqlx.DB) Service

NewService creates a deleting service with the necessary dependencies.

type UpdateUser

type UpdateUser struct {
	Username string `json:"username" validate:"required"`
}

UpdateUser is the structure used to update users.

type User

type User struct {
	ID               string           `json:"id" validate:"unique"`
	CartID           string           `json:"cart_id" db:"cart_id"`
	Username         string           `json:"username"`
	Email            string           `json:"email" validate:"email"`
	Password         string           `json:"password"`
	EmailVerifiedAt  time.Time        `json:"-" db:"email_verified_at"`
	ConfirmationCode string           `json:"-" db:"confirmation_code"`
	Orders           []ordering.Order `json:"orders,omitempty"`
	Reviews          []review.Review  `json:"reviews,omitempty"`
	CreatedAt        time.Time        `json:"created_at" db:"created_at"`
	UpdatedAt        time.Time        `json:"updated_at" db:"updated_at"`
}

User represents platform customers. Each user has a unique cart.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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