feat: activity log producers

This commit is contained in:
fsylvain committed 2026-10-06 22:25:23 +02:00
1 parent 50b1649965
commit e37a46a027
93 files changed
+3396 -440

No files matched your search

@@ -2,11 +2,14 @@ package useCases
import (
"RenewCMS/internal/domain/article"
"RenewCMS/internal/domain/audit"
"context"
)
type CreateArticleUseCase struct {
articleRepository article.Repository
bodyRenderer article.BodyRenderer
recorder audit.Recorder
}
type CreateArticleCommand struct {
@@ -15,12 +18,14 @@ type CreateArticleCommand struct {
Format article.BodyFormat
}
func NewCreateArticleUseCase(articleRepository article.Repository, bodyRenderer article.BodyRenderer) *CreateArticleUseCase {
return &CreateArticleUseCase{articleRepository, bodyRenderer}
func NewCreateArticleUseCase(articleRepository article.Repository, bodyRenderer article.BodyRenderer, recorder audit.Recorder) *CreateArticleUseCase {
return &CreateArticleUseCase{articleRepository, bodyRenderer, recorder}
}
func (g *CreateArticleUseCase) CreateArticle(createArticle CreateArticleCommand) (article.Article, error) {
func (g *CreateArticleUseCase) CreateArticle(ctx context.Context, createArticle CreateArticleCommand) (article.Article, error) {
event := audit.NewEvent(audit.ActionArticleCreate, audit.CategoryArticles)
if err := article.ValidateTitle(createArticle.Title); err != nil {
recordFailure(ctx, g.recorder, event, err)
return article.Article{}, err
}
@@ -30,7 +35,15 @@ func (g *CreateArticleUseCase) CreateArticle(createArticle CreateArticleCommand)
IsOnline: false,
})
if err != nil {
recordFailure(ctx, g.recorder, event, err)
return article.Article{}, err
}
event.Target = articleTarget(created)
g.recorder.Record(ctx, event)
return renderArticle(g.bodyRenderer, created, createArticle.Format)
}
func articleTarget(a article.Article) audit.Target {
return audit.NewTarget(audit.TargetArticle, a.ID, a.Title)
}