API - add elevation edition for workout w/o gpx file

This commit is contained in:
Sam
2022-12-14 16:36:06 +01:00
parent 8a0e1d2b40
commit c611f41519
3 changed files with 187 additions and 2 deletions

View File

@ -241,6 +241,12 @@ def edit_workout(
else float(workout.distance) / (workout.duration.seconds / 3600)
)
workout.max_speed = workout.ave_speed
if 'ascent' in workout_data:
workout.ascent = workout_data.get('ascent')
if 'descent' in workout_data:
workout.descent = workout_data.get('descent')
return workout

View File

@ -1301,8 +1301,9 @@ def update_workout(
:param string workout_short_id: workout short id
:<json string workout_date: workout date in user timezone
(format: ``%Y-%m-%d %H:%M``)
:<json float ascent: workout ascent
(only for workout without gpx)
:<json float descent: workout descent
(only for workout without gpx)
:<json float distance: workout distance in km
(only for workout without gpx)
@ -1311,6 +1312,9 @@ def update_workout(
:<json string notes: notes
:<json integer sport_id: workout sport id
:<json string title: workout title
:<json string workout_date: workout date in user timezone
(format: ``%Y-%m-%d %H:%M``)
(only for workout without gpx)
:reqheader Authorization: OAuth 2.0 Bearer Token
@ -1338,6 +1342,33 @@ def update_workout(
if response_object:
return response_object
if not workout.gpx:
try:
# for workout without gpx file, both elevation values must be
# provided.
if (
(
'ascent' in workout_data
and 'descent' not in workout_data
)
or (
'ascent' not in workout_data
and 'descent' in workout_data
)
) or (
not (
workout_data.get('ascent') is None
and workout_data.get('descent') is None
)
and (
float(workout_data.get('ascent')) < 0
or float(workout_data.get('descent')) < 0
)
):
return InvalidPayloadErrorResponse()
except (TypeError, ValueError):
return InvalidPayloadErrorResponse()
workout = edit_workout(workout, workout_data, auth_user)
db.session.commit()
return {