This repository has been archived by the owner on Dec 27, 2020. It is now read-only.
/
create.go
59 lines (50 loc) · 1.95 KB
/
create.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
package request
import (
"CitySourcedAPI/data"
"CitySourcedAPI/logs"
"CitySourcedAPI/response"
"time"
)
// ==============================================================================================================================
// GetReportsByLatLng
// ==============================================================================================================================
type CreateThreeOneOne struct {
Request
Processor
data.BaseReport
KeyValuePairs []KeyValuePair `xml:"KeyValuePairs>KeyValuePair"`
}
type KeyValuePair struct {
Value string `xml:",chardata"`
Key string `xml:"Key,attr"`
}
func (st *CreateThreeOneOne) validate() error {
return st.BaseReport.Validate()
}
func (st *CreateThreeOneOne) Validate(start time.Time) string {
var v validate
st.start = start
st.LatitudeV = v.float("Latitude", st.Latitude)
st.LongitudeV = v.float("Longitude", st.Longitude)
st.AuthorIsAnonymousV = v.bool("AuthorIsAnonymous", st.AuthorIsAnonymous)
return v.errmsg
}
func (st *CreateThreeOneOne) Run() (string, error) {
reportid, authorid, _ := data.Append(st.BaseReport, false)
return response.NewResponseReport("New report created OK", st.start, reportid, authorid)
}
func (s CreateThreeOneOne) String() string {
ls := new(logs.LogString)
ls.AddS("CreateThreeOneOne_Type\n")
ls.AddS(s.Request.String())
ls.AddF("DateCreated \"%v\"\n", s.DateCreated)
ls.AddF("Device - type %s model: %s Id: %s\n", s.DeviceType, s.DeviceModel, s.DeviceID)
ls.AddF("Request - type: %q id: %q\n", s.RequestType, s.RequestTypeID)
ls.AddF("Location - lat: %v lon: %v directionality: %q\n", s.Latitude, s.Longitude, s.Directionality)
ls.AddF("Description: %q\n", s.Description)
ls.AddF("Author(anon: %t) %s %s Email: %s Tel: %s\n", s.AuthorIsAnonymous, s.AuthorNameFirst, s.AuthorNameLast, s.AuthorEmail, s.AuthorTelephone)
for _, v := range s.KeyValuePairs {
ls.AddF(" %s: %s\n", v.Key, v.Value)
}
return ls.Box(90)
}