Documentation ¶
Index ¶
- func HandleError(w http.ResponseWriter, r *http.Request, err error)
- type AddIngredientToStepParams
- type Application
- func (app *Application) AddIngredient(ctx context.Context, name string) (Ingredient, error)
- func (app *Application) AddIngredientToStep(ctx context.Context, params AddIngredientToStepParams) error
- func (app *Application) AddStepToRecipe(ctx context.Context, recipeID int, s *Step) error
- func (app *Application) DeleteIngredientFromStep(ctx context.Context, params DeleteIngredientFromStepParams) error
- func (app *Application) DeleteRecipeStepByID(ctx context.Context, id int) error
- func (app *Application) GetAllIngredients(ctx context.Context) ([]Ingredient, error)
- func (app *Application) GetAllRecipes(ctx context.Context) ([]ListEntry, error)
- func (app *Application) GetAllUnits(ctx context.Context) ([]Unit, error)
- func (app *Application) GetIngredient(ctx context.Context, id int) (Ingredient, error)
- func (app *Application) GetSingleRecipe(ctx context.Context, id int) (*Recipe, error)
- func (app *Application) GetStepByID(ctx context.Context, id int) (Step, error)
- func (app *Application) UpdateRecipe(ctx context.Context, r *Recipe) error
- func (app *Application) UpdateStep(ctx context.Context, s Step) error
- type Configuration
- type DeleteIngredientFromStepParams
- type Ingredient
- type ListEntry
- type Recipe
- type Step
- type Unit
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func HandleError ¶
func HandleError(w http.ResponseWriter, r *http.Request, err error)
HandleError handles all errors. They are logged. If a user message is provided with resperr.UserMessenger, that message is written to w.
Types ¶
type Application ¶
type Application struct { Templates templates.Templates Queries *queries.Queries Logger *zap.Logger }
Application holds the required resources for the application. This includes, but is not limited, to loggers, databases, cache handlers, etc.
func (*Application) AddIngredient ¶
func (app *Application) AddIngredient(ctx context.Context, name string) (Ingredient, error)
AddIngredient adds a new ingredient.
func (*Application) AddIngredientToStep ¶
func (app *Application) AddIngredientToStep(ctx context.Context, params AddIngredientToStepParams) error
AddIngredientToStep adds an ingredient to a step.
func (*Application) AddStepToRecipe ¶
AddStepToRecipe adds a step to the recipe.
func (*Application) DeleteIngredientFromStep ¶
func (app *Application) DeleteIngredientFromStep(ctx context.Context, params DeleteIngredientFromStepParams) error
DeleteIngredientFromStep deletes an ingredient from a step. The ingredient itself is unaffected. This action is idempotent, if the step is already deleted, no error is returned.
func (*Application) DeleteRecipeStepByID ¶
func (app *Application) DeleteRecipeStepByID(ctx context.Context, id int) error
DeleteRecipeStepByID deletes a recipe step by its ID. This is an idempotent action, if the step is already deleted, no error is returned.
func (*Application) GetAllIngredients ¶
func (app *Application) GetAllIngredients(ctx context.Context) ([]Ingredient, error)
func (*Application) GetAllRecipes ¶
func (app *Application) GetAllRecipes(ctx context.Context) ([]ListEntry, error)
func (*Application) GetAllUnits ¶
func (app *Application) GetAllUnits(ctx context.Context) ([]Unit, error)
func (*Application) GetIngredient ¶
func (app *Application) GetIngredient(ctx context.Context, id int) (Ingredient, error)
func (*Application) GetSingleRecipe ¶
GetSingleRecipe returns a recipe by its ID.
func (*Application) GetStepByID ¶
GetStepByID returns a step by its ID. If it does not exist, a not found error is returned.
func (*Application) UpdateRecipe ¶
func (app *Application) UpdateRecipe(ctx context.Context, r *Recipe) error
UpdateRecipe updates basic information about a recipe. This includes:
- Name
- Servings
- Description
All other properties are unaffected.
func (*Application) UpdateStep ¶
func (app *Application) UpdateStep(ctx context.Context, s Step) error
UpdateStep updates an existing step.
type Configuration ¶
type Ingredient ¶
type Recipe ¶
type Recipe struct { ID int Name string Description string WorkingTime time.Duration WaitingTime time.Duration CreatedAt time.Time UpdatedAt time.Time Source string BaseServings int // The number of servings that the recipe was written for. Servings int // The current amount of servings, calculated with WithServings. ServingsDescription string Ingredients []Ingredient Steps []Step }
func (*Recipe) WithServings ¶
WithServings recalculates the recipe with the given amount of servings. Any value less or equal to zero is ignored.