Add new API endpoints for media retrieval by country and enhance configuration
Some checks failed
Test Suite / test (push) Has been cancelled

- Introduced `/api/tmdb` and `/api/collection/missing-locations` endpoints to the backend for improved media management.
- Added a new `get_media_by_country` function in the collection API to fetch media items based on country codes.
- Updated configuration to allow overriding *arr base URLs via environment variables for better flexibility.
- Enhanced frontend with a new `MissingLocations` component and integrated it into the routing structure.
- Improved the `CollectionMap` component to handle country selection and display media items accordingly.
- Added testing dependencies in `requirements.txt` and updated frontend configuration for testing support.
This commit is contained in:
Danilo Reyes
2025-12-28 22:35:06 -06:00
parent 4caba81599
commit 2b1a92fb49
32 changed files with 2733 additions and 76 deletions

View File

@@ -1,7 +1,8 @@
"""Collection API endpoints"""
from fastapi import APIRouter, Query
from fastapi import APIRouter, Query, HTTPException
from typing import List, Optional
import json
from app.core.database import init_db, pool as db_pool
router = APIRouter()
@@ -61,3 +62,70 @@ async def get_collection_summary(
return result
@router.get("/by-country")
async def get_media_by_country(
country_code: str = Query(..., description="ISO 3166-1 alpha-2 country code"),
types: Optional[str] = Query(None, description="Comma-separated list: movie,show,music")
):
"""
Get list of media items for a specific country.
Returns media items with their details.
"""
await init_db()
if db_pool is None:
raise HTTPException(status_code=503, detail="Database not available")
# Validate country code
if len(country_code) != 2 or not country_code.isalpha():
raise HTTPException(status_code=400, detail="Country code must be 2 letters (ISO 3166-1 alpha-2)")
country_code = country_code.upper()
# Parse types filter
type_filter = []
if types:
type_filter = [t.strip() for t in types.split(",") if t.strip() in ["movie", "show", "music"]]
async with db_pool.connection() as conn:
async with conn.cursor() as cur:
query = """
SELECT
mi.id,
mi.source_kind,
mi.source_item_id,
mi.title,
mi.year,
mi.media_type
FROM moviemap.media_country mc
JOIN moviemap.media_item mi ON mc.media_item_id = mi.id
WHERE mc.country_code = %s
"""
params = [country_code]
if type_filter:
query += " AND mi.media_type = ANY(%s)"
params.append(type_filter)
query += " ORDER BY mi.title"
await cur.execute(query, params)
rows = await cur.fetchall()
items = []
for row in rows:
items.append({
"id": str(row[0]),
"source_kind": row[1],
"source_item_id": row[2],
"title": row[3],
"year": row[4],
"media_type": row[5],
})
return {
"country_code": country_code,
"count": len(items),
"items": items
}