diff --git a/backend/endpoints/platform.py b/backend/endpoints/platform.py
index bcce3bc09..af16d820b 100644
--- a/backend/endpoints/platform.py
+++ b/backend/endpoints/platform.py
@@ -1,3 +1,5 @@
+from datetime import datetime
+
from decorators.auth import protected_route
from endpoints.responses import MessageResponse
from endpoints.responses.platform import PlatformSchema
@@ -74,6 +76,8 @@ def get_supported_platforms(request: Request) -> list[PlatformSchema]:
"logo_path": "",
"roms": [],
"rom_count": 0,
+ "created_at": datetime.now(),
+ "updated_at": datetime.now(),
}
if platform["name"] in db_platforms_map:
@@ -96,7 +100,15 @@ def get_platform(request: Request, id: int) -> PlatformSchema:
PlatformSchema: Platform
"""
- return db_platform_handler.get_platforms(id)
+ platform = db_platform_handler.get_platforms(id)
+ if platform:
+ return platform
+ else:
+ msg = f"Platform with {id} not found"
+ log.critical(msg)
+ raise HTTPException(
+ status_code=status.HTTP_500_INTERNAL_SERVER_ERROR, detail=msg
+ )
@protected_route(router.put, "/platforms/{id}", ["platforms.write"])
diff --git a/backend/models/collection.py b/backend/models/collection.py
new file mode 100644
index 000000000..9c988da20
--- /dev/null
+++ b/backend/models/collection.py
@@ -0,0 +1,32 @@
+from datetime import datetime
+
+from models.base import BaseModel
+from models.rom import Rom
+from sqlalchemy import DateTime, String, Text, func, select
+from sqlalchemy.orm import Mapped, column_property, mapped_column, relationship
+
+
+class Collection(BaseModel):
+ __tablename__ = "collections"
+
+ id: Mapped[int] = mapped_column(primary_key=True, autoincrement=True)
+ name: Mapped[str | None] = mapped_column(String(length=400))
+ description: Mapped[str | None] = mapped_column(Text)
+ logo_path: Mapped[str | None] = mapped_column(String(length=1000), default="")
+
+ roms: Mapped[list["Rom"]] = relationship(back_populates="platform")
+
+ created_at: Mapped[datetime] = mapped_column(
+ DateTime(timezone=True), server_default=func.now()
+ )
+ updated_at: Mapped[datetime] = mapped_column(
+ DateTime(timezone=True), server_default=func.now(), onupdate=func.now()
+ )
+
+ # This runs a subquery to get the count of roms for the platform
+ rom_count = column_property(
+ select(func.count(Rom.id)).where(Rom.platform_id == id).scalar_subquery()
+ )
+
+ def __repr__(self) -> str:
+ return self.name
diff --git a/frontend/src/components/common/Navigation/CollectionsDrawer.vue b/frontend/src/components/common/Navigation/CollectionsDrawer.vue
index 12417284b..a09f11fd8 100644
--- a/frontend/src/components/common/Navigation/CollectionsDrawer.vue
+++ b/frontend/src/components/common/Navigation/CollectionsDrawer.vue
@@ -1,12 +1,20 @@
+
+
+
+ Add Collection
+
+
+
+
+
+
diff --git a/frontend/src/components/common/Navigation/PlatformsDrawer.vue b/frontend/src/components/common/Navigation/PlatformsDrawer.vue
index cbb1dc3b1..26c4bfff2 100644
--- a/frontend/src/components/common/Navigation/PlatformsDrawer.vue
+++ b/frontend/src/components/common/Navigation/PlatformsDrawer.vue
@@ -1,27 +1,52 @@
+
+
+
+
+
+
+
{
+ return {
+ all: [
+ {
+ name: "Favourites",
+ description: "My favourites collection",
+ rom_count: 10,
+ id: 3,
+ },
+ {
+ name: "Nintendo",
+ description: "Nintendo collection",
+ rom_count: 7,
+ id: 1,
+ },
+ {
+ name: "Sony",
+ description: "Sony collection",
+ rom_count: 20,
+ id: 2,
+ },
+ {
+ name: "Sega",
+ description: "Sega collection",
+ rom_count: 0,
+ id: 2,
+ },
+ {
+ name: "Favourites",
+ description: "My favourites collection",
+ rom_count: 10,
+ id: 0,
+ },
+ {
+ name: "Nintendo",
+ description: "Nintendo collection",
+ rom_count: 7,
+ id: 1,
+ },
+ {
+ name: "Sony",
+ description: "Sony collection",
+ rom_count: 20,
+ id: 2,
+ },
+ {
+ name: "Sega",
+ description: "Sega collection",
+ rom_count: 0,
+ id: 2,
+ },
+ {
+ name: "Favourites",
+ description: "My favourites collection",
+ rom_count: 10,
+ id: 0,
+ },
+ {
+ name: "Nintendo",
+ description: "Nintendo collection",
+ rom_count: 7,
+ id: 1,
+ },
+ {
+ name: "Sony",
+ description: "Sony collection",
+ rom_count: 20,
+ id: 2,
+ },
+ {
+ name: "Sega",
+ description: "Sega collection",
+ rom_count: 0,
+ id: 2,
+ },
+ {
+ name: "Favourites",
+ description: "My favourites collection",
+ rom_count: 10,
+ id: 0,
+ },
+ {
+ name: "Nintendo",
+ description: "Nintendo collection",
+ rom_count: 7,
+ id: 1,
+ },
+ {
+ name: "Sony",
+ description: "Sony collection",
+ rom_count: 20,
+ id: 2,
+ },
+ {
+ name: "Sega",
+ description: "Sega collection",
+ rom_count: 0,
+ id: 2,
+ },
+ ] as Collection[],
+ searchText: "" as string,
+ };
+ },
+ getters: {
+ totalGames: ({ all: value }) =>
+ value.reduce((count, p) => count + p.rom_count, 0),
+ filledCollections: ({ all }) => all.filter((p) => p.rom_count > 0),
+ filteredCollections: ({ all, searchText }) =>
+ all.filter(
+ (p) =>
+ p.rom_count > 0 &&
+ p.name.toLowerCase().includes(searchText.toLowerCase()),
+ ),
+ },
+ actions: {
+ _reorder() {
+ this.all = this.all.sort((a, b) => {
+ return a.name.localeCompare(b.name);
+ });
+ this.all = uniqBy(this.all, "id");
+ },
+ set(collections: Collection[]) {
+ this.all = collections;
+ },
+ add(collection: Collection) {
+ this.all.push(collection);
+ // this._reorder();
+ },
+ exists(collection: Collection) {
+ return this.all.filter((p) => p.fs_slug == collection.fs_slug).length > 0;
+ },
+ remove(collection: Collection) {
+ this.all = this.all.filter((p) => {
+ return p.slug !== collection.slug;
+ });
+ },
+ get(collectionId: number) {
+ return this.all.find((p) => p.id === collectionId);
+ },
+ },
+});
diff --git a/frontend/src/stores/platforms.ts b/frontend/src/stores/platforms.ts
index ef12e23ff..6df4aac3e 100644
--- a/frontend/src/stores/platforms.ts
+++ b/frontend/src/stores/platforms.ts
@@ -7,38 +7,45 @@ export type Platform = PlatformSchema;
export default defineStore("platforms", {
state: () => {
return {
- value: [] as Platform[],
+ all: [] as Platform[],
+ searchText: "" as string,
};
},
getters: {
- totalGames: ({ value }) =>
+ totalGames: ({ all: value }) =>
value.reduce((count, p) => count + p.rom_count, 0),
- filledPlatforms: ({ value }) => value.filter((p) => p.rom_count > 0),
+ filledPlatforms: ({ all }) => all.filter((p) => p.rom_count > 0),
+ filteredPlatforms: ({ all, searchText }) =>
+ all.filter(
+ (p) =>
+ p.rom_count > 0 &&
+ p.name.toLowerCase().includes(searchText.toLowerCase()),
+ ),
},
actions: {
_reorder() {
- this.value = this.value.sort((a, b) => {
+ this.all = this.all.sort((a, b) => {
return a.name.localeCompare(b.name);
});
- this.value = uniqBy(this.value, "id");
+ this.all = uniqBy(this.all, "id");
},
set(platforms: Platform[]) {
- this.value = platforms;
+ this.all = platforms;
},
add(platform: Platform) {
- this.value.push(platform);
+ this.all.push(platform);
this._reorder();
},
exists(platform: Platform) {
- return this.value.filter((p) => p.fs_slug == platform.fs_slug).length > 0;
+ return this.all.filter((p) => p.fs_slug == platform.fs_slug).length > 0;
},
remove(platform: Platform) {
- this.value = this.value.filter((p) => {
+ this.all = this.all.filter((p) => {
return p.slug !== platform.slug;
});
},
get(platformId: number) {
- return this.value.find((p) => p.id === platformId);
+ return this.all.find((p) => p.id === platformId);
},
},
});
diff --git a/frontend/src/views/Gallery/Collection.vue b/frontend/src/views/Gallery/Collection.vue
index 4fdcfca38..c39277cdf 100644
--- a/frontend/src/views/Gallery/Collection.vue
+++ b/frontend/src/views/Gallery/Collection.vue
@@ -215,12 +215,13 @@ onMounted(async () => {
} else {
romsStore.setCurrentPlatform(routePlatform);
}
- resetGallery();
- await fetchRoms();
- setFilters();
-
- window.addEventListener("wheel", onScroll);
- window.addEventListener("scroll", onScroll);
+ if (!noPlatformError.value) {
+ resetGallery();
+ await fetchRoms();
+ setFilters();
+ window.addEventListener("wheel", onScroll);
+ window.addEventListener("scroll", onScroll);
+ }
});
onBeforeRouteUpdate(async (to, from) => {
diff --git a/frontend/src/views/Gallery/Platform.vue b/frontend/src/views/Gallery/Platform.vue
index 13999e211..4977a83d8 100644
--- a/frontend/src/views/Gallery/Platform.vue
+++ b/frontend/src/views/Gallery/Platform.vue
@@ -215,12 +215,14 @@ onMounted(async () => {
} else {
romsStore.setCurrentPlatform(routePlatform);
}
- resetGallery();
- await fetchRoms();
- setFilters();
- window.addEventListener("wheel", onScroll);
- window.addEventListener("scroll", onScroll);
+ if (!noPlatformError.value) {
+ resetGallery();
+ await fetchRoms();
+ setFilters();
+ window.addEventListener("wheel", onScroll);
+ window.addEventListener("scroll", onScroll);
+ }
});
onBeforeRouteUpdate(async (to, from) => {
diff --git a/frontend/src/views/Scan.vue b/frontend/src/views/Scan.vue
index c6e2c396d..fc59ee88a 100644
--- a/frontend/src/views/Scan.vue
+++ b/frontend/src/views/Scan.vue
@@ -107,7 +107,7 @@ async function stopScan() {
v-model="platformsToScan"
label="Platforms"
item-title="name"
- :items="platforms.value"
+ :items="platforms.all"
variant="outlined"
density="comfortable"
multiple