Skip to content

Commit

Permalink
Merge pull request #107 from ECE444-2023Fall/filtering
Browse files Browse the repository at this point in the history
Search, filter and sort.
  • Loading branch information
tmahabir authored Nov 13, 2023
2 parents e8aa587 + e263c97 commit 55fc3a8
Show file tree
Hide file tree
Showing 17 changed files with 987 additions and 155 deletions.
75 changes: 75 additions & 0 deletions backend/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,43 @@ def get_all_tags():
500,
)

@app.route("/api/get-all-locations", methods=["GET"])
def get_all_locations():
try:
from .datalayer.event import EventDataLayer

event_data = EventDataLayer()
locations = event_data.get_all_locations()
return jsonify(locations)
except Exception as e:
error_message = str(e)
return (
jsonify(
{
"error": "Failed to get all locations",
"error message": error_message,
}
),
500,
)

@app.route("/api/get-all-clubs", methods=["GET"])
def get_all_clubs():
try:
from .datalayer.event import EventDataLayer

event_data = EventDataLayer()
clubs = event_data.get_all_clubs()
return jsonify(clubs)
except Exception as e:
error_message = str(e)
return (
jsonify(
{"error": "Failed to get all clubs", "error message": error_message}
),
500,
)

@app.route("/api/autosuggest", methods=["GET"])
def autosuggest():
query = request.args.get("query").lower()
Expand Down Expand Up @@ -533,6 +570,44 @@ def my_profile():
500,
)

@app.route("/api/filter", methods=["GET"])
def filter_tags():
try:
from .datalayer.event import EventDataLayer

event_data = EventDataLayer()

# start by getting the search results
query = request.args.get("query", default="").lower()
tagname = request.args.get("tag", None)
location = request.args.get("location", None)
club = request.args.get("club", None)
start_time = request.args.get("start_time", None)
end_time = request.args.get("end_time", None)
sortby = request.args.get("sortby", None)
events = event_data.search_filter_sort(
keyword=query,
tag_name=tagname,
location=location,
club=club,
start_time=start_time,
end_time=end_time,
sort_by=sortby,
)
print("returning event")
return jsonify_event_list(events)
except Exception as e:
error_message = str(e)
return (
jsonify(
{
"error": "Failed to search sort and filter events",
"error message": error_message,
}
),
500,
)

@app.route("/api/favourites", methods=["GET"])
@jwt_required() # new line
def my_favourites():
Expand Down
6 changes: 4 additions & 2 deletions backend/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,10 @@

setup_routes(app)

# Run populate_database only in development environment
if app.config.get("ENV") == "development" or app.config.get("ENV") == "testing":
# only when we're using SQLite
if url.startswith("sqlite:///") and not os.path.exists(
Path(basedir).joinpath(DATABASE)
):
print("Populating database...")
from .create_mock_db import populate_database

Expand Down
168 changes: 76 additions & 92 deletions backend/create_mock_db.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,100 +50,84 @@ def create_mock_events():
image_data = image_file.read()

