feat: activity log producers
This commit is contained in:
1 parent
50b1649965
commit
e37a46a027
93 files changed
+3396
-440
No files matched your search
@@ -0,0 +1,30 @@
|
||||
package audit
|
||||
|
||||
import (
|
||||
"RenewCMS/internal/domain/article"
|
||||
"strconv"
|
||||
"unicode/utf8"
|
||||
)
|
||||
|
||||
func TextChange(field string, before string, after string) Change {
|
||||
return Change{Field: field, Kind: ChangeText, Before: &before, After: &after}
|
||||
}
|
||||
|
||||
func BodyChange(before string, after string) Change {
|
||||
delta := utf8.RuneCountInString(after) - utf8.RuneCountInString(before)
|
||||
return Change{Field: FieldBody, Kind: ChangeBody, Delta: &delta}
|
||||
}
|
||||
|
||||
func ArticleChanges(before article.Article, after article.Article) []Change {
|
||||
changes := []Change{}
|
||||
if before.Title != after.Title {
|
||||
changes = append(changes, TextChange(FieldTitle, before.Title, after.Title))
|
||||
}
|
||||
if before.IsOnline != after.IsOnline {
|
||||
changes = append(changes, TextChange(FieldOnline, strconv.FormatBool(before.IsOnline), strconv.FormatBool(after.IsOnline)))
|
||||
}
|
||||
if before.Body != after.Body {
|
||||
changes = append(changes, BodyChange(before.Body, after.Body))
|
||||
}
|
||||
return changes
|
||||
}
|
||||
Reference in new issue
Block a user