Add NixOS VM configuration and new media search endpoint
Some checks failed
Test Suite / test (push) Failing after 45s

- Introduced a new NixOS VM configuration in `flake.nix` for testing purposes.
- Updated CI workflow to build the VM using the flake input for a more streamlined process.
- Added a new API endpoint `/search` in the collection API to search owned media by title, with optional filtering by media type.
- Refactored frontend components to utilize the new media search functionality, updating types and state management accordingly.
- Enhanced CSS for the map component to ensure proper rendering in various layouts.
This commit is contained in:
Danilo Reyes
2025-12-28 23:02:48 -06:00
parent 4709a05ad4
commit 1329958b4e
7 changed files with 125 additions and 20 deletions

View File

@@ -2,7 +2,7 @@
from fastapi import APIRouter, Query, HTTPException
from typing import List, Optional
import json
from app.core.database import init_db, pool as db_pool
from app.core.database import init_db
router = APIRouter()
@@ -73,6 +73,7 @@ async def get_media_by_country(
Returns media items with their details.
"""
await init_db()
from app.core.database import pool as db_pool
if db_pool is None:
raise HTTPException(status_code=503, detail="Database not available")
@@ -129,3 +130,65 @@ async def get_media_by_country(
"items": items
}
@router.get("/search")
async def search_owned_media(
query: str = Query(..., min_length=1, description="Search query (title substring)"),
media_type: Optional[str] = Query(None, description="Filter by media type: movie or show"),
limit: int = Query(10, ge=1, le=50),
):
"""
Search owned media (from your synced Radarr/Sonarr library) by title.
"""
await init_db()
from app.core.database import pool as db_pool
if db_pool is None:
raise HTTPException(status_code=503, detail="Database not available")
mt = None
if media_type is not None:
if media_type not in ["movie", "show"]:
raise HTTPException(status_code=400, detail="media_type must be 'movie' or 'show'")
mt = media_type
like = f"%{query.strip()}%"
async with db_pool.connection() as conn:
async with conn.cursor() as cur:
if mt:
sql = """
SELECT id, title, year, media_type
FROM moviemap.media_item
WHERE media_type = %s
AND title ILIKE %s
ORDER BY title
LIMIT %s
"""
params = (mt, like, limit)
else:
sql = """
SELECT id, title, year, media_type
FROM moviemap.media_item
WHERE media_type = ANY(%s)
AND title ILIKE %s
ORDER BY title
LIMIT %s
"""
params = (["movie", "show"], like, limit)
await cur.execute(sql, params)
rows = await cur.fetchall()
return {
"query": query,
"results": [
{
"id": str(r[0]),
"title": r[1],
"year": r[2],
"media_type": r[3],
}
for r in rows
],
}