Skip to content
Snippets Groups Projects
Commit 3b2af8c9 authored by Yvan Peter's avatar Yvan Peter
Browse files

README + ajout classes UUID

parent 8b29d76d
No related branches found
No related tags found
No related merge requests found
# 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
......
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());
}
}
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());
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment