Remove search engine, add event list api
All checks were successful
Client CMS Check Build (NixCN CMS) TeamCity build finished
Backend Check Build (NixCN CMS) TeamCity build finished

Signed-off-by: Asai Neko <sugar@sne.moe>
This commit is contained in:
2026-01-30 11:54:13 +08:00
parent 2aa344a11f
commit 39f555b780
26 changed files with 401 additions and 499 deletions

View File

@@ -10,27 +10,27 @@ import (
"github.com/google/uuid"
)
type InfoData struct {
type EventInfoData struct {
EventId uuid.UUID `json:"event_id"`
}
type InfoPayload struct {
type EventInfoPayload struct {
Context context.Context
Data *InfoData
Data *EventInfoData
}
type InfoResponse struct {
type EventInfoResponse struct {
Name string `json:"name"`
StartTime time.Time `json:"start_time"`
EndTime time.Time `json:"end_time"`
}
type InfoResult struct {
type EventInfoResult struct {
Common shared.CommonResult
Data *InfoResponse
Data *EventInfoResponse
}
func (self *EventServiceImpl) Info(payload *InfoPayload) (result *InfoResult) {
func (self *EventServiceImpl) GetEventInfo(payload *EventInfoPayload) (result *EventInfoResult) {
event, err := new(data.Event).GetEventById(payload.Context, payload.Data.EventId)
if err != nil {
exception := new(exception.Builder).
@@ -42,7 +42,7 @@ func (self *EventServiceImpl) Info(payload *InfoPayload) (result *InfoResult) {
SetError(err).
Throw(payload.Context)
result = &InfoResult{
result = &EventInfoResult{
Common: shared.CommonResult{
HttpCode: 404,
Exception: exception,
@@ -52,7 +52,7 @@ func (self *EventServiceImpl) Info(payload *InfoPayload) (result *InfoResult) {
return
}
result = &InfoResult{
result = &EventInfoResult{
Common: shared.CommonResult{
HttpCode: 200,
Exception: new(exception.Builder).
@@ -63,7 +63,7 @@ func (self *EventServiceImpl) Info(payload *InfoPayload) (result *InfoResult) {
SetOriginal(exception.CommonSuccess).
Throw(payload.Context),
},
Data: &InfoResponse{
Data: &EventInfoResponse{
Name: event.Name,
StartTime: event.StartTime,
EndTime: event.EndTime,

View File

@@ -0,0 +1,131 @@
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 == "" {
exc := 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: exc,
},
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
}

View File

@@ -4,7 +4,8 @@ type EventService interface {
Checkin(*CheckinPayload) *CheckinResult
CheckinSubmit(*CheckinSubmitPayload) *CheckinSubmitResult
CheckinQuery(*CheckinQueryPayload) *CheckinQueryResult
Info(*InfoPayload) *InfoResult
GetEventInfo(*EventInfoPayload) *EventInfoResult
ListEvents(*EventListPayload) *EventListResult
}
type EventServiceImpl struct{}