-
Notifications
You must be signed in to change notification settings - Fork 2
feat: complete webhook and add auto assign commands #260
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 10 commits
e059f38
90088cc
541fa02
9538b2f
671a2eb
554027e
28af3e4
b88cc37
e9bf979
625bfd3
f9faa87
39b2d82
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -120,6 +120,12 @@ func (api *API) setupRoutes(mw *mw.Middleware) { | |
| r.Post("/join/{requestId}/reject", api.Handlers.Teams.RejectTeamJoinRequest) | ||
| }) | ||
|
|
||
| // --- Discord routes (for Discord bot) --- | ||
| api.Router.Route("/discord", func(r chi.Router) { | ||
| r.Use(mw.Auth.RequireAuth) | ||
| r.Get("/event/{event_id}/attendees", api.Handlers.Discord.GetEventAttendeesWithDiscord) | ||
| }) | ||
|
|
||
| // --- Event routes --- | ||
| api.Router.Route("/events", func(r chi.Router) { | ||
| r.Post("/{eventId}/calc-admissions", api.Handlers.Admission.HandleCalculateAdmissionsRequest) | ||
|
|
@@ -139,6 +145,7 @@ func (api *API) setupRoutes(mw *mw.Middleware) { | |
|
|
||
| r.Get("/", api.Handlers.Event.GetEventByID) | ||
| r.Get("/role", api.Handlers.Event.GetEventRole) | ||
| r.Get("/discord/{discordId}", api.Handlers.Discord.GetUserEventRoleByDiscordIDAndEventId) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In a later refactor, we should probably move this to GET /discord/account/{discordId}/ under the Discord Routes section |
||
|
|
||
| r.With(ensureEventStaff).Get("/overview", api.Handlers.Event.GetEventOverview) | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,111 @@ | ||
| package handlers | ||
| import ( | ||
| "encoding/json" | ||
| "net/http" | ||
|
|
||
| "github.com/go-chi/chi/v5" | ||
| "github.com/google/uuid" | ||
| "github.com/rs/zerolog" | ||
| res "github.com/swamphacks/core/apps/api/internal/api/response" | ||
| "github.com/swamphacks/core/apps/api/internal/services" | ||
| ) | ||
|
|
||
| type DiscordHandler struct { | ||
| discordService *services.DiscordService | ||
| logger zerolog.Logger | ||
| } | ||
|
|
||
| func NewDiscordHandler(discordService *services.DiscordService, logger zerolog.Logger) *DiscordHandler { | ||
| return &DiscordHandler{ | ||
| discordService: discordService, | ||
| logger: logger.With().Str("handler", "DiscordHandler").Str("component", "discord").Logger(), | ||
| } | ||
| } | ||
|
|
||
| // GetEventAttendeesWithDiscord | ||
| // | ||
| // @Summary Get event attendees with Discord IDs | ||
| // @Description Get all attendees for an event who have Discord accounts linked | ||
| // @Tags Discord | ||
| // @Param event_id path string true "Event ID (UUID)" | ||
| // @Success 200 {array} sqlc.GetEventAttendeesWithDiscordRow "List of attendees with Discord IDs" | ||
| // @Failure 400 {object} response.ErrorResponse "Invalid event ID" | ||
| // @Failure 500 {object} response.ErrorResponse "Internal server error" | ||
| // @Router /discord/event/{event_id}/attendees [get] | ||
| func (h *DiscordHandler) GetEventAttendeesWithDiscord(w http.ResponseWriter, r *http.Request) { | ||
| eventIDStr := chi.URLParam(r, "event_id") | ||
| if eventIDStr == "" { | ||
| res.SendError(w, http.StatusBadRequest, res.NewError("bad_request", "event_id is required")) | ||
| return | ||
| } | ||
|
|
||
| eventID, err := uuid.Parse(eventIDStr) | ||
| if err != nil { | ||
| res.SendError(w, http.StatusBadRequest, res.NewError("bad_request", "invalid event ID format")) | ||
| return | ||
| } | ||
|
|
||
| attendees, err := h.discordService.GetEventAttendeesWithDiscord(r.Context(), eventID) | ||
| if err != nil { | ||
| h.logger.Err(err).Msg("failed to get event attendees with discord") | ||
| res.SendError(w, http.StatusInternalServerError, res.NewError("internal_error", "Failed to get attendees")) | ||
| return | ||
| } | ||
|
|
||
| w.Header().Set("Content-Type", "application/json") | ||
| if err := json.NewEncoder(w).Encode(attendees); err != nil { | ||
| h.logger.Err(err).Msg("failed to encode response") | ||
| res.SendError(w, http.StatusInternalServerError, res.NewError("internal_error", "Failed to encode response")) | ||
| return | ||
| } | ||
| } | ||
|
|
||
| // GetUserEventRoleByDiscordIDAndEventId | ||
| // | ||
| // @Summary Get user event role by Discord ID and Event ID | ||
| // @Description Get the event role for a user based on their Discord account ID and a specific event ID | ||
| // @Tags Discord | ||
| // @Param eventId path string true "Event ID (UUID)" | ||
| // @Param discordId path string true "Discord account ID" | ||
| // @Success 200 {object} map[string]interface{} "role" | ||
| // @Failure 400 {object} response.ErrorResponse "Invalid event ID or discord ID" | ||
| // @Failure 404 {object} response.ErrorResponse "User or role not found" | ||
| // @Failure 500 {object} response.ErrorResponse "Internal server error" | ||
| // @Router /events/{eventId}/discord/{discordId} [get] | ||
| func (h *DiscordHandler) GetUserEventRoleByDiscordIDAndEventId(w http.ResponseWriter, r *http.Request) { | ||
| eventIDStr := chi.URLParam(r, "eventId") | ||
| if eventIDStr == "" { | ||
| res.SendError(w, http.StatusBadRequest, res.NewError("bad_request", "eventId is required")) | ||
| return | ||
| } | ||
|
|
||
| eventID, err := uuid.Parse(eventIDStr) | ||
| if err != nil { | ||
| res.SendError(w, http.StatusBadRequest, res.NewError("bad_request", "invalid event ID format")) | ||
| return | ||
| } | ||
|
|
||
| discordID := chi.URLParam(r, "discordId") | ||
| if discordID == "" { | ||
| res.SendError(w, http.StatusBadRequest, res.NewError("bad_request", "discordId is required")) | ||
| return | ||
| } | ||
|
|
||
| role, err := h.discordService.GetUserEventRoleByDiscordIDAndEventId(r.Context(), discordID, eventID) | ||
| if err != nil { | ||
| if err == services.ErrNoEventRole { | ||
| res.SendError(w, http.StatusNotFound, res.NewError("not_found", err.Error())) | ||
| return | ||
| } | ||
| h.logger.Err(err).Msg("failed to get user event role") | ||
| res.SendError(w, http.StatusInternalServerError, res.NewError("internal_error", "Failed to get user role")) | ||
| return | ||
| } | ||
|
|
||
| response := map[string]interface{}{ | ||
| "role": role, | ||
| } | ||
|
|
||
| w.Header().Set("Content-Type", "application/json") | ||
| json.NewEncoder(w).Encode(response) | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -31,3 +31,8 @@ WHERE provider_id = $1 AND account_id = $2; | |
| -- name: DeleteAccount :exec | ||
| DELETE FROM auth.accounts | ||
| WHERE provider_id = $1 AND account_id = $2; | ||
|
|
||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. if this and its repo function isn't being used anywhere it should be removed, but since we are low on time im okay with doing that in a refactor later |
||
| -- name: GetUserIDByDiscordAccountID :one | ||
| SELECT user_id | ||
| FROM auth.accounts | ||
| WHERE provider_id = 'discord' AND account_id = $1; | ||
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
delete pls