package user import ( "nixcn-cms/data" "nixcn-cms/internal/exception" "nixcn-cms/utils" "github.com/gin-gonic/gin" "github.com/google/uuid" ) func Full(c *gin.Context) { userIdOrig, ok := c.Get("user_id") if !ok { errorCode := new(exception.Builder). SetStatus(exception.ErrorStatusUser). SetService(exception.UserService). SetEndpoint(exception.UserFullEndpoint). SetType(exception.ErrorTypeCommon). SetOriginal(exception.CommonErrorMissingUserId). Build() utils.HttpResponse(c, 403, errorCode) return } userId, err := uuid.Parse(userIdOrig.(string)) if err != nil { errorCode := new(exception.Builder). SetStatus(exception.ErrorStatusServer). SetService(exception.UserService). SetEndpoint(exception.UserFullEndpoint). SetType(exception.ErrorTypeCommon). SetOriginal(exception.CommonErrorUuidParseFailed). Build() utils.HttpResponse(c, 500, errorCode) return } userData, err := new(data.User).GetByUserId(userId) if err != nil { errorCode := new(exception.Builder). SetStatus(exception.ErrorStatusUser). SetService(exception.UserService). SetEndpoint(exception.UserFullEndpoint). SetType(exception.ErrorTypeCommon). SetOriginal(exception.CommonErrorUserNotFound). Build() utils.HttpResponse(c, 404, errorCode) return } users, err := userData.GetFullTable() if err != nil { errorCode := new(exception.Builder). SetStatus(exception.ErrorStatusServer). SetService(exception.UserService). SetEndpoint(exception.UserFullEndpoint). SetType(exception.ErrorTypeCommon). SetOriginal(exception.CommonErrorDatabase). Build() utils.HttpResponse(c, 500, errorCode) return } userFullResp := struct { UserTable *[]data.User `json:"user_table"` }{users} utils.HttpResponse(c, 200, "", "success", userFullResp) }