implement Comics schema and endpoints

This commit is contained in:
2026-01-01 23:21:41 +01:00
parent a57cd9c294
commit fe919eaa35
6 changed files with 271 additions and 10 deletions
+42
View File
@@ -12,6 +12,8 @@ import (
func SetupComicRoutes(api fiber.Router) {
comics := api.Group("/comics")
comics.Get("/comics", GetAllComics)
comics.Get("/publishers", GetAllPublishers)
comics.Get("/comicworks", GetAllComicWorks)
}
func GetAllComics(c *fiber.Ctx) error {
@@ -33,3 +35,43 @@ func GetAllComics(c *fiber.Ctx) error {
return c.JSON(comics)
}
func GetAllPublishers(c *fiber.Ctx) error {
var publishers []schema.Publisher
var err error
var db *bun.DB
ctx := context.Background()
db, err = schema.GetDatabase()
if err != nil {
log.Fatal(err)
}
err = db.NewSelect().Model(&publishers).Relation("ParentPublisher").Scan(ctx)
if err != nil {
log.Fatal(err)
return fiber.NewError(fiber.StatusInternalServerError)
}
return c.JSON(publishers)
}
func GetAllComicWorks(c *fiber.Ctx) error {
var comic_works []schema.ComicWork
var err error
var db *bun.DB
ctx := context.Background()
db, err = schema.GetDatabase()
if err != nil {
log.Fatal(err)
}
err = db.NewSelect().Model(&comic_works).Relation("Comic").Relation("Artist").Relation("WorkType").Scan(ctx)
if err != nil {
log.Fatal(err)
return fiber.NewError(fiber.StatusInternalServerError)
}
return c.JSON(comic_works)
}