no more content

This commit is contained in:
Niko Abeler 2023-07-06 18:56:43 +02:00
parent 936a0a0d80
commit bcacbf1e4d
7 changed files with 26 additions and 29 deletions

View File

@ -9,7 +9,7 @@ type Entry interface {
Content() EntryContent Content() EntryContent
PublishedAt() *time.Time PublishedAt() *time.Time
MetaData() interface{} 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 { type EntryMetaData interface {

View File

@ -4,13 +4,13 @@ import "time"
type ImageEntry struct { type ImageEntry struct {
id string id string
content EntryContent
publishedAt *time.Time publishedAt *time.Time
ImagePath string meta ImageEntryMetaData
} }
type ImageEntryMetaData struct { 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 { func (e *ImageEntry) ID() string {
@ -18,7 +18,7 @@ func (e *ImageEntry) ID() string {
} }
func (e *ImageEntry) Content() EntryContent { func (e *ImageEntry) Content() EntryContent {
return e.content return e.meta.Content
} }
func (e *ImageEntry) PublishedAt() *time.Time { func (e *ImageEntry) PublishedAt() *time.Time {
@ -27,14 +27,14 @@ func (e *ImageEntry) PublishedAt() *time.Time {
func (e *ImageEntry) MetaData() interface{} { func (e *ImageEntry) MetaData() interface{} {
return &ImageEntryMetaData{ 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.id = id
e.content = EntryContent(content)
e.publishedAt = publishedAt e.publishedAt = publishedAt
e.ImagePath = metaData.(*ImageEntryMetaData).ImagePath e.meta = *metaData.(*ImageEntryMetaData)
return nil return nil
} }

View File

@ -17,7 +17,6 @@ import (
type sqlEntry struct { type sqlEntry struct {
Id string `db:"id"` Id string `db:"id"`
Type string `db:"type"` Type string `db:"type"`
Content string `db:"content"`
PublishedAt *time.Time `db:"published_at"` PublishedAt *time.Time `db:"published_at"`
MetaData *string `db:"meta_data"` MetaData *string `db:"meta_data"`
} }
@ -44,7 +43,7 @@ func (r *DefaultEntryRepo) Create(entry model.Entry) error {
metaDataJson, _ = json.Marshal(entry.MetaData()) 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 return err
} }
@ -119,7 +118,7 @@ func (r *DefaultEntryRepo) Update(entry model.Entry) error {
metaDataJson, _ = json.Marshal(entry.MetaData()) 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 return err
} }
@ -131,7 +130,6 @@ func NewEntryRepository(db Database, register *app.EntryTypeRegistry) repository
CREATE TABLE IF NOT EXISTS entries ( CREATE TABLE IF NOT EXISTS entries (
id TEXT PRIMARY KEY, id TEXT PRIMARY KEY,
type TEXT NOT NULL, type TEXT NOT NULL,
content TEXT NOT NULL,
published_at DATETIME, published_at DATETIME,
meta_data TEXT NOT NULL 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() metaData := reflect.New(reflect.TypeOf(e.MetaData()).Elem()).Interface()
json.Unmarshal([]byte(*entry.MetaData), metaData) 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 return e, nil
} }

View File

@ -24,7 +24,7 @@ func TestRepoCreate(t *testing.T) {
entry := &test.MockEntry{} entry := &test.MockEntry{}
now := time.Now() now := time.Now()
entry.Create("id", "content", &now, &test.MockEntryMetaData{ entry.Create("id", &now, &test.MockEntryMetaData{
Str: "str", Str: "str",
Number: 1, Number: 1,
Date: now, Date: now,
@ -49,7 +49,7 @@ func TestRepoDelete(t *testing.T) {
entry := &test.MockEntry{} entry := &test.MockEntry{}
now := time.Now() now := time.Now()
entry.Create("id", "content", &now, &test.MockEntryMetaData{ entry.Create("id", &now, &test.MockEntryMetaData{
Str: "str", Str: "str",
Number: 1, Number: 1,
Date: now, Date: now,
@ -69,7 +69,7 @@ func TestRepoFindAll(t *testing.T) {
entry := &test.MockEntry{} entry := &test.MockEntry{}
now := time.Now() now := time.Now()
entry.Create("id", "content", &now, &test.MockEntryMetaData{ entry.Create("id", &now, &test.MockEntryMetaData{
Str: "str", Str: "str",
Number: 1, Number: 1,
Date: now, Date: now,
@ -79,7 +79,7 @@ func TestRepoFindAll(t *testing.T) {
entry2 := &test.MockEntry{} entry2 := &test.MockEntry{}
now2 := time.Now() now2 := time.Now()
entry2.Create("id2", "content2", &now2, &test.MockEntryMetaData{ entry2.Create("id2", &now2, &test.MockEntryMetaData{
Str: "str2", Str: "str2",
Number: 2, Number: 2,
Date: now2, Date: now2,
@ -106,7 +106,7 @@ func TestRepoUpdate(t *testing.T) {
entry := &test.MockEntry{} entry := &test.MockEntry{}
now := time.Now() now := time.Now()
entry.Create("id", "content", &now, &test.MockEntryMetaData{ entry.Create("id", &now, &test.MockEntryMetaData{
Str: "str", Str: "str",
Number: 1, Number: 1,
Date: now, Date: now,
@ -116,7 +116,7 @@ func TestRepoUpdate(t *testing.T) {
entry2 := &test.MockEntry{} entry2 := &test.MockEntry{}
now2 := time.Now() now2 := time.Now()
entry2.Create("id", "content2", &now2, &test.MockEntryMetaData{ entry2.Create("id", &now2, &test.MockEntryMetaData{
Str: "str2", Str: "str2",
Number: 2, Number: 2,
Date: now2, Date: now2,

View File

@ -13,7 +13,6 @@ type MockEntryMetaData struct {
type MockEntry struct { type MockEntry struct {
id string id string
content model.EntryContent
publishedAt *time.Time publishedAt *time.Time
metaData *MockEntryMetaData metaData *MockEntryMetaData
} }
@ -23,7 +22,7 @@ func (e *MockEntry) ID() string {
} }
func (e *MockEntry) Content() model.EntryContent { func (e *MockEntry) Content() model.EntryContent {
return e.content return model.EntryContent(e.metaData.Str)
} }
func (e *MockEntry) PublishedAt() *time.Time { func (e *MockEntry) PublishedAt() *time.Time {
@ -34,9 +33,8 @@ func (e *MockEntry) MetaData() interface{} {
return e.metaData 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.id = id
e.content = model.EntryContent(content)
e.publishedAt = publishedAt e.publishedAt = publishedAt
e.metaData = metaData.(*MockEntryMetaData) e.metaData = metaData.(*MockEntryMetaData)
return nil return nil

View File

@ -17,7 +17,6 @@ type MockEntryMetaData struct {
type MockEntry struct { type MockEntry struct {
id string id string
content model.EntryContent
publishedAt *time.Time publishedAt *time.Time
metaData *MockEntryMetaData metaData *MockEntryMetaData
} }
@ -27,7 +26,7 @@ func (e *MockEntry) ID() string {
} }
func (e *MockEntry) Content() model.EntryContent { func (e *MockEntry) Content() model.EntryContent {
return e.content return model.EntryContent(e.metaData.Content)
} }
func (e *MockEntry) PublishedAt() *time.Time { func (e *MockEntry) PublishedAt() *time.Time {
@ -38,9 +37,8 @@ func (e *MockEntry) MetaData() interface{} {
return e.metaData 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.id = id
e.content = model.EntryContent(content)
e.publishedAt = publishedAt e.publishedAt = publishedAt
e.metaData = metaData.(*MockEntryMetaData) e.metaData = metaData.(*MockEntryMetaData)
return nil return nil

View File

@ -19,7 +19,10 @@ func NewEditorHandler(entryService *app.EntryService) *EditorHandler {
func (h *EditorHandler) HandleGet(c *fiber.Ctx) error { func (h *EditorHandler) HandleGet(c *fiber.Ctx) error {
c.Set(fiber.HeaderContentType, fiber.MIMETextHTML) c.Set(fiber.HeaderContentType, fiber.MIMETextHTML)
formService := editor.NewEditorFormService(&model.ImageEntry{}) formService := editor.NewEditorFormService(&model.ImageEntry{})
form, _ := formService.HtmlForm() form, err := formService.HtmlForm()
if err != nil {
return err
}
return c.SendString(form) return c.SendString(form)
} }