优化
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user