models

package
v2.1.1+incompatible Latest Latest
Warning

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

Go to latest
Published: Dec 9, 2017 License: GPL-3.0 Imports: 12 Imported by: 3

Documentation

Index

Constants

View Source
const (
	ActionTypeTelegram  = "telegram"
	ActionTypeMessenger = "messenger"
)

List of actions available

View Source
const (
	Sunday = 1 << iota
	Saturday
	Friday
	Thursday
	Wednesday
	Tuesday
	Monday
)

Variables

AllActionTypes regroup all types available, used for validation

Functions

This section is empty.

Types

type Action

type Action struct {
	Entity
	ActionData
	User *User  `gorm:"ForeignKey:UserID" json:"-"`
	UUID string `gorm:"column:uuid"       json:"-"` // Use for identify user without UserID
	rest.Hateoas
}

Action to perform when alert is triggered

func (*Action) GenerateHateoas

func (a *Action) GenerateHateoas(ctx *aah.Context) error

GenerateHateoas content

func (*Action) SetUUID

func (a *Action) SetUUID() string

SetUUID for ensure only one action is set per type and user

type ActionData

type ActionData struct {
	Type *string `gorm:"column:type" json:"type" validate:"required,action_type"`
	Data *JSON   `gorm:"column:data" json:"data" validate:"required"`
}

ActionData send by client

type ActionInput

type ActionInput ActionData

ActionInput send by client

func (*ActionInput) TableName

func (i *ActionInput) TableName() string

TableName for ActionInput, used by unique validation on ActionInput

func (*ActionInput) ToEntity

func (i *ActionInput) ToEntity() *Action

ToEntity transform ActionInput to Action

type Alert

type Alert struct {
	Entity
	AlertData
	CodeTrain string   `gorm:"column:code_train"    json:"-"`
	StationID uint     `gorm:"column:station_id"    json:"-"`
	Station   *Station `gorm:"ForeignKey:StationID" json:"-"`
	Action    *Action  `gorm:"ForeignKey:ActionID"  json:"-"`
	rest.Hateoas
}

Alert is a watcher for one stop (if issue is detected, action is triggered)

func (*Alert) GenerateHateoas

func (a *Alert) GenerateHateoas(ctx *aah.Context) error

GenerateHateoas content

type AlertData

type AlertData struct {
	ActionID *uint `gorm:"column:action_id" json:"action_id" validate:"foreign_key=action"`
}

AlertData send by client

type AlertInput

type AlertInput AlertData

AlertInput send by client

func (*AlertInput) ToEntity

func (i *AlertInput) ToEntity() *Alert

ToEntity transform AlertInput to Alert

type Bitmask

type Bitmask uint8

Bitmask is binary representation

func (*Bitmask) AddFlag

func (b *Bitmask) AddFlag(flag Bitmask)

AddFlag to the binary representation

func (*Bitmask) ClearFlag

func (b *Bitmask) ClearFlag(flag Bitmask)

ClearFlag remove flag

func (Bitmask) HasFlag

func (b Bitmask) HasFlag(flag Bitmask) bool

HasFlag return true if mask has specific flag set

func (*Bitmask) ToggleFlag

func (b *Bitmask) ToggleFlag(flag Bitmask)

ToggleFlag inverse state of the flag

type Calendar

type Calendar struct {
	Entity
	Start int     `gorm:"column:start" json:"start"`
	End   int     `gorm:"column:end"   json:"end"`
	Days  Bitmask `gorm:"column:days"  json:"days"`
	rest.Hateoas
}

Calendar of the trips

func (*Calendar) GenerateHateoas

func (c *Calendar) GenerateHateoas(ctx *aah.Context) error

GenerateHateoas content

type Collection

type Collection struct {
	Page  int `json:"page"`
	Limit int `json:"limit"`
	Pages int `json:"pages"`
	Total int `json:"total"`
	rest.Hateoas
}

Collection of one entity

func (*Collection) GenerateHateoas

func (c *Collection) GenerateHateoas(ctx *aah.Context) error

GenerateHateoas content

type Entity

type Entity struct {
	ID        uint       `json:"id" gorm:"primary_key"`
	CreatedAt time.Time  `json:"-"`
	UpdatedAt time.Time  `json:"-"`
	DeletedAt *time.Time `json:"deleted_at,omitempty" sql:"index"`
}

Entity regroup all necessary field for database

type JSON

type JSON map[string]string

JSON is alias of map[string]string

func (*JSON) Get

func (j *JSON) Get(field string, fallback string) string

Get return value in a given key, or fallback if key not exist

func (*JSON) Scan

func (j *JSON) Scan(value interface{}) error

Scan retrieve value from database

