添加反馈接口
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,
|
||||
})
|
||||
}
|
||||
Reference in New Issue
Block a user