Migrate booknotes endpoint to FastAPI#12007
Conversation
709411a to
a569bcf
Compare
RayBB
left a comment
There was a problem hiding this comment.
Overall, this is a great start. There's a few minor things to fix, and please fix them and then request another review, and please be sure to test thoroughly, but overall I think it looks about right!
|
|
||
|
|
||
| class BooknoteResponse(BaseModel): | ||
| """Response model for booknote POST endpoint.""" |
| except Exception: # noqa: BLE001 | ||
| raise HTTPException( | ||
| status_code=status.HTTP_502_BAD_GATEWAY, | ||
| detail="Error communicating with the database", | ||
| ) |
There was a problem hiding this comment.
We shouldn't need this try except it should be handled automatically by FastAPI.
| - If `notes` is provided: create or update the note. | ||
| - If `notes` is omitted: remove the existing note. | ||
| """ | ||
| from openlibrary.core.models import Booknotes |
There was a problem hiding this comment.
This import needs to be at the top of the file.
| include_in_schema=SHOW_INTERNAL_IN_SCHEMA, | ||
| ) | ||
| async def booknotes_post( | ||
| work_id: str, |
| """ | ||
| from openlibrary.core.models import Booknotes | ||
|
|
||
| numeric_work_id = int(work_id) |
There was a problem hiding this comment.
You don't need to cast it as an int if you make it required as an integer above.
825a384 to
106fbf4
Compare
|
@RayBB
|
RayBB
left a comment
There was a problem hiding this comment.
Sorry for the long delay in reviewing here. You did excellent work. It was a little tricky to test but ultimately I used http://localhost:18080/docs#/internal/booknotes_post_works_OL_work_id_W_notes_post to test several cases and then added them to the test file.
Really appreciate your work and patience on this one!
Closes #11999
Migrates
class booknotes(delegate.page)fromopenlibrary/plugins/openlibrary/api.pyto FastAPI.Technical
POST /works/OL{work_id}W/notesinopenlibrary/fastapi/internal/api.pyrequire_authenticated_userdependency→returns 401 instead of legacy browser redirectredirparam (not applicable for a JSON API)BooknoteResponsePydantic modelTesting
docker compose exec web pytest openlibrary/tests/fastapi/test_booknotes.py -vScreenshot
Stakeholders
@RayBB