models

package
v0.0.0-...-e6f8ebc Latest Latest
Warning

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

Go to latest
Published: Apr 30, 2023 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ErrorMaximumOffsetReached

func ErrorMaximumOffsetReached(m int) error

ErrorMaximumOffsetReached creates a unique error

Types

type ErrorObject

type ErrorObject struct {
	Error       string            `json:"error"`
	ErrorValues map[string]string `json:"error_values,omitempty"`
}

ErrorObject contains an error message and error values

func CreateErrorObject

func CreateErrorObject(err error) *ErrorObject

CreateErrorObject formulates an error object from an error

func HandleValidationErrors

func HandleValidationErrors(patchIndex, tag, field, value, param string) *ErrorObject

HandleValidationErrors works out a human friendly error for all Validation Errors Extend function for additional validation tags

func ValidatePage

func ValidatePage(page PageVariables) []*ErrorObject

ValidatePage represents a model for validating combination of offset and limit

type ErrorResponse

type ErrorResponse struct {
	Errors []*ErrorObject `json:"errors"`
}

ErrorResponse builds a list of errors for an unsuccessful request

type Ingredient

type Ingredient struct {
	Item     string `bson:"item"           json:"item"`
	Quantity int    `bson:"quantity"       json:"quantity"`
	Unit     string `bson:"unit,omitempty" json:"unit,omitempty"`
}

Ingredient contains the ingredient amount

type Location

type Location struct {
	CookBook string `bson:"cook_book,omitempty" json:"cook_book,omitempty"`
	Link     string `bson:"link,omitempty"      json:"link,omitempty"`
	Page     int    `bson:"page,omitempty"      json:"page,omitempty"`
}

Location contains location information for recipe

type PageVariables

type PageVariables struct {
	DefaultMaxResults int
	Limit             int
	Offset            int
}

PageVariables are the necessary fields to determine paging

type Recipe

type Recipe struct {
	ID          string       `bson:"_id,omitempty"               json:"id"`
	CookTime    int          `bson:"cook_time"                   json:"cook_time"`
	Difficulty  string       `bson:"difficulty"                  json:"difficulty"`
	Extras      []Ingredient `bson:"extra_ingredients,omitempty" json:"extra_ingredients,omitempty"`
	Favourite   bool         `bson:"favourite"                   json:"favourite"`
	Ingredients []Ingredient `bson:"ingredients"                 json:"ingredients"`
	Location    Location     `bson:"location"                    json:"location"`
	Notes       string       `bson:"notes,omitempty"             json:"notes,omitempty"`
	PortionSize int          `bson:"portion_size"                json:"portion_size"`
	Tags        []string     `bson:"tags,omitempty"              json:"tags,omitempty"`
	Title       string       `bson:"title"                       json:"title"`
}

Recipe contains information of a recipe

func (*Recipe) Validate

func (recipe *Recipe) Validate() []*ErrorObject

Validate recipe creation

type Recipes

type Recipes struct {
	Count      int      `json:"count"`
	Items      []Recipe `json:"items"`
	Limit      int      `json:"limit"`
	Offset     int      `json:"offset"`
	TotalCount int64    `json:"total_count"`
}

Recipes contains a list of recipes

type UpdateRecipe

type UpdateRecipe struct {
	CookTime    int          `bson:"cook_time"                   json:"cook_time"`
	Difficulty  string       `bson:"difficulty"                  json:"difficulty"`
	Extras      []Ingredient `bson:"extra_ingredients,omitempty" json:"extra_ingredients,omitempty"`
	Favourite   bool         `bson:"favourite"                   json:"favourite"`
	Ingredients []Ingredient `bson:"ingredients"                 json:"ingredients"`
	Location    Location     `bson:"location"                    json:"location"`
	Notes       string       `bson:"notes,omitempty"             json:"notes,omitempty"`
	PortionSize int          `bson:"portion_size"                json:"portion_size"`
	Tags        []string     `bson:"tags,omitempty"              json:"tags,omitempty"`
	Title       string       `bson:"title"                       json:"title"`
}

UpdateRecipe TODO probably needs to be removed and logic using this updated to use Patch

func (*UpdateRecipe) Validate

func (updateRecipe *UpdateRecipe) Validate() []*ErrorObject

Validate recipe creation

Jump to

Keyboard shortcuts

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