product

package
v0.0.0-...-1f73362 Latest Latest
Warning

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

Go to latest
Published: Mar 28, 2024 License: MIT Imports: 21 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrorForbidden     = Response{Code: http.StatusForbidden, Message: "Forbidden", Error: errors.New("Forbidden")}
	ErrorUnauthorized  = Response{Code: http.StatusUnauthorized, Message: "Unauthorized", Error: errors.New("Unauthorized")}
	ErrorRequiredField = Response{Code: http.StatusBadRequest, Message: "Required field"}
	ErrorInternal      = Response{Code: http.StatusInternalServerError, Message: "Internal Server Error", Error: errors.New("Internal Server Error")}
	ErrorBadRequest    = Response{Code: http.StatusBadRequest, Message: "Bad Request"}
	ErrorNoRecords     = Response{Code: http.StatusOK, Message: "No records found"}
	ErrorNotFound      = Response{Code: http.StatusNotFound, Message: "No records found"}

	ErrorNotPurchasable    = Response{Code: http.StatusBadRequest, Message: "product is not purchasable"}
	ErrorInsufficientStock = Response{Code: http.StatusBadRequest, Message: "insufficient product stock"}
)
View Source
var (
	SortByPrice productSortBy = "price"
	SortByDate  productSortBy = "date"
)
View Source
var (
	SuccessCreateResponse      = Response{Code: 200, Message: "Product created successfully"}
	SuccessListResponse        = Response{Code: 200, Message: "ok"}
	SuccessPatchResponse       = Response{Code: 200, Message: "Product patched successfully"}
	SuccessGetResponse         = Response{Code: 200, Message: "ok"}
	SuccessPurchaseResponse    = Response{Code: 200, Message: "Product purchased successfully"}
	SuccessUpdateStockResponse = Response{Code: 200, Message: "Stock updated successfully"}
	SuccessDeleteResponse      = Response{Code: 200, Message: "Product deleted successfully"}
)
View Source
var Conditions []interface{} = []interface{}{New, Second}

Functions

This section is empty.

Types

type Condition

type Condition string
const (
	New    Condition = "new"
	Second Condition = "second"
)

type CreateProductPayload

type CreateProductPayload struct {
	Name          string    `json:"name"`
	Price         int       `json:"price"`
	ImageURL      string    `json:"imageUrl"`
	Stock         int       `json:"stock"`
	Condition     Condition `json:"condition"`
	Tags          []string  `json:"tags"`
	IsPurchasable bool      `json:"isPurchasable"`
	UserID        uint64    `json:"-"`
}

func (CreateProductPayload) Validate

func (p CreateProductPayload) Validate() error

type DBRepository

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

func NewRepository

func NewRepository(db *db.DB) *DBRepository

func (*DBRepository) Create

func (d *DBRepository) Create(ctx context.Context, product *Product) error

func (*DBRepository) Delete

func (d *DBRepository) Delete(ctx context.Context, uid uuid.UUID) error

Delete implements Repository.

func (*DBRepository) GetByUUID

func (d *DBRepository) GetByUUID(ctx context.Context, uuid uuid.UUID) (*Product, error)

func (*DBRepository) List

func (*DBRepository) Patch

func (d *DBRepository) Patch(ctx context.Context, product *Product) error

func (*DBRepository) Purchase

func (d *DBRepository) Purchase(ctx context.Context, data PurchaseProductPayload) error

func (*DBRepository) Update

func (d *DBRepository) Update(ctx context.Context, product *Product) error

type DeleteProductPayload

type DeleteProductPayload struct {
	ProductUID uuid.UUID
	UserID     uint64
}

func (DeleteProductPayload) Validate

func (p DeleteProductPayload) Validate() error

type GetProductPayload

type GetProductPayload struct {
	ProductUID uuid.UUID `json:"-"`
}

func (GetProductPayload) Validate

func (p GetProductPayload) Validate() error

type Handler

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

func NewHandler

func NewHandler(service Service) *Handler

func (*Handler) CreateProduct

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

func (*Handler) DeleteProduct

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

func (*Handler) GetProduct

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

func (*Handler) GetProductList

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

func (*Handler) PatchProduct

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

func (*Handler) PurchaseProduct

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

func (*Handler) UpdateStockProduct

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

type ListProductPayload

