database

package
v0.0.0-...-6ff84a0 Latest Latest
Warning

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

Go to latest
Published: Jan 5, 2021 License: AGPL-3.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DB *gorm.DB

DB holds the the database connection. I know, it's global variable. I think in this case might be justified ¯\_(ツ)_/¯

Functions

func DeleteFluid

func DeleteFluid(id string) error

func DeleteFoodDiary

func DeleteFoodDiary(id string) error

func DeleteFoodInventory

func DeleteFoodInventory(id string) error

func DeleteMeasurement

func DeleteMeasurement(id string) error

func GetDB

func GetDB() *gorm.DB

GetDB use this function to get a connection

func Init

func Init() (*gorm.DB, error)

Connect creates a new gorm db connection.

func InitData

func InitData() error

func Migrate

func Migrate() error

func PasswordHash

func PasswordHash(password string) (string, error)

func SaveOne

func SaveOne(data interface{}) error

SaveOne insert or update an element in the database, can be anything

func StoreImages

func StoreImages(urls *[]string, userID uint, FoodInventoryID *uint) error

StoreImages build the mapping table between images and uploads

Types

type Fluid

type Fluid struct {
	gorm.Model `binding:"-"`
	Type       string    `json:"type" binding:"required"`
	Date       time.Time `json:"date" binding:"required"`
	Value      float32   `gorm:"type:FLOAT" json:"value,string" binding:"required"`
	UserID     uint      `binding:"-"`
}

func FindFluids

func FindFluids(f *FluidSearch) ([]Fluid, error)

func FindOneFluid

func FindOneFluid(UserID string) (Fluid, error)

type FluidSearch

type FluidSearch struct {
	UserID uint
	From   time.Time
	To     time.Time
}

type FoodDiary

type FoodDiary struct {
	gorm.Model
	MealTypeID      string  // Breakfast, Lunch, Dinner, Snacks, Water
	Quantity        float32 `gorm:"type:FLOAT"`
	Date            time.Time
	QuantityUnitID  uint
	Comments        string
	UserID          uint
	FoodInventoryID uint
	FoodInventory   FoodInventory
}

func FindManyFoodDiary

func FindManyFoodDiary(UserID uint, start time.Time, end time.Time) ([]FoodDiary, error)

func FindOneFoodDiary

func FindOneFoodDiary(id string) (FoodDiary, error)

type FoodInventory

type FoodInventory struct {
	gorm.Model
	OffCode          string
	ProductName      string
	Description      string
	Favourite        bool
	UserID           uint
	FoodDiary        []FoodDiary
	FoodInventoryImg []FoodInventoryImg

	// Important values to save so we're not always querying OFF
	Calories           float32
	FatTotal           float32
	FatSaturated       float32
	FatPolyunsaturated float32
	FatMonounsaturated float32
	FatTrans           float32
	FatCholesterol     float32
	Sodium             float32
	Potassium          float32
	Carbs              float32
	Fibers             float32
	Sugars             float32
	Proteins           float32
}

func FindManyFoodInventory

func FindManyFoodInventory(UserID uint) ([]FoodInventory, error)

func FindOneFoodInventory

func FindOneFoodInventory(id string) (FoodInventory, error)

type FoodInventoryImg

type FoodInventoryImg struct {
	gorm.Model
	UploadID        uint
	FoodInventoryID uint
	Upload          Upload
}

type MealType

type MealType struct {
	ID          string
	Name        string
	FoodDiaries []FoodDiary
}

type Measurement

type Measurement struct {
	gorm.Model `binding:"-"`
	Type       string    `json:"type" binding:"required"`
	Date       time.Time `json:"date" binding:"required"`
	Value      float32   `gorm:"type:FLOAT" json:"value,string" binding:"required"`
	UserID     uint      `binding:"-"`
}

func FindManyMeasurement

func FindManyMeasurement(UserID uint) ([]Measurement, error)

func FindOneMeasurement

func FindOneMeasurement(UserID string) (Measurement, error)

type QuantityUnit

type QuantityUnit struct {
	ID          uint
	Name        string
	FoodDiaries []FoodDiary
}

type Upload

type Upload struct {
	gorm.Model
	Title       string
	Caption     string
	Size        string
	RelativeDir string
	Filename    string
	UserID      uint
}

type User

type User struct {
	gorm.Model
	Username      string
	Password      string
	IsAdmin       bool
	UserSettingID uint
	UserSetting   UserSetting
	FoodDiaries   []FoodDiary
	FoodInventory []FoodInventory
	Measurement   []Measurement
	Upload        []Upload
}

func FindOneUser

func FindOneUser(condition interface{}) (User, error)

FindOneUser search in the users table for a user.

func (*User) CheckPassword

func (u *User) CheckPassword(password string) error

type UserSetting

type UserSetting struct {
	gorm.Model
	Country       string // Used for searching in OpenFoodFacts
	Timezone      string
	Avatar        string
	Language      string
	Theme         string
	FullName      string
	Email         string
	Birthday      time.Time
	UseMetric     bool
	Sex           string
	Height        float32
	BodyFat       string
	ActivityLevel string
	UserID        uint
}

func FindOneSetting

func FindOneSetting(UserID int) (UserSetting, error)

FindOneUser search in the users table for a user.

Jump to

Keyboard shortcuts

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