API - add elevation to workout w/o gpx file when provided
This commit is contained in:
@ -296,8 +296,10 @@ class Workout(BaseModel):
|
||||
'distance': float(self.distance) if self.distance else None,
|
||||
'min_alt': float(self.min_alt) if self.min_alt else None,
|
||||
'max_alt': float(self.max_alt) if self.max_alt else None,
|
||||
'descent': float(self.descent) if self.descent else None,
|
||||
'ascent': float(self.ascent) if self.ascent else None,
|
||||
'descent': float(self.descent)
|
||||
if self.descent is not None
|
||||
else None,
|
||||
'ascent': float(self.ascent) if self.ascent is not None else None,
|
||||
'max_speed': float(self.max_speed) if self.max_speed else None,
|
||||
'ave_speed': float(self.ave_speed) if self.ave_speed else None,
|
||||
'with_gpx': self.gpx is not None,
|
||||
|
@ -160,6 +160,8 @@ def create_workout(
|
||||
else float(new_workout.distance) / (duration.seconds / 3600)
|
||||
)
|
||||
new_workout.max_speed = new_workout.ave_speed
|
||||
new_workout.ascent = workout_data.get('ascent')
|
||||
new_workout.descent = workout_data.get('descent')
|
||||
return new_workout
|
||||
|
||||
|
||||
|
@ -1132,13 +1132,15 @@ def post_workout_no_gpx(
|
||||
"status": "success"
|
||||
}
|
||||
|
||||
:<json string workout_date: workout date, in user timezone
|
||||
(format: ``%Y-%m-%d %H:%M``)
|
||||
:<json float ascent: workout ascent (not mandatory)
|
||||
:<json float descent: workout descent (not mandatory)
|
||||
:<json float distance: workout distance in km
|
||||
:<json integer duration: workout duration in seconds
|
||||
:<json string notes: notes (not mandatory)
|
||||
:<json integer sport_id: workout sport id
|
||||
:<json string title: workout title
|
||||
:<json string title: workout title (not mandatory)
|
||||
:<json string workout_date: workout date, in user timezone
|
||||
(format: ``%Y-%m-%d %H:%M``)
|
||||
|
||||
:reqheader Authorization: OAuth 2.0 Bearer Token
|
||||
|
||||
@ -1161,6 +1163,20 @@ def post_workout_no_gpx(
|
||||
):
|
||||
return InvalidPayloadErrorResponse()
|
||||
|
||||
ascent = workout_data.get('ascent')
|
||||
descent = workout_data.get('descent')
|
||||
try:
|
||||
if (
|
||||
(ascent is None and descent is not None)
|
||||
or (ascent is not None and descent is None)
|
||||
or (
|
||||
(ascent is not None and descent is not None)
|
||||
and (float(ascent) < 0 or float(descent) < 0)
|
||||
)
|
||||
):
|
||||
return InvalidPayloadErrorResponse()
|
||||
except ValueError:
|
||||
return InvalidPayloadErrorResponse()
|
||||
try:
|
||||
new_workout = create_workout(auth_user, workout_data)
|
||||
db.session.add(new_workout)
|
||||
|
Reference in New Issue
Block a user