models

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Aug 3, 2016 License: MIT Imports: 18 Imported by: 6

Documentation

Index

Constants

This section is empty.

Variables

View Source
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

func New added in v0.3.0

func New(cfg *conf.Config) *Model

New constructs a new Model object

func (*Model) TearDown added in v1.0.0

func (m *Model) TearDown()

TearDown closes the connection to the database.

type Note

type Note struct {
	ID         int64
	RecipeID   int64
	Note       string
	CreatedAt  time.Time
	ModifiedAt time.Time
}

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

func (m *NoteModel) Create(note *Note) error

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

func (m *NoteModel) CreateTx(note *Note, tx *sqlx.Tx) error

CreateTx stores the note in the database as a new record using the specified transaction.

func (*NoteModel) Delete added in v0.6.0

func (m *NoteModel) Delete(id int64) error

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

func (m *NoteModel) DeleteAll(recipeID int64) error

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

func (m *NoteModel) DeleteAllTx(recipeID int64, tx *sqlx.Tx) error

DeleteAllTx removes all notes for the specified recipe from the database using the specified transaction.

func (*NoteModel) DeleteTx added in v0.6.0

func (m *NoteModel) DeleteTx(id int64, tx *sqlx.Tx) error

DeleteTx removes the specified note from the database using the specified transaction.

func (*NoteModel) List added in v0.3.0

func (m *NoteModel) List(recipeID int64) (*Notes, error)

List retrieves all notes associated with the recipe with the specified id.

func (*NoteModel) Update added in v0.6.1

func (m *NoteModel) Update(note *Note) error

Update stores the note in the database by updating the existing record with the specified id using a dedicated transation that is committed if there are not errors.

func (*NoteModel) UpdateTx added in v0.6.1

func (m *NoteModel) UpdateTx(note *Note, tx *sqlx.Tx) error

UpdateTx stores the note in the database by updating the existing record with the specified id using the specified transaction.

type Notes

type Notes []Note

Notes represents a collection of Note objects

type Recipe

type Recipe struct {
	ID            int64
	Name          string
	ServingSize   string
	NutritionInfo string
	Ingredients   string
	Directions    string
	SourceURL     string
	AvgRating     float64
	MainImage     RecipeImage
	Tags          []string
}

Recipe is the primary model class for recipe storage and retrieval

type RecipeImage

type RecipeImage struct {
	ID           int64
	RecipeID     int64
	Name         string
	URL          string
	ThumbnailURL string
	CreatedAt    time.Time
	ModifiedAt   time.Time
}

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) 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.

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.

func (*RecipeModel) UpdateMainImage added in v1.0.0

func (m *RecipeModel) UpdateMainImage(recipe *Recipe) error

UpdateMainImage sets the id of the main image for the specified recipes using a dedicated transation that is committed if there are not errors.

func (*RecipeModel) UpdateMainImageTx added in v1.0.0

func (m *RecipeModel) UpdateMainImageTx(recipe *Recipe, tx *sqlx.Tx) error

UpdateMainImageTx sets the id of the main image for the specified recipes using the specified transaction.

func (*RecipeModel) UpdateTx added in v0.3.0

func (m *RecipeModel) UpdateTx(recipe *Recipe, tx *sqlx.Tx) error

UpdateTx stores the specified recipe in the database by updating the existing record with the sepcified id using the specified transaction.

type Recipes

type Recipes []Recipe

Recipes represents a collection of Recipe objects

type SearchFilter added in v1.0.0

type SearchFilter struct {
	Query    string
	Tags     []string
	SortBy   SortBy
	SortDesc bool
}

SearchFilter 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) Find added in v1.0.0

func (m *SearchModel) Find(filter SearchFilter, page int64, count int64) (*Recipes, int64, error)

Find retrieves all recipes matching the specified search filter and within the range specified, sorted by name.

type SortBy added in v1.0.0

type SortBy int

SortBy represents an enumeration of possible sort fields

const (
	SortByName   SortBy = 0
	SortByID     SortBy = 1
	SortByRating SortBy = 2
	SortByRandom SortBy = 3
)

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

func (m *TagModel) Create(recipeID int64, tag string) error

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

func (m *TagModel) CreateTx(recipeID int64, tag string, tx *sqlx.Tx) error

CreateTx stores the tag in the database as a new record using the specified transaction.

func (*TagModel) DeleteAll added in v0.3.0

func (m *TagModel) DeleteAll(recipeID int64) error

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

func (m *TagModel) DeleteAllTx(recipeID int64, tx *sqlx.Tx) error

DeleteAllTx removes all tags for the specified recipe from the database using the specified transaction.

func (*TagModel) List added in v0.3.0

func (m *TagModel) List(recipeID int64) (*[]string, error)

List retrieves all tags associated with the recipe with the specified id.

func (*TagModel) ListAll added in v1.0.0

func (m *TagModel) ListAll() (*[]string, error)

ListAll retrieves all tags.

func (*TagModel) ListMostUsed added in v1.0.0

func (m *TagModel) ListMostUsed(count int) (*[]string, error)

ListMostUsed retrieves the N most used tags.

type User added in v0.8.0

type User struct {
	ID       int64
	Username string
}

type UserModel added in v0.8.0

type UserModel struct {
	*Model
}

func (*UserModel) Authenticate added in v0.8.0

func (m *UserModel) Authenticate(username, password string) (*User, error)

func (*UserModel) Create added in v0.8.0

func (m *UserModel) Create(username, password string) error

func (*UserModel) CreateTx added in v0.8.0

func (m *UserModel) CreateTx(username, password string, tx *sqlx.Tx) error

func (*UserModel) Read added in v0.8.0

func (m *UserModel) Read(id int64) (*User, error)

Jump to

Keyboard shortcuts

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