experiments for editor

This commit is contained in:
Niko Abeler 2023-06-25 22:09:27 +02:00
parent 5d97d87c9b
commit 1742728639
3 changed files with 54 additions and 2 deletions

View File

@ -10,7 +10,7 @@ type ImageEntry struct {
}
type ImageEntryMetaData struct {
ImagePath string
ImagePath string `owl:"type=upload"`
}
func (e *ImageEntry) ID() string {

49
web/editor/entry_form.go Normal file
View File

@ -0,0 +1,49 @@
package editor
import (
"fmt"
"owl-blogs/domain/model"
"reflect"
"strings"
)
type EditorEntryForm struct {
entry model.Entry
}
type EntryFormField struct {
Name string
Params map[string]string
}
func NewEditorFormService(entry model.Entry) *EditorEntryForm {
return &EditorEntryForm{
entry: entry,
}
}
func (s *EditorEntryForm) HtmlForm() string {
meta := s.entry.MetaData()
entryType := reflect.TypeOf(meta).Elem()
numFields := entryType.NumField()
fields := []EntryFormField{}
for i := 0; i < numFields; i++ {
field := EntryFormField{
Name: entryType.Field(i).Name,
Params: map[string]string{},
}
tag := entryType.Field(i).Tag.Get("owl")
for _, param := range strings.Split(tag, " ") {
parts := strings.Split(param, "=")
if len(parts) == 2 {
field.Params[parts[0]] = parts[1]
} else {
field.Params[param] = ""
}
}
fields = append(fields, field)
}
return fmt.Sprintf("%v", fields)
}

View File

@ -2,6 +2,8 @@ package web
import (
"owl-blogs/app"
"owl-blogs/domain/model"
"owl-blogs/web/editor"
"github.com/gofiber/fiber/v2"
)
@ -15,7 +17,8 @@ func NewEditorHandler(entryService *app.EntryService) *EditorHandler {
}
func (h *EditorHandler) HandleGet(c *fiber.Ctx) error {
return c.SendString("Hello, Editor!")
form := editor.NewEditorFormService(&model.ImageEntry{})
return c.SendString(form.HtmlForm())
}
func (h *EditorHandler) HandlePost(c *fiber.Ctx) error {