models

package
v0.0.0-...-fa930de Latest Latest
Warning

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

Go to latest
Published: Oct 20, 2023 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CreateURL

func CreateURL(url *URL)

CreateURL is a method used to create a new URL in the database It takes in a pointer to a URL struct as a parameter and returns nothing

func UpdateURL

func UpdateURL(url *URL) error

UpdateURL is a method used to update a URL in the database

Types

type Book

type Book struct {
	gorm.Model         // gorm.Model provides the fields ID, CreatedAt, UpdatedAt, and DeletedAt
	Title       string `gorm:"size:191;not null;unique" json:"title"`
	Author      string `gorm:"size:191;not null" json:"author"`
	Publisher   string `gorm:"size:191;not null" json:"publisher"`
	Description string `gorm:"size:191;not null" json:"description"`
}

Book is a struct that represents a book in the database

type File

type File struct {
	gorm.Model        // GORM model that contains the ID, CreatedAt, UpdatedAt, and DeletedAt fields
	Filename   string `gorm:"not null"`        // Filename of the file. Cannot be null.
	UUID       string `gorm:"unique;not null"` // UUID of the file. Must be unique and cannot be null.
}

File is a struct that represents a file in the database

type URL

type URL struct {
	gorm.Model
	LongURL      string     `json:"long_url" gorm:"unique"`
	ShortURL     string     `json:"short_url" gorm:"unique"`
	AccessCount  uint       `json:"access_count"`
	LastAccessed *time.Time `json:"last_accessed"`
	AccessPlace  string     `json:"access_place"`
}

URL is a struct that stores the information for a URL

func GetURLByShortURL

func GetURLByShortURL(shortURL string) (URL, error)

GetURLByShortURL is a method used to get a URL from the database by its short URL It takes a string as a parameter and returns a URL struct and an error

func (*URL) GenerateShortURL

func (u *URL) GenerateShortURL()

GenerateShortURL is a method used to generate a random short URL It takes no parameters and returns nothing

type User

type User struct {
	gorm.Model
	ID       uint   `gorm:"primaryKey"`
	Name     string `json:"name" binding:"required"`
	Email    string `json:"email" binding:"required,email" gorm:"unique"`
	Password string `json:"password" binding:"required"`
}

User defines the user in db User struct is used to store user information in the database

func (*User) CheckPassword

func (user *User) CheckPassword(providedPassword string) error

CheckPassword checks user password CheckPassword takes a string as a parameter and compares it to the user's encrypted password It returns an error if there is an issue comparing the passwords

func (*User) CreateUserRecord

func (user *User) CreateUserRecord() error

CreateUserRecord creates a user record in the database CreateUserRecord takes a pointer to a User struct and creates a user record in the database It returns an error if there is an issue creating the user record

func (*User) HashPassword

func (user *User) HashPassword(password string) error

HashPassword encrypts user password HashPassword takes a string as a parameter and encrypts it using bcrypt It returns an error if there is an issue encrypting the password

Jump to

Keyboard shortcuts

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