Update code in endpoints/whatsapp.get.py
This commit is contained in:
parent
f5122459c4
commit
713d7e36eb
@ -1,53 +1,24 @@
|
|||||||
from fastapi import APIRouter, HTTPException
|
from fastapi import APIRouter
|
||||||
from sqlalchemy import Column, String, Integer
|
import random
|
||||||
from sqlalchemy.ext.declarative import declarative_base
|
|
||||||
from typing import List
|
|
||||||
|
|
||||||
Base = declarative_base()
|
|
||||||
|
|
||||||
class Country(Base):
|
|
||||||
__tablename__ = "countries"
|
|
||||||
|
|
||||||
id = Column(Integer, primary_key=True, index=True)
|
|
||||||
name = Column(String, unique=True, index=True)
|
|
||||||
code = Column(String, unique=True)
|
|
||||||
phone_code = Column(String)
|
|
||||||
|
|
||||||
router = APIRouter()
|
router = APIRouter()
|
||||||
|
|
||||||
|
messages = [
|
||||||
|
"Hey there! I am using WhatsApp",
|
||||||
|
"Available",
|
||||||
|
"In a meeting",
|
||||||
|
"At work",
|
||||||
|
"Battery about to die",
|
||||||
|
"Can't talk WhatsApp only",
|
||||||
|
"Urgent calls only",
|
||||||
|
"Sleeping"
|
||||||
|
]
|
||||||
|
|
||||||
@router.get("/whatsapp")
|
@router.get("/whatsapp")
|
||||||
async def get_countries() -> List[dict]:
|
async def whatsapp_status():
|
||||||
"""Get list of countries with phone codes"""
|
"""Get random WhatsApp status"""
|
||||||
countries = [
|
|
||||||
{"name": "United States", "code": "US", "phone_code": "+1"},
|
|
||||||
{"name": "United Kingdom", "code": "GB", "phone_code": "+44"},
|
|
||||||
{"name": "India", "code": "IN", "phone_code": "+91"}
|
|
||||||
]
|
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
"message": random.choice(messages),
|
||||||
"method": "GET",
|
"method": "GET",
|
||||||
"_verb": "get",
|
"_verb": "get"
|
||||||
"countries": countries,
|
}
|
||||||
"total": len(countries)
|
|
||||||
}
|
|
||||||
|
|
||||||
# Migration file
|
|
||||||
"""
|
|
||||||
from alembic import op
|
|
||||||
import sqlalchemy as sa
|
|
||||||
|
|
||||||
def upgrade():
|
|
||||||
op.create_table(
|
|
||||||
'countries',
|
|
||||||
sa.Column('id', sa.Integer(), nullable=False),
|
|
||||||
sa.Column('name', sa.String(), nullable=False),
|
|
||||||
sa.Column('code', sa.String(), nullable=False),
|
|
||||||
sa.Column('phone_code', sa.String(), nullable=False),
|
|
||||||
sa.PrimaryKeyConstraint('id'),
|
|
||||||
sa.UniqueConstraint('name'),
|
|
||||||
sa.UniqueConstraint('code')
|
|
||||||
)
|
|
||||||
|
|
||||||
def downgrade():
|
|
||||||
op.drop_table('countries')
|
|
||||||
"""
|
|
Loading…
x
Reference in New Issue
Block a user