Documentation ¶
Index ¶
- Variables
- type Condition
- type CreateProductPayload
- type DBRepository
- func (d *DBRepository) Create(ctx context.Context, product *Product) error
- func (d *DBRepository) Delete(ctx context.Context, uid uuid.UUID) error
- func (d *DBRepository) GetByUUID(ctx context.Context, uuid uuid.UUID) (*Product, error)
- func (d *DBRepository) List(ctx context.Context, filter ListProductPayload) ([]Product, *response.Pagination, error)
- func (d *DBRepository) Patch(ctx context.Context, product *Product) error
- func (d *DBRepository) Purchase(ctx context.Context, data PurchaseProductPayload) error
- func (d *DBRepository) Update(ctx context.Context, product *Product) error
- type DeleteProductPayload
- type GetProductPayload
- type Handler
- func (h *Handler) CreateProduct(w http.ResponseWriter, r *http.Request)
- func (h *Handler) DeleteProduct(w http.ResponseWriter, r *http.Request)
- func (h *Handler) GetProduct(w http.ResponseWriter, r *http.Request)
- func (h *Handler) GetProductList(w http.ResponseWriter, r *http.Request)
- func (h *Handler) PatchProduct(w http.ResponseWriter, r *http.Request)
- func (h *Handler) PurchaseProduct(w http.ResponseWriter, r *http.Request)
- func (h *Handler) UpdateStockProduct(w http.ResponseWriter, r *http.Request)
- type ListProductPayload
- type Product
- type ProductDetailResponse
- type ProductResponse
- type ProductService
- func (s *ProductService) Create(ctx context.Context, req CreateProductPayload) Response
- func (s *ProductService) Delete(ctx context.Context, req DeleteProductPayload) Response
- func (s *ProductService) Get(ctx context.Context, req GetProductPayload) Response
- func (s *ProductService) List(ctx context.Context, req ListProductPayload) Response
- func (s *ProductService) Purchase(ctx context.Context, req PurchaseProductPayload) Response
- func (s *ProductService) Update(ctx context.Context, req UpdateProductPayload) Response
- func (s *ProductService) UpdateStock(ctx context.Context, req UpdateStockPayload) Response
- type PurchaseProductPayload
- type Repository
- type Response
- type SellerResponse
- type Service
- type UpdateProductPayload
- type UpdateStockPayload
Constants ¶
This section is empty.
Variables ¶
View Source
var ( ErrorForbidden = Response{Code: http.StatusForbidden, Message: "Forbidden", Error: errors.New("Forbidden")} 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 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) List ¶
func (d *DBRepository) List(ctx context.Context, filter ListProductPayload) ([]Product, *response.Pagination, error)
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
type DeleteProductPayload ¶
func (DeleteProductPayload) Validate ¶
func (p DeleteProductPayload) Validate() error
type GetProductPayload ¶
func (GetProductPayload) Validate ¶
func (p GetProductPayload) Validate() error
type Handler ¶
type Handler struct {
// contains filtered or unexported fields
}
func NewHandler ¶
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 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 (s *ProductService) Create(ctx context.Context, req CreateProductPayload) Response
func (*ProductService) Delete ¶
func (s *ProductService) Delete(ctx context.Context, req DeleteProductPayload) Response
func (*ProductService) Get ¶
func (s *ProductService) Get(ctx context.Context, req GetProductPayload) Response
func (*ProductService) List ¶
func (s *ProductService) List(ctx context.Context, req ListProductPayload) Response
func (*ProductService) Purchase ¶
func (s *ProductService) Purchase(ctx context.Context, req PurchaseProductPayload) Response
func (*ProductService) Update ¶
func (s *ProductService) Update(ctx context.Context, req UpdateProductPayload) Response
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 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 ¶
type Service interface { Create(ctx context.Context, req CreateProductPayload) Response List(ctx context.Context, req ListProductPayload) Response Update(ctx context.Context, req UpdateProductPayload) Response Get(ctx context.Context, req GetProductPayload) Response Purchase(ctx context.Context, req PurchaseProductPayload) Response UpdateStock(ctx context.Context, req UpdateStockPayload) Response Delete(ctx context.Context, req DeleteProductPayload) Response }
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 ¶
func (UpdateStockPayload) Validate ¶
func (p UpdateStockPayload) Validate() error
Click to show internal directories.
Click to hide internal directories.