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: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type MockProductRepository

type MockProductRepository struct {
	Storage map[string]Product
}

MockProductRepository handles interactions with database for products.

func NewProductRepo

func NewProductRepo() *MockProductRepository

NewProductRepo initializes MockProductRepository with empty storage.

func (*MockProductRepository) FetchAll

func (p *MockProductRepository) FetchAll() (products []Product)

FetchAll fetches all products from database.

func (*MockProductRepository) FetchOne

func (p *MockProductRepository) FetchOne(ID string) (*Product, error)

FetchOne fetches one record from database with matching ID, else returns error.

type Product

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

Product is a struct for representing products.

func SeedDatabase

func SeedDatabase() []Product

SeedDatabase seeds database with placeholder product records.

func (Product) ConvertToGRPC

func (p Product) ConvertToGRPC() *product_grpc.Product

ConvertToGRPC converts Product struct to gRPC compatible struct.

type ProductRepository

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

func (*ProductRepository) FetchAll

func (p *ProductRepository) FetchAll() []Product

func (*ProductRepository) FetchOne

func (p *ProductRepository) FetchOne(s string) (*Product, error)

type Repository

type Repository interface {
	FetchAll() []Product
	FetchOne(string) (*Product, error)
}

Repository is an interface to communicate with database.

Jump to

Keyboard shortcuts

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