db

package
v0.0.0-...-4b8b255 Latest Latest
Warning

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

Go to latest
Published: Jan 21, 2024 License: AGPL-3.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DB *gorm.DB

Functions

func InitDB

func InitDB(conf config.DBConfig) error

Types

type CreateRecipe

type CreateRecipe struct {
	Title            string             `json:"title" validate:"required,min=1,max=60"`
	Info             CreateRecipeInfo   `json:"info,omitempty"`
	ShortDescription *string            `json:"shortDescription,omitempty" validate:"omitempty,max=256"`
	LongDescription  *string            `json:"longDescription,omitempty"`
	Ingredients      []RecipeIngredient `json:"ingredients,omitempty"`
	Steps            []RecipeStep       `json:"steps,omitempty"`
	Labels           []string           `json:"labels,omitempty" validate:"dive,min=1,max=60"`
}

func (*CreateRecipe) IntoRecipe

func (r *CreateRecipe) IntoRecipe(ownerID uuid.UUID, imageID *uuid.UUID) Recipe

type CreateRecipeInfo

type CreateRecipeInfo RecipeInfo

type CreateUser

type CreateUser struct {
	Username string `json:"username" validate:"required,alphanum,min=3,max=30"`
	Password string `json:"password" validate:"required"`
}

func (*CreateUser) IntoUser

func (u *CreateUser) IntoUser() User

type Label

type Label struct {
	ID   uint   `gorm:"primarykey" json:"-"`
	Name string `gorm:"uniqueIndex;not null;type:varchar(60);<-:create" json:"name"`
}

type PantryItem

type PantryItem struct {
	UUIDBase
	TimeBase
	Name       string         `gorm:"not null;size:60" json:"name"`
	LocationId uuid.UUID      `gorm:"not null;type:uuid" json:"locationId"`
	Quantity   uint           `gorm:"not null;default:1" json:"quantity"`
	Notes      *string        `json:"notes,omitempty"`
	Expiry     *time.Time     `json:"expiry,omitempty"`
	Labels     []Label        `gorm:"many2many:pantry_item_labels" json:"-"`
	Location   PantryLocation `json:"-"`
}

type PantryLocation

type PantryLocation struct {
	UUIDBase
	TimeBase
	Name    string       `gorm:"not null;size:60" json:"name"`
	OwnerId uuid.UUID    `gorm:"not null;type:uuid" json:"ownerId"`
	Items   []PantryItem `gorm:"foreignKey:LocationId" json:"-"`
}

type ReadRecipe

type ReadRecipe struct {
	UUIDBase
	TimeBase
	OwnerID          uuid.UUID           `json:"ownerId"`
	Title            string              `json:"title"`
	Info             RecipeInfo          `json:"info"`
	ShortDescription *string             `json:"shortDescription,omitempty"`
	LongDescription  *string             `json:"longDescription,omitempty"`
	Ingredients      *[]RecipeIngredient `json:"ingredients,omitempty"`
	Steps            *[]RecipeStep       `json:"steps,omitempty"`
	ImageID          *uuid.UUID          `json:"imageId"`
	Labels           []string            `json:"labels"`
}

type Recipe

type Recipe struct {
	UUIDBase
	TimeBase
	OwnerID          uuid.UUID                               `gorm:"not null;type:uuid" json:"ownerId"`
	Title            string                                  `gorm:"not null;type:varchar(60)" json:"title"`
	Info             RecipeInfo                              `gorm:"embedded;embeddedPrefix:info_" json:"info"`
	ShortDescription *string                                 `gorm:"type:varchar(256)" json:"shortDescription,omitempty"`
	LongDescription  *string                                 `json:"longDescription,omitempty"`
	Ingredients      *datatypes.JSONType[[]RecipeIngredient] `gorm:"type:json" json:"ingredients,omitempty"`
	Steps            *datatypes.JSONType[[]RecipeStep]       `gorm:"type:json" json:"steps,omitempty"`
	ImageID          *uuid.UUID                              `gorm:"type:uuid" json:"imageId"`
	Labels           []Label                                 `gorm:"many2many:recipe_labels" json:"-"`
}

