优化结构
This commit is contained in:
@@ -27,8 +27,12 @@ func versionStage(err error) (system.VersionStage, bool) {
|
||||
}
|
||||
|
||||
func (h *Version) Delete(c *gin.Context) {
|
||||
id, _ := strconv.ParseUint(c.Query("ID"), 10, 64)
|
||||
if err := h.service.DeleteVersions(c.Request.Context(), []uint{uint(id)}); err != nil {
|
||||
id, err := positiveUintQuery(c, "ID")
|
||||
if err != nil {
|
||||
Fail(c, "版本ID非法")
|
||||
return
|
||||
}
|
||||
if err := h.service.DeleteVersions(c.Request.Context(), []uint{id}); err != nil {
|
||||
Fail(c, "删除失败:"+err.Error())
|
||||
return
|
||||
}
|
||||
@@ -38,8 +42,16 @@ func (h *Version) DeleteMany(c *gin.Context) {
|
||||
raw := c.QueryArray("IDs[]")
|
||||
ids := make([]uint, 0, len(raw))
|
||||
for _, value := range raw {
|
||||
id, _ := strconv.ParseUint(value, 10, 64)
|
||||
ids = append(ids, uint(id))
|
||||
id, err := positiveUint(value)
|
||||
if err != nil {
|
||||
Fail(c, "版本ID非法")
|
||||
return
|
||||
}
|
||||
ids = append(ids, id)
|
||||
}
|
||||
if len(ids) == 0 {
|
||||
Fail(c, "版本ID不能为空")
|
||||
return
|
||||
}
|
||||
if err := h.service.DeleteVersions(c.Request.Context(), ids); err != nil {
|
||||
Fail(c, "批量删除失败:"+err.Error())
|
||||
@@ -48,8 +60,12 @@ func (h *Version) DeleteMany(c *gin.Context) {
|
||||
Write(c, CodeSuccess, gin.H{}, "批量删除成功")
|
||||
}
|
||||
func (h *Version) Find(c *gin.Context) {
|
||||
id, _ := strconv.ParseUint(c.Query("ID"), 10, 64)
|
||||
item, err := h.service.Version(c.Request.Context(), uint(id))
|
||||
id, err := positiveUintQuery(c, "ID")
|
||||
if err != nil {
|
||||
Fail(c, "版本ID非法")
|
||||
return
|
||||
}
|
||||
item, err := h.service.Version(c.Request.Context(), id)
|
||||
if err != nil {
|
||||
Fail(c, "查询失败:"+err.Error())
|
||||
return
|
||||
@@ -112,8 +128,12 @@ func (h *Version) Download(c *gin.Context) {
|
||||
Fail(c, "版本ID不能为空")
|
||||
return
|
||||
}
|
||||
id, _ := strconv.ParseUint(rawID, 10, 64)
|
||||
raw, code, err := h.service.VersionData(c.Request.Context(), uint(id))
|
||||
id, err := positiveUint(rawID)
|
||||
if err != nil {
|
||||
Fail(c, "版本ID非法")
|
||||
return
|
||||
}
|
||||
raw, code, err := h.service.VersionData(c.Request.Context(), id)
|
||||
if err != nil {
|
||||
Fail(c, "获取版本记录失败:"+err.Error())
|
||||
return
|
||||
|
||||
Reference in New Issue
Block a user