# Reservation Platform Backend This is the Flask backend for the 3D Printer Reservation Platform, providing a RESTful API for managing printers, reservations, and users. ## Features - User authentication with email/password - Role-based permission system (admin, user) - Printer management - Reservation system - User management ## API Endpoints ### Authentication - `POST /auth/register` - Register a new user - `POST /auth/login` - Login with username/email and password - `POST /auth/logout` - Log out a user by invalidating their session ### Printers - `GET /api/printers` - Get all printers - `GET /api/printers/` - Get a specific printer - `POST /api/printers` - Create a new printer (admin only) - `PUT /api/printers/` - Update a printer (admin only) - `DELETE /api/printers/` - Delete a printer (admin only) - `GET /api/printers/availability` - Get availability information for all printers ### Print Jobs - `GET /api/jobs` - Get jobs for the current user or all jobs for admin - `GET /api/jobs/` - Get a specific job - `POST /api/jobs` - Create a new print job (reserve a printer) - `PUT /api/jobs/` - Update a job - `DELETE /api/jobs/` - Delete a job (cancel reservation) - `GET /api/jobs//remaining-time` - Get remaining time for a job (public endpoint) ### Users - `GET /api/users` - Get all users (admin only) - `GET /api/users/` - Get a specific user (admin only) - `PUT /api/users/` - Update a user (admin only) - `DELETE /api/users/` - Delete a user (admin only) - `GET /api/me` - Get the current user's profile - `PUT /api/me` - Update the current user's profile ## Installation ### Prerequisites - Python 3.11 or higher - pip ### Setup 1. Clone the repository ```bash git clone https://github.com/your-repo/reservation-platform.git cd reservation-platform/packages/flask-backend ``` 2. Install dependencies ```bash pip install -r requirements.txt ``` 3. Create a `.env` file with the following variables: ``` SECRET_KEY=your-secret-key DATABASE_URL=sqlite:///app.db JWT_SECRET=your-jwt-secret ``` 4. Initialize the database ```bash flask db upgrade python scripts/init_db.py ``` 5. Run the development server ```bash python wsgi.py ``` ## Docker Deployment 1. Build and run with Docker Compose ```bash docker-compose up -d ``` ## Development ### Running Migrations To create a new migration after updating models: ```bash flask db migrate -m "Description of changes" flask db upgrade ```