Skip to content

Commit

Permalink
Merge branch 'main' into wei
Browse files Browse the repository at this point in the history
  • Loading branch information
l7wei committed Nov 3, 2023
2 parents d389a8c + e0a5342 commit 482a6fc
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 11 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -150,3 +150,5 @@ cython_debug/
# and can be added to the global gitignore or merged into this file. For a more nuclear
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
#.idea/

/temp
5 changes: 3 additions & 2 deletions src/api/models/dining.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,11 +68,12 @@ def get_all_restaurant_names(self):

def query_by_restaurant_name(self, query):
dining_data = self.get_dining_data()
res = []
for building in dining_data:
for restaurant in building["restaurants"]:
if restaurant["name"] == query:
return restaurant
return None
res.append(restaurant)
return None if len(res) == 0 else res

def get_scheduled_on_saturday(self):
dining_data = self.get_dining_data()
Expand Down
3 changes: 0 additions & 3 deletions src/api/models/phones.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
import json

from thefuzz import fuzz, process
from .data import Data


Expand Down
16 changes: 12 additions & 4 deletions src/api/routers/dining.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,16 @@
from enum import Enum
from fastapi import APIRouter, HTTPException
from ..models.dining import Dining


class Building(str, Enum):
小吃部 = "小吃部"
水木生活中心 = "水木生活中心"
風雲樓 = "風雲樓"
綜合教學大樓_南大校區 = "綜合教學大樓(南大校區)"
其他餐廳 = "其他餐廳"


router = APIRouter(
prefix="/dining",
tags=["dining"],
Expand Down Expand Up @@ -95,7 +105,7 @@ def get_all_building_names():
},
},
)
def get_dining_data(building_name: str):
def get_dining_data(building_name: Building):
try:
return dining.query_by_building_name(building_name)
except Exception as e:
Expand Down Expand Up @@ -144,9 +154,7 @@ def get_all_restaurant_names():
},
},
)
def get_dining_data(
restaurant_name: str,
):
def get_dining_data(restaurant_name: str):
try:
return dining.query_by_restaurant_name(restaurant_name)
except Exception as e:
Expand Down
19 changes: 17 additions & 2 deletions src/api/routers/lib.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from enum import Enum
from fastapi import APIRouter, HTTPException

from ..models.lib import (
Expand All @@ -7,6 +8,20 @@
get_rss_data,
)


class Lib(str, Enum):
mainlib = "mainlib"
hslib = "hslib"
nandalib = "nandalib"


class Rss(str, Enum):
rss_news = "rss_news"
rss_eresources = "rss_eresources"
rss_exhibit = "rss_exhibit"
rss_branches = "rss_branches"


router = APIRouter(
prefix="/lib",
tags=["lib"],
Expand All @@ -15,7 +30,7 @@


@router.get("/openinghours/{lib}")
def openinghours(lib):
def openinghours(lib: Lib):
try:
content, code = get_opening_hours(lib)
if code != 200:
Expand Down Expand Up @@ -48,7 +63,7 @@ def spacedata():


@router.get("/rss/{rss}")
def rssdata(rss):
def rssdata(rss: Rss):
try:
content, code = get_rss_data(rss)
if code != 200:
Expand Down

0 comments on commit 482a6fc

Please sign in to comment.