Unset Point & Error Handling

This commit is contained in:
Supan Adit Pratama 2019-12-15 14:50:05 +07:00
parent 3233509f56
commit e02e1513fa
2 changed files with 35 additions and 9 deletions

42
main.go
View File

@ -6,8 +6,8 @@ import (
"github.com/gin-gonic/gin"
"github.com/go-redis/redis"
"github.com/rs/xid"
"github.com/supanadit/geosmartsystem/model"
"github.com/supanadit/geosmartsystem/model/tile38"
"github.com/supanadit/geo-smart-system/model"
"github.com/supanadit/geo-smart-system/model/tile38"
"net/http"
)
@ -17,18 +17,44 @@ func main() {
})
r := gin.Default()
r.Use(cors.Default())
r.GET("/unique/id", func(c *gin.Context) {
r.GET("/id/get/unique", func(c *gin.Context) {
id := xid.New()
c.JSON(200, gin.H{"id": id.String()})
})
r.POST("/set/point", func(c *gin.Context) {
r.POST("/point/set", func(c *gin.Context) {
var location model.Location
_ = c.BindJSON(&location)
c.Writer.Header().Set("Content-Type", "application/json")
err := c.BindJSON(&location)
client.Do("SET", location.Type, location.Id, "POINT", location.Lat, location.Lng)
c.JSON(200, gin.H{"status": "ok"})
var status map[string]interface{}
if err != nil {
status = gin.H{"status": "Unknown Error"}
} else {
status = gin.H{"status": "Ok"}
}
c.Writer.Header().Set("Content-Type", "application/json")
c.JSON(http.StatusOK, status)
})
r.GET("/stream", func(c *gin.Context) {
r.POST("/point/unset", func(c *gin.Context) {
var location model.Location
err := c.BindJSON(&location)
client.Do("DEL", location.Type, location.Id)
var status map[string]interface{}
if err != nil {
status = gin.H{"status": "Unknown Error"}
} else {
status = gin.H{"status": "Ok"}
}
c.Writer.Header().Set("Content-Type", "application/json")
c.JSON(http.StatusOK, status)
})
r.GET("/point/get", func(c *gin.Context) {
t := c.DefaultQuery("type", "user")
data, _ := tile38.FromScan(client, t)
c.JSON(http.StatusOK, data)
})
r.GET("/point/get/stream", func(c *gin.Context) {
w := c.Writer
t := c.DefaultQuery("type", "user")
r := c.DefaultQuery("request", "")

View File

@ -4,7 +4,7 @@ import (
"encoding/json"
"fmt"
"github.com/go-redis/redis"
"github.com/supanadit/geosmartsystem/model"
"github.com/supanadit/geo-smart-system/model"
"strconv"
)