func (*Recipe) IntoReadRecipe

func (r *Recipe) IntoReadRecipe() ReadRecipe

type RecipeInfo

type RecipeInfo struct {
	Yields        *datatypes.JSONType[RecipeInfoYields] `gorm:"type:json" json:"yields,omitempty"`
	CookTime      uint                                  `gorm:"not null;default:0" json:"cookTime,omitempty"`
	PrepTime      uint                                  `gorm:"not null;default:0" json:"prepTime,omitempty"`
	Freezable     bool                                  `gorm:"not null;default:false" json:"freezable"`
	MicrowaveOnly bool                                  `gorm:"not null;default:false" json:"microwaveOnly"`
	Source        *string                               `json:"source,omitempty"`
}

type RecipeInfoYields

type RecipeInfoYields struct {
	Value    uint   `json:"value" validate:"required"`
	UnitType string `json:"unitType" validate:"required"`
}

type RecipeIngredient

type RecipeIngredient struct {
	Name        string  `json:"name" validate:"required"`
	Amount      float32 `json:"amount" validate:"required"`
	UnitType    string  `json:"unitType" validate:"required"`
	Description *string `json:"description,omitempty"`
}

type RecipeStep

type RecipeStep struct {
	Title       *string `json:"title,omitempty"`
	Description string  `json:"description" validate:"required"`
}

type TimeBase

type TimeBase struct {
	CreatedAt time.Time `json:"createdAt"`
	UpdatedAt time.Time `json:"updatedAt"`
}

type UUIDBase

type UUIDBase struct {
	ID uuid.UUID `gorm:"primarykey;type:uuid" json:"id"`
}

func (*UUIDBase) BeforeCreate

func (base *UUIDBase) BeforeCreate(tx *gorm.DB) (err error)

type UpdateIngredient

type UpdateIngredient struct {
	Name        string  `json:"name,omitempty"`
	Amount      float32 `json:"amount,omitempty"`
	UnitType    string  `json:"unitType,omitempty"`
	Description *string `json:"description,omitempty"`
}

type UpdateRecipe

type UpdateRecipe struct {
	Title            *string             `json:"title,omitempty" validate:"omitempty,min=1,max=60"`
	Info             UpdateRecipeInfo    `json:"info,omitempty"`
	ShortDescription *string             `json:"shortDescription,omitempty" validate:"omitempty,max=256"`
	LongDescription  *string             `json:"longDescription,omitempty"`
	Ingredients      *[]UpdateIngredient `json:"ingredients,omitempty"`
	Steps            *[]UpdateStep       `json:"steps,omitempty"`
	ImageID          *uuid.UUID          `json:"-"`
	Labels           *[]string           `json:"labels,omitempty" validate:"omitempty,dive,min=1,max=60"`
}

func (*UpdateRecipe) IntoRecipe

func (r *UpdateRecipe) IntoRecipe() Recipe

type UpdateRecipeInfo

type UpdateRecipeInfo RecipeInfo

type UpdateStep

type UpdateStep struct {
	Title       *string `json:"title,omitempty"`
	Description string  `json:"description,omitempty"`
}

type User

type User struct {
	UUIDBase
	TimeBase
	Username        string           `gorm:"uniqueIndex;not null;type:varchar(30)" json:"username"`
	HashedPassword  []byte           `gorm:"not null" json:"-"`
	Recipes         []Recipe         `gorm:"foreignKey:OwnerID" json:"-"`
	PantryLocations []PantryLocation `gorm:"foreignKey:OwnerId" json:"-"`
}

func (*User) IsPasswordMatch

func (u *User) IsPasswordMatch(plainPassword string) bool

func (*User) SetPassword

func (u *User) SetPassword(newPlainPassword string)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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