mirror of
https://github.com/supanadit/geo-smart-system.git
synced 2024-11-22 00:26:21 +00:00
Delete Hook when Hook is Called once
This commit is contained in:
parent
8a8364da2c
commit
e407af393e
19
main.go
19
main.go
@ -85,12 +85,15 @@ 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 trigger == "" {
|
||||||
|
status = gin.H{"status": "Please include trigger type such as 'enter','cross','exit','inside' or 'outside'"}
|
||||||
|
httpStatus = http.StatusBadRequest
|
||||||
|
} else {
|
||||||
|
client.Do("SETHOOK", hookID, hookURL, "NEARBY", detection.Type, "FENCE", "DETECT", trigger, "COMMANDS", "set", "POINT", detection.Lat, detection.Lng)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
status = gin.H{"status": "Unknown Error"}
|
status = gin.H{"status": "Unknown Error"}
|
||||||
httpStatus = http.StatusInternalServerError
|
httpStatus = http.StatusInternalServerError
|
||||||
@ -98,13 +101,19 @@ func main() {
|
|||||||
status = gin.H{"status": "Ok"}
|
status = gin.H{"status": "Ok"}
|
||||||
httpStatus = http.StatusOK
|
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