A backend application built using FastAPI and SQLAlchemy that allows users to manage songs, simulate purchases with gateway logic, and create/shuffle playlists.
📌 Submitted as part of the OpsWerks Academy backend technical assessment.
- Create, retrieve, update, and delete songs
- Each song includes:
title(string)length(int in seconds)date_released(datetime)price(positive decimal)
- Accepts a list of song IDs
- Determines the payment gateway based on total price:
- CheapPaymentGateway if total < 10
- ExpensivePaymentGateway if total ≥ 10
- Returns a success message after simulated payment
- Create a playlist containing multiple songs
- Shuffle the order of songs within the playlist
- Python 3.11+
- FastAPI
- SQLAlchemy
- Pydantic v2
- SQLite (dev environment)
- Pytest (testing framework)
├── app/
├── main.py
├── app/
│ ├── main.py
│ ├── models.py
│ ├── schemas.py
│ ├── database.py
│ └── routers/
│ ├── songs.py
│ ├── purchase.py
│ └── playlist.py
├── tests/
│ ├── test_songs.py
│ ├── test_purchase.py
│ └── test_playlist.py
├── requirements.txt
└── README.md
git clone https://github.com/Sweep76/fastapi-song-api.git
cd fastapi-song-apipython -m venv venv
venv\Scripts\activate # Windows
# OR
source venv/bin/activate # macOS/Linuxpip install -r requirements.txtuvicorn app.main:app --reloadVisit: http://127.0.0.1:8000/docs
Make sure you're in the root folder and run:
pytestPOST /songs
{
"title": "Sample Song",
"length": 240,
"date_released": "2024-01-01T00:00:00",
"price": 5.99
}POST /purchase
{
"song_ids": [1, 2, 3]
}POST /playlists
{
"name": "My Favorite Tracks",
"song_ids": [1, 2, 3]
}POST /playlists/{playlist_id}/shuffle