WIP: Full restruct, seprate service and api
Signed-off-by: Asai Neko <sugar@sne.moe>
This commit is contained in:
@@ -1,74 +1,51 @@
|
||||
package user
|
||||
|
||||
import (
|
||||
"nixcn-cms/data"
|
||||
"nixcn-cms/internal/exception"
|
||||
"nixcn-cms/utils"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/google/uuid"
|
||||
)
|
||||
|
||||
func Info(c *gin.Context) {
|
||||
userData := new(data.User)
|
||||
userIdOrig, ok := c.Get("user_id")
|
||||
if !ok {
|
||||
errorCode := new(exception.Builder).
|
||||
SetStatus(exception.StatusUser).
|
||||
SetService(exception.ServiceUser).
|
||||
SetEndpoint(exception.EndpointUserServiceInfo).
|
||||
SetType(exception.TypeCommon).
|
||||
SetOriginal(exception.CommonErrorMissingUserId).
|
||||
Build(c)
|
||||
utils.HttpResponse(c, 403, errorCode)
|
||||
return
|
||||
}
|
||||
userId, err := uuid.Parse(userIdOrig.(string))
|
||||
if err != nil {
|
||||
errorCode := new(exception.Builder).
|
||||
SetStatus(exception.StatusServer).
|
||||
SetService(exception.ServiceUser).
|
||||
SetEndpoint(exception.EndpointUserServiceInfo).
|
||||
SetType(exception.TypeCommon).
|
||||
SetOriginal(exception.CommonErrorUuidParseFailed).
|
||||
SetError(err).
|
||||
Build(c)
|
||||
utils.HttpResponse(c, 500, errorCode)
|
||||
return
|
||||
}
|
||||
// userData := new(data.User)
|
||||
// userIdOrig, ok := c.Get("user_id")
|
||||
// if !ok {
|
||||
// errorCode := new(exception.Builder).
|
||||
// SetStatus(exception.StatusUser).
|
||||
// SetService(exception.ServiceUser).
|
||||
// SetEndpoint(exception.EndpointUserServiceInfo).
|
||||
// SetType(exception.TypeCommon).
|
||||
// SetOriginal(exception.CommonErrorMissingUserId).
|
||||
// Build(c)
|
||||
// utils.HttpResponse(c, 403, errorCode)
|
||||
// return
|
||||
// }
|
||||
// userId, err := uuid.Parse(userIdOrig.(string))
|
||||
// if err != nil {
|
||||
// errorCode := new(exception.Builder).
|
||||
// SetStatus(exception.StatusServer).
|
||||
// SetService(exception.ServiceUser).
|
||||
// SetEndpoint(exception.EndpointUserServiceInfo).
|
||||
// SetType(exception.TypeCommon).
|
||||
// SetOriginal(exception.CommonErrorUuidParseFailed).
|
||||
// SetError(err).
|
||||
// Build(c)
|
||||
// utils.HttpResponse(c, 500, errorCode)
|
||||
// return
|
||||
// }
|
||||
|
||||
// Get user from database
|
||||
user, err := userData.GetByUserId(c, userId)
|
||||
if err != nil {
|
||||
errorCode := new(exception.Builder).
|
||||
SetStatus(exception.StatusUser).
|
||||
SetService(exception.ServiceUser).
|
||||
SetEndpoint(exception.EndpointUserServiceInfo).
|
||||
SetType(exception.TypeCommon).
|
||||
SetOriginal(exception.CommonErrorUserNotFound).
|
||||
SetError(err).
|
||||
Build(c)
|
||||
utils.HttpResponse(c, 404, errorCode)
|
||||
return
|
||||
}
|
||||
// user, err := userData.GetByUserId(c, userId)
|
||||
// if err != nil {
|
||||
// utils.HttpResponse(c, 404, errorCode)
|
||||
// return
|
||||
// }
|
||||
|
||||
userInfoResp := struct {
|
||||
UserId uuid.UUID `json:"user_id"`
|
||||
Email string `json:"email"`
|
||||
Username string `json:"username"`
|
||||
Nickname string `json:"nickname"`
|
||||
Subtitle string `json:"subtitle"`
|
||||
Avatar string `json:"avatar"`
|
||||
Bio string `json:"bio"`
|
||||
PermissionLevel uint `json:"permission_level"`
|
||||
}{user.UserId, user.Email, user.Username, user.Nickname, user.Subtitle, user.Avatar, user.Bio, user.PermissionLevel}
|
||||
|
||||
errorCode := new(exception.Builder).
|
||||
SetStatus(exception.StatusUser).
|
||||
SetService(exception.ServiceUser).
|
||||
SetEndpoint(exception.EndpointUserServiceInfo).
|
||||
SetType(exception.TypeCommon).
|
||||
SetOriginal(exception.CommonSuccess).
|
||||
Build(c)
|
||||
utils.HttpResponse(c, 200, errorCode, userInfoResp)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user