- Update old ErrorStatus, ErrorType, and Service/Endpoint constants to new naming convention - Fix incorrect TypeSpecific usage in JWT middleware - Add missing event specific error definitions to specific.yaml - Regenerate exception constants Co-authored-by: Gemini <gemini@google.com>
69 lines
1.8 KiB
Go
69 lines
1.8 KiB
Go
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.StatusUser).
|
|
SetService(exception.ServiceUser).
|
|
SetEndpoint(exception.EndpointUserServiceFull).
|
|
SetType(exception.TypeCommon).
|
|
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.StatusServer).
|
|
SetService(exception.ServiceUser).
|
|
SetEndpoint(exception.EndpointUserServiceFull).
|
|
SetType(exception.TypeCommon).
|
|
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.StatusUser).
|
|
SetService(exception.ServiceUser).
|
|
SetEndpoint(exception.EndpointUserServiceFull).
|
|
SetType(exception.TypeCommon).
|
|
SetOriginal(exception.CommonErrorUserNotFound).
|
|
Build()
|
|
utils.HttpResponse(c, 404, errorCode)
|
|
return
|
|
}
|
|
|
|
users, err := userData.GetFullTable()
|
|
if err != nil {
|
|
errorCode := new(exception.Builder).
|
|
SetStatus(exception.StatusServer).
|
|
SetService(exception.ServiceUser).
|
|
SetEndpoint(exception.EndpointUserServiceFull).
|
|
SetType(exception.TypeCommon).
|
|
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)
|
|
}
|