Skip to content

Commit

Permalink
added Maintenance Summary and Simplified endpoints
Browse files Browse the repository at this point in the history
  • Loading branch information
Prashant Marathay committed Sep 6, 2023
1 parent 297d472 commit 2c42666
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 1 deletion.
57 changes: 57 additions & 0 deletions maintenance.py
Original file line number Diff line number Diff line change
Expand Up @@ -286,3 +286,60 @@ def put(self):
with connect() as db:
response = db.update('maintenanceRequests', key, payload)
return response



class MaintenanceSummaryByOwner(Resource):
def get(self, owner_id):
print('in New Owner Maintenance Dashboard')
response = {}

# print("Owner UID: ", owner_id)

with connect() as db:
print("in connect loop")
maintenanceQuery = db.execute("""
-- MAINTENANCE STATUS BY OWNER
SELECT property_owner.property_owner_id
, maintenanceRequests.maintenance_request_status
, COUNT(maintenanceRequests.maintenance_request_status) AS num
FROM space.properties
LEFT JOIN space.property_owner ON property_id = property_uid
LEFT JOIN space.maintenanceRequests ON maintenance_property_id = property_uid
WHERE property_owner_id = \'""" + owner_id + """\'
GROUP BY maintenance_request_status;
""")

# print("Query: ", maintenanceQuery) # This is a list
# # FOR DEBUG ONLY - THESE STATEMENTS ALLOW YOU TO CHECK THAT THE QUERY WORKS
response["MaintenanceSummary"] = maintenanceQuery
return response



class MaintenanceStatusByOwnerSimplified(Resource):
def get(self, owner_id):
print('in New Owner Maintenance Dashboard')
response = {}

# print("Owner UID: ", owner_id)

with connect() as db:
print("in connect loop")
maintenanceQuery = db.execute("""
-- MAINTENANCE STATUS BY OWNER BY PROPERTY BY STATUS WITH LIMITED DETAILS FOR FLUTTERFLOW
SELECT property_owner_id
, property_uid, property_address -- , property_unit, property_city, property_state, property_zip, property_type, property_num_beds, property_num_baths, property_area, property_listed_rent, property_images
, maintenance_request_uid, maintenance_title, maintenance_images, maintenance_request_type, maintenance_request_status
FROM space.maintenanceRequests
LEFT JOIN space.maintenanceQuotes ON quote_maintenance_request_id = maintenance_request_uid
LEFT JOIN space.properties ON maintenance_property_id = property_uid -- ASSOCIATE PROPERTY DETAILS WITH MAINTENANCE DETAILS
LEFT JOIN space.property_owner ON property_id = property_uid -- SO WE CAN SORT BY OWNER
WHERE property_owner_id = \'""" + owner_id + """\'
ORDER BY maintenance_request_status;
""")

# print("Query: ", maintenanceQuery) # This is a list
# # FOR DEBUG ONLY - THESE STATEMENTS ALLOW YOU TO CHECK THAT THE QUERY WORKS
response["MaintenanceSummary"] = maintenanceQuery
return response
5 changes: 4 additions & 1 deletion myspace_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
from documents import OwnerDocuments, TenantDocuments
from leases import LeaseDetails
from purchases import Bills, AddExpense, AddRevenue
from maintenance import MaintenanceStatusByProperty, MaintenanceByProperty, MaintenanceStatusByOwner, MaintenanceRequestsByOwner, MaintenanceRequests
from maintenance import MaintenanceStatusByProperty, MaintenanceByProperty, MaintenanceStatusByOwner, MaintenanceRequestsByOwner, MaintenanceRequests, MaintenanceSummaryByOwner, MaintenanceStatusByOwnerSimplified
from contacts import ContactsMaintenance, ContactsOwnerContactsDetails, ContactsBusinessContacts, ContactsBusinessContactsOwnerDetails, ContactsBusinessContactsTenantDetails, ContactsBusinessContactsMaintenanceDetails
from contracts import Contracts, ContractsByUid
from settings import Account
Expand Down Expand Up @@ -393,6 +393,9 @@ def get(self, tenant_id):
api.add_resource(MaintenanceByProperty, '/maintenanceByProperty/<string:property_id>')
api.add_resource(MaintenanceStatusByProperty, '/maintenanceStatusByProperty/<string:property_id>')
api.add_resource(MaintenanceStatusByOwner, '/maintenanceStatusByOwner/<string:owner_id>')
api.add_resource(MaintenanceSummaryByOwner, '/maintenanceSummaryByOwner/<string:owner_id>')
api.add_resource(MaintenanceStatusByOwnerSimplified, '/maintenanceStatusByOwnerSimplified/<string:owner_id>')


api.add_resource(Bills, '/bills')
api.add_resource(ContractsByUid, '/contracts/<string:contract_uid>')
Expand Down

0 comments on commit 2c42666

Please sign in to comment.