store

package
v0.0.0-...-a457421 Latest Latest
Warning

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

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

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Seed

func Seed(db *gorm.DB) error

Types

type Database

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

func NewDatabase

func NewDatabase() (*Database, error)

NewDatabase makes persistent sqlite based store

func (*Database) GetIngredients

func (s *Database) GetIngredients() (result *Ingredients, err error)

func (*Database) GetRecipe

func (s *Database) GetRecipe(id uint) (result *RecipeV1, err error)

func (*Database) GetServing

func (s *Database) GetServing(id uint) (result *ServingV1, err error)

func (*Database) GetUnits

func (s *Database) GetUnits() (result *[]UnitV1, err error)

func (*Database) LoadRecipes

func (s *Database) LoadRecipes(page int, pageSize int, searchTerm string) (result *Recipes, err error)

func (*Database) LoadServings

func (s *Database) LoadServings() (result *[]ServingV1, err error)

func (*Database) Migrate

func (s *Database) Migrate() error

func (*Database) SaveIngredient

func (s *Database) SaveIngredient(ingredient *IngredientV1) (err error)

func (*Database) SaveRecipe

func (s *Database) SaveRecipe(recipe *RecipeV1) (savedRecipe *RecipeV1, err error)

func (*Database) SaveServing

func (s *Database) SaveServing(serving *ServingV1) (err error)

func (*Database) SaveSyncJob

func (s *Database) SaveSyncJob(job *JobV1) (savedJob *JobV1, err error)

type Day

type Day struct {
	ID           string
	IsCurrentDay bool
	Title        string
}

type IngredientV1

type IngredientV1 struct {
	ID uint `gorm:"primaryKey;autoIncrement"`

	Name string `gorm:"type:varchar(255);unique;not null"`

	UnitID uint   `gorm:"not null"`
	Unit   UnitV1 `gorm:"foreignKey:UnitID"`

	CreatedAt time.Time
	UpdatedAt sql.NullTime
}

type Ingredients

type Ingredients struct {
	Ingredients []IngredientV1
}

TODO: add pagination

type JobStatus

type JobStatus string
const (
	JobStatusPending    JobStatus = "pending"
	JobStatusInProgress JobStatus = "in_progress"
	JobStatusCompleted  JobStatus = "completed"
	JobStatusFailed     JobStatus = "failed"
)

type JobV1

type JobV1 struct {
	ID     uint      `gorm:"primaryKey;autoIncrement"`
	Status JobStatus `gorm:"not null"`

	CreatedAt time.Time
	UpdatedAt sql.NullTime
}

type PantryV1

type PantryV1 struct {
	IngredientV1ID uint
	Ingredient     IngredientV1 `gorm:"foreignKey:IngredientV1ID"`

	Amount float64
}

type RecipeDifficultyV1

type RecipeDifficultyV1 struct {
	ID uint `gorm:"primaryKey;autoIncrement"`

	Name string `gorm:"type:varchar(255);unique;not null"`

	Recipes []RecipeV1 `gorm:"foreignKey:RecipeDifficultyID"`

	CreatedAt time.Time
	UpdatedAt sql.NullTime
}

type RecipeV1

type RecipeV1 struct {
	ID uint `gorm:"primaryKey;autoIncrement"`

	Title                    string                 `gorm:"type:varchar(255);unique;not null"`
	Description              string                 `gorm:"type:varchar(4000)"`
	Ingredients              []RecipeV1IngredientV1 `gorm:"foreignKey:RecipeV1ID"`
	PreparationTimeInMinutes uint
	CookingTimeInMinutes     uint
	ThumbnailUrl             sql.NullString
	PdfUrl                   sql.NullString

	RecipeDifficultyID uint
	RecipeDifficulty   RecipeDifficultyV1 `gorm:"foreignKey:RecipeDifficultyID"`

	Rating      float64 `gorm:"default:0.0"`
	RatingCount uint    `gorm:"default:0"`

	Servings []ServingV1 `gorm:"foreignKey:RecipeID"`

	CreatedAt time.Time
	UpdatedAt sql.NullTime
}

type RecipeV1IngredientV1

type RecipeV1IngredientV1 struct {
	ID uint `gorm:"primaryKey;autoIncrement"`

	RecipeV1ID uint
	Recipe     RecipeV1 `gorm:"foreignKey:RecipeV1ID"`

	IngredientV1ID uint
	Ingredient     IngredientV1 `gorm:"foreignKey:IngredientV1ID"`

	Amount float64
}

type Recipes

type Recipes struct {
	Recipes    []RecipeV1
	Page       int
	PageSize   int
	SearchTerm string
}

type ServingV1

type ServingV1 struct {
	ID uint `gorm:"primaryKey;autoIncrement"`

	RecipeID uint
	Recipe   RecipeV1 `gorm:"foreignKey:RecipeID"`

	CookedAt sql.NullTime

	CreatedAt time.Time
	UpdatedAt sql.NullTime
}

type UnitV1

type UnitV1 struct {
	ID uint `gorm:"primaryKey;autoIncrement"`

	Name string `gorm:"type:varchar(255);unique;not null"`

	Ingredients []IngredientV1 `gorm:"foreignKey:UnitID"`

	CreatedAt time.Time
	UpdatedAt sql.NullTime
}

type Week

type Week struct {
	Days   []Day
	Number int
	Year   int
}

Jump to

Keyboard shortcuts

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