v2 #43
|
@ -10,7 +10,7 @@ type ImageEntry struct {
|
|||
}
|
||||
|
||||
type ImageEntryMetaData struct {
|
||||
ImagePath string
|
||||
ImagePath string `owl:"type=upload"`
|
||||
}
|
||||
|
||||
func (e *ImageEntry) ID() string {
|
||||
|
|
|
@ -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)
|
||||
}
|
|
@ -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 {
|
||||
|
|
Loading…
Reference in New Issue