Skip to content

Technical Test - CRUD with Django and Django Rest Framework

Notifications You must be signed in to change notification settings

Arkemix30/api-django-drf-test

Repository files navigation

Spot Test with Django

Solutions Implemented 💡

  • An endpoint to provide a search lookup within the tracks (at least by name, but is open to any suggestions)
    • Solution: Created a ListAPIView to get a list of all tracks that matches with the query parameters in the url. In this case you can filter by name and artistName. Using Raw SQL queries *Endpoint example: /api/tracks/?name={name}
  • An endpoint that would allow to get the top 50 popularity tracks.
    • Solution: Created another ListAPIView class to get the list of most popular tracks, order by rank field. Using Raw SQL queries
    • Endpoint example: /api/tracks/most_popular
  • An endpoint to remove a track, using a given identifier (defined by you)
    • Solution: Created a RetrieveUpdateDestroyAPIView that you can delete a track using the DELETE http method, passing the id of the track.
    • You need to register and be logged in to remove or update a track. /api/auth/register or /api/auth/login/
    • Endpoint example: api/tracks/{id}/
  • An endpoint to add new tracks using ORM.
    • Solution: Created a CreateAPIView that recieves the data, deserialize it and save it if data is valid.
    • You need to register and be logged in to create a track.
    • Endpoint example: api/tracks/create/
  • Extra: There's an entire CRUD for Genres model, you can access at the endpoint: api/genres/
    • You need to register and be logged in.

Bonus:

  • Use a Database (suggested: SQLite), instead of the JSON File
  • Add authentication API endpoint(s) with Django Rest Framework (DRF)
    • Created an endpoint: api/auth/register/ using a Serializer with the default Django Auth User Model, that receives username, first_name, last_name, password, re_password (for confirmation). It validates if both password matches. And then saves it into the database.
    • To login, you can use the endpoint: /api/auth/login with you created user.
  • Use SQL instead of ORM only for SELECT queries.
    • Using Raw Queries
  • Create an endpoint to return the tracks grouped by genres
    • Created a ListAPIView class that filters against the URL, using the Django ORM filters by genre name.
    • Endpoint example: api/tracks/genre/{genre}/

Project's Folder Structure

.
├── api             # DRF app folder
    ├── auth
        ├── serializers.py
        └── views.py
    ├── genres
        ├── models.py
        ├── serializers.py
        └── views.py
    ├── migrations
    ├── tracks
        ├── models.py
        ├── serializers.py
        └── views.py
    ├── admin.py
    ├── apps.py
    └── urls.py
├── spot_test       # Django project's folder
├── manage.py
├── poetry.toml     # build configs
├── pyproject.toml  # build configs
└── README.md

How to run the code 🏃‍♂️

Installation 🔧

You will need to install Poetry to install project's dependencies

curl -sSL https://raw.githubusercontent.com/python-poetry/poetry/master/get-poetry.py | python3 -

Locate where Poetry is installed

whereis poetry

Copy and replace poetry's path to this line and added it at the end of the .bashrc file

export PATH="$HOME/.poetry/bin:$PATH"

Installing project's dependencies 📚

Enter into project's root folder and run:

poetry install

It should create a .venv folder, generating a virtual enviroment with all project's dependencies

How to run locally ⚙️

  • Clone the repository
$ git clone https://github.com/Arkemix30/spot-test.git
  • To run the project, you need to activate the virtual environment. For that, you can run this command:
$ poetry shell
  • You have to migrate the model's schema into database, run the next commands:
$ python manage.py makemigrations && python manage.py migrate

(if you have problems, run the commands separately)

  • Then, you should run the following command to insert the dummy data.
$ python manage.py loaddata genres_data.json
$ python manage.py loaddata tracks_data.json
  • And finally, to run the server:
$ python manage.py runserver

Built with 🛠️

Authors ✒️


⌨️ with ❤️ by Arkemix30 😊

About

Technical Test - CRUD with Django and Django Rest Framework

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages