feat: update articles

This commit is contained in:
hanif salafi 2025-03-03 09:40:41 +07:00
parent 9d5a58f927
commit 56ecb6f753
2 changed files with 8 additions and 1 deletions

View File

@ -25,6 +25,7 @@ type ArticlesRepository interface {
FindByFilename(thumbnailName string) (articleReturn *entity.Articles, err error)
Create(articles *entity.Articles) (articleReturn *entity.Articles, err error)
Update(id uint, articles *entity.Articles) (err error)
UpdateSkipNull(id uint, articles *entity.Articles) (err error)
Delete(id uint) (err error)
SummaryStats(userID uint) (articleSummaryStats *response.ArticleSummaryStats, err error)
ArticlePerUserLevelStats(userLevelId *uint, levelNumber *int, startDate *time.Time, endDate *time.Time) (articlePerUserLevelStats []*response.ArticlePerUserLevelStats, err error)
@ -139,6 +140,12 @@ func (_i *articlesRepository) Update(id uint, articles *entity.Articles) (err er
Save(articles).Error
}
func (_i *articlesRepository) UpdateSkipNull(id uint, articles *entity.Articles) (err error) {
return _i.DB.DB.Model(&entity.Articles{}).
Where(&entity.Articles{ID: id}).
Updates(articles).Error
}
func (_i *articlesRepository) Delete(id uint) error {
return _i.DB.DB.Delete(&entity.Articles{}, id).Error
}

View File

@ -350,7 +350,7 @@ func (_i *articlesService) Update(id uint, req request.ArticlesUpdateRequest) (e
newReq.CreatedAt = parsedTime
}
return _i.Repo.Update(id, newReq)
return _i.Repo.UpdateSkipNull(id, newReq)
}
func (_i *articlesService) Delete(id uint) error {