mirror of
https://github.com/rommapp/romm.git
synced 2026-02-18 23:42:07 +01:00
add user_rom_props to get_roms
This commit is contained in:
@@ -98,6 +98,8 @@ class RomSchema(BaseModel):
|
||||
created_at: datetime
|
||||
updated_at: datetime
|
||||
|
||||
user_rom_props: UserRomPropsSchema = Field(default_factory=list)
|
||||
|
||||
class Config:
|
||||
from_attributes = True
|
||||
|
||||
@@ -120,7 +122,6 @@ class DetailedRomSchema(RomSchema):
|
||||
user_saves: list[SaveSchema] = Field(default_factory=list)
|
||||
user_states: list[StateSchema] = Field(default_factory=list)
|
||||
user_screenshots: list[ScreenshotSchema] = Field(default_factory=list)
|
||||
user_rom_props: list[UserRomPropsSchema] = Field(default_factory=list)
|
||||
|
||||
@classmethod
|
||||
def from_orm_with_request(
|
||||
@@ -128,7 +129,6 @@ class DetailedRomSchema(RomSchema):
|
||||
) -> "DetailedRomSchema":
|
||||
rom = cls.model_validate(db_rom)
|
||||
user_id = request.user.id
|
||||
|
||||
rom.sibling_roms = [
|
||||
RomSchema.model_validate(r) for r in db_rom.get_sibling_roms()
|
||||
]
|
||||
@@ -143,8 +143,6 @@ class DetailedRomSchema(RomSchema):
|
||||
for s in db_rom.screenshots
|
||||
if s.user_id == user_id
|
||||
]
|
||||
rom.user_rom_props = UserRomPropsSchema.for_user(db_rom, user_id)
|
||||
|
||||
return rom
|
||||
|
||||
|
||||
|
||||
@@ -114,6 +114,7 @@ def get_roms(
|
||||
order_by=order_by.lower(),
|
||||
order_dir=order_dir.lower(),
|
||||
limit=limit,
|
||||
user_id=request.user.id,
|
||||
)
|
||||
|
||||
|
||||
|
||||
@@ -69,21 +69,22 @@ class DBRomsHandler(DBBaseHandler):
|
||||
search_term: str = "",
|
||||
order_by: str = "name",
|
||||
order_dir: str = "asc",
|
||||
limit: int = None,
|
||||
limit: int | None = None,
|
||||
user_id: int | None = None,
|
||||
query: Query = None,
|
||||
session: Session = None,
|
||||
) -> list[Rom] | Rom | None:
|
||||
return (
|
||||
session.scalar(query.filter_by(id=id).limit(1))
|
||||
if id
|
||||
else session.scalars(
|
||||
# TODO: get user_rom_props from user_id
|
||||
if id:
|
||||
return session.scalar(query.filter_by(id=id).limit(1))
|
||||
else:
|
||||
return session.scalars(
|
||||
self._order(
|
||||
self._filter(select(Rom), platform_id, search_term),
|
||||
order_by,
|
||||
order_dir,
|
||||
).limit(limit)
|
||||
).all()
|
||||
)
|
||||
|
||||
@begin_session
|
||||
@with_assets
|
||||
|
||||
@@ -50,11 +50,11 @@ export type DetailedRomSchema = {
|
||||
full_path: string;
|
||||
created_at: string;
|
||||
updated_at: string;
|
||||
user_rom_props?: Array<UserRomPropsSchema>;
|
||||
merged_screenshots: Array<string>;
|
||||
sibling_roms?: Array<RomSchema>;
|
||||
user_saves?: Array<SaveSchema>;
|
||||
user_states?: Array<StateSchema>;
|
||||
user_screenshots?: Array<ScreenshotSchema>;
|
||||
user_rom_props?: Array<UserRomPropsSchema>;
|
||||
readonly sort_comparator: string;
|
||||
};
|
||||
|
||||
2
frontend/src/__generated__/models/RomSchema.ts
generated
2
frontend/src/__generated__/models/RomSchema.ts
generated
@@ -5,6 +5,7 @@
|
||||
|
||||
import type { RomIGDBMetadata } from "./RomIGDBMetadata";
|
||||
import type { RomMobyMetadata } from "./RomMobyMetadata";
|
||||
import type { UserRomPropsSchema } from "./UserRomPropsSchema";
|
||||
|
||||
export type RomSchema = {
|
||||
id: number;
|
||||
@@ -45,5 +46,6 @@ export type RomSchema = {
|
||||
full_path: string;
|
||||
created_at: string;
|
||||
updated_at: string;
|
||||
user_rom_props?: Array<UserRomPropsSchema>;
|
||||
readonly sort_comparator: string;
|
||||
};
|
||||
|
||||
@@ -5,6 +5,7 @@ import type { ExtractPiniaStoreType } from "@/types";
|
||||
import { groupBy, uniqBy } from "lodash";
|
||||
import { nanoid } from "nanoid";
|
||||
import { defineStore } from "pinia";
|
||||
import storeAuth from "@/stores/auth";
|
||||
import storeGalleryFilter from "./galleryFilter";
|
||||
|
||||
type GalleryFilterStore = ExtractPiniaStoreType<typeof storeGalleryFilter>;
|
||||
@@ -51,6 +52,8 @@ export default defineStore("roms", {
|
||||
return;
|
||||
}
|
||||
|
||||
const auth = storeAuth();
|
||||
|
||||
// Group roms by external id
|
||||
this._grouped = Object.values(
|
||||
groupBy(
|
||||
@@ -61,12 +64,14 @@ export default defineStore("roms", {
|
||||
),
|
||||
)
|
||||
.map((games) => {
|
||||
const primaryGame = games.shift();
|
||||
// const favSiblingIndex = games.findIndex((game) => game.fav_sibling);
|
||||
// const primaryGame =
|
||||
// favSiblingIndex !== -1
|
||||
// ? games.splice(favSiblingIndex, 1)[0]
|
||||
// : games.shift();
|
||||
const favSiblingIndex = games.findIndex((game) =>
|
||||
game.user_rom_props?.find((prop) => prop.user_id === auth.user?.id),
|
||||
);
|
||||
console.log(favSiblingIndex);
|
||||
const primaryGame =
|
||||
favSiblingIndex !== -1
|
||||
? games.splice(favSiblingIndex, 1)[0]
|
||||
: games.shift();
|
||||
|
||||
return {
|
||||
...(primaryGame as SimpleRom),
|
||||
|
||||
Reference in New Issue
Block a user