File size: 3,006 Bytes
2da7ed3
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
from fastapi import APIRouter, Body, Request, status
from typing import List
from datetime import date

import sys
# sys.path.append('/Users/benolojo/DCU/CA4/ca400_FinalYearProject/2024-ca400-olojob2-majdap2/src/backend/src/')

from ..operations import calls as calls
from ..models.calls import UserCall, UpdateCall

router = APIRouter(prefix="/call",
    tags=["Calls"])

@router.post("/create-call", response_description="Create a new user call record", status_code=status.HTTP_201_CREATED, response_model=UserCall)
async def create_calls(request: Request, user_calls: UserCall = Body(...)):  
    return calls.create_calls(request, user_calls)

@router.get("/list-call", response_description="List all existing call records", response_model=List[UserCall])
async def list_calls(request: Request, limit: int):
    return calls.list_calls(request, 100)

@router.get("/find-call/{call_id}", response_description="Find user's calls based on User ID", response_model=UserCall)
async def find_calls(request: Request, call_id: str):    
    return calls.find_calls(request, call_id)

@router.get("/find-user/{user_id}", response_description="Find user's calls based on User ID", response_model=List[UserCall])
async def find_user_calls(request: Request, user_id: str):    
    return calls.find_user_calls(request, user_id)

'''Key terms list can have variable length -> using POST request over GET'''
@router.post("/find-term/", response_description="Find calls based on key term list", response_model=List[UserCall])
async def list_transcripts_by_key_terms(request: Request, key_terms: List[str]):
    return calls.list_transcripts_by_key_terms(request, key_terms)

@router.get("/find-date/{start_date}/{end_date}", response_description="Find calls based on date ranges", response_model=List[UserCall])
async def list_transcripts_by_dates(request: Request, start_date: str, end_date: str):
    return calls.list_transcripts_by_dates(request, start_date, end_date)

@router.get("/find-duration/{min_len}/{max_len}", response_description="Find calls based on call duration in minutes", response_model=List[UserCall])
async def list_transcripts_by_duration(request: Request, min_len: int, max_len: int):
    return calls.list_transcripts_by_duration(request, min_len, max_len)

@router.put("/update-call/{call_id}", response_description="Update an existing call", response_model=UpdateCall)
async def update_calls(request: Request, call_id: str, user_calls: UpdateCall = Body(...)):
    return calls.update_calls(request, call_id, user_calls)

@router.put("/update-captions/{call_id}", response_description="Update an existing call", response_model=UpdateCall)
async def update_captions(request: Request, call_id: str, user_calls: UpdateCall = Body(...)):
    return calls.update_captions(request, call_id, user_calls)

@router.delete("/delete-call/{call_id}", response_description="Delete a call by its id")
async def delete_call(request: Request, call_id :str):
    return calls.delete_calls(request, call_id)