Spaces:
Paused
Paused
from fastapi import APIRouter, Body, Request, status, HTTPException | |
from typing import List | |
from datetime import date | |
import sys | |
from ..operations import calls as calls | |
from ..models.calls import UserCaptions, UserCall, UpdateCall | |
from ..endpoints.users import get_collection_users | |
router = APIRouter(prefix="/call", | |
tags=["Calls"]) | |
def get_collection_calls(request: Request): | |
try: | |
return request.app.database["call_records"] | |
# return request.app.database["call_test"] | |
except: | |
raise HTTPException(status_code=status.HTTP_404_NOT_FOUND, detail=f"Unable to find call records Database.") | |
async def create_calls(request: Request, user_calls: UserCall = Body(...)): | |
collection = get_collection_calls(request) | |
return calls.create_calls(collection, user_calls) | |
async def list_calls(request: Request, limit: int): | |
collection = get_collection_calls(request) | |
return calls.list_calls(collection, 100) | |
async def find_call(request: Request, call_id: str): | |
collection = get_collection_calls(request) | |
return calls.find_call(collection, call_id) | |
async def find_user_calls(request: Request, user_id: str): | |
collection = get_collection_calls(request) | |
return calls.find_user_calls(collection, user_id) | |
async def get_caption_text(request: Request, user_id: str): | |
collection = get_collection_calls(request) | |
return calls.get_caption_text(collection, user_id) | |
'''Key terms list can have variable length -> using POST request over GET''' | |
async def list_transcripts_by_key_terms(request: Request, key_terms: List[str]): | |
collection = get_collection_calls(request) | |
return calls.list_transcripts_by_key_terms(collection, key_terms) | |
async def list_transcripts_by_dates(request: Request, start_date: str, end_date: str): | |
collection = get_collection_calls(request) | |
return calls.list_transcripts_by_dates(collection, start_date, end_date) | |
async def list_transcripts_by_duration(request: Request, min_len: int, max_len: int): | |
collection = get_collection_calls(request) | |
return calls.list_transcripts_by_duration(collection, min_len, max_len) | |
async def update_calls(request: Request, call_id: str, user_calls: UpdateCall = Body(...)): | |
collection = get_collection_calls(request) | |
return calls.update_calls(collection, call_id, user_calls) | |
async def update_captions(request: Request, call_id: str, user_calls: UserCaptions = Body(...)): | |
call_collection = get_collection_calls(request) | |
user_collection = get_collection_users(request) | |
return calls.update_captions(call_collection, user_collection, call_id, user_calls) | |
async def delete_call(request: Request, call_id: str): | |
collection = get_collection_calls(request) | |
return calls.delete_calls(collection, call_id) | |
async def full_text_search(request: Request, query: str): | |
collection = get_collection_calls(request) | |
return calls.full_text_search(collection, query) | |
async def summarise(request: Request, call_id: str): | |
collection = get_collection_calls(request) | |
return calls.summarise(collection, call_id) |