fixed db errors

This commit is contained in:
2025-12-09 23:14:35 +00:00
parent d43f841037
commit dc88df23d9

View File

@@ -60,7 +60,11 @@ func (store *Store) CreatePost(ctx *gin.Context) {
// Create post
post := models.Post{Title: input.Title, Content: input.Content, AuthorID: userID}
store.DB.Create(&post)
tx := store.DB.Create(&post)
if tx.Error != nil {
ctx.JSON(http.StatusInternalServerError, tx.Error.Error())
return
}
ctx.JSON(http.StatusCreated, post)
}
@@ -103,7 +107,11 @@ func (store *Store) UpdatePost(ctx *gin.Context) {
post.Title = input.Title
post.Content = input.Content
store.DB.Save(&post)
tx := store.DB.Save(&post)
if tx.Error != nil {
ctx.JSON(http.StatusInternalServerError, tx.Error.Error())
return
}
ctx.JSON(http.StatusOK, post)
}