database

package
v0.0.0-...-6a7e3ee Latest Latest
Warning

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

Go to latest
Published: Sep 24, 2021 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type MockOrderRepository

type MockOrderRepository struct {
	ErrorOnFindAll  bool
	ErrorOnStart    bool
	ErrorOnComplete bool

	Storage map[string]*Order

	CompleteCallCounter int
}

MockOrderRepository will mock real database connection for testing purposes.

func (*MockOrderRepository) Complete

func (o *MockOrderRepository) Complete(orderID string) (string, error)

func (*MockOrderRepository) FindAll

func (o *MockOrderRepository) FindAll(userID string) (OrderList, error)

func (*MockOrderRepository) Start

func (o *MockOrderRepository) Start(userID string, products []Product) (*Order, error)

type Order

type Order struct {
	ID            string                        `bson:"_id,omitempty"`
	UserID        string                        `bson:"user_id,omitempty"`
	CreatedAt     time.Time                     `bson:"created_at,omitempty"`
	PaymentAmount float32                       `bson:"payment_amount,omitempty"`
	Status        orders_grpc.Order_OrderStatus `bson:"status,omitempty"`

	Products []Product `bson:"products,omitempty"`
}

Order struct represents order.

func (Order) ConvertToGRPCModel

func (o Order) ConvertToGRPCModel() *orders_grpc.Order

ConvertToGRPCModel converts order to grpc compatible struct.

type OrderList

type OrderList []Order

func (OrderList) ConvertToGRPCModel

func (o OrderList) ConvertToGRPCModel() []*orders_grpc.Order

type OrderRepository

type OrderRepository struct {
	Storage *mongo.Database
	Ctx     context.Context
}

OrderRepository handles operations in Mongo.

func (*OrderRepository) Complete

func (o *OrderRepository) Complete(orderID string) (string, error)

Complete updates status of given order id and returns userID.

func (*OrderRepository) FindAll

func (o *OrderRepository) FindAll(userID string) (OrderList, error)

FindAll fetches all completed order documents that matching with user id.

func (*OrderRepository) Start

func (o *OrderRepository) Start(userID string, products []Product) (*Order, error)

Start inserts new order record with state *STARTED*.

type Product

type Product struct {
	ID          string  `bson:"id,omitempty"`
	Title       string  `bson:"title,omitempty"`
	Description string  `bson:"description,omitempty"`
	Image       string  `bson:"image,omitempty"`
	Price       float32 `bson:"price,omitempty"`
}

Product struct represents product.

func (Product) ConvertToGRPCModel

func (p Product) ConvertToGRPCModel() *orders_grpc.Product

ConvertToGRPCModel converts product to grpc compatible struct.

type Repository

type Repository interface {
	FindAll(userID string) (OrderList, error)
	Start(userID string, products []Product) (*Order, error)
	Complete(orderID string) (string, error)
}

Jump to

Keyboard shortcuts

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