record

package
v0.0.0-...-7171961 Latest Latest
Warning

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

Go to latest
Published: Mar 18, 2024 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ResponseStart = "Welcome. Here's a list of my commands:\n\n" +
		listItems +
		"/showitem - show an item's details\n" +
		"/additem - add an item\n" +
		"/updateitem - update an item\n" +
		"/deleteitem - delete an item\n" +
		"/importitems - import items from a CSV file\n"

	ResponseInvalid = "That's not a valid command. Here's a list of valid commands:\n\n" +
		listItems +
		"/showitem - show an item's details\n" +
		"/additem - add an item\n" +
		"/updateitem - update an item\n" +
		"/deleteitem - delete an item\n"

	ResponseInvalidList = "That's not a valid command. Here's a list of valid commands:\n\n" +
		"*List DB*\n" +
		listItems +
		"/listitems sort by _field_ - sort list (ascending)\n" +
		"/listitems sort by _field_ desc - sort list (descending)\n" +
		"/listitems filter by _field_ = _value_ - filter items in your inventory\n" +
		"_filter operations: =, <, >, <=, >=, <>, like_\n"

	ResponseAdd        = "What is this item called?"
	ResponseSuccessAdd = "Added \"<item>\" to the inventory.\n\n" +
		"Update this item's details using the commands below:\n" +
		"/updateitem _itemName_ description _itemDescription_\n" +
		"/updateitem _itemName_ calories _calories_\n" +
		"/updateitem _itemName_ amount _itemAmount_\n" +
		"/updateitem _itemName_ category _itemCategory_\n" +
		"/updateitem _itemName_ price _itemPrice_\n" +
		"/updateitem _itemName_ expiration _itemExpiration_\n"

	ResponseShow = "Which item do you want to see?"

	ResponseDelete        = "Which item do you want to delete?"
	ResponseSuccessDelete = "Removed \"<item>\" from the inventory."

	ResponseUpdate        = "Which item do you want to update?"
	ResponseSuccessUpdate = "Updated <item>'s <field>."
	ResponseInvalidUpdate = "Invalid parameters. To update an item, use the commands below:\n\n" +
		"*Update DB*\n" +
		"/updateitem _itemName_ description _itemDescription_\n" +
		"/updateitem _itemName_ calories _calories_\n" +
		"/updateitem _itemName_ amount _itemAmount_\n" +
		"/updateitem _itemName_ category _itemCategory_\n" +
		"/updateitem _itemName_ price _itemPrice_\n" +
		"/updateitem _itemName_ expiration _itemExpiration_\n"

	ResponseItemNotExist  = "Item \"<item>\" does not exist in the inventory."
	ResponseNoMatchFilter = "There are no items matching that filter."
	ResponseNoItems       = "There are no items in your inventory."

	ResponseImport = "Please attach the CSV file."
)

Functions

This section is empty.

Types

type Item

type Item struct {
	ID          uint
	Name        string
	Description string
	Amount      float32
	Unit        string
	Calories    uint16
	Category    string
	Price       float32
	Currency    string
	Expiration  time.Time
	CreatedAt   time.Time
	UpdatedAt   time.Time
}

Item is the model used for item-specific records

type RecordDB

type RecordDB struct {
	DB *gorm.DB
}

RecordDB contains the database instance used for record transactions

func (*RecordDB) Add

func (r *RecordDB) Add(params []string) (string, error)

Add inserts a new record into a table

func (*RecordDB) CheckCommand

func (r *RecordDB) CheckCommand(data string) (string, error)

CheckCommand checks if the command is valid and returns the appropriate response

func (*RecordDB) Delete

func (r *RecordDB) Delete(params []string) (string, error)

Delete deletes a specific record

func (*RecordDB) Import

func (r *RecordDB) Import(records [][]string) (string, error)

Import imports a list of records into a table

func (*RecordDB) ImportRecords

func (r *RecordDB) ImportRecords(records [][]string) (string, error)

ImportRecords imports a list of records into the "item" table

func (*RecordDB) List

func (r *RecordDB) List(params []string) (string, error)

List returns a list of records from a table

func (*RecordDB) ListRecords

func (r *RecordDB) ListRecords(cmd []string) (string, error)

ListRecords returns a list of records from the "item" table

func (*RecordDB) Listen

func (r *RecordDB) Listen(updates tgbotapi.UpdatesChannel, bot *tgbotapi.BotAPI)

Listen listens to the messages send to the bot and sends the appropriate response

func (*RecordDB) Show

func (r *RecordDB) Show(params []string) (string, error)

Show returns the details of a specific record

func (*RecordDB) Update

func (r *RecordDB) Update(params []string) (string, error)

Update updates a specific record

func (*RecordDB) UpdateRecord

func (r *RecordDB) UpdateRecord(params []string) (string, error)

UpdateRecord updates a specific "item" record

Jump to

Keyboard shortcuts

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