user

package
v0.0.0-...-67df6f6 Latest Latest
Warning

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

Go to latest
Published: May 12, 2024 License: MIT Imports: 15 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")
	ErrPhoneNumberAlreadyExists = errors.New("phone number already exists")
	ErrValidationFailed         = errors.New("validation failed")
)

Functions

This section is empty.

Types

type CreateCustomerPayload

type CreateCustomerPayload struct {
	PhoneNumber string `json:"phoneNumber"`
	Name        string `json:"name"`
}

func (CreateCustomerPayload) Validate

func (p CreateCustomerPayload) Validate() error

type CreateStaffPayload

type CreateStaffPayload struct {
	PhoneNumber string `json:"phoneNumber"`
	Name        string `json:"name"`
	Password    string `json:"password"`
}

func (CreateStaffPayload) Validate

func (p CreateStaffPayload) Validate() error

type CustomerResponse

type CustomerResponse struct {
	UserID      string `json:"userId"`
	PhoneNumber string `json:"phoneNumber"`
	Name        string `json:"name"`
}

type Handler

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

func NewHandler

func NewHandler(service Service) *Handler

func (*Handler) CreateCustomer

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

func (*Handler) CreateStaff

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

func (*Handler) ListCustomers

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

func (*Handler) StaffLogin

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

type ListCustomerPayload

type ListCustomerPayload struct {
	PhoneNumber string `schema:"phoneNumber" binding:"omitempty"`
	Name        string `schema:"name" binding:"omitempty"`
}

type LoginPayload

type LoginPayload struct {
	PhoneNumber string `json:"phoneNumber"`
	Password    string `json:"password"`
}

func (LoginPayload) Validate

func (p LoginPayload) Validate() error

type Repository

type Repository interface {
	Create(ctx context.Context, user *User) error
	GetByPhoneNumberAndUserType(ctx context.Context, phoneNumber string, userType UserType) (*User, error)
	GetByID(ctx context.Context, id string) (*User, error)
	ListCustomers(ctx context.Context, req ListCustomerPayload) ([]*User, error)
}

func NewRepository

func NewRepository(db *db.DB) Repository

type Service

type Service interface {
	CreateStaff(ctx context.Context, req CreateStaffPayload) (*StaffResponse, error)
	CreateCustomer(ctx context.Context, req CreateCustomerPayload) (*CustomerResponse, error)
	StaffLogin(ctx context.Context, req LoginPayload) (*StaffResponse, error)
	ListCustomers(ctx context.Context, req ListCustomerPayload) ([]*CustomerResponse, error)
}

func NewService

func NewService(repository Repository) Service

type StaffResponse

type StaffResponse struct {
	UserID      string `json:"userId"`
	PhoneNumber string `json:"phoneNumber"`
	Name        string `json:"name"`
	AccessToken string `json:"accessToken"`
}

type User

type User struct {
	ID             string
	UserType       UserType
	PhoneNumber    string
	Name           string
	HashedPassword string
}

type UserType

type UserType string
const (
	Staff    UserType = "Staff"
	Customer UserType = "Customer"
)

Jump to

Keyboard shortcuts

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