From c2d3850a33851539a7cec2aef697198ac07580a3 Mon Sep 17 00:00:00 2001 From: ferreo Date: Tue, 30 Jul 2024 19:17:33 +0100 Subject: [PATCH] Fix old pacakge versions hanging around --- db/repository.go | 9 +++++++++ handlers/packages/package.go | 17 +++++++++++++++++ packages/packages.go | 4 ++++ server.go | 1 + 4 files changed, 31 insertions(+) create mode 100644 handlers/packages/package.go diff --git a/db/repository.go b/db/repository.go index afb6009..ea5dfb3 100644 --- a/db/repository.go +++ b/db/repository.go @@ -129,6 +129,15 @@ func (r *Repository) SavePackages(pkgs *haxmap.Map[string, domain.SourcePackage] return nil } +func (r *Repository) DropPackages() error { + tx := r.db.Where("1 = 1").Delete(&domain.SourcePackageDTO{}) + if tx.Error != nil { + return tx.Error + } + tx = r.db.Where("1 = 1").Delete(&domain.PackageInfo{}) + return tx.Error +} + func (r *Repository) UpdateLastUpdateTime(time time.Time) error { val := &domain.TimeContainer{ Time: time, diff --git a/handlers/packages/package.go b/handlers/packages/package.go new file mode 100644 index 0000000..09b6203 --- /dev/null +++ b/handlers/packages/package.go @@ -0,0 +1,17 @@ +package handlers_packages + +import ( + "brunel/packages" + + "github.com/gofiber/fiber/v2" +) + +func Package(c *fiber.Ctx) error { + pkgName := c.Params("package") + packs := packages.GetPackages() + pack, ok := packs.Get(pkgName) + if !ok { + return c.Status(fiber.StatusNotFound).SendString("Package not found") + } + return c.Status(fiber.StatusOK).JSON(pack) +} diff --git a/packages/packages.go b/packages/packages.go index 85bf258..1d6b340 100644 --- a/packages/packages.go +++ b/packages/packages.go @@ -92,6 +92,10 @@ func ProcessPackages() error { LastUpdateTime = time.Now() helpers.ReloadCache() + err = helpers.DBInst.DropPackages() + if err != nil { + return err + } err = SaveToDb() if err != nil { return err diff --git a/server.go b/server.go index b4f28a0..6b2d0bc 100644 --- a/server.go +++ b/server.go @@ -92,6 +92,7 @@ func runServer(ctx context.Context) error { server.Get("/api/counts", handlers_packages.Counts) server.Get("/api/packages", handlers_packages.Packages) + server.Get("/api/package/:package", handlers_packages.Package) server.Get("/api/queue", handlers_build.Queue) server.Get("/api/errored", handlers_build.Errored)