Fixed post updating

This commit is contained in:
rawleyIfowler
2022-03-13 09:46:56 -05:00
parent 2b62838435
commit 736d885f6e
2 changed files with 2 additions and 2 deletions

View File

@@ -22,7 +22,7 @@ import (
type BlogPost struct {
gorm.Model
Url string `json:"url" gorm:"primaryKey"`
Url string `json:"url" gorm:"primaryKey unique"`
Title string `json:"title" gorm:"unique"`
Date string `json:"date" gorm:"default:NOW()"`
Content string `json:"content"`

View File

@@ -85,7 +85,7 @@ func (b *BlogRepo) UpdateExistingPost(p *models.BlogPost) error {
if p.Url == "" {
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 {
return err
}