events = [
(
Event(
title="Fall Career Week",
description="Meet top recruiters from leading companies.",
extended_description="The Fall Career Week is a premier event that offers a unique platform for students and recent graduates to connect with recruiters from top firms across the nation. Attendees will have the chance to network, learn about job opportunities, and gain insights into various industries. This event is perfect for those looking to start or advance their careers.",
location="online",
start_time=start_time,
end_time=end_time,
author_id=1,
is_published=True,
like_count=0,
club="YNCN, You're Next Career Networks",
image=image_data,
),
["Career Development"],
(Event(
title="Fall Career Week",
description="Meet top recruiters from leading companies.",
extended_description="The Fall Career Week is a premier event that offers a unique platform for students and recent graduates to connect with recruiters from top firms across the nation. Attendees will have the chance to network, learn about job opportunities, and gain insights into various industries. This event is perfect for those looking to start or advance their careers.",
location="online",
start_time=datetime.strptime("2023-10-28 09:00:00", "%Y-%m-%d %H:%M:%S"),
end_time=datetime.strptime("2023-11-28 11:00:00", "%Y-%m-%d %H:%M:%S"),
author_id=1,
is_published=True,
like_count=0,
club="YNCN, You're Next Career Networks",
image=image_data
),
(
Event(
title="Origami Workshop",
description="Discover the joy of paper folding.",
extended_description="Our Origami Workshop is designed for both beginners and those with some experience in the art of paper folding. Participants will learn the basic folds and techniques required to create beautiful origami models. From classic cranes to intricate flowers, the workshop provides a relaxing and rewarding experience for everyone involved.",
location="Bahen 8th Floor",
start_time=start_time,
end_time=end_time,
author_id=None,
is_published=True,
like_count=10,
club="Origami club",
image=image_data,
),
[],
),
(
Event(
title="Community Soccer Match",
description="Join us for a friendly soccer match.",
extended_description="The community soccer match is a weekly event that invites players of all skill levels to enjoy a fun and competitive game. It's a fantastic opportunity to stay active, meet new friends, and indulge in the love of the sport. Whether you're an experienced player or just looking to kick the ball around, the event is open to everyone.",
location="Varsity Stadium",
start_time=start_time,
end_time=end_time,
author_id=None,
is_published=True,
like_count=5,
club="Skule Soccer",
image=image_data,
),
[],
),
(
Event(
title="Hockey Game",
description="Come watch our varsity team play.",
extended_description="Join us at the Varisty Arena to watch our varsity hockey team play against Waterloo",
location="Varsity Arena",
start_time=start_time,
end_time=end_time,
author_id=None,
is_published=True,
like_count=10,
image=image_data,
),
["Clubs & Organizations", "Arts & Culture"],
),
(
Event(
title="Spanish Lessons",
description="Want to learn Spanish? Join our club.",
extended_description="The spanish lesson meetup is a weekly event that invites non native spanish speakers to learn.",
location="Bahen",
start_time=start_time,
end_time=end_time,
author_id=None,
is_published=True,
like_count=5,
club="Lesa",
image=image_data,
),
[],
),
(
Event(
title="Skateboard Contest",
description="Compete or just have fun at our skateboard contest.",
extended_description="Our annual skateboard contest is back, bigger and better than ever. Skateboarders from all over the city will come together to showcase their skills and compete for prizes. With categories for different age groups and skill levels, everyone from novices to pros can participate. Even if you're not competing, come enjoy the vibrant atmosphere and cheer on your favorite skaters.",
location="Galbraith",
start_time=start_time,
end_time=end_time,
author_id=None,
is_published=True,
like_count=10,
image=image_data,
),
["Clubs & Organizations", "Arts & Culture"],
["Career Development"]),
(Event(
title="Origami Workshop",
description="Discover the joy of paper folding.",
extended_description="Our Origami Workshop is designed for both beginners and those with some experience in the art of paper folding. Participants will learn the basic folds and techniques required to create beautiful origami models. From classic cranes to intricate flowers, the workshop provides a relaxing and rewarding experience for everyone involved.",
location="Bahen 8th Floor",
start_time=datetime.strptime("2023-10-28 08:00:00", "%Y-%m-%d %H:%M:%S"),
end_time=datetime.strptime("2023-10-28 12:00:00", "%Y-%m-%d %H:%M:%S"),
author_id=None,
is_published=True,
like_count=10,
club="Origami club",
image=image_data
),[]),
(Event(
title="Community Soccer Match",
description="Join us for a friendly soccer match.",
extended_description="The community soccer match is a weekly event that invites players of all skill levels to enjoy a fun and competitive game. It's a fantastic opportunity to stay active, meet new friends, and indulge in the love of the sport. Whether you're an experienced player or just looking to kick the ball around, the event is open to everyone.",
location="Varsity Stadium",
start_time=datetime.strptime("2023-11-18 13:00:00", "%Y-%m-%d %H:%M:%S"),
end_time=datetime.strptime("2023-11-28 13:30:00", "%Y-%m-%d %H:%M:%S"),
author_id=None,
is_published=True,
like_count=5,
club="Skule Soccer",
image=image_data
),[]),
(Event(
title="Hockey Game",
description="Come watch our varsity team play.",
extended_description="Join us at the Varisty Arena to watch our varsity hockey team play against Waterloo",
location="Varsity Arena",
start_time=datetime.strptime("2023-11-28 10:00:00", "%Y-%m-%d %H:%M:%S"),
end_time=datetime.strptime("2023-11-28 23:59:59", "%Y-%m-%d %H:%M:%S"),
author_id=None,
is_published=True,
like_count=10,
image=image_data
),
["Clubs & Organizations", "Arts & Culture", "Academic"]),
(Event(
title="Spanish Lessons",
description="Want to learn Spanish? Join our club.",
extended_description="The spanish lesson meetup is a weekly event that invites non native spanish speakers to learn.",
location="Bahen",
start_time=datetime.strptime("2024-02-28 09:00:00", "%Y-%m-%d %H:%M:%S"),
end_time=datetime.strptime("2024-02-28 11:00:00", "%Y-%m-%d %H:%M:%S"),
author_id=None,
is_published=True,
like_count=5,
club="Lesa",
image=image_data
),[]),
(Event(
title="Skateboard Contest",
description="Compete or just have fun at our skateboard contest.",
extended_description="Our annual skateboard contest is back, bigger and better than ever. Skateboarders from all over the city will come together to showcase their skills and compete for prizes. With categories for different age groups and skill levels, everyone from novices to pros can participate. Even if you're not competing, come enjoy the vibrant atmosphere and cheer on your favorite skaters.",
location="Galbraith",
start_time=start_time,
end_time=end_time,
author_id=None,
is_published=True,
like_count=10,
image=image_data
),[])
]
return events

Expand Down
Loading

0 comments on commit 55fc3a8

Please sign in to comment.