2026-04-19 14:18:20 +08:00
|
|
|
package transport
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"github.com/gin-gonic/gin"
|
|
|
|
|
|
|
|
|
|
"github.com/geo-platform/tenant-api/internal/bootstrap"
|
|
|
|
|
"github.com/geo-platform/tenant-api/internal/shared/auth"
|
|
|
|
|
"github.com/geo-platform/tenant-api/internal/shared/response"
|
|
|
|
|
"github.com/geo-platform/tenant-api/internal/tenant/app"
|
|
|
|
|
"github.com/geo-platform/tenant-api/internal/tenant/repository"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
type DesktopClientHandler struct {
|
|
|
|
|
svc *app.DesktopClientService
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func NewDesktopClientHandler(a *bootstrap.App) *DesktopClientHandler {
|
2026-04-23 09:11:23 +08:00
|
|
|
taskSvc := app.NewDesktopTaskService(
|
|
|
|
|
a.DB,
|
|
|
|
|
a.MonitoringDB,
|
|
|
|
|
a.RabbitMQ,
|
|
|
|
|
a.Logger,
|
2026-04-28 09:14:24 +08:00
|
|
|
).WithCache(a.Cache).WithRedis(a.Redis)
|
2026-04-19 14:18:20 +08:00
|
|
|
return &DesktopClientHandler{
|
|
|
|
|
svc: app.NewDesktopClientService(
|
|
|
|
|
repository.NewDesktopClientRepository(a.DB),
|
2026-04-20 09:52:48 +08:00
|
|
|
a.Redis,
|
2026-04-23 09:11:23 +08:00
|
|
|
).WithTaskService(taskSvc),
|
2026-04-19 14:18:20 +08:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (h *DesktopClientHandler) Register(c *gin.Context) {
|
|
|
|
|
actor := auth.MustActor(c.Request.Context())
|
|
|
|
|
|
|
|
|
|
var req app.RegisterDesktopClientRequest
|
|
|
|
|
if err := c.ShouldBindJSON(&req); err != nil {
|
|
|
|
|
response.Error(c, response.ErrBadRequest(40001, "invalid_params", err.Error()))
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
data, err := h.svc.Register(c.Request.Context(), actor, req)
|
|
|
|
|
if err != nil {
|
|
|
|
|
response.Error(c, err)
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
response.SuccessWithStatus(c, 201, data)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (h *DesktopClientHandler) Rotate(c *gin.Context) {
|
|
|
|
|
data, err := h.svc.Rotate(c.Request.Context(), MustDesktopClient(c.Request.Context()))
|
|
|
|
|
if err != nil {
|
|
|
|
|
response.Error(c, err)
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
response.Success(c, data)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (h *DesktopClientHandler) Heartbeat(c *gin.Context) {
|
|
|
|
|
var req app.HeartbeatDesktopClientRequest
|
|
|
|
|
if err := c.ShouldBindJSON(&req); err != nil {
|
|
|
|
|
response.Error(c, response.ErrBadRequest(40001, "invalid_params", err.Error()))
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
data, err := h.svc.Heartbeat(c.Request.Context(), MustDesktopClient(c.Request.Context()), req)
|
|
|
|
|
if err != nil {
|
|
|
|
|
response.Error(c, err)
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
response.Success(c, data)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (h *DesktopClientHandler) Revoke(c *gin.Context) {
|
|
|
|
|
data, err := h.svc.Revoke(c.Request.Context(), MustDesktopClient(c.Request.Context()))
|
|
|
|
|
if err != nil {
|
|
|
|
|
response.Error(c, err)
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
response.Success(c, data)
|
|
|
|
|
}
|
2026-04-20 09:52:48 +08:00
|
|
|
|
|
|
|
|
func (h *DesktopClientHandler) Offline(c *gin.Context) {
|
|
|
|
|
data, err := h.svc.Offline(c.Request.Context(), MustDesktopClient(c.Request.Context()))
|
|
|
|
|
if err != nil {
|
|
|
|
|
response.Error(c, err)
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
response.Success(c, data)
|
|
|
|
|
}
|