Documentation ¶
Index ¶
- Variables
- func AddBillbeeResponseToOrder(id int64, billbeeResponse string, db *sql.DB, mutex *sync.Mutex) error
- func AddOrder(db *sql.DB, order *Order, mutex *sync.Mutex) error
- func AddProduct(db *sql.DB, product *Product, mutex *sync.Mutex) error
- func ComputePrice(order *Order) float64
- func GetNumOrders(db *sql.DB, mutex *sync.Mutex) (int, error)
- func OpenDb(filename string) (*sql.DB, error)
- func Validate(db *sql.DB, mutex *sync.Mutex) error
- func VerifyOrder(order *Order) error
- type Order
- type Product
Constants ¶
This section is empty.
Variables ¶
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 AddProduct ¶
AddProduct adds a product to the database.
func ComputePrice ¶
ComputePrice applies our discount model.
func GetNumOrders ¶
GetNumOrders returns the number of orders currently saved in the database.
func VerifyOrder ¶
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.
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 ¶
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 ¶
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 ¶
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.