/
station.go
44 lines (37 loc) · 1.02 KB
/
station.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
package models
import (
"aahframework.org/aah.v0"
"github.com/train-cat/api-train/app/rest"
)
type (
// StationData is all fields can be send by the client
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"`
}
// Station of the SNCF
Station struct {
Entity
StationData
rest.Hateoas
}
// StationInput by the client
StationInput StationData
)
// ToEntity transform StationInput to Station
func (i *StationInput) ToEntity() *Station {
return &Station{StationData: StationData(*i)}
}
// GenerateHateoas content
func (s *Station) GenerateHateoas(ctx *aah.Context) error {
s.Links = rest.Links{
"self": rest.Link{
Href: rest.GenerateURI(ctx, "get_station", s.ID),
},
"stops": rest.Link{
Href: rest.GenerateURI(ctx, "cget_station_stops_time", s.ID),
},
}
return nil
}