Add agenda service and submit api
Signed-off-by: Asai Neko <sugar@sne.moe>
This commit is contained in:
94
api/event/joined.go
Normal file
94
api/event/joined.go
Normal file
@@ -0,0 +1,94 @@
|
||||
package event
|
||||
|
||||
import (
|
||||
"nixcn-cms/internal/exception"
|
||||
"nixcn-cms/service/service_event"
|
||||
"nixcn-cms/utils"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/google/uuid"
|
||||
)
|
||||
|
||||
// GetJoined retrieves a paginated list of events that the current user has joined.
|
||||
//
|
||||
// @Summary Get Joined Events
|
||||
// @Description Fetches a list of events where the authenticated user is a participant. Supports pagination.
|
||||
// @Tags Event
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Param limit query int false "Maximum number of events to return (default 20)"
|
||||
// @Param offset query int false "Number of events to skip"
|
||||
// @Success 200 {object} utils.RespStatus{data=[]data.EventIndexDoc} "Successful retrieval of joined events"
|
||||
// @Failure 400 {object} utils.RespStatus{data=nil} "Invalid Input"
|
||||
// @Failure 401 {object} utils.RespStatus{data=nil} "Unauthorized"
|
||||
// @Failure 500 {object} utils.RespStatus{data=nil} "Internal Server Error"
|
||||
// @Security ApiKeyAuth
|
||||
// @Router /event/joined [get]
|
||||
func (self *EventHandler) Joined(c *gin.Context) {
|
||||
userIdOrig, ok := c.Get("user_id")
|
||||
if !ok {
|
||||
errorCode := new(exception.Builder).
|
||||
SetStatus(exception.StatusUser).
|
||||
SetService(exception.ServiceUser).
|
||||
SetEndpoint(exception.EndpointUserServiceInfo).
|
||||
SetType(exception.TypeCommon).
|
||||
SetOriginal(exception.CommonErrorMissingUserId).
|
||||
Throw(c).
|
||||
String()
|
||||
utils.HttpResponse(c, 403, errorCode)
|
||||
return
|
||||
}
|
||||
|
||||
userId, err := uuid.Parse(userIdOrig.(string))
|
||||
if err != nil {
|
||||
errorCode := new(exception.Builder).
|
||||
SetStatus(exception.StatusServer).
|
||||
SetService(exception.ServiceUser).
|
||||
SetEndpoint(exception.EndpointUserServiceInfo).
|
||||
SetType(exception.TypeCommon).
|
||||
SetOriginal(exception.CommonErrorUuidParseFailed).
|
||||
SetError(err).
|
||||
Throw(c).
|
||||
String()
|
||||
utils.HttpResponse(c, 500, errorCode)
|
||||
return
|
||||
}
|
||||
|
||||
type JoinedQuery struct {
|
||||
Limit *string `form:"limit"`
|
||||
Offset *string `form:"offset"`
|
||||
}
|
||||
|
||||
var query JoinedQuery
|
||||
if err := c.ShouldBindQuery(&query); err != nil {
|
||||
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
|
||||
}
|
||||
|
||||
payload := &service_event.JoinedEventListPayload{
|
||||
Context: c,
|
||||
UserId: userId,
|
||||
Data: &service_event.JoinedEventListData{
|
||||
Limit: query.Limit,
|
||||
Offset: query.Offset,
|
||||
},
|
||||
}
|
||||
|
||||
result := self.svc.GetJoinedEvent(payload)
|
||||
|
||||
if result.Common.Exception.Original != exception.CommonSuccess {
|
||||
utils.HttpResponse(c, result.Common.HttpCode, result.Common.Exception.String())
|
||||
return
|
||||
}
|
||||
|
||||
utils.HttpResponse(c, result.Common.HttpCode, result.Common.Exception.String(), result.Data)
|
||||
}
|
||||
Reference in New Issue
Block a user