add user collections to details

This commit is contained in:
zurdi
2024-07-04 00:51:17 +02:00
parent 5126c56ba9
commit f2f202de9e
6 changed files with 38 additions and 8 deletions

View File

@@ -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:
@@ -171,8 +171,8 @@ class DetailedRomSchema(RomSchema):
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

View File

@@ -181,12 +181,16 @@ class DBRomsHandler(DBBaseHandler):
@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()

View File

@@ -104,10 +104,10 @@ class Rom(BaseModel):
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

View File

@@ -3,6 +3,7 @@
/* tslint:disable */
/* eslint-disable */
import type { CollectionSchema } from "./CollectionSchema";
import type { RomIGDBMetadata } from "./RomIGDBMetadata";
import type { RomMobyMetadata } from "./RomMobyMetadata";
import type { RomSchema } from "./RomSchema";
@@ -58,5 +59,6 @@ export type DetailedRomSchema = {
user_states?: Array<StateSchema>;
user_screenshots?: Array<ScreenshotSchema>;
user_notes?: Array<UserNotesSchema>;
user_collections?: Array<CollectionSchema>;
readonly sort_comparator: string;
};

View File

@@ -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";
@@ -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>

View File

@@ -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>