广告点击添加
This commit is contained in:
@@ -0,0 +1,56 @@
|
||||
package web
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
"videoweb/app/service/adsser"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
// adsClickBody 浏览器上报体;appId 由服务端固定,不信任前端。
|
||||
type adsClickBody struct {
|
||||
AdsId int64 `json:"adsId"`
|
||||
Location int64 `json:"location"`
|
||||
}
|
||||
|
||||
// AdsClick BFF:代理 POST /api/app/ads/click(广告点击上报)。
|
||||
func AdsClick(c *gin.Context) {
|
||||
var body adsClickBody
|
||||
if err := c.ShouldBindJSON(&body); err != nil || body.AdsId <= 0 || body.Location <= 0 {
|
||||
c.JSON(http.StatusBadRequest, gin.H{
|
||||
"code": 400,
|
||||
"msg": "invalid body",
|
||||
"tip": "参数错误",
|
||||
"data": nil,
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
env, err := adsser.Click(c, adsser.ClickReq{
|
||||
AppId: adsser.ClickAppID,
|
||||
AdsId: body.AdsId,
|
||||
Location: body.Location,
|
||||
})
|
||||
if err != nil {
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"code": 500,
|
||||
"msg": err.Error(),
|
||||
"data": nil,
|
||||
})
|
||||
return
|
||||
}
|
||||
if env == nil {
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"code": 500,
|
||||
"msg": "empty response",
|
||||
"data": nil,
|
||||
})
|
||||
return
|
||||
}
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"code": env.Code,
|
||||
"msg": env.Msg,
|
||||
"tip": env.Tip,
|
||||
"data": env.Data,
|
||||
})
|
||||
}
|
||||
Reference in New Issue
Block a user