diff --git a/README.md b/README.md index 6a0ce6a..fb27004 100644 --- a/README.md +++ b/README.md @@ -10,6 +10,7 @@ A RESTful API for a music streaming service built with FastAPI and SQLite. - Music streaming - Search functionality - Basic recommendation system +- File uploads for audio and images ## Tech Stack @@ -28,9 +29,16 @@ A RESTful API for a music streaming service built with FastAPI and SQLite. ├── alembic/ # Database migration scripts ├── app/ # Application source code │ ├── api/ # API endpoints +│ │ ├── deps.py # API dependencies │ │ └── v1/ # API version 1 -│ ├── core/ # Core modules (config, security) -│ ├── db/ # Database session and utilities +│ │ ├── api.py # Main API router +│ │ └── endpoints/ # API endpoint modules +│ ├── core/ # Core modules +│ │ ├── config.py # Configuration settings +│ │ └── security.py # Security utilities +│ ├── db/ # Database +│ │ ├── init_db.py # Database initialization +│ │ └── session.py # Database session │ ├── models/ # SQLAlchemy models │ ├── schemas/ # Pydantic models/schemas │ ├── services/ # Business logic services @@ -45,24 +53,113 @@ A RESTful API for a music streaming service built with FastAPI and SQLite. ## Setup and Installation -1. Clone the repository -2. Install dependencies: +1. Clone the repository: + ```bash + git clone + cd music-streaming-api ``` + +2. Create virtual environment (optional): + ```bash + python -m venv venv + source venv/bin/activate # On Windows: venv\Scripts\activate + ``` + +3. Install dependencies: + ```bash pip install -r requirements.txt ``` -3. Set up environment variables (create a `.env` file in the root directory): + +4. Set up environment variables (create a `.env` file in the root directory): ``` SECRET_KEY=your-secret-key + ACCESS_TOKEN_EXPIRE_MINUTES=11520 # 8 days ``` -4. Run database migrations: - ``` + +5. Run database migrations: + ```bash alembic upgrade head ``` -5. Start the server: + +6. Initialize the database (creates admin user): + ```bash + # Access the endpoint or run the Python script + curl http://localhost:8000/init-db ``` - uvicorn main:app --reload + +7. Start the server: + ```bash + uvicorn main:app --reload --host 0.0.0.0 --port 8000 ``` +## API Endpoints + +The API is organized into the following groups: + +### Authentication +- `POST /api/v1/auth/register` - Register a new user +- `POST /api/v1/auth/login` - Login to get access token +- `GET /api/v1/auth/me` - Get current user information + +### Users +- `GET /api/v1/users/` - List users (admin only) +- `POST /api/v1/users/` - Create a new user (admin only) +- `GET /api/v1/users/me` - Get current user +- `PUT /api/v1/users/me` - Update current user +- `GET /api/v1/users/{user_id}` - Get a specific user +- `PUT /api/v1/users/{user_id}` - Update a user (admin only) +- `DELETE /api/v1/users/{user_id}` - Delete a user (admin only) + +### Artists +- `GET /api/v1/artists/` - List artists +- `POST /api/v1/artists/` - Create a new artist (admin only) +- `GET /api/v1/artists/{artist_id}` - Get a specific artist +- `PUT /api/v1/artists/{artist_id}` - Update an artist (admin only) +- `DELETE /api/v1/artists/{artist_id}` - Delete an artist (admin only) + +### Albums +- `GET /api/v1/albums/` - List albums +- `POST /api/v1/albums/` - Create a new album (admin only) +- `GET /api/v1/albums/{album_id}` - Get a specific album +- `PUT /api/v1/albums/{album_id}` - Update an album (admin only) +- `DELETE /api/v1/albums/{album_id}` - Delete an album (admin only) + +### Songs +- `GET /api/v1/songs/` - List songs +- `POST /api/v1/songs/` - Create a new song (admin only) +- `GET /api/v1/songs/{song_id}` - Get a specific song +- `PUT /api/v1/songs/{song_id}` - Update a song (admin only) +- `DELETE /api/v1/songs/{song_id}` - Delete a song (admin only) + +### Playlists +- `GET /api/v1/playlists/` - List user's playlists +- `GET /api/v1/playlists/public` - List public playlists +- `POST /api/v1/playlists/` - Create a new playlist +- `GET /api/v1/playlists/{playlist_id}` - Get a specific playlist +- `PUT /api/v1/playlists/{playlist_id}` - Update a playlist +- `DELETE /api/v1/playlists/{playlist_id}` - Delete a playlist +- `POST /api/v1/playlists/{playlist_id}/songs` - Add a song to a playlist +- `DELETE /api/v1/playlists/{playlist_id}/songs` - Remove a song from a playlist + +### Streaming +- `GET /api/v1/stream/song/{song_id}` - Stream a song +- `GET /api/v1/stream/album/cover/{album_id}` - Get album cover image +- `GET /api/v1/stream/artist/image/{artist_id}` - Get artist image + +### Upload +- `POST /api/v1/upload/song` - Upload a song file (admin only) +- `POST /api/v1/upload/image` - Upload an image file (admin only) + +### Recommendations +- `GET /api/v1/recommendations/similar-songs/{song_id}` - Get similar songs +- `GET /api/v1/recommendations/for-user` - Get personalized recommendations +- `GET /api/v1/recommendations/popular` - Get popular songs +- `GET /api/v1/recommendations/similar-artists/{artist_id}` - Get similar artists + +### Other +- `GET /health` - Health check endpoint +- `GET /init-db` - Initialize the database with an admin user + ## API Documentation Once the application is running, you can access the API documentation at: @@ -77,6 +174,30 @@ Once the application is running, you can access the API documentation at: | SECRET_KEY | Secret key for JWT tokens | Auto-generated | | ACCESS_TOKEN_EXPIRE_MINUTES | Minutes before JWT token expires | 11520 (8 days) | +## Default Admin User + +When the database is initialized, a default admin user is created: +- Email: admin@example.com +- Username: admin +- Password: adminpassword + +It's recommended to change the password immediately after first login in a production environment. + +## Development + +### Running Tests +```bash +# To be implemented +pytest +``` + +### Database Migrations +To create a new migration after changing models: +```bash +alembic revision --autogenerate -m "Description of changes" +alembic upgrade head +``` + ## License This project is licensed under the MIT License. \ No newline at end of file diff --git a/main.py b/main.py index 7c515be..0380a73 100644 --- a/main.py +++ b/main.py @@ -9,11 +9,36 @@ from app.db.init_db import init_db app = FastAPI( title=settings.PROJECT_NAME, - description="Music Streaming API", + description=""" + # Music Streaming API + + A RESTful API for a music streaming service built with FastAPI and SQLite. + + ## Features + + * User authentication (register, login, JWT tokens) + * Music management (songs, albums, artists) + * Playlist creation and management + * Music streaming + * Search functionality + * Basic recommendation system + + ## Authentication + + This API uses JWT Bearer tokens for authentication. To authenticate: + 1. Register a new user or use existing credentials + 2. Get a token using the /api/v1/auth/login endpoint + 3. Include the token in the Authorization header for protected endpoints + + """, version="0.1.0", openapi_url="/openapi.json", docs_url="/docs", redoc_url="/redoc", + license_info={ + "name": "MIT License", + "url": "https://opensource.org/licenses/MIT", + }, ) # Set up CORS