fixed db errors
This commit is contained in:
@@ -60,7 +60,11 @@ func (store *Store) CreatePost(ctx *gin.Context) {
|
|||||||
|
|
||||||
// Create post
|
// Create post
|
||||||
post := models.Post{Title: input.Title, Content: input.Content, AuthorID: userID}
|
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)
|
ctx.JSON(http.StatusCreated, post)
|
||||||
}
|
}
|
||||||
@@ -103,7 +107,11 @@ func (store *Store) UpdatePost(ctx *gin.Context) {
|
|||||||
|
|
||||||
post.Title = input.Title
|
post.Title = input.Title
|
||||||
post.Content = input.Content
|
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)
|
ctx.JSON(http.StatusOK, post)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user