change /movies output format for id filtered listing
The new format is much closer to the format used by /groups/ratings. Also allows to filter based on Unwind's ID.
This commit is contained in:
parent
a468c8ad60
commit
32bbfe881b
2 changed files with 38 additions and 5 deletions
|
|
@ -2,7 +2,7 @@ from starlette.testclient import TestClient
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
from unwind import create_app
|
from unwind import create_app
|
||||||
from unwind import db, models
|
from unwind import db, models, imdb
|
||||||
|
|
||||||
pytestmark = pytest.mark.asyncio
|
pytestmark = pytest.mark.asyncio
|
||||||
|
|
||||||
|
|
@ -38,8 +38,24 @@ async def test_app():
|
||||||
assert response.status_code == 200
|
assert response.status_code == 200
|
||||||
assert response.json() == [{**db.asplain(m), "user_scores": []}]
|
assert response.json() == [{**db.asplain(m), "user_scores": []}]
|
||||||
|
|
||||||
|
m_plain = {
|
||||||
|
"unwind_id": m.id,
|
||||||
|
"canonical_title": m.title,
|
||||||
|
"imdb_score": m.imdb_score,
|
||||||
|
"imdb_votes": m.imdb_votes,
|
||||||
|
"link": imdb.movie_url(m.imdb_id),
|
||||||
|
"media_type": m.media_type,
|
||||||
|
"original_title": m.original_title,
|
||||||
|
"user_scores": [],
|
||||||
|
"year": m.release_year,
|
||||||
|
}
|
||||||
|
|
||||||
response = client.get("/api/v1/movies", params={"imdb_id": m.imdb_id})
|
response = client.get("/api/v1/movies", params={"imdb_id": m.imdb_id})
|
||||||
assert response.status_code == 200
|
assert response.status_code == 200
|
||||||
assert response.json() == [db.asplain(m)]
|
assert response.json() == [m_plain]
|
||||||
|
|
||||||
|
response = client.get("/api/v1/movies", params={"unwind_id": str(m.id)})
|
||||||
|
assert response.status_code == 200
|
||||||
|
assert response.json() == [m_plain]
|
||||||
|
|
||||||
await db.close_connection_pool()
|
await db.close_connection_pool()
|
||||||
|
|
|
||||||
|
|
@ -283,10 +283,27 @@ async def list_movies(request):
|
||||||
|
|
||||||
user_ids |= {user_id}
|
user_ids |= {user_id}
|
||||||
|
|
||||||
if imdb_id := params.get("imdb_id"):
|
imdb_id = params.get("imdb_id")
|
||||||
|
unwind_id = params.get("unwind_id")
|
||||||
|
|
||||||
|
if imdb_id or unwind_id:
|
||||||
# XXX missing support for user_ids and user_scores
|
# XXX missing support for user_ids and user_scores
|
||||||
movies = [await db.get(Movie, imdb_id=imdb_id)]
|
movies = [await db.get(Movie, id=unwind_id, imdb_id=imdb_id)]
|
||||||
resp = [asplain(m) for m in movies]
|
|
||||||
|
resp = [
|
||||||
|
{
|
||||||
|
"unwind_id": m["id"],
|
||||||
|
"canonical_title": m["title"],
|
||||||
|
"imdb_score": m["imdb_score"],
|
||||||
|
"imdb_votes": m["imdb_votes"],
|
||||||
|
"link": imdb.movie_url(m["imdb_id"]),
|
||||||
|
"media_type": m["media_type"],
|
||||||
|
"original_title": m["original_title"],
|
||||||
|
"user_scores": [],
|
||||||
|
"year": m["release_year"],
|
||||||
|
}
|
||||||
|
for m in map(asplain, movies)
|
||||||
|
]
|
||||||
|
|
||||||
else:
|
else:
|
||||||
per_page = as_int(params.get("per_page"), max=1000, default=5)
|
per_page = as_int(params.get("per_page"), max=1000, default=5)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue