Juna190825 commited on
Commit
633a8b5
·
verified ·
1 Parent(s): d44a926

Create app/api/v1/endpoints/word_of_day.py

Browse files
Files changed (1) hide show
  1. app/api/v1/endpoints/word_of_day.py +27 -0
app/api/v1/endpoints/word_of_day.py ADDED
@@ -0,0 +1,27 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from fastapi import APIRouter, Depends
2
+ from sqlalchemy.orm import Session
3
+ from datetime import date
4
+
5
+ from app.db.session import SessionLocal
6
+ from app.models.dictionary_entry import DictionaryEntry
7
+ from app.schemas.dictionary_entry import DictionaryEntry as DictionaryEntrySchema
8
+
9
+ router = APIRouter()
10
+
11
+
12
+ def get_db():
13
+ db = SessionLocal()
14
+ try:
15
+ yield db
16
+ finally:
17
+ db.close()
18
+
19
+
20
+ @router.get("", response_model=DictionaryEntrySchema)
21
+ def word_of_day(db: Session = Depends(get_db)):
22
+ # Simple example: pick deterministic entry by day
23
+ entries = db.query(DictionaryEntry).order_by(DictionaryEntry.id).all()
24
+ if not entries:
25
+ raise RuntimeError("No entries available")
26
+ idx = date.today().day % len(entries)
27
+ return entries[idx]