mirror of
https://github.com/Theodor-Springmann-Stiftung/kgpz_web.git
synced 2025-10-28 16:45:32 +00:00
Started agent view
This commit is contained in:
@@ -1,12 +0,0 @@
|
||||
package controllers
|
||||
|
||||
import (
|
||||
"github.com/Theodor-Springmann-Stiftung/kgpz_web/app"
|
||||
"github.com/gofiber/fiber/v2"
|
||||
)
|
||||
|
||||
func GetAgent(kgpz *app.KGPZ) fiber.Handler {
|
||||
return func(c *fiber.Ctx) error {
|
||||
return c.Render("/akteur/", nil)
|
||||
}
|
||||
}
|
||||
@@ -1,12 +1,27 @@
|
||||
package controllers
|
||||
|
||||
import (
|
||||
"strings"
|
||||
|
||||
"github.com/Theodor-Springmann-Stiftung/kgpz_web/app"
|
||||
"github.com/Theodor-Springmann-Stiftung/kgpz_web/helpers/logging"
|
||||
"github.com/Theodor-Springmann-Stiftung/kgpz_web/viewmodels"
|
||||
"github.com/gofiber/fiber/v2"
|
||||
)
|
||||
|
||||
const (
|
||||
DEFAULT_AGENT = "a"
|
||||
)
|
||||
|
||||
func GetAgents(kgpz *app.KGPZ) fiber.Handler {
|
||||
return func(c *fiber.Ctx) error {
|
||||
return c.Render("/akteure/", nil)
|
||||
a := c.Params("letterorid", DEFAULT_AGENT)
|
||||
a = strings.ToLower(a)
|
||||
agents := viewmodels.AgentsView(a, kgpz.Library)
|
||||
if len(agents.Agents) == 0 {
|
||||
logging.Error(nil, "No agents found for letter or id: "+a)
|
||||
return c.SendStatus(fiber.StatusNotFound)
|
||||
}
|
||||
return c.Render("/akteure/", fiber.Map{"model": fiber.Map{"agents": agents, "search": a}, "title": "Akteure"})
|
||||
}
|
||||
}
|
||||
|
||||
@@ -26,6 +26,11 @@ const (
|
||||
CACHE_TIME = 24 * time.Hour
|
||||
|
||||
STATIC_PREFIX = "/assets"
|
||||
|
||||
EDITION_URL = "/edition/"
|
||||
PRIVACY_URL = "/datenschutz/"
|
||||
CONTACT_URL = "/kontakt/"
|
||||
CITATION_URL = "/zitation/"
|
||||
)
|
||||
|
||||
const (
|
||||
@@ -142,21 +147,20 @@ func (s *Server) Start() {
|
||||
c.Redirect("/1764")
|
||||
return nil
|
||||
})
|
||||
srv.Get("/:year", controllers.GetYear(s.kgpz))
|
||||
|
||||
// TODO: Same here, this prob applies to all paths with two or three segments, which is bad.
|
||||
// Prob better to do /ausgabe/:year/:issue/:page? here and /jahrgang/:year? above.
|
||||
srv.Get("/:year/:issue/:page?", controllers.GetIssue(s.kgpz))
|
||||
srv.Get("/:year/:issue/beilage/:page?", controllers.GetIssue(s.kgpz))
|
||||
|
||||
srv.Get("/ort/:place?", controllers.GetPlace(s.kgpz))
|
||||
srv.Get("/kategorie/:category?", controllers.GetCategory(s.kgpz))
|
||||
srv.Get("/akteure/:letterorid?", controllers.GetAgents(s.kgpz))
|
||||
|
||||
srv.Get("/edition/", controllers.Get("/edition/"))
|
||||
srv.Get("/datenschutz/", controllers.Get("/datenschutz/"))
|
||||
srv.Get("/kontakt/", controllers.Get("/kontakt/"))
|
||||
srv.Get("/zitation/", controllers.Get("/zitation/"))
|
||||
// TODO: Same here, this prob applies to all paths with two or three segments, which is bad.
|
||||
// Prob better to do /ausgabe/:year/:issue/:page? here and /jahrgang/:year? above.
|
||||
srv.Get("/:year", controllers.GetYear(s.kgpz))
|
||||
srv.Get("/:year/:issue/:page?", controllers.GetIssue(s.kgpz))
|
||||
srv.Get("/:year/:issue/beilage/:page?", controllers.GetIssue(s.kgpz))
|
||||
|
||||
srv.Get(EDITION_URL, controllers.Get(EDITION_URL))
|
||||
srv.Get(PRIVACY_URL, controllers.Get(PRIVACY_URL))
|
||||
srv.Get(CONTACT_URL, controllers.Get(CONTACT_URL))
|
||||
srv.Get(CITATION_URL, controllers.Get(CITATION_URL))
|
||||
|
||||
s.runner(srv)
|
||||
|
||||
|
||||
25
viewmodels/agentsvm.go
Normal file
25
viewmodels/agentsvm.go
Normal file
@@ -0,0 +1,25 @@
|
||||
package viewmodels
|
||||
|
||||
import (
|
||||
"strings"
|
||||
|
||||
"github.com/Theodor-Springmann-Stiftung/kgpz_web/providers/xmlprovider"
|
||||
)
|
||||
|
||||
type AgentView struct {
|
||||
Agents []xmlprovider.Agent
|
||||
}
|
||||
|
||||
func AgentsView(letterorid string, lib *xmlprovider.Library) *AgentView {
|
||||
res := AgentView{}
|
||||
lib.Agents.Items.Range(func(key, value interface{}) bool {
|
||||
k := key.(string)
|
||||
if strings.HasPrefix(k, letterorid) {
|
||||
agent := value.(xmlprovider.Agent)
|
||||
res.Agents = append(res.Agents, agent)
|
||||
}
|
||||
return true
|
||||
})
|
||||
|
||||
return &res
|
||||
}
|
||||
Reference in New Issue
Block a user