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;
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());

View File

@ -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 +
'}';
}

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)
List<Menu> FindMenusByTeam(@Param("team_id") int team_id);
}