This commit is contained in:
2026-08-16 09:02:39 +08:00
parent c554152f4f
commit f7f6db8695
105 changed files with 2535 additions and 948 deletions
+21 -12
View File
@@ -35,8 +35,16 @@ func (h *Announcement) Create(c *gin.Context) {
}
func (h *Announcement) Delete(c *gin.Context) {
id, _ := strconv.ParseUint(c.Query("ID"), 10, 64)
if err := h.service.Delete(c.Request.Context(), uint(id)); err != nil {
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 {
httpx.Fail(c, "删除失败")
return
}
@@ -78,8 +86,12 @@ func (h *Announcement) Update(c *gin.Context) {
}
func (h *Announcement) Find(c *gin.Context) {
id, _ := strconv.ParseUint(c.Query("ID"), 10, 64)
item, err := h.service.Find(c.Request.Context(), uint(id))
id, _, err := queryUintValue(c, "ID")
if err != nil {
httpx.Fail(c, err.Error())
return
}
item, err := h.service.Find(c.Request.Context(), id)
if err != nil {
httpx.Fail(c, "查询失败")
return
@@ -88,20 +100,17 @@ func (h *Announcement) Find(c *gin.Context) {
}
func (h *Announcement) List(c *gin.Context) {
page, _ := strconv.Atoi(c.Query("page"))
pageSize, _ := strconv.Atoi(c.Query("pageSize"))
start, startErr := parseTime(c.Query("startCreatedAt"))
end, endErr := parseTime(c.Query("endCreatedAt"))
if startErr != nil || endErr != nil || (start == nil) != (end == nil) {
httpx.Fail(c, "创建日期范围不合法")
var req dto.AnnouncementSearchRequest
if err := c.ShouldBindQuery(&req); err != nil {
httpx.Fail(c, err.Error())
return
}
items, total, err := h.service.List(c.Request.Context(), page, pageSize, start, end)
items, total, err := h.service.List(c.Request.Context(), req.Page, req.PageSize, req.StartCreatedAt, req.EndCreatedAt)
if err != nil {
httpx.Fail(c, "获取失败")
return
}
httpx.Write(c, httpx.CodeSuccess, httpx.PageResult{List: items, Total: total, Page: page, PageSize: pageSize}, "获取成功")
httpx.Write(c, httpx.CodeSuccess, httpx.PageResult{List: items, Total: total, Page: req.Page, PageSize: req.PageSize}, "获取成功")
}
func (h *Announcement) DataSource(c *gin.Context) {