model

package
v0.0.0-...-d9fbcb9 Latest Latest
Warning

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

Go to latest
Published: Nov 16, 2019 License: GPL-3.0 Imports: 8 Imported by: 0

Documentation

Overview

This file contain functions for operating a database

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AllAppointments

func AllAppointments(from, to time.Time, userid uint, appointments *[]Appointment) (err error)

func Close

func Close() error

close the database

func Connect

func Connect()

connect to the database

func GetAppointments

func GetAppointments(UserID uint, a *[]Appointment)

func GetPrice

func GetPrice(option WashOption) string

func Migrate

func Migrate()

migrate tables without delete the database

func Reset

func Reset()

drop and create all of the tables, reset the db

func Seed

func Seed()

reset and seed all of the tables

Types

type Appointment

type Appointment struct {
	IgnoreTimeModel
	UserID uint `json:",omitempty"`
	//DateTime string    `gorm:"-"`
	//Time     time.Time `json:"-" gorm:"unique;not null"`
	Time    time.Time  `binding:"required" gorm:"unique" json:",omitempty"`
	Option  WashOption `json:",omitempty" binding:"min=1,max=3"`
	Comment string     `json:",omitempty"`
	Car
	User *User `json:",omitempty" binding:"isdefault"`
}

func (*Appointment) Create

func (a *Appointment) Create(UserID uint) error

func (*Appointment) Delete

func (a *Appointment) Delete(UserID uint) (NotFound bool)

query and delete

func (*Appointment) MarshallTime

func (a *Appointment) MarshallTime() (err error)

marshall time and check valid valid hour should be [8, 12), [13, 17) deprecated

func (*Appointment) UnmarshallTime

func (a *Appointment) UnmarshallTime()

deprecated

func (*Appointment) Update

func (a *Appointment) Update(UserID uint)

type Car

type Car struct {
	Car     CarType `json:"-"`
	CarType string  `gorm:"-" json:",omitempty"`
}

func (*Car) EnumToStr

func (c *Car) EnumToStr()

func (*Car) StrToEnum

func (c *Car) StrToEnum()

type CarType

type CarType uint
const (
	UnknownCarType CarType = iota
	Hatchback
	Sedan
	SUV
)

type IgnoreTimeModel

type IgnoreTimeModel struct {
	ID        uint       `gorm:"primary_key"`
	CreatedAt time.Time  `json:"-"`
	UpdatedAt time.Time  `json:"-"`
	DeletedAt *time.Time `json:"-";sql:"index"`
}

basic database model that ignore time information when perform json marshalling

type User

type User struct {
	IgnoreTimeModel
	Password string `json:",omitempty"`

	Admin bool `binding:"isdefault" gorm:"default:false" json:",omitempty"`

	FirstName string `binding:"required"`
	LastName  string `binding:"required"`
	Email     string `gorm:"unique;not null" binding:"required,email" json:",omitempty"`

	Mobile  string `json:",omitempty"`
	Home    string `json:",omitempty"`
	Work    string `json:",omitempty"`
	Address string `json:",omitempty"`

	CarInfo string `json:",omitempty"`
	Car
	// contains filtered or unexported fields
}

func (*User) AfterFind

func (u *User) AfterFind() (err error)

after find, mask password

func (*User) AfterSave

func (u *User) AfterSave(scope *gorm.Scope) (err error)

after save, mask password

func (*User) Auth

func (u *User) Auth(pwd string) bool

auth users

func (*User) BeforeCreate

func (u *User) BeforeCreate() (err error)

before create, hashing password

func (*User) Create

func (u *User) Create() error

func (*User) Find

func (u *User) Find(email string) bool

find user given email, return true if found

func (*User) Retrieve

func (u *User) Retrieve(id uint)

func (*User) Update

func (u *User) Update()

must update through this function, fields that cannot be updated will be omitted

type WashOption

type WashOption uint
const (
	WashOptionNone WashOption = iota
	WashOut
	WashInAndOut
	WashDelux
)

Jump to

Keyboard shortcuts

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