This commit is contained in:
2026-08-15 01:12:04 +08:00
parent f63acae353
commit 6698e59c3a
45 changed files with 725 additions and 415 deletions
+11 -11
View File
@@ -23,12 +23,12 @@ func announcementInput(req dto.AnnouncementRequest) service.AnnouncementInput {
func (h *Announcement) Create(c *gin.Context) {
var req dto.AnnouncementRequest
if c.ShouldBindJSON(&req) != nil {
httpx.Fail(c, "参数错误")
if err := c.ShouldBindJSON(&req); err != nil {
httpx.Fail(c, err.Error())
return
}
if err := h.service.Create(c.Request.Context(), announcementInput(req)); err != nil {
httpx.Fail(c, "创建失败:"+err.Error())
httpx.Fail(c, "创建失败")
return
}
httpx.Write(c, httpx.CodeSuccess, gin.H{}, "创建成功")
@@ -37,7 +37,7 @@ 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 {
httpx.Fail(c, "删除失败:"+err.Error())
httpx.Fail(c, "删除失败")
return
}
httpx.Write(c, httpx.CodeSuccess, gin.H{}, "删除成功")
@@ -58,7 +58,7 @@ func (h *Announcement) DeleteByIDs(c *gin.Context) {
ids = append(ids, uint(id))
}
if err := h.service.DeleteByIDs(c.Request.Context(), ids); err != nil {
httpx.Fail(c, "批量删除失败:"+err.Error())
httpx.Fail(c, "批量删除失败")
return
}
httpx.Write(c, httpx.CodeSuccess, gin.H{}, "批量删除成功")
@@ -66,12 +66,12 @@ func (h *Announcement) DeleteByIDs(c *gin.Context) {
func (h *Announcement) Update(c *gin.Context) {
var req dto.AnnouncementRequest
if c.ShouldBindJSON(&req) != nil {
httpx.Fail(c, "参数错误")
if err := c.ShouldBindJSON(&req); err != nil {
httpx.Fail(c, err.Error())
return
}
if err := h.service.Update(c.Request.Context(), announcementInput(req)); err != nil {
httpx.Fail(c, "更新失败:"+err.Error())
httpx.Fail(c, "更新失败")
return
}
httpx.Write(c, httpx.CodeSuccess, gin.H{}, "更新成功")
@@ -81,7 +81,7 @@ 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))
if err != nil {
httpx.Fail(c, "查询失败:"+err.Error())
httpx.Fail(c, "查询失败")
return
}
httpx.OKWithData(c, item)
@@ -98,7 +98,7 @@ func (h *Announcement) List(c *gin.Context) {
}
items, total, err := h.service.List(c.Request.Context(), page, pageSize, start, end)
if err != nil {
httpx.Fail(c, "获取失败:"+err.Error())
httpx.Fail(c, "获取失败")
return
}
httpx.Write(c, httpx.CodeSuccess, httpx.PageResult{List: items, Total: total, Page: page, PageSize: pageSize}, "获取成功")
@@ -107,7 +107,7 @@ func (h *Announcement) List(c *gin.Context) {
func (h *Announcement) DataSource(c *gin.Context) {
users, err := h.service.UserOptions(c.Request.Context())
if err != nil {
httpx.Fail(c, "查询失败:"+err.Error())
httpx.Fail(c, "查询失败")
return
}
httpx.OKWithData(c, gin.H{"userID": users})