Skip to content

Commit

Permalink
feat: 补全接口
Browse files Browse the repository at this point in the history
  • Loading branch information
rehiy committed Feb 12, 2023
1 parent 7bf4865 commit 6512dd9
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 0 deletions.
36 changes: 36 additions & 0 deletions api/keypair/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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) {
Expand Down
2 changes: 2 additions & 0 deletions api/keypair/router.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand Down
15 changes: 15 additions & 0 deletions api/script/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
1 change: 1 addition & 0 deletions api/script/router.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down

0 comments on commit 6512dd9

Please sign in to comment.