API - add preferences for ascent record display
This commit is contained in:
parent
d66f6828e4
commit
06b7af126a
@ -23,8 +23,16 @@ def upgrade():
|
||||
"""
|
||||
)
|
||||
|
||||
op.add_column(
|
||||
'users', sa.Column('display_ascent', sa.Boolean(), nullable=True)
|
||||
)
|
||||
op.execute("UPDATE users SET display_ascent = true")
|
||||
op.alter_column('users', 'display_ascent', nullable=False)
|
||||
|
||||
|
||||
def downgrade():
|
||||
op.drop_column('users', 'display_ascent')
|
||||
|
||||
op.execute("DELETE FROM records WHERE record_type = 'HA';")
|
||||
op.execute("ALTER TYPE record_types RENAME TO record_types_old")
|
||||
op.execute("CREATE TYPE record_types AS ENUM('AS', 'FD', 'LD', 'MS')")
|
||||
|
@ -1272,6 +1272,7 @@ class TestUserPreferencesUpdate(ApiTestCaseMixin):
|
||||
weekm=True,
|
||||
language=input_language,
|
||||
imperial_units=True,
|
||||
display_ascent=False,
|
||||
)
|
||||
),
|
||||
headers=dict(Authorization=f'Bearer {auth_token}'),
|
||||
@ -1281,8 +1282,11 @@ class TestUserPreferencesUpdate(ApiTestCaseMixin):
|
||||
data = json.loads(response.data.decode())
|
||||
assert data['status'] == 'success'
|
||||
assert data['message'] == 'user preferences updated'
|
||||
assert data['data']['display_ascent'] is False
|
||||
assert data['data']['imperial_units'] is True
|
||||
assert data['data']['language'] == expected_language
|
||||
assert data['data'] == jsonify_dict(user_1.serialize(user_1))
|
||||
assert data['data']['timezone'] == 'America/New_York'
|
||||
assert data['data']['weekm'] is True
|
||||
|
||||
|
||||
class TestUserSportPreferencesUpdate(ApiTestCaseMixin):
|
||||
|
@ -66,6 +66,7 @@ class TestUserSerializeAsAuthUser(UserModelAssertMixin):
|
||||
assert serialized_user['language'] == user_1.language
|
||||
assert serialized_user['timezone'] == user_1.timezone
|
||||
assert serialized_user['weekm'] == user_1.weekm
|
||||
assert serialized_user['display_ascent'] == user_1.display_ascent
|
||||
|
||||
def test_it_returns_workouts_infos(self, app: Flask, user_1: User) -> None:
|
||||
serialized_user = user_1.serialize(user_1)
|
||||
|
@ -830,6 +830,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',
|
||||
@ -838,12 +839,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
|
||||
|
@ -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}>'
|
||||
@ -170,6 +171,7 @@ class User(BaseModel):
|
||||
serialized_user = {
|
||||
**serialized_user,
|
||||
**{
|
||||
'display_ascent': self.display_ascent,
|
||||
'imperial_units': self.imperial_units,
|
||||
'language': self.language,
|
||||
'timezone': self.timezone,
|
||||
|
Loading…
Reference in New Issue
Block a user