diff --git a/api/keypair/controller.go b/api/keypair/controller.go index 954eae60..c9406c4b 100644 --- a/api/keypair/controller.go +++ b/api/keypair/controller.go @@ -21,6 +21,21 @@ func list(c *gin.Context) { } +// 获取密钥 + +func detail(c *gin.Context) { + + userId := c.GetUint("UserId") + id := cast.ToUint(c.Param("id")) + + if res, err := keypair.Fetch(id, userId); err == nil { + c.Set("Payload", res) + } else { + c.Set("Error", err) + } + +} + // 添加密钥 func create(c *gin.Context) { @@ -43,6 +58,27 @@ func create(c *gin.Context) { } +// 修改密钥 + +func update(c *gin.Context) { + + var rq *keypair.UpdateParam + + if err := c.ShouldBind(&rq); err != nil { + c.Set("Error", err) + return + } + + rq.UserId = c.GetUint("UserId") + + if err := keypair.Update(rq); err == nil { + c.Set("Message", "修改成功") + } else { + c.Set("Error", err) + } + +} + // 删除密钥 func delete(c *gin.Context) { diff --git a/api/keypair/router.go b/api/keypair/router.go index 9015e7f2..c5473d90 100644 --- a/api/keypair/router.go +++ b/api/keypair/router.go @@ -15,6 +15,8 @@ func Router(api *gin.RouterGroup) { { rg.GET("/keypair", list) rg.POST("/keypair", create) + rg.GET("/keypair/:id", detail) + rg.PATCH("/keypair/:id", update) rg.DELETE("/keypair/:id", delete) } diff --git a/api/script/controller.go b/api/script/controller.go index c9624051..ad1f0065 100644 --- a/api/script/controller.go +++ b/api/script/controller.go @@ -21,6 +21,21 @@ func list(c *gin.Context) { } +// 获取脚本 + +func detail(c *gin.Context) { + + userId := c.GetUint("UserId") + id := cast.ToUint(c.Param("id")) + + if res, err := script.Fetch(id, userId); err == nil { + c.Set("Payload", res) + } else { + c.Set("Error", err) + } + +} + // 添加脚本 func create(c *gin.Context) { diff --git a/api/script/router.go b/api/script/router.go index 92613af6..4b781230 100644 --- a/api/script/router.go +++ b/api/script/router.go @@ -15,6 +15,7 @@ func Router(api *gin.RouterGroup) { { rg.GET("/script", list) rg.POST("/script", create) + rg.GET("/script/:id", detail) rg.PATCH("/script/:id", update) rg.DELETE("/script/:id", delete) }