storage

package
v0.0.0-...-ce38df1 Latest Latest
Warning

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

Go to latest
Published: Apr 2, 2024 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// Food
	ErrFoodNotFound  = errors.New("food not found")
	ErrFoodInvalid   = errors.New("invalid food")
	ErrFoodEmptyList = errors.New("empty food list")
	ErrFoodIsUsed    = errors.New("food is used")

	// Journal
	ErrJournalInvalid         = errors.New("journal invalid")
	ErrJournalMealReportEmpty = errors.New("empty journal meal report")
	ErrJournalReportEmpty     = errors.New("empty journal report")
	ErrJournalStatsEmpty      = errors.New("empty journal stats")
	ErrJournalInvalidFood     = errors.New("journal invalid food")
	ErrCopyToNotEmpty         = errors.New("copy destination not empty")

	// Weight
	ErrWeightNotFound  = errors.New("weight not found")
	ErrWeightInvalid   = errors.New("invalid weight")
	ErrWeightEmptyList = errors.New("empty weight list")

	// UserSettings
	ErrUserSettingsNotFound = errors.New("user settings not found")
	ErrUserSettingsInvalid  = errors.New("invalid user settings")
)

Functions

func WithDebug

func WithDebug() func(*StorageSQLite)

Types

type Food

type Food struct {
	Key     string
	Name    string
	Brand   string
	Cal100  float64
	Prot100 float64
	Fat100  float64
	Carb100 float64
	Comment string
}

func (*Food) Validate

func (r *Food) Validate() bool

type Journal

type Journal struct {
	Timestamp  time.Time
	Meal       Meal
	FoodKey    string
	FoodWeight float64
}

func (*Journal) Validate

func (r *Journal) Validate() bool

type JournalMealReport

type JournalMealReport struct {
	Timestamp  time.Time
	FoodKey    string
	FoodName   string
	FoodBrand  string
	FoodWeight float64
	Cal        float64
}

type JournalReport

type JournalReport struct {
	Timestamp  time.Time
	Meal       Meal
	FoodKey    string
	FoodName   string
	FoodBrand  string
	FoodWeight float64
	Cal        float64
	Prot       float64
	Fat        float64
	Carb       float64
}

type JournalStats

type JournalStats struct {
	Timestamp time.Time
	TotalCal  float64
	TotalProt float64
	TotalFat  float64
	TotalCarb float64
}

type Meal

type Meal int64

func NewMealFromString

func NewMealFromString(m string) Meal

func (Meal) ToString

func (r Meal) ToString() string

type Storage

type Storage interface {
	// // Food
	GetFood(ctx context.Context, key string) (*Food, error)
	SetFood(ctx context.Context, food *Food) error
	SetFoodComment(ctx context.Context, key, comment string) error
	GetFoodList(ctx context.Context) ([]Food, error)
	FindFood(ctx context.Context, pattern string) ([]Food, error)
	DeleteFood(ctx context.Context, key string) error

	// Weight
	GetWeightList(ctx context.Context, userID int64, from, to time.Time) ([]Weight, error)
	SetWeight(ctx context.Context, userID int64, weight *Weight) error
	DeleteWeight(ctx context.Context, userID int64, timestamp time.Time) error

	// Journal
	SetJournal(ctx context.Context, userID int64, journal *Journal) error
	DeleteJournal(ctx context.Context, userID int64, timestamp time.Time, meal Meal, foodkey string) error
	DeleteJournalMeal(ctx context.Context, userID int64, timestamp time.Time, meal Meal) error
	GetJournalMealReport(ctx context.Context, userID int64, timestamp time.Time, meal Meal) ([]JournalMealReport, error)
	GetJournalReport(ctx context.Context, userID int64, from, to time.Time) ([]JournalReport, error)
	GetJournalStats(ctx context.Context, userID int64, from, to time.Time) ([]JournalStats, error)
	CopyJournal(ctx context.Context, userID int64, from time.Time, mealFrom Meal, to time.Time, mealTo Meal) (int, error)

	// UserSettings
	GetUserSettings(ctx context.Context, userID int64) (*UserSettings, error)
	SetUserSettings(ctx context.Context, userID int64, settings *UserSettings) error

	Close() error
}

