๊ฐ•๋ฏผ๊ท  commited on
Commit
96a4d11
ยท
1 Parent(s): dbcc2a1

Add /recipes endpoint for list all recipes

Browse files
Files changed (1) hide show
  1. src/api.py +22 -0
src/api.py CHANGED
@@ -56,6 +56,28 @@ def health_check():
56
  status = "loading" if logic.df is None else "ok"
57
  return {"status": status, "service": "K-Recipe2Vec API"}
58
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
59
  @app.get("/recipes/search")
60
  def search_recipes(q: str):
61
  """์š”๋ฆฌ๋ช…์œผ๋กœ ๋ ˆ์‹œํ”ผ ๊ฒ€์ƒ‰"""
 
56
  status = "loading" if logic.df is None else "ok"
57
  return {"status": status, "service": "K-Recipe2Vec API"}
58
 
59
+ @app.get("/recipes")
60
+ def list_recipes(limit: int = 50, offset: int = 0):
61
+ """์ „์ฒด ๋ ˆ์‹œํ”ผ ๋ชฉ๋ก ์กฐํšŒ (ํŽ˜์ด์ง€๋„ค์ด์…˜)"""
62
+ logic.ensure_initialized()
63
+
64
+ try:
65
+ total = len(logic.df)
66
+ subset = logic.df.iloc[offset:offset+limit][['๋ ˆ์‹œํ”ผ์ผ๋ จ๋ฒˆํ˜ธ', '์š”๋ฆฌ๋ช…', '์žฌ๋ฃŒํ† ํฐ', '์š”๋ฆฌ๋ฐฉ๋ฒ•๋ณ„๋ช…', '์š”๋ฆฌ์ข…๋ฅ˜๋ณ„๋ช…_์„ธ๋ถ„ํ™”']]
67
+
68
+ output = []
69
+ for _, row in subset.iterrows():
70
+ output.append({
71
+ "id": int(row['๋ ˆ์‹œํ”ผ์ผ๋ จ๋ฒˆํ˜ธ']),
72
+ "name": row['์š”๋ฆฌ๋ช…'],
73
+ "ingredients": row['์žฌ๋ฃŒํ† ํฐ'],
74
+ "method": row['์š”๋ฆฌ๋ฐฉ๋ฒ•๋ณ„๋ช…'],
75
+ "category": row['์š”๋ฆฌ์ข…๋ฅ˜๋ณ„๋ช…_์„ธ๋ถ„ํ™”']
76
+ })
77
+ return {"total": total, "recipes": output}
78
+ except Exception as e:
79
+ raise HTTPException(status_code=500, detail=str(e))
80
+
81
  @app.get("/recipes/search")
82
  def search_recipes(q: str):
83
  """์š”๋ฆฌ๋ช…์œผ๋กœ ๋ ˆ์‹œํ”ผ ๊ฒ€์ƒ‰"""