Skip to content

Commit 91c6e93

Browse files
committed
Adds 'last analysis' endpoint
1 parent 6e6297c commit 91c6e93

File tree

2 files changed

+55
-3
lines changed

2 files changed

+55
-3
lines changed

src/client/src/pages/DataView360/View/View360.js

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,14 @@ class View360 extends Component {
6868
});
6969
response = await response.json();
7070

71-
let shelterluvInfo = await fetch(`/api/person/${this.state.matchId}/animals`);
71+
let shelterluvInfo = await fetch(`/api/person/${this.state.matchId}/animals`,
72+
{
73+
method: 'GET',
74+
headers: {
75+
'Content-Type': 'application/json',
76+
'Authorization': 'Bearer ' + this.props.access_token
77+
}
78+
});
7279
shelterluvInfo = await shelterluvInfo.json()
7380
const shelterluvShortId = shelterluvInfo["person_details"]["shelterluv_short_id"]
7481
let animalInfo = shelterluvInfo["animal_details"]
@@ -89,7 +96,14 @@ class View360 extends Component {
8996
});
9097
}
9198

92-
let supportOverviewData = await fetch(`/api/person/${this.state.matchId}/support`);
99+
let supportOverviewData = await fetch(`/api/person/${this.state.matchId}/support`,
100+
{
101+
method: 'GET',
102+
headers: {
103+
'Content-Type': 'application/json',
104+
'Authorization': 'Bearer ' + this.props.access_token
105+
}
106+
});
93107
supportOverviewData = await supportOverviewData.json()
94108

95109
this.setState({
@@ -104,7 +118,14 @@ class View360 extends Component {
104118
}
105119

106120
async getAnimalEvents(animalId, matchId) {
107-
let response = await fetch(`/api/person/${matchId}/animal/${animalId}/events`);
121+
let response = await fetch(`/api/person/${matchId}/animal/${animalId}/events`,
122+
{
123+
method: 'GET',
124+
headers: {
125+
'Content-Type': 'application/json',
126+
'Authorization': 'Bearer ' + this.props.access_token
127+
}
128+
});
108129
return await response.json()
109130
}
110131

src/server/api/common_api.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,7 @@ def get_360(matching_id):
180180

181181

182182
@common_api.route('/api/person/<matching_id>/animals', methods=['GET'])
183+
@jwt_ops.jwt_required()
183184
def get_animals(matching_id):
184185
result = {
185186
"person_details": {},
@@ -207,6 +208,7 @@ def get_animals(matching_id):
207208

208209

209210
@common_api.route('/api/person/<matching_id>/animal/<animal_id>/events', methods=['GET'])
211+
@jwt_ops.jwt_required()
210212
def get_person_animal_events(matching_id, animal_id):
211213
result = {}
212214
events = []
@@ -228,6 +230,7 @@ def get_person_animal_events(matching_id, animal_id):
228230
return result
229231

230232
@common_api.route('/api/person/<matching_id>/support', methods=['GET'])
233+
@jwt_ops.jwt_required()
231234
def get_support_oview(matching_id):
232235
"""Return these values for the specified match_id:
233236
largest gift, date for first donation, total giving, number of gifts,
@@ -376,3 +379,31 @@ def get_support_oview(matching_id):
376379
current_app.logger.debug('No SF contact IDs found for matching_id ' + str(matching_id))
377380
oview_fields['number_of_gifts'] = 0 # Marker for no data
378381
return jsonify(oview_fields)
382+
383+
384+
@common_api.route('/api/last_analysis', methods=['GET'])
385+
@jwt_ops.jwt_required()
386+
def get_last_analysis():
387+
""" Return the UTC string (e.g., '2021-12-11T02:29:14.830371') representing
388+
when the last analysis run succesfully completed.
389+
Returns an empty string if no results.
390+
"""
391+
392+
last_run = ''
393+
394+
last_stamp = """
395+
select update_stamp
396+
from execution_status
397+
where stage = 'flow' and status = 'complete'
398+
order by update_stamp desc
399+
limit 1;
400+
"""
401+
402+
with engine.connect() as connection:
403+
result = connection.execute(last_stamp)
404+
if result.rowcount:
405+
row = result.fetchone()
406+
last_run_dt = row[0] # We get as a datetime object
407+
last_run = last_run_dt.isoformat()
408+
409+
return last_run

0 commit comments

Comments
 (0)