a617d39a4a
SaaS 侧人工审核后才创建 publish job,desktop 不再做二次审核:移除 manual/waiting_user/parked/from_parked 状态机与 LeaseFromParked 查询, desktop client 只执行发布并新增"发布管理"页(待发布队列 / 历史 / 再次 发送)。同时抽离 @geo/publisher-platforms 共享适配器包、新增 Redis-based desktop_presence 与 publish_record_support,刷新 admin-web 发布弹窗与 媒体库;plan A / spec 文档同步口径。
125 lines
3.5 KiB
Go
125 lines
3.5 KiB
Go
package transport
|
|
|
|
import (
|
|
"strconv"
|
|
|
|
"github.com/gin-gonic/gin"
|
|
"github.com/google/uuid"
|
|
|
|
"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 DesktopAccountHandler struct {
|
|
svc *app.DesktopAccountService
|
|
}
|
|
|
|
func NewDesktopAccountHandler(a *bootstrap.App) *DesktopAccountHandler {
|
|
return &DesktopAccountHandler{
|
|
svc: app.NewDesktopAccountService(
|
|
repository.NewDesktopAccountRepository(a.DB),
|
|
repository.NewDesktopClientRepository(a.DB),
|
|
a.Redis,
|
|
),
|
|
}
|
|
}
|
|
|
|
func (h *DesktopAccountHandler) List(c *gin.Context) {
|
|
if clientQuery := c.Query("client"); clientQuery != "" && clientQuery != "self" {
|
|
response.Error(c, response.ErrBadRequest(40081, "invalid_client_query", "client query must be self"))
|
|
return
|
|
}
|
|
|
|
data, err := h.svc.ListByUser(c.Request.Context(), MustDesktopClient(c.Request.Context()))
|
|
if err != nil {
|
|
response.Error(c, err)
|
|
return
|
|
}
|
|
response.Success(c, data)
|
|
}
|
|
|
|
func (h *DesktopAccountHandler) TenantList(c *gin.Context) {
|
|
data, err := h.svc.ListForActor(c.Request.Context(), auth.MustActor(c.Request.Context()))
|
|
if err != nil {
|
|
response.Error(c, err)
|
|
return
|
|
}
|
|
response.Success(c, data)
|
|
}
|
|
|
|
func (h *DesktopAccountHandler) Upsert(c *gin.Context) {
|
|
var req app.UpsertDesktopAccountRequest
|
|
if err := c.ShouldBindJSON(&req); err != nil {
|
|
response.Error(c, response.ErrBadRequest(40001, "invalid_params", err.Error()))
|
|
return
|
|
}
|
|
|
|
data, err := h.svc.Upsert(c.Request.Context(), MustDesktopClient(c.Request.Context()), req)
|
|
if err != nil {
|
|
response.Error(c, err)
|
|
return
|
|
}
|
|
response.SuccessWithStatus(c, 201, data)
|
|
}
|
|
|
|
func (h *DesktopAccountHandler) Patch(c *gin.Context) {
|
|
desktopID, err := uuid.Parse(c.Param("id"))
|
|
if err != nil {
|
|
response.Error(c, response.ErrBadRequest(40082, "invalid_desktop_account_id", "desktop account id must be a uuid"))
|
|
return
|
|
}
|
|
|
|
var req app.PatchDesktopAccountRequest
|
|
if err := c.ShouldBindJSON(&req); err != nil {
|
|
response.Error(c, response.ErrBadRequest(40001, "invalid_params", err.Error()))
|
|
return
|
|
}
|
|
|
|
data, err := h.svc.Patch(c.Request.Context(), MustDesktopClient(c.Request.Context()), desktopID, req)
|
|
if err != nil {
|
|
response.Error(c, err)
|
|
return
|
|
}
|
|
response.Success(c, data)
|
|
}
|
|
|
|
func (h *DesktopAccountHandler) Delete(c *gin.Context) {
|
|
desktopID, err := uuid.Parse(c.Param("id"))
|
|
if err != nil {
|
|
response.Error(c, response.ErrBadRequest(40082, "invalid_desktop_account_id", "desktop account id must be a uuid"))
|
|
return
|
|
}
|
|
|
|
ifSyncVersion, err := strconv.ParseInt(c.Query("if_sync_version"), 10, 64)
|
|
if err != nil {
|
|
response.Error(c, response.ErrBadRequest(40083, "invalid_sync_version", "if_sync_version must be an integer"))
|
|
return
|
|
}
|
|
|
|
data, err := h.svc.Tombstone(c.Request.Context(), MustDesktopClient(c.Request.Context()), desktopID, ifSyncVersion)
|
|
if err != nil {
|
|
response.Error(c, err)
|
|
return
|
|
}
|
|
response.Success(c, data)
|
|
}
|
|
|
|
func (h *DesktopAccountHandler) RequestDelete(c *gin.Context) {
|
|
desktopID, err := uuid.Parse(c.Param("id"))
|
|
if err != nil {
|
|
response.Error(c, response.ErrBadRequest(40082, "invalid_desktop_account_id", "desktop account id must be a uuid"))
|
|
return
|
|
}
|
|
|
|
actor := auth.MustActor(c.Request.Context())
|
|
data, err := h.svc.RequestDelete(c.Request.Context(), actor, desktopID, c.Query("undo") == "true")
|
|
if err != nil {
|
|
response.Error(c, err)
|
|
return
|
|
}
|
|
response.Success(c, data)
|
|
}
|