diff --git a/managers.py b/managers.py new file mode 100644 index 0000000..b6a0743 --- /dev/null +++ b/managers.py @@ -0,0 +1,45 @@ +from flask import request +from flask_restful import Resource +from flask_jwt_extended import jwt_required, get_jwt_identity + +from data_pm import connect, uploadImage, s3 + +class SearchManager(Resource): + + # def get(self): + # response = {} + # business_location = request.args.get('business_location') + # business_name = request.args.get('business_name') + + # with connect() as db: + # searchQuery = f""" + # SELECT * + # FROM space.businessProfileInfo + # JOIN JSON_TABLE( + # space.businessProfileInfo.business_locations, + # '$[*]' + # COLUMNS ( + # distance VARCHAR(255) PATH '$.distance', + # location VARCHAR(255) PATH '$.location' + # ) + # ) AS json_data ON json_data.location = '{business_location}' + # WHERE space.businessProfileInfo.business_name = '{business_name}'; + # """ + # # print(searchQuery) + # response = db.execute(searchQuery) + # return response + + def get(self): + response = {} + # filters = ['business_uid', 'business_type', + # 'business_name', 'business_locations'] + where = {} + # for filter in filters: + # filterValue = request.args.get(filter) + # if filterValue is not None: + # where[filter] = filterValue + where['business_type'] = 'MANAGEMENT' + # print(where) + with connect() as db: + response = db.select('b_details', where) + return response \ No newline at end of file diff --git a/myspace_api.py b/myspace_api.py index c146ab5..51962b2 100644 --- a/myspace_api.py +++ b/myspace_api.py @@ -21,7 +21,7 @@ from properties import Properties, PropertiesByOwner, PropertyDashboardByOwner from transactions import AllTransactions, TransactionsByOwner, TransactionsByOwnerByProperty from cashflow import CashflowByOwner -from profiles import OwnerProfile, TenantProfile, OwnerProfileByOwnerUid +from profiles import OwnerProfile, OwnerProfileByOwnerUid, TenantProfile, TenantProfileByTenantUid from documents import OwnerDocuments, TenantDocuments from leases import LeaseDetails from purchases import Bills, AddExpense, AddRevenue @@ -30,7 +30,9 @@ from contracts import Contracts, ContractsByUid from settings import Account from lists import List +from managers import SearchManager 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 @@ -419,9 +421,10 @@ def get(self, tenant_id): api.add_resource(OwnerProfileByOwnerUid, '/ownerProfile/') -api.add_resource(TenantProfile, '/tenantProfile/') +api.add_resource(TenantProfileByTenantUid, '/tenantProfile/') api.add_resource(OwnerProfile, '/ownerProfile') # POST, PUT OwnerProfile +api.add_resource(TenantProfile, '/tenantProfile') api.add_resource(OwnerDocuments, '/ownerDocuments/') api.add_resource(TenantDocuments, '/tenantDocuments/') @@ -440,6 +443,7 @@ def get(self, tenant_id): api.add_resource(Account, '/account') api.add_resource(TenantDashboard, '/tenantDashboard/') +api.add_resource(SearchManager, '/searchManager') # refresh # api.add_resource(Refresh, '/refresh') diff --git a/profiles.py b/profiles.py index 46e64f3..e9428fa 100644 --- a/profiles.py +++ b/profiles.py @@ -61,8 +61,28 @@ def get(self, owner_id): return response +class TenantProfile(Resource): + def post(self): + response = {} + print('in TenantProfile') + payload = request.get_json() + + with connect() as db: + response = db.insert('tenantProfileInfo', payload) + return response + + def put(self): + response = {} + print('in TenantProfile') + payload = request.get_json() + if payload.get('tenant_uid') is None: + raise BadRequest("Request failed, no UID in payload.") + key = {'tenant_uid': payload.pop('tenant_uid')} + with connect() as db: + response = db.update('tenantProfileInfo', key, payload) + return response -class TenantProfile(Resource): +class TenantProfileByTenantUid(Resource): # decorators = [jwt_required()] def get(self, tenant_id):