models

package
v0.0.0-...-4061f55 Latest Latest
Warning

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

Go to latest
Published: Jun 22, 2019 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// Tables of SQL entities.
	Tables = []interface{}{
		new(User),
		new(Role),
		new(Team),
		new(Absence), new(Reason),
	}
	// FKeys are foreign keys.
	FKeys = []database.FKey{
		database.FKey{
			Model: &User{},
			Args:  [...]string{"role", "roles(name)", "SET NULL", "NO ACTION"},
		},
		database.FKey{
			Model: &Absence{},
			Args:  [...]string{"user_id", "users(id)", "CASCADE", "NO ACTION"},
		},
		database.FKey{
			Model: &Absence{},
			Args:  [...]string{"reason_id", "reasons(id)", "CASCADE", "NO ACTION"},
		},
	}
)

Functions

This section is empty.

Types

type Absence

type Absence struct {
	Model
	UserID   uint      `json:"user"`
	ReasonID uint      `json:"reason"`
	From     time.Time `json:"from"`
	To       time.Time `json:"to"`
}

func NewAbsence

func NewAbsence(data []byte) (*Absence, error)

func (*Absence) Validate

func (a *Absence) Validate() error

type Model

type Model struct {
	ID uint `gorm:"primary_key" json:"id"`
}

Model is the base model for all data models.

type Reason

type Reason struct {
	Model
	Label      string `json:"label" gorm:"not null" validate:"min=1,max=25"`
	Deductable bool   `json:"deductable"`
}

func NewReason

func NewReason(data []byte) (*Reason, error)

func (*Reason) Validate

func (r *Reason) Validate() error

type Role

type Role struct {
	Model
	Name string `gorm:"not null;unique" validate:"min=3,max=25" json:"name"`
}

Role data model.

func NewRole

func NewRole(data []byte) (*Role, error)

NewRole creates a new role data model instance.

func (*Role) Validate

func (r *Role) Validate() error

Validate a role.

type Team

type Team struct {
	Model
	Name  string `json:"name" gorm:"not null;unique" validate:"min=3,max=25"`
	Size  uint   `json:"size" gorm:"-"`
	Users []User `json:"-"`
}

func NewTeam

func NewTeam(data []byte) (*Team, error)

func (*Team) Validate

func (t *Team) Validate() error

type User

type User struct {
	Model
	Email     string  `json:"email" gorm:"not null;unique" validate:"email"`
	Password  string  `json:"-" gorm:"not null"`
	Role      *string `json:"role"`
	Firstname *string `json:"firstname" validate:"min=1,max=25"`
	Lastname  *string `json:"lastname" validate:"min=1,max=25"`
	TeamID    *uint   `json:"team"`
}

func NewUser

func NewUser(data []byte) (*User, error)

func (*User) BeforeSave

func (o *User) BeforeSave() error

BeforeSave runs before insert or update.

func (*User) Validate

func (o *User) Validate() error

Jump to

Keyboard shortcuts

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