You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
66 lines
1.7 KiB
Python
66 lines
1.7 KiB
Python
import sqlite3
|
|
from typing import List
|
|
|
|
from fastapi import APIRouter
|
|
from fastapi.params import Depends
|
|
|
|
from core import diyanetdb, diyanet
|
|
from core.diyanet import PrayerTimes
|
|
from core.diyanetdb import Location
|
|
|
|
api = APIRouter()
|
|
|
|
|
|
def get_connection():
|
|
with diyanetdb.get_connection() as conn:
|
|
yield conn
|
|
|
|
|
|
@api.get('/diyanet/countries', response_model=List[str])
|
|
async def list_countries(
|
|
conn: sqlite3.Connection = Depends(get_connection)
|
|
):
|
|
return diyanetdb.find_countries(conn)
|
|
|
|
|
|
@api.get('/diyanet/countries/{country}/cities', response_model=List[str])
|
|
async def list_cities_in_country(
|
|
country: str,
|
|
conn: sqlite3.Connection = Depends(get_connection)
|
|
):
|
|
cities = diyanetdb.find_cities(conn, country=country)
|
|
return cities
|
|
|
|
|
|
@api.get('/diyanet/location/{country}', response_model=List[Location])
|
|
async def list_locations_for_country(
|
|
country: str,
|
|
conn: sqlite3.Connection = Depends(get_connection)
|
|
):
|
|
items = diyanetdb.find_locations(conn, country=country)
|
|
return items
|
|
|
|
|
|
@api.get('/diyanet/location/{country}/{city}', response_model=List[Location])
|
|
async def list_locations_for_city(
|
|
country: str,
|
|
city: str,
|
|
conn: sqlite3.Connection = Depends(get_connection)
|
|
):
|
|
items = diyanetdb.find_locations(conn, country=country, city=city)
|
|
return items
|
|
|
|
|
|
@api.get('/diyanet/prayertimes', response_model=List[PrayerTimes])
|
|
async def get_prayer_times(location_id: int):
|
|
times = diyanet.get_prayer_times(location_id)
|
|
return times
|
|
|
|
|
|
@api.get('/diyanet/search', response_model=List[PrayerTimes])
|
|
async def search_location(
|
|
q: str,
|
|
conn: sqlite3.Connection = Depends(get_connection)):
|
|
locations = diyanetdb.find_location_by_name(conn, q)
|
|
return locations
|