WIP more types

This commit is contained in:
Niko Abeler 2023-07-09 21:04:59 +02:00
parent 34119d5642
commit 9921b1f91e
5 changed files with 105 additions and 0 deletions

View File

@ -32,6 +32,9 @@ func App(db infra.Database) *web.WebApp {
registry := app.NewEntryTypeRegistry()
registry.Register(&model.Image{})
registry.Register(&model.Article{})
registry.Register(&model.Page{})
registry.Register(&model.Recipe{})
registry.Register(&model.Note{})
entryRepo := infra.NewEntryRepository(db, registry)
binRepo := infra.NewBinaryFileRepo(db)

26
domain/model/note.go Normal file
View File

@ -0,0 +1,26 @@
package model
type Note struct {
EntryBase
meta NoteMetaData
}
type NoteMetaData struct {
Content string `owl:"inputType=text widget=textarea"`
}
func (e *Note) Title() string {
return ""
}
func (e *Note) Content() EntryContent {
return EntryContent(e.meta.Content)
}
func (e *Note) MetaData() interface{} {
return &e.meta
}
func (e *Note) SetMetaData(metaData interface{}) {
e.meta = *metaData.(*NoteMetaData)
}

36
domain/model/page.go Normal file
View File

@ -0,0 +1,36 @@
package model
import (
"fmt"
"owl-blogs/render"
)
type Page struct {
EntryBase
meta PageMetaData
}
type PageMetaData struct {
Title string `owl:"inputType=text"`
Content string `owl:"inputType=text widget=textarea"`
}
func (e *Page) Title() string {
return e.meta.Title
}
func (e *Page) Content() EntryContent {
str, err := render.RenderTemplateToString("entry/Page", e)
if err != nil {
fmt.Println(err)
}
return EntryContent(str)
}
func (e *Page) MetaData() interface{} {
return &e.meta
}
func (e *Page) SetMetaData(metaData interface{}) {
e.meta = *metaData.(*PageMetaData)
}

39
domain/model/recipe.go Normal file
View File

@ -0,0 +1,39 @@
package model
import (
"fmt"
"owl-blogs/render"
)
type Recipe struct {
EntryBase
meta RecipeMetaData
}
type RecipeMetaData struct {
Title string `owl:"inputType=text"`
Yield string `owl:"inputType=text"`
Duration string `owl:"inputType=text"`
Ingredients []string `owl:"inputType=text widget=textarea"`
Content string `owl:"inputType=text widget=textarea"`
}
func (e *Recipe) Title() string {
return e.meta.Title
}
func (e *Recipe) Content() EntryContent {
str, err := render.RenderTemplateToString("entry/Recipe", e)
if err != nil {
fmt.Println(err)
}
return EntryContent(str)
}
func (e *Recipe) MetaData() interface{} {
return &e.meta
}
func (e *Recipe) SetMetaData(metaData interface{}) {
e.meta = *metaData.(*RecipeMetaData)
}

View File

@ -0,0 +1 @@
{{.MetaData.Content}}