mirror of
https://github.com/Theodor-Springmann-Stiftung/musenalm.git
synced 2026-02-04 02:25:30 +00:00
+ make IApp available in the controllers
This commit is contained in:
@@ -16,33 +16,33 @@ type DefaultPage[T IPageCollection] struct {
|
||||
URL string
|
||||
}
|
||||
|
||||
func (r *DefaultPage[T]) Up(app core.App, engine *templating.Engine) error {
|
||||
_, err := app.FindCollectionByNameOrId(GeneratePageTableName(r.Name))
|
||||
func (r *DefaultPage[T]) Up(app IApp, engine *templating.Engine) error {
|
||||
_, err := app.Core().FindCollectionByNameOrId(GeneratePageTableName(r.Name))
|
||||
if err == sql.ErrNoRows {
|
||||
collection := r.Record.Collection(r.Name)
|
||||
err = app.Save(collection)
|
||||
err = app.Core().Save(collection)
|
||||
if err != nil {
|
||||
app.Logger().Error("Error saving collection", "Name", GeneratePageTableName(r.Name), "Error", err, "Collection", collection)
|
||||
app.Core().Logger().Error("Error saving collection", "Name", GeneratePageTableName(r.Name), "Error", err, "Collection", collection)
|
||||
return err
|
||||
}
|
||||
} else if err != nil {
|
||||
app.Logger().Error("Error finding collection %s: %s", GeneratePageTableName(r.Name), err)
|
||||
app.Core().Logger().Error("Error finding collection %s: %s", GeneratePageTableName(r.Name), err)
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (r *DefaultPage[T]) Down(app core.App, engine *templating.Engine) error {
|
||||
func (r *DefaultPage[T]) Down(app IApp, engine *templating.Engine) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (p *DefaultPage[T]) Setup(router *router.Router[*core.RequestEvent], app core.App, engine *templating.Engine) error {
|
||||
func (p *DefaultPage[T]) Setup(router *router.Router[*core.RequestEvent], app IApp, engine *templating.Engine) error {
|
||||
router.GET(p.URL, func(e *core.RequestEvent) error {
|
||||
data := make(map[string]interface{})
|
||||
|
||||
record := &core.Record{}
|
||||
err := app.RecordQuery(GeneratePageTableName(p.Name)).
|
||||
err := app.Core().RecordQuery(GeneratePageTableName(p.Name)).
|
||||
OrderBy("created").
|
||||
One(record)
|
||||
if err != nil {
|
||||
|
||||
@@ -4,11 +4,18 @@ import (
|
||||
"github.com/Theodor-Springmann-Stiftung/musenalm/templating"
|
||||
"github.com/pocketbase/pocketbase/core"
|
||||
"github.com/pocketbase/pocketbase/tools/router"
|
||||
"log/slog"
|
||||
)
|
||||
|
||||
type IPage interface {
|
||||
Up(app core.App, engine *templating.Engine) error
|
||||
Down(app core.App, engine *templating.Engine) error
|
||||
// TODO: pass the cache here
|
||||
Setup(router *router.Router[*core.RequestEvent], app core.App, engine *templating.Engine) error
|
||||
type IApp interface {
|
||||
Core() core.App
|
||||
ResetDataCache()
|
||||
ResetHtmlCache()
|
||||
Logger() *slog.Logger
|
||||
}
|
||||
|
||||
type IPage interface {
|
||||
Up(app IApp, engine *templating.Engine) error
|
||||
Down(app IApp, engine *templating.Engine) error
|
||||
Setup(router *router.Router[*core.RequestEvent], app IApp, engine *templating.Engine) error
|
||||
}
|
||||
|
||||
@@ -13,7 +13,7 @@ type StaticPage struct {
|
||||
URL string
|
||||
}
|
||||
|
||||
func (p *StaticPage) Setup(router *router.Router[*core.RequestEvent], app core.App, engine *templating.Engine) error {
|
||||
func (p *StaticPage) Setup(router *router.Router[*core.RequestEvent], ia IApp, engine *templating.Engine) error {
|
||||
router.GET(p.URL, func(e *core.RequestEvent) error {
|
||||
data := map[string]interface{}{}
|
||||
data["record"] = p
|
||||
@@ -22,10 +22,10 @@ func (p *StaticPage) Setup(router *router.Router[*core.RequestEvent], app core.A
|
||||
return nil
|
||||
}
|
||||
|
||||
func (p *StaticPage) Up(app core.App, engine *templating.Engine) error {
|
||||
func (p *StaticPage) Up(ia IApp, engine *templating.Engine) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (p *StaticPage) Down(app core.App, engine *templating.Engine) error {
|
||||
func (p *StaticPage) Down(ia IApp, engine *templating.Engine) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -52,15 +52,16 @@ func (r *TextPage) SetText(text string) {
|
||||
r.Set(F_TEXT, text)
|
||||
}
|
||||
|
||||
func (r *TextPage) Up(app core.App, engine *templating.Engine) error {
|
||||
func (r *TextPage) Up(ia IApp, engine *templating.Engine) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (r *TextPage) Down(app core.App, engine *templating.Engine) error {
|
||||
func (r *TextPage) Down(ia IApp, engine *templating.Engine) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (p *TextPage) Setup(router *router.Router[*core.RequestEvent], app core.App, engine *templating.Engine) error {
|
||||
func (p *TextPage) Setup(router *router.Router[*core.RequestEvent], ia IApp, engine *templating.Engine) error {
|
||||
app := ia.Core()
|
||||
router.GET(p.URL, func(e *core.RequestEvent) error {
|
||||
data := make(map[string]interface{})
|
||||
|
||||
|
||||
Reference in New Issue
Block a user