package handler import ( "context" "net/http" "github.com/labstack/echo/v4" ) type FruitBackfiller interface { BackfillThumbnails(ctx context.Context) (int, error) } type PubBackfiller interface { BackfillThumbnails(ctx context.Context) (int, error) } type AdminHandler struct { fruitRepo FruitBackfiller pubRepo PubBackfiller } func NewAdminHandler(fruitRepo FruitBackfiller, pubRepo PubBackfiller) *AdminHandler { return &AdminHandler{fruitRepo: fruitRepo, pubRepo: pubRepo} } func (h *AdminHandler) BackfillThumbnails(c echo.Context) error { ctx := c.Request().Context() fruitCount, err := h.fruitRepo.BackfillThumbnails(ctx) if err != nil { return c.JSON(http.StatusInternalServerError, map[string]string{"error": "backfill failed: " + err.Error()}) } pubCount, err := h.pubRepo.BackfillThumbnails(ctx) if err != nil { return c.JSON(http.StatusInternalServerError, map[string]string{"error": "backfill failed: " + err.Error()}) } return c.JSON(http.StatusOK, map[string]int{ "fruit_images_processed": fruitCount, "pub_fruit_images_processed": pubCount, }) }