products

package
v0.0.0-...-2127833 Latest Latest
Warning

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

Go to latest
Published: Feb 27, 2024 License: MIT Imports: 18 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type DataRequest

type DataRequest struct {
	CreatedAt    time.Time
	ProductID    uuid.UUID
	Quantity     int
	BuyerAddress string
}

type Handler

type Handler interface {

	// Gets handles a request to get all products
	Gets(w http.ResponseWriter, r *http.Request)

	// Get handles a request to get a product
	Get(w http.ResponseWriter, r *http.Request)

	// Create handles a request to create a new product
	Create(w http.ResponseWriter, r *http.Request)

	// Update handles a request to update a product
	Update(w http.ResponseWriter, r *http.Request)

	// Delete handles a request to delete a product
	Delete(w http.ResponseWriter, r *http.Request)

	// GetFromStore handles a request to get products from a store using pagination and store id
	GetFromStore(w http.ResponseWriter, r *http.Request)

	// CreateOrder handles a request to create a new order
	CreateOrder(w http.ResponseWriter, r *http.Request)

	// GetOrders handles a request to get all orders
	GetOrders(w http.ResponseWriter, r *http.Request)

	// GetOrder handles a request to get an order
	GetOrder(w http.ResponseWriter, r *http.Request)
}

Handler provides the products handlers

func NewProductsHandler

func NewProductsHandler(i *do.Injector) (Handler, error)

NewProductsHandler creates a new users handler

type OrderRequest

type OrderRequest struct {
	Data []DataRequest `json:"data"`
}

type OrderResponse

type OrderResponse struct {
	ID           string `json:"id"`
	OwnerAddress string `json:"owner_address"`
}

type OrderStatus

type OrderStatus string
const (
	OrderStatusPending   OrderStatus = "pending"
	OrderStatusCompleted OrderStatus = "completed"
	OrderStatusCancelled OrderStatus = "cancelled"
	OrderStatusReleased  OrderStatus = "released"
)

type Orders

type Orders struct {
	gorm.Model
	ID        uuid.UUID   `gorm:"primaryKey"`
	ProductID uuid.UUID   `gorm:"not null"`
	Product   Products    `gorm:"foreignKey:ProductID"`
	BuyerID   uuid.UUID   `gorm:"not null"`
	Quantity  int         `gorm:"not null"`
	Total     float64     `gorm:"not null"`
	Status    OrderStatus `gorm:"not null, type:ENUM('pending', 'completed', 'cancelled', 'released'), default:'pending'"`
	TxHash    string
}

func (*Orders) BeforeCreate

func (o *Orders) BeforeCreate(tx *gorm.DB) (err error)

type Products

type Products struct {
	gorm.Model
	ID    uuid.UUID `gorm:"primaryKey"`
	Name  string    `gorm:"not null"`
	Price float64   `gorm:"not null"`
	Unit  string    `gorm:"not null"`

	ImageURL string
	// TODO: Define options for products
	Description string    `gorm:"not null"`
	StoreID     uuid.UUID `gorm:"not null"`
	Store       Stores    `gorm:"foreignKey:StoreID"`
}

func (*Products) BeforeCreate

func (s *Products) BeforeCreate(tx *gorm.DB) (err error)

type Service

type Service interface {
	// GetProducts returns all products
	GetProducts() ([]Products, error)

	// GetProduct returns a product by id
	GetProduct(id string) (*Products, error)

	// CreateProduct creates a new product
	CreateProduct(userId string, p *Products) (string, error)

	// UpdateProduct updates a product
	UpdateProduct(userId string, id string, p *Products) error

	// DeleteProduct deletes a product
	DeleteProduct(userId string, id string) error

	// GetProductsFromStore returns paginated products from a store
	GetProductsFromStore(storeId string, cursor string, limit int) ([]Products, error)

	// CreateOrders returns order_ids for given products
	CreateOrders(userId string, orders []DataRequest) ([]OrderResponse, error)

	// GetOrders returns all orders
	GetOrders(userId string, filter string) ([]Orders, error)

	// SaveFile saves a file to the object storage
	SaveFile(file multipart.File, filepath string) (string, error)

	// GetOrder returns an order by id
	GetOrder(id string) (*Orders, error)
}

Service is the products service interface

func NewProductsService

func NewProductsService(i *do.Injector) (Service, error)

NewProductsService creates a new users service

type Stores

type Stores struct {
	gorm.Model
	ID       uuid.UUID  `gorm:"primaryKey"`
	Name     string     `gorm:"unique, not null"`
	OwnerID  uuid.UUID  `gorm:"not null"`
	Owner    Users      `gorm:"foreignKey:OwnerID"`
	Products []Products `gorm:"foreignKey:StoreID"`
}

type Users

type Users struct {
	gorm.Model
	ID            uuid.UUID `gorm:"primaryKey"`
	FirstName     string    `gorm:"not null"`
	LastName      string    `gorm:"not null"`
	Address       string
	Email         string `gorm:"not null, unique"`
	EmailVerified bool   `gorm:"default:false"`
	Password      string `gorm:"not null"`
	WalletAddress string
}

Jump to

Keyboard shortcuts

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