func (JSON) Value

func (j JSON) Value() (driver.Value, error)

Value transform Json to friendly value for database

type Schedule

type Schedule struct {
	Hour   uint `validate:"min=0,max=23"`
	Minute uint `validate:"min=0,max=59"`
	Valid  bool `validate:"true"`
}

Schedule is struct for time (not datetime)

func (*Schedule) Scan

func (s *Schedule) Scan(value interface{}) error

Scan retrieve value from database

func (Schedule) String

func (s Schedule) String() string

String return representation of Schedule in string

func (*Schedule) UnmarshalJSON

func (s *Schedule) UnmarshalJSON(data []byte) error

UnmarshalJSON convert JSON send by client to Schedule struct

func (Schedule) Value

func (s Schedule) Value() (driver.Value, error)

Value convert Schedule to friendly database value

type SliceString

type SliceString []string

SliceString alias for []string

func (*SliceString) Scan

func (s *SliceString) Scan(value interface{}) error

Scan retrieve value from database

func (SliceString) Value

func (s SliceString) Value() (driver.Value, error)

Value return value can be store in database

type Station

type Station struct {
	Entity
	StationData
	rest.Hateoas
}

Station of the SNCF

func (*Station) GenerateHateoas

func (s *Station) GenerateHateoas(ctx *aah.Context) error

GenerateHateoas content

type StationData

type StationData struct {
	Name     *string `gorm:"column:name"        json:"name"        validate:"required,min=2,max=255"`
	UIC      *string `gorm:"column:UIC"         json:"uic"         validate:"required,len=8"`
	IsEnable *bool   `gorm:"column:is_enable"   json:"is_enable"   validate:"required"`
}

StationData is all fields can be send by the client

type StationInput

type StationInput StationData

StationInput by the client

func (*StationInput) ToEntity

func (i *StationInput) ToEntity() *Station

ToEntity transform StationInput to Station

type StopTime

type StopTime struct {
	Entity
	Time      *Schedule `gorm:"column:schedule"      json:"schedule"`
	StationID uint      `gorm:"column:station_id"    json:"station_id"`
	TripID    uint      `gorm:"column:trip_id"       json:"-"`
	Station   *Station  `gorm:"ForeignKey:StationID" json:"-"`
	Trip      *Trip     `gorm:"ForeignKey:TripID"    json:"-"`
	rest.Hateoas
}

StopTime represent one train stop at one station in given time

func (*StopTime) GenerateHateoas

func (s *StopTime) GenerateHateoas(ctx *aah.Context) error

GenerateHateoas content

func (StopTime) MarshalJSON

func (s StopTime) MarshalJSON() ([]byte, error)

MarshalJSON StopTime to StopTimeOutput

type StopTimeOutput

type StopTimeOutput struct {
	ID       uint   `json:"id"`
	Schedule string `json:"schedule"`
	rest.Hateoas
}

StopTimeOutput is json send by the API

type Trip

type Trip struct {
	Entity
	Code       string    `gorm:"column:code"           json:"code"`
	Mission    string    `gorm:"column:mission"        json:"mission"`
	CalendarID uint      `gorm:"column:calendar_id"    json:"-"`
	Calendar   *Calendar `gorm:"ForeignKey:CalendarID" json:"-"`
	rest.Hateoas
}

Trip of the SNCF

func (*Trip) GenerateHateoas

func (t *Trip) GenerateHateoas(ctx *aah.Context) error

GenerateHateoas content

type User

type User struct {
	Entity
	UserData
	EncodedPassword string      `gorm:"column:password" json:"-"`
	Roles           SliceString `gorm:"column:roles"    json:"roles"`
	rest.Hateoas
}

User of the API

func (*User) GenerateHateoas

func (u *User) GenerateHateoas(ctx *aah.Context) error

GenerateHateoas content

type UserData

type UserData struct {
	Username *string `gorm:"column:username" json:"username" validate:"required,unique=username,min=2,max=255"`
	Email    *string `gorm:"column:email"    json:"email"    validate:"required,unique=email,email,max=255"`
	Password *string `gorm:"-"               json:"password,omitempty" validate:"required,min=6,max=255"`
}

UserData regroup all values can be received by client

type UserInput

type UserInput UserData

UserInput send by client

func (*UserInput) TableName

func (i *UserInput) TableName() string

TableName for UserInput, used for 'unique' validation

func (*UserInput) ToEntity

func (i *UserInput) ToEntity() (*User, error)

ToEntity transform UserInput to User

type UserToken

type UserToken struct {
	Username string `json:"username"`
	Password string `json:"password"`
}

UserToken used for retrieve new JsonWebToken

Jump to

Keyboard shortcuts

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