mirror of
https://github.com/Theodor-Springmann-Stiftung/kgpz_web.git
synced 2025-10-29 00:55:32 +00:00
restructured viewmodels, better serialization
This commit is contained in:
33
controllers/issue.go
Normal file
33
controllers/issue.go
Normal file
@@ -0,0 +1,33 @@
|
||||
package controllers
|
||||
|
||||
import (
|
||||
"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"
|
||||
)
|
||||
|
||||
func GetIssue(kgpz *app.KGPZ) fiber.Handler {
|
||||
return func(c *fiber.Ctx) error {
|
||||
y := c.Params("year")
|
||||
if len(y) != 4 {
|
||||
logging.Error(nil, "Year is not 4 characters long")
|
||||
return c.SendStatus(fiber.StatusNotFound)
|
||||
}
|
||||
|
||||
d := c.Params("issue")
|
||||
if d == "" {
|
||||
logging.Error(nil, "Issue number is empty")
|
||||
return c.SendStatus(fiber.StatusNotFound)
|
||||
}
|
||||
|
||||
issue, err := viewmodels.IssueView(y, d, kgpz.Library)
|
||||
|
||||
if err != nil {
|
||||
logging.Error(err, "Issue could not be found")
|
||||
return c.SendStatus(fiber.StatusNotFound)
|
||||
}
|
||||
|
||||
return c.Render("/issue/", fiber.Map{"model": issue})
|
||||
}
|
||||
}
|
||||
@@ -2,6 +2,8 @@ package controllers
|
||||
|
||||
import (
|
||||
"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"
|
||||
)
|
||||
|
||||
@@ -16,8 +18,9 @@ func GetYear(kgpz *app.KGPZ) fiber.Handler {
|
||||
return c.SendStatus(fiber.StatusBadRequest)
|
||||
}
|
||||
|
||||
issues := kgpz.Library.Issues.GetYear(y)
|
||||
if len(issues.Issues) == 0 {
|
||||
issues, err := viewmodels.YearView(y, kgpz.Library)
|
||||
if err != nil {
|
||||
logging.Error(err, "Keine Ausgaben für das Jahr "+y)
|
||||
return c.SendStatus(fiber.StatusNotFound)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user