diff --git a/src/main/java/fr/organizee/controller/TodoListController.java b/src/main/java/fr/organizee/controller/TodoListController.java index 747eff9..8733fdc 100644 --- a/src/main/java/fr/organizee/controller/TodoListController.java +++ b/src/main/java/fr/organizee/controller/TodoListController.java @@ -1,6 +1,7 @@ package fr.organizee.controller; import fr.organizee.model.TodoList; +import fr.organizee.model.Team; import fr.organizee.repository.TodoListRepository; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.HttpStatus; @@ -19,6 +20,7 @@ public class TodoListController { @Autowired private TodoListRepository todolistRepo; + @GetMapping(value = "/all") public ResponseEntity getAll(){ List liste = null; @@ -32,6 +34,23 @@ public class TodoListController { return ResponseEntity.status(HttpStatus.OK).body(liste); } + //Ajoute une nouvelle ToDoList + @PostMapping(value="/add/{team_id}", produces="application/json", consumes= "application/json") + //@PreAuthorize("hasRole('ROLE_PARENT') or hasRole('ROLE_ENFANT')") + public ResponseEntity addTodolist(@RequestBody TodoList todolist, @PathVariable Integer team_id) { + TodoList resultTodolist = null; + try { + Team team = new Team(); + team.setId(team_id); + todolist.setTeam(team); + resultTodolist = todolistRepo.saveAndFlush(todolist); + } catch (Exception e) { + return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(e.getMessage()); + } + + return ResponseEntity.status(HttpStatus.CREATED).body(resultTodolist); + } + @DeleteMapping(value = "/delete/{id}") //@PreAuthorize("hasRole('ROLE_PARENT')") public ResponseEntity deleteTodolist(@PathVariable int id){ diff --git a/src/main/java/fr/organizee/repository/TacheRepository.java b/src/main/java/fr/organizee/repository/TacheRepository.java index a9ac6f9..0c2e1bf 100644 --- a/src/main/java/fr/organizee/repository/TacheRepository.java +++ b/src/main/java/fr/organizee/repository/TacheRepository.java @@ -9,7 +9,8 @@ import org.springframework.stereotype.Repository; import java.util.List; @Repository -public interface TacheRepository extends JpaRepository { +public interface +TacheRepository extends JpaRepository { // N'est plus utilisé normalement @Query(value = "select * from todo_list, tache where todo_list.team_id = :team_id and todo_list.id = tache.todolist_id", nativeQuery = true) diff --git a/src/main/java/fr/organizee/service/MembreServiceImpl.java b/src/main/java/fr/organizee/service/MembreServiceImpl.java index e04c48e..ed33039 100644 --- a/src/main/java/fr/organizee/service/MembreServiceImpl.java +++ b/src/main/java/fr/organizee/service/MembreServiceImpl.java @@ -17,7 +17,8 @@ import fr.organizee.repository.MembreRepository; import fr.organizee.security.JwtTokenProvider; @Service -public class MembreServiceImpl implements MembreService { +public class +MembreServiceImpl implements MembreService { @Autowired private MembreRepository membreRepository; // permet communication avec la BD