fmt+refactor
All checks were successful
Deploy on push / deploy (push) Successful in 24s

This commit is contained in:
2024-02-23 19:35:40 +03:00
parent 14947225a6
commit e80b3ac770
9 changed files with 307 additions and 119 deletions

View File

@@ -60,10 +60,18 @@ def create_shout(_, info, inp):
'published_at': None,
'created_at': current_time, # Set created_at as Unix timestamp
}
same_slug_shout = session.query(Shout).filter(Shout.slug == shout_dict.get('slug')).first()
same_slug_shout = (
session.query(Shout)
.filter(Shout.slug == shout_dict.get('slug'))
.first()
)
c = 1
while same_slug_shout is not None:
same_slug_shout = session.query(Shout).filter(Shout.slug == shout_dict.get('slug')).first()
same_slug_shout = (
session.query(Shout)
.filter(Shout.slug == shout_dict.get('slug'))
.first()
)
c += 1
shout_dict['slug'] += f'-{c}'
new_shout = Shout(**shout_dict)
@@ -174,10 +182,18 @@ async def update_shout(_, info, shout_id, shout_input=None, publish=False):
if slug:
shout_by_id = session.query(Shout).filter(Shout.id == shout_id).first()
if shout_by_id and slug != shout_by_id.slug:
same_slug_shout = session.query(Shout).filter(Shout.slug == shout_input.get('slug')).first()
same_slug_shout = (
session.query(Shout)
.filter(Shout.slug == shout_input.get('slug'))
.first()
)
c = 1
while same_slug_shout is not None:
same_slug_shout = session.query(Shout).filter(Shout.slug == shout_input.get('slug')).first()
same_slug_shout = (
session.query(Shout)
.filter(Shout.slug == shout_input.get('slug'))
.first()
)
c += 1
slug += f'-{c}'
shout_input['slug'] = slug