models

package
v0.0.0-...-9dae437 Latest Latest
Warning

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

Go to latest
Published: Aug 10, 2021 License: BSD-3-Clause Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FilterEnd

func FilterEnd(end time.Time) func(*gorm.DB)

FilterEnd is used with ListShifts to filter Shift results that have end times that fall on or after the specified filtered time. If end is specified as a time.Time zero value, it is ignored.

func FilterStart

func FilterStart(start time.Time) func(*gorm.DB)

FilterStart is used with ListShifts to filter Shift results that have start times that fall on or before the specified filtered time. If start is specified as a time.Time zero value, it is ignored.

func FilterUserID

func FilterUserID(uid string) func(*gorm.DB)

FilterUserID is used with ListShifts to filter the query to return results matching the specific User.ID If uid is not an empty string, results will be filtered by that User.ID

func WithLimit

func WithLimit(limit int) func(*gorm.DB)

WithLimit is used with ListShifts to limit the number of results returned by the query. If limit specified is less than or equal to 0, result will not be limited

Types

type Shift

type Shift struct {
	ID        string    `gorm:"primaryKey" json:"id"`
	Start     time.Time `gorm:"not null" json:"start"`
	End       time.Time `gorm:"not null" json:"end"`
	UserID    string    `gorm:"not null" json:"user_id"`
	CreatedAt time.Time `json:"created_at"`
	UpdatedAt time.Time `json:"updated_at"`
}

Shift struct represents a timespan of a work shift object with a Unique ID, Start and End times, and a UserID which the shift belongs to.

func FindShiftByID

func FindShiftByID(db *gorm.DB, sid string) (*Shift, error)

FindShiftByID attempts to return a row from the Shifts table with the matching ID

func ListShifts

func ListShifts(db *gorm.DB, opts ...ShiftFilterOption) ([]*Shift, error)

ListShifts attempts to return rows from the Shifts table with the specified limits and filters ordered by start time Provide ShiftFilterOption parameters to modify the query with additional filters.

func (*Shift) BeforeCreate

func (s *Shift) BeforeCreate(_ *gorm.DB) error

BeforeCreate hooks GORM and prepares a new object for creation

func (*Shift) BeforeSave

func (s *Shift) BeforeSave(db *gorm.DB) error

BeforeSave hooks GORM to run necessary checks before saving the object

func (*Shift) Create

func (s *Shift) Create(db *gorm.DB) error

Create attempts to create the Shift object in the database

func (*Shift) Delete

func (s *Shift) Delete(db *gorm.DB) error

Delete will attempt to delete the Shift object from the database

func (*Shift) Update

func (s *Shift) Update(db *gorm.DB) error

Update will attempt to update the current Shift object in the database

func (*Shift) Validate

func (s *Shift) Validate() error

Validate checks to ensure all fields of the object are present and valid

type ShiftFilterOption

type ShiftFilterOption func(*gorm.DB)

type User

type User struct {
	ID        string    `gorm:"primaryKey" json:"id"`
	Name      string    `gorm:"size:30;not null;unique'" json:"name"`        //login name
	Password  string    `gorm:"size:100;not null" json:"password,omitempty"` //bcrypt hash
	Role      string    `gorm:"size:10;not null" json:"role"`                //user role: user, admin
	CreatedAt time.Time `json:"created_at"`
	UpdatedAt time.Time `json:"updated_at"`
}

User struct represents a user with a unique ID, Name, Password, and Role

func FindUserByID

func FindUserByID(db *gorm.DB, uid string) (*User, error)

FindUserByID attempts to return a row from the Users table with the matching User.ID

func FindUserByName

func FindUserByName(db *gorm.DB, name string) (*User, error)

FindUserByName attempts to return a row from the Users table with the matching User.Name

func ListUsers

func ListUsers(db *gorm.DB, limit int) ([]*User, error)

ListUsers attempts to return rows from the Users table with the specified limit If limit specified is less than or equal to 0, result will not be limited.

func (*User) AfterDelete

func (u *User) AfterDelete(db *gorm.DB) error

AfterDelete hooks GORM to remove the associated Shift rows for ths user when it is deleted

func (*User) Create

func (u *User) Create(db *gorm.DB) error

Create attempts to create the User object in the database

func (*User) Delete

func (u *User) Delete(db *gorm.DB) error

Delete will attempt to delete the User object from the database

func (*User) Prepare

func (u *User) Prepare() error

Prepare prepares a new object for update by escaping the name field and hashing the password field before it is written

func (*User) Update

func (u *User) Update(db *gorm.DB) error

Update will attempt to update the current User object in the database

func (*User) Validate

func (u *User) Validate() error

Validate checks to ensure all fields of the object are present and valid

Jump to

Keyboard shortcuts

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