models

package
v0.0.0-...-e6b71c9 Latest Latest
Warning

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

Go to latest
Published: Jan 19, 2023 License: MIT Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FindStoreCategoryName

func FindStoreCategoryName(id uuid.UUID, tx *gorm.DB) (name string)

Types

type ApiClient

type ApiClient struct {
	ID        uuid.UUID `gorm:"primaryKey;type:uuid;default:gen_random_uuid()"`
	Name      string    `gorm:"type:varchar(100);uniqueIndex;not null"`
	Key       string    `gorm:"type:varchar(100);not null"`
	Secret    string    `gorm:"type:varchar(100);not null"`
	CreatedAt time.Time
	UpdatedAt time.Time

	// Associations
	Tokens []AuthToken `gorm:"foreignKey:ClientID"`
}

func (*ApiClient) BeforeCreate

func (c *ApiClient) BeforeCreate(tx *gorm.DB) (err error)

BeforeCreate hook to generate key/secret

type AuthToken

type AuthToken struct {
	ID           uuid.UUID `gorm:"primaryKey;type:uuid;default:gen_random_uuid()"`
	ClientID     uuid.UUID `gorm:"type:uuid;default:gen_random_uuid();not null"`
	UserID       uuid.UUID `gorm:"type:uuid;default:gen_random_uuid();not null"`
	AccessToken  string    `gorm:"type:varchar(100);not null;index:idx_auth_tokens_access_token"`
	RefreshToken string    `gorm:"type:varchar(100);not null"`
	ExpiresIn    time.Time `gorm:"not null"`
	DeviceName   string    `gorm:"type:varchar(100)"`
	CreatedAt    time.Time
	UpdatedAt    time.Time

	// Associations
	Client ApiClient
	User   User
}

func (*AuthToken) BeforeCreate

func (c *AuthToken) BeforeCreate(tx *gorm.DB) (err error)

BeforeCreate handles generating tokens and also handles old token cleanup

type Device

type Device struct {
	ID     uuid.UUID `gorm:"primaryKey;type:uuid;default:gen_random_uuid()"`
	UserID uuid.UUID `gorm:"type:uuid;not null"`
	Token  string    `gorm:"type:varchar(255);not null"`

	CreatedAt time.Time
	UpdatedAt time.Time
	DeletedAt gorm.DeletedAt

	// Associations
	User User
}

type GroceryTrip

type GroceryTrip struct {
	ID                 uuid.UUID `gorm:"primaryKey;type:uuid;default:gen_random_uuid()"`
	StoreID            uuid.UUID `gorm:"type:uuid;not null;index"`
	Name               string    `gorm:"type:varchar(100);not null"`
	Completed          bool      `gorm:"default:false;not null"`
	CopyRemainingItems bool      `gorm:"default:false;not null"`

	CreatedAt time.Time
	UpdatedAt time.Time
	DeletedAt gorm.DeletedAt

	// Associations
	Store Store
	Items []Item
}

func (*GroceryTrip) BeforeCreate

func (g *GroceryTrip) BeforeCreate(tx *gorm.DB) (err error)

BeforeCreate hook is triggered before a trip is created

type GroceryTripCategory

type GroceryTripCategory struct {
	ID              uuid.UUID `gorm:"primaryKey;type:uuid;default:gen_random_uuid()"`
	GroceryTripID   uuid.UUID `gorm:"type:uuid;not null;index:idx_grocery_trip_categories_grocery_trip_id"`
	StoreCategoryID uuid.UUID `gorm:"type:uuid;not null;index:idx_grocery_trip_categories_store_category_id"`

	CreatedAt time.Time
	UpdatedAt time.Time
	DeletedAt gorm.DeletedAt

	// Associations
	GroceryTrip   GroceryTrip
	StoreCategory StoreCategory
	Item          []Item `gorm:"foreignKey:CategoryID"`
}

type Item

type Item struct {
	ID            uuid.UUID  `gorm:"primaryKey;type:uuid;default:gen_random_uuid()"`
	GroceryTripID uuid.UUID  `gorm:"type:uuid;not null;index:idx_items_grocery_trip_id_name"`
	CategoryID    *uuid.UUID `gorm:"type:uuid;not null"`
	UserID        uuid.UUID  `gorm:"type:uuid;not null"`
	StapleItemID  *uuid.UUID `gorm:"type:uuid;index"`
	Name          string     `gorm:"type:varchar(100);not null;index:idx_items_grocery_trip_id_name"`
	Quantity      int        `gorm:"default:1;not null"`
	Completed     *bool      `gorm:"default:false;not null"`
	Position      int        `gorm:"default:1;not null"`
	Notes         *string    `gorm:"type:varchar(255)"`
	MealID        *uuid.UUID `gorm:"type:uuid"`
	MealName      *string    `gorm:"type:varchar(255)"`

	CreatedAt time.Time
	UpdatedAt time.Time
	DeletedAt gorm.DeletedAt

	// Associations
	GroceryTrip GroceryTrip
	Meal        Meal
	StapleItem  StoreStapleItem
}