type StorageSQLite

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

func NewStorageSQLite

func NewStorageSQLite(dbFilePath string, opts ...func(*StorageSQLite)) (*StorageSQLite, error)

func (*StorageSQLite) Close

func (r *StorageSQLite) Close() error

func (*StorageSQLite) CopyJournal

func (r *StorageSQLite) CopyJournal(ctx context.Context, userID int64, from time.Time, mealFrom Meal, to time.Time, mealTo Meal) (int, error)

func (*StorageSQLite) DeleteFood

func (r *StorageSQLite) DeleteFood(ctx context.Context, key string) error

func (*StorageSQLite) DeleteJournal

func (r *StorageSQLite) DeleteJournal(ctx context.Context, userID int64, timestamp time.Time, meal Meal, foodkey string) error

func (*StorageSQLite) DeleteJournalMeal

func (r *StorageSQLite) DeleteJournalMeal(ctx context.Context, userID int64, timestamp time.Time, meal Meal) error

func (*StorageSQLite) DeleteWeight

func (r *StorageSQLite) DeleteWeight(ctx context.Context, userID int64, timestamp time.Time) error

func (*StorageSQLite) FindFood

func (r *StorageSQLite) FindFood(ctx context.Context, pattern string) ([]Food, error)

func (*StorageSQLite) GetFood

func (r *StorageSQLite) GetFood(ctx context.Context, key string) (*Food, error)

func (*StorageSQLite) GetFoodList

func (r *StorageSQLite) GetFoodList(ctx context.Context) ([]Food, error)

func (*StorageSQLite) GetJournalMealReport

func (r *StorageSQLite) GetJournalMealReport(ctx context.Context, userID int64, timestamp time.Time, meal Meal) ([]JournalMealReport, error)

func (*StorageSQLite) GetJournalReport

func (r *StorageSQLite) GetJournalReport(ctx context.Context, userID int64, from, to time.Time) ([]JournalReport, error)

func (*StorageSQLite) GetJournalStats

func (r *StorageSQLite) GetJournalStats(ctx context.Context, userID int64, from, to time.Time) ([]JournalStats, error)

func (*StorageSQLite) GetUserSettings

func (r *StorageSQLite) GetUserSettings(ctx context.Context, userID int64) (*UserSettings, error)

func (*StorageSQLite) GetWeightList

func (r *StorageSQLite) GetWeightList(ctx context.Context, userID int64, from, to time.Time) ([]Weight, error)

func (*StorageSQLite) SetFood

func (r *StorageSQLite) SetFood(ctx context.Context, food *Food) error

func (*StorageSQLite) SetFoodComment

func (r *StorageSQLite) SetFoodComment(ctx context.Context, key, comment string) error

func (*StorageSQLite) SetJournal

func (r *StorageSQLite) SetJournal(ctx context.Context, userID int64, journal *Journal) error

func (*StorageSQLite) SetUserSettings

func (r *StorageSQLite) SetUserSettings(ctx context.Context, userID int64, settings *UserSettings) error

func (*StorageSQLite) SetWeight

func (r *StorageSQLite) SetWeight(ctx context.Context, userID int64, weight *Weight) error

type TxFn

type TxFn func(ctx context.Context, tx *ent.Tx) (any, error)

type UserSettings

type UserSettings struct {
	CalLimit float64
}

func (*UserSettings) Validate

func (r *UserSettings) Validate() bool

type Weight

type Weight struct {
	Timestamp time.Time
	Value     float64
}

func (*Weight) Validate

func (r *Weight) Validate() bool

Directories

Path Synopsis
ent

Jump to

Keyboard shortcuts

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