model

package
v0.0.0-...-3669a94 Latest Latest
Warning

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

Go to latest
Published: Feb 28, 2023 License: GPL-3.0 Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var InvalidID = -1

InvalidID corresponds to the ID that is returned when something is *not* found in the database.

Functions

func AddBillbeeResponseToOrder

func AddBillbeeResponseToOrder(id int64, billbeeResponse string, db *sql.DB, mutex *sync.Mutex) error

AddBillbeeResponseToOrder saves the API response from forwarding an order to billbee for later debugging purposes.

func AddOrder

func AddOrder(db *sql.DB, order *Order, mutex *sync.Mutex) error

AddOrder adds an order to the database and sets the ID in the order.

func AddProduct

func AddProduct(db *sql.DB, product *Product, mutex *sync.Mutex) error

AddProduct adds a product to the database.

func ComputePrice

func ComputePrice(order *Order) float64

ComputePrice applies our discount model.

func GetNumOrders

func GetNumOrders(db *sql.DB, mutex *sync.Mutex) (int, error)

GetNumOrders returns the number of orders currently saved in the database.

func OpenDb

func OpenDb(filename string) (*sql.DB, error)

OpenDb opens the database with the given filename and returns a pointer to it.

func Validate

func Validate(db *sql.DB, mutex *sync.Mutex) error

Validate the content of the provided database and creates tables if-need-be.

func VerifyOrder

func VerifyOrder(order *Order) error

VerifyOrder verifies that an order is valid.

Types

type Order

type Order struct {
	ID                      int64  `json:"id"`
	ProductID               int    `json:"product_id"`
	Amount                  int    `json:"amount"`
	Date                    string `json:"date"`
	CompanyInvoice          string `json:"company_invoice"`
	FirstNameInvoice        string `json:"first_name_invoice"`
	LastNameInvoice         string `json:"last_name_invoice"`
	CompanyDelivery         string `json:"company_delivery"`
	FirstNameDelivery       string `json:"first_name_delivery"`
	LastNameDelivery        string `json:"last_name_delivery"`
	Email                   string `json:"email"`
	AddressStreetInvoice    string `json:"address_street_invoice"`
	AddressStreetNoInvoice  string `json:"address_street_no_invoice"`
	AddressCodeInvoice      string `json:"address_code_invoice"`
	AddressCityInvoice      string `json:"address_city_invoice"`
	AddressCountryInvoice   string `json:"address_country_invoice"`
	AddressStreetDelivery   string `json:"address_street_delivery"`
	AddressStreetNoDelivery string `json:"address_street_no_delivery"`
	AddressCodeDelivery     string `json:"address_code_delivery"`
	AddressCityDelivery     string `json:"address_city_delivery"`
	AddressCountryDelivery  string `json:"address_country_delivery"`
	Payment                 string `json:"payment"`
	Premium                 string `json:"premium"`
	Reseller                bool   `json:"is_reseller"`
	SlowFoodMember          bool   `json:"slow_food_member"`
	AgreesAGB               bool   `json:"agrees_agb"`
	AgreesPrivacy           bool   `json:"agrees_data_privacy"`
	Message                 string `json:"message"`
	BillbeeResponse         string `json:"billbee_api_response"`
}

Order database entry.

func GetOrders

func GetOrders(db *sql.DB, mutex *sync.Mutex) ([]Order, error)

GetOrders returns all orders.

type Product

type Product struct {
	ID          int     `json:"id"`
	Name        string  `json:"name"`
	Description string  `json:"description"`
	Price       float64 `json:"price"`
	Shipping    float64 `json:"shipping"`
}

Product database entry.

func GetProduct

func GetProduct(db *sql.DB, name string, mutex *sync.Mutex) (*Product, error)

GetProduct queries the database for a product with the given name. If the returned product's ID is identical to model.InvalidID, then the corresponding product was not found.

func GetProductByID

func GetProductByID(db *sql.DB, id int, mutex *sync.Mutex) (*Product, error)

GetProductByID queries the database for a product with the given ID. If the returned product's ID is identical to model.InvalidID, then the corresponding product was not found.

func GetProducts

func GetProducts(db *sql.DB, mutex *sync.Mutex) ([]Product, error)

GetProducts returns all products in the database.

func GetProductsThatShouldExist

func GetProductsThatShouldExist() [1]Product

GetProductsThatShouldExist returns an array of products that should exist in the database.

Jump to

Keyboard shortcuts

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