Skip to content

Anon23261/python-API

Repository files navigation

πŸ”§ Mechanic Shop API πŸš—

Python Flask License Code Style

🏎️ A modern, high-performance RESTful API for managing your auto repair shop operations. Built with Flask and love! πŸ’

✨ Features

πŸ§‘β€πŸ’Ό Customer Management

  • Track customer details and history
  • Seamless CRUD operations
  • Secure data handling
  • Preferred mechanics selection
  • Vehicle ownership tracking

πŸš™ Vehicle Management

  • Comprehensive vehicle tracking
  • Service history logging
  • Multiple vehicles per customer
  • Detailed service records
  • Mileage tracking

πŸ‘¨β€πŸ”§ Mechanic Management

  • Skill tracking and specializations
  • Work schedule management
  • Performance monitoring
  • Tool certifications
  • Customer preferences tracking

πŸ› οΈ Service Management

  • Customizable service catalog
  • Dynamic pricing with parts
  • Service categorization
  • Required tools tracking
  • Parts inventory management

πŸ“‹ Service Tickets

  • Real-time status tracking
  • Detailed service records
  • Automated notifications
  • Cost estimation and tracking
  • Service history integration

πŸ“ Project Structure

πŸ“¦ pthon-API
 ┣ πŸ“‚ app
 ┃ ┣ πŸ“‚ auth                  # Authentication module
 ┃ ┣ πŸ“‚ blueprints           # API blueprints
 ┃ ┃ ┣ πŸ“‚ customers          # Customer management
 ┃ ┃ ┣ πŸ“‚ vehicles           # Vehicle management
 ┃ ┃ ┣ πŸ“‚ services           # Service catalog
 ┃ ┃ ┣ πŸ“‚ mechanics          # Mechanic management
 ┃ ┃ ┣ πŸ“‚ service_tickets    # Service tickets
 ┃ ┃ ┣ πŸ“‚ models             # Common models
 ┃ ┃ β”— πŸ“œ associations.py    # Many-to-many relationships
 ┃ ┣ πŸ“‚ common               # Common utilities
 ┃ ┃ ┣ πŸ“œ models.py         # Base model class
 ┃ ┃ β”— πŸ“œ utils.py          # Utility functions
 ┃ ┣ πŸ“œ extensions.py        # Flask extensions
 ┃ β”— πŸ“œ __init__.py         # App initialization
 ┣ πŸ“œ wsgi.py               # Application entry point
 ┣ πŸ“œ config.py             # Configuration
 ┣ πŸ“œ requirements.txt      # Dependencies
 β”— πŸ“œ README.md             # Documentation

πŸ”„ Database Relationships

Many-to-Many Relationships

  • Mechanic-Specialization: Mechanics can have multiple specializations
  • Service-Parts: Services require multiple parts with quantities
  • Vehicle-Service History: Tracks services performed on vehicles
  • Customer-Preferred Mechanics: Customers can have preferred mechanics
  • Service-Required Tools: Services require specific tools
  • Mechanic-Tool Certifications: Mechanics are certified for specific tools

One-to-Many Relationships

  • Customer -> Vehicles
  • Customer -> Service Tickets
  • Vehicle -> Service Tickets
  • Mechanic -> Service Tickets
  • Service -> Service Tickets

πŸš€ Getting Started

Prerequisites

  • Python 3.9+
  • pip (Python package manager)
  • Virtual environment (recommended)
  • SQLite (default) or PostgreSQL

Installation

  1. Clone the repository
git clone https://github.com/yourusername/mechanic-shop-api.git
cd mechanic-shop-api
  1. Create and activate a virtual environment
python -m venv venv
source venv/bin/activate  # On Windows: .\venv\Scripts\activate
  1. Install dependencies
pip install -r requirements.txt
  1. Set up environment variables in .env:
FLASK_APP=wsgi.py
FLASK_ENV=development
SECRET_KEY=your-secret-key
DATABASE_URL=sqlite:///app.db
JWT_SECRET_KEY=your-jwt-secret
  1. Initialize the database
flask db init
flask db migrate
flask db upgrade
  1. Run the application
flask run

πŸ” Authentication

The API uses JWT (JSON Web Token) authentication. To access protected endpoints:

  1. Register a new user or login
  2. Use the returned JWT token in the Authorization header:
Authorization: Bearer <your-jwt-token>

πŸ“š API Documentation

Customer Endpoints

