Coverage for src/data_api/api/routers/dining.py: 100%

13 statements  

« prev     ^ index     » next       coverage.py v7.16.2, created at 2026-11-13 19:28 +0000

1""" 

2Dining router. 

3 

4Handles HTTP endpoints for dining information. 

5""" 

6 

7from fastapi import APIRouter, Query, Response 

8 

9from data_api.api.schemas import dining as schemas 

10from data_api.api.schemas.responses import SNAPSHOT_RESPONSES 

11from data_api.runtime import get_runtime 

12 

13router = APIRouter(responses=SNAPSHOT_RESPONSES) 

14 

15 

16@router.get("", operation_id="getDiningData") 

17async def get_dining_data( 

18 response: Response, 

19 building_name: schemas.DiningBuildingName = Query(None, description="餐廳建築名稱(可選)"), 

20 restaurant_name: str = Query(None, description="餐廳名稱(可選)"), 

21 fuzzy: bool = Query( 

22 True, description="是否進行模糊搜尋;停用時建築名稱完全比對,餐廳名稱使用子字串比對" 

23 ), 

24 schedule: schemas.DiningScheduleName | None = Query( 

25 None, 

26 description=( 

27 "營業日篩選(可選);省略時不篩選。today 使用 Asia/Taipei 日期。" 

28 "依備註排除指定日休息的餐廳,不代表此刻營業中" 

29 ), 

30 ), 

31) -> list[schemas.DiningBuilding]: 

32 """ 

33 取得所有餐廳及廠商資料。 

34 各篩選條件取交集,回傳格式固定依建築分組;營業日篩選後移除沒有符合餐廳的建築。 

35 資料來源:[總務處經營管理組](https://ddfm.site.nthu.edu.tw/p/404-1494-256455.php?Lang=zh-tw) 

36 """ 

37 if fuzzy: 

38 commit_hash, data = await get_runtime().dining.fuzzy_search_dining_data( 

39 building_name=building_name, 

40 restaurant_name=restaurant_name, 

41 schedule=schedule, 

42 ) 

43 else: 

44 commit_hash, data = await get_runtime().dining.get_dining_data( 

45 building_name=building_name, 

46 restaurant_name=restaurant_name, 

47 schedule=schedule, 

48 ) 

49 if commit_hash is not None: 

50 response.headers["X-Data-Commit-Hash"] = commit_hash 

51 return data