model

package
v0.0.0-...-a25ac86 Latest Latest
Warning

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

Go to latest
Published: Mar 17, 2024 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func InitDB

func InitDB(dest string) *gorm.DB

Types

type File

type File struct {
	gorm.Model
	Name      string `gorm:"type:varchar(160);not null;uniqueIndex"` // "shoe1.jpg", "shoe2.jpg", ...
	Category  string `gorm:"type:varchar(100);not null"`             // "image", "downloadable", ...
	FileBlob  []byte `gorm:"type:blob;not null"`
	Type      string `gorm:"type:varchar(100);not null"` // "image/jpeg", "application/pdf", ...
	Extension string `gorm:"type:varchar(10);not null"`  // "jpg", "png", "pdf", ...
	ProductID uint   `gorm:"index;not null"`             // the product this file belongs to
}

func (*File) Create

func (model *File) Create(database *gorm.DB) error

make sure to put this behind role permissions so only admins can create files

func (*File) Delete

func (model *File) Delete(database *gorm.DB) error

make sure to put this behind role permissions so only admins can delete files

func (*File) Read

func (model *File) Read(database *gorm.DB) error

func (*File) ReadAll

func (model *File) ReadAll(database *gorm.DB) ([]File, error)

func (*File) Update

func (model *File) Update(database *gorm.DB) error

make sure to put this behind role permissions so only admins can update files

type Order

type Order struct {
	gorm.Model
	ExternalId    string      `json:"external_id" gorm:"unique;not null"` // from NOWPayments
	UserId        uint        `json:"user_id" gorm:"not null"`            // the user who made the payment
	Status        OrderStatus `json:"status" gorm:"not null"`             // waiting, confirming, confirmed, sending, partially_paid, finished, failed, expired
	ProductId     uint        `json:"product_id" gorm:"not null"`         // the product the user bought
	PriceAmount   float64     `json:"price_amount" gorm:"not null"`       // the amount the user paid (it's important to store because prices can change)
	PriceCurrency string      `json:"price_currency" gorm:"not null"`     // the currency in which we denominate the amount (e.g. usd)
	InvoiceUrl    string      `json:"invoice_url" gorm:"unique;not null"` // from NOWPayments
}

func (*Order) Create

func (model *Order) Create(database *gorm.DB) error

func (*Order) Delete

func (model *Order) Delete(database *gorm.DB) error

func (*Order) Read

func (model *Order) Read(database *gorm.DB) error

func (*Order) ReadAll

func (model *Order) ReadAll(database *gorm.DB) ([]Order, error)

func (*Order) Update

func (model *Order) Update(database *gorm.DB) error

type OrderStatus

type OrderStatus string
const (
	Waiting       OrderStatus = "waiting"
	Confirming    OrderStatus = "confirming"
	Confirmed     OrderStatus = "confirmed"
	Sending       OrderStatus = "sending"
	PartiallyPaid OrderStatus = "partially_paid"
	Finished      OrderStatus = "finished"
	Failed        OrderStatus = "failed"
	Expired       OrderStatus = "expired"
)

type Post

type Post struct {
	gorm.Model
	Title     string `gorm:"type:varchar(100);not null"`
	Content   string `gorm:"type:text;not null"`
	AuthorID  uint   `gorm:"type:integer;not null"`
	Published bool   `gorm:"type:boolean;default:false"`
}

func (*Post) Create

func (model *Post) Create(database *gorm.DB) error

func (*Post) Delete

func (model *Post) Delete(database *gorm.DB) error

func (*Post) Read

func (model *Post) Read(database *gorm.DB) error

func (*Post) ReadAll

func (model *Post) ReadAll(database *gorm.DB) ([]Post, error)

func (*Post) Update

func (model *Post) Update(database *gorm.DB) error

type Product

type Product struct {
	gorm.Model
	Name          string  `gorm:"type:varchar(160);not null;uniqueIndex"`                             // "Shoe #1", "Shoe #2", ...
	Description   string  `gorm:"type:text;not null"`                                                 // "A very nice shoe", ...
	Files         []File  `gorm:"foreignKey:ProductID;constraint:OnUpdate:CASCADE,OnDelete:CASCADE;"` // 1 to many; downloadables, ...
	Images        []File  `gorm:"foreignKey:ProductID;constraint:OnUpdate:CASCADE,OnDelete:CASCADE;"` // 1 to many; images for the product, ...
	PriceAmount   float64 `gorm:"type:decimal(10,2);not null"`                                        // 100.00
	PriceCurrency string  `gorm:"type:varchar(3);not null"`                                           // usd, eur, ...
}

func (*Product) Create

func (model *Product) Create(database *gorm.DB) error

make sure to put this behind role permissions so only admins can create plans

func (*Product) Delete

func (model *Product) Delete(database *gorm.DB) error

make sure to put this behind role permissions so only admins can delete plans

func (*Product) Read

func (model *Product) Read(database *gorm.DB) error

func (*Product) ReadAll

func (model *Product) ReadAll(database *gorm.DB) ([]Product, error)

func (*Product) Update

func (model *Product) Update(database *gorm.DB) error

make sure to put this behind role permissions so only admins can update plans

type Token

type Token struct {
	gorm.Model
	Email string `gorm:"primaryKey"`
	Value string `gorm:"primaryKey"`
}

For magic link login, but could also help with email verification, password reset if that was needed. It's meant as a way to verify that the user has access to the email of the account.

func (*Token) Create

func (model *Token) Create(database *gorm.DB) (string, error)

Note that this generates a random hashed token value. The unhashed value is returned for use in the email link.

func (*Token) Delete

func (model *Token) Delete(database *gorm.DB) error

Delete deletes a token by email and value.

func (*Token) Read

func (model *Token) Read(database *gorm.DB) error

Reads a token by email where CreatedAt is no older than 24 hours. You're meant to check the read value against another hashed value to verify the token.

type User

type User struct {
	gorm.Model
	ID    uint   `gorm:"primaryKey"`
	Email string `gorm:"unique"`
	Role  string `gorm:"type:varchar(100);not null;default:'user'"` // "user", "admin", ...
}

func (*User) Create

func (model *User) Create(database *gorm.DB) error

func (*User) Delete

func (model *User) Delete(database *gorm.DB) error

func (*User) Read

func (model *User) Read(database *gorm.DB) error

func (*User) ReadAll

func (model *User) ReadAll(database *gorm.DB) ([]User, error)

func (*User) ReadByEmail

func (model *User) ReadByEmail(database *gorm.DB) error

Jump to

Keyboard shortcuts

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