omaksi / clishop

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

cli shop

clishop screnshot

Definiton:

https://db.dai.fmph.uniba.sk/teaching/db2/projekt/

https://docs.google.com/document/d/12sy75jUickbnZCY0HU3kC7AHjLCxAdfOPmqy-dRTYis/edit#

To run:

configure database connection in /db/db.go

go run main.go

Requirements

Golang 1.18 (because of generics)

db

import "ondrejmaksi.com/db2project/db"

Index

func GetDatabase

func GetDatabase() *sql.DB

public function to get database instance as singleton

func RunScript

func RunScript(path string) error

function to run sql script

Generated by gomarkdoc

rdg

import "ondrejmaksi.com/db2project/rdg"

Index

func AddProductToBasket

func AddProductToBasket(user User, product Product)

func CreateOrder

func CreateOrder(order Order) int

func CreateOrderItem

func CreateOrderItem(orderItem OrderItem)

func CreateProduct

func CreateProduct(product Product)

func CreateUser

func CreateUser(user User)

func DeleteBasketItem

func DeleteBasketItem(product Product)

func DeleteProduct

func DeleteProduct(product Product)

func DeleteUser

func DeleteUser(user User)

func EmptyBasket

func EmptyBasket(userId int)

func ListOrderItems

func ListOrderItems(orderId int)

func UpdateBasketItemQuantity

func UpdateBasketItemQuantity(product Product)

func UpdateProduct

func UpdateProduct(product Product)

func UpdateUser

func UpdateUser(user User)

type Jsonable

Json serialization struct

type Jsonable struct {
}

func (*Jsonable) ToJson

func (u *Jsonable) ToJson() string

type Order

An order, containing an address, Total price and status.

type Order struct {
    Id      int
    UserId  int
    Address string
    Total   float64
    Status  string
}

func ListOrders

func ListOrders() []Order

type OrderItem

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
}

type Product

A product row with Name, Price and Quantity

type Product struct {
    Jsonable
    Id       uint
    Name     string
    Price    float64
    Quantity uint
}

func GetProducts

func GetProducts() []Product

func ListProductsInBasket

func ListProductsInBasket(userId int) []Product

func SearchForProductByAttribute

func SearchForProductByAttribute(searchText string) ([]Product, error)

Fulltext search for product by string input. Searches in all product attributes and product name

type SaleStatistic

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

func GetSaleStatistics() []SaleStatistic

type SearchStatistic

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

func GetSearchStatistics(year string) []SearchStatistic

type User

User struct containing id, email and basket item count

type User struct {
    Id              int
    Email           string
    BasketItemCount int
}

func GetUser

func GetUser(id int) []User

func GetUsers

func GetUsers() []User

Generated by gomarkdoc

ts

import "ondrejmaksi.com/db2project/ts"

Index

func CancelOrder

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

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

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

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

ui

import "ondrejmaksi.com/db2project/ui"

Index

func Init

func Init() *tview.Application

Application initialization

func NewApp

func NewApp() *tview.Application

Application constructor, creates main application window and components, adds handling for state changes

func Noop

func Noop[T any](T)

type Actions

Actions struct, holds actions modifying state, actions beginning with Show change screen content

type Actions struct {
}

func (*Actions) AddBasketItem

func (c *Actions) AddBasketItem(product rdg.Product)

func (*Actions) CancelOrder

func (c *Actions) CancelOrder(order rdg.Order)

func (*Actions) CreateOrder

func (c *Actions) CreateOrder(userId int, address string)

func (*Actions) CreateProduct

func (c *Actions) CreateProduct(product rdg.Product)

func (*Actions) CreateUser

func (c *Actions) CreateUser(user rdg.User)

func (*Actions) DeleteBasketItem

func (c *Actions) DeleteBasketItem(product rdg.Product)

func (*Actions) DeleteProduct

func (c *Actions) DeleteProduct(product rdg.Product)

func (*Actions) DeleteUser

func (c *Actions) DeleteUser(user rdg.User)

func (*Actions) ExpediteOrder

func (c *Actions) ExpediteOrder(order rdg.Order)

func (*Actions) GetSearchStatistics

func (c *Actions) GetSearchStatistics(searchText string)

func (*Actions) PayOrder

func (c *Actions) PayOrder(order rdg.Order, amount float64)

func (*Actions) SearchByAttribute

func (c *Actions) SearchByAttribute(searchText string)

func (*Actions) ShowAddBasketItem

func (c *Actions) ShowAddBasketItem(product rdg.Product)

