models

package
v1.2.2 Latest Latest
Warning

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

Go to latest
Published: Dec 19, 2024 License: GPL-3.0 Imports: 32 Imported by: 0

Documentation

Overview

Package models provides various abstractions/representations of real-world concepts or objects.

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrIsAccuChef         = errors.New("accuchef") // TODO: Place errors somewhere else.
	ErrIsEasyRecipeDeluxe = errors.New("easy recipe deluxe")
)

Errors to signal specific applications.

Functions

func EnsureNutritionUnitForString added in v1.2.0

func EnsureNutritionUnitForString(nutritionValue any, nutritionProperty string) string

EnsureNutritionUnitForString extracts digits from nutritional property and appends metric unit. Returns a string value.

Types

type AdvancedSearch added in v1.2.0

type AdvancedSearch struct {
	Category     string
	Cuisine      string
	Description  string
	Ingredients  string
	Instructions string
	Keywords     string
	Name         string
	Source       string
	Text         string
	Tools        string
}

AdvancedSearch stores the components of an advanced search query.

func NewAdvancedSearch added in v1.2.0

func NewAdvancedSearch(query string) AdvancedSearch

NewAdvancedSearch creates an AdvancedSearch object from a search query.

type AppInfo added in v1.1.0

type AppInfo struct {
	IsUpdateAvailable   bool
	LastUpdatedAt       time.Time
	LastCheckedUpdateAt time.Time
}

AppInfo holds information on the application.

type AuthToken

type AuthToken struct {
	ID            int64
	Selector      string
	HashValidator string
	Expires       time.Time
	UserID        int64
}

AuthToken holds details on an authentication token.

func NewAuthToken

func NewAuthToken(id int64, selector, hashValidator string, expiresSeconds, userID int64) *AuthToken

NewAuthToken creates a new AuthToken.

func (*AuthToken) IsExpired

func (a *AuthToken) IsExpired() bool

IsExpired verifies whether the auth token is expired.

type AzureDIError added in v1.2.0

type AzureDIError struct {
	Error struct {
		Code    string `json:"code"`
		Message string `json:"message"`
	} `json:"error"`
}

AzureDIError holds the data of an Azure AI Document Intelligence error.

type AzureDILayout added in v1.2.0

type AzureDILayout struct {
	Status              string    `json:"status"`
	CreatedDateTime     time.Time `json:"createdDateTime"`
	LastUpdatedDateTime time.Time `json:"lastUpdatedDateTime"`
	AnalyzeResult       struct {
		APIVersion      string `json:"apiVersion"`
		ModelID         string `json:"modelId"`
		StringIndexType string `json:"stringIndexType"`
		Content         string `json:"content"`
		Pages           []struct {
			PageNumber int     `json:"pageNumber"`
			Angle      float64 `json:"angle"`
			Width      float64 `json:"width"`
			Height     float64 `json:"height"`
			Unit       string  `json:"unit"`
			Words      []struct {
				Content    string    `json:"content"`
				Polygon    []float64 `json:"polygon"`
				Confidence float64   `json:"confidence"`
				Span       struct {
					Offset int `json:"offset"`
					Length int `json:"length"`
				} `json:"span"`
			} `json:"words"`
			Lines []struct {
				Content string    `json:"content"`
				Polygon []float64 `json:"polygon"`
				Spans   []struct {
					Offset int `json:"offset"`
					Length int `json:"length"`
				} `json:"spans"`
			} `json:"lines"`
			Spans []struct {
				Offset int `json:"offset"`
				Length int `json:"length"`
			} `json:"spans"`
		} `json:"pages"`
		Tables     []interface{}      `json:"tables"`
		Paragraphs []azureDIParagraph `json:"paragraphs"`
		Styles     []struct {
			Confidence float64 `json:"confidence"`
			Spans      []struct {
				Offset int `json:"offset"`
				Length int `json:"length"`
			} `json:"spans"`
			IsHandwritten bool `json:"isHandwritten"`
		} `json:"styles"`
		ContentFormat string `json:"contentFormat"`
		Sections      []struct {
			Spans []struct {
				Offset int `json:"offset"`
				Length int `json:"length"`
			} `json:"spans"`
			Elements []string `json:"elements"`
		} `json:"sections"`
	} `json:"analyzeResult"`
}

