Keywords: Spring Framework
, Neo4j
, MongoDB
, Microservice
, GitFlow
This is an Java implementation of the backend for a Music Application similar to spodify. Assumptions were made that songs and users are stored in different database. Java Spring Framework was used and thwo databases were communicating through REST-api calls.
- The backend is running on port 8080.
- ProfileMicroservice:
- database connect to: 7687;
- Neo4j Username: neo4j;
- Password: password;
- SongMicroservice:
- MongoDB name: csc301-test;
- collection name: songs;
- Command Line:
- Install maven
- To compile your code simply run mvn compile in the root directory (the folder that has pom.xml)
- To run your code run mvn exec:java
- Eclipse:
- File → Import → Maven → Existing Maven Projects
- Navigate to the project location
- Right click the project → Maven Build…
- Input compile exec:java in the Goals input box
- Click apply then run/close
- You can now run the project by pressing the green play button
- Intellij:
- Import project
- Navigate to the project location
- Import project from external model → Maven
- Next → Next → Next → Finish
- Add Configuration → + Button → Maven
- Name the configuration and input
exec:java
in the Command Line box - Apply → Ok
- You can now run the project by pressing the green play button
-
Song Microservice:
- Song Schema
- _id - The ObjectId of the document (i.e. a unique identifier for each document). The id is auto-generated by Mongo when a document is inserted into the database
- songName - The name of the song
- songArtistFullName - The full name of the artist of the song
- songAlbum - The album the song belongs to
- songAmountFavourites - The amount of Profiles that have favourited the Song
- DB Methods
- DbQueryStatus addSong(Song songToAdd) - Adds the specified song to the Mongo DB
- DbQueryStatus findSongById(String songId) - Returns the specified Song that matches the songId
- DbQueryStatus getSongTitleById(String songId) - Returns the song title which matches the songId
- DbQueryStatus deleteSongById(String songId) - Deletes the specified song from the Mongo DB
- DbQueryStatus updateSongFavouritesCount(String songId, boolean shouldDecrement) - Increments/decrements a Song’s like count
- Song Schema
-
Profile Microservice:
- Node schema:
- “profile”
- “song”
- “playlist”
- The relationships:
- (:profile)-[:created]->(:playlist)
- (profile)-[:follows]->(:profile)
- (:playlist)-[:includes]->(:song)
- DB Methods to Implement
- DbQueryStatus likeSong(String userName, String songId) - Adds the songId to the Profile’s favourites list
- DbQueryStatus unlikeSong(String userName, String songId) - Removes the songId from the Profile’s favourites list
- DbQueryStatus deleteSongFromDb(String songId) - Deletes the songId from all favourites playlist
- DbQueryStatus createUserProfile(String userName, String fullName, String password) - Creates the Profile and adds it to the Neo4J DB
- DbQueryStatus followFriend(String userName, String frndUserName) - Allows the userName Profile to follow the frndUserName Profile
- DbQueryStatus unfollowFriend(String userName, String frndUserName) - Allows the userName Profile to unfollow the frndUserName Profile
- DbQueryStatus getAllSongFriendsLike(String userName)
- Node schema:
-
Response Body:
- JSON format
-
Response Status:
- 200 OK for a successful add
- 400 BAD REQUEST if the request body is improperly formatted or missing required information
- 404 NOT FOUND if the actors or movies do not exist when adding a relationship
- 500 INTERNAL SERVER ERROR if save or add was unsuccessful (Java Exception is thrown)
-
Existing endpoints:
- SongMicroservice:
- ProfileMicroservice:
- (POST) http://localhost:8080/profile
- (PUT) http://localhost:8080/followFriend/{userName}/{friendUserName}
- (PUT) http://localhost:8080/unfollowFriend/{userName}/{friendUserName}
- (PUT) http://localhost:8080/likeSong/{userName}/{songId}
- (PUT) http://localhost:8080/unlikeSong/{userName}/{songId}
- (GET) http://localhost:8080/getAllFriendFavouriteSongTitles/{userName}
-
PostMan Testing Package:
You can download it from the PostMan folder.