- 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>
63 lines
1.6 KiB
Go
63 lines
1.6 KiB
Go
package event
|
|
|
|
import (
|
|
"nixcn-cms/data"
|
|
"nixcn-cms/exception"
|
|
"nixcn-cms/utils"
|
|
"time"
|
|
|
|
"github.com/gin-gonic/gin"
|
|
"github.com/google/uuid"
|
|
)
|
|
|
|
func Info(c *gin.Context) {
|
|
eventData := new(data.Event)
|
|
eventIdOrig, ok := c.GetQuery("event_id")
|
|
if !ok {
|
|
errorCode := new(exception.Builder).
|
|
SetStatus(exception.ErrorStatusClient).
|
|
SetService(exception.EventService).
|
|
SetEndpoint(exception.EventInfoEndpoint).
|
|
SetType(exception.ErrorTypeCommon).
|
|
SetOriginal(exception.CommonErrorInvalidInput).
|
|
Build()
|
|
utils.HttpResponse(c, 400, errorCode)
|
|
return
|
|
}
|
|
|
|
// Parse event id
|
|
eventId, err := uuid.Parse(eventIdOrig)
|
|
if err != nil {
|
|
errorCode := new(exception.Builder).
|
|
SetStatus(exception.ErrorStatusServer).
|
|
SetService(exception.EventService).
|
|
SetEndpoint(exception.EventInfoEndpoint).
|
|
SetType(exception.ErrorTypeCommon).
|
|
SetOriginal(exception.CommonErrorUuidParseFailed).
|
|
Build()
|
|
utils.HttpResponse(c, 500, errorCode)
|
|
return
|
|
}
|
|
|
|
event, err := eventData.GetEventById(eventId)
|
|
if err != nil {
|
|
errorCode := new(exception.Builder).
|
|
SetStatus(exception.ErrorStatusClient).
|
|
SetService(exception.EventService).
|
|
SetEndpoint(exception.EventInfoEndpoint).
|
|
SetType(exception.ErrorTypeSpecific).
|
|
SetOriginal(exception.EventInfoNotFound).
|
|
Build()
|
|
utils.HttpResponse(c, 404, errorCode)
|
|
return
|
|
}
|
|
|
|
eventInfoResp := struct {
|
|
Name string `json:"name"`
|
|
StartTime time.Time `json:"start_time"`
|
|
EndTime time.Time `json:"end_time"`
|
|
}{event.Name, event.StartTime, event.EndTime}
|
|
|
|
utils.HttpResponse(c, 200, "", "success", eventInfoResp)
|
|
}
|