API & Client - refacto + handle null values

This commit is contained in:
Sam 2023-07-29 10:51:04 +02:00
parent 4af294cd4a
commit 01ee50c50c
4 changed files with 23 additions and 20 deletions

View File

@ -200,21 +200,21 @@ class Workout(BaseModel):
'creation_date': self.creation_date, 'creation_date': self.creation_date,
'modification_date': self.modification_date, 'modification_date': self.modification_date,
'workout_date': self.workout_date, 'workout_date': self.workout_date,
'duration': str(self.duration) if self.duration else None, 'duration': None if self.duration is None else str(self.duration),
'pauses': str(self.pauses) if self.pauses else None, 'pauses': str(self.pauses) if self.pauses else None,
'moving': str(self.moving) if self.moving else None, 'moving': None if self.moving is None else str(self.moving),
'distance': float(self.distance) if self.distance else None, 'distance': (
'min_alt': float(self.min_alt) if self.min_alt else None, None if self.distance is None else float(self.distance)
'max_alt': float(self.max_alt) if self.max_alt else None, ),
'descent': float(self.descent) 'min_alt': None if self.min_alt is None else float(self.min_alt),
if self.descent is not None 'max_alt': None if self.max_alt is None else float(self.max_alt),
else None, 'descent': None if self.descent is None else float(self.descent),
'ascent': float(self.ascent) if self.ascent is not None else None, 'ascent': None if self.ascent is None else float(self.ascent),
'max_speed': ( 'max_speed': (
float(self.max_speed) if self.max_speed is not None else None None if self.max_speed is None else float(self.max_speed)
), ),
'ave_speed': ( 'ave_speed': (
float(self.ave_speed) if self.ave_speed is not None else None None if self.ave_speed is None else float(self.ave_speed)
), ),
'records': [record.serialize() for record in self.records], 'records': [record.serialize() for record in self.records],
'segments': [segment.serialize() for segment in self.segments], 'segments': [segment.serialize() for segment in self.segments],

View File

@ -12,7 +12,7 @@
<span class="value">{{ workoutObject.duration }})</span> <span class="value">{{ workoutObject.duration }})</span>
</div> </div>
</div> </div>
<div class="workout-data"> <div class="workout-data" v-if="workoutObject.distance !== null">
<i class="fa fa-road" aria-hidden="true" /> <i class="fa fa-road" aria-hidden="true" />
<span class="label"> {{ $t('workouts.DISTANCE') }} </span>: <span class="label"> {{ $t('workouts.DISTANCE') }} </span>:
<Distance <Distance

View File

@ -98,6 +98,7 @@
{{ $t('workouts.DISTANCE') }} {{ $t('workouts.DISTANCE') }}
</span> </span>
<Distance <Distance
v-if="workout.distance !== null"
:distance="workout.distance" :distance="workout.distance"
unitFrom="km" unitFrom="km"
:useImperialUnits="user.imperial_units" :useImperialUnits="user.imperial_units"
@ -114,6 +115,7 @@
{{ $t('workouts.AVE_SPEED') }} {{ $t('workouts.AVE_SPEED') }}
</span> </span>
<Distance <Distance
v-if="workout.ave_speed !== null"
:distance="workout.ave_speed" :distance="workout.ave_speed"
unitFrom="km" unitFrom="km"
:speed="true" :speed="true"
@ -125,6 +127,7 @@
{{ $t('workouts.MAX_SPEED') }} {{ $t('workouts.MAX_SPEED') }}
</span> </span>
<Distance <Distance
v-if="workout.max_speed !== null"
:distance="workout.max_speed" :distance="workout.max_speed"
unitFrom="km" unitFrom="km"
:speed="true" :speed="true"

View File

@ -55,19 +55,19 @@ export interface IWeather {
export interface IWorkout { export interface IWorkout {
ascent: number | null ascent: number | null
ave_speed: number ave_speed: number | null
bounds: number[] bounds: number[]
creation_date: string creation_date: string
descent: number | null descent: number | null
distance: number distance: number | null
duration: string duration: string | null
id: string id: string
map: string | null map: string | null
max_alt: number | null max_alt: number | null
max_speed: number max_speed: number | null
min_alt: number | null min_alt: number | null
modification_date: string | null modification_date: string | null
moving: string moving: string | null
next_workout: string | null next_workout: string | null
notes: string notes: string
pauses: string | null pauses: string | null
@ -87,12 +87,12 @@ export interface IWorkoutObject {
ascent: number | null ascent: number | null
aveSpeed: number | null aveSpeed: number | null
descent: number | null descent: number | null
distance: number distance: number | null
duration: string duration: string | null
maxAlt: number | null maxAlt: number | null
maxSpeed: number | null maxSpeed: number | null
minAlt: number | null minAlt: number | null
moving: string moving: string | null
nextUrl: string | null nextUrl: string | null
pauses: string | null pauses: string | null
previousUrl: string | null previousUrl: string | null