A Flask-based web application for managing a classical music database using MongoDB. The application allows users to add, search, and view information about composers, pieces, orchestras, conductors, and reviews.
- Python 3.x
- MongoDB
- Docker and Docker Compose (for containerized deployment)
- Required Python packages (see requirements.txt)
- Clone the repository
- Install MongoDB and ensure it's running on your system
- Install required Python packages:
pip install -r requirements.txt
- Create a
.envfile in the project root using.env-exampleas a template:Then edit thecp .env-example .env
.envfile with your specific configuration.
- Install Docker and Docker Compose
- Build and start the containers:
docker-compose up --build
To import the sample data into your MongoDB Docker container:
-
First, ensure your MongoDB container is running:
docker ps
-
Copy the database dump to your container:
docker cp ./dump <container_name>:/dump
-
Restore the dump inside the container (if you encounter an auth_error pass your user and password as parameters, aswell as --authenticationDatabase admin):
docker exec -it <container_name> mongorestore /dump
- Run the Flask application (from folder containing app.py):
flask run
- Access the application at
http://localhost:5000
- Login
curl -X POST http://localhost:5000/login \
-H "Content-Type: application/x-www-form-urlencoded" \
-d "username=your_username&password=your_password"- Register
curl -X POST http://localhost:5000/register \
-H "Content-Type: application/x-www-form-urlencoded" \
-d "username=new_user&password=new_password&is_admin=false"- Logout
curl -X GET http://localhost:5000/logout- Check Login Status
curl -X GET http://localhost:5000/check_login- Check Admin Status
curl -X GET http://localhost:5000/check_admin- Search
curl -X GET "http://localhost:5000/search?q=search_term&entity_type=all"Parameters:
q: Search query stringentity_type: Type of entity to search (Composer, Piece, Orchestra, Conductor, Review, or 'all') Returns: JSON object containing search results grouped by entity type
- Get Entities by Type
curl -X GET "http://localhost:5000/get_entities/Composer"Parameters:
entity_type: Type of entity to retrieve (Composer, Piece, Orchestra, Conductor, Review) Returns: JSON array of entities of the specified type
- Add Document
curl -X POST "http://localhost:5000/add_document?entity_type=Composer" \
-H "Content-Type: application/json" \
-d '{"name": "John Doe", "nationality": "British"}'Parameters:
entity_type: Type of entity being added (via query parameter)- JSON body: Document data to be added Returns: JSON object with success message and inserted document ID
- Edit Document
curl -X POST "http://localhost:5000/edit_document/Composer/document_id" \
-H "Content-Type: application/json" \
-d '{"name": "Updated Name", "nationality": "Updated Nationality"}'The application uses MongoDB with the following collections and their fields:
- name
- nationality
- piece_name
- composer_id
- orchestra_id
- era
- orchestra_name
- conductor_id
- firstname
- lastname
- age
- text_content
- score
- date
- user_id
- piece_id
- All API endpoints except
/login,/register, and/check_loginrequire authentication - Only admin users can add or edit non-review entities
- Regular users can only add reviews
- Session cookies are set to expire after 1 day
- CSRF protection is enabled through SameSite cookie policy
/home- Landing page with application overview/add_document- Form page for adding new data/searchpage- Search interface for querying the database
-
/search(GET)- Parameters:
q: Search query stringentity_type: Type of entity to search (Composer, Piece, Orchestra, Conductor, Review, or 'all')
- Returns: JSON object containing search results grouped by entity type
- Parameters:
-
/get_entities/<entity_type>(GET)- Parameters:
entity_type: Type of entity to retrieve (Composer, Piece, Orchestra, Conductor, Review)
- Returns: JSON array of entities of the specified type
- Parameters:
-
/add_document(POST)- Parameters:
entity_type: Type of entity being added (via query parameter)- JSON body: Document data to be added
- Returns: JSON object with success message and inserted document ID
- Parameters: