Skip to content

1r00t/car-management-ninja

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

16 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Django Ninja Car API

A Django Ninja project for managing car information with REST API endpoints for the coding challenge from oneclick AG at https://github.com/oneclick-ag/python-car-management-api-challenge

Table of Contents

Features

  • Swagger Documentation (OpenAPI)

    API documentation is generated using Swagger (OpenAPI) to provide detailed information about available endpoints, request parameters, response formats, and example usage. Explore and interact with the API documentation at http://localhost:8000/cars/docs.

  • Throttling

    Django REST Framework's throttling mechanism is implemented to control the rate of incoming requests. Throttling can be configured in api/settings.py.

  • Pagination

    Pagination is implemented for the GET /cars endpoint and works with limit / offset GET parameters.

  • Admin Panel

    Access the Django admin panel from http://localhost:8000/admin.

  • Unittests

    The project includes comprehensive unit tests to ensure functionality and reliability across all API endpoints. Tests cover input validation, error handling, and expected behavior under various scenarios. Find the unit tests under api/tests/

Installation

  1. Clone the repository:

    git clone https://github.com/1r00t/car-management-ninja.git
    cd car-management-ninja
  2. Set up a virtual environment:

    python3 -m venv env
    source env/bin/activate
  3. Install dependencies:

    pip install -r requirements.txt

Environment Variables

The project uses environment variables to manage settings for development and production environments. By default, it looks for a .env file. You can set the DJANGO_ENV_FILE variable to switch between .env.dev and .env.prod.

  1. Create a .env.dev file for development:

    SECRET_KEY=your_secret_key
    DEBUG=True
    ALLOWED_HOSTS=localhost,127.0.0.1
    DATABASE_URL=sqlite:///db.sqlite3
    NINJA_SKIP_REGISTRY=yes  # https://github.com/vitalik/django-ninja/issues/229
  2. Create a .env.prod file for production:

    SECRET_KEY=your_production_secret_key
    DEBUG=False
    ALLOWED_HOSTS=your_production_domain
    DATABASE_URL=postgres://user:password@hostname/dbname
  3. Export DJANGO_ENV_FILE environment variable:

    export DJANGO_ENV_FILE=.env.dev  # For development
    export DJANGO_ENV_FILE=.env.prod  # For production

Running the Project

  1. Apply database migrations:

    python manage.py migrate
  2. Run the development server:

    python manage.py runserver

Testing

  • Run the test suite with Django

    python manage.py test
  • Or with Pytest

    pytest

Admin Panel

  1. Create a superuser for accessing the admin panel:

    python manage.py createsuperuser
  2. Access the admin panel:

    Open your browser and go to http://localhost:8000/admin/.

    Use the superuser credentials to log in.

About

Car Management API for oneclick AG coding challenge

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages