Skip to content
Snippets Groups Projects
Commit c59a3574 authored by Theo Chilinski's avatar Theo Chilinski :computer:
Browse files

Réécupérer une tâche

parent c42d2483
No related branches found
No related tags found
No related merge requests found
Pipeline #8293 passed
...@@ -7,6 +7,7 @@ import org.jdbi.v3.sqlobject.statement.SqlQuery; ...@@ -7,6 +7,7 @@ import org.jdbi.v3.sqlobject.statement.SqlQuery;
import org.jdbi.v3.sqlobject.statement.SqlUpdate; import org.jdbi.v3.sqlobject.statement.SqlUpdate;
import fr.ulille.iut.todo.service.Tache; import fr.ulille.iut.todo.service.Tache;
import jakarta.ws.rs.Path;
/** /**
* TacheDAO * TacheDAO
...@@ -24,5 +25,9 @@ public interface TacheDAO { ...@@ -24,5 +25,9 @@ public interface TacheDAO {
@SqlQuery("select * from taches") @SqlQuery("select * from taches")
@RegisterBeanMapper(Tache.class) @RegisterBeanMapper(Tache.class)
List<Tache> getAll(); List<Tache> getAll();
@SqlQuery("select * from taches where id = ?")
@RegisterBeanMapper(Tache.class)
Tache getById(String id);
} }
...@@ -10,12 +10,15 @@ import fr.ulille.iut.todo.service.Tache; ...@@ -10,12 +10,15 @@ import fr.ulille.iut.todo.service.Tache;
import fr.ulille.iut.todo.service.TodoService; import fr.ulille.iut.todo.service.TodoService;
import jakarta.ws.rs.Consumes; import jakarta.ws.rs.Consumes;
import jakarta.ws.rs.DELETE; import jakarta.ws.rs.DELETE;
import jakarta.ws.rs.DefaultValue;
import jakarta.ws.rs.GET; import jakarta.ws.rs.GET;
import jakarta.ws.rs.NotFoundException;
import jakarta.ws.rs.POST; import jakarta.ws.rs.POST;
import jakarta.ws.rs.PUT; import jakarta.ws.rs.PUT;
import jakarta.ws.rs.Path; import jakarta.ws.rs.Path;
import jakarta.ws.rs.PathParam; import jakarta.ws.rs.PathParam;
import jakarta.ws.rs.Produces; import jakarta.ws.rs.Produces;
import jakarta.ws.rs.QueryParam;
import jakarta.ws.rs.WebApplicationException; import jakarta.ws.rs.WebApplicationException;
import jakarta.ws.rs.core.Context; import jakarta.ws.rs.core.Context;
import jakarta.ws.rs.core.EntityTag; import jakarta.ws.rs.core.EntityTag;
...@@ -64,4 +67,14 @@ public class TodoRessource { ...@@ -64,4 +67,14 @@ public class TodoRessource {
} }
return builder.build(); return builder.build();
} }
@GET
@Path("{id}")
public Tache getTacheById(@PathParam("id") String id) {
Tache tache = todoService.getTache(UUID.fromString(id));
if(tache == null) {
throw new NotFoundException();
}
return tache;
}
} }
...@@ -15,7 +15,7 @@ public class TodoService { ...@@ -15,7 +15,7 @@ public class TodoService {
} }
public Tache getTache(UUID id) { public Tache getTache(UUID id) {
return null; return taches.getById(id.toString());
} }
public List<Tache> getAll() { public List<Tache> getAll() {
...@@ -33,4 +33,5 @@ public class TodoService { ...@@ -33,4 +33,5 @@ public class TodoService {
public void updateTache(Tache tache) { public void updateTache(Tache tache) {
return; return;
} }
} }
...@@ -5,6 +5,7 @@ import static org.junit.Assert.assertTrue; ...@@ -5,6 +5,7 @@ import static org.junit.Assert.assertTrue;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.UUID;
import java.util.logging.Level; import java.util.logging.Level;
import java.util.logging.Logger; import java.util.logging.Logger;
...@@ -21,6 +22,7 @@ import fr.ulille.iut.todo.DebugMapper; ...@@ -21,6 +22,7 @@ import fr.ulille.iut.todo.DebugMapper;
import fr.ulille.iut.todo.dao.TacheDAO; import fr.ulille.iut.todo.dao.TacheDAO;
import fr.ulille.iut.todo.dto.CreationTacheDTO; import fr.ulille.iut.todo.dto.CreationTacheDTO;
import fr.ulille.iut.todo.service.Tache; import fr.ulille.iut.todo.service.Tache;
import jakarta.ws.rs.NotFoundException;
import jakarta.ws.rs.client.Entity; import jakarta.ws.rs.client.Entity;
import jakarta.ws.rs.core.Application; import jakarta.ws.rs.core.Application;
import jakarta.ws.rs.core.Form; import jakarta.ws.rs.core.Form;
...@@ -94,12 +96,26 @@ public class TodoRessourceTest extends JerseyTest { ...@@ -94,12 +96,26 @@ public class TodoRessourceTest extends JerseyTest {
assertEquals(tache, returned); assertEquals(tache, returned);
} }
@Test @Test(expected = NotFoundException.class)
public void get_with_wrong_id_should_return_404() { public void get_with_wrong_id_should_return_404() {
Tache tache = new Tache();
tache.setNom("test");
tache.setDescription("description");
dao.insert(tache);
target("taches").path(tache.getId().toString().substring(1)).request().get(Tache.class);
} }
@Test @Test
public void get_for_description_should_work_with_existing_task() { public void get_for_description_should_work_with_existing_task() {
Tache tache = new Tache();
tache.setNom("test");
tache.setDescription("description");
dao.insert(tache);
//Tache returned = target("taches").path(tache.getId().toString()).request().get(tache.getDescription());
//assertEquals(tache, returned);
} }
@Test @Test
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment