Files
nl-pms-api/internal/controller/sync.go
2026-08-15 17:04:47 +08:00

41 lines
810 B
Go

package controller
import (
"net/http"
"github.com/gin-gonic/gin"
"nl-pms-api/internal/commonservice"
"nl-pms-api/internal/service"
)
// SyncController 同步推拉。
type SyncController struct {
Svc *service.SyncService
}
func (h *SyncController) Push(c *gin.Context) {
var req struct {
Table string `json:"table"`
Rows []map[string]any `json:"rows"`
}
if !bindJSON(c, &req) {
return
}
n, err := h.Svc.Push(req.Table, commonservice.UserID(c), req.Rows)
if err != nil {
writeErr(c, err)
return
}
c.JSON(http.StatusOK, gin.H{"pushed": n})
}
func (h *SyncController) Pull(c *gin.Context) {
rows, err := h.Svc.Pull(c.Query("table"), commonservice.UserID(c), c.Query("cursor"))
if err != nil {
writeErr(c, err)
return
}
c.JSON(http.StatusOK, gin.H{"rows": rows})
}