diff --git a/service/user/full.go b/service/user/full.go index a00006b..f895b2d 100644 --- a/service/user/full.go +++ b/service/user/full.go @@ -1 +1,41 @@ package user + +import ( + "nixcn-cms/data" + + "github.com/gin-gonic/gin" + "github.com/google/uuid" +) + +func Full(c *gin.Context) { + userIdOrig, ok := c.Get("user_id") + if !ok { + c.JSON(403, gin.H{"status": "userid error"}) + return + } + userId, err := uuid.Parse(userIdOrig.(string)) + if err != nil { + c.JSON(500, gin.H{"status": "failed to parse uuid"}) + return + } + + userData := new(data.User) + user, err := userData.GetByUserId(userId) + if err != nil { + c.JSON(404, gin.H{"status": "user not found"}) + return + } + + if user.PermissionLevel < 50 { + c.JSON(403, gin.H{"status": "permission denied"}) + return + } + + data, err := userData.GetFullTable() + if err != nil { + c.JSON(500, gin.H{"status": "database error"}) + return + } + + c.JSON(200, gin.H{"user_table": data}) +} diff --git a/service/user/handler.go b/service/user/handler.go index 1af4338..00f5e1e 100644 --- a/service/user/handler.go +++ b/service/user/handler.go @@ -14,4 +14,5 @@ func Handler(r *gin.RouterGroup) { r.PATCH("/update", Update) r.GET("/list", List) r.GET("/query", Query) + r.POST("/full", Full) }