-
Notifications
You must be signed in to change notification settings - Fork 29
/
report.go
43 lines (34 loc) · 977 Bytes
/
report.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
package frontend
import (
"context"
"github.com/gin-gonic/gin"
"github.com/gogf/gf/v2/frame/g"
fe "github.com/hhandhuan/ku-bbs/internal/entity/frontend"
"github.com/hhandhuan/ku-bbs/internal/service"
"github.com/hhandhuan/ku-bbs/internal/service/frontend"
)
var Report = cReport{}
type cReport struct{}
// ReportSubmit 举报提交
func (c *cReport) ReportSubmit(ctx *gin.Context) {
s := service.Context(ctx)
if !s.Check() {
s.Json(gin.H{"code": 1, "msg": "请登录后在继续操作"})
return
}
var req fe.SubmitReportReq
if err := ctx.ShouldBind(&req); err != nil {
s.Json(gin.H{"code": 1, "msg": err.Error()})
return
}
verr := g.Validator().Data(req).Run(context.Background())
if verr != nil {
s.Json(gin.H{"code": 1, "msg": verr.FirstError()})
return
}
if err := frontend.ReportService(ctx).Store(&req); err != nil {
s.Json(gin.H{"code": 1, "msg": err.Error()})
} else {
s.Json(gin.H{"code": 0, "msg": "提交举报成功"})
}
}