Item defines the model for items

func (*Item) AfterCreate

func (i *Item) AfterCreate(tx *gorm.DB) (err error)

AfterCreate hook to touch the associated grocery trip after an item is created so that its UpdatedAt column is updated

func (*Item) AfterUpdate

func (i *Item) AfterUpdate(tx *gorm.DB) (err error)

func (*Item) BeforeCreate

func (i *Item) BeforeCreate(tx *gorm.DB) (err error)

BeforeCreate hook updates the item position

func (*Item) BeforeSave

func (i *Item) BeforeSave(tx *gorm.DB) (err error)

BeforeSave hook

func (*Item) BeforeUpdate

func (i *Item) BeforeUpdate(tx *gorm.DB) (err error)

BeforeUpdate hook handles reordering items

func (*Item) CreateGroceryTripCategory

func (i *Item) CreateGroceryTripCategory(name string, tx *gorm.DB) (category GroceryTripCategory, err error)

CreateGroceryTripCategory creates a grocery trip category by name

func (*Item) DetermineCategoryName

func (i *Item) DetermineCategoryName(storeID uuid.UUID, tx *gorm.DB) (result string, err error)

DetermineCategoryName first checks to see if this item's preferred category has been saved in the store settings and uses that if so. As a fallback, it opens the FoodClassification.json file and scans it

func (*Item) FetchGroceryTripCategory

func (i *Item) FetchGroceryTripCategory(name string, tx *gorm.DB) (category GroceryTripCategory, err error)

FetchGroceryTripCategory retrieves a grocery trip category for a new item by finding or creating a category depending on if one exists by the name provided

type Meal

type Meal struct {
	ID       uuid.UUID `gorm:"primaryKey;type:uuid;default:gen_random_uuid()"`
	RecipeID uuid.UUID `gorm:"type:uuid;not null"`
	UserID   uuid.UUID `gorm:"type:uuid;not null"`
	StoreID  uuid.UUID `gorm:"type:uuid;not null"`
	Name     string    `gorm:"type:varchar(255);not null;index:idx_meals_name"`
	MealType *string   `gorm:"type:varchar(10)"`
	Servings int       `gorm:"default:1;not null"`
	Notes    *string   `gorm:"type:text"`
	Date     string    `gorm:"type:varchar(255);not null;index:idx_meals_date"`

	CreatedAt time.Time
	UpdatedAt time.Time
	DeletedAt gorm.DeletedAt

	// Associations
	Users  []MealUser
	Recipe Recipe
	User   User
}

Meal defines the model for meals A meal is a planned recipe for a user

func (*Meal) AfterDelete

func (m *Meal) AfterDelete(tx *gorm.DB) (err error)

AfterDelete hook handles deleting associated records after meal is soft-deleted

type MealUser

type MealUser struct {
	ID     uuid.UUID `gorm:"primaryKey;type:uuid;default:gen_random_uuid()"`
	MealID uuid.UUID `gorm:"type:uuid;not null"`
	UserID uuid.UUID `gorm:"type:uuid;not null;index:idx_meal_users_user_id"`

	CreatedAt time.Time
	UpdatedAt time.Time
	DeletedAt gorm.DeletedAt

	// Associations
	Meal Meal
	User User
}

MealUser defines the model for meal_users, which represents a user's usage of a recipe

type Recipe

type Recipe struct {
	ID           uuid.UUID       `gorm:"primaryKey;type:uuid;default:gen_random_uuid()"`
	UserID       uuid.UUID       `gorm:"type:uuid;not null;index:idx_recipes_user_id"`
	Name         string          `gorm:"type:varchar(255);not null;index:idx_recipes_name"`
	Description  *string         `gorm:"type:text"`
	Instructions *datatypes.JSON `gorm:"type:json"`
	MealType     *string         `gorm:"type:varchar(10)"`
	URL          *string         `gorm:"type:varchar(255)"`
	ImageURL     *string         `gorm:"type:text"`

	CreatedAt time.Time
	UpdatedAt time.Time
	DeletedAt gorm.DeletedAt

	// Associations
	Ingredients []RecipeIngredient
	Meals       []Meal
}

Recipe defines the model for recipes

type RecipeIngredient

type RecipeIngredient struct {
	ID       uuid.UUID `gorm:"primaryKey;type:uuid;default:gen_random_uuid()"`
	RecipeID uuid.UUID `gorm:"type:uuid;not null;index:idx_recipe_ingredients_recipe_id"`
	Name     string    `gorm:"type:varchar(255);not null"`
	Amount   *string
	Unit     *string `gorm:"type:varchar(20)"`
	Notes    *string `gorm:"type:varchar(255);"`

	CreatedAt time.Time
	UpdatedAt time.Time
	DeletedAt gorm.DeletedAt

	// Associations
	Recipe Recipe
}

RecipeIngredient defines the model for recipe_ingredients

type Store

