model

package
v0.0.0-...-cb8fb00 Latest Latest
Warning

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

Go to latest
Published: Mar 26, 2024 License: Unlicense Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FindAllReceiptsForUser

func FindAllReceiptsForUser(db *sql.DB, user *User, filters *ReceiptFilter) (*[]Receipt, error)

func InitDB

func InitDB(db *sql.DB) error

func NewDB

func NewDB() (*sql.DB, error)

Types

type Receipt

type Receipt struct {
	ID          int64     `db:"id"`
	UserID      int64     `db:"user_id"`
	Supermarket string    `db:"supermarket"`
	Date        time.Time `db:"receipt_date"`
	Total       float64   `db:"total"`
	Currency    string    `db:"currency"`
	Items       []ReceiptItem
}

func CreateReceipt

func CreateReceipt(db *sql.DB, receipt *Receipt) (*Receipt, error)

Create a new receipt in the database and return record ID or error if could not be created

func FindReceiptBySupermarketDateAmount

func FindReceiptBySupermarketDateAmount(db *sql.DB, supermarket string, date time.Time, total float64) (*Receipt, error)

Check if exists a receipt for given supermarket, date and amount (these values should be unique)

func FindReceiptForUser

func FindReceiptForUser(db *sql.DB, receipt_id int, user_id int) (*Receipt, error)

type ReceiptFilter

type ReceiptFilter struct {
	Supermarket string
	Page        int64
	PerPage     int64
	MinDate     *time.Time
	MaxDate     *time.Time
	Item        string
}

type ReceiptItem

type ReceiptItem struct {
	ID        int64   `db:"id"`
	ReceiptID int64   `db:"receipt_id"`
	Name      string  `db:"name"`
	Quantity  float64 `db:"quantity"`
	Price     float64 `db:"price"`
	UnitPrice float64 `db:"unit_price"`
}

type User

type User struct {
	ID        int64  `db:"id"`
	GoogleUID string `db:"google_uid"`
}

func FindUserByGoogleUid

func FindUserByGoogleUid(db *sql.DB, google_uid string) (*User, error)

Check if given google id user exists in database

func FindUserById

func FindUserById(db *sql.DB, user_id int) (*User, error)

Find user by given ID and return User instance or error

Jump to

Keyboard shortcuts

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