An API that lists artists and their songs. Authenticated users can perform actions such as liking a song, following an artist and creating playlists.
Technologies used: MongoDB, NodeJS, Mongoose and Docker.
- custom user auth
- artists list
- single artist
- follow artist
- song list per artists
- liked songs
- create playlists
- user profile
- pagination
git clone [email protected]:raptisj/artiz-mono-api.git
cd ./artiz-mono-api
To run:
docker-compose up โ-build
To connect to a MongoDB shell:
docker exec -it mongodb /bin/bash
mongosh
Info: MongoDB shell commands cheatsheet
Info: Get started with MongoDB and Mongoose
I used ChatGPT to generate the data. To do so youself you can insert the prompts from the data/prompts/index.md
file. Replace curly braces with your intended value
In the data
folder there are two JSON files.
First, we need to copy each file to the container. Second, we need to run mongoimport to populate the database.
Note: Mongo usually generates an _id of type ObjectId for us. Here we add it explicitly in a format that mongoimport can understand in order to generate an _id in the correct format.
docker cp ./data/artists.json mongodb:/artists.json \
&& docker exec mongodb mongoimport --db mono --collection artists --drop --file /artists.json --jsonArray --mode upsert \
&& docker cp ./data/songs.json mongodb:/songs.json \
&& docker exec mongodb mongoimport --db mono --collection songs --drop --file /songs.json --jsonArray --mode upsert
To try out the API you can use Postman. Register a user and copy the access token in the response to your clipboard. Paste it in the Authorization > Bearer Token
section in the token field.
![Screen Shot 2023-11-26 at 5 44 17 PM](https://private-user-images.githubusercontent.com/23478420/285663052-90618e55-38e5-4578-8fdd-22a3136a6545.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MjM4NzY3MTUsIm5iZiI6MTcyMzg3NjQxNSwicGF0aCI6Ii8yMzQ3ODQyMC8yODU2NjMwNTItOTA2MThlNTUtMzhlNS00NTc4LThmZGQtMjJhMzEzNmE2NTQ1LnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNDA4MTclMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjQwODE3VDA2MzMzNVomWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPWFmY2I0OGU1YjdiNjJkNjE0OWIwNjljZGFjMmJlZDczYmJjNmJkNDZmNGMxYWI3OTkxZDg3MDc3ZTdkMGNmNjgmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0JmFjdG9yX2lkPTAma2V5X2lkPTAmcmVwb19pZD0wIn0.Yw5gmOqDO5i9XJxDgP9jjquXJOPzz1f07uOXyJhi7ao)
[
{
"_id": "5fc612c4397f9b74b2e8c266",
"name": "Pat Metheny",
"birth_year": 1954,
"instrument": "Guitar",
"genre": "Jazz",
"bio": "Pat Metheny is an American jazz guitarist known for his innovative and diverse musical style. He has won numerous awards, including 20 Grammy Awards across various categories. Metheny's work spans jazz fusion, contemporary jazz, and beyond, showcasing his virtuosity and creativity.",
"image_url": "https://upload.wikimedia.org/wikipedia/commons/thumb/4/4c/Pat_Metheny.jpg/500px-Pat_Metheny.jpg"
}
]
[
{
"_id": "5fc6140f397f9b74b2e8c268",
"artist_id": "5fc612c4397f9b74b2e8c266",
"title": "Last Train Home",
"album": "Still Life (Talking)",
"year": 1987,
"duration": "5:42",
"genre": "Jazz Fusion",
"added_to_playlist_dates": "2023-11-24T18:38:34.064Z" // only visible within a playlist
}
]
[
{
"_id": "09d6140f397f5b74b4e8c244",
"username": "doe",
"email": "[email protected]",
"liked_songs": ["1", "2", "3"],
"following": ["11", "22", "33"]
}
]
[
{
"_id": "09d6140f397f5b74b4e8c244",
"user_id": "9d6147f58c244b700f394b4e",
"song_ids": ["1", "2", "3"],
"title": "Jazz hits",
"description": "A smooth collection",
"song_count": 4,
"total_track_duration_in_seconds": 1123123,
"total_track_duration": "1h 20m" // from a virtual
}
]
John Raptis