Documentation
¶
Index ¶
- Constants
- Variables
- func GetDefaultTimeoutContext() (context.Context, context.CancelFunc)
- func Max[T Number](a, b T) T
- func ValidateComponentConsumableList(v *validator.Validator, recipeID int64, recipeComponents []*RecipeComponent, ...)
- func ValidateConsumable(v *validator.Validator, consumable *Consumable)
- func ValidateConsumed(v *validator.Validator, consumed *Consumed)
- func ValidateEmail(v *validator.Validator, email string)
- func ValidateFullRecipe(v *validator.Validator, fullRecipe *FullRecipe)
- func ValidateMacroNutrients(v *validator.Validator, macros Macronutrients)
- func ValidateMeasurementUnit(v *validator.Validator, consumable *Consumable)
- func ValidateMetadataFilters(v *validator.Validator, f MetadataFilters)
- func ValidatePantryItem(v *validator.Validator, pantryItem *PantryItem)
- func ValidatePasswordPlaintext(v *validator.Validator, password string)
- func ValidateRecipe(v *validator.Validator, recipe *Recipe)
- func ValidateRecipeComponent(v *validator.Validator, recipeComponent *RecipeComponent)
- func ValidateTokenPlaintext(v *validator.Validator, tokenPlaintext string)
- func ValidateUser(v *validator.Validator, user *User)
- type Consumable
- type ConsumableFilters
- type ConsumableModel
- func (m ConsumableModel) Delete(ID int64) error
- func (m ConsumableModel) GetByCreatorID(ID int64, filters ConsumableFilters) ([]*Consumable, Metadata, error)
- func (m ConsumableModel) GetByID(ID int64) (*Consumable, error)
- func (m ConsumableModel) Insert(consumable *Consumable) error
- func (m ConsumableModel) Search(filters ConsumableFilters) ([]*Consumable, Metadata, error)
- func (m ConsumableModel) Update(consumable *Consumable) error
- type Consumed
- type ConsumedModel
- func (m ConsumedModel) Delete(ID int64, userID int64) error
- func (m ConsumedModel) GetAllByUserID(userID int64) ([]*Consumed, error)
- func (m ConsumedModel) GetAllByUserIDAndDate(userID int64, from time.Time, to time.Time) ([]*Consumed, error)
- func (m ConsumedModel) GetByConsumedID(ConsumedID int64) (*Consumed, error)
- func (m ConsumedModel) Insert(consumed *Consumed) error
- func (m ConsumedModel) Update(consumed *Consumed) error
- type FullRecipe
- type IConsumableModel
- type IConsumedModel
- type IPantryItemModel
- type IRecipeComponentModel
- type IRecipeModel
- type ITokenModel
- type IUserModel
- type Macronutrients
- type MeasurementUnit
- type Metadata
- type MetadataFilters
- type Models
- type Number
- type PantryItem
- type PantryItemModel
- func (m PantryItemModel) Create(pantryItem *PantryItem) error
- func (m PantryItemModel) Delete(ID int64, userID int64) error
- func (m PantryItemModel) Get(ID int64) (*PantryItem, error)
- func (m PantryItemModel) GetAllByUserID(userID int64) ([]*PantryItem, error)
- func (m PantryItemModel) Update(pantryItem *PantryItem) error
- type Recipe
- type RecipeComponent
- type RecipeComponentModel
- type RecipeFilters
- type RecipeModel
- func (m RecipeModel) Delete(ID int64) error
- func (m RecipeModel) Get(ID int64) (*Recipe, error)
- func (m RecipeModel) GetAllAncestors(childRecipe *Recipe, filters RecipeFilters) ([]*Recipe, Metadata, error)
- func (m RecipeModel) GetByCreatorID(ID int64, filters RecipeFilters) ([]*Recipe, Metadata, error)
- func (m RecipeModel) GetFullRecipe(ID int64, userID int64) (*FullRecipe, error)
- func (m RecipeModel) GetLatestByCreatorID(ID int64, filters RecipeFilters) ([]*Recipe, Metadata, error)
- func (m RecipeModel) GetParentRecipe(childRecipe *Recipe) (*Recipe, error)
- func (m RecipeModel) Insert(recipe *Recipe) error
- func (m RecipeModel) InsertFullRecipe(fullRecipe *FullRecipe) error
- func (m RecipeModel) Update(recipe *Recipe) error
- func (m RecipeModel) UpdateFullRecipe(fullRecipe *FullRecipe) error
- type Token
- type TokenModel
- type User
- type UserModel
- func (m UserModel) Authenticate(email string, password string) (*User, error)
- func (m UserModel) Exists(id int) (bool, error)
- func (m UserModel) GetByEmail(email string) (*User, error)
- func (m UserModel) GetForToken(tokenScope string, tokenPlaintext string) (*User, error)
- func (m UserModel) Insert(user *User) error
- func (m UserModel) Update(user *User) error
Constants ¶
View Source
const (
ScopeAuthentication = "authentication"
)
Variables ¶
View Source
var ( ErrRecordNotFound = errors.New("record not found") ErrInvalidCredentials = errors.New("credentials were not correct") ErrEditConflict = errors.New("edit conflict") ErrReferencedUserDoesNotExist = errors.New("user doesn't exist") ErrParentRecipeDoesNotExist = errors.New("parent recipe doesn't exist") ErrPantryItemDoesNotExist = errors.New("pantry item does not exist") ErrChildRecipeExists = errors.New("child recipe exists") ErrRecipeDoesNotExist = errors.New("recipe does not exists") )
View Source
var AnonymousUser = &User{}
View Source
var (
ErrDuplicateEmail = errors.New("duplicate email")
)
View Source
var (
ValidMeasurementUnits = []MeasurementUnit{
"g",
"ml",
}
)
Functions ¶
func GetDefaultTimeoutContext ¶
func GetDefaultTimeoutContext() (context.Context, context.CancelFunc)
func ValidateComponentConsumableList ¶
func ValidateComponentConsumableList(v *validator.Validator, recipeID int64, recipeComponents []*RecipeComponent, pantryItems []*PantryItem, consumables []*Consumable)
func ValidateConsumable ¶
func ValidateConsumable(v *validator.Validator, consumable *Consumable)
func ValidateConsumed ¶
func ValidateEmail ¶
func ValidateFullRecipe ¶
func ValidateFullRecipe(v *validator.Validator, fullRecipe *FullRecipe)
func ValidateMacroNutrients ¶
func ValidateMacroNutrients(v *validator.Validator, macros Macronutrients)
func ValidateMeasurementUnit ¶
func ValidateMeasurementUnit(v *validator.Validator, consumable *Consumable)
func ValidateMetadataFilters ¶
func ValidateMetadataFilters(v *validator.Validator, f MetadataFilters)
func ValidatePantryItem ¶
func ValidatePantryItem(v *validator.Validator, pantryItem *PantryItem)
func ValidateRecipe ¶
func ValidateRecipeComponent ¶
func ValidateRecipeComponent(v *validator.Validator, recipeComponent *RecipeComponent)
func ValidateTokenPlaintext ¶
func ValidateUser ¶
Types ¶
type Consumable ¶
type Consumable struct { ID int64 `json:"id"` CreatorID int64 `json:"creator_id"` CreatedAt time.Time `json:"created_at"` Name string `json:"name"` BrandName string `json:"brand_name"` Size float64 `json:"size"` Units MeasurementUnit `json:"units"` Macros Macronutrients `json:"macros"` }
type ConsumableFilters ¶
type ConsumableFilters struct { Metadata MetadataFilters NameSearch string BrandNameSearch string RequireNameAndBrandNameMatch bool }
func (ConsumableFilters) GetWhereClauseDelimiter ¶
func (options ConsumableFilters) GetWhereClauseDelimiter() string
type ConsumableModel ¶
func (ConsumableModel) Delete ¶
func (m ConsumableModel) Delete(ID int64) error
func (ConsumableModel) GetByCreatorID ¶
func (m ConsumableModel) GetByCreatorID(ID int64, filters ConsumableFilters) ([]*Consumable, Metadata, error)
func (ConsumableModel) GetByID ¶
func (m ConsumableModel) GetByID(ID int64) (*Consumable, error)
func (ConsumableModel) Insert ¶
func (m ConsumableModel) Insert(consumable *Consumable) error
func (ConsumableModel) Search ¶
func (m ConsumableModel) Search(filters ConsumableFilters) ([]*Consumable, Metadata, error)
func (ConsumableModel) Update ¶
func (m ConsumableModel) Update(consumable *Consumable) error
type Consumed ¶
type Consumed struct { ID int64 `json:"id"` UserID int64 `json:"user_id"` RecipeID int64 `json:"recipe_id"` Quantity float64 `json:"quantity"` Macros Macronutrients `json:"macros"` ConsumedAt time.Time `json:"consumed_at"` CreatedAt time.Time `json:"created_at"` LastEditedAt time.Time `json:"last_edited_at"` Notes string `json:"notes"` }
type ConsumedModel ¶
func (ConsumedModel) GetAllByUserID ¶
func (m ConsumedModel) GetAllByUserID(userID int64) ([]*Consumed, error)
func (ConsumedModel) GetAllByUserIDAndDate ¶
func (ConsumedModel) GetByConsumedID ¶
func (m ConsumedModel) GetByConsumedID(ConsumedID int64) (*Consumed, error)
func (ConsumedModel) Insert ¶
func (m ConsumedModel) Insert(consumed *Consumed) error
func (ConsumedModel) Update ¶
func (m ConsumedModel) Update(consumed *Consumed) error
type FullRecipe ¶
type FullRecipe struct { Recipe Recipe RecipeComponents []*RecipeComponent PantryItems []*PantryItem Consumables []*Consumable }
type IConsumableModel ¶
type IConsumableModel interface { GetByID(int64) (*Consumable, error) GetByCreatorID(int64, ConsumableFilters) ([]*Consumable, Metadata, error) Search(ConsumableFilters) ([]*Consumable, Metadata, error) Insert(*Consumable) error Update(*Consumable) error Delete(int64) error }
type IConsumedModel ¶
type IPantryItemModel ¶
type IPantryItemModel interface { GetAllByUserID(int64) ([]*PantryItem, error) Get(int64) (*PantryItem, error) Create(*PantryItem) error Update(*PantryItem) error Delete(int64, int64) error }
type IRecipeComponentModel ¶
type IRecipeComponentModel interface { Get(int64) (*RecipeComponent, error) Insert(*RecipeComponent) error Update(*RecipeComponent, int64) error }
type IRecipeModel ¶
type IRecipeModel interface { Get(int64) (*Recipe, error) GetByCreatorID(int64, RecipeFilters) ([]*Recipe, Metadata, error) GetLatestByCreatorID(int64, RecipeFilters) ([]*Recipe, Metadata, error) GetFullRecipe(int64, int64) (*FullRecipe, error) Insert(*Recipe) error InsertFullRecipe(*FullRecipe) error Update(*Recipe) error UpdateFullRecipe(*FullRecipe) error Delete(int64) error GetParentRecipe(*Recipe) (*Recipe, error) GetAllAncestors(*Recipe, RecipeFilters) ([]*Recipe, Metadata, error) }
type ITokenModel ¶
type IUserModel ¶
type Macronutrients ¶
type Macronutrients struct { Carbs float64 `json:"carbs"` Fats float64 `json:"fats"` Proteins float64 `json:"proteins"` Alcohol float64 `json:"alcohol"` }
func (*Macronutrients) CalculateKJ ¶
func (macros *Macronutrients) CalculateKJ() float64
type MeasurementUnit ¶
type MeasurementUnit string
type MetadataFilters ¶
type Models ¶
type Models struct { Users IUserModel Tokens ITokenModel Consumed IConsumedModel Consumables IConsumableModel Recipes IRecipeModel RecipeComponents IRecipeComponentModel PantryItems IPantryItemModel }
type Number ¶
type Number interface { constraints.Integer | constraints.Float }
type PantryItem ¶
type PantryItemModel ¶
func (PantryItemModel) Create ¶
func (m PantryItemModel) Create(pantryItem *PantryItem) error
func (PantryItemModel) Get ¶
func (m PantryItemModel) Get(ID int64) (*PantryItem, error)
func (PantryItemModel) GetAllByUserID ¶
func (m PantryItemModel) GetAllByUserID(userID int64) ([]*PantryItem, error)
func (PantryItemModel) Update ¶
func (m PantryItemModel) Update(pantryItem *PantryItem) error
type Recipe ¶
type Recipe struct { ID int64 `json:"id"` Name string `json:"recipe_name"` CreatorID int64 `json:"creator_id"` CreatedAt time.Time `json:"created_at"` LastEditedAt time.Time `json:"last_edited_at"` Notes string `json:"notes"` ParentRecipeID int64 `json:"parent_recipe_id"` IsLatest bool `json:"is_latest"` }
type RecipeComponent ¶
type RecipeComponentModel ¶
func (RecipeComponentModel) Get ¶
func (m RecipeComponentModel) Get(ID int64) (*RecipeComponent, error)
func (RecipeComponentModel) Insert ¶
func (m RecipeComponentModel) Insert(recipeComponent *RecipeComponent) error
func (RecipeComponentModel) Update ¶
func (m RecipeComponentModel) Update(recipeComponent *RecipeComponent, userID int64) error
type RecipeFilters ¶
type RecipeFilters struct { Metadata MetadataFilters NameSearch string }
type RecipeModel ¶
func (RecipeModel) Delete ¶
func (m RecipeModel) Delete(ID int64) error
func (RecipeModel) GetAllAncestors ¶
func (m RecipeModel) GetAllAncestors(childRecipe *Recipe, filters RecipeFilters) ([]*Recipe, Metadata, error)
func (RecipeModel) GetByCreatorID ¶
func (m RecipeModel) GetByCreatorID(ID int64, filters RecipeFilters) ([]*Recipe, Metadata, error)
func (RecipeModel) GetFullRecipe ¶
func (m RecipeModel) GetFullRecipe(ID int64, userID int64) (*FullRecipe, error)
func (RecipeModel) GetLatestByCreatorID ¶
func (m RecipeModel) GetLatestByCreatorID(ID int64, filters RecipeFilters) ([]*Recipe, Metadata, error)
func (RecipeModel) GetParentRecipe ¶
func (m RecipeModel) GetParentRecipe(childRecipe *Recipe) (*Recipe, error)
func (RecipeModel) Insert ¶
func (m RecipeModel) Insert(recipe *Recipe) error
func (RecipeModel) InsertFullRecipe ¶
func (m RecipeModel) InsertFullRecipe(fullRecipe *FullRecipe) error
func (RecipeModel) Update ¶
func (m RecipeModel) Update(recipe *Recipe) error
func (RecipeModel) UpdateFullRecipe ¶
func (m RecipeModel) UpdateFullRecipe(fullRecipe *FullRecipe) error
not good name, maybe createChildOfFullRecipe()
type TokenModel ¶
func (TokenModel) DeleteAllForUser ¶
func (m TokenModel) DeleteAllForUser(scope string, userID int64) error
func (TokenModel) Insert ¶
func (m TokenModel) Insert(token *Token) error
type User ¶
type User struct { ID int64 `json:"id"` CreatedAt time.Time `json:"created_at"` Username string `json:"username"` Email string `json:"email"` Password password `json:"-"` Version int `json:"-"` }
func (*User) IsAnonymous ¶
Source Files
¶
Click to show internal directories.
Click to hide internal directories.