v2 #43
|
@ -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)
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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)
|
||||
}
|
|
@ -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)
|
||||
}
|
|
@ -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)
|
||||
}
|
|
@ -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)
|
||||
}
|
Loading…
Reference in New Issue