- Replace hardcoded error messages with structured error codes using exception.Builder. - Introduce new common error constants in exception/common.go (CommonErrorInvalidInput, CommonErrorUserNotFound, etc.). - Update exception/specific.go with domain-specific errors and remove redundant ones. - Apply consistent error handling across auth, event, user services and middleware. Co-authored-by: Gemini <gemini@google.com> Signed-off-by: Noa Virellia <noa@requiem.garden>
69 lines
1.8 KiB
Go
69 lines
1.8 KiB
Go
package user
|
|
|
|
import (
|
|
"nixcn-cms/data"
|
|
"nixcn-cms/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)
|
|
}
|