Skip to content

Commit

Permalink
Event RSVP endpoint creation for FE
Browse files Browse the repository at this point in the history
  • Loading branch information
Alder Whiteford authored and Alder Whiteford committed Jun 20, 2024
1 parent e3f8575 commit 2fbd9c8
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 9 deletions.
11 changes: 5 additions & 6 deletions backend/entities/events/rsvps/routes.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,15 @@ package rsvps
import (
"github.com/GenerateNU/sac/backend/permission"
"github.com/GenerateNU/sac/backend/types"
"github.com/gofiber/fiber/v2"
)

func EventsRSVPs(params types.RouteParams) {
controller := NewController(NewHandler(params.ServiceParams))

// api/v1/events/:eventID/rsvps/*
params.Router.Route("/rsvps", func(r fiber.Router) {
r.Get("/", params.UtilityMiddleware.Paginator, controller.GetEventRSVPs)
r.Post("/:userID", controller.CreateEventRSVP)
r.Delete("/:userID", params.AuthMiddleware.UserAuthorizeById, params.AuthMiddleware.Authorize(permission.DeleteAll), controller.DeleteEventRSVP)
})
eventRSVPS := params.Router.Group("/:eventID/rsvps")

eventRSVPS.Get("/", params.UtilityMiddleware.Paginator, controller.GetEventRSVPs)
eventRSVPS.Post("/:userID", params.AuthMiddleware.UserAuthorizeById, controller.CreateEventRSVP)
eventRSVPS.Delete("/:userID", params.AuthMiddleware.UserAuthorizeById, params.AuthMiddleware.Authorize(permission.DeleteAll), controller.DeleteEventRSVP)
}
2 changes: 1 addition & 1 deletion backend/integrations/oauth/soth/msft_web/msft_web.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ var defaultScopes = []string{"openid", "offline_access", "user.read", "calendars
func New(clientKey *m.Secret[string], secret *m.Secret[string], callbackURL string, tenant string, scopes ...string) *Provider {
p := &Provider{
ClientKey: clientKey,
Secret: secret,
Secret: secret,
CallbackURL: callbackURL,
ProviderName: "microsoftonlineweb",
tenant: tenant,
Expand Down
2 changes: 1 addition & 1 deletion frontend/lib/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@generatesac/lib",
"version": "0.0.186",
"version": "0.0.187",
"type": "module",
"main": "dist/index.js",
"types": "dist/index.d.ts",
Expand Down
33 changes: 32 additions & 1 deletion frontend/lib/src/api/eventApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,15 @@ import {
CreateEventRequestBody,
Event,
EventPreview,
EventUserParams,
UpdateEventRequestBody,
eventPreviewSchema,
eventSchema,
} from "../types/event";
import { PaginationQueryParams } from "../types/root";
import { Tag } from "../types/tag";
import { Tag, tagSchema } from "../types/tag";
import { baseApi, handleQueryParams } from "./base";
import { User, userSchema } from "../types";

const EVENT_API_BASE_URL = "/events";

Expand Down Expand Up @@ -102,6 +104,35 @@ export const eventApi = baseApi.injectEndpoints({
}),
providesTags: (result) =>
result ? result.map((tag) => ({ type: "Tag", id: tag.id })) : ["Tag"],
transformResponse: (response) => {
return z.array(tagSchema).parse(response);
}
}),
createEventRegistration: builder.mutation<User[], EventUserParams>({
query: ({ user_id, event_id }) => ({
url: `${EVENT_API_BASE_URL}/${event_id}/rsvps/${user_id}`,
method: "POST",
responseHandler: 'text'
}),
transformResponse: (response) => {
return z.array(userSchema).parse(response);
}
}),
deleteEventRegistration: builder.mutation<void, EventUserParams>({
query: ({ user_id, event_id }) => ({
url: `${EVENT_API_BASE_URL}/${event_id}/rsvps/${user_id}`,
method: "DELETE",
responseHandler: 'text',
}),
}),
eventRegistrations: builder.query<User[], string>({
query: (id) => ({
url: `${EVENT_API_BASE_URL}/${id}/rsvps`,
method: "GET",
}),
transformResponse: (response) => {
return z.array(userSchema).parse(response);
},
}),
}),
});
6 changes: 6 additions & 0 deletions frontend/lib/src/types/event.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,11 @@ const eventPreviewSchemaIntermediate = z.object({
host_logo: z.string().max(255).optional(),
});

const eventUserParams = z.object({
event_id: z.string().uuid(),
user_id: z.string().uuid(),
})

export const eventSchema = eventSchemaIntermediate.merge(rootModelSchema);
export const eventPreviewSchema = eventPreviewSchemaIntermediate

Expand All @@ -77,3 +82,4 @@ export type UpdateEventRequestBody = z.infer<
export type Event = z.infer<typeof eventSchema>;
export type EventPreview = z.infer<typeof eventPreviewSchema>;
export type EventType = z.infer<typeof eventTypeEnum>;
export type EventUserParams = z.infer<typeof eventUserParams>;
1 change: 1 addition & 0 deletions frontend/mobile/src/app/auth/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ const WelcomePage = () => {
const handleLogin = () => {
login().then(async ({ data }) => {
if (data) {
console.log(data.sac_session);
await Linking.openURL(data.redirect_uri);
dispatch(setAccessToken(data.sac_session));
}
Expand Down

0 comments on commit 2fbd9c8

Please sign in to comment.