功能更新
This commit is contained in:
40
internal/controller/sync.go
Normal file
40
internal/controller/sync.go
Normal file
@@ -0,0 +1,40 @@
|
||||
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})
|
||||
}
|
||||
Reference in New Issue
Block a user