mirror of
https://github.com/supanadit/geo-smart-system.git
synced 2024-11-24 09:36:22 +00:00
Delete Hook when Hook is Called once
This commit is contained in:
parent
8a8364da2c
commit
e407af393e
29
main.go
29
main.go
@ -85,26 +85,35 @@ func main() {
|
|||||||
var detection model.Detection
|
var detection model.Detection
|
||||||
err := c.BindJSON(&detection)
|
err := c.BindJSON(&detection)
|
||||||
hookID := "HOOK-" + xid.New().String()
|
hookID := "HOOK-" + xid.New().String()
|
||||||
fmt.Printf("Set HOOK with ID : %s \n", hookID)
|
hookURL := "http://192.168.99.1:" + port + "/detection/call?hook=" + hookID
|
||||||
hookURL := "http://192.168.99.1:" + port + "/detection/call"
|
|
||||||
trigger := strings.Join(detection.TriggerType, ",")
|
trigger := strings.Join(detection.TriggerType, ",")
|
||||||
client.Do("SETHOOK", hookID, hookURL, "NEARBY", detection.Type, "FENCE", "DETECT", trigger, "COMMANDS", "set", "POINT", detection.Lat, detection.Lng)
|
|
||||||
var status map[string]interface{}
|
var status map[string]interface{}
|
||||||
var httpStatus int
|
var httpStatus int
|
||||||
if err != nil {
|
if trigger == "" {
|
||||||
status = gin.H{"status": "Unknown Error"}
|
status = gin.H{"status": "Please include trigger type such as 'enter','cross','exit','inside' or 'outside'"}
|
||||||
httpStatus = http.StatusInternalServerError
|
httpStatus = http.StatusBadRequest
|
||||||
} else {
|
} else {
|
||||||
status = gin.H{"status": "Ok"}
|
client.Do("SETHOOK", hookID, hookURL, "NEARBY", detection.Type, "FENCE", "DETECT", trigger, "COMMANDS", "set", "POINT", detection.Lat, detection.Lng)
|
||||||
httpStatus = http.StatusOK
|
if err != nil {
|
||||||
|
status = gin.H{"status": "Unknown Error"}
|
||||||
|
httpStatus = http.StatusInternalServerError
|
||||||
|
} else {
|
||||||
|
status = gin.H{"status": "Ok"}
|
||||||
|
httpStatus = http.StatusOK
|
||||||
|
}
|
||||||
}
|
}
|
||||||
c.Writer.Header().Set("Content-Type", "application/json")
|
c.Writer.Header().Set("Content-Type", "application/json")
|
||||||
c.JSON(httpStatus, status)
|
c.JSON(httpStatus, status)
|
||||||
})
|
})
|
||||||
|
|
||||||
r.GET("/detection/call", func(c *gin.Context) {
|
r.GET("/detection/call", func(c *gin.Context) {
|
||||||
fmt.Println("Called")
|
hookID := c.Query("hook")
|
||||||
c.JSON(200, gin.H{"status": "test"})
|
if hookID == "" {
|
||||||
|
c.JSON(http.StatusBadRequest, gin.H{"status": "Wrong Request"})
|
||||||
|
} else {
|
||||||
|
client.Do("DELHOOK", hookID)
|
||||||
|
c.JSON(http.StatusOK, gin.H{"status": "OK"})
|
||||||
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
r.GET("/ws", func(c *gin.Context) {
|
r.GET("/ws", func(c *gin.Context) {
|
||||||
|
Loading…
Reference in New Issue
Block a user