refac: deleting an article also deletes its images, and deleting a missing article returns 404

This commit is contained in:
fsylvain committed 2026-09-23 23:42:18 +02:00
1 parent c16fdbd26d
commit 8a8a24434a
13 files changed
+414 -18

No files matched your search

@@ -1,15 +1,30 @@
package useCases
import "RenewCMS/internal/domain/article"
import (
"RenewCMS/internal/domain/article"
"RenewCMS/internal/domain/image"
)
type DeleteArticleUseCase struct {
articleRepository article.Repository
imageRepository image.Repository
}
func NewDeleteArticleUseCase(articleRepository article.Repository) *DeleteArticleUseCase {
return &DeleteArticleUseCase{articleRepository}
func NewDeleteArticleUseCase(articleRepository article.Repository, imageRepository image.Repository) *DeleteArticleUseCase {
return &DeleteArticleUseCase{articleRepository, imageRepository}
}
func (g *DeleteArticleUseCase) DeleteArticle(userId uint32) error {
return g.articleRepository.Delete(userId)
func (g *DeleteArticleUseCase) DeleteArticle(id uint32) error {
a, err := g.articleRepository.Get(id)
if err != nil {
return err
}
for _, img := range a.Images {
if err := g.imageRepository.Delete(img.ID); err != nil {
return err
}
}
return g.articleRepository.Delete(id)
}