Skip to content

[Java] API for querying and selling discs - Technical challenge Beblue back-end engineer (approved)

License

Notifications You must be signed in to change notification settings

gbzarelli/music-store-api

Repository files navigation

Issues Forks Stars Release Version Codacy Badge Coverage Status

Music Store API CircleCI

The Music Store API is an API for inquiries and disco sales, your database will be powered by the Spotify API at system startup, each disc has a random value between 10 and 100 and is associated with one of the four pre-defined categories in the system (POP, MPB, CLASSIC and ROCK), on the sale of the disk a cashback will be created according to the day of the week and the genre of each disc, these values are also pre-defined according to the system specifications.

Specifications

The app should provide a REST API containing the following operations::

  • Consult the disc catalog in paginated way, filtering by the genre and shorting in an increasing order by the name of the disc;

  • Consult the disc by its identifier;

  • Consult all sales made in paginated way, filtering by the range of dates (initial and final) of the sale and ordering in decreasing order by the date of the sale;

  • Consult a sale by its identifier;

  • Register a new disc sale with the total cashback value considering the table;

  • The app will be powered by the Spotify database: web-api

  • Each sale may have one or more discs selected, the cashback must be calculated and stored individually for each disc as well as the total cashback of the sale;

  • When registering a sale, the API must send a message to a messaging service passing the unique number of the sale

Technologies

Executing with Docker in develop environment

The following steps have been documented to performed on a Linux platform, but the commands with the Windows system can be similar, but, the operation isn't fully guaranteed. Make sure you have installed in your environment the Java (with the $JAVA_HOME in your classpath properly configured) and the Maven.

  • Clone the project
$ git clone https://github.com/gbzarelli/music-store-api.git
  • Access the project folder to start compiling and running the app
$ cd ./music-store-api
  • The following instruction will be executed via Maven the clean of the project, right after the package, which will perform the unit tests to guarantee the integrity of the project and to generate our .jar, lastly build Dockerfile will be generated an image in the local repository called helpdev/music-store-api. To build the plugin dockerfile-maven-plugin has been configured in the pom.xml;
$ mvn clean package dockerfile:build
  • Configure the following ENVs to Spotify access:
ENV Description
SPOTFY_ID The Spotify credentials ID
SPOTFY_SECRET The Spotify credential secret key
  • After the image will be generated through the dockerfile:build we will mount the containers by docker-compose. The prepared compose will go up to the API;
$ docker-compose up

Endpoints

Home page

  • Home page

    GET http://{address}:8080

Genres

  • Genre List

     GET http://{address}:8080/genre
    

Discs

  • Search disc by ID

      GET http://{address}:8080/disc/{id}
    
  • Search discs (with pagination)

      GET http://{address}:8080/disc{?page=1&limit=50}
    
  • Search disc by a genre (with pagination)

      GET http://{address}:8080/disc/genre/{genre}{?page=1&limit=50}
    
  • Note: Pagination parameters

Sales

  • New Sale

      POST http://{address}::8080/sale
    

    BODY:

    {
      "discsIds":[1,2,3]
    }
  • Search sale by purchase number

      GET http://{address}:8080/sale/{orderNumber}
    
  • Search sales by date

      GET http://{address}:8080/sale/start_date/{startDate}/end_date/{endDate}{?page=1&limit=50}
    

Note: Accepted data format: 'yyyy-MM-dd' ex: 2019-05-23

The Dynamic documentation with Swagger

The Swagger UI provide a display structure who is able to interpret project endpoints and generate an interactive documentation site;

  • http://{address}:8080/swagger-ui.html