test api
This commit is contained in:
25
bot/database/subscription_db.py
Normal file
25
bot/database/subscription_db.py
Normal file
@@ -0,0 +1,25 @@
|
||||
import aiohttp
|
||||
|
||||
API_URL = "http://api:8000/subscription"
|
||||
|
||||
async def get_subscription(user_id: int):
|
||||
async with aiohttp.ClientSession() as session:
|
||||
async with session.get(f"{API_URL}/{user_id}") as resp:
|
||||
if resp.status == 200:
|
||||
data = await resp.json()
|
||||
if data:
|
||||
data["until"] = datetime.fromisoformat(data["until"])
|
||||
return data
|
||||
return None
|
||||
|
||||
async def set_subscription(user_id: int, uuid: str, until: datetime, months: int):
|
||||
async with aiohttp.ClientSession() as session:
|
||||
payload = {"user_id": user_id, "months": months}
|
||||
async with session.post(f"{API_URL}/new", json=payload) as resp:
|
||||
return await resp.json()
|
||||
|
||||
async def extend_subscription(user_id: int, months: int):
|
||||
async with aiohttp.ClientSession() as session:
|
||||
payload = {"user_id": user_id, "months": months}
|
||||
async with session.post(f"{API_URL}/extend", json=payload) as resp:
|
||||
return await resp.json()
|
||||
Reference in New Issue
Block a user