-
Notifications
You must be signed in to change notification settings - Fork 27
refactor(server): extract the wishlist routes into routers/wanted.py (R3) #847
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,45 @@ | ||
| """Wishlist / "wanted" API (feedBack#636) — songs the user wants but doesn't own. | ||
|
|
||
| Extracted verbatim from ``server.py`` (R3); edits: ``@app`` -> ``@router``, | ||
| ``meta_db`` -> ``appstate.meta_db``, ``_clean_str`` from ``reqfields``. | ||
| """ | ||
|
|
||
| from fastapi import APIRouter | ||
| from fastapi.responses import JSONResponse | ||
|
|
||
| import appstate | ||
| from reqfields import _clean_str | ||
|
|
||
| router = APIRouter() | ||
|
|
||
|
|
||
| @router.get("/api/wanted") | ||
| def api_list_wanted(): | ||
| """The wishlist — songs the user wants but doesn't own yet (newest first).""" | ||
| return {"wanted": appstate.meta_db.list_wanted()} | ||
|
|
||
|
|
||
| @router.post("/api/wanted") | ||
| def api_add_wanted(data: dict): | ||
| """Add a not-owned song to the wishlist. `artist`/`title` are required (at | ||
| least one non-empty); `source`/`source_ref`/`note` are optional. Idempotent | ||
| on identity so producers (find_more ownership-diff, manual add) can re-post.""" | ||
| if not isinstance(data, dict): | ||
| return JSONResponse({"error": "body must be an object"}, status_code=400) | ||
| artist = _clean_str(data.get("artist")) | ||
| title = _clean_str(data.get("title")) | ||
| if not artist and not title: | ||
| return JSONResponse({"error": "artist or title required"}, status_code=400) | ||
| row = appstate.meta_db.add_wanted( | ||
| artist=artist, title=title, | ||
| source=_clean_str(data.get("source")) or "manual", | ||
| source_ref=_clean_str(data.get("source_ref")), | ||
| note=_clean_str(data.get("note")), | ||
| ) | ||
| return {"ok": True, "wanted": row} | ||
|
|
||
|
|
||
| @router.delete("/api/wanted/{wanted_id}") | ||
| def api_remove_wanted(wanted_id: int): | ||
| """Remove a wishlist entry by id.""" | ||
| return {"ok": appstate.meta_db.remove_wanted(wanted_id)} | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.