models

package
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: May 25, 2024 License: GPL-3.0 Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrNoRecord = errors.New("models: no matching record found")

Functions

This section is empty.

Types

type FullIngredient added in v1.1.0

type FullIngredient struct {
	*Ingredient
	Quantity float64 `json:"quantity"`
	Unit     string  `json:"unit"`
}

FullIngredient abstracts away the two models for storing ingredients and their quantities/units

type Ingredient added in v1.1.0

type Ingredient struct {
	ID   int    `json:"id"`
	Name string `json:"name"`
}

type IngredientModel added in v1.1.0

type IngredientModel struct {
	DB *sql.DB
}

func (*IngredientModel) GetByRecipeID added in v1.1.0

func (m *IngredientModel) GetByRecipeID(tx transactions.Transaction, recipeID int) ([]*FullIngredient, error)

func (*IngredientModel) InsertIfNotExists added in v1.1.0

func (m *IngredientModel) InsertIfNotExists(tx transactions.Transaction, name string) (int, error)

type IngredientModelInterface added in v1.1.0

type IngredientModelInterface interface {
	GetByRecipeID(tx transactions.Transaction, recipeID int) ([]*FullIngredient, error)
	InsertIfNotExists(tx transactions.Transaction, name string) (int, error)
}

type Recipe

type Recipe struct {
	ID              int               `json:"id"`
	Name            string            `json:"name"`
	Description     string            `json:"description,omitempty"`
	Instructions    string            `json:"instructions,omitempty"`
	PreparationTime string            `json:"preparation_time,omitempty"`
	CookingTime     string            `json:"cooking_time,omitempty"`
	Portions        int               `json:"portions,omitempty"`
	CreatedAt       time.Time         `json:"-"`
	Ingredients     []*FullIngredient `json:"ingredients,omitempty"`
	Tags            []*Tag            `json:"tags,omitempty"`
}

type RecipeIngredient added in v1.1.0

type RecipeIngredient struct {
	RecipeID     int     `json:"recipe_id"`
	IngredientID int     `json:"ingredient_id"`
	Quantity     float64 `json:"quantity"`
	Unit         string  `json:"unit"`
}

type RecipeIngredientModel added in v1.1.0

type RecipeIngredientModel struct {
	DB *sql.DB
}

func (*RecipeIngredientModel) Associate added in v1.1.0

func (m *RecipeIngredientModel) Associate(tx transactions.Transaction, recipeID, ingredientID int, quantity float64, unit string) error

func (*RecipeIngredientModel) DissociateNotInList added in v1.1.0

func (m *RecipeIngredientModel) DissociateNotInList(tx transactions.Transaction, recipeID int, recipeIngredients []*FullIngredient) error

type RecipeIngredientModelInterface added in v1.1.0

type RecipeIngredientModelInterface interface {
	Associate(tx transactions.Transaction, recipeID, ingredientID int, quantity float64, unit string) error
	DissociateNotInList(tx transactions.Transaction, recipeID int, recipeIngredients []*FullIngredient) error
	// contains filtered or unexported methods
}

type RecipeModel

type RecipeModel struct {
	DB                    *sql.DB
	IngredientModel       IngredientModelInterface
	RecipeIngredientModel RecipeIngredientModelInterface
	TagModel              TagModelInterface
	RecipeTagModel        RecipeTagModelInterface
}

func (*RecipeModel) Delete

func (m *RecipeModel) Delete(id int) error

func (*RecipeModel) Get

func (m *RecipeModel) Get(id int) (*Recipe, error)

func (*RecipeModel) GetAll added in v1.1.0

func (m *RecipeModel) GetAll() ([]*Recipe, error)

func (*RecipeModel) GetWithTx added in v1.1.0

func (m *RecipeModel) GetWithTx(tx transactions.Transaction, id int) (*Recipe, error)

func (*RecipeModel) Insert

func (m *RecipeModel) Insert(name, description, instructions, preparationTime, cookingTime string, portions int, ingredients []*FullIngredient, tags []*Tag) (int, error)

func (*RecipeModel) Ping added in v1.1.0

func (m *RecipeModel) Ping() error

func (*RecipeModel) Update

func (m *RecipeModel) Update(recipe *Recipe) error

type RecipeModelInterface added in v1.1.0

type RecipeModelInterface interface {
	Ping() error
	Insert(name, description, instructions, preparationTime, cookingTime string, portions int, ingredients []*FullIngredient, tags []*Tag) (int, error)
	GetAll() ([]*Recipe, error)
	GetWithTx(tx transactions.Transaction, id int) (*Recipe, error)
	Get(id int) (*Recipe, error)
	Update(recipe *Recipe) error
	Delete(id int) error
}

type RecipeTag added in v1.1.0

type RecipeTag struct {
	RecipeID int `json:"recipe_id"`
	TagID    int `json:"tag_id"`
}

type RecipeTagModel added in v1.1.0

type RecipeTagModel struct {
	DB *sql.DB
}

func (*RecipeTagModel) Associate added in v1.1.0

func (m *RecipeTagModel) Associate(tx transactions.Transaction, recipeID, tagID int) error

func (*RecipeTagModel) DissociateNotInList added in v1.1.0

func (m *RecipeTagModel) DissociateNotInList(tx transactions.Transaction, recipeID int, recipeTags []*Tag) error

type RecipeTagModelInterface added in v1.1.0

type RecipeTagModelInterface interface {
	Associate(tx transactions.Transaction, recipeID, tagID int) error
	DissociateNotInList(tx transactions.Transaction, recipeID int, recipeTags []*Tag) error
	// contains filtered or unexported methods
}

type Tag added in v1.1.0

type Tag struct {
	ID   int    `json:"id"`
	Name string `json:"name,omitempty"`
}

type TagModel added in v1.1.0

type TagModel struct {
	DB *sql.DB
}

func (*TagModel) GetByRecipeID added in v1.1.0

func (m *TagModel) GetByRecipeID(tx transactions.Transaction, recipeID int) ([]*Tag, error)

func (*TagModel) InsertIfNotExists added in v1.1.0

func (m *TagModel) InsertIfNotExists(tx transactions.Transaction, name string) (int, error)

type TagModelInterface added in v1.1.0

type TagModelInterface interface {
	GetByRecipeID(tx transactions.Transaction, recipeID int) ([]*Tag, error)
	InsertIfNotExists(tx transactions.Transaction, name string) (int, error)
}

Jump to

Keyboard shortcuts

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