← 返回 amazon 的题目列表Debug a Movie DB Watchlist Full-Stack Project
类型:online_judge
Problem: Debug the Watchlist Feature in a Movie DB Full-Stack Project
You are given an existing Movie DB full-stack project. Authenticated users can manage their watchlists and add or remove movies from those watchlists. Currently, 6 unit tests related to watchlist/movie operations are failing. Your task is to inspect and fix the existing code so that those tests pass.
Existing Features
The system supports:
User login
Creating a watchlist
Deleting a watchlist
Updating a watchlist
Adding a movie to a watchlist
Removing a movie from a watchlist
Scenarios to Fix
Make sure the following behaviors work correctly:
A movie can be added to an existing watchlist.
Adding a movie that already exists in the watchlist should return the correct error status code or prevent duplication.
A movie can be removed from a watchlist.
After adding many movies to a watchlist, they can be removed one by one and the database state remains correct.
Adding a movie to a non-existing watchlist should return the correct error status code.
Removing a movie from a non-existing watchlist should return the correct error status code.
Key Points to Check
Whether the watchlist existence is checked correctly.
Whether the movie existence is checked correctly.
Whether duplicate movies are prevented.
Whether a newly added movie is actually persisted to the database.
Whether removing a movie actually removes the association from the database.
Whether the API returns the correct HTTP status code.
Example API Contract
The actual route names may differ in the project, but the semantics are similar:
POST /watchlists/{watchListId}/movies
DELETE /watchlists/{watchListId}/movies/{movieId}
Example Expected Status Codes
| Scenario | Expected Status Code | |---|---| | Movie added successfully | 201 Created or the project's agreed success code | | Movie removed successfully | 200 OK / 204 No Content | | Watchlist does not exist | 404 Not Found | | Movie does not exist | 404 Not Found | | Movie already exists in the watchlist | 409 Conflict or the project's agreed error code |
Fix the implementation according to the existing project conventions instead of changing the tests arbitrarily.
Example
Input
POST /watchlists/1/movies with body {"movieId": 10}; watchlist 1 exists, movie 10 exists, movie 10 is not in the list
Output
201 Created; watchlist 1 now contains movie 10