https://db.dai.fmph.uniba.sk/teaching/db2/projekt/
https://docs.google.com/document/d/12sy75jUickbnZCY0HU3kC7AHjLCxAdfOPmqy-dRTYis/edit#
configure database connection in /db/db.go
go run main.go
Golang 1.18 (because of generics)
import "ondrejmaksi.com/db2project/db"
func GetDatabase() *sql.DB
public function to get database instance as singleton
func RunScript(path string) error
function to run sql script
Generated by gomarkdoc
import "ondrejmaksi.com/db2project/rdg"
- func AddProductToBasket(user User, product Product)
- func CreateOrder(order Order) int
- func CreateOrderItem(orderItem OrderItem)
- func CreateProduct(product Product)
- func CreateUser(user User)
- func DeleteBasketItem(product Product)
- func DeleteProduct(product Product)
- func DeleteUser(user User)
- func EmptyBasket(userId int)
- func ListOrderItems(orderId int)
- func UpdateBasketItemQuantity(product Product)
- func UpdateProduct(product Product)
- func UpdateUser(user User)
- type Jsonable
- type Order
- type OrderItem
- type Product
- type SaleStatistic
- type SearchStatistic
- type User
func AddProductToBasket(user User, product Product)
func CreateOrder(order Order) int
func CreateOrderItem(orderItem OrderItem)
func CreateProduct(product Product)
func CreateUser(user User)
func DeleteBasketItem(product Product)
func DeleteProduct(product Product)
func DeleteUser(user User)
func EmptyBasket(userId int)
func ListOrderItems(orderId int)
func UpdateBasketItemQuantity(product Product)
func UpdateProduct(product Product)
func UpdateUser(user User)
Json serialization struct
type Jsonable struct {
}
func (u *Jsonable) ToJson() string
An order, containing an address, Total price and status.
type Order struct {
Id int
UserId int
Address string
Total float64
Status string
}
func ListOrders() []Order
An item of an order, containing the product id reference, the order id reference and the quantity.
type OrderItem struct {
Id int
UserId int
ProductId int
OrderId int
Quantity int
}
A product row with Name, Price and Quantity
type Product struct {
Jsonable
Id uint
Name string
Price float64
Quantity uint
}
func GetProducts() []Product
func ListProductsInBasket(userId int) []Product
func SearchForProductByAttribute(searchText string) ([]Product, error)
Fulltext search for product by string input. Searches in all product attributes and product name
Detailnosť popisu produktu je počet atribútov, ktorý má produkt v systéme vyplnený. Pre každú detailnosť popisu produktu vypočítajte počet predaných kusov produktov s danou detailnosťou produktu.
type SaleStatistic struct {
AttributeCount int
TotalSold int
}
func GetSaleStatistics() []SaleStatistic
Používateľ zadá na vstupe počiatočný rok. Pre každý mesiac v danom a nasledovných rokoch (januar 2018, februar 2018, …) vypočítajte, aký je pomer medzi tými vyhľadávacími dopytmi, ktoré obsahujú názov produktu a tými, ktorý názov produktu neobsahujú. Vo výstupe musia byť mesiace, pre ktoré nie sú v databáze dáta. Ak daný pomer nie je pre daný mesiac definovaný, vo výstupe má byť NULL.
type SearchStatistic struct {
Month time.Time
Share sql.NullFloat64
}
func GetSearchStatistics(year string) []SearchStatistic
User struct containing id, email and basket item count
type User struct {
Id int
Email string
BasketItemCount int
}
func GetUser(id int) []User
func GetUsers() []User
Generated by gomarkdoc
import "ondrejmaksi.com/db2project/ts"
- func CancelOrder(order rdg.Order)
- func CreateOrder(userId int, address string)
- func ExpediteOrder(order rdg.Order) error
- func PayOrder(order rdg.Order, amount float64) error
func CancelOrder(order rdg.Order)
Objednávky, ktoré ešte neboli zaplatené, sa dajú zrušiť. Zarezervovaný tovar sa musí odblokovať. Zaplatené ani expedované objednávky nie je možné zrušiť.
func CreateOrder(userId int, address string)
Používateľ si zvolí, že chce objednať tovar, ktorý má vložený v košíku. Zadá miesto dodania. Vypočíta sa celková cena (produkty + doprava). V systéme sa vytvorí objednávka v stave vytvorená. Tovar sa na sklade rezervuje. Ak nie je všetok tovar na sklade, objednávka sa stale vytvorí, no používateľ je na to upozornený.
func ExpediteOrder(order rdg.Order) error
Zamestnanec vyberie id objednávky, ktorú chce expedovať. Ak je objednávka zaplatená a je dostatok tovarov na sklade, objednávka sa presunie do stavu expedovaná. Zároveň sa upravia skladové zásoby tovarov.
func PayOrder(order rdg.Order, amount float64) error
Po zaplatení sa v systéme eviduje platba. V prípade, že výška platby nesedí so sumou objednávky, platba musí byť vrátená (toto simulujte nejakým výpisom do konzoly). Po úspešnej platbe sa objednávka presúva do stavu zaplatená. V prípade, že na sklade nie je dostatočné množstvo nejakého tovaru, tento tovar sa automaticky objedná z veľkoskladu a doplní v požadovanom počte (simulujte výpisom do konzoly). Dvakrát zaplatiť tú istú objednávku možné nie je. Systém to musí odmietnuť a oznámiť chybu.
Generated by gomarkdoc
import "ondrejmaksi.com/db2project/ui"
- func Init() *tview.Application
- func NewApp() *tview.Application
- [func NoopT any](<#func-noop>)
- type Actions
- func (c *Actions) AddBasketItem(product rdg.Product)
- func (c *Actions) CancelOrder(order rdg.Order)
- func (c *Actions) CreateOrder(userId int, address string)
- func (c *Actions) CreateProduct(product rdg.Product)
- func (c *Actions) CreateUser(user rdg.User)
- func (c *Actions) DeleteBasketItem(product rdg.Product)
- func (c *Actions) DeleteProduct(product rdg.Product)
- func (c *Actions) DeleteUser(user rdg.User)
- func (c *Actions) ExpediteOrder(order rdg.Order)
- func (c *Actions) GetSearchStatistics(searchText string)
- func (c *Actions) PayOrder(order rdg.Order, amount float64)
- func (c *Actions) SearchByAttribute(searchText string)
- func (c *Actions) ShowAddBasketItem(product rdg.Product)
- func (c *Actions) ShowBasket(user rdg.User)
- func (c *Actions) ShowCreateOrder(user rdg.User)
- func (c *Actions) ShowEditBasketItem(product rdg.Product)
- func (c *Actions) ShowEditProduct(product rdg.Product)
- func (c *Actions) ShowEditUser(user rdg.User)
- func (c *Actions) ShowNewUser()
- func (c *Actions) ShowOrderList()
- func (c *Actions) ShowPayOrder(order rdg.Order)
- func (c *Actions) ShowProductList()
- func (c *Actions) ShowSaleStatistics()
- func (c *Actions) ShowUserList()
- func (c *Actions) UpdateBasketItem(product rdg.Product)
- func (c *Actions) UpdateProduct(product rdg.Product)
- func (c *Actions) UpdateUser(user rdg.User)
- type AppState
func Init() *tview.Application
Application initialization
func NewApp() *tview.Application
Application constructor, creates main application window and components, adds handling for state changes
func Noop[T any](T)
Actions struct, holds actions modifying state, actions beginning with Show change screen content
type Actions struct {
}
func (c *Actions) AddBasketItem(product rdg.Product)
func (c *Actions) CancelOrder(order rdg.Order)
func (c *Actions) CreateOrder(userId int, address string)
func (c *Actions) CreateProduct(product rdg.Product)
func (c *Actions) CreateUser(user rdg.User)
func (c *Actions) DeleteBasketItem(product rdg.Product)
func (c *Actions) DeleteProduct(product rdg.Product)
func (c *Actions) DeleteUser(user rdg.User)
func (c *Actions) ExpediteOrder(order rdg.Order)
func (c *Actions) GetSearchStatistics(searchText string)
func (c *Actions) PayOrder(order rdg.Order, amount float64)
func (c *Actions) SearchByAttribute(searchText string)
func (c *Actions) ShowAddBasketItem(product rdg.Product)
func (c *Actions) ShowBasket(user rdg.User)
func (c *Actions) ShowCreateOrder(user rdg.User)
func (c *Actions) ShowEditBasketItem(product rdg.Product)
func (c *Actions) ShowEditProduct(product rdg.Product)
func (c *Actions) ShowEditUser(user rdg.User)
func (c *Actions) ShowNewUser()
func (c *Actions) ShowOrderList()
func (c *Actions) ShowPayOrder(order rdg.Order)
func (c *Actions) ShowProductList()
func (c *Actions) ShowSaleStatistics()
func (c *Actions) ShowUserList()
func (c *Actions) UpdateBasketItem(product rdg.Product)
func (c *Actions) UpdateProduct(product rdg.Product)
func (c *Actions) UpdateUser(user rdg.User)
Struct holding all of the application UI state
type AppState struct {
// contains filtered or unexported fields
}
Generated by gomarkdoc
import "ondrejmaksi.com/db2project/ui/cmp"
- func NewBasketItemForm(product rdg.Product, onSubmit func(product rdg.Product), onCancel func()) *tview.Form
- func NewLog() *tview.List
- func NewMainMenu(onMenuSelect func(int, string)) *tview.List
- func NewOrderForm(userId int, onSubmit func(userId int, address string), onCancel func()) *tview.Form
- func NewPaymentForm(order rdg.Order, onSubmit func(order rdg.Order, amount float64), onCancel func()) *tview.Form
- func NewProductForm(product rdg.Product, onSubmit func(product rdg.Product), onCancel func()) *tview.Form
- func NewSearchForm(onSubmit func(searchText string), onCancel func()) *tview.Form
- func NewSearchStatisticsForm(onSubmit func(year string), onCancel func()) *tview.Form
- func NewStatusBar() (*tview.Flex, *tview.TextView, *tview.TextView)
- func NewUserForm(user rdg.User, onSubmit func(user rdg.User), onCancel func()) *tview.Form
- type Content
- type OrderTable
- type ProductTable
- func NewProductsTable(products []rdg.Product, onEdit func(product rdg.Product), onDelete func(product rdg.Product), onAdd func(user rdg.Product), onDone func()) *ProductTable
- func (pt *ProductTable) SetProps(products []rdg.Product, onDelete func(user rdg.Product), onEdit func(user rdg.Product), onAdd func(user rdg.Product), onDone func())
- func (pt *ProductTable) ShowProducts(products []rdg.Product)
- type SaleStatisticTable
- type SearchStatisticTable
- type UserTable
- func NewUsersTable(users []rdg.User, onDelete func(user rdg.User), onEdit func(user rdg.User), onBasket func(user rdg.User), onOrder func(user rdg.User), onDone func()) *UserTable
- func (ut *UserTable) SetProps(users []rdg.User, onDelete func(user rdg.User), onEdit func(user rdg.User), onBasket func(user rdg.User), onOrder func(user rdg.User), onDone func())
- func (ut *UserTable) ShowUsers(users []rdg.User)
func NewBasketItemForm(product rdg.Product, onSubmit func(product rdg.Product), onCancel func()) *tview.Form
Creates a new basket item form.
func NewLog() *tview.List
func NewMainMenu(onMenuSelect func(int, string)) *tview.List
func NewOrderForm(userId int, onSubmit func(userId int, address string), onCancel func()) *tview.Form
func NewPaymentForm(order rdg.Order, onSubmit func(order rdg.Order, amount float64), onCancel func()) *tview.Form
func NewProductForm(product rdg.Product, onSubmit func(product rdg.Product), onCancel func()) *tview.Form
func NewSearchForm(onSubmit func(searchText string), onCancel func()) *tview.Form
func NewSearchStatisticsForm(onSubmit func(year string), onCancel func()) *tview.Form
func NewStatusBar() (*tview.Flex, *tview.TextView, *tview.TextView)
func NewUserForm(user rdg.User, onSubmit func(user rdg.User), onCancel func()) *tview.Form
type Content struct {
*tview.Pages
}
func NewContent() *Content
func (c *Content) SetContent(content tview.Primitive)
type OrderTable struct {
*tview.Table
}
func NewOrdersTable(orders []rdg.Order, onCancel func(order rdg.Order), onPay func(order rdg.Order), onExpedite func(order rdg.Order), onDone func()) *OrderTable
Creates a new table for displaying a list of orders
type ProductTable struct {
*tview.Table
}
func NewProductsTable(products []rdg.Product, onEdit func(product rdg.Product), onDelete func(product rdg.Product), onAdd func(user rdg.Product), onDone func()) *ProductTable
func (pt *ProductTable) SetProps(products []rdg.Product, onDelete func(user rdg.Product), onEdit func(user rdg.Product), onAdd func(user rdg.Product), onDone func())
func (pt *ProductTable) ShowProducts(products []rdg.Product)
type SaleStatisticTable struct {
*tview.Table
}
func NewSaleStatisticsTable(saleStatistics []rdg.SaleStatistic, onDone func()) *SaleStatisticTable
func (sst *SaleStatisticTable) SetProps(saleStatistics []rdg.SaleStatistic, onDone func())
func (sst *SaleStatisticTable) ShowSaleStatistics(saleStatistics []rdg.SaleStatistic)
type SearchStatisticTable struct {
*tview.Table
}
func NewSearchStatisticsTable(searchStatistics []rdg.SearchStatistic, onDone func()) *SearchStatisticTable
func (sst *SearchStatisticTable) SetProps(searchStatistics []rdg.SearchStatistic, onDone func())
func (sst *SearchStatisticTable) ShowSearchStatistics(searchStatistics []rdg.SearchStatistic)
type UserTable struct {
*tview.Table
}
func NewUsersTable(users []rdg.User, onDelete func(user rdg.User), onEdit func(user rdg.User), onBasket func(user rdg.User), onOrder func(user rdg.User), onDone func()) *UserTable
func (ut *UserTable) SetProps(users []rdg.User, onDelete func(user rdg.User), onEdit func(user rdg.User), onBasket func(user rdg.User), onOrder func(user rdg.User), onDone func())
func (ut *UserTable) ShowUsers(users []rdg.User)
Generated by gomarkdoc
import "ondrejmaksi.com/db2project/ui/lib"
Generic single value state with Setter, Getter and ability to add handler, and notify all listeners
type GenericState[T any] struct {
// contains filtered or unexported fields
}
func NewGenericState[T any](value T) *GenericState[T]
func (s *GenericState[T]) AddHandler(handler func(T))
func (s *GenericState[T]) GetState() T
func (s *GenericState[T]) NotifyAll()
func (s *GenericState[T]) SetState(value T)
Generated by gomarkdoc
import "ondrejmaksi.com/db2project/ui/state"
- type ContentState
- type FocusState
- type KeyHintsState
- type MessageState
- type OrderState
- type OrdersState
- type ProductState
- type ProductsState
- type SaleStatisticsState
- type SearchStatisticsState
- type TitleState
- type UserState
- type UsersState
type ContentState struct {
// contains filtered or unexported fields
}
func NewContentState(value string) *ContentState
type FocusState struct {
// contains filtered or unexported fields
}
func NewFocusState(value string) *FocusState
func (f *FocusState) AddFocusTarget(name string, p tview.Primitive)
func (s *FocusState) Content()
func (f *FocusState) GetPrimitives() map[string]tview.Primitive
func (s *FocusState) Menu()
type KeyHintsState struct {
// contains filtered or unexported fields
}
func NewKeyHintsState(value string) *KeyHintsState
func (k *KeyHintsState) Clear()
func (k *KeyHintsState) SetForAddToBasket()
func (k *KeyHintsState) SetForBasket()
func (k *KeyHintsState) SetForOrder()
func (k *KeyHintsState) SetForProduct()
func (k *KeyHintsState) SetForUser()
type MessageState struct {
// contains filtered or unexported fields
}
func NewMessageState(value string) *MessageState
func (s *MessageState) Fail(message string)
func (s *MessageState) SetMessage(message string)
func (s *MessageState) Success(message string)
type OrderState struct {
// contains filtered or unexported fields
}
func NewOrderState(user rdg.Order) *OrderState
type OrdersState struct {
// contains filtered or unexported fields
}
func NewOrdersState(users []rdg.Order) *OrdersState
type ProductState struct {
// contains filtered or unexported fields
}
func NewProductState(user rdg.Product) *ProductState
type ProductsState struct {
// contains filtered or unexported fields
}
func NewProductsState(users []rdg.Product) *ProductsState
type SaleStatisticsState struct {
// contains filtered or unexported fields
}
func NewSaleStatisticsState(ss []rdg.SaleStatistic) *SaleStatisticsState
type SearchStatisticsState struct {
// contains filtered or unexported fields
}
func NewSearchStatisticsState(ss []rdg.SearchStatistic) *SearchStatisticsState
type TitleState struct {
// contains filtered or unexported fields
}
func NewTitleState(value string) *TitleState
type UserState struct {
// contains filtered or unexported fields
}
func NewUserState(user rdg.User) *UserState
type UsersState struct {
// contains filtered or unexported fields
}
func NewUsersState(users []rdg.User) *UsersState
Generated by gomarkdoc