Nous avons décidé de créer une API de musique. Dans laquelle on trouve des Albums, Artistes et des Genres. Pour des choix techniques nous avons décidé qu’un Album avait un Artist et qu’un Artist avait plusieurs Albums. Les Albums peuvent avoir plusieurs Genres et les Genres peuvent appartenir à plusieurs Albums.
classDiagram
class Album
Album : +Integer id
Album : +Integer numberTrack
Album : +String name
Album : +String dateAlbum
Album : +Float price
Album : +Artist artist
Album : +Set[Genre] genre
class Artist
Artist : +Integer id
Artist : +String name
Artist : +String pays
class Genre
Genre : +Integer id
Genre : +String name
Pour le stockage des données nous avons choisi Microsoft Azure (2Go) ce qui permet de stocker les données dans le cloud, et nécessite aucune configuration de votre côté pour l’exécution du programme. Noté que si vous exécuter le projet sous le réseau de l’IUT il est bloqué par le par-feux.
Dans l’application vous trouverez un fichier schema.sql
****qui détermine la structure de nos tables. A chaque démarrage du projet l’application ajoute des données venant de [https://theaudiodb.com](https://theaudiodb.com)
, permettant de remplir la base de données. Grâce au fichier ApiTheAudioDb.java
Une fois l’application lancé vous pouvez trouver toutes les routes à l’adresse suivante : http://localhost:9090/swagger-ui/
Pour lancer l’application il faut la build, puis générer un jar, puis l’exécuter. Lancer les commandes à la racine du projet.
$bash : ./gradlew build #Build de l'application
$bash : ./gradlew jar #Créer un jar
$bash : java -jar build/libs/ApiMusic21-0.0.1-SNAPSHOT.jar #Lance le serveur
Lancer dans un container docker, avant il faut avoir build l'image avec les commandes précédente
$bash : ./gradlew build #Build de l'application
$bash : ./gradlew jar #Créer un jar
$bash : docker build -t api-music.
$bash : docker run --name container-music-api -p 9090:80 api-music
#ou en détached
$bash : docker run --name container-music-api -d -p 9090:80 api-music
#Supprimer un container
$bash : docker container rm container-music-api
The API Design Platform and API Client
Si vous utilisez Insomnia pour tester les apis voici le fichier json des requêtes que vous pouvez importer.
Tutoriel pour importer les data
Sinon vous pouvez faire les commandes avec un bash et curl.
curl --request GET \
--url http://localhost:9090/Genres/ \
--header 'Content-Type: application/json' \
--data '{}'
curl --request POST \
--url http://localhost:9090/Genres/ \
--header 'Content-Type: application/json' \
--data ' {
"name" : "Nouveau Genre"
}'
curl --request GET \
--url http://localhost:9090/Genres/1 \
--header 'Content-Type: application/json' \
--data '{}'
curl --request GET \
--url http://localhost:9090/Genres/name/rap \
--header 'Content-Type: application/json' \
--data '{}'
curl --request DELETE \
--url http://localhost:9090/Genres/1 \
--header 'Content-Type: application/json' \
--data '{}'
curl --request PUT \
--url http://localhost:9090/Genres/2 \
--header 'Content-Type: application/json' \
--data '{
"name" : "test"
}'
curl --request GET \
--url http://localhost:9090/Artistes/ \
--header 'Content-Type: application/json' \
--data '{}'
curl --request GET \
--url http://localhost:9090/Artistes/2
curl --request POST \
--url http://localhost:9090/Artistes/ \
--header 'Content-Type: application/json' \
--data '{
"id" : "50",
"name":"lrt",
"pays":"états-unis"
}'
curl --request GET \
--url http://localhost:9090/Artistes/name/the \
--header 'Content-Type: application/json' \
--data '{}'
curl --request GET \
--url http://localhost:9090/Artistes/pays/ca \
--header 'Content-Type: application/json' \
--data '{}'
curl --request DELETE \
--url http://localhost:9090/Artistes/2 \
--header 'Content-Type: application/json' \
--data '{}'
curl --request PUT \
--url http://localhost:9090/Artistes/1 \
--header 'Content-Type: application/json' \
--data '{
"id":"1",
"name" : "xxxtenatcion",
"pays" : "test"
}'
curl --request GET \
--url http://localhost:9090/Album/ \
--header 'Content-Type: application/json' \
--data '{}'
curl --request GET \
--url http://localhost:9090/Album/name/Hous \
--header 'Content-Type: application/json' \
--data '{}'
curl --request GET \
--url http://localhost:9090/Album/tracks/5 \
--header 'Content-Type: application/json' \
--data '{}'
curl --request GET \
--url http://localhost:9090/Album/price/2.5
curl --request POST \
--url http://localhost:9090/Album/add/stromae \
--header 'Content-Type: application/json' \
--data '{
"id":"5",
"date": "2021",
"name" : "dorianAlbum",
"numberTrack": "10",
"price": "21.21"
}
'
curl --request PUT \
--url http://localhost:9090/Album/addGenre/2/3/ \
--header 'Content-Type: application/json' \
--data '{}'