From 332e1d1918846bfd125c596c942f79185cb8b98d Mon Sep 17 00:00:00 2001 From: Kentai Radiquum Date: Wed, 1 May 2024 12:01:34 +0500 Subject: [PATCH] feat(backend): add a user favorites route --- backend/main.py | 6 ++++++ backend/modules/models/__init__.py | 0 backend/modules/pages/favorites.py | 33 ++++++++++++++++++++++++++++++ backend/modules/proxy.py | 1 + 4 files changed, 40 insertions(+) delete mode 100644 backend/modules/models/__init__.py create mode 100644 backend/modules/pages/favorites.py diff --git a/backend/main.py b/backend/main.py index 791cb0e..a777c62 100644 --- a/backend/main.py +++ b/backend/main.py @@ -2,6 +2,7 @@ import uvicorn from fastapi import FastAPI from modules import proxy from modules.pages import bookmarks +from modules.pages import favorites from modules.pages import index from modules.pages import search from modules.release import release @@ -25,6 +26,10 @@ TAGS = [ "name": "Bookmarks", "description": "Bookmarks API requests", }, + { + "name": "Favorites", + "description": "Favorites API requests", + }, { "name": "Search", "description": "Search API requests", @@ -47,6 +52,7 @@ app.include_router(release.router, prefix="/api/release", tags=["Releases"]) app.include_router(index.router, prefix="/api/index", tags=["Index"]) app.include_router(bookmarks.router, prefix="/api/bookmarks", tags=["Bookmarks"]) +app.include_router(favorites.router, prefix="/api/favorites", tags=["Favorites"]) app.include_router(search.router, prefix="/api/search", tags=["Search"]) app.include_router(proxy.router, prefix="/api/proxy") diff --git a/backend/modules/models/__init__.py b/backend/modules/models/__init__.py deleted file mode 100644 index e69de29..0000000 diff --git a/backend/modules/pages/favorites.py b/backend/modules/pages/favorites.py new file mode 100644 index 0000000..68c3dde --- /dev/null +++ b/backend/modules/pages/favorites.py @@ -0,0 +1,33 @@ +from fastapi import APIRouter +from fastapi import Request +from modules.proxy import apiRequest +from modules.proxy import ENDPOINTS + +router = APIRouter() + + +@router.get("", summary="Get user favorites list") +async def GetUserFavorites(request: Request, token: str, page: int = 0): + return await apiRequest( + request, ENDPOINTS["user"]["favorite"], f"/all/{page}", query=f"?token={token}" + ) + + +@router.get("/list/{release_id}/add", summary="Add release to user favorites") +async def addReleaseToFavorites(request: Request, release_id: int, token: str): + return await apiRequest( + request, + ENDPOINTS["user"]["favorite"], + f"/add/{release_id}", + query=f"?token={token}", + ) + + +@router.get("/list/{release_id}/delete", summary="Remove release from user favorites") +async def deleteReleaseFromFavorites(request: Request, release_id: int, token: str): + return await apiRequest( + request, + ENDPOINTS["user"]["favorite"], + f"/delete/{release_id}", + query=f"?token={token}", + ) diff --git a/backend/modules/proxy.py b/backend/modules/proxy.py index 43c2c44..bccf61e 100644 --- a/backend/modules/proxy.py +++ b/backend/modules/proxy.py @@ -33,6 +33,7 @@ ENDPOINTS: Endpoints = { "watched": f"{API_URL}/profile/list/all/3", "delayed": f"{API_URL}/profile/list/all/4", "abandoned": f"{API_URL}/profile/list/all/5", + "favorite": f"{API_URL}/favorite", }, "search": f"{API_URL}/search/releases", "statistic": {