Skip to content

Commit

Permalink
Added GET /locations to get a unique list of locations
Browse files Browse the repository at this point in the history
  • Loading branch information
schollz committed Dec 24, 2016
1 parent 2e9cbb1 commit a2d6eca
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
25 changes: 25 additions & 0 deletions api.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,28 @@ type UserPositionJSON struct {
Rf map[string]float64 `json:"rf"`
}

func getLocationList(c *gin.Context) {
c.Writer.Header().Set("Content-Type", "application/json")
c.Writer.Header().Set("Access-Control-Allow-Origin", "*")
c.Writer.Header().Set("Access-Control-Max-Age", "86400")
c.Writer.Header().Set("Access-Control-Allow-Methods", "GET")
c.Writer.Header().Set("Access-Control-Allow-Headers", "Content-Type, Content-Length, Accept-Encoding, X-CSRF-Token, Authorization, X-Max")
c.Writer.Header().Set("Access-Control-Allow-Credentials", "true")

group := strings.ToLower(c.DefaultQuery("group", "noneasdf"))
if group == "noneasdf" {
c.JSON(http.StatusOK, gin.H{"message": "You need to speciy group", "success": false})
return
}
if !groupExists(group) {
c.JSON(http.StatusOK, gin.H{"message": "You should insert a fingerprint first, see documentation", "success": false})
return
}
ps, _ := openParameters(group)

c.JSON(http.StatusOK, gin.H{"message": fmt.Sprintf("Found %d unique locations in group %s", len(ps.UniqueLocs), group), "locations": ps.UniqueLocs, "success": true})
}

func apiGetLastFingerprint(c *gin.Context) {
group := c.DefaultQuery("group", "noneasdf")
user := c.DefaultQuery("user", "noneasdf")
Expand Down Expand Up @@ -290,6 +312,7 @@ func userLocations(c *gin.Context) {
c.JSON(http.StatusOK, gin.H{"success": false, "message": "Error parsing request"})
}
}

func getUserLocations(c *gin.Context) {
c.Writer.Header().Set("Content-Type", "application/json")
c.Writer.Header().Set("Access-Control-Allow-Origin", "*")
Expand Down Expand Up @@ -438,6 +461,8 @@ func putMixinOverride(c *gin.Context) {
func putCutoffOverride(c *gin.Context) {
group := strings.ToLower(c.DefaultQuery("group", "noneasdf"))
newCutoff := c.DefaultQuery("cutoff", "none")
Debug.Println(group)
Debug.Println(newCutoff)
if group != "noneasdf" {
newCutoffFloat, err := strconv.ParseFloat(newCutoff, 64)
if err == nil {
Expand Down
1 change: 1 addition & 0 deletions server.go
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,7 @@ cp svm-train /usr/local/bin/`)

// Routes for API access (api.go)
r.GET("/location", getUserLocations)
r.GET("/locations", getLocationList)
r.GET("/editname", editName)
r.GET("/editusername", editUserName)
r.GET("/editnetworkname", editNetworkName)
Expand Down

0 comments on commit a2d6eca

Please sign in to comment.