func (*Actions) ShowBasket

func (c *Actions) ShowBasket(user rdg.User)

func (*Actions) ShowCreateOrder

func (c *Actions) ShowCreateOrder(user rdg.User)

func (*Actions) ShowEditBasketItem

func (c *Actions) ShowEditBasketItem(product rdg.Product)

func (*Actions) ShowEditProduct

func (c *Actions) ShowEditProduct(product rdg.Product)

func (*Actions) ShowEditUser

func (c *Actions) ShowEditUser(user rdg.User)

func (*Actions) ShowNewUser

func (c *Actions) ShowNewUser()

func (*Actions) ShowOrderList

func (c *Actions) ShowOrderList()

func (*Actions) ShowPayOrder

func (c *Actions) ShowPayOrder(order rdg.Order)

func (*Actions) ShowProductList

func (c *Actions) ShowProductList()

func (*Actions) ShowSaleStatistics

func (c *Actions) ShowSaleStatistics()

func (*Actions) ShowUserList

func (c *Actions) ShowUserList()

func (*Actions) UpdateBasketItem

func (c *Actions) UpdateBasketItem(product rdg.Product)

func (*Actions) UpdateProduct

func (c *Actions) UpdateProduct(product rdg.Product)

func (*Actions) UpdateUser

func (c *Actions) UpdateUser(user rdg.User)

type AppState

Struct holding all of the application UI state

type AppState struct {
    // contains filtered or unexported fields
}

Generated by gomarkdoc

cmp

import "ondrejmaksi.com/db2project/ui/cmp"

Index

func NewBasketItemForm

func NewBasketItemForm(product rdg.Product, onSubmit func(product rdg.Product), onCancel func()) *tview.Form

Creates a new basket item form.

func NewLog

func NewLog() *tview.List

func NewMainMenu

func NewMainMenu(onMenuSelect func(int, string)) *tview.List

func NewOrderForm

func NewOrderForm(userId int, onSubmit func(userId int, address string), onCancel func()) *tview.Form

func NewPaymentForm

func NewPaymentForm(order rdg.Order, onSubmit func(order rdg.Order, amount float64), onCancel func()) *tview.Form

func NewProductForm

func NewProductForm(product rdg.Product, onSubmit func(product rdg.Product), onCancel func()) *tview.Form

func NewSearchForm

func NewSearchForm(onSubmit func(searchText string), onCancel func()) *tview.Form

func NewSearchStatisticsForm

func NewSearchStatisticsForm(onSubmit func(year string), onCancel func()) *tview.Form

func NewStatusBar

func NewStatusBar() (*tview.Flex, *tview.TextView, *tview.TextView)

func NewUserForm

func NewUserForm(user rdg.User, onSubmit func(user rdg.User), onCancel func()) *tview.Form

type Content

type Content struct {
    *tview.Pages
}

func NewContent

func NewContent() *Content

func (*Content) SetContent

func (c *Content) SetContent(content tview.Primitive)

type OrderTable

type OrderTable struct {
    *tview.Table
}

func NewOrdersTable

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

type ProductTable struct {
    *tview.Table
}

func NewProductsTable

func NewProductsTable(products []rdg.Product, onEdit func(product rdg.Product), onDelete func(product rdg.Product), onAdd func(user rdg.Product), onDone func()) *ProductTable

func (*ProductTable) SetProps

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 (*ProductTable) ShowProducts

func (pt *ProductTable) ShowProducts(products []rdg.Product)

type SaleStatisticTable

type SaleStatisticTable struct {
    *tview.Table
}

func NewSaleStatisticsTable

func NewSaleStatisticsTable(saleStatistics []rdg.SaleStatistic, onDone func()) *SaleStatisticTable

func (*SaleStatisticTable) SetProps

func (sst *SaleStatisticTable) SetProps(saleStatistics []rdg.SaleStatistic, onDone func())

func (*SaleStatisticTable) ShowSaleStatistics

func (sst *SaleStatisticTable) ShowSaleStatistics(saleStatistics []rdg.SaleStatistic)

type SearchStatisticTable

type SearchStatisticTable struct {
    *tview.Table
}

func NewSearchStatisticsTable

func NewSearchStatisticsTable(searchStatistics []rdg.SearchStatistic, onDone func()) *SearchStatisticTable

func (*SearchStatisticTable) SetProps

func (sst *SearchStatisticTable) SetProps(searchStatistics []rdg.SearchStatistic, onDone func())

