package appregistry

import (
	"database/sql"

	"hyapp-admin-server/internal/response"

	"github.com/gin-gonic/gin"
)

type Handler struct {
	service *Service
}

func New(userDB *sql.DB) *Handler {
	return &Handler{service: NewService(userDB)}
}

func (h *Handler) ListApps(c *gin.Context) {
	items, err := h.service.ListApps(c.Request.Context())
	if err != nil {
		response.ServerError(c, "获取 App 列表失败")
		return
	}
	response.OK(c, gin.H{"items": items, "total": len(items)})
}
