Skip to content

Commit

Permalink
actually hide games
Browse files Browse the repository at this point in the history
  • Loading branch information
gantoine committed Sep 8, 2024
1 parent e1e2134 commit d5dfb71
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 13 deletions.
10 changes: 8 additions & 2 deletions backend/endpoints/responses/rom.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,10 +163,16 @@ class SimpleRomSchema(RomSchema):
rom_user: RomUserSchema

@classmethod
def from_orm_with_request(cls, db_rom: Rom, request: Request) -> SimpleRomSchema:
def from_orm_with_request(
cls, db_rom: Rom, request: Request
) -> SimpleRomSchema | None:
user_id = request.user.id

db_rom.rom_user = RomUserSchema.for_user(user_id, db_rom)
rom_user = RomUserSchema.for_user(user_id, db_rom)
if rom_user and rom_user.hidden:
return None

db_rom.rom_user = rom_user

return cls.model_validate(db_rom)

Expand Down
23 changes: 12 additions & 11 deletions backend/endpoints/rom.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,8 @@ def get_roms(
limit=limit,
)

return [SimpleRomSchema.from_orm_with_request(rom, request) for rom in roms]
roms = [SimpleRomSchema.from_orm_with_request(rom, request) for rom in roms]
return [rom for rom in roms if rom]


@protected_route(
Expand Down Expand Up @@ -541,34 +542,34 @@ async def update_rom_user(request: Request, id: int) -> RomUserSchema:

cleaned_data = {}

if data.get("note_raw_markdown", None):
if "note_raw_markdown" in data:
cleaned_data.update({"note_raw_markdown": data.get("note_raw_markdown")})

if data.get("note_is_public", None):
if "note_is_public" in data:
cleaned_data.update({"note_is_public": data.get("note_is_public")})

if data.get("is_main_sibling", None):
if "is_main_sibling" in data:
cleaned_data.update({"is_main_sibling": data.get("is_main_sibling")})

if data.get("backlogged", None):
if "backlogged" in data:
cleaned_data.update({"backlogged": data.get("backlogged")})

if data.get("now_playing", None):
if "now_playing" in data:
cleaned_data.update({"now_playing": data.get("now_playing")})

if data.get("hidden", None):
if "hidden" in data:
cleaned_data.update({"hidden": data.get("hidden")})

if data.get("rating", None):
if "rating" in data:
cleaned_data.update({"rating": data.get("rating")})

if data.get("difficulty", None):
if "difficulty" in data:
cleaned_data.update({"difficulty": data.get("difficulty")})

if data.get("completion", None):
if "completion" in data:
cleaned_data.update({"completion": data.get("completion")})

if data.get("status", None):
if "status" in data:
cleaned_data.update({"status": data.get("status")})

return db_rom_handler.update_rom_user(db_rom_user.id, cleaned_data)

0 comments on commit d5dfb71

Please sign in to comment.