Skip to content

Commit

Permalink
Update achievement.py
Browse files Browse the repository at this point in the history
  • Loading branch information
BombinBM authored Sep 3, 2024
1 parent ef3a7da commit 865b207
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions achievement_api/routes/achievement.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,10 @@ def get_all_achievements() -> list[AchievementGet]:

@router.get("/{id}")
def get_achievement(id: int) -> AchievementGet:
if db.session.query(Achievement).filter(Achievement.id == id).one_or_none() == None:
achievement = db.session.query(Achievement).filter(Achievement.id == id)
if achievement is None:
raise HTTPException(404, "The achievement was not found")
return db.session.query(Achievement).get(id)
return achievement


@router.post("")
Expand All @@ -68,9 +69,9 @@ def edit_achievement(
id: int, new_data: AchievementEdit, user=Depends(UnionAuth(['achievements.achievement.edit']))
) -> AchievementGet:
"""Нужны права на: `achievements.achievement.edit`"""
if db.session.query(Achievement).filter(Achievement.id == id).one_or_none() == None:
raise HTTPException(404, "The achievement was not found")
achievement: Achievement = db.session.query(Achievement).get(id)
if achievement is None:
raise HTTPException(404, "The achievement was not found")
logger.info(f"User id={user['id']} edit achievement {new_data.name} ({achievement.name})")
achievement.name = new_data.name or achievement.name
achievement.description = new_data.description or achievement.description
Expand All @@ -84,9 +85,9 @@ async def upload_picture(
picture_file: UploadFile = File(...),
user=Depends(UnionAuth(['achievements.achievement.create', 'achievements.achievement.edit'])),
) -> AchievementGet:
if db.session.query(Achievement).filter(Achievement.id == id).one_or_none() == None:
raise HTTPException(404, "The achievement was not found")
achievement: Achievement = db.session.query(Achievement).get(id)
if achievement is None:
raise HTTPException(404, "The achievement was not found")
logger.info(f"User id={user['id']} uploaded photo for achievement {achievement.name}")
picture = await picture_file.read()
await picture_file.close()
Expand Down

0 comments on commit 865b207

Please sign in to comment.