no more content
This commit is contained in:
parent
936a0a0d80
commit
bcacbf1e4d
|
@ -9,7 +9,7 @@ type Entry interface {
|
|||
Content() EntryContent
|
||||
PublishedAt() *time.Time
|
||||
MetaData() interface{}
|
||||
Create(id string, content string, publishedAt *time.Time, metaData EntryMetaData) error
|
||||
Create(id string, publishedAt *time.Time, metaData EntryMetaData) error
|
||||
}
|
||||
|
||||
type EntryMetaData interface {
|
||||
|
|
|
@ -4,13 +4,13 @@ import "time"
|
|||
|
||||
type ImageEntry struct {
|
||||
id string
|
||||
content EntryContent
|
||||
publishedAt *time.Time
|
||||
ImagePath string
|
||||
meta ImageEntryMetaData
|
||||
}
|
||||
|
||||
type ImageEntryMetaData struct {
|
||||
ImagePath string `owl:"inputType=file"`
|
||||
ImagePath string `owl:"inputType=file"`
|
||||
Content EntryContent `owl:"inputType=text widget=textarea"`
|
||||
}
|
||||
|
||||
func (e *ImageEntry) ID() string {
|
||||
|
@ -18,7 +18,7 @@ func (e *ImageEntry) ID() string {
|
|||
}
|
||||
|
||||
func (e *ImageEntry) Content() EntryContent {
|
||||
return e.content
|
||||
return e.meta.Content
|
||||
}
|
||||
|
||||
func (e *ImageEntry) PublishedAt() *time.Time {
|
||||
|
@ -27,14 +27,14 @@ func (e *ImageEntry) PublishedAt() *time.Time {
|
|||
|
||||
func (e *ImageEntry) MetaData() interface{} {
|
||||
return &ImageEntryMetaData{
|
||||
ImagePath: e.ImagePath,
|
||||
ImagePath: e.meta.ImagePath,
|
||||
Content: e.meta.Content,
|
||||
}
|
||||
}
|
||||
|
||||
func (e *ImageEntry) Create(id string, content string, publishedAt *time.Time, metaData EntryMetaData) error {
|
||||
func (e *ImageEntry) Create(id string, publishedAt *time.Time, metaData EntryMetaData) error {
|
||||
e.id = id
|
||||
e.content = EntryContent(content)
|
||||
e.publishedAt = publishedAt
|
||||
e.ImagePath = metaData.(*ImageEntryMetaData).ImagePath
|
||||
e.meta = *metaData.(*ImageEntryMetaData)
|
||||
return nil
|
||||
}
|
||||
|
|
|
@ -17,7 +17,6 @@ import (
|
|||
type sqlEntry struct {
|
||||
Id string `db:"id"`
|
||||
Type string `db:"type"`
|
||||
Content string `db:"content"`
|
||||
PublishedAt *time.Time `db:"published_at"`
|
||||
MetaData *string `db:"meta_data"`
|
||||
}
|
||||
|
@ -44,7 +43,7 @@ func (r *DefaultEntryRepo) Create(entry model.Entry) error {
|
|||
metaDataJson, _ = json.Marshal(entry.MetaData())
|
||||
}
|
||||
|
||||
_, err = r.db.Exec("INSERT INTO entries (id, type, content, published_at, meta_data) VALUES (?, ?, ?, ?, ?)", entry.ID(), t, entry.Content(), entry.PublishedAt(), metaDataJson)
|
||||
_, err = r.db.Exec("INSERT INTO entries (id, type, published_at, meta_data) VALUES (?, ?, ?, ?)", entry.ID(), t, entry.PublishedAt(), metaDataJson)
|
||||
return err
|
||||
}
|
||||
|
||||
|
@ -119,7 +118,7 @@ func (r *DefaultEntryRepo) Update(entry model.Entry) error {
|
|||
metaDataJson, _ = json.Marshal(entry.MetaData())
|
||||
}
|
||||
|
||||
_, err = r.db.Exec("UPDATE entries SET content = ?, published_at = ?, meta_data = ? WHERE id = ?", entry.Content(), entry.PublishedAt(), metaDataJson, entry.ID())
|
||||
_, err = r.db.Exec("UPDATE entries SET published_at = ?, meta_data = ? WHERE id = ?", entry.PublishedAt(), metaDataJson, entry.ID())
|
||||
return err
|
||||
}
|
||||
|
||||
|
@ -131,7 +130,6 @@ func NewEntryRepository(db Database, register *app.EntryTypeRegistry) repository
|
|||
CREATE TABLE IF NOT EXISTS entries (
|
||||
id TEXT PRIMARY KEY,
|
||||
type TEXT NOT NULL,
|
||||
content TEXT NOT NULL,
|
||||
published_at DATETIME,
|
||||
meta_data TEXT NOT NULL
|
||||
);
|
||||
|
@ -150,6 +148,6 @@ func (r *DefaultEntryRepo) sqlEntryToEntry(entry sqlEntry) (model.Entry, error)
|
|||
}
|
||||
metaData := reflect.New(reflect.TypeOf(e.MetaData()).Elem()).Interface()
|
||||
json.Unmarshal([]byte(*entry.MetaData), metaData)
|
||||
e.Create(entry.Id, entry.Content, entry.PublishedAt, metaData)
|
||||
e.Create(entry.Id, entry.PublishedAt, metaData)
|
||||
return e, nil
|
||||
}
|
||||
|
|
|
@ -24,7 +24,7 @@ func TestRepoCreate(t *testing.T) {
|
|||
|
||||
entry := &test.MockEntry{}
|
||||
now := time.Now()
|
||||
entry.Create("id", "content", &now, &test.MockEntryMetaData{
|
||||
entry.Create("id", &now, &test.MockEntryMetaData{
|
||||
Str: "str",
|
||||
Number: 1,
|
||||
Date: now,
|
||||
|
@ -49,7 +49,7 @@ func TestRepoDelete(t *testing.T) {
|
|||
|
||||
entry := &test.MockEntry{}
|
||||
now := time.Now()
|
||||
entry.Create("id", "content", &now, &test.MockEntryMetaData{
|
||||
entry.Create("id", &now, &test.MockEntryMetaData{
|
||||
Str: "str",
|
||||
Number: 1,
|
||||
Date: now,
|
||||
|
@ -69,7 +69,7 @@ func TestRepoFindAll(t *testing.T) {
|
|||
|
||||
entry := &test.MockEntry{}
|
||||
now := time.Now()
|
||||
entry.Create("id", "content", &now, &test.MockEntryMetaData{
|
||||
entry.Create("id", &now, &test.MockEntryMetaData{
|
||||
Str: "str",
|
||||
Number: 1,
|
||||
Date: now,
|
||||
|
@ -79,7 +79,7 @@ func TestRepoFindAll(t *testing.T) {
|
|||
|
||||
entry2 := &test.MockEntry{}
|
||||
now2 := time.Now()
|
||||
entry2.Create("id2", "content2", &now2, &test.MockEntryMetaData{
|
||||
entry2.Create("id2", &now2, &test.MockEntryMetaData{
|
||||
Str: "str2",
|
||||
Number: 2,
|
||||
Date: now2,
|
||||
|
@ -106,7 +106,7 @@ func TestRepoUpdate(t *testing.T) {
|
|||
|
||||
entry := &test.MockEntry{}
|
||||
now := time.Now()
|
||||
entry.Create("id", "content", &now, &test.MockEntryMetaData{
|
||||
entry.Create("id", &now, &test.MockEntryMetaData{
|
||||
Str: "str",
|
||||
Number: 1,
|
||||
Date: now,
|
||||
|
@ -116,7 +116,7 @@ func TestRepoUpdate(t *testing.T) {
|
|||
|
||||
entry2 := &test.MockEntry{}
|
||||
now2 := time.Now()
|
||||
entry2.Create("id", "content2", &now2, &test.MockEntryMetaData{
|
||||
entry2.Create("id", &now2, &test.MockEntryMetaData{
|
||||
Str: "str2",
|
||||
Number: 2,
|
||||
Date: now2,
|
||||
|
|
|
@ -13,7 +13,6 @@ type MockEntryMetaData struct {
|
|||
|
||||
type MockEntry struct {
|
||||
id string
|
||||
content model.EntryContent
|
||||
publishedAt *time.Time
|
||||
metaData *MockEntryMetaData
|
||||
}
|
||||
|
@ -23,7 +22,7 @@ func (e *MockEntry) ID() string {
|
|||
}
|
||||
|
||||
func (e *MockEntry) Content() model.EntryContent {
|
||||
return e.content
|
||||
return model.EntryContent(e.metaData.Str)
|
||||
}
|
||||
|
||||
func (e *MockEntry) PublishedAt() *time.Time {
|
||||
|
@ -34,9 +33,8 @@ func (e *MockEntry) MetaData() interface{} {
|
|||
return e.metaData
|
||||
}
|
||||
|
||||
func (e *MockEntry) Create(id string, content string, publishedAt *time.Time, metaData model.EntryMetaData) error {
|
||||
func (e *MockEntry) Create(id string, publishedAt *time.Time, metaData model.EntryMetaData) error {
|
||||
e.id = id
|
||||
e.content = model.EntryContent(content)
|
||||
e.publishedAt = publishedAt
|
||||
e.metaData = metaData.(*MockEntryMetaData)
|
||||
return nil
|
||||
|
|
|
@ -17,7 +17,6 @@ type MockEntryMetaData struct {
|
|||
|
||||
type MockEntry struct {
|
||||
id string
|
||||
content model.EntryContent
|
||||
publishedAt *time.Time
|
||||
metaData *MockEntryMetaData
|
||||
}
|
||||
|
@ -27,7 +26,7 @@ func (e *MockEntry) ID() string {
|
|||
}
|
||||
|
||||
func (e *MockEntry) Content() model.EntryContent {
|
||||
return e.content
|
||||
return model.EntryContent(e.metaData.Content)
|
||||
}
|
||||
|
||||
func (e *MockEntry) PublishedAt() *time.Time {
|
||||
|
@ -38,9 +37,8 @@ func (e *MockEntry) MetaData() interface{} {
|
|||
return e.metaData
|
||||
}
|
||||
|
||||
func (e *MockEntry) Create(id string, content string, publishedAt *time.Time, metaData model.EntryMetaData) error {
|
||||
func (e *MockEntry) Create(id string, publishedAt *time.Time, metaData model.EntryMetaData) error {
|
||||
e.id = id
|
||||
e.content = model.EntryContent(content)
|
||||
e.publishedAt = publishedAt
|
||||
e.metaData = metaData.(*MockEntryMetaData)
|
||||
return nil
|
||||
|
|
|
@ -19,7 +19,10 @@ func NewEditorHandler(entryService *app.EntryService) *EditorHandler {
|
|||
func (h *EditorHandler) HandleGet(c *fiber.Ctx) error {
|
||||
c.Set(fiber.HeaderContentType, fiber.MIMETextHTML)
|
||||
formService := editor.NewEditorFormService(&model.ImageEntry{})
|
||||
form, _ := formService.HtmlForm()
|
||||
form, err := formService.HtmlForm()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return c.SendString(form)
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue