From 3b2af8c99c3b5ee10d7b4b4609701ef95b6c98a7 Mon Sep 17 00:00:00 2001 From: Yvan Peter <yvan.peter@univ-lille.fr> Date: Sun, 14 Feb 2021 17:54:21 +0100 Subject: [PATCH] README + ajout classes UUID --- README.md | 88 ++++++++++--------- .../iut/pizzaland/dao/UUIDArgument.java | 21 +++++ .../pizzaland/dao/UUIDArgumentFactory.java | 19 ++++ 3 files changed, 87 insertions(+), 41 deletions(-) create mode 100644 src/main/java/fr/ulille/iut/pizzaland/dao/UUIDArgument.java create mode 100644 src/main/java/fr/ulille/iut/pizzaland/dao/UUIDArgumentFactory.java diff --git a/README.md b/README.md index 873d4a1..e3f1e50 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# Développement REST avec Jersey +# Projet REST avec Jersey ## Récupération du projet initial Pour récupérer le projet vous pouvez utiliser la commande `git clone @@ -12,53 +12,59 @@ projet. La classe `ApiV1` sera le point d'entrée de notre application REST qui permet de configurer le chemin de l'URI (`@ApplicationPath`) ainsi que les paquetages Java qui contiennent les ressources. - - . - ├── pom.xml - └── src - ├── main - │ ├── java - │ │ └── fr - │ │ └── ulille - │ │ └── iut - │ │ └── pizzaland - │ │ ├── ApiV1.java - │ │ ├── BDDFactory.java - │ │ ├── beans - │ │ ├── dao - │ │ ├── dto - │ │ └── resources - │ ├── resources - │ │ ├── ingredients.json - │ │ └── logback.xml - └── test - ├── java - │ └── fr - │ └── ulille - │ └── iut - │ └── pizzaland - │ └── IngredientResourceTest.java - └── resources - └── logback-test.xml +~~~ +. +├── architecture.svg +├── pom.xml +├── README.md +└── src + ├── main + │ ├── java + │ │ └── fr + │ │ └── ulille + │ │ └── iut + │ │ └── pizzaland + │ │ ├── ApiV1.java + │ │ ├── BDDFactory.java + │ │ ├── beans + │ │ ├── dao + │ │ │ ├── UUIDArgumentFactory.java + │ │ │ └── UUIDArgument.java + │ │ ├── dto + │ │ │ └── IngredientDto.java + │ │ ├── Main.java + │ │ └── resources + │ │ ├── BDDClearRessource.java + │ │ └── IngredientResource.java + │ └── resources + │ ├── ingredients.json + │ └── logging.properties + └── test + ├── java + │ └── fr + │ └── ulille + │ └── iut + │ └── pizzaland + │ └── IngredientResourceTest.java + └── resources + └── logging.properties +~~~ + ## Développement d'une ressource *ingredients* ### API et représentation des données Nous pouvons tout d'abord réfléchir à l'API REST que nous allons offrir pour la ressource *ingredients*. Celle-ci devrait répondre aux URI suivantes : -| Opération | URI | Action réalisée | Retour | -|:----------|:------------|:----------------------------------------------|:----------------------------------------------| -| GET | /ingredients | récupère l'ensemble des ingrédients | 200 et un tableau d'ingrédients | -| GET | /ingredients/{id} | récupère l'ingrédient d'identifiant id | 200 et l'ingrédient | -| | | | 404 si id est inconnu | -| GET | /ingredients/{id}/name | récupère le nom de l'ingrédient | 200 et le nom de l'ingrédient | -| | | d'identifiant id | 404 si id est inconnu | -| POST | /ingredients | création d'un ingrédient | 201 et l'URI de la ressource créée + représentation | -| | | | 400 si les informations ne sont pas correctes | -| | | | 409 si l'ingrédient existe déjà (même nom) | -| DELETE | /ingredients/{id} | destruction de l'ingrédient d'identifiant id | 204 si l'opération à réussi | -| | | | 404 si id est inconnu | +| URI | Opération | MIME | Requête | Réponse | +| :----------------------- | :---------- | :--------------------------------------------- | :-- | :---------------------------------------------------- | +| /ingredients | GET | <-application/json&<-application/xml | | 200 et liste des ingrédients (I2) | +| /ingredients/{id} | GET | <-application/json&<-application/xml | | 200 et un ingrédient (I2) ou 404 | +| /ingredients/{id}/name | GET | <-text/plain | | 200 et le nom de l'ingrédient ou 404 | +| /ingredients | POST | <-/->application/json& ->application/x-www-form-urlencoded | Ingrédient (I1) | Nouvel ingrédient (I2) | +| | | | | 409 si l'ingrédient existe déjà (même nom) | +| /ingredients/{id} | DELETE | | | | Un ingrédient comporte uniquement un identifiant et un nom. Sa diff --git a/src/main/java/fr/ulille/iut/pizzaland/dao/UUIDArgument.java b/src/main/java/fr/ulille/iut/pizzaland/dao/UUIDArgument.java new file mode 100644 index 0000000..7e31bf9 --- /dev/null +++ b/src/main/java/fr/ulille/iut/pizzaland/dao/UUIDArgument.java @@ -0,0 +1,21 @@ +package fr.ulille.iut.pizzaland.dao; + +import java.sql.PreparedStatement; +import java.sql.SQLException; +import java.util.UUID; + +import org.jdbi.v3.core.argument.Argument; +import org.jdbi.v3.core.statement.StatementContext; + +public class UUIDArgument implements Argument { + private final UUID value; + + public UUIDArgument(UUID value) { + this.value = value; + } + + @Override + public void apply(int position, PreparedStatement statement, StatementContext ctx) throws SQLException { + statement.setString(position, value.toString()); + } +} diff --git a/src/main/java/fr/ulille/iut/pizzaland/dao/UUIDArgumentFactory.java b/src/main/java/fr/ulille/iut/pizzaland/dao/UUIDArgumentFactory.java new file mode 100644 index 0000000..1382b41 --- /dev/null +++ b/src/main/java/fr/ulille/iut/pizzaland/dao/UUIDArgumentFactory.java @@ -0,0 +1,19 @@ +package fr.ulille.iut.pizzaland.dao; + +import java.sql.Types; +import java.util.UUID; + +import org.jdbi.v3.core.argument.AbstractArgumentFactory; +import org.jdbi.v3.core.argument.Argument; +import org.jdbi.v3.core.config.ConfigRegistry; + +public class UUIDArgumentFactory extends AbstractArgumentFactory<UUID> { + UUIDArgumentFactory() { + super(Types.VARCHAR); + } + + @Override + protected Argument build(UUID value, ConfigRegistry config) { + return (position, statement, ctx) -> statement.setString(position, value.toString()); + } +} -- GitLab