recipes

package
v0.0.0-...-f849b58 Latest Latest
Warning

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

Go to latest
Published: Apr 20, 2023 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Comments

type Comments struct {
	Comment string    `bson:"comment"`
	Author  string    `bson:"author"`
	Date    time.Time `bson:"date"`
}

type Ingredient

type Ingredient struct {
	Name     string `bson:"name"`
	Quantity string `bson:"quantity"`
}

func MergeIngredientQuantities

func MergeIngredientQuantities(ingredients []Ingredient) (Ingredient, error)

MergeIngredientQuantities merges multiple ingredients of the same type together

func MergeIngredients

func MergeIngredients(ingredients []Ingredient) []Ingredient

MergeIngredients takes a list of ingredients and merges any that are the same

type MongoRecipeManager

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

Define a MongoDB recipe manager that implements the RecipeManager interface

func CreateMongoRecipeManager

func CreateMongoRecipeManager(uri, dbName, collectionName string) (*MongoRecipeManager, error)

CreateMongoRecipeManager creates a new MongoDB recipe manager

func (*MongoRecipeManager) AddRecipe

func (m *MongoRecipeManager) AddRecipe(recipe Recipe) (string, error)

AddRecipe adds a recipe to the recipe manager and returns the ID of the new recipe

func (*MongoRecipeManager) DeleteRecipe

func (m *MongoRecipeManager) DeleteRecipe(id string) error

DeleteRecipe deletes a recipe from the recipe manager

func (*MongoRecipeManager) GetAllRecipes

func (m *MongoRecipeManager) GetAllRecipes() ([]Recipe, error)

GetAllRecipes returns all recipes in the recipe manager

func (*MongoRecipeManager) GetRecipeByID

func (m *MongoRecipeManager) GetRecipeByID(id string) (Recipe, error)

GetRecipeByID returns a recipe with the given ID

func (*MongoRecipeManager) GetRecipesByTags

func (m *MongoRecipeManager) GetRecipesByTags(tags []string) ([]Recipe, error)

GetRecipesByTags returns all recipes with the given tags

func (*MongoRecipeManager) GetTags

func (m *MongoRecipeManager) GetTags() ([]string, error)

GetTags returns all tags in the recipe manager

func (*MongoRecipeManager) SearchRecipes

func (m *MongoRecipeManager) SearchRecipes(query string, tags []string) ([]Recipe, error)

SearchRecipes returns all recipes that match the given query string and tags

func (*MongoRecipeManager) UpdateRecipe

func (m *MongoRecipeManager) UpdateRecipe(recipe Recipe) error

UpdateRecipe updates a recipe in the recipe manager

type Recipe

type Recipe struct {
	ID          primitive.ObjectID `bson:"_id,omitempty"`
	Name        string             `bson:"name"`
	Description string             `bson:"description"`
	Ingredients []Ingredient       `bson:"ingredients"`
	Steps       []string           `bson:"steps"`
	Tags        []string           `bson:"tags"`
	Comments    []Comments         `bson:"comments"`
}

func (*Recipe) AddTagToRecipe

func (recipe *Recipe) AddTagToRecipe(tag string)

AddTagToRecipe adds a tag to a recipe if it is not already present

func (*Recipe) RemoveTagFromRecipe

func (recipe *Recipe) RemoveTagFromRecipe(tag string)

RemoveTagFromRecipe removes a tag from a recipe if it is present

func (*Recipe) SetID

func (recipe *Recipe) SetID(id string) error

SetID sets the ID of a recipe

type RecipeManager

type RecipeManager interface {
	// AddRecipe adds a recipe to the recipe manager and returns the ID of the new recipe
	AddRecipe(recipe Recipe) (string, error)
	// DeleteRecipe deletes a recipe from the recipe manager
	DeleteRecipe(id string) error
	// UpdateRecipe updates a recipe in the recipe manager
	UpdateRecipe(recipe Recipe) error
	// GetAllRecipes returns all recipes in the recipe manager
	GetAllRecipes() ([]Recipe, error)
	// GetRecipeByID returns a recipe with the given ID
	GetRecipeByID(id string) (Recipe, error)
	// GetRecipesByTags returns all recipes with the given tags
	GetRecipesByTags(tags []string) ([]Recipe, error)
	// GetTags returns all tags in the recipe manager
	GetTags() ([]string, error)
	// SearchRecipes returns all recipes that match the given query string and tags
	SearchRecipes(query string, tags []string) ([]Recipe, error)
}

Define an interface for a generic recipe manager

Jump to

Keyboard shortcuts

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