Skip to content

Commit

Permalink
feat: user and meta get api
Browse files Browse the repository at this point in the history
  • Loading branch information
xhofe committed Jul 27, 2022
1 parent b399c92 commit 53fd098
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 0 deletions.
15 changes: 15 additions & 0 deletions server/handles/meta.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,3 +95,18 @@ func DeleteMeta(c *gin.Context) {
}
common.SuccessResp(c)
}

func GetMeta(c *gin.Context) {
idStr := c.Query("id")
id, err := strconv.Atoi(idStr)
if err != nil {
common.ErrorResp(c, err, 400)
return
}
meta, err := db.GetMetaById(uint(id))
if err != nil {
common.ErrorResp(c, err, 500, true)
return
}
common.SuccessResp(c, meta)
}
15 changes: 15 additions & 0 deletions server/handles/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,3 +81,18 @@ func DeleteUser(c *gin.Context) {
}
common.SuccessResp(c)
}

func GetUser(c *gin.Context) {
idStr := c.Query("id")
id, err := strconv.Atoi(idStr)
if err != nil {
common.ErrorResp(c, err, 400)
return
}
user, err := db.GetUserById(uint(id))
if err != nil {
common.ErrorResp(c, err, 500, true)
return
}
common.SuccessResp(c, user)
}
2 changes: 2 additions & 0 deletions server/router.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,14 @@ func Init(r *gin.Engine) {
func admin(g *gin.RouterGroup) {
meta := g.Group("/meta")
meta.GET("/list", handles.ListMetas)
meta.GET("/get", handles.GetMeta)
meta.POST("/create", handles.CreateMeta)
meta.POST("/update", handles.UpdateMeta)
meta.POST("/delete", handles.DeleteMeta)

user := g.Group("/user")
user.GET("/list", handles.ListUsers)
user.GET("/get", handles.GetUser)
user.POST("/create", handles.CreateUser)
user.POST("/update", handles.UpdateUser)
user.POST("/delete", handles.DeleteUser)
Expand Down

0 comments on commit 53fd098

Please sign in to comment.