Skip to content

Commit

Permalink
Update achievement.py
Browse files Browse the repository at this point in the history
  • Loading branch information
BombinBM authored Aug 16, 2024
1 parent d26f321 commit 9d61671
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions achievement_api/routes/achievement.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ 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:
raise HTTPException(400, "Not valid image, should be png 512x512px")
return db.session.query(Achievement).get(id)


Expand All @@ -66,6 +68,8 @@ 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(400, "Not valid image, should be png 512x512px")
achievement: Achievement = db.session.query(Achievement).get(id)
logger.info(f"User id={user['id']} edit achievement {new_data.name} ({achievement.name})")
achievement.name = new_data.name or achievement.name
Expand All @@ -80,6 +84,8 @@ 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(400, "Not valid image, should be png 512x512px")
achievement: Achievement = db.session.query(Achievement).get(id)
logger.info(f"User id={user['id']} uploaded photo for achievement {achievement.name}")
picture = await picture_file.read()
Expand Down

0 comments on commit 9d61671

Please sign in to comment.