user

package
v0.0.0-...-8bff5d1 Latest Latest
Warning

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

Go to latest
Published: Apr 5, 2023 License: MIT Imports: 27 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,omitempty"`
	CartID    string    `json:"cart_id,omitempty" db:"cart_id"`
	Username  string    `json:"username,omitempty" validate:"required,max=25"`
	Email     string    `json:"email,omitempty" validate:"email,required"`
	Password  string    `json:"password,omitempty" validate:"required,min=6"`
	IsAdmin   bool      `json:"is_admin,omitempty" db:"is_admin"`
	CreatedAt time.Time `json:"created_at,omitempty" db:"created_at"`
}

AddUser is used to create new users.

type Handler

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

Handler handles user endpoints.

func NewHandler

func NewHandler(dev bool, userS Service, cartS cart.Service, emailer email.Emailer, cache *memcache.Client) Handler

NewHandler returns a new user handler.

func (*Handler) Create

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

Create creates a new user and saves it.

func (*Handler) Delete

func (h *Handler) Delete(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) GetByEmail

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

GetByEmail lists the user with the id requested.

func (*Handler) GetByID

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

GetByID lists the user with the id requested.

func (*Handler) GetByUsername

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

GetByUsername lists the user with the id requested.

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,omitempty"`
	CartID    string          `json:"cart_id,omitempty" db:"cart_id"`
	Username  string          `json:"username,omitempty"`
	Email     string          `json:"email,omitempty" validate:"email"`
	IsAdmin   bool            `json:"is_admin,omitempty" db:"is_admin"`
	Reviews   []review.Review `json:"reviews,omitempty"`
	CreatedAt time.Time       `json:"created_at,omitempty" db:"created_at"`
	UpdatedAt zero.Time       `json:"updated_at,omitempty" db:"updated_at"`
}

ListUser is the structure used to list users.

type Service

type Service interface {
	Create(ctx context.Context, user AddUser) error
	Delete(ctx context.Context, id string) error
	Get(ctx context.Context, params params.Query) ([]ListUser, error)
	GetByEmail(ctx context.Context, email string) (ListUser, error)
	GetByID(ctx context.Context, id string) (ListUser, error)
	GetByUsername(ctx context.Context, username string) (ListUser, error)
	IsAdmin(ctx context.Context, id string) (bool, error)
	Search(ctx context.Context, query string) ([]ListUser, error)
	Update(ctx context.Context, u UpdateUser, id string) error
}

Service provides user operations.

func NewService

func NewService(db *sqlx.DB, mc *memcache.Client) Service

NewService returns a new user service.

type UpdateUser

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

UpdateUser is the structure used to update users.

type User

type User struct {
	ID               string           `json:"id,omitempty" validate:"uuid4_rfc4122"`
	CartID           string           `json:"cart_id,omitempty" db:"cart_id"`
	Username         string           `json:"username,omitempty"`
	Email            string           `json:"email,omitempty" validate:"email"`
	Password         string           `json:"password,omitempty"`
	VerifiedEmail    bool             `json:"verified_email,omitempty" db:"verified_email"`
	IsAdmin          bool             `json:"is_admin,omitempty" db:"is_admin"`
	ConfirmationCode string           `json:"confirmation_code,omitempty" db:"confirmation_code"`
	Orders           []ordering.Order `json:"orders,omitempty"`
	Reviews          []review.Review  `json:"reviews,omitempty"`
	CreatedAt        time.Time        `json:"created_at,omitempty" db:"created_at"`
	UpdatedAt        zero.Time        `json:"updated_at,omitempty" 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