This commit is contained in:
Blandine Bajard 2022-02-17 11:42:52 +01:00
parent e83810c9fd
commit 9c72f95494
3 changed files with 16 additions and 12 deletions

View File

@ -1,6 +1,7 @@
package fr.organizee.controller; package fr.organizee.controller;
import fr.organizee.model.Menu; import fr.organizee.model.Menu;
import fr.organizee.model.Team;
import fr.organizee.repository.MenuRepository; import fr.organizee.repository.MenuRepository;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus; import org.springframework.http.HttpStatus;
@ -49,11 +50,14 @@ public class MenuController {
} }
//Ajoute un nouveau menu //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')") //@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; Menu resultMenu = null;
try { try {
Team team=new Team();
team.setId(team_id);
menu.setTeam(team);
resultMenu = menuRepository.saveAndFlush(menu); resultMenu = menuRepository.saveAndFlush(menu);
} catch (Exception e) { } catch (Exception e) {
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(e.getMessage()); return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(e.getMessage());

View File

@ -12,7 +12,7 @@ public class Menu {
private int id; private int id;
private String libelle; private String libelle;
private LocalDate dateMenu; private LocalDate dateMenu;
private int validationProposition; // private int validationProposition;
@ManyToOne @ManyToOne
@JoinColumn(name="TEAM_ID") @JoinColumn(name="TEAM_ID")
@JsonIgnoreProperties({"menu","membre"}) @JsonIgnoreProperties({"menu","membre"})
@ -21,10 +21,10 @@ public class Menu {
public 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.libelle = libelle;
this.dateMenu = dateMenu; this.dateMenu = dateMenu;
this.validationProposition=validationProposition; //this.validationProposition=validationProposition;
this.team = team; this.team = team;
} }
@ -52,13 +52,13 @@ public class Menu {
this.dateMenu = dateMenu; this.dateMenu = dateMenu;
} }
public int getValidationProposition() { // public int getValidationProposition() {
return validationProposition; // return validationProposition;
} //}
public void setValidationProposition(int validationProposition) { //public void setValidationProposition(int validationProposition) {
this.validationProposition = validationProposition; // this.validationProposition = validationProposition;
} // }
public Team getTeam() { public Team getTeam() {
return team; return team;
@ -74,7 +74,6 @@ public class Menu {
"id=" + id + "id=" + id +
", libelle='" + libelle + '\'' + ", libelle='" + libelle + '\'' +
", dateMenu=" + dateMenu + ", dateMenu=" + dateMenu +
", validationProposition=" + validationProposition +
", team=" + team + ", team=" + team +
'}'; '}';
} }

View File

@ -14,4 +14,5 @@ public interface MenuRepository extends JpaRepository <Menu, Integer> {
@Query(value = "select * from menu where team_id = :team_id", nativeQuery = true) @Query(value = "select * from menu where team_id = :team_id", nativeQuery = true)
List<Menu> FindMenusByTeam(@Param("team_id") int team_id); List<Menu> FindMenusByTeam(@Param("team_id") int team_id);
} }