Hayden Hargreaves 7ad710f880 (FEAT): Search is returning recipes, next just need a UI and wire job.
Furthermore, not sure how we are going to handle the searching. Maybe a
full-text search index? For now, it has been ignored, but the filters
seem to be working properly.
2025-07-06 22:40:15 -07:00

83 lines
2.2 KiB
Go

package domain
import "time"
// RecipeDuration is the duration to prepare recipe. It has JSON tags which allows it to be
// marshaled into a JSON object and stored in the database (JSONB).
type RecipeDuration struct {
Total int `json:"total"`
Prep int `json:"prep"`
Cook int `json:"cook"`
}
// RecipeMeal is the database enum E_MEAL which defines the meal type of a recipe. Postgres enums
// are case sensitive so these must match the values in the database exactly.
type RecipeMeal string
const (
MealBreakfast RecipeMeal = "breakfast"
MealLunch RecipeMeal = "lunch"
MealDinner RecipeMeal = "dinner"
MealDesert RecipeMeal = "dessert"
MealSnack RecipeMeal = "snack"
MealSide RecipeMeal = "side"
MealOther RecipeMeal = "other"
)
// ParseMeal converts an integer value into a meal type (string). Values are 0-indexed.
func ParseMeal(meal int) RecipeMeal {
switch meal {
case 0:
return MealBreakfast
case 1:
return MealLunch
case 2:
return MealDinner
case 3:
return MealDesert
case 4:
return MealSnack
case 5:
return MealSide
case 6:
return MealOther
default:
return MealOther
}
}
// RecipeIngredient is a single ingredients in a recipe. These have JSON tags which allow them
// to be marshaled into a JSON array and stored in the database (JSONB).
type RecipeIngredient struct {
Name string `json:"name"`
Quantity string `json:"quantity"`
}
// Recipe is the database model of a recipe. There is no need to map to a different model so
// this will remain in the domain.
type Recipe struct {
Id int
Title string
Description string
Instructions []string
Serves int
Difficulty int
Duration RecipeDuration
Category RecipeMeal
Ingredients []RecipeIngredient // Just a list of ingredients
UserId int
Modified *time.Time // Pointer to allow null
Created time.Time
}
// SearchFilters is a model which represents the required filters to complete a recipe search.
// The integer values should be provided as bits and used to parse out individual flags. More
// details can be found in the SearchRecipes service function.
type SearchFilters struct {
Search string
MealType int
Time int
Difficulty int
ServingSize int
}