bindbox-game/internal/api/admin/system_recycle.go
邹方成 2a89a1ab9d
Some checks failed
Build docker and publish / linux (1.24.5) (push) Failing after 39s
feat(admin): 更新前端资源文件及修复相关功能
refactor(service): 修改banner和guild删除逻辑为软删除
fix(service): 修复删除操作使用软删除而非物理删除

build: 添加SQLite测试仓库实现
docs: 新增奖励管理字段拆分和批量抽奖UI改造文档

ci: 更新CI忽略文件
style: 清理无用资源文件
2025-11-19 01:35:55 +08:00

63 lines
2.3 KiB
Go

package admin
import (
"net/http"
"strconv"
"bindbox-game/internal/pkg/core"
"bindbox-game/internal/service/recycle"
)
type recycleListResponse struct {
Page int `json:"page"`
PageSize int `json:"page_size"`
Total int64 `json:"total"`
List []map[string]any `json:"list"`
}
func (h *handler) ListRecycle() core.HandlerFunc {
return func(ctx core.Context) {
typ := ctx.RequestInputParams().Get("type")
pageStr := ctx.RequestInputParams().Get("page")
sizeStr := ctx.RequestInputParams().Get("page_size")
page, _ := strconv.Atoi(pageStr)
size, _ := strconv.Atoi(sizeStr)
svc := recycle.NewRaw(h.readDB, h.writeDB, h.repo.GetDbR(), h.repo.GetDbW())
list, total, err := svc.List(ctx.RequestContext(), typ, page, size)
if err != nil {
ctx.AbortWithError(core.Error(http.StatusBadRequest, 19001, err.Error()))
return
}
if page <= 0 { page = 1 }
if size <= 0 { size = 20 }
ctx.Payload(recycleListResponse{Page: page, PageSize: size, Total: total, List: list})
}
}
func (h *handler) RestoreRecycle() core.HandlerFunc {
return func(ctx core.Context) {
typ := ctx.RequestInputParams().Get("type")
idStr := ctx.RequestInputParams().Get("id")
id, _ := strconv.ParseInt(idStr, 10, 64)
svc := recycle.NewRaw(h.readDB, h.writeDB, h.repo.GetDbR(), h.repo.GetDbW())
if err := svc.Restore(ctx.RequestContext(), typ, id); err != nil {
ctx.AbortWithError(core.Error(http.StatusBadRequest, 19002, err.Error()))
return
}
ctx.Payload(map[string]string{"message": "ok"})
}
}
func (h *handler) ForceDeleteRecycle() core.HandlerFunc {
return func(ctx core.Context) {
typ := ctx.RequestInputParams().Get("type")
idStr := ctx.RequestInputParams().Get("id")
id, _ := strconv.ParseInt(idStr, 10, 64)
svc := recycle.NewRaw(h.readDB, h.writeDB, h.repo.GetDbR(), h.repo.GetDbW())
if err := svc.ForceDelete(ctx.RequestContext(), typ, id); err != nil {
ctx.AbortWithError(core.Error(http.StatusBadRequest, 19003, err.Error()))
return
}
ctx.Payload(map[string]string{"message": "ok"})
}
}