添加反馈接口
This commit is contained in:
43
controllers/feedback/upfeedback.go
Normal file
43
controllers/feedback/upfeedback.go
Normal file
@@ -0,0 +1,43 @@
|
||||
package feedback
|
||||
|
||||
import (
|
||||
"github.com/gin-gonic/gin"
|
||||
"time"
|
||||
"toutoukan/init/databaseInit"
|
||||
)
|
||||
|
||||
type Feedback struct {
|
||||
ID uint `gorm:"primaryKey;autoIncrement" json:"id"`
|
||||
UserID string `json:"user_id"`
|
||||
FeedBackType int8 `json:"feed_back_type"`
|
||||
FeedbackContent string `json:"feedback_content"`
|
||||
FeedbackStatus int8 `gorm:"default:0" json:"feedback_status,omitempty"` // 默认为 0(待处理),前端无需传入
|
||||
HandlerID string `gorm:"default:''" json:"handler_id,omitempty"` // 默认为空,前端无需传入
|
||||
CreateTime time.Time `gorm:"autoCreateTime" json:"create_time,omitempty"` // 自动生成创建时间,前端无需传入
|
||||
HandleTime time.Time `gorm:"default:null" json:"handle_time,omitempty"` // 默认为空,处理时赋值,前端无需传入
|
||||
HandleRemark string `gorm:"default:''" json:"handle_remark,omitempty"` // 默认为空,处理时赋值,前端无需传入
|
||||
IsDelete int8 `gorm:"default:0" json:"is_delete,omitempty"` // 默认为 0(未删除),前端无需传入
|
||||
}
|
||||
|
||||
// UpFeedback 新增用户反馈
|
||||
func UpFeedback(c *gin.Context) {
|
||||
var feedback Feedback
|
||||
// 绑定请求体中的 JSON 数据到 feedback 结构体
|
||||
if err := c.ShouldBindJSON(&feedback); err != nil {
|
||||
c.JSON(400, gin.H{"error": err.Error()})
|
||||
return
|
||||
}
|
||||
|
||||
// 使用 GORM 连接池进行数据库操作
|
||||
result := databaseInit.UserDB.Create(&feedback)
|
||||
if result.Error != nil {
|
||||
c.JSON(500, gin.H{"error": result.Error.Error()})
|
||||
return
|
||||
}
|
||||
|
||||
// 返回成功响应,包含新增反馈的 ID
|
||||
c.JSON(200, gin.H{
|
||||
"message": "反馈提交成功",
|
||||
"data": feedback,
|
||||
})
|
||||
}
|
||||
@@ -5,6 +5,7 @@ import (
|
||||
"toutoukan/controllers/article/getArticleNum"
|
||||
"toutoukan/controllers/comments/getcomments"
|
||||
"toutoukan/controllers/comments/publishComments"
|
||||
"toutoukan/controllers/feedback"
|
||||
"toutoukan/controllers/file"
|
||||
"toutoukan/controllers/goods"
|
||||
"toutoukan/controllers/kills"
|
||||
@@ -20,14 +21,15 @@ import (
|
||||
|
||||
func SetupRouter() *gin.Engine {
|
||||
r := gin.Default()
|
||||
apiGroup := r.Group("/user")
|
||||
userGroup := r.Group("/user")
|
||||
//apiGroup.Use(hystrix.CircuitBreakerMiddleware("user_api"))
|
||||
{
|
||||
apiGroup.POST("/login", user.UserLogin)
|
||||
apiGroup.POST("/kill", ratelimit.RateLimitMiddleware(), kills.Userkill)
|
||||
apiGroup.POST("/getscore", user.GetScore)
|
||||
apiGroup.POST("/getInfo", user.GetUserInfo)
|
||||
apiGroup.POST("/change", setting.ChangeUserSetting)
|
||||
userGroup.POST("/login", user.UserLogin)
|
||||
userGroup.POST("/kill", ratelimit.RateLimitMiddleware(), kills.Userkill)
|
||||
userGroup.POST("/getscore", user.GetScore)
|
||||
userGroup.POST("/getInfo", user.GetUserInfo)
|
||||
userGroup.POST("/change", setting.ChangeUserSetting)
|
||||
userGroup.POST("/feedback", feedback.UpFeedback)
|
||||
|
||||
}
|
||||
//r.GET("/socket", jwt.JWTAuthMiddleware(), func(c *gin.Context) {
|
||||
|
||||
Reference in New Issue
Block a user