Skip to content

Commit

Permalink
list participants
Browse files Browse the repository at this point in the history
  • Loading branch information
ARUMANDESU committed May 31, 2024
1 parent 767d291 commit fb3e4fe
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 0 deletions.
36 changes: 36 additions & 0 deletions internal/handler/event/info.go
Original file line number Diff line number Diff line change
Expand Up @@ -457,3 +457,39 @@ func (h *Handler) GetUserInvites(c *gin.Context) {

c.JSON(http.StatusOK, gin.H{"invites": res.GetInvites()})
}

func (h *Handler) ListParticipantsHandler(c *gin.Context) {
const op = "EventHandler.ListParticipantsHandler"
log := h.log.With(slog.String("op", op))

eventID := c.Params.ByName("id")
if eventID == "" {
c.AbortWithStatusJSON(http.StatusBadRequest, gin.H{"error": "event_id parameter must be provided"})
return
}

page, err := utils.GetIntFromQuery(c, "page")
if err != nil && !strings.Contains(err.Error(), "query parameter must be provided") {
c.AbortWithStatusJSON(http.StatusBadRequest, gin.H{"error": err.Error()})
return
}

pageSize, err := utils.GetIntFromQuery(c, "page_size")
if err != nil && !strings.Contains(err.Error(), "query parameter must be provided") {
c.AbortWithStatusJSON(http.StatusBadRequest, gin.H{"error": err.Error()})
return
}

res, err := h.eventClient.ListParticipants(c, &eventv1.ListParticipantsRequest{
EventId: eventID,
Query: c.Query("query"),
PageNumber: int32(page),
PageSize: int32(pageSize),
})
if err != nil {
h.handleEventError(c, log, err)
return
}

c.JSON(http.StatusOK, gin.H{"participants": domain.ProtoToEventUserArr(res.Participants), "metadata": res.Metadata})
}
1 change: 1 addition & 0 deletions internal/handler/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@ func (h *Handler) InitRoutes() *gin.Engine {
{
eventPath.GET("/:id", h.UsrHandler.GetUserIDMiddleware(), h.EventHandler.GetEventHandler)
eventPath.GET("", h.EventHandler.ListPublishedEventsHandler)
eventPath.GET("/:id/participants", h.EventHandler.ListParticipantsHandler)

eventPathAuth := eventPath.Group("")
{
Expand Down

0 comments on commit fb3e4fe

Please sign in to comment.