/
models.go
105 lines (92 loc) · 2.43 KB
/
models.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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
package serviceguiden
import (
"strings"
)
type Content struct {
Id string `json:"id"`
Name string `json:"name"`
Organization struct {
Id string `json:"id"`
Name string `json:"name"`
} `json:"organization"`
ServiceTypes []struct {
Id string `json:"id"`
Name string `json:"name"`
Attributes []struct {
Name string `json:"name"`
Values []struct {
Name string `json:"name"`
} `json:"values"`
} `json:"attributes"`
} `json:"serviceTypes"`
Position struct {
Latitude float64 `json:"latitude"`
Longitude float64 `json:"longitude"`
} `json:"position"`
PrimaryArea string `json:"primaryArea"`
CityArea string `json:"cityArea"`
SubCityArea string `json:"subCityArea"`
SiteUrl string `json:"siteUrl"`
AccessibilityUrl string `json:"accessibilityUrl"`
Address string `json:"visitingAddress"`
PostalAddress struct {
Street string `json:"street"`
City string `json:"city"`
PostalCode string `json:"postalCode"`
} `json:"postalAddress"`
Deleted bool `json:"deleted"`
Description string `json:"description"`
DistrictOrganization string `json:"districtOrganization"`
BusinessId int64 `json:"businessId"`
}
/*
id (från service guide),
namn (name från service guide),
inriktning (name från values under attributes, serviceTypes från service guide med kommatecken mellan dem),
hemsida (siteUrl från service guide),
besoksAdress (visitingAddress från service guide),
*/
func (c Content) Inriktning() string {
str := ""
for _, st := range c.ServiceTypes {
for _, attr := range st.Attributes {
n := strings.TrimSpace(attr.Name)
if strings.EqualFold(n, "inriktning") {
if len(attr.Values) > 0 {
for _, v := range attr.Values {
str = str + v.Name + ", "
}
}
if str == "" {
return ""
}
if strings.LastIndex(str, ",") == -1 {
return str
}
return str[:strings.LastIndex(str, ",")]
}
}
}
return ""
}
func (c Content) BeachTypes() []string {
facilities := strings.Split(c.Inriktning(), ",")
if len(facilities) == 0 {
return nil
}
s := []string{}
for _, f := range facilities {
s = append(s, strings.TrimSpace(f))
}
return s
}
func (c Content) AreaServed() string {
if c.PrimaryArea != "" {
return c.PrimaryArea
} else if c.CityArea != "" {
return c.CityArea
} else if c.SubCityArea != "" {
return c.SubCityArea
}
return ""
}