models

package
v0.0.0-...-d5fe67c Latest Latest
Warning

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

Go to latest
Published: Apr 4, 2024 License: MIT, MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DB *gorm.DB

Functions

func CheckByUsername

func CheckByUsername(username string, password string) (string, error)

Try to log in the user with the username and password provided

func InitDatabase

func InitDatabase()

func VerifyPassword

func VerifyPassword(password, hashedPassword string) error

Verify the password provided in the login request with the hashed password stored in the database

Types

type ExerciseInformation

type ExerciseInformation struct {
	gorm.Model
	ActivityName      string  // Name of the activity
	Category          string  // Type of activity (e.g. Cardio, Resistance, Sports, etc.)
	Resistance        string  // The vigour for the exercise (valid values include High, Medium or Low)
	EnergyExpenditure float32 // Energy expenditure of the activity in kilocalories per unit body weight of the person
	Users             []*User `gorm:"many2many:user_exercises;"`
}

Struct to store the exercise information of the User

type HealthInformation

type HealthInformation struct {
	gorm.Model
	UserID            uint      // User to which the health information belongs
	Birthday          time.Time // Birthday of the user
	Weight            uint8     // Weight of the user in kilograms
	Height            uint8     // Height of the user in centimeters
	BMI               float32   // Body Mass Index of the user calculated from the weight and height
	ExerciseFrequency uint8     // Weekly exercise frequency of the user
}

Struct to store the health information of the User

type User

type User struct {
	gorm.Model
	Name              string                 `gorm:"not null"`        // Full Name of the user
	Username          string                 `gorm:"not null;unique"` // Username of the user used for logging in to the application
	Password          string                 `gorm:"not null"`        // Password of the user used for logging in to the application
	Email             string                 `gorm:"not null;unique"` // Email of the user, might be autofilled if user signs up using Google
	PhoneNumber       uint64                 `gorm:"not null;unique"` // Phone number of the user
	Gender            string                 `gorm:"not null"`        // Gender of the user values may include, male, female or other (BMI calculated as per male standards for other)
	HealthInformation HealthInformation      // Health information of the user
	Exercises         []*ExerciseInformation `gorm:"many2many:user_exercises;"` // Exercises performed by the user
}

Struct to store the basic information about the User One to One relation with the Health Information of the User One to Many relation with the Exercises performed by the User

func GetUserByID

func GetUserByID(uid uint) (User, error)

Find the user from the database with the provided ID

func (*User) BeforeSave

func (u *User) BeforeSave(tx *gorm.DB) error

Encrypt the password for the user before saving it to the database

func (*User) PrepareGive

func (u *User) PrepareGive()

Return the user without the password

func (*User) Save

func (u *User) Save() (*User, error)

Save the user to the database

Jump to

Keyboard shortcuts

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