HEX
Server: Apache/2.4.52 (Ubuntu)
System: Linux spn-python 5.15.0-89-generic #99-Ubuntu SMP Mon Oct 30 20:42:41 UTC 2023 x86_64
User: arjun (1000)
PHP: 8.1.2-1ubuntu2.20
Disabled: NONE
Upload Files
File: //home/arjun/projects/buyercall_new/buyercall/buyercall/blueprints/leads/rest_api.py
import logging as log

from flask import Blueprint, jsonify, make_response
from buyercall.lib.util_rest import rest_method, rest_partnership_account
from buyercall.blueprints.leads.models import Lead


leads_api = Blueprint('leads_api', __name__, template_folder='templates')


@leads_api.route('/api/v1/calls', methods=['GET'])
@rest_method
def leads_json():
    """ External REST API endpoint.
    """
    data = list()
    leads = Lead.query.outerjoin(Lead.agent).filter(
        Lead.partnership_account_id == rest_partnership_account.id
    ).all()
    log.debug('Found {} leads for user {}'.format(len(leads), rest_partnership_account.id))
    for lead in leads:
        data.append(dict(
            id=lead.id,
            status=lead.status,
            firstname=lead.firstname,
            lastname=lead.lastname,
            email=lead.email,
            phonenumber=lead.phonenumber,
            question=lead.question,
            duration=lead.duration,
            starttime=lead.starttime.isoformat() if lead.starttime else None,
            endtime=lead.endtime.isoformat() if lead.endtime else None,
            recording_url=lead.recording_url or None,
            agent=lead.agent.full_name if lead.agent else None,
            notes=lead.notes,
            call_count=lead.call_count
        ))

    response = make_response(jsonify(calls=data))
    response.headers['Cache-Control'] = 'no-cache'
    return response