v2 #43

Merged
h4kor merged 41 commits from v2 into main 2023-07-19 19:09:19 +00:00
8 changed files with 54 additions and 54 deletions
Showing only changes of commit 723c94c576 - Show all commits

View File

@ -38,7 +38,7 @@ func TestEditorFormGet(t *testing.T) {
app := owlApp.FiberApp
token := getUserToken(owlApp.AuthorService)
req := httptest.NewRequest("GET", "/editor/ImageEntry", nil)
req := httptest.NewRequest("GET", "/editor/Image", nil)
req.AddCookie(&http.Cookie{Name: "token", Value: token})
resp, err := app.Test(req)
require.NoError(t, err)
@ -50,7 +50,7 @@ func TestEditorFormGetNoAuth(t *testing.T) {
owlApp := App(db)
app := owlApp.FiberApp
req := httptest.NewRequest("GET", "/editor/ImageEntry", nil)
req := httptest.NewRequest("GET", "/editor/Image", nil)
req.AddCookie(&http.Cookie{Name: "token", Value: "invalid"})
resp, err := app.Test(req)
require.NoError(t, err)
@ -83,7 +83,7 @@ func TestEditorFormPost(t *testing.T) {
io.WriteString(part, "test content")
writer.Close()
req := httptest.NewRequest("POST", "/editor/ImageEntry", body)
req := httptest.NewRequest("POST", "/editor/Image", body)
req.Header.Set("Content-Type", writer.FormDataContentType())
req.AddCookie(&http.Cookie{Name: "token", Value: token})
resp, err := app.Test(req)
@ -94,8 +94,8 @@ func TestEditorFormPost(t *testing.T) {
id := strings.Split(resp.Header.Get("Location"), "/")[2]
entry, err := repo.FindById(id)
require.NoError(t, err)
require.Equal(t, "test content", entry.MetaData().(*model.ImageEntryMetaData).Content)
imageId := entry.MetaData().(*model.ImageEntryMetaData).ImageId
require.Equal(t, "test content", entry.MetaData().(*model.ImageMetaData).Content)
imageId := entry.MetaData().(*model.ImageMetaData).ImageId
require.NotZero(t, imageId)
bin, err := binRepo.FindById(imageId)
require.NoError(t, err)
@ -125,7 +125,7 @@ func TestEditorFormPostNoAuth(t *testing.T) {
io.WriteString(part, "test content")
writer.Close()
req := httptest.NewRequest("POST", "/editor/ImageEntry", body)
req := httptest.NewRequest("POST", "/editor/Image", body)
req.Header.Set("Content-Type", writer.FormDataContentType())
req.AddCookie(&http.Cookie{Name: "token", Value: "invalid"})
resp, err := app.Test(req)

View File

@ -30,8 +30,8 @@ func App(db infra.Database) *web.WebApp {
config := config.NewConfig()
registry := app.NewEntryTypeRegistry()
registry.Register(&model.ImageEntry{})
registry.Register(&model.PostEntry{})
registry.Register(&model.Image{})
registry.Register(&model.Article{})
entryRepo := infra.NewEntryRepository(db, registry)
binRepo := infra.NewBinaryFileRepo(db)

23
domain/model/article.go Normal file
View File

@ -0,0 +1,23 @@
package model
type Article struct {
EntryBase
meta ArticleMetaData
}
type ArticleMetaData struct {
Title string `owl:"inputType=text"`
Content string `owl:"inputType=text widget=textarea"`
}
func (e *Article) Content() EntryContent {
return EntryContent(e.meta.Content)
}
func (e *Article) MetaData() interface{} {
return &e.meta
}
func (e *Article) SetMetaData(metaData interface{}) {
e.meta = *metaData.(*ArticleMetaData)
}

23
domain/model/image.go Normal file
View File

@ -0,0 +1,23 @@
package model
type Image struct {
EntryBase
meta ImageMetaData
}
type ImageMetaData struct {
ImageId string `owl:"inputType=file"`
Content string `owl:"inputType=text widget=textarea"`
}
func (e *Image) Content() EntryContent {
return EntryContent(e.meta.Content)
}
func (e *Image) MetaData() interface{} {
return &e.meta
}
func (e *Image) SetMetaData(metaData interface{}) {
e.meta = *metaData.(*ImageMetaData)
}

View File

@ -1,23 +0,0 @@
package model
type ImageEntry struct {
EntryBase
meta ImageEntryMetaData
}
type ImageEntryMetaData struct {
ImageId string `owl:"inputType=file"`
Content string `owl:"inputType=text widget=textarea"`
}
func (e *ImageEntry) Content() EntryContent {
return EntryContent(e.meta.Content)
}
func (e *ImageEntry) MetaData() interface{} {
return &e.meta
}
func (e *ImageEntry) SetMetaData(metaData interface{}) {
e.meta = *metaData.(*ImageEntryMetaData)
}

View File

@ -1,23 +0,0 @@
package model
type PostEntry struct {
EntryBase
meta PostEntryMetaData
}
type PostEntryMetaData struct {
Title string `owl:"inputType=text"`
Content string `owl:"inputType=text widget=textarea"`
}
func (e *PostEntry) Content() EntryContent {
return EntryContent(e.meta.Content)
}
func (e *PostEntry) MetaData() interface{} {
return &e.meta
}
func (e *PostEntry) SetMetaData(metaData interface{}) {
e.meta = *metaData.(*PostEntryMetaData)
}