Remove search engine, add event list api
Signed-off-by: Asai Neko <sugar@sne.moe>
This commit is contained in:
65
api/event/list.go
Normal file
65
api/event/list.go
Normal file
@@ -0,0 +1,65 @@
|
||||
package event
|
||||
|
||||
import (
|
||||
"nixcn-cms/internal/exception"
|
||||
"nixcn-cms/service/service_event"
|
||||
"nixcn-cms/utils"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
// List retrieves a paginated list of events from the database.
|
||||
//
|
||||
// @Summary List Events
|
||||
// @Description Fetches a list of events with support for pagination via limit and offset. Data is retrieved directly from the database for consistency.
|
||||
// @Tags Event
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Param limit query string false "Maximum number of events to return (default 20)"
|
||||
// @Param offset query string true "Number of events to skip"
|
||||
// @Success 200 {object} utils.RespStatus{data=[]data.EventIndexDoc} "Successful paginated list retrieval"
|
||||
// @Failure 400 {object} utils.RespStatus{data=nil} "Invalid Input (Missing offset or malformed parameters)"
|
||||
// @Failure 500 {object} utils.RespStatus{data=nil} "Internal Server Error (Database query failed)"
|
||||
// @Security ApiKeyAuth
|
||||
// @Router /event/list [get]
|
||||
func (self *EventHandler) List(c *gin.Context) {
|
||||
type ListQuery struct {
|
||||
Limit *string `form:"limit"`
|
||||
Offset *string `form:"offset"`
|
||||
}
|
||||
|
||||
var query ListQuery
|
||||
if err := c.ShouldBindQuery(&query); err != nil {
|
||||
// Handle binding error (e.g., syntax errors in query string)
|
||||
exc := new(exception.Builder).
|
||||
SetStatus(exception.StatusClient).
|
||||
SetService(exception.ServiceEvent).
|
||||
SetEndpoint(exception.EndpointEventServiceList).
|
||||
SetType(exception.TypeCommon).
|
||||
SetOriginal(exception.CommonErrorInvalidInput).
|
||||
Throw(c).
|
||||
String()
|
||||
|
||||
utils.HttpResponse(c, 400, exc)
|
||||
return
|
||||
}
|
||||
|
||||
// Prepare payload for the service layer
|
||||
eventListPayload := &service_event.EventListPayload{
|
||||
Context: c,
|
||||
Limit: query.Limit,
|
||||
Offset: query.Offset,
|
||||
}
|
||||
|
||||
// Call the service implementation
|
||||
result := self.svc.ListEvents(eventListPayload)
|
||||
|
||||
// Check if the service returned any exception
|
||||
if result.Common.Exception.Original != exception.CommonSuccess {
|
||||
utils.HttpResponse(c, result.Common.HttpCode, result.Common.Exception.String())
|
||||
return
|
||||
}
|
||||
|
||||
// Return successful response with event data
|
||||
utils.HttpResponse(c, result.Common.HttpCode, result.Common.Exception.String(), result.Data)
|
||||
}
|
||||
Reference in New Issue
Block a user