Use utils.HttpResponse/Abort to replace c.JSON/Abort
Signed-off-by: Asai Neko <sugar@sne.moe>
This commit is contained in:
@@ -2,6 +2,7 @@ package user
|
||||
|
||||
import (
|
||||
"nixcn-cms/data"
|
||||
"nixcn-cms/utils"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/google/uuid"
|
||||
@@ -10,26 +11,29 @@ import (
|
||||
func Full(c *gin.Context) {
|
||||
userIdOrig, ok := c.Get("user_id")
|
||||
if !ok {
|
||||
c.JSON(403, gin.H{"status": "userid error"})
|
||||
utils.HttpResponse(c, 403, "", "userid error")
|
||||
return
|
||||
}
|
||||
userId, err := uuid.Parse(userIdOrig.(string))
|
||||
if err != nil {
|
||||
c.JSON(500, gin.H{"status": "failed to parse uuid"})
|
||||
utils.HttpResponse(c, 500, "", "failed to parse uuid")
|
||||
return
|
||||
}
|
||||
|
||||
userData, err := new(data.User).GetByUserId(userId)
|
||||
if err != nil {
|
||||
c.JSON(404, gin.H{"status": "user not found"})
|
||||
utils.HttpResponse(c, 404, "", "user not found")
|
||||
return
|
||||
}
|
||||
|
||||
data, err := userData.GetFullTable()
|
||||
users, err := userData.GetFullTable()
|
||||
if err != nil {
|
||||
c.JSON(500, gin.H{"status": "database error"})
|
||||
utils.HttpResponse(c, 500, "", "database error")
|
||||
return
|
||||
}
|
||||
|
||||
c.JSON(200, gin.H{"user_table": data})
|
||||
userFullResp := struct {
|
||||
UserTable *[]data.User `json:"user_table"`
|
||||
}{users}
|
||||
utils.HttpResponse(c, 200, "", "success", userFullResp)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user