For this assignment, you will set up a Spring Boot application that connects to a database, fetches data from the web, and tests the interfaces.
We’ll continue working on the Postify app! Some things to get out of the way:
The Postify product team wants a statistics page for each user. When a user opens their profile, the app calls your endpoint and displays a summary of their listening behaviour.
Implement the following endpoint:
GET /users/{id}/stats
It should return a JSON response with the following fields, depending on the user id:
{
"userId": 1,
"userName": "lena_v",
"userCountry": "NL",
"totalStreams": 65,
"uniqueTracksStreamed": 34,
"uniqueArtistsStreamed": 8,
"favoriteGenre": "Nederpop",
"totalListeningTimeSeconds": 14021
}
The fields are defined as follows:
totalStreams: total number of stream events for this useruniqueTracksStreamed: number of distinct tracks the user has ever streameduniqueArtistsStreamed: number of distinct artists the user has ever streamed (via tracks → albums → artists)favoriteGenre: the genre the user has streamed the most timestotalListeningTimeSeconds: sum of track_duration_s across all streams for this userSome additional requirements:
Return 404 Not Found if the user does not exist
All fields must be computed in SQL; do not fetch raw rows and calculate in Java
Try to write as little SQL queries as possible. True SQL wizards can do it in a single query, but two queries is maybe even better, for readability’s sake.
Write at least two MockMvc integration tests:
404💡 Getting stuck? Here are some hints:
Great! The Postify product team is happy with your delivery, and now they’re hungry for more. Up next, they’ve decided Postify should be showing users the lyrics of songs. They did some research and found that you can fetch lyrics using an API for free at https://lyricsovh.docs.apiary.io/#reference/0/lyrics-of-a-song/search. Make sure to look at the docs! Here’s a quick example of how the API works:
Request:
GET <https://api.lyrics.ovh/v1/Coldplay/Yellow>
Response:
{
"lyrics": "Look at the stars..."
}
If no lyrics are found, the API returns a 404. You can test it yourself on https://lyricsovh.docs.apiary.io/#reference/0/lyrics-of-a-song/search?console=1; on the right side, change the URI parameters, and click “Call resource”.
Please implement an endpoint that returns the lyrics for a given track.
GET /tracks/{id}/lyrics
It should look up the track and its artist in your database, call the lyrics API, and return:
{
"trackId": 67,
"trackTitle": "the 1",
"artistName": "Taylor Swift",
"lyrics": "I'm doing good, I'm on some new shi..."
}
Some additional requirements:
404 Not Found if the track does not exist in your database404 Not Found if the track exists but the lyrics API has no lyrics for it. Add a meaningful message explaining this error.RestClient to call the external API404404 with a meaningful error messageNOTE: The Postify database contains plenty of Dutch songs! The API we’re using does not have a lot of lyrics for Dutch songs. If you want to test your happy path, you can use for instance track_id=41, track_title='LUNCH', artist_name='Billie Eilish' or track_id=83, track_title='WUSYANAME', artist_name='Tyler the Creator'. You can test they will return proper lyrics by entering these details in https://lyricsovh.docs.apiary.io/#reference/0/lyrics-of-a-song/search?console=1 or by running this from a shell terminal (non-windows):
curl <https://api.lyrics.ovh/v1/Billie+Eilish/LUNCH>
Follow the Assignment submission guide to submit
The HackYourFuture curriculum is licensed under CC BY-NC-SA 4.0 *https://hackyourfuture.net/*

Built with ❤️ by the HackYourFuture community · Thank you, contributors
Found a mistake or have a suggestion? Let us know in the feedback form.