You are inheriting a partially implemented API application using Django and the Django REST Framework plugin. It's a community driven site where anyone can add a restaurant to the system, and adds meals to restaurants.
Think of a very small scale Zomato or Yelp style service.
After implementing the features for this application, you should know that verbs in the URL can be implemented with the @action
decorator on a method in a ViewSet.
After implementing the features for this application, you should know the difference between properties on models that get their values from the database, and custom properties that get their values from the logic in a ViewSet.
- You should be able to identify a custom model property.
- You should be able to understand that a custom model property is used to define properties on model instances that do not get their values from the database.
- You should be able to implement a custom property on a database model.
- You should be able to assign a value to a custom property in the logic of a ViewSet.
- You should be able to identify a custom action on a ViewSet.
- You should be able to understand when a custom action is needed on a ViewSet.
- You should be able to know how to specify that a custom action is for an individual resource, and not the collection of resources.
- You should be able to know how to specify which HTTP methods a custom action will support.
- Clone the repository to a directory of your choosing.
- Start the virtual environment with
pipenv shell
- Start the API with
python manage.py runserver
- Open Postman and verify that the current functionality (list below) works.
The current functionality includes the following actions.
Restaurant entries are not tied to a user. Once a restaurant has been added by any user, another user cannot enter it again.
- POST a new restaurant
- GET a single restaurant
- GET all restaurants
Meal entries are not tied to a user. Once a restaurant meal has been added by any user, another user cannot enter it again.
- POST a new meal assigned to a restaurant
- GET a single meal
- GET all meals
Users should be able to mark a restaurant as a favorite, and also remove that choice.
Method | URL |
---|---|
POST | http://localhost:8080/restaurants/1/star |
DELETE | http://localhost:8080/restaurants/1/star |
When the client requests all restaurants, or a single restaurant, each JSON representation of a restaurant should have a favorite
property. The value of the property must be true
if the current user has marked it as a favorite, and false
if the user hasn't.
Users should be able to mark a meal as a favorite, and also remove that choice.
Method | URL |
---|---|
POST | http://localhost:8080/meals/1/star |
DELETE | http://localhost:8080/meals/1/star |
When the client requests all meals, or a single meal, each JSON representation of a meal should have a favorite
property. The value of the property must be true
if the current user has marked it as a favorite, and false
if the user hasn't.
Users should be able to rate a meal on a scale of 1 to 10, and also update that rating.
Method | URL |
---|---|
POST | http://localhost:8080/meals/1/rate |
PUT | http://localhost:8080/meals/1/rate |
{
"rating": 3
}
When the client requests all meals, or a single meal, each JSON representation of a meal should have a rating
property. The value of the property must be the current user rating if the current user has rated it, and 0 if the user hasn't.
When the client requests all meals, or a single meal, each JSON representation of a meal should have an avg_rating
property. The value of the property must be the average of all user ratings for the meal.