diff --git a/src/main/java/fr/organizee/controller/MenuController.java b/src/main/java/fr/organizee/controller/MenuController.java index b7db085..0ea98e3 100644 --- a/src/main/java/fr/organizee/controller/MenuController.java +++ b/src/main/java/fr/organizee/controller/MenuController.java @@ -1,6 +1,7 @@ package fr.organizee.controller; import fr.organizee.model.Menu; +import fr.organizee.model.Team; import fr.organizee.repository.MenuRepository; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.HttpStatus; @@ -49,11 +50,14 @@ public class MenuController { } //Ajoute un nouveau menu - @PostMapping(value="/add") + @PostMapping(value="/add/{team_id}", produces="application/json", consumes= "application/json") //@PreAuthorize("hasRole('ROLE_PARENT') or hasRole('ROLE_ENFANT')") - public ResponseEntity addMenu(@RequestBody Menu menu){ + public ResponseEntity addMenu(@RequestBody Menu menu, @PathVariable Integer team_id){ Menu resultMenu = null; try { + Team team=new Team(); + team.setId(team_id); + menu.setTeam(team); resultMenu = menuRepository.saveAndFlush(menu); } catch (Exception e) { return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(e.getMessage()); diff --git a/src/main/java/fr/organizee/model/Menu.java b/src/main/java/fr/organizee/model/Menu.java index dcc5cb0..22a1ab1 100644 --- a/src/main/java/fr/organizee/model/Menu.java +++ b/src/main/java/fr/organizee/model/Menu.java @@ -12,7 +12,7 @@ public class Menu { private int id; private String libelle; private LocalDate dateMenu; - private int validationProposition; + // private int validationProposition; @ManyToOne @JoinColumn(name="TEAM_ID") @JsonIgnoreProperties({"menu","membre"}) @@ -21,10 +21,10 @@ public class Menu { public Menu() { } - public Menu(String libelle, LocalDate dateMenu, int validationProposition, Team team) { + public Menu(String libelle, LocalDate dateMenu, Team team) { this.libelle = libelle; this.dateMenu = dateMenu; - this.validationProposition=validationProposition; + //this.validationProposition=validationProposition; this.team = team; } @@ -52,13 +52,13 @@ public class Menu { this.dateMenu = dateMenu; } - public int getValidationProposition() { - return validationProposition; - } + // public int getValidationProposition() { + // return validationProposition; + //} - public void setValidationProposition(int validationProposition) { - this.validationProposition = validationProposition; - } + //public void setValidationProposition(int validationProposition) { + // this.validationProposition = validationProposition; + // } public Team getTeam() { return team; @@ -74,7 +74,6 @@ public class Menu { "id=" + id + ", libelle='" + libelle + '\'' + ", dateMenu=" + dateMenu + - ", validationProposition=" + validationProposition + ", team=" + team + '}'; } diff --git a/src/main/java/fr/organizee/repository/MenuRepository.java b/src/main/java/fr/organizee/repository/MenuRepository.java index 1f22d7d..7c5d0cb 100644 --- a/src/main/java/fr/organizee/repository/MenuRepository.java +++ b/src/main/java/fr/organizee/repository/MenuRepository.java @@ -14,4 +14,5 @@ public interface MenuRepository extends JpaRepository { @Query(value = "select * from menu where team_id = :team_id", nativeQuery = true) List FindMenusByTeam(@Param("team_id") int team_id); + }