This commit is contained in:
2024-08-01 02:44:06 +08:00
parent 1860e3666d
commit a8891902c6
11 changed files with 121 additions and 57 deletions

24
controllers/contents.go Normal file
View File

@@ -0,0 +1,24 @@
package controllers
import (
"go_blog/models"
"github.com/gin-gonic/gin"
)
// 登录
func CreateContentHandler(ctx *gin.Context) {
var content models.Content
if err := ctx.ShouldBindJSON(&content); err != nil {
ctx.JSON(400, gin.H{"error": err.Error()})
return
}
if err := models.DB.Create(&content).Error; err != nil {
ctx.JSON(500, gin.H{"error": "Failed to create content"})
return
}
ctx.JSON(201, content)
}