-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgofoodwebhookhandler.go
44 lines (40 loc) · 1.03 KB
/
gofoodwebhookhandler.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
package main
import (
"net/http"
"github.com/gin-gonic/gin"
)
// historyHandler godoc
// @Summary Receive webhook from Gofood
// @Description log if there is gofood events such as new order, driver otw, driver cancel, etc
// @Tags ping
// @Accept json
// @Produce json
// @Security GofoodSignature
// @Param request body GofoodWebhookPayload true "Webhook Payload sent by Gofood server"
// @Success 200 {object} DefaultResponse
// @Failure 400 {object} DefaultErrorResponse
// @Router /webhook/gofood [post]
func gofoodWebhookHandler(c *gin.Context) {
var payload GofoodWebhookPayload
err := c.BindJSON(&payload)
if err != nil {
log := DefaultErrorResponse{
Error: err.Error(),
Level: "error",
Message: "Error parsing body",
}
logJson(log.JSON())
c.JSON(http.StatusBadRequest, log)
return
}
log := DefaultErrorResponse{
Header: c.Request.Header,
Level: "info",
Message: "Gofood Webhook received",
Payload: payload,
}
logJson(log.JSON())
c.JSON(http.StatusOK, DefaultResponse{
Message: "ok",
})
}