Method Endpoint Description Auth Required
POST /auth/register Register new customer ❌
POST /auth/login Login customer ❌
GET /customers List all customers βœ…
GET /customers/<id> Get customer details βœ…
PUT /customers/<id> Update customer βœ…
DELETE /customers/<id> Delete customer βœ…
POST /customers/<id>/preferred-mechanics Add preferred mechanic βœ…

Vehicle Endpoints

Method Endpoint Description Auth Required
GET /vehicles List all vehicles βœ…
POST /vehicles Add new vehicle βœ…
GET /vehicles/<id> Get vehicle details βœ…
PUT /vehicles/<id> Update vehicle βœ…
DELETE /vehicles/<id> Delete vehicle βœ…
GET /vehicles/<id>/service-history Get service history βœ…

Mechanic Endpoints

Method Endpoint Description Auth Required
GET /mechanics List all mechanics βœ…
POST /mechanics Add new mechanic βœ…
GET /mechanics/<id> Get mechanic details βœ…
PUT /mechanics/<id> Update mechanic βœ…
DELETE /mechanics/<id> Delete mechanic βœ…
GET /mechanics/<id>/specializations Get specializations βœ…
POST /mechanics/<id>/certifications Add tool certification βœ…

Service Endpoints

Method Endpoint Description Auth Required
GET /services List all services βœ…
POST /services Add new service βœ…
GET /services/<id> Get service details βœ…
PUT /services/<id> Update service βœ…
DELETE /services/<id> Delete service βœ…
GET /services/<id>/required-parts Get required parts βœ…
GET /services/<id>/required-tools Get required tools βœ…

Service Ticket Endpoints

Method Endpoint Description Auth Required
GET /service-tickets List all tickets βœ…
POST /service-tickets Create ticket βœ…
GET /service-tickets/<id> Get ticket details βœ…
PUT /service-tickets/<id> Update ticket βœ…
DELETE /service-tickets/<id> Delete ticket βœ…
PUT /service-tickets/<id>/status Update status βœ…

πŸ“¦ Models

Customer

  • id: Integer (Primary Key)
  • name: String
  • email: String (Unique)
  • phone: String
  • address: String
  • preferred_mechanics: Relationship (Many-to-Many with Mechanic)
  • vehicles: Relationship (One-to-Many with Vehicle)
  • service_tickets: Relationship (One-to-Many with ServiceTicket)

Vehicle

  • id: Integer (Primary Key)
  • make: String
  • model: String
  • year: Integer
  • vin: String (Unique)
  • license_plate: String
  • color: String
  • mileage: Integer
  • last_service_date: DateTime
  • owner: Relationship (Many-to-One with Customer)
  • service_history: Relationship (Many-to-Many with Service)

Mechanic

  • id: Integer (Primary Key)
  • name: String
  • email: String (Unique)
  • phone: String
  • hourly_rate: Float
  • years_of_experience: Integer
  • specializations: Relationship (Many-to-Many with Specialization)
  • certified_tools: Relationship (Many-to-Many with Tool)
  • service_tickets: Relationship (One-to-Many with ServiceTicket)

Service

  • id: Integer (Primary Key)
  • name: String
  • description: Text
  • base_price: Float
  • estimated_hours: Float
  • complexity_level: Integer
  • is_diagnostic: Boolean
  • required_parts: Relationship (Many-to-Many with Part)
  • required_tools: Relationship (Many-to-Many with Tool)

ServiceTicket

  • id: Integer (Primary Key)
  • description: Text
  • status: String
  • scheduled_date: DateTime
  • completion_date: DateTime
  • estimated_cost: Float
  • final_cost: Float
  • diagnostic_notes: Text
  • completion_notes: Text
  • priority: Integer
  • customer: Relationship (Many-to-One with Customer)
  • vehicle: Relationship (Many-to-One with Vehicle)
  • mechanic: Relationship (Many-to-One with Mechanic)
  • service: Relationship (Many-to-One with Service)

πŸ› οΈ Development

Running Tests

pytest

Code Style

The project follows the Black code style. Format your code with:

black .

Database Migrations

After model changes:

flask db migrate -m "Description of changes"
flask db upgrade

πŸ“„ License

This project is licensed under the MIT License - see the LICENSE file for details.

🀝 Contributing

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/AmazingFeature)
  3. Commit your changes (git commit -m 'Add some AmazingFeature')
  4. Push to the branch (git push origin feature/AmazingFeature)
  5. Open a Pull Request

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published