feat(API): media library
This commit is contained in:
1 parent
95ae043d3e
commit
0d99544579
65 files changed
+3992
-1530
No files matched your search
+19
-20
@@ -2,25 +2,24 @@ package test
|
||||
|
||||
import (
|
||||
"RenewCMS/internal/domain/article"
|
||||
imageDomain "RenewCMS/internal/domain/image"
|
||||
"RenewCMS/internal/infrastructure/useCases"
|
||||
"errors"
|
||||
"sort"
|
||||
"strings"
|
||||
"testing"
|
||||
)
|
||||
|
||||
type mockArticleRepo struct {
|
||||
articles map[uint32]article.Article
|
||||
images map[uint32]*imageDomain.Image
|
||||
nextID uint32
|
||||
fail failSwitch
|
||||
createCalled bool
|
||||
articles map[uint32]article.Article
|
||||
failUpdateBodyFor map[uint32]error
|
||||
nextID uint32
|
||||
fail failSwitch
|
||||
createCalled bool
|
||||
}
|
||||
|
||||
func newMockArticleRepo() *mockArticleRepo {
|
||||
return &mockArticleRepo{
|
||||
articles: make(map[uint32]article.Article),
|
||||
images: make(map[uint32]*imageDomain.Image),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -95,6 +94,9 @@ func (m *mockArticleRepo) UpdateBody(id uint32, body string) (article.Article, e
|
||||
if err := m.fail.trigger("UpdateBody"); err != nil {
|
||||
return article.Article{}, err
|
||||
}
|
||||
if err, ok := m.failUpdateBodyFor[id]; ok {
|
||||
return article.Article{}, err
|
||||
}
|
||||
a, ok := m.articles[id]
|
||||
if !ok {
|
||||
return article.Article{}, article.ErrArticleNotFound
|
||||
@@ -128,21 +130,18 @@ func (m *mockArticleRepo) Delete(id uint32) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (m *mockArticleRepo) AddImage(articleId uint32, imageId uint32) error {
|
||||
if err := m.fail.trigger("AddImage"); err != nil {
|
||||
return err
|
||||
func (m *mockArticleRepo) FindByBodyContaining(filename string) ([]article.Article, error) {
|
||||
if err := m.fail.trigger("FindByBodyContaining"); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
a, ok := m.articles[articleId]
|
||||
if !ok {
|
||||
return article.ErrArticleNotFound
|
||||
result := make([]article.Article, 0)
|
||||
for _, id := range m.sortedIds() {
|
||||
a := m.articles[id]
|
||||
if strings.Contains(a.Body, filename) {
|
||||
result = append(result, a)
|
||||
}
|
||||
}
|
||||
img, ok := m.images[imageId]
|
||||
if !ok {
|
||||
return imageDomain.ErrImageNotFound
|
||||
}
|
||||
a.Images = append(a.Images, img)
|
||||
m.articles[articleId] = a
|
||||
return nil
|
||||
return result, nil
|
||||
}
|
||||
|
||||
var _ article.Repository = &mockArticleRepo{}
|
||||
|
||||
Reference in new issue
Block a user