mirror of
https://github.com/Sagit-chu/flvx.git
synced 2026-11-13 00:14:22 +08:00
feat: show current owner names and persist user and limit order (#576)
Resolve current forwarding-rule owner names by user ID. Add administrator-managed persistent user and speed-limit ordering, backup compatibility, and conflict recovery. Repair PostgreSQL explicit-ID import sequences transactionally. Closes #574 Closes #575
This commit is contained in:
@@ -0,0 +1,45 @@
|
||||
package handler
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"go-backend/internal/http/response"
|
||||
"go-backend/internal/store/repo"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
func (h *Handler) userDisplayOrder(w http.ResponseWriter, r *http.Request) {
|
||||
updateDisplayOrder(w, r, h.repo.UpdateUserDisplayOrder)
|
||||
}
|
||||
func (h *Handler) speedLimitDisplayOrder(w http.ResponseWriter, r *http.Request) {
|
||||
updateDisplayOrder(w, r, h.repo.UpdateSpeedLimitDisplayOrder)
|
||||
}
|
||||
func updateDisplayOrder(w http.ResponseWriter, r *http.Request, save func([]int64, []int64) error) {
|
||||
if r.Method != http.MethodPost {
|
||||
response.WriteJSON(w, response.Err(400, "请求方法错误"))
|
||||
return
|
||||
}
|
||||
var req struct {
|
||||
IDs []int64 `json:"ids"`
|
||||
ExpectedIDs []int64 `json:"expectedIds"`
|
||||
}
|
||||
if err := decodeJSON(r.Body, &req); err != nil {
|
||||
response.WriteJSON(w, response.Err(400, "请求参数错误"))
|
||||
return
|
||||
}
|
||||
if err := save(req.IDs, req.ExpectedIDs); err != nil {
|
||||
code := 500
|
||||
if errors.Is(err, repo.ErrInvalidDisplayOrder) {
|
||||
code = 400
|
||||
}
|
||||
if errors.Is(err, repo.ErrDisplayOrderConflict) {
|
||||
code = 409
|
||||
}
|
||||
msg := "排序保存失败,请刷新后重试"
|
||||
if code != 500 {
|
||||
msg = err.Error()
|
||||
}
|
||||
response.WriteJSON(w, response.Err(code, msg))
|
||||
return
|
||||
}
|
||||
response.WriteJSON(w, response.OKEmpty())
|
||||
}
|
||||
Reference in New Issue
Block a user