models

package
v0.0.0-...-a494c4b Latest Latest
Warning

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

Go to latest
Published: Jan 26, 2021 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Admin

type Admin struct {
	BaseModelSoftDelete
	FullName    string  `gorm:"not null;"`
	Email       string  `gorm:"not null;unique"`
	Password    string  `gorm:"not null;"`
	Phone       *string `gorm:"unique"`
	Role        string  `gorm:"not null;"`
	CreatedByID *string
	CreatedBy   *Admin
}

Admin defines a administrators who are to manage the app

func (*Admin) BeforeDelete

func (admin *Admin) BeforeDelete(tx *gorm.DB) (err error)

BeforeDelete hook is called before the data is delete so that we dont delete super admin

func (*Admin) BeforeSave

func (admin *Admin) BeforeSave(tx *gorm.DB) (err error)

BeforeSave hook is called before the data is persisted to db

type BaseModel

type BaseModel struct {
	// ID should use uuid_generate_v4() for the pk's
	ID        uuid.UUID `gorm:"primary_key;type:uuid;default:uuid_generate_v4()"`
	CreatedAt time.Time `gorm:"index;not null;default:CURRENT_TIMESTAMP"`
	UpdatedAt time.Time `gorm:"index;not null;default:CURRENT_TIMESTAMP"`
}

BaseModel defines the common columns that all db structs should hold, usually db structs based on this have no soft delete

type BaseModelSoftDelete

type BaseModelSoftDelete struct {
	BaseModel
	DeletedAt gorm.DeletedAt
}

BaseModelSoftDelete defines the common columns that all db structs should hold, usually. This struct also defines the fields for GORM triggers to detect the entity should soft delete

type Customer

type Customer struct {
	BaseModelSoftDelete
	LastName   string `gorm:"not null;"`
	OtherNames *string
	Email      *string `gorm:"unique"`
	Phone      string  `gorm:"not null;unique"`
}

Customer defines a customer who requests for a ride hail service

func (*Customer) BeforeSave

func (customer *Customer) BeforeSave(tx *gorm.DB) (err error)

BeforeSave hook is called before the data is persisted to db

type Rider

type Rider struct {
	BaseModelSoftDelete
	LastName     string `gorm:"not null;"`
	OtherNames   string `gorm:"not null;"`
	Email        string `gorm:"not null;unique"`
	Phone        string `gorm:"not null;unique"`
	Password     string `gorm:"not null;"`
	AuthorisedAt *time.Time
	AuthorisedBy *Admin `gorm:"foreignKey:ID"`
	ProfilePhoto string `gorm:"not null;"`
	LicenseBack  string `gorm:"not null;"`
	LicenseFront string `gorm:"not null;"`
	Bike         string `gorm:"not null;"`
}

Rider defines a riders who are to accept trips from customers

func (*Rider) BeforeSave

func (rider *Rider) BeforeSave(tx *gorm.DB) (err error)

BeforeSave hook is called before the data is persisted to db

Jump to

Keyboard shortcuts

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