Skip to content

Repository files navigation

Markdown

🛡️ Warranty Management — REST API

Python Django Django REST Framework PostgreSQL JWT License

A robust RESTful API built with Python and Django REST Framework, designed for efficient and centralized management of product warranties, expiration deadlines, and asset categories.


📌 Overview & Best Practices

This repository contains the implementation of the Warranty Management API. The project was structured following best development practices in Django and Django REST Framework, focusing on maintainability, testability, and a clear separation of concerns.


📐 Architecture & Adopted Patterns

The development of this system is guided by the strictest standards of modern software engineering:

  • PEP 8 Compliance: All code strictly adheres to the official Python style guide. Code quality, formatting, and typing are enforced using Pylint and django-stubs.
  • SOLID Principles:
    • Single Responsibility (SRP): Clear separation of concerns between models (models.py), serializers (serializers.py), view logic, and environment configurations.
    • Open/Closed (OCP): Architecture open for extension and closed for modification through Django REST Framework's extensible ecosystem.
    • Liskov Substitution (LSP): Utilization of standard DRF abstractions (ModelSerializer, ModelViewSet) ensuring consistent API contracts.
    • Interface Segregation (ISP): Lean Serializers and DTOs with selective field exposure (fields, read_only_fields).
    • Dependency Inversion (DIP): Inversion of control and dependency injection managed by Django ORM's data access container.
  • DRY (Don't Repeat Yourself): Encapsulation of complex business logic through dynamic computed properties directly in models (data_vencimento_garantia, garantia_vigente).
  • Information Security & DevSecOps:
    • Complete decoupling of credentials and sensitive keys via environment variables (python-decouple).
    • Secure Stateless authentication via JWT (JSON Web Tokens) with Access and Refresh key pairs.
    • Environment configuration and database secrets isolated outside version control using .env.

🛠️ Tech Stack

  • Language: Python 3.12+
  • Core Framework: Django 6.0
  • API Toolkit: Django REST Framework (DRF)
  • Authentication: djangorestframework-simplejwt
  • Database: PostgreSQL
  • Admin Panel: Django-Jazzmin (Modern & Responsive UI)
  • Environment Management: python-decouple
  • Code Quality: Pylint, Isort, Type-hinting (django-stubs)

⚙️ Environment Setup (.env)

For security reasons, the .env file must never be committed to version control. Create a .env file in the root directory based on the provided .env.example:

# PostgreSQL Database Configuration
DB_NAME=garantias_db
DB_USER=postgres
DB_PASSWORD=your_secure_password
DB_HOST=localhost
DB_PORT=5432

# Django Secret Key
SECRET_KEY=your_super_secret_key
🚀 Installation & Setup
1. Clone the Repository
Bash
git clone [https://github.com/your-username/warranty-management-api.git](https://github.com/your-username/warranty-management-api.git)
cd warranty-management-api
2. Create and Activate Virtual Environment (venv)
Bash
# Linux/macOS
python3 -m venv venv
source venv/bin/activate

# Windows (PowerShell)
python -m venv venv
.\venv\Scripts\Activate.ps1
3. Install Dependencies
Bash
pip install -r requirements.txt
4. Run Database Migrations
Bash
python manage.py migrate
5. Create Superuser (Admin)
Bash
python manage.py createsuperuser
6. Start the Development Server
Bash
python manage.py runserver
Access the Jazzmin administrative dashboard at: http://localhost:8000/admin/

🔑 API Endpoints
JWT Authentication
POST /api/token/ — Obtain Access and Refresh tokens.

POST /api/token/refresh/ — Refresh an expired access token.

Category Management
GET /api/categorias/ — List all categories.

POST /api/categorias/ — Create a new category.

GET /api/categorias/{id}/ — Category details.

PUT / PATCH /api/categorias/{id}/ — Update category.

DELETE /api/categorias/{id}/ — Delete category.

Product & Warranty Management
GET /api/produtos/ — List all products.

POST /api/produtos/ — Register a new product with warranty.

GET /api/produtos/{id}/ — Product details.

PUT / PATCH /api/produtos/{id}/ — Update product details.

DELETE /api/produtos/{id}/ — Delete product.

🧪 Usage Examples via HTTP Requests
1. Obtain JWT Token (PowerShell)
PowerShell
Invoke-RestMethod -Uri "http://localhost:8000/api/token/" -Method Post -ContentType "application/json" -Body '{"username": "admin", "password": "your_password"}'
2. Fetch Authenticated Products (cURL)
Bash
curl -X GET http://localhost:8000/api/produtos/ \
     -H "Authorization: Bearer YOUR_ACCESS_TOKEN_HERE"
📄 License
This project is licensed under the MIT License. See the LICENSE file for details.

About

RESTful API for centralized product warranty management. Built with Python, Django REST Framework, PostgreSQL, and JWT, following SOLID principles, PEP 8, and clean architecture.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages