This commit is contained in:
2026-08-17 02:12:17 +08:00
parent 560ae46b82
commit 6a05803e08
96 changed files with 2888 additions and 685 deletions
+3 -31
View File
@@ -1,7 +1,6 @@
package handler
import (
"strconv"
"time"
"kra/internal/server/httpx"
@@ -35,16 +34,7 @@ func (h *Announcement) Create(c *gin.Context) {
}
func (h *Announcement) Delete(c *gin.Context) {
id, present, err := queryUintValue(c, "ID")
if err != nil {
httpx.Fail(c, err.Error())
return
}
if !present {
// Preserve the legacy endpoint behavior for an omitted ID.
id = 0
}
if err := h.service.Delete(c.Request.Context(), id); err != nil {
if err := h.service.Delete(c.Request.Context(), c.Query("ID")); err != nil {
httpx.Fail(c, "删除失败")
return
}
@@ -52,20 +42,7 @@ func (h *Announcement) Delete(c *gin.Context) {
}
func (h *Announcement) DeleteByIDs(c *gin.Context) {
values := c.QueryArray("IDs[]")
if len(values) == 0 {
values = c.QueryArray("IDs")
}
ids := make([]uint, 0, len(values))
for _, value := range values {
id, err := strconv.ParseUint(value, 10, 64)
if err != nil || id == 0 {
httpx.Fail(c, "参数错误")
return
}
ids = append(ids, uint(id))
}
if err := h.service.DeleteByIDs(c.Request.Context(), ids); err != nil {
if err := h.service.DeleteByIDs(c.Request.Context(), c.QueryArray("IDs[]")); err != nil {
httpx.Fail(c, "批量删除失败")
return
}
@@ -86,12 +63,7 @@ func (h *Announcement) Update(c *gin.Context) {
}
func (h *Announcement) Find(c *gin.Context) {
id, _, err := queryUintValue(c, "ID")
if err != nil {
httpx.Fail(c, err.Error())
return
}
item, err := h.service.Find(c.Request.Context(), id)
item, err := h.service.Find(c.Request.Context(), c.Query("ID"))
if err != nil {
httpx.Fail(c, "查询失败")
return