Skip to content
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

Fix/list all events in previous events view #100

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 26 additions & 6 deletions app/api/events.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from datetime import datetime, timedelta
from datetime import datetime, timedelta, timezone
import os
import shutil
from fastapi import APIRouter, Response, Request, HTTPException, Depends, BackgroundTasks
from fastapi import APIRouter, Response, Request, HTTPException, Depends, BackgroundTasks, Query
from fastapi.datastructures import UploadFile
from fastapi.param_functions import File
from pydantic import ValidationError
Expand Down Expand Up @@ -93,9 +93,28 @@ def get_upcoming_events(request: Request, token: AccessTokenPayload = Depends(op
return [Event.model_validate(event) for event in upcoming_events]


@router.get('/past-events/count')
def get_past_events_count(request: Request, token: AccessTokenPayload = Depends(optional_authentication)):
"""Get count of past events"""
db = get_database(request)

# Get current UTC datetime
current_datetime = datetime.now(timezone.utc)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This endpoint uses timezone.utc, but none of the others do. This might lead to wrong results here

# Apply search filter according to role
search_filter = {"date": {"$lt": current_datetime}}
if token and token.role != Role.admin:
search_filter["public"] = True

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure this is leads to a valid mongodb query. You can copy the search filter logic from the get_past_events endpoint instead

# Count the number of documents that match the filter
count = db.events.count_documents(search_filter)
return {"count": count}

@router.get('/past-events')
def get_past_events(request: Request, token: AccessTokenPayload = Depends(optional_authentication)):
""" Get last 10 events that have passed """
def get_past_events(request: Request, token: AccessTokenPayload = Depends(optional_authentication),
skip: int = Query(0, ge=0),
limit: int = Query(10,ge=1,le=50)):
""" Get last events that have passed """
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Like I commented on the frontend, another design here that might be simpler is to simply use a hardcoded limit, instead of allowing clients to supply it in the query parameters. If you choose to simplify it, remember to do it both on the api and the frontend.

# TODO: Expand endpoint to accept custom amount?
db = get_database(request)

Expand All @@ -110,11 +129,12 @@ def get_past_events(request: Request, token: AccessTokenPayload = Depends(option
if token and token.role == Role.admin:
search_filter = {'date': {"$lt": date}}

# Get the last 10 events
# Get the last events
pipeline = [
{"$match": search_filter},
{"$sort": {"date": -1}},
{"$limit": 10}
{"$skip": skip},
{"$limit": limit},
]

res = db.events.aggregate(pipeline)
Expand Down
257 changes: 256 additions & 1 deletion db/seeds/events.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,5 +50,260 @@
"bindingRegistration": true,
"registrationOpeningDate": "2030-04-15 16:30:00",
"registeredPenalties": []
},
{
"eid": "6819761d9f814b1897cda685c658b19c",
"title": "Teknologisk fremtid med CompTech",
"address": "Realfagbygget C112",
"date": "2022-05-15 10:00:00",
"duration": 2,
"price": 0,
"maxParticipants": 40,
"description": "CompTech holder en inspirerende presentasjon om teknologiske nyvinninger og hvordan de påvirker samfunnet vårt. Det blir en diskusjonsrunde med mingling etterpå.",
"picturePath": "db/eventImages/uuid4.png",
"participants": [],
"transportation": true,
"food": true,
"public": false,
"bindingRegistration": false,
"registeredPenalties": []
},
{
"eid": "ff7f44d7ae784bfb8c1a795bffb8b456",
"title": "Foredrag om bærekraft",
"address": "Universitetsaulaen",
"date": "2022-06-12 14:00:00",
"duration": 2,
"price": 0,
"maxParticipants": 100,
"description": "Et foredrag om hvordan teknologibransjen kan bidra til bærekraftige løsninger i fremtiden. Foredragsholdere fra flere kjente selskaper vil være tilstede.",
"picturePath": "db/eventImages/uuid5.png",
"participants": [],
"transportation": false,
"food": true,
"public": true,
"bindingRegistration": true,
"registeredPenalties": []
},
{
"eid": "76fa60301e724fa5acbc3d01ec106d1f",
"title": "Workshop om AI og ML",
"address": "Realfagbygget A101",
"date": "2022-07-14 15:00:00",
"duration": 3,
"price": 50,
"maxParticipants": 50,
"description": "Delta på en spennende workshop om AI og maskinlæring, med fokus på nybegynnere og viderekomne. Mat og drikke blir servert.",
"picturePath": "db/eventImages/uuid6.png",
"participants": [],
"transportation": false,
"food": true,
"public": true,
"bindingRegistration": false,
"registeredPenalties": []
},
{
"eid": "10108a19e6dd4863a500755678467095",
"title": "Networking med Startups",
"address": "Innovasjonsparken",
"date": "2022-08-10 18:00:00",
"duration": 2,
"price": 0,
"maxParticipants": 40,
"description": "Bli med på en spennende kveld med networking. Møt representanter fra ulike startups og lær om deres spennende prosjekter.",
"picturePath": "db/eventImages/uuid7.png",
"participants": [],
"transportation": true,
"food": true,
"public": true,
"bindingRegistration": true,
"registeredPenalties": []
},
{
"eid": "74d6ad1b442546e4b762935301ed252f",
"title": "Hackathon: Code for a Cause",
"address": "Informatikkbygget D200",
"date": "2022-09-15 09:00:00",
"duration": 8,
"price": 0,
"maxParticipants": 100,
"description": "Delta på hackathon for en god sak. Utvikle løsninger som kan hjelpe lokale organisasjoner med teknologibaserte utfordringer.",
"picturePath": "db/eventImages/uuid8.png",
"participants": [],
"transportation": false,
"food": true,
"public": false,
"bindingRegistration": true,
"registeredPenalties": []
},
{
"eid": "5bcea836b3cb489eb658b9e5ab0a93b7",
"title": "Introkurs i Python",
"address": "Realfagbygget B120",
"date": "2022-10-02 12:00:00",
"duration": 3,
"price": 0,
"maxParticipants": 25,
"description": "Et kurs for nybegynnere i Python-programmering. Lær grunnleggende konsepter og bygg dine første programmer.",
"picturePath": "db/eventImages/uuid9.png",
"participants": [],
"transportation": false,
"food": true,
"public": true,
"bindingRegistration": false,
"registeredPenalties": []
},
{
"eid": "59669e52716f4e82bf5365498b79bb8c",
"title": "Kveldsmingling med Accenture",
"address": "Realfagbygget A200",
"date": "2022-11-05 17:00:00",
"duration": 2,
"price": 0,
"maxParticipants": 30,
"description": "Accenture inviterer til mingling og nettverksbygging. Lær om deres prosjekter og karrieremuligheter i selskapet.",
"picturePath": "db/eventImages/uuid10.png",
"participants": [],
"transportation": true,
"food": false,
"public": true,
"bindingRegistration": true,
"registeredPenalties": []
},
{
"eid": "d01da25dc2894dcdbb098bb28752c6e5",
"title": "Workshop i prosjektledelse",
"address": "Informatikkbygget A110",
"date": "2022-12-10 14:00:00",
"duration": 2,
"price": 20,
"maxParticipants": 20,
"description": "Lær grunnleggende prosjektledelse og metodikk som Scrum og Kanban. Perfekt for deg som ønsker å lede egne prosjekter.",
"picturePath": "db/eventImages/uuid11.png",
"participants": [],
"transportation": false,
"food": false,
"public": true,
"bindingRegistration": false,
"registeredPenalties": []
},
{
"eid": "99fb1f7b428d4fd3a3856fa184f345ec",
"title": "Introduksjon til UI/UX design",
"address": "Realfagbygget C204",
"date": "2022-04-22 09:30:00",
"duration": 2,
"price": 0,
"maxParticipants": 35,
"description": "Lær om prinsipper for UI/UX design og hvordan du kan forbedre brukeropplevelsen i dine prosjekter.",
"picturePath": "db/eventImages/uuid12.png",
"participants": [],
"transportation": true,
"food": false,
"public": false,
"bindingRegistration": true,
"registeredPenalties": []
},
{
"eid": "a6cab28b4de540d9a47f2ee55807b102",
"title": "Workshop i DevOps",
"address": "Informatikkbygget E120",
"date": "2022-05-17 16:00:00",
"duration": 2,
"price": 0,
"maxParticipants": 40,
"description": "Lær DevOps-verktøy og metodikk, inkludert CI/CD og automatisering. En praktisk workshop for teknologientusiaster.",
"picturePath": "db/eventImages/uuid13.png",
"participants": [],
"transportation": true,
"food": true,
"public": true,
"bindingRegistration": true,
"registeredPenalties": []
},
{
"eid": "37c3970af14546028467ef6235de3dff",
"title": "Forelesning i IT-sikkerhet",
"address": "Realfagbygget B101",
"date": "2022-06-20 12:00:00",
"duration": 2,
"price": 0,
"maxParticipants": 45,
"description": "Bli med på en informativ forelesning om cybersikkerhet og hvilke trusler bedrifter står overfor.",
"picturePath": "db/eventImages/uuid14.png",
"participants": [],
"transportation": true,
"food": false,
"public": false,
"bindingRegistration": true,
"registeredPenalties": []
},
{
"eid": "a891362a04e345e79810aec1d451386b",
"title": "Kodekveld med Open Source",
"address": "Informatikkbygget A220",
"date": "2022-09-25 17:30:00",
"duration": 3,
"price": 0,
"maxParticipants": 20,
"description": "Utforsk verdenen av open-source-prosjekter. Lær hvordan du kan bidra og hva som skal til for å bli en open-source-utvikler.",
"picturePath": "db/eventImages/uuid15.png",
"participants": [],
"transportation": false,
"food": true,
"public": true,
"bindingRegistration": false,
"registeredPenalties": []
},
{
"eid": "a07930c3119746f586d029cb9d89ad67",
"title": "Foredrag: Karriereveier i tech",
"address": "Realfagbygget A003",
"date": "2022-03-23 15:00:00",
"duration": 2,
"price": 0,
"maxParticipants": 50,
"description": "Lær om muligheter og karriereveier i teknologibransjen. Ideelt for nyutdannede og studenter som vurderer ulike retninger.",
"picturePath": "db/eventImages/uuid16.png",
"participants": [],
"transportation": true,
"food": true,
"public": true,
"bindingRegistration": true,
"registeredPenalties": []
},
{
"eid": "322e7ad606fb4be2b79208aab6c81eb8",
"title": "Workshop i datastrukturer",
"address": "Informatikkbygget C103",
"date": "2022-11-08 13:00:00",
"duration": 2,
"price": 0,
"maxParticipants": 30,
"description": "Grunnleggende workshop i datastrukturer og algoritmer. Lær om lister, stakker, køer og trær, samt deres praktiske anvendelser.",
"picturePath": "db/eventImages/uuid17.png",
"participants": [],
"transportation": false,
"food": false,
"public": true,
"bindingRegistration": true,
"registeredPenalties": []
},
{
"eid": "09effc6304fe489c921cadc53e195efa",
"title": "Introduksjon til Kotlin",
"address": "Realfagbygget A200",
"date": "2022-10-05 10:00:00",
"duration": 2,
"price": 0,
"maxParticipants": 15,
"description": "Et introduksjonskurs i programmeringsspråket Kotlin, spesielt for Java-utviklere som ønsker å lære mer.",
"picturePath": "db/eventImages/uuid18.png",
"participants": [],
"transportation": true,
"food": true,
"public": true,
"bindingRegistration": true,
"registeredPenalties": []
}
]
]
Loading
Loading