AzureDILayout holds the data contained in the response of a call to the Azure AI Document Intelligence layout analysis endpoint.

func (*AzureDILayout) Recipe added in v1.2.0

func (a *AzureDILayout) Recipe() Recipe

Recipe converts an AzureDILayout to a Recipe.

type Broker

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

Broker represents a message broker that manages WebSocket connections for subscribers.

func NewBroker

func NewBroker() *Broker

NewBroker creates a subscribes a new Broker for a specific user.

func (*Broker) Add added in v1.2.0

func (b *Broker) Add(userID int64, c *websocket.Conn)

Add adds a connection to the subscriber.

func (*Broker) Clone added in v1.2.0

func (b *Broker) Clone() *Broker

Clone creates a deep copy of the Broker.

func (*Broker) Has added in v1.2.0

func (b *Broker) Has(userID int64) bool

Has checks whether a subscriber with the given userID exists in the Broker's subscribers map.

func (*Broker) HideNotification

func (b *Broker) HideNotification(userID int64)

HideNotification hides the websocket's frontend notification.

func (*Broker) Monitor added in v1.2.0

func (b *Broker) Monitor()

Monitor monitors the websocket connections to clean those closed.

func (*Broker) SendFile

func (b *Broker) SendFile(fileName string, data *bytes.Buffer, userID int64)

SendFile sends a file to the connected client.

func (*Broker) SendProgress

func (b *Broker) SendProgress(title string, value, numValues int, userID int64)

SendProgress sends a progress update with a title and value to the client. The isToastVisible parameter controls whether the progress bar is displayed in a toast notification.

func (*Broker) SendProgressStatus

func (b *Broker) SendProgressStatus(title string, isToastVisible bool, value, numValues int, userID int64)

SendProgressStatus sends a progress update with a title and value, optionally hiding the toast notification.

func (*Broker) SendToast

func (b *Broker) SendToast(toast Toast, userID int64)

SendToast sends a toast notification to the user.

type Category

type Category struct {
	Value string
}

Category holds a recipe's category.

func NewCategory added in v1.2.0

func NewCategory(name string) *Category

NewCategory creates an initialized Category. The default value of a Category is 'uncategorized'.

func (*Category) MarshalJSON

func (c *Category) MarshalJSON() ([]byte, error)

MarshalJSON encodes the category.

func (*Category) UnmarshalJSON

func (c *Category) UnmarshalJSON(data []byte) error

