Files
kgpz_web/controllers/akteur_controller.go
2025-09-22 21:03:27 +02:00

60 lines
1.4 KiB
Go

package controllers
import (
"strings"
"github.com/Theodor-Springmann-Stiftung/kgpz_web/helpers/logging"
"github.com/Theodor-Springmann-Stiftung/kgpz_web/viewmodels"
"github.com/Theodor-Springmann-Stiftung/kgpz_web/xmlmodels"
"github.com/gofiber/fiber/v2"
)
const (
DEFAULT_AGENT = "a"
)
func GetAgents(kgpz *xmlmodels.Library) fiber.Handler {
return func(c *fiber.Ctx) error {
a := c.Params("letterorid", DEFAULT_AGENT)
a = strings.ToLower(a)
// Handle special "autoren" route
if a == "autoren" {
agents := viewmodels.AuthorsView(kgpz)
if len(agents.Agents) == 0 {
logging.Error(nil, "No authors found")
return c.SendStatus(fiber.StatusNotFound)
}
return c.Render(
"/autoren/",
fiber.Map{"model": agents},
)
}
// Handle special "anonym" route
if a == "anonym" {
anonymAgent := viewmodels.AnonymView(kgpz)
return c.Render(
"/akteure/",
fiber.Map{"model": &viewmodels.AgentsListView{
Search: "anonym",
AvailableLetters: []string{},
Agents: map[string]xmlmodels.Agent{"anonym": *anonymAgent},
Sorted: []string{"anonym"},
}},
)
}
// Handle normal letter/id lookup
agents := viewmodels.AgentsView(a, kgpz)
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": agents},
)
}
}