|
8 | 8 | from fastapi import Request |
9 | 9 | from pydantic import ConfigDict, Field, computed_field, field_validator |
10 | 10 |
|
11 | | -from endpoints.responses.assets import SaveSchema, ScreenshotSchema, StateSchema |
| 11 | +from endpoints.responses.assets import ( |
| 12 | + SaveSchema, |
| 13 | + ScreenshotSchema, |
| 14 | + StateSchema, |
| 15 | + UserScreenshotSchema, |
| 16 | +) |
12 | 17 | from handler.metadata.flashpoint_handler import FlashpointMetadata |
13 | 18 | from handler.metadata.gamelist_handler import GamelistMetadata |
14 | 19 | from handler.metadata.hasheous_handler import HasheousMetadata |
@@ -460,6 +465,7 @@ class DetailedRomSchema(RomSchema): |
460 | 465 | user_saves: list[SaveSchema] |
461 | 466 | user_states: list[StateSchema] |
462 | 467 | user_screenshots: list[ScreenshotSchema] |
| 468 | + all_user_screenshots: list[UserScreenshotSchema] |
463 | 469 | user_collections: list[UserCollectionSchema] |
464 | 470 | all_user_notes: list[UserNoteSchema] |
465 | 471 |
|
@@ -524,6 +530,27 @@ def from_orm_with_request(cls, db_rom: Rom, request: Request) -> DetailedRomSche |
524 | 530 | all_notes.sort(key=lambda x: x.updated_at, reverse=True) |
525 | 531 | db_rom.all_user_notes = all_notes # type: ignore[assignment] |
526 | 532 |
|
| 533 | + # Gallery screenshots visible to this user: own (public + private) plus |
| 534 | + # other users' public ones. Mirrors the notes flow above. Excludes the |
| 535 | + # auto-captured save/state thumbnails (is_gallery == False). |
| 536 | + from handler.database import db_screenshot_handler |
| 537 | + |
| 538 | + gallery_screenshots = db_screenshot_handler.get_rom_gallery_screenshots( |
| 539 | + rom_id=db_rom.id, user_id=user_id |
| 540 | + ) |
| 541 | + db_rom.all_user_screenshots = [ # type: ignore[assignment] |
| 542 | + UserScreenshotSchema.model_validate( |
| 543 | + { |
| 544 | + **{ |
| 545 | + field: getattr(s, field) |
| 546 | + for field in ScreenshotSchema.model_fields |
| 547 | + }, |
| 548 | + "username": s.user.username, |
| 549 | + } |
| 550 | + ) |
| 551 | + for s in gallery_screenshots |
| 552 | + ] |
| 553 | + |
527 | 554 | return cls.model_validate(db_rom) |
528 | 555 |
|
529 | 556 | @field_validator("user_saves") |
|
0 commit comments