+ make IApp available in the controllers

This commit is contained in:
Simon Martens
2026-01-14 15:17:26 +01:00
parent d4881a589a
commit ec47dcb147
35 changed files with 240 additions and 97 deletions

View File

@@ -24,7 +24,7 @@ type ErrorPage struct {
pagemodels.StaticPage
}
func (p *ErrorPage) Setup(router *router.Router[*core.RequestEvent], app core.App, engine *templating.Engine) error {
func (p *ErrorPage) Setup(router *router.Router[*core.RequestEvent], ia pagemodels.IApp, engine *templating.Engine) error {
router.GET(URL_ERROR_404, func(e *core.RequestEvent) error {
return engine.Response404(e, nil, nil)
})

View File

@@ -49,12 +49,13 @@ type AbkuerzungenResult struct {
Entries []AbkEntry
}
func (p *AbkuerzungenPage) Setup(router *router.Router[*core.RequestEvent], app core.App, engine *templating.Engine) error {
func (p *AbkuerzungenPage) Setup(router *router.Router[*core.RequestEvent], ia pagemodels.IApp, engine *templating.Engine) error {
app := ia.Core()
router.GET(URL_ABKUERZUNGEN, p.GET(engine, app))
rg := router.Group(URL_ABKUERZUNGEN)
rg.BindFunc(middleware.IsAdminOrEditor())
rg.POST("", p.POST(engine, app))
rg.POST("", p.POST(engine, ia))
return nil
}
@@ -123,8 +124,9 @@ type abkFormEntry struct {
Delete string `form:"_delete"`
}
func (p *AbkuerzungenPage) POST(engine *templating.Engine, app core.App) HandleFunc {
func (p *AbkuerzungenPage) POST(engine *templating.Engine, ia pagemodels.IApp) HandleFunc {
return func(e *core.RequestEvent) error {
app := ia.Core()
req := templating.NewRequest(e)
// Parse form manually to handle array syntax
@@ -198,6 +200,8 @@ func (p *AbkuerzungenPage) POST(engine *templating.Engine, app core.App) HandleF
return p.redirectError(e, "Speichern fehlgeschlagen.")
}
go ia.ResetDataCache()
// Redirect with success message
redirect := fmt.Sprintf("%s?success=%s", URL_ABKUERZUNGEN, url.QueryEscape("Änderungen gespeichert."))
return e.Redirect(http.StatusSeeOther, redirect)

View File

@@ -80,7 +80,8 @@ type AlmanachPage struct {
pagemodels.StaticPage
}
func (p *AlmanachPage) Setup(router *router.Router[*core.RequestEvent], app core.App, engine *templating.Engine) error {
func (p *AlmanachPage) Setup(router *router.Router[*core.RequestEvent], ia pagemodels.IApp, engine *templating.Engine) error {
app := ia.Core()
router.GET(p.URL, p.GET(engine, app))
return nil
}

View File

@@ -40,7 +40,8 @@ type AlmanachEditPage struct {
pagemodels.StaticPage
}
func (p *AlmanachEditPage) Setup(router *router.Router[*core.RequestEvent], app core.App, engine *templating.Engine) error {
func (p *AlmanachEditPage) Setup(router *router.Router[*core.RequestEvent], ia pagemodels.IApp, engine *templating.Engine) error {
app := ia.Core()
rg := router.Group(URL_ALMANACH)
rg.BindFunc(middleware.IsAdminOrEditor())
rg.GET(URL_ALMANACH_EDIT, p.GET(engine, app))

View File

@@ -35,7 +35,8 @@ type AlmanachNewPage struct {
pagemodels.StaticPage
}
func (p *AlmanachNewPage) Setup(router *router.Router[*core.RequestEvent], app core.App, engine *templating.Engine) error {
func (p *AlmanachNewPage) Setup(router *router.Router[*core.RequestEvent], ia pagemodels.IApp, engine *templating.Engine) error {
app := ia.Core()
rg := router.Group(URL_ALMANACH_NEW)
rg.BindFunc(middleware.IsAdminOrEditor())
rg.GET("", p.GET(engine, app))

View File

@@ -8,6 +8,7 @@ import (
"github.com/Theodor-Springmann-Stiftung/musenalm/app"
"github.com/Theodor-Springmann-Stiftung/musenalm/dbmodels"
"github.com/Theodor-Springmann-Stiftung/musenalm/middleware"
"github.com/Theodor-Springmann-Stiftung/musenalm/pagemodels"
"github.com/Theodor-Springmann-Stiftung/musenalm/templating"
"github.com/pocketbase/pocketbase/core"
"github.com/pocketbase/pocketbase/tools/router"
@@ -24,15 +25,16 @@ func init() {
type AgentsAPI struct{}
func (p *AgentsAPI) Up(app core.App, engine *templating.Engine) error {
func (p *AgentsAPI) Up(ia pagemodels.IApp, engine *templating.Engine) error {
return nil
}
func (p *AgentsAPI) Down(app core.App, engine *templating.Engine) error {
func (p *AgentsAPI) Down(ia pagemodels.IApp, engine *templating.Engine) error {
return nil
}
func (p *AgentsAPI) Setup(router *router.Router[*core.RequestEvent], app core.App, engine *templating.Engine) error {
func (p *AgentsAPI) Setup(router *router.Router[*core.RequestEvent], ia pagemodels.IApp, engine *templating.Engine) error {
app := ia.Core()
rg := router.Group(URL_API_AGENTS)
rg.BindFunc(middleware.Authenticated(app))
rg.BindFunc(middleware.IsAdminOrEditor())

View File

@@ -8,6 +8,7 @@ import (
"github.com/Theodor-Springmann-Stiftung/musenalm/app"
"github.com/Theodor-Springmann-Stiftung/musenalm/dbmodels"
"github.com/Theodor-Springmann-Stiftung/musenalm/middleware"
"github.com/Theodor-Springmann-Stiftung/musenalm/pagemodels"
"github.com/Theodor-Springmann-Stiftung/musenalm/templating"
"github.com/pocketbase/pocketbase/core"
"github.com/pocketbase/pocketbase/tools/router"
@@ -24,15 +25,16 @@ func init() {
type EntriesAPI struct{}
func (p *EntriesAPI) Up(app core.App, engine *templating.Engine) error {
func (p *EntriesAPI) Up(ia pagemodels.IApp, engine *templating.Engine) error {
return nil
}
func (p *EntriesAPI) Down(app core.App, engine *templating.Engine) error {
func (p *EntriesAPI) Down(ia pagemodels.IApp, engine *templating.Engine) error {
return nil
}
func (p *EntriesAPI) Setup(router *router.Router[*core.RequestEvent], app core.App, engine *templating.Engine) error {
func (p *EntriesAPI) Setup(router *router.Router[*core.RequestEvent], ia pagemodels.IApp, engine *templating.Engine) error {
app := ia.Core()
rg := router.Group(URL_API_ENTRIES)
rg.BindFunc(middleware.Authenticated(app))
rg.BindFunc(middleware.IsAdminOrEditor())

View File

@@ -8,6 +8,7 @@ import (
"github.com/Theodor-Springmann-Stiftung/musenalm/app"
"github.com/Theodor-Springmann-Stiftung/musenalm/dbmodels"
"github.com/Theodor-Springmann-Stiftung/musenalm/middleware"
"github.com/Theodor-Springmann-Stiftung/musenalm/pagemodels"
"github.com/Theodor-Springmann-Stiftung/musenalm/templating"
"github.com/pocketbase/pocketbase/core"
"github.com/pocketbase/pocketbase/tools/router"
@@ -24,15 +25,16 @@ func init() {
type PlacesAPI struct{}
func (p *PlacesAPI) Up(app core.App, engine *templating.Engine) error {
func (p *PlacesAPI) Up(ia pagemodels.IApp, engine *templating.Engine) error {
return nil
}
func (p *PlacesAPI) Down(app core.App, engine *templating.Engine) error {
func (p *PlacesAPI) Down(ia pagemodels.IApp, engine *templating.Engine) error {
return nil
}
func (p *PlacesAPI) Setup(router *router.Router[*core.RequestEvent], app core.App, engine *templating.Engine) error {
func (p *PlacesAPI) Setup(router *router.Router[*core.RequestEvent], ia pagemodels.IApp, engine *templating.Engine) error {
app := ia.Core()
rg := router.Group(URL_API_PLACES)
rg.BindFunc(middleware.Authenticated(app))
rg.BindFunc(middleware.IsAdminOrEditor())

View File

@@ -8,6 +8,7 @@ import (
"github.com/Theodor-Springmann-Stiftung/musenalm/app"
"github.com/Theodor-Springmann-Stiftung/musenalm/dbmodels"
"github.com/Theodor-Springmann-Stiftung/musenalm/middleware"
"github.com/Theodor-Springmann-Stiftung/musenalm/pagemodels"
"github.com/Theodor-Springmann-Stiftung/musenalm/templating"
"github.com/pocketbase/pocketbase/core"
"github.com/pocketbase/pocketbase/tools/router"
@@ -24,15 +25,16 @@ func init() {
type SeriesAPI struct{}
func (p *SeriesAPI) Up(app core.App, engine *templating.Engine) error {
func (p *SeriesAPI) Up(ia pagemodels.IApp, engine *templating.Engine) error {
return nil
}
func (p *SeriesAPI) Down(app core.App, engine *templating.Engine) error {
func (p *SeriesAPI) Down(ia pagemodels.IApp, engine *templating.Engine) error {
return nil
}
func (p *SeriesAPI) Setup(router *router.Router[*core.RequestEvent], app core.App, engine *templating.Engine) error {
func (p *SeriesAPI) Setup(router *router.Router[*core.RequestEvent], ia pagemodels.IApp, engine *templating.Engine) error {
app := ia.Core()
rg := router.Group(URL_API_SERIES)
rg.BindFunc(middleware.Authenticated(app))
rg.BindFunc(middleware.IsAdminOrEditor())

View File

@@ -31,7 +31,8 @@ type BeitragPage struct {
pagemodels.StaticPage
}
func (p *BeitragPage) Setup(router *router.Router[*core.RequestEvent], app core.App, engine *templating.Engine) error {
func (p *BeitragPage) Setup(router *router.Router[*core.RequestEvent], ia pagemodels.IApp, engine *templating.Engine) error {
app := ia.Core()
router.GET(p.URL, func(e *core.RequestEvent) error {
id := e.Request.PathValue("id")
data := make(map[string]any)

View File

@@ -25,7 +25,8 @@ type IndexPage struct {
}
// TODO:
func (p *IndexPage) Setup(router *router.Router[*core.RequestEvent], app core.App, engine *templating.Engine) error {
func (p *IndexPage) Setup(router *router.Router[*core.RequestEvent], ia pagemodels.IApp, engine *templating.Engine) error {
app := ia.Core()
router.GET("/{$}", func(e *core.RequestEvent) error {
bilder := []*pagemodels.IndexBilder{}
err := app.RecordQuery(pagemodels.GeneratePageTableName(pagemodels.P_INDEX_NAME, pagemodels.T_INDEX_BILDER)).

View File

@@ -47,7 +47,8 @@ type LoginPage struct {
pagemodels.StaticPage
}
func (p *LoginPage) Setup(router *router.Router[*core.RequestEvent], app core.App, engine *templating.Engine) error {
func (p *LoginPage) Setup(router *router.Router[*core.RequestEvent], ia pagemodels.IApp, engine *templating.Engine) error {
app := ia.Core()
router.GET(URL_LOGIN, p.GET(engine, app))
r := router.POST(URL_LOGIN, p.POST(engine, app))
r.BindFunc(middleware.RateLimiter(30, time.Minute*2, time.Hour*6))

View File

@@ -28,7 +28,8 @@ type LogoutPage struct {
pagemodels.StaticPage
}
func (p *LogoutPage) Setup(router *router.Router[*core.RequestEvent], app core.App, engine *templating.Engine) error {
func (p *LogoutPage) Setup(router *router.Router[*core.RequestEvent], ia pagemodels.IApp, engine *templating.Engine) error {
app := ia.Core()
router.GET(p.URL, p.GET(app))
return nil
}

View File

@@ -41,7 +41,8 @@ type OrtEditPage struct {
pagemodels.StaticPage
}
func (p *OrtEditPage) Setup(router *router.Router[*core.RequestEvent], app core.App, engine *templating.Engine) error {
func (p *OrtEditPage) Setup(router *router.Router[*core.RequestEvent], ia pagemodels.IApp, engine *templating.Engine) error {
app := ia.Core()
rg := router.Group(URL_ORT)
rg.BindFunc(middleware.IsAdminOrEditor())
rg.GET(URL_ORT_EDIT, p.GET(engine, app))

View File

@@ -36,7 +36,8 @@ type OrtNewPage struct {
pagemodels.StaticPage
}
func (p *OrtNewPage) Setup(router *router.Router[*core.RequestEvent], app core.App, engine *templating.Engine) error {
func (p *OrtNewPage) Setup(router *router.Router[*core.RequestEvent], ia pagemodels.IApp, engine *templating.Engine) error {
app := ia.Core()
rg := router.Group(URL_ORTE_NEW)
rg.BindFunc(middleware.IsAdminOrEditor())
rg.GET("", p.GET(engine, app))

View File

@@ -34,7 +34,8 @@ type OrteResult struct {
Places []*dbmodels.Place
}
func (p *OrtePage) Setup(router *router.Router[*core.RequestEvent], app core.App, engine *templating.Engine) error {
func (p *OrtePage) Setup(router *router.Router[*core.RequestEvent], ia pagemodels.IApp, engine *templating.Engine) error {
app := ia.Core()
router.GET(URL_ORTE, func(e *core.RequestEvent) error {
places := []*dbmodels.Place{}
if err := app.RecordQuery(dbmodels.PLACES_TABLE).All(&places); err != nil {

View File

@@ -34,7 +34,8 @@ type PersonPage struct {
pagemodels.StaticPage
}
func (p *PersonPage) Setup(router *router.Router[*core.RequestEvent], app core.App, engine *templating.Engine) error {
func (p *PersonPage) Setup(router *router.Router[*core.RequestEvent], ia pagemodels.IApp, engine *templating.Engine) error {
app := ia.Core()
router.GET(URL_PERSON, func(e *core.RequestEvent) error {
person := e.Request.PathValue("id")
data := make(map[string]interface{})

View File

@@ -38,7 +38,8 @@ type PersonEditPage struct {
pagemodels.StaticPage
}
func (p *PersonEditPage) Setup(router *router.Router[*core.RequestEvent], app core.App, engine *templating.Engine) error {
func (p *PersonEditPage) Setup(router *router.Router[*core.RequestEvent], ia pagemodels.IApp, engine *templating.Engine) error {
app := ia.Core()
rg := router.Group("/person/{id}/")
rg.BindFunc(middleware.IsAdminOrEditor())
rg.GET(URL_PERSON_EDIT, p.GET(engine, app))

View File

@@ -36,7 +36,8 @@ type PersonNewPage struct {
pagemodels.StaticPage
}
func (p *PersonNewPage) Setup(router *router.Router[*core.RequestEvent], app core.App, engine *templating.Engine) error {
func (p *PersonNewPage) Setup(router *router.Router[*core.RequestEvent], ia pagemodels.IApp, engine *templating.Engine) error {
app := ia.Core()
rg := router.Group(URL_PERSONEN_NEW)
rg.BindFunc(middleware.IsAdminOrEditor())
rg.GET("", p.GET(engine, app))

View File

@@ -28,7 +28,8 @@ type PersonenPage struct {
pagemodels.StaticPage
}
func (p *PersonenPage) Setup(router *router.Router[*core.RequestEvent], app core.App, engine *templating.Engine) error {
func (p *PersonenPage) Setup(router *router.Router[*core.RequestEvent], ia pagemodels.IApp, engine *templating.Engine) error {
app := ia.Core()
router.GET(URL_PERSONEN, func(e *core.RequestEvent) error {
if e.Request.URL.Query().Get(PARAM_SEARCH) != "" {
return p.SearchRequest(app, engine, e)

View File

@@ -31,7 +31,8 @@ type ReihePage struct {
}
// TODO: data richtig seutzen, damit die Reihe mit dem template _reihe angezeigt wird
func (p *ReihePage) Setup(router *router.Router[*core.RequestEvent], app core.App, engine *templating.Engine) error {
func (p *ReihePage) Setup(router *router.Router[*core.RequestEvent], ia pagemodels.IApp, engine *templating.Engine) error {
app := ia.Core()
router.GET(URL_REIHE, func(e *core.RequestEvent) error {
id := e.Request.PathValue("id")
data := make(map[string]interface{})

View File

@@ -39,7 +39,8 @@ type ReiheEditPage struct {
pagemodels.StaticPage
}
func (p *ReiheEditPage) Setup(router *router.Router[*core.RequestEvent], app core.App, engine *templating.Engine) error {
func (p *ReiheEditPage) Setup(router *router.Router[*core.RequestEvent], ia pagemodels.IApp, engine *templating.Engine) error {
app := ia.Core()
rg := router.Group(URL_REIHE)
rg.BindFunc(middleware.IsAdminOrEditor())
rg.GET(URL_REIHE_EDIT, p.GET(engine, app))

View File

@@ -36,7 +36,8 @@ type ReiheNewPage struct {
pagemodels.StaticPage
}
func (p *ReiheNewPage) Setup(router *router.Router[*core.RequestEvent], app core.App, engine *templating.Engine) error {
func (p *ReiheNewPage) Setup(router *router.Router[*core.RequestEvent], ia pagemodels.IApp, engine *templating.Engine) error {
app := ia.Core()
rg := router.Group(URL_REIHEN_NEW)
rg.BindFunc(middleware.IsAdminOrEditor())
rg.GET("", p.GET(engine, app))

View File

@@ -40,7 +40,8 @@ type ReihenPage struct {
pagemodels.DefaultPage[*pagemodels.DefaultPageRecord]
}
func (p *ReihenPage) Setup(router *router.Router[*core.RequestEvent], app core.App, engine *templating.Engine) error {
func (p *ReihenPage) Setup(router *router.Router[*core.RequestEvent], ia pagemodels.IApp, engine *templating.Engine) error {
app := ia.Core()
router.GET(URL_REIHEN, func(e *core.RequestEvent) error {
search := e.Request.URL.Query().Get(PARAM_SEARCH)
if search != "" {

View File

@@ -42,7 +42,8 @@ func init() {
app.Register(rp)
}
func (p *SuchePage) Setup(router *router.Router[*core.RequestEvent], app core.App, engine *templating.Engine) error {
func (p *SuchePage) Setup(router *router.Router[*core.RequestEvent], ia pagemodels.IApp, engine *templating.Engine) error {
app := ia.Core()
router.GET(URL_SUCHE_ALT, func(e *core.RequestEvent) error {
return e.Redirect(http.StatusPermanentRedirect, DEFAULT_SUCHE)
})

View File

@@ -34,7 +34,8 @@ type UserCreatePage struct {
pagemodels.StaticPage
}
func (p *UserCreatePage) Setup(router *router.Router[*core.RequestEvent], app core.App, engine *templating.Engine) error {
func (p *UserCreatePage) Setup(router *router.Router[*core.RequestEvent], ia pagemodels.IApp, engine *templating.Engine) error {
app := ia.Core()
rg := router.Group(URL_USER_CREATE)
rg.BindFunc(middleware.HasToken())
rg.GET("{"+PATH_VALUE_ROLE+"}", p.GET(engine, app))

View File

@@ -40,7 +40,8 @@ type UserEditPage struct {
pagemodels.StaticPage
}
func (p *UserEditPage) Setup(router *router.Router[*core.RequestEvent], app core.App, engine *templating.Engine) error {
func (p *UserEditPage) Setup(router *router.Router[*core.RequestEvent], ia pagemodels.IApp, engine *templating.Engine) error {
app := ia.Core()
rg := router.Group(URL_USER)
rg.BindFunc(middleware.IsAdminOrUser())
rg.GET(URL_USER_EDIT, p.GET(engine, app))

View File

@@ -42,7 +42,8 @@ type UserManagementPage struct {
pagemodels.StaticPage
}
func (p *UserManagementPage) Setup(router *router.Router[*core.RequestEvent], app core.App, engine *templating.Engine) error {
func (p *UserManagementPage) Setup(router *router.Router[*core.RequestEvent], ia pagemodels.IApp, engine *templating.Engine) error {
app := ia.Core()
rg := router.Group(URL_USER_MANAGEMENT)
rg.BindFunc(middleware.IsAdmin())
rg.GET("", p.GET(engine, app))

View File

@@ -35,7 +35,8 @@ type UserManagementAccessPage struct {
pagemodels.StaticPage
}
func (p *UserManagementAccessPage) Setup(router *router.Router[*core.RequestEvent], app core.App, engine *templating.Engine) error {
func (p *UserManagementAccessPage) Setup(router *router.Router[*core.RequestEvent], ia pagemodels.IApp, engine *templating.Engine) error {
app := ia.Core()
rg := router.Group(URL_USER_MANAGEMENT_ACCESS)
rg.BindFunc(middleware.IsAdmin())
rg.GET("{"+PATH_VALUE_ROLE+"}", p.GET(engine, app))