app

package
v0.0.0-...-08b4e76 Latest Latest
Warning

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

Go to latest
Published: Sep 28, 2023 License: AGPL-3.0 Imports: 14 Imported by: 0

Documentation

Index

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 AddIngredientToStepParams

type AddIngredientToStepParams struct {
	StepID       int
	IngredientID int
	UnitID       *int
	Amount       float64
	Note         string
}

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

func (app *Application) AddStepToRecipe(ctx context.Context, recipeID int, s *Step) error

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

func (app *Application) GetSingleRecipe(ctx context.Context, id int) (*Recipe, error)

GetSingleRecipe returns a recipe by its ID.

func (*Application) GetStepByID

func (app *Application) GetStepByID(ctx context.Context, id int) (Step, error)

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 Configuration struct {
	Database struct {
		ConnectionString string `toml:"connection-string"`
	} `toml:"database"`
	Web struct {
		Endpoint    string `toml:"endpoint"`
		TemplateDir string `toml:"template-dir"`
	}
}

type DeleteIngredientFromStepParams

type DeleteIngredientFromStepParams struct {
	StepID       int
	IngredientID int
}

type Ingredient

type Ingredient struct {
	ID       int
	Name     string
	Amount   float64
	Note     string
	UnitName string

	// only used for the template "ingredient" and its delete button
	RecipeID int
	StepID   int
}

type ListEntry

type ListEntry struct {
	ID   int
	Name string
}

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

func (r *Recipe) WithServings(servings int)

WithServings recalculates the recipe with the given amount of servings. Any value less or equal to zero is ignored.

type Step

type Step struct {
	ID          int
	RecipeID    int
	Instruction string
	Time        time.Duration
	Ingredients []Ingredient
}

type Unit

type Unit struct {
	ID   int
	Name string
}

Jump to

Keyboard shortcuts

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