Documentation
¶
Index ¶
- Constants
- Variables
- type Model
- type Note
- type NoteModel
- func (m *NoteModel) Create(note *Note) error
- func (m *NoteModel) CreateTx(note *Note, tx *sqlx.Tx) error
- func (m *NoteModel) Delete(id int64) error
- func (m *NoteModel) DeleteAll(recipeID int64) error
- func (m *NoteModel) DeleteAllTx(recipeID int64, tx *sqlx.Tx) error
- func (m *NoteModel) DeleteTx(id int64, tx *sqlx.Tx) error
- func (m *NoteModel) List(recipeID int64) (*Notes, error)
- func (m *NoteModel) Update(note *Note) error
- func (m *NoteModel) UpdateTx(note *Note, tx *sqlx.Tx) error
- type Notes
- type Recipe
- type RecipeImage
- type RecipeImageModel
- func (m *RecipeImageModel) Create(imageInfo *RecipeImage, imageData []byte) error
- func (m *RecipeImageModel) CreateTx(imageInfo *RecipeImage, imageData []byte, tx *sqlx.Tx) error
- func (m *RecipeImageModel) Delete(id int64) error
- func (m *RecipeImageModel) DeleteAll(recipeID int64) error
- func (m *RecipeImageModel) DeleteAllTx(recipeID int64, tx *sqlx.Tx) error
- func (m *RecipeImageModel) DeleteTx(id int64, tx *sqlx.Tx) error
- func (m *RecipeImageModel) List(recipeID int64) (*RecipeImages, error)
- func (m *RecipeImageModel) ReadMainImage(recipeID int64) (*RecipeImage, error)
- func (m *RecipeImageModel) ReadMainImageTx(recipeID int64, tx *sqlx.Tx) (*RecipeImage, error)
- func (m *RecipeImageModel) ReadTx(id int64, tx *sqlx.Tx) (*RecipeImage, error)
- func (m *RecipeImageModel) UpdateMainImage(image *RecipeImage) error
- func (m *RecipeImageModel) UpdateMainImageTx(image *RecipeImage, tx *sqlx.Tx) error
- type RecipeImages
- type RecipeModel
- func (m *RecipeModel) Create(recipe *Recipe) error
- func (m *RecipeModel) CreateTx(recipe *Recipe, tx *sqlx.Tx) error
- func (m *RecipeModel) Delete(id int64) error
- func (m *RecipeModel) DeleteTx(id int64, tx *sqlx.Tx) error
- func (m *RecipeModel) Read(id int64) (*Recipe, error)
- func (m *RecipeModel) SetRating(id int64, rating float64) error
- func (m *RecipeModel) Update(recipe *Recipe) error
- func (m *RecipeModel) UpdateTx(recipe *Recipe, tx *sqlx.Tx) error
- type Recipes
- type RecipesFilter
- type SearchModel
- type TagModel
- func (m *TagModel) Create(recipeID int64, tag string) error
- func (m *TagModel) CreateTx(recipeID int64, tag string, tx *sqlx.Tx) error
- func (m *TagModel) DeleteAll(recipeID int64) error
- func (m *TagModel) DeleteAllTx(recipeID int64, tx *sqlx.Tx) error
- func (m *TagModel) List(recipeID int64) (*[]string, error)
- type TagsFilter
- type User
- type UserModel
Constants ¶
Variables ¶
var ErrNotFound = errors.New("No record found matching supplied criteria")
ErrNotFound represents the error when a database record cannot be found matching the criteria specified by the caller
Functions ¶
This section is empty.
Types ¶
type Model ¶ added in v0.3.0
type Model struct { Recipes *RecipeModel Tags *TagModel Notes *NoteModel Images *RecipeImageModel Users *UserModel Search *SearchModel // contains filtered or unexported fields }
Model encapsulates the model layer of the application, including database access
type Note ¶
type Note struct { ID int64 `json:"id"` RecipeID int64 `json:"recipeId"` Note string `json:"text"` CreatedAt time.Time `json:"createdAt"` ModifiedAt time.Time `json:"modifiedAt"` }
Note represents an individual comment (or note) on a recipe
type NoteModel ¶ added in v0.3.0
type NoteModel struct {
*Model
}
NoteModel provides functionality to edit and retrieve notes attached to recipes.
func (*NoteModel) Create ¶ added in v0.3.0
Create stores the note in the database as a new record using a dedicated transation that is committed if there are not errors.
func (*NoteModel) CreateTx ¶ added in v0.3.0
CreateTx stores the note in the database as a new record using the specified transaction.
func (*NoteModel) Delete ¶ added in v0.6.0
Delete removes the specified note from the database using a dedicated transation that is committed if there are not errors.
func (*NoteModel) DeleteAll ¶ added in v0.4.1
DeleteAll removes all notes for the specified recipe from the database using a dedicated transation that is committed if there are not errors.
func (*NoteModel) DeleteAllTx ¶ added in v0.4.1
DeleteAllTx removes all notes for the specified recipe from the database using the specified transaction.
func (*NoteModel) DeleteTx ¶ added in v0.6.0
DeleteTx removes the specified note from the database using the specified transaction.
func (*NoteModel) List ¶ added in v0.3.0
List retrieves all notes associated with the recipe with the specified id.
type Recipe ¶
type Recipe struct { ID int64 `json:"id"` Name string `json:"name"` ServingSize string `json:"servingSize"` NutritionInfo string `json:"nutritionInfo"` Ingredients string `json:"ingredients"` Directions string `json:"directions"` SourceURL string `json:"sourceUrl"` AvgRating float64 `json:"averageRating"` MainImage RecipeImage `json:"mainImage"` Tags []string `json:"tags"` }
Recipe is the primary model class for recipe storage and retrieval
type RecipeImage ¶
type RecipeImage struct { ID int64 `json:"id"` RecipeID int64 `json:"recipeId"` Name string `json:"name"` URL string `json:"url"` ThumbnailURL string `json:"thumbnailUrl"` CreatedAt time.Time `json:"createdAt"` ModifiedAt time.Time `json:"modifiedAt"` }
RecipeImage represents the data associated with an image attached to a recipe
type RecipeImageModel ¶ added in v0.3.0
type RecipeImageModel struct { *Model // contains filtered or unexported fields }
RecipeImageModel provides functionality to edit and retrieve images attached to recipes
func NewRecipeImageModel ¶ added in v0.8.0
func NewRecipeImageModel(model *Model) *RecipeImageModel
NewRecipeImageModel constructs a RecipeImageModel
func (*RecipeImageModel) Create ¶ added in v1.0.0
func (m *RecipeImageModel) Create(imageInfo *RecipeImage, imageData []byte) error
Create saves the image using the backing upload.Driver and creates an associated record in the database using a dedicated transation that is committed if there are not errors.
func (*RecipeImageModel) CreateTx ¶ added in v1.0.0
func (m *RecipeImageModel) CreateTx(imageInfo *RecipeImage, imageData []byte, tx *sqlx.Tx) error
CreateTx saves the image using the backing upload.Driver and creates an associated record in the database using the specified transaction.
func (*RecipeImageModel) Delete ¶ added in v0.6.0
func (m *RecipeImageModel) Delete(id int64) error
Delete removes the specified image from the backing store and database using a dedicated transation that is committed if there are not errors.
func (*RecipeImageModel) DeleteAll ¶ added in v0.4.1
func (m *RecipeImageModel) DeleteAll(recipeID int64) error
DeleteAll removes all images for the specified recipe from the database using a dedicated transation that is committed if there are not errors.
func (*RecipeImageModel) DeleteAllTx ¶ added in v1.0.0
func (m *RecipeImageModel) DeleteAllTx(recipeID int64, tx *sqlx.Tx) error
DeleteAllTx removes all images for the specified recipe from the database using the specified transaction.
func (*RecipeImageModel) DeleteTx ¶ added in v1.0.0
func (m *RecipeImageModel) DeleteTx(id int64, tx *sqlx.Tx) error
DeleteTx removes the specified image from the backing store and database using the specified transaction.
func (*RecipeImageModel) List ¶ added in v0.3.0
func (m *RecipeImageModel) List(recipeID int64) (*RecipeImages, error)
List returns a RecipeImages slice that contains data for all images attached to the specified recipe.
func (*RecipeImageModel) ReadMainImage ¶ added in v1.1.0
func (m *RecipeImageModel) ReadMainImage(recipeID int64) (*RecipeImage, error)
ReadMainImage retrieves the information about the main image for the specified recipe image from the database, if found, using a dedicated transation that is committed if there are not errors. If no main image exists, a ErrNotFound error is returned.
func (*RecipeImageModel) ReadMainImageTx ¶ added in v1.1.0
func (m *RecipeImageModel) ReadMainImageTx(recipeID int64, tx *sqlx.Tx) (*RecipeImage, error)
ReadMainImageTx retrieves the information about the main image for the specified recipe image from the database, if found, using the specified transaction. If no main image exists, a ErrNotFound error is returned.
func (*RecipeImageModel) ReadTx ¶ added in v1.0.0
func (m *RecipeImageModel) ReadTx(id int64, tx *sqlx.Tx) (*RecipeImage, error)
ReadTx retrieves the information about the image from the database, if found, using the specified transaction. If no image exists with the specified ID, a ErrNotFound error is returned.
func (*RecipeImageModel) UpdateMainImage ¶ added in v1.1.0
func (m *RecipeImageModel) UpdateMainImage(image *RecipeImage) error
UpdateMainImage sets the id of the main image for the specified recipe using a dedicated transation that is committed if there are not errors.
func (*RecipeImageModel) UpdateMainImageTx ¶ added in v1.1.0
func (m *RecipeImageModel) UpdateMainImageTx(image *RecipeImage, tx *sqlx.Tx) error
UpdateMainImageTx sets the id of the main image for the specified recipe using the specified transaction.
type RecipeImages ¶
type RecipeImages []RecipeImage
RecipeImages represents a collection of RecipeImage objects
type RecipeModel ¶ added in v0.3.0
type RecipeModel struct {
*Model
}
RecipeModel provides functionality to edit and retrieve recipes.
func (*RecipeModel) Create ¶ added in v0.3.0
func (m *RecipeModel) Create(recipe *Recipe) error
Create stores the recipe in the database as a new record using a dedicated transation that is committed if there are not errors.
func (*RecipeModel) CreateTx ¶ added in v0.3.0
func (m *RecipeModel) CreateTx(recipe *Recipe, tx *sqlx.Tx) error
CreateTx stores the recipe in the database as a new record using the specified transaction.
func (*RecipeModel) Delete ¶ added in v0.3.0
func (m *RecipeModel) Delete(id int64) error
Delete removes the specified recipe from the database using a dedicated transation that is committed if there are not errors. Note that this method does not delete any attachments that we associated with the deleted recipe.
func (*RecipeModel) DeleteTx ¶ added in v0.3.0
func (m *RecipeModel) DeleteTx(id int64, tx *sqlx.Tx) error
DeleteTx removes the specified recipe from the database using the specified transaction. Note that this method does not delete any attachments that we associated with the deleted recipe.
func (*RecipeModel) Read ¶ added in v0.3.0
func (m *RecipeModel) Read(id int64) (*Recipe, error)
Read retrieves the information about the recipe from the database, if found. If no recipe exists with the specified ID, a NoRecordFound error is returned.
func (*RecipeModel) SetRating ¶ added in v0.4.0
func (m *RecipeModel) SetRating(id int64, rating float64) error
SetRating adds or updates the rating of the specified recipe.
func (*RecipeModel) Update ¶ added in v0.3.0
func (m *RecipeModel) Update(recipe *Recipe) error
Update stores the specified recipe in the database by updating the existing record with the specified id using a dedicated transation that is committed if there are not errors.
type RecipesFilter ¶ added in v1.1.0
type RecipesFilter struct { Query string `json:"query"` Tags []string `json:"tags"` SortBy string `json:"sortBy"` SortDir string `json:"sortDir"` Page int64 `json:"page"` Count int64 `json:"count"` }
RecipesFilter is the primary model class for recipe search
type SearchModel ¶ added in v1.0.0
type SearchModel struct {
*Model
}
SearchModel provides functionality to search recipes.
func (*SearchModel) FindRecipes ¶ added in v1.1.0
func (m *SearchModel) FindRecipes(filter RecipesFilter) (*Recipes, int64, error)
FindRecipes retrieves all recipes matching the specified search filter and within the range specified.
func (*SearchModel) FindTags ¶ added in v1.1.0
func (m *SearchModel) FindTags(filter TagsFilter) (*[]string, error)
FindRecipes retrieves all tags matching the specified search filter and within the range specified.
type TagModel ¶ added in v0.3.0
type TagModel struct {
*Model
}
TagModel provides functionality to edit and retrieve tags attached to recipes.
func (*TagModel) Create ¶ added in v0.3.0
Create stores the tag in the database as a new record using a dedicated transation that is committed if there are not errors.
func (*TagModel) CreateTx ¶ added in v0.3.0
CreateTx stores the tag in the database as a new record using the specified transaction.
func (*TagModel) DeleteAll ¶ added in v0.3.0
DeleteAll removes all tags for the specified recipe from the database using a dedicated transation that is committed if there are not errors.
func (*TagModel) DeleteAllTx ¶ added in v0.3.0
DeleteAllTx removes all tags for the specified recipe from the database using the specified transaction.
type TagsFilter ¶ added in v1.1.0
type TagsFilter struct { SortBy string `json:"sortBy"` SortDir string `json:"sortDir"` Count int64 `json:"count"` }
TagsFilter is the primary model class for tag search