order

package
v0.0.0-...-097408c Latest Latest
Warning

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

Go to latest
Published: Jun 15, 2024 License: MIT Imports: 21 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrValidationFailed           = errors.New("validation failed")
	ErrStartingPointInvalid       = errors.New("starting point must be exactly 1")
	ErrSomeMerchantNotFound       = errors.New("some merchants are not found")
	ErrSomeItemNotFound           = errors.New("some items are not found")
	ErrDistanceTooFar             = errors.New("distance too far")
	ErrCalculatedEstimateNotFound = errors.New("calculated estimate not found")
)

Functions

This section is empty.

Types

type CalculateOrderEstimateRequest

type CalculateOrderEstimateRequest struct {
	UserLocation UserLocationRequest `json:"userLocation"`
	Orders       []OrderRequest      `json:"orders"`
}

func (CalculateOrderEstimateRequest) Validate

func (p CalculateOrderEstimateRequest) Validate() error

type CalculateOrderEstimateResponse

type CalculateOrderEstimateResponse struct {
	TotalPrice                     int    `json:"totalPrice"`
	EstimatedDeliveryTimeInMinutes int    `json:"estimatedDeliveryTimeInMinutes"`
	CalculatedEstimateID           string `json:"calculatedEstimateId"`
}

type CalculatedEstimate

type CalculatedEstimate struct {
	ID                    string
	UserID                string
	TotalPrice            int
	Lat                   float64
	Long                  float64
	Merchants             CalculatedEstimateMerchants
	Items                 Items
	EstimatedDeliveryTime int
	Ordered               bool
	CreatedAt             time.Time
}

type CalculatedEstimateMerchants

type CalculatedEstimateMerchants []string

func (*CalculatedEstimateMerchants) Scan

func (a *CalculatedEstimateMerchants) Scan(value interface{}) error

Make the Attrs struct implement the sql.Scanner interface. This method simply decodes a JSON-encoded value into the struct fields.

func (CalculatedEstimateMerchants) Value

Make the Attrs struct implement the driver.Valuer interface. This method simply returns the JSON-encoded representation of the struct.

type CreateOrderRequest

type CreateOrderRequest struct {
	CalculatedEstimateID string `json:"calculatedEstimateId"`
}

func (CreateOrderRequest) Validate

func (p CreateOrderRequest) Validate() error

type CreateOrderResponse

type CreateOrderResponse struct {
	OrderID string `json:"orderId"`
}

type Handler

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

func NewHandler

func NewHandler(service Service) *Handler

func (*Handler) CalculateEstimate

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

func (*Handler) CreateOrder

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

func (*Handler) SearchOrders

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

type Item

type Item struct {
	ItemID     string `json:"itemId"`
	MerchantID string `json:"merchantId"`
	Quantity   int    `json:"quantity"`
}

type Items

type Items []Item

func (*Items) Scan

func (a *Items) Scan(value interface{}) error

Make the Attrs struct implement the sql.Scanner interface. This method simply decodes a JSON-encoded value into the struct fields.

func (Items) Value

func (a Items) Value() (driver.Value, error)

Make the Attrs struct implement the driver.Valuer interface. This method simply returns the JSON-encoded representation of the struct.

type Order

type Order struct {
	ID                   string
	CalculatedEstimateID string
	UserID               string
	CreatedAt            time.Time
}

type OrderItem

type OrderItem struct {
	ID         string
	UserID     string
	OrderID    string
	MerchantID string
	Items      Items
}

type OrderItemRequest

type OrderItemRequest struct {
	ItemID   string `json:"itemId"`
	Quantity int    `json:"quantity"`
}

func (OrderItemRequest) Validate

func (p OrderItemRequest) Validate() error

type OrderRequest

type OrderRequest struct {
	MerchantID      string             `json:"merchantId"`
	IsStartingPoint *bool              `json:"isStartingPoint"`
	Items           []OrderItemRequest `json:"items"`
}

func (OrderRequest) Validate

func (p OrderRequest) Validate() error

type Repository

type Repository interface {
	InsertCalculatedEstimate(ctx context.Context, calculatedEstimate *CalculatedEstimate) error
	GetCalculatedEstimate(ctx context.Context, id string) (*CalculatedEstimate, error)
	InsertOrder(ctx context.Context, order *Order) error
	InsertOrderItem(ctx context.Context, orderItem *OrderItem) error
	ListOrdersByUserID(ctx context.Context, userID string) (*Order, error)
	ListOrderItemsByOrderID(ctx context.Context, orderID string) ([]*OrderItem, error)
	SearchOrderItemMerchants(ctx context.Context, req SearchOrderPayload, userID string) ([]*searchOrderItemMerchantsQueryResult, error)
}

func NewRepository

func NewRepository(db *db.DB) Repository

type SearchOrderDetailItemResponse

type SearchOrderDetailItemResponse struct {
	merchantitems.MerchantItemResponse
	Quantity int `json:"quantity"`
}

type SearchOrderDetailResponse

type SearchOrderDetailResponse struct {
	Merchant merchants.MerchantsResponse     `json:"merchant"`
	Items    []SearchOrderDetailItemResponse `json:"items"`
}

type SearchOrderPayload

type SearchOrderPayload struct {
	MerchantID       string `schema:"merchantId" binding:"omitempty"`
	Name             string `schema:"name" binding:"omitempty"`
	MerchantCategory string `schema:"merchantCategory" binding:"omitempty"`
	Limit            int    `schema:"limit" binding:"omitempty"`
	Offset           int    `schema:"offset" binding:"omitempty"`
}

type SearchOrderResponse

type SearchOrderResponse struct {
	OrderID string                      `json:"orderId"`
	Orders  []SearchOrderDetailResponse `json:"orders"`
}

type Service

type Service interface {
	CalculateEstimate(ctx context.Context, req CalculateOrderEstimateRequest, userID string) (*CalculateOrderEstimateResponse, error)
	CreateOrder(ctx context.Context, req CreateOrderRequest, userID string) (*CreateOrderResponse, error)
	SearchOrders(ctx context.Context, req SearchOrderPayload, userID string) ([]*SearchOrderResponse, error)
}

func NewService

func NewService(repository Repository, merchantRepository merchants.Repository, merchantItemsRepository merchantitems.Repository) Service

type UserLocationRequest

type UserLocationRequest struct {
	Lat  float64 `json:"lat"`
	Long float64 `json:"long"`
}

func (UserLocationRequest) Validate

func (p UserLocationRequest) Validate() error

Jump to

Keyboard shortcuts

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