func (*SearchStatisticTable) ShowSearchStatistics

func (sst *SearchStatisticTable) ShowSearchStatistics(searchStatistics []rdg.SearchStatistic)

type UserTable

type UserTable struct {
    *tview.Table
}

func NewUsersTable

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 (*UserTable) SetProps

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 (*UserTable) ShowUsers

func (ut *UserTable) ShowUsers(users []rdg.User)

Generated by gomarkdoc

lib

import "ondrejmaksi.com/db2project/ui/lib"

Index

type GenericState

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

func NewGenericState[T any](value T) *GenericState[T]

func (*GenericState[T]) AddHandler

func (s *GenericState[T]) AddHandler(handler func(T))

func (*GenericState[T]) GetState

func (s *GenericState[T]) GetState() T

func (*GenericState[T]) NotifyAll

func (s *GenericState[T]) NotifyAll()

func (*GenericState[T]) SetState

func (s *GenericState[T]) SetState(value T)

Generated by gomarkdoc

state

import "ondrejmaksi.com/db2project/ui/state"

Index

type ContentState

type ContentState struct {
    // contains filtered or unexported fields
}

func NewContentState

func NewContentState(value string) *ContentState

type FocusState

type FocusState struct {
    // contains filtered or unexported fields
}

func NewFocusState

func NewFocusState(value string) *FocusState

func (*FocusState) AddFocusTarget

func (f *FocusState) AddFocusTarget(name string, p tview.Primitive)

func (*FocusState) Content

func (s *FocusState) Content()

func (*FocusState) GetPrimitives

func (f *FocusState) GetPrimitives() map[string]tview.Primitive

func (*FocusState) Menu

func (s *FocusState) Menu()

type KeyHintsState

type KeyHintsState struct {
    // contains filtered or unexported fields
}

func NewKeyHintsState

func NewKeyHintsState(value string) *KeyHintsState

func (*KeyHintsState) Clear

func (k *KeyHintsState) Clear()

func (*KeyHintsState) SetForAddToBasket

func (k *KeyHintsState) SetForAddToBasket()

func (*KeyHintsState) SetForBasket

func (k *KeyHintsState) SetForBasket()

func (*KeyHintsState) SetForOrder

func (k *KeyHintsState) SetForOrder()

func (*KeyHintsState) SetForProduct

func (k *KeyHintsState) SetForProduct()

func (*KeyHintsState) SetForUser

func (k *KeyHintsState) SetForUser()

type MessageState

type MessageState struct {
    // contains filtered or unexported fields
}

func NewMessageState

func NewMessageState(value string) *MessageState

func (*MessageState) Fail

func (s *MessageState) Fail(message string)

func (*MessageState) SetMessage

func (s *MessageState) SetMessage(message string)

func (*MessageState) Success

func (s *MessageState) Success(message string)

type OrderState

type OrderState struct {
    // contains filtered or unexported fields
}

func NewOrderState

func NewOrderState(user rdg.Order) *OrderState

type OrdersState

type OrdersState struct {
    // contains filtered or unexported fields
}

func NewOrdersState

func NewOrdersState(users []rdg.Order) *OrdersState

type ProductState

type ProductState struct {
    // contains filtered or unexported fields
}

func NewProductState

func NewProductState(user rdg.Product) *ProductState

type ProductsState

type ProductsState struct {
    // contains filtered or unexported fields
}

func NewProductsState

func NewProductsState(users []rdg.Product) *ProductsState

type SaleStatisticsState

type SaleStatisticsState struct {
    // contains filtered or unexported fields
}

func NewSaleStatisticsState

func NewSaleStatisticsState(ss []rdg.SaleStatistic) *SaleStatisticsState

type SearchStatisticsState

type SearchStatisticsState struct {
    // contains filtered or unexported fields
}

func NewSearchStatisticsState

func NewSearchStatisticsState(ss []rdg.SearchStatistic) *SearchStatisticsState

type TitleState

type TitleState struct {
    // contains filtered or unexported fields
}

func NewTitleState

func NewTitleState(value string) *TitleState

type UserState

type UserState struct {
    // contains filtered or unexported fields
}

func NewUserState

func NewUserState(user rdg.User) *UserState

type UsersState

type UsersState struct {
    // contains filtered or unexported fields
}

func NewUsersState

func NewUsersState(users []rdg.User) *UsersState

Generated by gomarkdoc

About

License:Other


Languages

Language:Go 91.6%Language:PLpgSQL 7.8%Language:Shell 0.5%