type ListProductPayload struct {
	UserOnly       bool `schema:"userOnly" binding:"omitempty"`
	UserID         uint64
	Tags           []string      `schema:"tags" binding:"omitempty"`
	Condition      Condition     `schema:"condition" binding:"omitempty"`
	ShowEmptyStock bool          `schema:"showEmptyStock" binding:"omitempty"`
	MinPrice       int           `schema:"minPrice" binding:"omitempty"`
	MaxPrice       int           `schema:"maxPrice" binding:"omitempty"`
	Search         string        `schema:"search" binding:"omitempty"`
	Limit          int           `schema:"limit" binding:"omitempty"`
	Offset         int           `schema:"offset" binding:"omitempty"`
	SortBy         productSortBy `schema:"sortBy" binding:"omitempty"`
	OrderBy        string        `schema:"orderBy" binding:"omitempty"`
}

func (ListProductPayload) Validate

func (p ListProductPayload) Validate() error

type Product

type Product struct {
	ID            int
	UUID          uuid.UUID
	Name          string
	ImageURL      string
	Stock         int
	Condition     Condition
	Tags          []string
	IsPurchasable bool
	Price         int
	PurchaseCount int
	User          user.User
	CreatedAt     time.Time
}

type ProductDetailResponse

type ProductDetailResponse struct {
	Product ProductResponse `json:"product"`
	Seller  SellerResponse  `json:"seller"`
}

type ProductResponse

type ProductResponse struct {
	UUID          uuid.UUID `json:"productId"`
	Name          string    `json:"name"`
	ImageURL      string    `json:"imageUrl"`
	Stock         int       `json:"stock"`
	Condition     Condition `json:"condition"`
	Tags          []string  `json:"tags"`
	IsPurchasable bool      `json:"isPurchasable"`
	Price         int       `json:"price"`
	PurchaseCount int       `json:"purchaseCount"`
}

func CreateProductResponse

func CreateProductResponse(product Product) ProductResponse

type ProductService

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

func (*ProductService) Create

func (*ProductService) Delete

func (*ProductService) Get

func (*ProductService) List

func (*ProductService) Purchase

func (*ProductService) Update

func (*ProductService) UpdateStock

func (s *ProductService) UpdateStock(ctx context.Context, req UpdateStockPayload) Response

type PurchaseProductPayload

type PurchaseProductPayload struct {
	ProductUID           uuid.UUID
	BankAccountID        uuid.UUID `json:"bankAccountId"`
	PaymentProofImageURL string    `json:"paymentProofImageUrl"`
	Quantity             int       `json:"quantity"`
	BuyerID              uint64
	SellerID             uint64
}

func (PurchaseProductPayload) Validate

func (p PurchaseProductPayload) Validate() error

type Repository

type Repository interface {
	Create(ctx context.Context, product *Product) error
	List(ctx context.Context, filter ListProductPayload) ([]Product, *response.Pagination, error)
	Update(ctx context.Context, product *Product) error
	GetByUUID(ctx context.Context, uuid uuid.UUID) (*Product, error)
	Patch(ctx context.Context, product *Product) error
	Purchase(ctx context.Context, data PurchaseProductPayload) error
	Delete(ctx context.Context, uid uuid.UUID) error
}

type Response

type Response struct {
	Code    int
	Message string
	Data    any
	Meta    *response.Pagination
	Error   error
}

type SellerResponse

type SellerResponse struct {
	Name             string                            `json:"name"`
	ProductSoldTotal int                               `json:"productSoldTotal"`
	BankAccounts     []bankaccount.BankAccountResponse `json:"bankAccounts"`
}

func CreateSellerResponse

func CreateSellerResponse(user *user.User, bankAccounts []*bankaccount.BankAccount) SellerResponse

type Service

func NewService

func NewService(repository Repository, userRepository user.Repository, bankRepository bankaccount.Repository) Service

type UpdateProductPayload

type UpdateProductPayload struct {
	ProductUID    uuid.UUID `json:"-"`
	Name          string    `json:"name,omitempty"`
	Price         int       `json:"price,omitempty"`
	ImageURL      string    `json:"imageUrl,omitempty"`
	Condition     Condition `json:"condition,omitempty"`
	Tags          []string  `json:"tags,omitempty"`
	IsPurchasable bool      `json:"isPurchasable,omitempty"`
	UserID        uint64    `json:"-"`
}

func (UpdateProductPayload) Validate

func (p UpdateProductPayload) Validate() error

type UpdateStockPayload

type UpdateStockPayload struct {
	ProductUID uuid.UUID
	Stock      int `json:"stock"`
	UserID     uint64
}

func (UpdateStockPayload) Validate

func (p UpdateStockPayload) Validate() error

Jump to

Keyboard shortcuts

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