Merge branch 'dev' into oauth2

This commit is contained in:
Sam
2022-07-27 16:29:57 +02:00
136 changed files with 1963 additions and 1212 deletions

View File

@ -291,6 +291,7 @@ def get_authenticated_user_profile(
"bio": null,
"birth_date": null,
"created_at": "Sun, 14 Jul 2019 14:09:58 GMT",
"display_ascent": true,
"email": "sam@example.com",
"first_name": null,
"imperial_units": false,
@ -320,6 +321,15 @@ def get_authenticated_user_profile(
"workout_date": "Sun, 07 Jul 2019 08:00:00 GMT",
"workout_id": "hvYBqYBRa7wwXpaStWR4V2"
},
{
"id": 13,
"record_type": "HA",
"sport_id": 1,
"user": "Sam",
"value": 43.97,
"workout_date": "Sun, 07 Jul 2019 08:00:00 GMT",
"workout_id": "hvYBqYBRa7wwXpaStWR4V2"
},
{
"id": 11,
"record_type": "LD",
@ -392,6 +402,7 @@ def edit_user(auth_user: User) -> Union[Dict, HttpResponse]:
"bio": null,
"birth_date": null,
"created_at": "Sun, 14 Jul 2019 14:09:58 GMT",
"display_ascent": true,
"email": "sam@example.com",
"first_name": null,
"imperial_units": false,
@ -421,6 +432,15 @@ def edit_user(auth_user: User) -> Union[Dict, HttpResponse]:
"workout_date": "Sun, 07 Jul 2019 08:00:00 GMT",
"workout_id": "hvYBqYBRa7wwXpaStWR4V2"
},
{
"id": 13,
"record_type": "HA",
"sport_id": 1,
"user": "Sam",
"value": 43.97,
"workout_date": "Sun, 07 Jul 2019 08:00:00 GMT",
"workout_id": "hvYBqYBRa7wwXpaStWR4V2"
},
{
"id": 11,
"record_type": "LD",
@ -549,6 +569,7 @@ def update_user_account(auth_user: User) -> Union[Dict, HttpResponse]:
"bio": null,
"birth_date": null,
"created_at": "Sun, 14 Jul 2019 14:09:58 GMT",
"display_ascent": true,
"email": "sam@example.com",
"first_name": null,
"imperial_units": false,
@ -578,6 +599,15 @@ def update_user_account(auth_user: User) -> Union[Dict, HttpResponse]:
"workout_date": "Sun, 07 Jul 2019 08:00:00 GMT",
"workout_id": "hvYBqYBRa7wwXpaStWR4V2"
},
{
"id": 13,
"record_type": "HA",
"sport_id": 1,
"user": "Sam",
"value": 43.97,
"workout_date": "Sun, 07 Jul 2019 08:00:00 GMT",
"workout_id": "hvYBqYBRa7wwXpaStWR4V2"
},
{
"id": 11,
"record_type": "LD",
@ -750,6 +780,7 @@ def edit_user_preferences(auth_user: User) -> Union[Dict, HttpResponse]:
"bio": null,
"birth_date": null,
"created_at": "Sun, 14 Jul 2019 14:09:58 GMT",
"display_ascent": true,
"email": "sam@example.com",
"first_name": null,
"imperial_units": false,
@ -779,6 +810,15 @@ def edit_user_preferences(auth_user: User) -> Union[Dict, HttpResponse]:
"workout_date": "Sun, 07 Jul 2019 08:00:00 GMT",
"workout_id": "hvYBqYBRa7wwXpaStWR4V2"
},
{
"id": 13,
"record_type": "HA",
"sport_id": 1,
"user": "Sam",
"value": 43.97,
"workout_date": "Sun, 07 Jul 2019 08:00:00 GMT",
"workout_id": "hvYBqYBRa7wwXpaStWR4V2"
},
{
"id": 11,
"record_type": "LD",
@ -813,10 +853,11 @@ def edit_user_preferences(auth_user: User) -> Union[Dict, HttpResponse]:
"status": "success"
}
:<json boolean display_ascent: display highest ascent records and total
:<json boolean imperial_units: display distance in imperial units
:<json string language: language preferences
:<json string timezone: user time zone
:<json boolean weekm: does week start on Monday?
:<json string language: language preferences
:<json boolean imperial_units: display distance in imperial units
:reqheader Authorization: OAuth 2.0 Bearer Token
@ -833,6 +874,7 @@ def edit_user_preferences(auth_user: User) -> Union[Dict, HttpResponse]:
# get post data
post_data = request.get_json()
user_mandatory_data = {
'display_ascent',
'imperial_units',
'language',
'timezone',
@ -841,12 +883,14 @@ def edit_user_preferences(auth_user: User) -> Union[Dict, HttpResponse]:
if not post_data or not post_data.keys() >= user_mandatory_data:
return InvalidPayloadErrorResponse()
display_ascent = post_data.get('display_ascent')
imperial_units = post_data.get('imperial_units')
language = get_language(post_data.get('language'))
timezone = post_data.get('timezone')
weekm = post_data.get('weekm')
try:
auth_user.display_ascent = display_ascent
auth_user.imperial_units = imperial_units
auth_user.language = language
auth_user.timezone = timezone

View File

@ -50,6 +50,7 @@ class User(BaseModel):
is_active = db.Column(db.Boolean, default=False, nullable=False)
email_to_confirm = db.Column(db.String(255), nullable=True)
confirmation_token = db.Column(db.String(255), nullable=True)
display_ascent = db.Column(db.Boolean, default=True, nullable=False)
def __repr__(self) -> str:
return f'<User {self.username!r}>'
@ -139,7 +140,7 @@ class User(BaseModel):
raise UserNotFoundException()
sports = []
total = (0, '0:00:00')
total = (0, '0:00:00', 0)
if self.workouts_count > 0: # type: ignore
sports = (
db.session.query(Workout.sport_id)
@ -150,7 +151,9 @@ class User(BaseModel):
)
total = (
db.session.query(
func.sum(Workout.distance), func.sum(Workout.duration)
func.sum(Workout.distance),
func.sum(Workout.duration),
func.sum(Workout.ascent),
)
.filter(Workout.user_id == self.id)
.first()
@ -174,6 +177,7 @@ class User(BaseModel):
'sports_list': [
sport for sportslist in sports for sport in sportslist
],
'total_ascent': float(total[2]) if total[2] else 0.0,
'total_distance': float(total[0]),
'total_duration': str(total[1]),
'username': self.username,
@ -182,6 +186,7 @@ class User(BaseModel):
serialized_user = {
**serialized_user,
**{
'display_ascent': self.display_ascent,
'imperial_units': self.imperial_units,
'language': self.language,
'timezone': self.timezone,

View File

@ -105,6 +105,15 @@ def get_users(auth_user: User) -> Dict:
"workout_date": "Sun, 07 Jul 2019 08:00:00 GMT",
"workout_id": "hvYBqYBRa7wwXpaStWR4V2"
},
{
"id": 13,
"record_type": "HA",
"sport_id": 1,
"user": "Sam",
"value": 43.97,
"workout_date": "Sun, 07 Jul 2019 08:00:00 GMT",
"workout_id": "hvYBqYBRa7wwXpaStWR4V2"
},
{
"id": 11,
"record_type": "LD",
@ -300,6 +309,15 @@ def get_single_user(
"workout_date": "Sun, 07 Jul 2019 08:00:00 GMT",
"workout_id": "hvYBqYBRa7wwXpaStWR4V2"
},
{
"id": 13,
"record_type": "HA",
"sport_id": 1,
"user": "Sam",
"value": 43.97,
"workout_date": "Sun, 07 Jul 2019 08:00:00 GMT",
"workout_id": "hvYBqYBRa7wwXpaStWR4V2"
},
{
"id": 11,
"record_type": "LD",
@ -464,6 +482,15 @@ def update_user(auth_user: User, user_name: str) -> Union[Dict, HttpResponse]:
"workout_date": "Sun, 07 Jul 2019 08:00:00 GMT",
"workout_id": "hvYBqYBRa7wwXpaStWR4V2"
},
{
"id": 13,
"record_type": "HA",
"sport_id": 1,
"user": "Sam",
"value": 43.97,
"workout_date": "Sun, 07 Jul 2019 08:00:00 GMT",
"workout_id": "hvYBqYBRa7wwXpaStWR4V2"
},
{
"id": 11,
"record_type": "LD",