Documentation ¶
Index ¶
- Constants
- Variables
- type Action
- type ActionData
- type ActionInput
- type Alert
- type AlertData
- type AlertInput
- type Bitmask
- type Calendar
- type Collection
- type Entity
- type JSON
- type Schedule
- type SliceString
- type Station
- type StationData
- type StationInput
- type StopTime
- type StopTimeOutput
- type Trip
- type User
- type UserData
- type UserInput
- type UserToken
Constants ¶
const ( ActionTypeTelegram = "telegram" ActionTypeMessenger = "messenger" )
List of actions available
const ( Sunday = 1 << iota Saturday Friday Thursday Wednesday Tuesday Monday )
Variables ¶
var AllActionTypes = []string{ActionTypeTelegram, ActionTypeMessenger}
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 ¶
GenerateHateoas content
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 ¶
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) ToggleFlag ¶
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 ¶
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 ¶
JSON is alias of map[string]string
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) UnmarshalJSON ¶
UnmarshalJSON convert JSON send by client to Schedule struct
type SliceString ¶
type SliceString []string
SliceString alias for []string
func (*SliceString) Scan ¶
func (s *SliceString) Scan(value interface{}) error
Scan retrieve value from database
type Station ¶
type Station struct { Entity StationData rest.Hateoas }
Station of the SNCF
func (*Station) GenerateHateoas ¶
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 ¶
GenerateHateoas content
func (StopTime) MarshalJSON ¶
MarshalJSON StopTime to StopTimeOutput
type StopTimeOutput ¶
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 ¶
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 ¶
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