mirror of
https://github.com/Theodor-Springmann-Stiftung/musenalm.git
synced 2025-10-29 17:25:32 +00:00
Single Reihen Page
This commit is contained in:
64
pages/reihe.go
Normal file
64
pages/reihe.go
Normal file
@@ -0,0 +1,64 @@
|
||||
package pages
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
"strings"
|
||||
|
||||
"github.com/Theodor-Springmann-Stiftung/musenalm/app"
|
||||
"github.com/Theodor-Springmann-Stiftung/musenalm/dbmodels"
|
||||
"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"
|
||||
)
|
||||
|
||||
const (
|
||||
URL_REIHE = "/reihe/{id}/"
|
||||
TEMPLATE_REIHE = "/reihe/"
|
||||
)
|
||||
|
||||
func init() {
|
||||
rp := &ReihePage{
|
||||
Page: pagemodels.Page{
|
||||
Name: pagemodels.P_REIHEN_NAME,
|
||||
},
|
||||
}
|
||||
app.Register(rp)
|
||||
}
|
||||
|
||||
type ReihePage struct {
|
||||
pagemodels.Page
|
||||
}
|
||||
|
||||
func (p *ReihePage) Setup(router *router.Router[*core.RequestEvent], app core.App, engine *templating.Engine) error {
|
||||
router.GET(URL_REIHE, func(e *core.RequestEvent) error {
|
||||
id := e.Request.PathValue("id")
|
||||
data := make(map[string]interface{})
|
||||
reihe, err := dbmodels.SeriesForId(app, id)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
data["series"] = reihe
|
||||
|
||||
rmap, emap, err := dbmodels.EntriesForSeriesses(app, []*dbmodels.Series{reihe})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
data["relations"] = rmap
|
||||
data["entries"] = emap
|
||||
|
||||
return p.Get(e, engine, data)
|
||||
|
||||
})
|
||||
return nil
|
||||
}
|
||||
|
||||
func (p *ReihePage) Get(request *core.RequestEvent, engine *templating.Engine, data map[string]interface{}) error {
|
||||
var builder strings.Builder
|
||||
err := engine.Render(&builder, TEMPLATE_REIHE, data)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return request.HTML(http.StatusOK, builder.String())
|
||||
}
|
||||
@@ -15,7 +15,6 @@ import (
|
||||
|
||||
const (
|
||||
URL_REIHEN = "/reihen/"
|
||||
URL_REIHE = "/reihen/{id}/"
|
||||
PARAM_LETTER = "letter"
|
||||
PARAM_SEARCH = "search"
|
||||
PARAM_PERSON = "agent"
|
||||
|
||||
Reference in New Issue
Block a user