orders

package
v0.0.0-...-2c400ab Latest Latest
Warning

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

Go to latest
Published: Sep 7, 2022 License: GPL-3.0 Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Places = []string{"inhouse", "delivery"}

Places describes where the order was placed or is being taken.

View Source
var Statuses = []string{"ordered", "paid"}

Statuses describe the payment status of the order.

Functions

func ValidatePlaces

func ValidatePlaces(order string) bool

ValidatePlaces check if the order place is acceptable

func ValidateStatus

func ValidateStatus(order string) bool

ValidateStatus check if the order status is acceptable

Types

type Metadata

type Metadata map[string]interface{}

Metadata to be used for customized describing of particular Order.

type Order

type Order struct {
	ID        string    `json:"id,omitempty"`
	Vendor    string    `json:"vendor,omitempty"`     // The name of the vendor os the product i.e shop.
	Name      string    `json:"name,omitempty"`       // The name of the order good.
	Price     uint64    `json:"price,omitempty"`      // This is the price of the order.
	Place     string    `json:"place,omitempty"`      // This is the place where the order was served. It is either inhouse or delivery.
	Status    string    `json:"status,omitempty"`     // This is the payment status. It is either paid or ordered.
	Metadata  Metadata  `json:"metadata,omitempty"`   // Metadata contains extra information about the order.
	UpdatedAt time.Time `json:"updated_at,omitempty"` // When the order was updated.
	CreatedAt time.Time `json:"created_at,omitempty"` // When the order was created in the system.
}

Order this represents the order to be made by a person to the shop.

func (Order) Validate

func (order Order) Validate() error

Validate returns an error if order representation is invalid.

type OrderRepository

type OrderRepository interface {
	// Save persists the Order. A non-nil error is returned to indicate
	// operation failure.
	Save(ctx context.Context, order Order) (string, error)

	// RetrieveByID retrieves Order by its unique identifier ID.
	RetrieveByID(ctx context.Context, id string) (Order, error)

	// RetrieveAll retrieves all orders for a give pageMetadata.
	RetrieveAll(ctx context.Context, pm PageMetadata) (OrdersPage, error)

	// Update updates the name, prices, metadata, place and status
	// for a given order by its unique identifier ID.
	Update(ctx context.Context, p Order) (string, error)

	// Delete deletes the order
	Delete(ctx context.Context, id string) error
}

OrderRepository specifies an account persistence API.

type OrderService

type OrderService interface {
	// CreateOrder creates and order to the system. Requires a token and the order object.
	CreateOrder(ctx context.Context, token string, order Order) (string, error)

	// ViewOrder retrieves Order by its unique identifier ID.
	ViewOrder(ctx context.Context, token string, id string) (Order, error)

	// ListOrders retrieves all orders for a give pageMetadata.
	ListOrders(ctx context.Context, token string, pm PageMetadata) (OrdersPage, error)

	// UpdateOrder updates the name, prices, metadata, place and status
	// for a given order by its unique identifier ID.
	UpdateOrder(ctx context.Context, token string, p Order) (string, error)

	// DeleteOrder deletes the order for a give unique identifier ID.
	DeleteOrder(ctx context.Context, token string, id string) error
}

OrderService. This describes the methods an Order undergo. CreateOrder ViewOrder ListOrders UpdateOrder DeleteOrder

func NewOrderService

func NewOrderService(orders OrderRepository) OrderService

NewOrderService instantiates the users service implementation

type OrdersPage

type OrdersPage struct {
	PageMetadata
	Orders []Order
}

OrdersPage contains a page of orders.

type PageMetadata

type PageMetadata struct {
	Total    uint64
	Offset   uint64
	Limit    uint64
	Vendor   string
	Name     string
	Price    uint64
	Place    string
	Metadata Metadata
	Status   string
}

PageMetadata contains page metadata that helps navigation.

Directories

Path Synopsis
Package api contains API-related concerns: endpoint definitions, middlewares and all resource representations.
Package api contains API-related concerns: endpoint definitions, middlewares and all resource representations.
Package postgres contains repository implementations using postgres as the underlying database.
Package postgres contains repository implementations using postgres as the underlying database.

Jump to

Keyboard shortcuts

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