Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ab 0907 #28

Merged
merged 3 commits into from
Sep 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion myspace_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -397,7 +398,8 @@ def get(self, tenant_id):
api.add_resource(MaintenanceStatusByOwnerSimplified, '/maintenanceStatusByOwnerSimplified/<string:owner_id>')
api.add_resource(MaintenanceSummaryAndStatusByOwner, '/maintenanceSummaryAndStatusByOwner/<string:owner_id>')


api.add_resource(QuotesByBusiness, '/quotesByBusiness')
api.add_resource(QuotesStatusByBusiness, '/quotesStatusByBusiness')

api.add_resource(Bills, '/bills')
api.add_resource(ContractsByUid, '/contracts/<string:contract_uid>')
Expand Down
57 changes: 57 additions & 0 deletions quotes.py
Original file line number Diff line number Diff line change
@@ -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
3 changes: 1 addition & 2 deletions requirements_myspace.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down