Files
cms-server/service/service_event/list_events.go
Asai Neko 0ac96ab3e6
All checks were successful
Client CMS Check Build (NixCN CMS) TeamCity build finished
Backend Check Build (NixCN CMS) TeamCity build finished
Add service_kyc
Signed-off-by: Asai Neko <sugar@sne.moe>
2026-02-01 13:15:17 +08:00

132 lines
2.9 KiB
Go

package service_event
import (
"context"
"nixcn-cms/data"
"nixcn-cms/internal/exception"
"nixcn-cms/service/shared"
"strconv"
)
type EventListPayload struct {
Context context.Context
Limit *string
Offset *string
}
type EventListResult struct {
Common shared.CommonResult
Data *[]data.EventIndexDoc `json:"event_list"`
}
func (self *EventServiceImpl) ListEvents(payload *EventListPayload) (result *EventListResult) {
var limit string
if payload.Limit == nil || *payload.Limit == "" {
limit = "20"
} else {
limit = *payload.Limit
}
var offset string
if payload.Offset == nil || *payload.Offset == "" {
exception := new(exception.Builder).
SetStatus(exception.StatusUser).
SetService(exception.ServiceEvent).
SetEndpoint(exception.EndpointEventServiceList).
SetType(exception.TypeCommon).
SetOriginal(exception.CommonErrorInvalidInput).
SetError(nil).
Throw(payload.Context)
return &EventListResult{
Common: shared.CommonResult{
HttpCode: 400,
Exception: exception,
},
Data: nil,
}
} else {
offset = *payload.Offset
}
limitNum, err := strconv.Atoi(limit)
if err != nil {
exc := new(exception.Builder).
SetStatus(exception.StatusUser).
SetService(exception.ServiceEvent).
SetEndpoint(exception.EndpointEventServiceList).
SetType(exception.TypeCommon).
SetOriginal(exception.CommonErrorInvalidInput).
SetError(err).
Throw(payload.Context)
return &EventListResult{
Common: shared.CommonResult{
HttpCode: 400,
Exception: exc,
},
Data: nil,
}
}
offsetNum, err := strconv.Atoi(offset)
if err != nil {
exc := new(exception.Builder).
SetStatus(exception.StatusUser).
SetService(exception.ServiceEvent).
SetEndpoint(exception.EndpointEventServiceList).
SetType(exception.TypeCommon).
SetOriginal(exception.CommonErrorInvalidInput).
SetError(err).
Throw(payload.Context)
return &EventListResult{
Common: shared.CommonResult{
HttpCode: 400,
Exception: exc,
},
Data: nil,
}
}
eventList, err := new(data.Event).
FastListEvents(payload.Context, int64(limitNum), int64(offsetNum))
if err != nil {
exc := new(exception.Builder).
SetStatus(exception.StatusServer).
SetService(exception.ServiceEvent).
SetEndpoint(exception.EndpointEventServiceList).
SetType(exception.TypeSpecific).
SetOriginal(exception.EventListDatabaseFailed).
SetError(err).
Throw(payload.Context)
return &EventListResult{
Common: shared.CommonResult{
HttpCode: 500,
Exception: exc,
},
Data: nil,
}
}
successExc := new(exception.Builder).
SetStatus(exception.StatusSuccess).
SetService(exception.ServiceEvent).
SetEndpoint(exception.EndpointEventServiceList).
SetType(exception.TypeCommon).
SetOriginal(exception.CommonSuccess).
SetError(nil).
Throw(payload.Context)
result = &EventListResult{
Common: shared.CommonResult{
HttpCode: 200,
Exception: successExc,
},
Data: eventList,
}
return
}