Skip to content
This repository was archived by the owner on Apr 30, 2023. It is now read-only.

Commit 6b02239

Browse files
intermediate
1 parent 6e6702e commit 6b02239

5 files changed

Lines changed: 40 additions & 0 deletions

File tree

app/controllers/locations.go

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,25 @@ func (c Locations) List() revel.Result {
2121

2222
return c.RenderJSON(location)
2323
}
24+
25+
type MyData struct {
26+
Device string
27+
Longitude string
28+
Latitude string
29+
}
30+
31+
func (c Locations) Post() revel.Result {
32+
data := MyData{}
33+
c.Params.BindJSON(&data)
34+
35+
return c.RenderJSON(data)
36+
37+
location := []models.Location{}
38+
39+
result := DB.Find(&location)
40+
if result.Error != nil {
41+
return c.RenderError(errors.New("Record Not Found"))
42+
}
43+
44+
return c.RenderJSON(location)
45+
}

app/models/location.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ import "time"
55
type Location struct {
66
ID uint `gorm:"primary_key"`
77
Updated time.Time
8+
Device string
9+
Color string
810
Longitude int
911
Latitude int
1012
}

app/routes/routes.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,13 @@ func (_ tLocations) List(
2929
return revel.MainRouter.Reverse("Locations.List", args).URL
3030
}
3131

32+
func (_ tLocations) Post(
33+
) string {
34+
args := make(map[string]string)
35+
36+
return revel.MainRouter.Reverse("Locations.Post", args).URL
37+
}
38+
3239

3340
type tLocationsArchive struct {}
3441
var LocationsArchive tLocationsArchive

app/tmp/run/run.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,13 @@ func Register() {
4949
RenderArgNames: map[int][]string{
5050
},
5151
},
52+
&revel.MethodType{
53+
Name: "Post",
54+
Args: []*revel.MethodArg{
55+
},
56+
RenderArgNames: map[int][]string{
57+
},
58+
},
5259

5360
})
5461

conf/routes

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ module:testrunner
99

1010
GET / App.Index
1111
GET /v3/locations Locations.List
12+
POST /v3/locations Locations.Post
13+
1214
GET /v3/locationsarchive LocationsArchive.List
1315

1416
GET /v3/twitter Twitter.List

0 commit comments

Comments
 (0)