UnmarshalJSON decodes the category according to the schema (https://schema.org/recipeCategory). The schema specifies that the expected value is of type Text. However, some websites send the category in an array, which explains the need for this function.

type Cookbook

type Cookbook struct {
	ID      int64
	Count   int64
	Image   uuid.UUID
	Recipes Recipes
	Title   string
}

Cookbook is the struct that holds information on a cookbook.

func (Cookbook) DominantCategories

func (c Cookbook) DominantCategories(n int) []string

DominantCategories returns the `n` most common categories of recipes in the cookbook. If there are fewer than `n` categories, all categories are returned.

type CookingMethod

type CookingMethod struct {
	Value string
}

CookingMethod holds a recipe's cooking method.

func (*CookingMethod) MarshalJSON

func (c *CookingMethod) MarshalJSON() ([]byte, error)

MarshalJSON encodes the cuisine.

func (*CookingMethod) UnmarshalJSON

func (c *CookingMethod) UnmarshalJSON(data []byte) error

UnmarshalJSON decodes the cooking method according to the schema (https://schema.org/cookingMethod). The schema specifies that the expected value is of type Text. However, some websites send the cuisine in an array, which explains the need for this function.

type Counts

type Counts struct {
	Cookbooks uint64
	Recipes   uint64
}

Counts holds the number of recipes and cookbooks.

type Cuisine

type Cuisine struct {
	Value string
}

Cuisine holds a recipe's cuisine type.

func (*Cuisine) MarshalJSON

func (c *Cuisine) MarshalJSON() ([]byte, error)

MarshalJSON encodes the cuisine.

func (*Cuisine) UnmarshalJSON

func (c *Cuisine) UnmarshalJSON(data []byte) error

UnmarshalJSON decodes the cuisine according to the schema (https://schema.org/recipeCuisine). The schema specifies that the expected value is of type Text. However, some websites send the cuisine in an array, which explains the need for this function.

type Description

type Description struct {
	Value string
}

Description holds a description.

func (*Description) MarshalJSON

func (d *Description) MarshalJSON() ([]byte, error)

MarshalJSON encodes the description.

func (*Description) UnmarshalJSON

func (d *Description) UnmarshalJSON(data []byte) error

UnmarshalJSON decodes the description field of a recipe.

type FFProbe added in v1.2.0

type FFProbe struct {
	Format struct {
		Duration string `json:"duration"`
	} `json:"format"`
}

FFProbe represents the output JSON of the FFprobe program.

type FileType

type FileType int64

FileType is an alias for a file type, e.g. JSON and PDF.

const (
	CML FileType = iota
	Crumb
	JSON
	PDF
	MXP
	Paprika
	TXT
	InvalidFileType
)

These constants enumerate all possible file types used by the software.

func NewFileType

func NewFileType(fileType string) FileType

NewFileType creates a FileType from the file type name.

func (FileType) Ext

func (f FileType) Ext() string

Ext returns the FileType's extension.

type HowToItem added in v1.2.0

type HowToItem struct {
	Image    string `json:"image,omitempty"`
	Quantity int    `json:"requiredQuantity,omitempty"`
	Name     string `json:"name,omitempty"`
	Text     string `json:"text,omitempty"`
	Type     string `json:"@type,omitempty"`
	URL      string `json:"url,omitempty"`
}

HowToItem is a representation of the HowToItem schema (https://schema.org/HowToItem).

func NewHowToStep added in v1.2.0

func NewHowToStep(text string, opts ...*HowToItem) HowToItem

NewHowToStep creates an initialized HowToStep struct.

func NewHowToTool added in v1.2.0

func NewHowToTool(text string, opts ...*HowToItem) HowToItem

NewHowToTool creates an initialized HowToTool struct.

func (*HowToItem) StringQuantity added in v1.2.0

func (h *HowToItem) StringQuantity() string

StringQuantity stringifies the HowToItem as `{Quantity} {Name}`.

type Image

type Image struct {
	Value string
}

Image holds a recipe's image.

func (*Image) MarshalJSON

func (i *Image) MarshalJSON() ([]byte, error)

MarshalJSON encodes the image.

func (*Image) UnmarshalJSON

func (i *Image) UnmarshalJSON(data []byte) error

UnmarshalJSON decodes the image according to the schema (https://schema.org/image).

type Ingredients

type Ingredients struct {
	Values []string
}

Ingredients holds a recipe's list of ingredients.

func (*Ingredients) MarshalJSON

func (i *Ingredients) MarshalJSON() ([]byte, error)

MarshalJSON encodes the ingredients.

func (*Ingredients) UnmarshalJSON

func (i *Ingredients) UnmarshalJSON(data []byte) error

UnmarshalJSON decodes the ingredients according to the schema (https://schema.org/recipeInstructions).

type Instructions

type Instructions struct {
	Values []HowToItem
}

Instructions holds a recipe's list of instructions.

func (*Instructions) MarshalJSON

func (i *Instructions) MarshalJSON() ([]byte, error)

MarshalJSON encodes the list of instructions.

func (*Instructions) UnmarshalJSON

func (i *Instructions) UnmarshalJSON(data []byte) error

UnmarshalJSON decodes the instructions according to the schema (https://schema.org/recipeInstructions).

type Keywords

type Keywords struct {
	Values string
}

Keywords holds keywords as a single string.

func (*Keywords) MarshalJSON

func (k *Keywords) MarshalJSON() ([]byte, error)

MarshalJSON encodes the keywords.

func (*Keywords) UnmarshalJSON

func (k *Keywords) UnmarshalJSON(data []byte) error

UnmarshalJSON decodes the recipe's keywords according to the schema (https://schema.org/keywords). Some websites store the keywords in an array, which explains the need for a custom decoder.

type Message

type Message struct {
	Type     string `json:"type"`     // Message type, e.g. file.
	FileName string `json:"fileName"` // File name (applicable for "file" type).
	Data     string `json:"data"`     // Message data to pass. Base64-encoded if type is "file".
	Toast    Toast  `json:"toast"`    // Toast to display to the user.
}

Message represents the data format for file and progress updates sent to the client.

type NextcloudRecipes

type NextcloudRecipes struct {
	Category            string `json:"category"`
	DateCreated         string `json:"dateCreated"`
	DateModified        string `json:"dateModified"`
	ID                  int64  `json:"recipe_id"`
	ImagePlaceholderURL string `json:"imagePlaceholderUrl"`
	ImageURL            string `json:"imageUrl"`
	Keywords            string `json:"keywords"`
}

NextcloudRecipes holds a Nextcloud recipe's metadata obtained from the Nextcloud Cookbook's /recipes endpoint.

type NutrientFDC

type NutrientFDC struct {
	ID        int64
	Name      string
	Amount    float64
	UnitName  string
	Reference units.Measurement
}

NutrientFDC holds the nutrient data from the FDC database.

func (NutrientFDC) Value

func (n NutrientFDC) Value() float64

Value calculates the amount of the nutrient scaled to the reference, in grams.

type NutrientsFDC

type NutrientsFDC []NutrientFDC

NutrientsFDC is a type alias for a slice of NutrientFDC.

func (NutrientsFDC) NutritionFact

func (n NutrientsFDC) NutritionFact(weight float64) Nutrition

NutritionFact calculates the nutrition facts from the nutrients. The values in the nutrition table are per 100 grams. The weight is the sum of all ingredient quantities in grams.

type Nutrition

type Nutrition struct {
	Calories           string
	Cholesterol        string
	Fiber              string
	IsPerServing       bool
	Protein            string
	TotalFat           string
	SaturatedFat       string
	UnsaturatedFat     string
	TransFat           string
	Sodium             string
	Sugars             string
	TotalCarbohydrates string
}

Nutrition holds nutrition facts.

func (*Nutrition) Clean added in v1.2.0

func (n *Nutrition) Clean()

Clean empties any negligent field of the Nutrition.

func (*Nutrition) Equal

func (n *Nutrition) Equal(other Nutrition) bool

Equal verifies whether the Nutrition struct is equal to the other.

func (*Nutrition) Format added in v1.2.0

func (n *Nutrition) Format() string

Format formats the nutrition.

func (*Nutrition) Scale added in v1.0.1

func (n *Nutrition) Scale(multiplier float64)

Scale scales the nutrition by the given multiplier.

func (*Nutrition) Schema

func (n *Nutrition) Schema(servings string) *NutritionSchema

Schema creates the schema representation of the Nutrition.

type NutritionSchema

type NutritionSchema struct {
	Calories       string `json:"calories,omitempty"`
	Carbohydrates  string `json:"carbohydrateContent,omitempty"`
	Cholesterol    string `json:"cholesterolContent,omitempty"`
	Fat            string `json:"fatContent,omitempty"`
	Fiber          string `json:"fiberContent,omitempty"`
	Protein        string `json:"proteinContent,omitempty"`
	SaturatedFat   string `json:"saturatedFatContent,omitempty"`
	Servings       string `json:"servingSize,omitempty"`
	Sodium         string `json:"sodiumContent,omitempty"`
	Sugar          string `json:"sugarContent,omitempty"`
	TransFat       string `json:"transFatContent,omitempty"`
	UnsaturatedFat string `json:"unsaturatedFatContent,omitempty"`
}

NutritionSchema is a representation of the nutrition schema (https://schema.org/NutritionInformation).

func (*NutritionSchema) Equal added in v1.2.0

func (n *NutritionSchema) Equal(other NutritionSchema) bool

Equal verifies whether the NutritionSchema equals the other.

func (*NutritionSchema) UnmarshalJSON

func (n *NutritionSchema) UnmarshalJSON(data []byte) error

UnmarshalJSON decodes the nutrition according to the schema.

type PaprikaRecipe added in v1.2.0

type PaprikaRecipe struct {
	UID             string   `json:"uid"`
	Created         string   `json:"created"`
	Hash            string   `json:"hash"`
	Name            string   `json:"name"`
	Description     string   `json:"description"`
	Ingredients     string   `json:"ingredients"`
	Directions      string   `json:"directions"`
	Notes           string   `json:"notes"`
	NutritionalInfo string   `json:"nutritional_info"`
	PrepTime        string   `json:"prep_time"`
	CookTime        string   `json:"cook_time"`
	TotalTime       string   `json:"total_time"`
	Difficulty      string   `json:"difficulty"`
	Servings        string   `json:"servings"`
	Rating          int      `json:"rating"`
	Source          string   `json:"source"`
	SourceURL       string   `json:"source_url"`
	Photo           string   `json:"photo"`
	PhotoLarge      any      `json:"photo_large"`
	PhotoHash       string   `json:"photo_hash"`
	ImageURL        string   `json:"image_url"`
	Categories      []string `json:"categories"`
	PhotoData       string   `json:"photo_data"`
	Photos          []struct {
		Name     string `json:"name"`
		Filename string `json:"filename"`
		Hash     string `json:"hash"`
		Data     string `json:"data"`
	} `json:"photos"`
}

PaprikaRecipe holds a Paprika recipe's JSON data.

func (PaprikaRecipe) Recipe added in v1.2.0

func (p PaprikaRecipe) Recipe(image uuid.UUID) Recipe

Recipe converts a PaprikaRecipe to a Recipe.

type Progress

type Progress struct {
	Value int
	Total int
}

Progress represents a current value and the total number of values. It is used to calculate progress as a percentage.

type Recipe

type Recipe struct {
	Category     string
	CreatedAt    time.Time
	Cuisine      string
	Description  string
	ID           int64
	Images       []uuid.UUID
	Ingredients  []string
	Instructions []string
	Keywords     []string
	Name         string
	Nutrition    Nutrition
	Times        Times
	Tools        []HowToItem
	UpdatedAt    time.Time
	URL          string
	Videos       []VideoObject
	Yield        int16
}

Recipe is the struct that holds a recipe's information.

func NewBaseRecipe added in v1.1.0

func NewBaseRecipe() Recipe

NewBaseRecipe creates a new, empty Recipe.

func NewRecipeFromCrouton added in v1.2.0

func NewRecipeFromCrouton(r io.Reader, uploadImageFunc func(rc io.ReadCloser) (uuid.UUID, error)) Recipe

NewRecipeFromCrouton create a Recipe from the content of a Crouton file.

func NewRecipeFromTextFile added in v1.1.0

func NewRecipeFromTextFile(r io.Reader) (Recipe, error)

NewRecipeFromTextFile extracts the recipe from a text file.

func (*Recipe) ConvertMeasurementSystem

func (r *Recipe) ConvertMeasurementSystem(to units.System) (*Recipe, error)

ConvertMeasurementSystem converts a recipe to another units.System.

func (*Recipe) Copy

func (r *Recipe) Copy() Recipe

Copy deep copies the Recipe.

func (*Recipe) IsEmpty

func (r *Recipe) IsEmpty() bool

IsEmpty verifies whether all the Recipe fields are empty.

func (*Recipe) Normalize

func (r *Recipe) Normalize()

Normalize normalizes texts for readability. It normalizes quantities, i.e. 1l -> 1L and 1 ml -> 1 mL.

func (*Recipe) Scale

func (r *Recipe) Scale(yield int16)

Scale scales the recipe to the given yield.

func (*Recipe) Schema

func (r *Recipe) Schema() RecipeSchema

Schema creates the schema representation of the Recipe.

type RecipeSchema

type RecipeSchema struct {
	AtContext       string           `json:"@context"`
	AtGraph         []*RecipeSchema  `json:"@graph,omitempty"`
	AtType          *SchemaType      `json:"@type"`
	Category        *Category        `json:"recipeCategory,omitempty"`
	CookTime        string           `json:"cookTime,omitempty"`
	CookingMethod   *CookingMethod   `json:"cookingMethod,omitempty"`
	Cuisine         *Cuisine         `json:"recipeCuisine,omitempty"`
	DateCreated     string           `json:"dateCreated,omitempty"`
	DateModified    string           `json:"dateModified,omitempty"`
	DatePublished   string           `json:"datePublished,omitempty"`
	Description     *Description     `json:"description"`
	Keywords        *Keywords        `json:"keywords,omitempty"`
	Image           *Image           `json:"image,omitempty"`
	Ingredients     *Ingredients     `json:"recipeIngredient,omitempty"`
	Instructions    *Instructions    `json:"recipeInstructions,omitempty"`
	Name            string           `json:"name,omitempty"`
	NutritionSchema *NutritionSchema `json:"nutrition,omitempty"`
	PrepTime        string           `json:"prepTime,omitempty"`
	ThumbnailURL    *ThumbnailURL    `json:"thumbnailUrl,omitempty"`
	Tools           *Tools           `json:"tool,omitempty"`
	TotalTime       string           `json:"totalTime,omitempty"`
	Yield           *Yield           `json:"recipeYield,omitempty"`
	URL             string           `json:"url,omitempty"`
	Video           *Videos          `json:"video,omitempty"`
}

RecipeSchema is a representation of the Recipe schema (https://schema.org/Recipe).

func NewRecipeSchema added in v1.2.0

func NewRecipeSchema() RecipeSchema

NewRecipeSchema creates an initialized RecipeSchema.

func (*RecipeSchema) Equal added in v1.2.0

func (r *RecipeSchema) Equal(other RecipeSchema) bool

Equal verifies whether a RecipeSchema is equal to the other.

func (*RecipeSchema) Recipe

func (r *RecipeSchema) Recipe() (*Recipe, error)

Recipe transforms the RecipeSchema to a Recipe.

type Recipes

type Recipes []Recipe

Recipes is the type for a slice of recipes.

func NewRecipesFromAccuChef added in v1.2.0

func NewRecipesFromAccuChef(r io.Reader) Recipes

NewRecipesFromAccuChef extracts all recipes from an exported Accuchef file.

func NewRecipesFromCML added in v1.2.0

func NewRecipesFromCML(r io.Reader, file *multipart.FileHeader, uploadImageFunc func(rc io.ReadCloser) (uuid.UUID, error)) Recipes

NewRecipesFromCML extracts all recipes from a CookML file.

func NewRecipesFromEasyRecipeDeluxe added in v1.2.0

func NewRecipesFromEasyRecipeDeluxe(r io.Reader) Recipes

NewRecipesFromEasyRecipeDeluxe extracts the recipes from a MasterCook file.

func NewRecipesFromMasterCook

func NewRecipesFromMasterCook(r io.Reader) Recipes

NewRecipesFromMasterCook extracts the recipes from a MasterCook file.

func NewRecipesFromRecipeKeeper added in v1.2.0

func NewRecipesFromRecipeKeeper(root *goquery.Document) Recipes

NewRecipesFromRecipeKeeper extracts the recipes from a Recipe Keeper export.

func (Recipes) Categories

func (r Recipes) Categories() []string

Categories returns the category of every recipe. The resulting slice has no duplicates.

type Replace added in v1.2.0

type Replace struct {
	Old string
	New string
}

Replace holds the old and new values for a strings.ReplaceAll operation.

type Report added in v1.1.0

type Report struct {
	CreatedAt time.Time
	ExecTime  time.Duration
	ID        int64
	Logs      []ReportLog
	Type      ReportType
}

Report holds information on a report.

func NewReport added in v1.1.0

func NewReport(reportType ReportType) Report

NewReport creates a new, initialized and empty Report of the given ReportType.

type ReportLog added in v1.1.0

type ReportLog struct {
	Error     string
	ID        int64
	IsSuccess bool
	Title     string
}

ReportLog holds information on a report's log.

func NewReportLog added in v1.2.0

func NewReportLog(title string, err error) ReportLog

NewReportLog creates a new ReportLog from the title and error.

type ReportType added in v1.1.0

type ReportType int64

ReportType represents

const ImportReportType ReportType = 1

ImportReportType is the ReportType for importing recipes, either from files or the web.

type SchemaType

type SchemaType struct {
	Value string
}

SchemaType holds the type of the schema. It should be "Recipe".

func (*SchemaType) MarshalJSON

func (s *SchemaType) MarshalJSON() ([]byte, error)

MarshalJSON encodes the schema's type.

func (*SchemaType) UnmarshalJSON

func (s *SchemaType) UnmarshalJSON(data []byte) error

UnmarshalJSON decodes the type of the schema. The type "Recipe" will be searched for if the data is an array.

type SearchOptionsRecipes

type SearchOptionsRecipes struct {
	Advanced   AdvancedSearch
	CookbookID int64
	Query      string
	Page       uint64
	Sort       Sort
}

SearchOptionsRecipes defines the options for searching recipes.

func NewSearchOptionsRecipe added in v1.1.0

func NewSearchOptionsRecipe(query url.Values) SearchOptionsRecipes

NewSearchOptionsRecipe creates a SearchOptionsRecipe struct configured for the search method.

func (*SearchOptionsRecipes) Arg added in v1.2.0

func (s *SearchOptionsRecipes) Arg() string

Arg returns combines the field values of the struct, ready for FTS.

func (*SearchOptionsRecipes) IsBasic added in v1.2.0

func (s *SearchOptionsRecipes) IsBasic() bool

IsBasic verifies whether the search is basic.

type Share

type Share struct {
	CookbookID int64
	Link       string
	RecipeID   int64
	UserID     int64
}

Share stores the ID of a recipe and the ID of the user who shared it.

type Sort added in v1.1.0

type Sort struct {
	IsAToZ bool
	IsZToA bool

	IsNewestToOldest bool
	IsOldestToNewest bool

	IsDefault bool
	IsRandom  bool
}

Sort defines sorting options.

func (*Sort) IsSort added in v1.1.0

func (s *Sort) IsSort() bool

IsSort verifies whether there is a sort option enabled.

func (*Sort) String added in v1.2.0

func (s *Sort) String() string

String returns a string representation of the sorting order based on the Sort struct.

type ThumbnailURL added in v1.2.0

type ThumbnailURL struct {
	Value string
}

ThumbnailURL holds a recipe's thumbnail.

func (*ThumbnailURL) MarshalJSON added in v1.2.0

func (t *ThumbnailURL) MarshalJSON() ([]byte, error)

MarshalJSON encodes the thumbnail URL.

func (*ThumbnailURL) UnmarshalJSON added in v1.2.0

func (t *ThumbnailURL) UnmarshalJSON(data []byte) error

UnmarshalJSON decodes the thumbnail URL according to the schema (https://schema.org/URL).

type Times

type Times struct {
	Prep  time.Duration
	Cook  time.Duration
	Total time.Duration
}

Times holds a variety of intervals.

func NewTimes

func NewTimes(prep, cook string) (Times, error)

NewTimes creates a struct of Times from the Schema Duration fields for prep and cook time.

func (Times) Equal

func (t Times) Equal(other Times) bool

Equal verifies whether the Times struct is equal to the other Times.

type Toast added in v1.1.0

type Toast struct {
	Action     string `json:"action"`
	Background string `json:"background"`
	Message    string `json:"message"`
	Title      string `json:"title"`
}

Toast holds data related to a notification toast.

func NewErrorAuthToast added in v1.1.0

func NewErrorAuthToast(message string) Toast

NewErrorAuthToast creates an action-less error Toast with the title of "Auth Error".

func NewErrorDBToast added in v1.1.0

func NewErrorDBToast(message string) Toast

NewErrorDBToast creates an action-less error Toast with the title of "Database Error".

func NewErrorFilesToast added in v1.1.0

func NewErrorFilesToast(message string) Toast

NewErrorFilesToast creates an action-less error Toast with the title of "Files Error".

func NewErrorFormToast added in v1.1.0

func NewErrorFormToast(message string) Toast

NewErrorFormToast creates an action-less error Toast with the title of "Form Error".

func NewErrorGeneralToast added in v1.1.0

func NewErrorGeneralToast(message string) Toast

NewErrorGeneralToast creates an action-less error Toast with the title of "General Error".

func NewErrorReqToast added in v1.1.0

func NewErrorReqToast(message string) Toast

NewErrorReqToast creates an action-less error Toast with the title of "Request Error".

func NewErrorToast added in v1.1.0

func NewErrorToast(title, message, action string) Toast

NewErrorToast creates a new error notification.

func NewInfoToast added in v1.1.0

func NewInfoToast(title, message, action string) Toast

NewInfoToast creates a new info notification.

func NewWarningToast added in v1.1.0

func NewWarningToast(title, message, action string) Toast

NewWarningToast creates a new warning notification.

func NewWarningWSToast added in v1.1.0

func NewWarningWSToast(message string) Toast

NewWarningWSToast creates an action-less warning Toast with the title of "Websocket".

func (Toast) Render added in v1.1.0

func (t Toast) Render() string

Render returns the JSON encoding of the toast.

type Tools

type Tools struct {
	Values []HowToItem
}

Tools holds the list of tools used for a recipe.

func (*Tools) MarshalJSON

func (t *Tools) MarshalJSON() ([]byte, error)

MarshalJSON encodes the list of tools.

func (*Tools) UnmarshalJSON

func (t *Tools) UnmarshalJSON(data []byte) error

UnmarshalJSON decodes the tools according to the schema (https://schema.org/tool).

type User

type User struct {
	ID    int64
	Email string
}

User holds data related to a user.

type UserBackup added in v1.1.0

type UserBackup struct {
	DeleteSQL  string
	ImagesPath string
	InsertSQL  string
	Recipes    Recipes
	UserID     int64
}

UserBackup holds components related to a user backup.

type UserSettings

type UserSettings struct {
	CalculateNutritionFact bool
	ConvertAutomatically   bool
	CookbooksViewMode      ViewMode
	MeasurementSystem      units.System
}

UserSettings holds the user's settings.

func (*UserSettings) IsCalculateNutrition

func (u *UserSettings) IsCalculateNutrition(recipe *Recipe) bool

IsCalculateNutrition verifies whether the nutrition facts should be calculated for the recipe.

type VideoObject added in v1.2.0

type VideoObject struct {
	AtID         string        `json:"@id"`
	AtType       string        `json:"@type"`
	ContentURL   string        `json:"contentUrl,omitempty"`
	Description  string        `json:"description,omitempty"`
	Duration     string        `json:"duration,omitempty"`
	EmbedURL     string        `json:"embedUrl,omitempty"`
	Expires      time.Time     `json:"expires,omitempty"`
	ID           uuid.UUID     `json:"-"`
	IsIFrame     bool          `json:"_"`
	Name         string        `json:"name,omitempty"`
	ThumbnailURL *ThumbnailURL `json:"thumbnailUrl,omitempty"`
	UploadDate   time.Time     `json:"uploadDate,omitempty"`
}

VideoObject is a representation of the VideoObject schema (https://schema.org/VideoObject).

type Videos added in v1.2.0

type Videos struct {
	Values []VideoObject
}

Videos holds a list of VideoObject.

func (*Videos) MarshalJSON added in v1.2.0

func (v *Videos) MarshalJSON() ([]byte, error)

MarshalJSON encodes the value of the yield.

func (*Videos) UnmarshalJSON added in v1.2.0

func (v *Videos) UnmarshalJSON(data []byte) error

UnmarshalJSON decodes the Videos according to the schema (https://schema.org/VideoObject).

type ViewMode

type ViewMode int

ViewMode is an integer type alias for various data view modes.

const (
	GridViewMode ViewMode = iota
	ListViewMode
)

These constants enumerate all possible viewing modes.

func ViewModeFromInt

func ViewModeFromInt(num int64) ViewMode

ViewModeFromInt returns the ViewMode for the respective integer.

func ViewModeFromString

func ViewModeFromString(s string) ViewMode

ViewModeFromString returns the ViewMode for the respective string.

type Website

type Website struct {
	ID   int64
	Host string
	URL  string
}

Website represents a website with its hostname and URL.

type Websites

type Websites []Website

Websites is the type for a slice of Website.

func (Websites) TableHTML

func (w Websites) TableHTML() string

TableHTML renders the websites to a string of table rows.

type Yield

type Yield struct {
	Value int16
}

Yield holds a recipe's yield.

func (*Yield) MarshalJSON

func (y *Yield) MarshalJSON() ([]byte, error)

MarshalJSON encodes the value of the yield.

func (*Yield) UnmarshalJSON

func (y *Yield) UnmarshalJSON(data []byte) error

UnmarshalJSON decodes the yield according to the schema (https://schema.org/recipeYield).

Jump to

Keyboard shortcuts

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