Fixed post updating
This commit is contained in:
@@ -22,7 +22,7 @@ import (
|
|||||||
|
|
||||||
type BlogPost struct {
|
type BlogPost struct {
|
||||||
gorm.Model
|
gorm.Model
|
||||||
Url string `json:"url" gorm:"primaryKey"`
|
Url string `json:"url" gorm:"primaryKey unique"`
|
||||||
Title string `json:"title" gorm:"unique"`
|
Title string `json:"title" gorm:"unique"`
|
||||||
Date string `json:"date" gorm:"default:NOW()"`
|
Date string `json:"date" gorm:"default:NOW()"`
|
||||||
Content string `json:"content"`
|
Content string `json:"content"`
|
||||||
|
|||||||
@@ -85,7 +85,7 @@ func (b *BlogRepo) UpdateExistingPost(p *models.BlogPost) error {
|
|||||||
if p.Url == "" {
|
if p.Url == "" {
|
||||||
return errors.New("Url must exist to update a blog post record")
|
return errors.New("Url must exist to update a blog post record")
|
||||||
}
|
}
|
||||||
err := b.DB.Table("blog_posts").Save(p).Error
|
err := b.DB.Table("blog_posts").Where(&models.BlogPost{Url: p.Url}).Save(p).Error
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user