From dc88df23d99f70694572e3988fa24f1a0dd4c382 Mon Sep 17 00:00:00 2001 From: Adam French Date: Tue, 9 Dec 2025 23:14:35 +0000 Subject: [PATCH] fixed db errors --- backend/handlers/handle_post.go | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/backend/handlers/handle_post.go b/backend/handlers/handle_post.go index 515fe80..c817550 100644 --- a/backend/handlers/handle_post.go +++ b/backend/handlers/handle_post.go @@ -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) }