From b9ae757cfdad3853f8b249a387890f19a5b6a967 Mon Sep 17 00:00:00 2001 From: Prashant Marathay Date: Tue, 5 Sep 2023 23:37:14 -0700 Subject: [PATCH 1/2] new requirements file --- requirements_myspace.txt | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/requirements_myspace.txt b/requirements_myspace.txt index a46ecd8..21066e9 100644 --- a/requirements_myspace.txt +++ b/requirements_myspace.txt @@ -39,10 +39,9 @@ jmespath==1.0.1 kappa==0.6.0 MarkupSafe==2.1.3 multidict==6.0.4 -numpy==1.21.6 +numpy==1.25.2 oauth2client==4.1.3 oauthlib==3.2.2 -pandas==1.3.5 placebo==0.9.0 protobuf==4.23.4 pyasn1==0.5.0 From 4fa981421dcd49034419dc1f8c74356f6480859f Mon Sep 17 00:00:00 2001 From: Aditya Baravkar Date: Thu, 7 Sep 2023 06:30:57 -0700 Subject: [PATCH 2/2] Quotes APIs --- myspace_api.py | 4 +++- quotes.py | 57 ++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 60 insertions(+), 1 deletion(-) create mode 100644 quotes.py diff --git a/myspace_api.py b/myspace_api.py index 984002c..16f6268 100644 --- a/myspace_api.py +++ b/myspace_api.py @@ -30,6 +30,7 @@ from contracts import Contracts, ContractsByUid from settings import Account from lists import List +from quotes import QuotesByBusiness, QuotesStatusByBusiness # from refresh import Refresh # from data import connect, disconnect, execute, helper_upload_img, helper_icon_img from data_pm import connect, uploadImage, s3 @@ -397,7 +398,8 @@ def get(self, tenant_id): api.add_resource(MaintenanceStatusByOwnerSimplified, '/maintenanceStatusByOwnerSimplified/') api.add_resource(MaintenanceSummaryAndStatusByOwner, '/maintenanceSummaryAndStatusByOwner/') - +api.add_resource(QuotesByBusiness, '/quotesByBusiness') +api.add_resource(QuotesStatusByBusiness, '/quotesStatusByBusiness') api.add_resource(Bills, '/bills') api.add_resource(ContractsByUid, '/contracts/') diff --git a/quotes.py b/quotes.py new file mode 100644 index 0000000..aa7a372 --- /dev/null +++ b/quotes.py @@ -0,0 +1,57 @@ +from flask import request +from flask_restful import Resource +from data_pm import connect + +class QuotesStatusByBusiness(Resource): + def get(self): + args = request.args + business_id = args.get("business_id") + filter = args.get("filter") + group_by = args.get("group_by") + last_30_days = "" + if filter == "last_30_days": + last_30_days = """ quote_created_date BETWEEN (CURDATE() - INTERVAL 1 MONTH) AND CURDATE() + AND""" + with connect() as db: + query = """ + SELECT maintenance_request_uid, maintenance_title, maintenance_priority, maintenance_images, + maintenance_quote_uid, quote_business_id, property_uid, property_address, quote_status + FROM space.m_details + LEFT JOIN space.properties ON property_uid = maintenance_property_id + WHERE""" + last_30_days + """ quote_business_id = \'""" + business_id + """\' + """ + query_result = db.execute(query) + response_dict = {} + for item in query_result["result"]: + group_by_value = item.pop(str(group_by or "quote_status")) + if group_by_value in response_dict: + response_dict[group_by_value].append(item) + else: + response_dict[group_by_value] = [item] + return response_dict + +class QuotesByBusiness(Resource): + def get(self): + args = request.args + business_id = args.get("business_id") + with connect() as db: + query = """ + SELECT maintenance_request_uid, maintenance_title, maintenance_desc, maintenance_images, + maintenance_request_type, maintenance_priority, maintenance_request_created_date, maintenance_quote_uid, + quote_business_id, quote_earliest_availability, quote_event_duration, quote_notes, quote_status, + quote_total_estimate, property_uid, property_address, CONCAT(first_name, ' ', last_name) AS manager_name + FROM space.m_details + LEFT JOIN space.properties ON property_uid = maintenance_property_id + LEFT JOIN space.businessProfileInfo ON quote_business_id = business_uid + LEFT JOIN space.users ON business_user_id = user_uid + WHERE quote_business_id = \'""" + business_id + """\' + """ + query_result = db.execute(query) + response_dict = {} + for item in query_result["result"]: + group_by_value = item.pop("quote_status") + if group_by_value in response_dict: + response_dict[group_by_value].append(item) + else: + response_dict[group_by_value] = [item] + return response_dict \ No newline at end of file