Documentation ¶
Index ¶
- Constants
- func AddRecipesAPIToHandler(handler core.Handler, recipes RecipeDB)
- func RecipeToBsonM(searchQuery *RecipeSearchFilter) bson.M
- type API
- type Ingredients
- type MongoRecipeDB
- func (m *MongoRecipeDB) AddPicture(pic *RecipePicture) error
- func (m *MongoRecipeDB) Clear()
- func (m *MongoRecipeDB) Close() error
- func (m *MongoRecipeDB) Get(id RecipeID) *Recipe
- func (m *MongoRecipeDB) GetByName(name string) (*Recipe, error)
- func (m *MongoRecipeDB) IDs(searchQuery *RecipeSearchFilter) RecipeList
- func (m *MongoRecipeDB) Insert(recipe *Recipe) error
- func (m *MongoRecipeDB) List() (recipes []*Recipe)
- func (m *MongoRecipeDB) Num() int64
- func (m *MongoRecipeDB) Picture(id RecipeID, name string) *RecipePicture
- func (m *MongoRecipeDB) Pictures(id RecipeID) map[string]*RecipePicture
- func (m *MongoRecipeDB) Ping() error
- func (m *MongoRecipeDB) Random() *Recipe
- func (m *MongoRecipeDB) Remove(id RecipeID) error
- func (m *MongoRecipeDB) RemoveByName(name string) error
- func (m *MongoRecipeDB) StartDB() error
- func (m *MongoRecipeDB) StopDB() (err error)
- func (m *MongoRecipeDB) Update(id RecipeID, recipe *Recipe) error
- type Recipe
- type RecipeDB
- type RecipeID
- type RecipeList
- type RecipePicture
- type RecipeSearchFilter
- type Recipes
Constants ¶
const ( // SERVINGS keyword used as part of the url SERVINGS = "servings" // RECIPE keyword used as part of the url RECIPE = "recipe" // NAME keyword used as part of the url NAME = "name" // INGREDIENT keyword used as part of the url INGREDIENT = "ingredient" // DESCRIPTION keyword used as part of the url DESCRIPTION = "description" )
const ( //DATABASE name DATABASE = "recipes-manager" //RECIPES index RECIPES = "recipes" //PICTURES index PICTURES = "pics" )
const (
//NoAmountIngredient is the amount value for ingredients when this field is not used
NoAmountIngredient = -1.0
)
const (
//NotSupportedError informs clients about operations that are not supported by a Recipes provider
NotSupportedError = "recipe operation not supported"
)
Variables ¶
This section is empty.
Functions ¶
func AddRecipesAPIToHandler ¶
AddRecipesAPIToHandler constructs an API for recipes
func RecipeToBsonM ¶
func RecipeToBsonM(searchQuery *RecipeSearchFilter) bson.M
RecipeToBsonM converts a RecipeSearchFilter to a search query (bson.M)
Types ¶
type Ingredients ¶
type Ingredients struct { //Name of the ingredient Name string `json:"name"` //Amount needed in a recipe of an ingredient Amount float64 `json:"amount"` //Unit of the Amount Unit string `json:"unit"` }
Ingredients of a recipe
type MongoRecipeDB ¶
type MongoRecipeDB struct {
// contains filtered or unexported fields
}
MongoRecipeDB implements the Recipe interface to read and write Recipes to and from a Mongo DB
func (*MongoRecipeDB) AddPicture ¶
func (m *MongoRecipeDB) AddPicture(pic *RecipePicture) error
AddPicture to the database
func (*MongoRecipeDB) Close ¶
func (m *MongoRecipeDB) Close() error
Close the connection to the database
func (*MongoRecipeDB) GetByName ¶
func (m *MongoRecipeDB) GetByName(name string) (*Recipe, error)
GetByName a recipe from the database
func (*MongoRecipeDB) IDs ¶
func (m *MongoRecipeDB) IDs(searchQuery *RecipeSearchFilter) RecipeList
IDs lists all ids of all recipes
func (*MongoRecipeDB) Insert ¶
func (m *MongoRecipeDB) Insert(recipe *Recipe) error
Insert a recipe into the database
func (*MongoRecipeDB) List ¶
func (m *MongoRecipeDB) List() (recipes []*Recipe)
List all recipes from the db
func (*MongoRecipeDB) Num ¶
func (m *MongoRecipeDB) Num() int64
Num counts the number of recipes in the db
func (*MongoRecipeDB) Picture ¶
func (m *MongoRecipeDB) Picture(id RecipeID, name string) *RecipePicture
Picture returns a specific picture with a specific name for a specific recipe
func (*MongoRecipeDB) Pictures ¶
func (m *MongoRecipeDB) Pictures(id RecipeID) map[string]*RecipePicture
Pictures returns all pictures for a given recipe
func (*MongoRecipeDB) Random ¶
func (m *MongoRecipeDB) Random() *Recipe
Random picture will be returned
func (*MongoRecipeDB) Remove ¶
func (m *MongoRecipeDB) Remove(id RecipeID) error
Remove removes a recipe by id
func (*MongoRecipeDB) RemoveByName ¶
func (m *MongoRecipeDB) RemoveByName(name string) error
RemoveByName a recipe by name
func (*MongoRecipeDB) StartDB ¶
func (m *MongoRecipeDB) StartDB() error
StartDB initializes the database connection
func (*MongoRecipeDB) StopDB ¶
func (m *MongoRecipeDB) StopDB() (err error)
StopDB closes the connection to the db
type Recipe ¶
type Recipe struct { ID RecipeID `json:"id"` Name string `json:"name"` Ingredients []Ingredients `json:"components"` Description string `json:"description"` PictureLink []string `json:"pictureLink"` Servings int8 `json:"servings"` }
Recipe model
func NewInvalidRecipe ¶
func NewInvalidRecipe() *Recipe
NewInvalidRecipe returns an empty Recipe object. The ID of the returned Recipe is InvalidRecipeID.
func (*Recipe) JSON ¶
JSON returns the encoded version of the recipe. If an error occurs, '{}' is returned.
type RecipeDB ¶
RecipeDB is the interface that all DB implementations have to expose
func NewDatabaseClient ¶
NewDatabaseClient builds a client to communicate with a database
type RecipeID ¶
type RecipeID string
RecipeID is a data type that provides a unique id for each recipe
func InvalidRecipeID ¶
func InvalidRecipeID() RecipeID
InvalidRecipeID should not be used for any valid Recipe
func NewRecipeIDFromString ¶
NewRecipeIDFromString converts a string to a recipe id and returns this recipe id. Returns the InvalidRecipeID iff the recipe id cannot be converted
type RecipeList ¶ added in v0.4.0
type RecipeList struct {
Recipes []string `json:"recipes"`
}
RecipeList models a list of recipes by ID
type RecipePicture ¶
type RecipePicture struct { ID RecipeID `json:"id"` Name string `json:"name"` Picture string `json:"picture"` }
RecipePicture model
func NewInvalidRecipePicture ¶
func NewInvalidRecipePicture() *RecipePicture
NewInvalidRecipePicture returns an invalid picture
type RecipeSearchFilter ¶
type RecipeSearchFilter struct { Name string `json:"name"` Ingredient []string `json:"ingredients"` Description string `json:"description"` }
RecipeSearchFilter models a search query to filter recipes
type Recipes ¶
type Recipes interface { List() []*Recipe IDs(filterQuery *RecipeSearchFilter) RecipeList Num() int64 Get(id RecipeID) *Recipe GetByName(name string) (*Recipe, error) Picture(id RecipeID, name string) *RecipePicture Pictures(id RecipeID) map[string]*RecipePicture Random() *Recipe Insert(recipe *Recipe) error Update(id RecipeID, recipe *Recipe) error AddPicture(pic *RecipePicture) error Remove(id RecipeID) error RemoveByName(name string) error }
Recipes interface is an abstraction for the provider of a collection of recipes, i.e., a data-base or a cache