Skip to content

Commit

Permalink
fix from_orm_with_request
Browse files Browse the repository at this point in the history
  • Loading branch information
Georges-Antoine Assi committed Feb 8, 2024
1 parent 0f3a2f5 commit 01c3054
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions backend/endpoints/responses/rom.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,13 +99,19 @@ def from_orm_with_request(cls, db_rom: Rom, request: Request) -> "RomSchema":
rom = cls.model_validate(db_rom)
user_id = request.user.id

rom.sibling_roms = db_rom.get_sibling_roms()
rom.user_saves = [save for save in db_rom.saves if save.user_id == user_id]
rom.user_states = [state for state in db_rom.states if state.user_id == user_id]
rom.sibling_roms = [
RomSchema.model_validate(r) for r in db_rom.get_sibling_roms()
]
rom.user_saves = [
SaveSchema.model_validate(s) for s in db_rom.saves if s.user_id == user_id
]
rom.user_states = [
StateSchema.model_validate(s) for s in db_rom.states if s.user_id == user_id
]
rom.user_screenshots = [
screenshot
for screenshot in db_rom.screenshots
if screenshot.user_id == user_id
ScreenshotSchema.model_validate(s)
for s in db_rom.screenshots
if s.user_id == user_id
]

return rom
Expand Down

0 comments on commit 01c3054

Please sign in to comment.