Skip to content

Commit

Permalink
add user collections to details
Browse files Browse the repository at this point in the history
  • Loading branch information
zurdi15 committed Jul 3, 2024
1 parent 5126c56 commit f2f202d
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 8 deletions.
6 changes: 3 additions & 3 deletions backend/endpoints/responses/rom.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ class DetailedRomSchema(RomSchema):
user_states: list[StateSchema] = Field(default_factory=list)
user_screenshots: list[ScreenshotSchema] = Field(default_factory=list)
user_notes: list[UserNotesSchema] = Field(default_factory=list)
collections: list[CollectionSchema] = Field(default_factory=list)
user_collections: list[CollectionSchema] = Field(default_factory=list)

@classmethod
def from_orm_with_request(cls, db_rom: Rom, request: Request) -> DetailedRomSchema:
Expand All @@ -171,8 +171,8 @@ def from_orm_with_request(cls, db_rom: Rom, request: Request) -> DetailedRomSche
for s in db_rom.screenshots
if s.user_id == user_id
]
rom.collections = [
CollectionSchema.model_validate(c) for c in db_rom.get_collections()
rom.user_collections = [
CollectionSchema.model_validate(c) for c in db_rom.get_collections(user_id)
]

return rom
Expand Down
8 changes: 6 additions & 2 deletions backend/handler/database/roms_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -181,12 +181,16 @@ def get_sibling_roms(

@begin_session
def get_rom_collections(
self, rom_id: int, session: Session = None
self, rom: Rom, user_id: int, session: Session = None
) -> list[Collection]:

return (
session.scalars(
select(Collection)
.filter(Collection.roms.contains([rom_id]))
.filter(
func.json_contains(Collection.roms, f"{rom.id}"),
Collection.user_id == user_id,
)
.order_by(Collection.name.asc())
)
.unique()
Expand Down
4 changes: 2 additions & 2 deletions backend/models/rom.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,10 +104,10 @@ def get_sibling_roms(self) -> list[Rom]:

return db_rom_handler.get_sibling_roms(self)

def get_collections(self) -> list[Collection]:
def get_collections(self, user_id) -> list[Collection]:
from handler.database import db_rom_handler

return db_rom_handler.get_rom_collections(self.id)
return db_rom_handler.get_rom_collections(self, user_id)

# Metadata fields
@property
Expand Down
2 changes: 2 additions & 0 deletions frontend/src/__generated__/models/DetailedRomSchema.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

24 changes: 24 additions & 0 deletions frontend/src/components/Details/Info/FileInfo.vue
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<script setup lang="ts">
import VersionSwitcher from "@/components/Details/VersionSwitcher.vue";
import RAvatar from "@/components/common/Collection/RAvatar.vue";
import romApi from "@/services/api/rom";
import storeAuth from "@/stores/auth";
import storeDownload from "@/stores/download";
Expand Down Expand Up @@ -150,6 +151,29 @@ watch(
</v-chip>
</v-col>
</v-row>
<v-row
v-if="rom.user_collections && rom.user_collections?.length > 0"
no-gutters
class="align-center my-3"
>
<v-col cols="3" xl="2">
<span>Collections</span>
</v-col>
<v-col>
<v-chip
v-for="collection in rom.user_collections"
:to="{ name: 'collection', params: { collection: collection.id } }"
size="large"
class="mr-1 mt-1"
label
>
<template #prepend>
<r-avatar :size="25" :collection="collection" />
</template>
<span class="ml-2">{{ collection.name }}</span>
</v-chip>
</v-col>
</v-row>
</v-col>
</v-row>
</template>
2 changes: 1 addition & 1 deletion frontend/src/components/Details/Info/GameInfo.vue
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ const show = ref(false);
<v-divider class="mx-2 my-4" />
<v-row no-gutters>
<v-col class="text-caption">
<p v-text="rom.summary" />
<span>{{ rom.summary }}</span>
</v-col>
</v-row>
</template>
Expand Down

0 comments on commit f2f202d

Please sign in to comment.