type Store struct {
	ID        uuid.UUID `gorm:"primaryKey;type:uuid;default:gen_random_uuid()"`
	UserID    uuid.UUID `gorm:"type:uuid;default:gen_random_uuid();not null"`
	Name      string    `gorm:"type:varchar(100);not null"`
	ShareCode string    `gorm:"type:varchar(255);uniqueIndex"`

	CreatedAt time.Time
	UpdatedAt time.Time
	DeletedAt gorm.DeletedAt

	// Associations
	StoreUsers   []StoreUser
	GroceryTrips []GroceryTrip
}

func (*Store) AfterCreate

func (s *Store) AfterCreate(tx *gorm.DB) (err error)

AfterCreate hook to automatically create some associated records

func (*Store) AfterDelete

func (s *Store) AfterDelete(tx *gorm.DB) (err error)

AfterDelete hook handles deleting associated records after store is deleted

func (*Store) BeforeCreate

func (s *Store) BeforeCreate(tx *gorm.DB) (err error)

BeforeCreate handles some prep work before a store is created

type StoreCategory

type StoreCategory struct {
	ID      uuid.UUID `gorm:"primaryKey;type:uuid;default:gen_random_uuid()"`
	StoreID uuid.UUID `gorm:"type:uuid;not null;index:idx_store_categories_store_id"`
	Name    string    `gorm:"type:varchar(100);not null"`

	CreatedAt time.Time
	UpdatedAt time.Time
	DeletedAt gorm.DeletedAt

	// Associations
	Store Store
}

type StoreItemCategorySettings

type StoreItemCategorySettings struct {
	ID      uuid.UUID `gorm:"primaryKey;type:uuid;default:gen_random_uuid()"`
	StoreID uuid.UUID `gorm:"type:uuid;not null;index:idx_store_category_items_store_id"`
	Items   datatypes.JSON

	CreatedAt time.Time
	UpdatedAt time.Time
	DeletedAt gorm.DeletedAt
}

type StoreStapleItem

type StoreStapleItem struct {
	ID      uuid.UUID `gorm:"primaryKey;type:uuid;default:gen_random_uuid()"`
	StoreID uuid.UUID `gorm:"type:uuid;not null;index:idx_store_staple_items_store_id"`
	Name    string    `gorm:"type:varchar(100);not null"`

	CreatedAt time.Time
	UpdatedAt time.Time
	DeletedAt gorm.DeletedAt

	// Associations
	Store Store
}

type StoreUser

type StoreUser struct {
	ID      uuid.UUID `gorm:"primaryKey;type:uuid;default:gen_random_uuid()"`
	StoreID uuid.UUID `gorm:"type:uuid;not null;index:idx_store_users_store_id"`
	UserID  uuid.UUID `gorm:"type:uuid"`
	Email   string    `gorm:"type:varchar(100)"`
	Creator *bool     `gorm:"default:false;not null"`
	Active  *bool     `gorm:"default:true;not null"`

	CreatedAt time.Time
	UpdatedAt time.Time
	DeletedAt gorm.DeletedAt

	// Associations
	Preferences StoreUserPreference
	Store       Store
	User        User
}

func (*StoreUser) AfterCreate

func (su *StoreUser) AfterCreate(tx *gorm.DB) (err error)

AfterCreate hook to handle sending an invite email to a new StoreUser if the email column is not empty (i.e. store invitation by another user)

type StoreUserPreference

type StoreUserPreference struct {
	ID            uuid.UUID `gorm:"primaryKey;type:uuid;default:gen_random_uuid()"`
	StoreUserID   uuid.UUID `gorm:"type:uuid;uniqueIndex;not null"`
	DefaultStore  bool      `gorm:"default:false;not null"`
	Notifications bool      `gorm:"default:true;not null"`

	CreatedAt time.Time
	UpdatedAt time.Time
	DeletedAt gorm.DeletedAt
}

func (*StoreUserPreference) AfterUpdate

func (sup *StoreUserPreference) AfterUpdate(tx *gorm.DB) (err error)

AfterUpdate hook handles some cleanup operations after updating store user prefs

type User

type User struct {
	ID                       uuid.UUID  `gorm:"primaryKey;type:uuid;default:gen_random_uuid()"`
	Email                    string     `gorm:"type:varchar(100);uniqueIndex;not null"`
	Password                 string     `gorm:"not null"`
	Name                     string     `gorm:"type:varchar(100)"`
	PasswordResetToken       *uuid.UUID `gorm:"type:uuid"`
	PasswordResetTokenExpiry *time.Time
	SiwaID                   *string `gorm:"type:varchar(255);uniqueIndex"`

	LastSeenAt time.Time
	CreatedAt  time.Time
	UpdatedAt  time.Time

	// Associations
	Stores []Store
	Tokens []AuthToken
}

func (*User) BeforeDelete

func (u *User) BeforeDelete(tx *gorm.DB) (err error)

BeforeDelete handles removing associated data before a user account is deleted

Jump to

Keyboard shortcuts

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