API - remove useless user queries

This commit is contained in:
Sam 2021-12-01 19:31:42 +01:00
parent 00b6e05805
commit 9e7fbd6eb4
4 changed files with 10 additions and 19 deletions

View File

@ -46,7 +46,7 @@ class TestStoppedSpeedThreshold:
) as gpx_track_segment_mock: ) as gpx_track_segment_mock:
process_files( process_files(
auth_user_id=user_1.id, auth_user=user_1,
folders=folders, folders=folders,
workout_data={'sport_id': sport_id}, workout_data={'sport_id': sport_id},
workout_file=gpx_file_storage, workout_file=gpx_file_storage,
@ -76,7 +76,7 @@ class TestStoppedSpeedThreshold:
) as gpx_track_segment_mock: ) as gpx_track_segment_mock:
process_files( process_files(
auth_user_id=user_1.id, auth_user=user_1,
folders=folders, folders=folders,
workout_data={'sport_id': sport_1_cycling.id}, workout_data={'sport_id': sport_1_cycling.id},
workout_file=gpx_file_storage, workout_file=gpx_file_storage,

View File

@ -12,14 +12,6 @@ from fittrackee.responses import (
from .models import User from .models import User
def is_admin(user_id: int) -> bool:
"""
Return if user has admin rights
"""
user = User.query.filter_by(id=user_id).first()
return user.admin
def is_valid_email(email: str) -> bool: def is_valid_email(email: str) -> bool:
""" """
Return if email format is valid Return if email format is valid

View File

@ -299,9 +299,9 @@ def process_one_gpx_file(
gpx_data, map_data, weather_data = get_gpx_info( gpx_data, map_data, weather_data = get_gpx_info(
params['file_path'], stopped_speed_threshold params['file_path'], stopped_speed_threshold
) )
auth_user_id = params['user'].id auth_user = params['auth_user']
new_filepath = get_new_file_path( new_filepath = get_new_file_path(
auth_user_id=auth_user_id, auth_user_id=auth_user.id,
workout_date=gpx_data['start'], workout_date=gpx_data['start'],
old_filename=filename, old_filename=filename,
sport=params['sport_label'], sport=params['sport_label'],
@ -311,7 +311,7 @@ def process_one_gpx_file(
gpx_data['filename'] = new_filepath gpx_data['filename'] = new_filepath
map_filepath = get_new_file_path( map_filepath = get_new_file_path(
auth_user_id=auth_user_id, auth_user_id=auth_user.id,
workout_date=gpx_data['start'], workout_date=gpx_data['start'],
extension='.png', extension='.png',
sport=params['sport_label'], sport=params['sport_label'],
@ -325,7 +325,7 @@ def process_one_gpx_file(
try: try:
new_workout = create_workout( new_workout = create_workout(
params['user'], params['workout_data'], gpx_data auth_user, params['workout_data'], gpx_data
) )
new_workout.map = map_filepath new_workout.map = map_filepath
new_workout.map_id = get_map_hash(map_filepath) new_workout.map_id = get_map_hash(map_filepath)
@ -380,7 +380,7 @@ def process_zip_archive(
def process_files( def process_files(
auth_user_id: int, auth_user: User,
workout_data: Dict, workout_data: Dict,
workout_file: FileStorage, workout_file: FileStorage,
folders: Dict, folders: Dict,
@ -399,9 +399,8 @@ def process_files(
'error', 'error',
f"Sport id: {workout_data.get('sport_id')} does not exist", f"Sport id: {workout_data.get('sport_id')} does not exist",
) )
user = User.query.filter_by(id=auth_user_id).first()
sport_preferences = UserSportPreference.query.filter_by( sport_preferences = UserSportPreference.query.filter_by(
user_id=user.id, sport_id=sport.id user_id=auth_user.id, sport_id=sport.id
).first() ).first()
stopped_speed_threshold = ( stopped_speed_threshold = (
sport.stopped_speed_threshold sport.stopped_speed_threshold
@ -410,7 +409,7 @@ def process_files(
) )
common_params = { common_params = {
'user': user, 'auth_user': auth_user,
'workout_data': workout_data, 'workout_data': workout_data,
'file_path': file_path, 'file_path': file_path,
'sport_label': sport.label, 'sport_label': sport.label,

View File

@ -980,7 +980,7 @@ def post_workout(auth_user: User) -> Union[Tuple[Dict, int], HttpResponse]:
try: try:
new_workouts = process_files( new_workouts = process_files(
auth_user.id, workout_data, workout_file, folders auth_user, workout_data, workout_file, folders
) )
if len(new_workouts) > 0: if len(new_workouts) > 0:
response_object = { response_object = {