From 86aae89f153866d9cc4a64fdc52a026f6e1050b5 Mon Sep 17 00:00:00 2001 From: SaraVieira Date: Fri, 30 Aug 2024 11:21:18 +0100 Subject: [PATCH 1/9] feat - Allow user to unmatch rom --- backend/endpoints/rom.py | 27 ++++++++++++++++++- .../components/common/Game/Dialog/EditRom.vue | 12 +++++++-- frontend/src/services/api/rom.ts | 8 +++++- 3 files changed, 43 insertions(+), 4 deletions(-) diff --git a/backend/endpoints/rom.py b/backend/endpoints/rom.py index 1d5eacb6c..62bbd6681 100644 --- a/backend/endpoints/rom.py +++ b/backend/endpoints/rom.py @@ -286,6 +286,7 @@ async def update_rom( rename_as_source: bool = False, remove_cover: bool = False, artwork: UploadFile | None = None, + unmatch: bool = False ) -> DetailedRomSchema: """Update rom endpoint @@ -294,6 +295,7 @@ async def update_rom( id (Rom): Rom internal id rename_as_source (bool, optional): Flag to rename rom file as matched IGDB game. Defaults to False. artwork (UploadFile, optional): Custom artork to set as cover. Defaults to File(None). + unmatch: Weather to remove the match for this game. Defaults to false Raises: HTTPException: If a rom already have that name when enabling the rename_as_source flag @@ -308,6 +310,29 @@ async def update_rom( if not rom: raise RomNotFoundInDatabaseException(id) + + if(unmatch): + cleaned_data = { + "igdb_id": None, + "sgdb_id": None, + "moby_id": None, + "name": rom.file_name, + "summary": "", + "url_screenshots": {}, + "path_cover_s": "", + "path_cover_l": "", + "url_cover": "", + "slug": "", + "igdb_metadata": {}, + "moby_metadata": {}, + "revision": "", + } + + db_rom_handler.update_rom(id, cleaned_data) + + return DetailedRomSchema.from_orm_with_request(db_rom_handler.get_rom(id), request) + + cleaned_data = { "igdb_id": data.get("igdb_id", None), @@ -423,7 +448,7 @@ async def update_rom( cleaned_data.update( {"path_cover_s": path_cover_s, "path_cover_l": path_cover_l} ) - + db_rom_handler.update_rom(id, cleaned_data) return DetailedRomSchema.from_orm_with_request(db_rom_handler.get_rom(id), request) diff --git a/frontend/src/components/common/Game/Dialog/EditRom.vue b/frontend/src/components/common/Game/Dialog/EditRom.vue index d81bcaac7..a437ea24d 100644 --- a/frontend/src/components/common/Game/Dialog/EditRom.vue +++ b/frontend/src/components/common/Game/Dialog/EditRom.vue @@ -55,7 +55,7 @@ async function removeArtwork() { removeCover.value = true; } -async function updateRom() { +async function updateRom({ unmatch }: { unmatch?: boolean } = {}) { if (!rom.value) return; if (!rom.value.file_name) { @@ -71,7 +71,7 @@ async function updateRom() { emitter?.emit("showLoadingDialog", { loading: true, scrim: true }); await romApi - .updateRom({ rom: rom.value, removeCover: removeCover.value }) + .updateRom({ rom: rom.value, removeCover: removeCover.value, unmatch }) .then(({ data }) => { emitter?.emit("snackbarShow", { msg: "Rom updated successfully!", @@ -214,6 +214,14 @@ function closeDialog() {