Week 6

Aggregations

Transactions

Indexes

Integrating with Spring Boot

Integrating with APIs

Integration Testing

Practice

Assignment

Back end Track

Week 6 Assignment

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:

  1. Start by setting up a spring boot application
  2. Make sure you have a postgres database with the Postify schema and data loaded
  3. Add the dependencies that you used throughout the chapters; postgresql, rest clients, testing frameworks, and whatever else you see fit
  4. Set the application properties so you can connect to the database
  5. Make sure your package structure is suitable for writing test classes.

Task 1: User statistics endpoint

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:

Some additional requirements:

Task 2 - Let’s get lyrical

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:

NOTE: 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>

Submission

Follow the Assignment submission guide to submit


The HackYourFuture curriculum is licensed under CC BY-NC-SA 4.0 *https://hackyourfuture.net/*

CC BY-NC-SA 4.0 Icons

Built with ❤️ by the HackYourFuture community · Thank you, contributors

Found a mistake or have a suggestion? Let us know in the feedback form.