Skip to content

Commit bd05d14

Browse files
feat: Event card integration
1 parent 1697384 commit bd05d14

15 files changed

Lines changed: 944 additions & 782 deletions

File tree

apps/api/internal/api/handlers/events.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@ func (h *EventHandler) DeleteEventById(w http.ResponseWriter, r *http.Request) {
224224

225225
func (h *EventHandler) GetEvents(w http.ResponseWriter, r *http.Request) {
226226
// Parse query params
227-
// inlcude_unpublished="true,false", default: false
227+
// include_unpublished="true,false", default: false
228228
queryParams := r.URL.Query()
229229
includeUnpublished, err := web.ParseParamBoolean(queryParams, "include_unpublished", ptr.BoolToPtr(false))
230230
if err != nil {

apps/api/internal/ctxutils/user.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ func IsUser(ctx context.Context) bool {
2828
return userCtx.Role == sqlc.AuthUserRoleUser
2929
}
3030

31+
// Takes in the request context and returns the userID or nil if not retrievable
3132
func GetUserIdFromCtx(ctx context.Context) *uuid.UUID {
3233
userCtx, ok := ctx.Value(mw.UserContextKey).(*mw.UserContext)
3334
if !ok {

apps/api/internal/db/queries/events.sql

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,13 +76,17 @@ LEFT JOIN event_roles AS er
7676
AND er.user_id = $1
7777
ORDER BY e.start_time ASC;
7878

79-
-- name: GetEventsWithRoles :many
79+
-- name: GetEventsWithUserInfo :many
8080
SELECT
8181
e.*,
82-
er.role AS event_role
82+
er.role AS event_role,
83+
a.status AS application_status
8384
FROM events e
8485
LEFT JOIN event_roles er
8586
ON er.event_id = e.id
8687
AND er.user_id = sqlc.narg(user_id)
88+
LEFT JOIN applications a
89+
ON a.event_id = e.id
90+
AND a.user_id = sqlc.narg(user_id)
8791
WHERE (sqlc.arg(include_unpublished)::boolean IS TRUE OR e.is_published = TRUE)
8892
ORDER BY e.start_time ASC;

apps/api/internal/db/repository/events.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,8 +84,8 @@ func (r *EventRepository) GetPublishedEvents(ctx context.Context, userId uuid.UU
8484
return &events, err
8585
}
8686

87-
func (r *EventRepository) GetEventsWithRoles(ctx context.Context, userId *uuid.UUID, includeUnpublished bool) (*[]sqlc.GetEventsWithRolesRow, error) {
88-
events, err := r.db.Query.GetEventsWithRoles(ctx, sqlc.GetEventsWithRolesParams{
87+
func (r *EventRepository) GetEventsWithRoles(ctx context.Context, userId *uuid.UUID, includeUnpublished bool) (*[]sqlc.GetEventsWithUserInfoRow, error) {
88+
events, err := r.db.Query.GetEventsWithUserInfo(ctx, sqlc.GetEventsWithUserInfoParams{
8989
UserID: userId,
9090
IncludeUnpublished: includeUnpublished,
9191
})

apps/api/internal/db/sqlc/events.sql.go

Lines changed: 31 additions & 25 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

apps/api/internal/db/sqlc/querier.go

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

apps/api/internal/services/events.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ func (s *EventService) DeleteEventById(ctx context.Context, id uuid.UUID) error
9898
return err
9999
}
100100

101-
func (s *EventService) GetEvents(ctx context.Context, includeUnpublished bool) (*[]sqlc.GetEventsWithRolesRow, error) {
101+
func (s *EventService) GetEvents(ctx context.Context, includeUnpublished bool) (*[]sqlc.GetEventsWithUserInfoRow, error) {
102102
isSuperuser := ctxu.IsSuperuser(ctx)
103103
userId := ctxu.GetUserIdFromCtx(ctx)
104104

apps/web/src/features/Admin/EventManager/hooks/useAdminEvents.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ type Events =
88
operations["get-events"]["responses"]["200"]["content"]["application/json"];
99

1010
export async function fetchEvents(): Promise<Events> {
11-
const result = await api.get<Events>("events").json();
11+
const result = await api.get<Events>("events?include_unpublished=true").json();
1212
console.log(result);
1313
return result;
1414
}

apps/web/src/features/Event/components/EventCard.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import type applicationStatus from "../applicationStatus";
1010
import { Separator } from "@/components/ui/Seperator";
1111
import { Card } from "@/components/ui/Card";
1212

13-
interface EventCardProps {
13+
export interface EventCardProps {
1414
eventId: string;
1515
status: keyof typeof applicationStatus;
1616
title: string;
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import { api } from "@/lib/ky";
2+
import type { operations } from "@/lib/openapi/schema";
3+
import { useQuery } from "@tanstack/react-query";
4+
5+
export const eventsQueryKey = ["events", "published"] as const;
6+
7+
export type EventsWithUserInfo =
8+
operations["get-events"]["responses"]["200"]["content"]["application/json"];
9+
10+
export async function fetchEvents(): Promise<EventsWithUserInfo> {
11+
const result = await api.get<EventsWithUserInfo>("events?include_unpublished=false").json();
12+
return result;
13+
}
14+
15+
export function useAdminEvents() {
16+
return useQuery({
17+
queryKey: eventsQueryKey,
18+
queryFn: fetchEvents,
19+
staleTime: 1000 * 60 * 5, // 5 minutes
20+
});
21+
}

0 commit comments

Comments
 (0)