Merge pull request from HediMjid/isa

Isa
This commit is contained in:
Blandine Bajard 2022-02-17 11:41:21 +01:00 committed by GitHub
commit d42c2ea70c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1,6 +1,7 @@
package fr.organizee.controller;
import fr.organizee.model.Tache;
import fr.organizee.model.TodoList;
import fr.organizee.repository.TacheRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
@ -61,10 +62,13 @@ public class TacheController {
}
// Ajoute une tache
@PostMapping(value="/add", produces="application/json", consumes="application/json")
public ResponseEntity<?> addTache(@RequestBody Tache tache){
@PostMapping(value="/add/{idTodoList}", produces="application/json", consumes="application/json")
public ResponseEntity<?> addTache(@RequestBody Tache tache,@PathVariable Integer idTodoList){
Tache resultTache = null;
try {
TodoList todolist=new TodoList();
todolist.setId(idTodoList);
tache.setTodolist(todolist);
resultTache = tacheRepo.saveAndFlush(tache);
} catch (Exception e) {
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(e.getMessage());
@ -73,11 +77,14 @@ public class TacheController {
return ResponseEntity.status(HttpStatus.CREATED).body(resultTache);
}
//Met a jour les informations d'une date avec son ID
//Met a jour les informations d'une tache avec son ID
@PutMapping("/update/{id}")
public ResponseEntity<?> updateTache(@RequestBody Tache tache, @PathVariable Integer id) throws Exception {
Tache resultTache = null;
try {
TodoList todolist=new TodoList();
todolist.setId(tacheRepo.findById(tache.getId()).get().getTodolist().getId());
tache.setTodolist(todolist);
resultTache = tacheRepo.save(tache);
} catch (Exception e) {