Skip to content

Commit

Permalink
Save photo after inserting to db
Browse files Browse the repository at this point in the history
Otherwise the id in file_path is unassigned
  • Loading branch information
Zaczero authored Apr 5, 2024
1 parent 80dcacc commit 8b54c8f
Showing 1 changed file with 5 additions and 7 deletions.
12 changes: 5 additions & 7 deletions services/photo_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,21 +27,19 @@ async def get_by_id(id: str, *, check_file: bool = True) -> Photo | None:
@staticmethod
@trace
async def upload(node_id: int, user_id: int, file: UploadFile) -> Photo:
photo = Photo(
node_id=node_id,
user_id=user_id,
)

img = Image.open(file.file)
img = ImageOps.exif_transpose(img)
img = _resize_image(img)
img_bytes = _optimize_quality(img)

await photo.file_path.write_bytes(img_bytes)

async with db_write() as session:
photo = Photo(
node_id=node_id,
user_id=user_id,
)
session.add(photo)

await photo.file_path.write_bytes(img_bytes)
return photo


Expand Down

0 comments on commit 8b54c8f

Please sign in to comment.