models

package
v0.8.0 Latest Latest
Warning

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

Go to latest
Published: Jun 12, 2016 License: MIT Imports: 19 Imported by: 0

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
	// 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

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 *sql.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 *sql.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 *sql.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 *sql.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
	AvgRating     float64
	Image         string
	Tags          []string
}

Recipe is the primary model class for recipe storage and retrieval

type RecipeImage

type RecipeImage struct {
	RecipeID     int64
	Name         string
	URL          string
	ThumbnailURL string
}

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) Delete added in v0.6.0

func (m *RecipeImageModel) Delete(recipeID int64, name string) error

Delete deletes a single image attached to the specified recipe

func (*RecipeImageModel) DeleteAll added in v0.4.1

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

DeleteAll deletes all the images attached to the specified recipe

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) Save added in v0.3.0

func (m *RecipeImageModel) Save(recipeID int64, name string, data []byte) error

Save saves the supplied image data as an attachment on the specified recipe

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 *sql.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 *sql.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) Find added in v0.3.0

func (m *RecipeModel) Find(search string, page int64, count int64) (*Recipes, int64, error)

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

func (*RecipeModel) List added in v0.3.0

func (m *RecipeModel) List(page int64, count int64) (*Recipes, int64, error)

List retrieves all recipes within the range specified, sorted by name.

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) UpdateTx added in v0.3.0

func (m *RecipeModel) UpdateTx(recipe *Recipe, tx *sql.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 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 *sql.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 *sql.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.

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 *sql.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