Skip to content

Commit

Permalink
feat: get storage by id api
Browse files Browse the repository at this point in the history
  • Loading branch information
xhofe committed Jul 18, 2022
1 parent e08810a commit 184b9d1
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 0 deletions.
File renamed without changes.
15 changes: 15 additions & 0 deletions server/handles/storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,3 +69,18 @@ func DeleteStorage(c *gin.Context) {
}
common.SuccessResp(c)
}

func GetStorage(c *gin.Context) {
idStr := c.Query("id")
id, err := strconv.Atoi(idStr)
if err != nil {
common.ErrorResp(c, err, 400)
return
}
storage, err := db.GetStorageById(uint(id))
if err != nil {
common.ErrorResp(c, err, 500, true)
return
}
common.SuccessResp(c, storage)
}
1 change: 1 addition & 0 deletions server/router.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ func Init(r *gin.Engine) {

storage := admin.Group("/storage")
storage.GET("/list", handles.ListStorages)
storage.GET("/get", handles.GetStorage)
storage.POST("/create", handles.CreateStorage)
storage.POST("/update", handles.UpdateStorage)
storage.POST("/delete", handles.DeleteStorage)
Expand Down

0 comments on commit 184b9d1

Please sign in to comment.