feat(backend): add a user favorites route

This commit is contained in:
Kentai Radiquum 2024-05-01 12:01:34 +05:00
parent f535d09e97
commit 332e1d1918
Signed by: Radiquum
GPG key ID: 858E8EE696525EED
4 changed files with 40 additions and 0 deletions

View file

@ -2,6 +2,7 @@ import uvicorn
from fastapi import FastAPI from fastapi import FastAPI
from modules import proxy from modules import proxy
from modules.pages import bookmarks from modules.pages import bookmarks
from modules.pages import favorites
from modules.pages import index from modules.pages import index
from modules.pages import search from modules.pages import search
from modules.release import release from modules.release import release
@ -25,6 +26,10 @@ TAGS = [
"name": "Bookmarks", "name": "Bookmarks",
"description": "Bookmarks API requests", "description": "Bookmarks API requests",
}, },
{
"name": "Favorites",
"description": "Favorites API requests",
},
{ {
"name": "Search", "name": "Search",
"description": "Search API requests", "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(index.router, prefix="/api/index", tags=["Index"])
app.include_router(bookmarks.router, prefix="/api/bookmarks", tags=["Bookmarks"]) 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(search.router, prefix="/api/search", tags=["Search"])
app.include_router(proxy.router, prefix="/api/proxy") app.include_router(proxy.router, prefix="/api/proxy")

View file

@ -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}",
)

View file

@ -33,6 +33,7 @@ ENDPOINTS: Endpoints = {
"watched": f"{API_URL}/profile/list/all/3", "watched": f"{API_URL}/profile/list/all/3",
"delayed": f"{API_URL}/profile/list/all/4", "delayed": f"{API_URL}/profile/list/all/4",
"abandoned": f"{API_URL}/profile/list/all/5", "abandoned": f"{API_URL}/profile/list/all/5",
"favorite": f"{API_URL}/favorite",
}, },
"search": f"{API_URL}/search/releases", "search": f"{API_URL}/search/releases",
"statistic": { "statistic": {