cecile
This commit is contained in:
commit
ce8c57b5ac
|
@ -6,11 +6,9 @@ import fr.organizee.exception.ExistingUsernameException;
|
||||||
import fr.organizee.exception.InvalidCredentialsException;
|
import fr.organizee.exception.InvalidCredentialsException;
|
||||||
import fr.organizee.exception.MembreNotFoundException;
|
import fr.organizee.exception.MembreNotFoundException;
|
||||||
import fr.organizee.model.Membre;
|
import fr.organizee.model.Membre;
|
||||||
import fr.organizee.model.Menu;
|
|
||||||
import fr.organizee.model.Team;
|
import fr.organizee.model.Team;
|
||||||
import fr.organizee.repository.MembreRepository;
|
import fr.organizee.repository.MembreRepository;
|
||||||
import fr.organizee.service.MembreService;
|
import fr.organizee.service.MembreService;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
|
||||||
import org.springframework.http.HttpStatus;
|
import org.springframework.http.HttpStatus;
|
||||||
import org.springframework.http.ResponseEntity;
|
import org.springframework.http.ResponseEntity;
|
||||||
import org.springframework.security.access.prepost.PreAuthorize;
|
import org.springframework.security.access.prepost.PreAuthorize;
|
||||||
|
@ -24,42 +22,39 @@ import java.util.UUID;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
|
||||||
|
@CrossOrigin(origins = "*")
|
||||||
|
@RequestMapping(value = "/membres")
|
||||||
@RestController
|
@RestController
|
||||||
@CrossOrigin("*")
|
|
||||||
@RequestMapping(value="/membres")
|
|
||||||
public class MembreController {
|
public class MembreController {
|
||||||
|
|
||||||
@Autowired
|
private MembreRepository membreRepository;
|
||||||
private MembreRepository membreRepo;
|
|
||||||
|
|
||||||
@Autowired
|
|
||||||
private MembreService membreService;
|
private MembreService membreService;
|
||||||
@Autowired
|
|
||||||
private BCryptPasswordEncoder passwordEncoder;
|
private BCryptPasswordEncoder passwordEncoder;
|
||||||
|
|
||||||
public MembreController() {}
|
/**
|
||||||
|
* Contrôleur Membre
|
||||||
|
*/
|
||||||
|
public MembreController(MembreRepository membreRepository,
|
||||||
|
MembreService membreService,
|
||||||
|
BCryptPasswordEncoder passwordEncoder) {
|
||||||
|
this.membreRepository = membreRepository;
|
||||||
|
this.membreService = membreService;
|
||||||
|
this.passwordEncoder = passwordEncoder;
|
||||||
|
|
||||||
@ResponseBody
|
|
||||||
public String home()
|
|
||||||
{
|
|
||||||
StringBuilder sb = new StringBuilder();
|
|
||||||
sb.append("<h1>Affichages des membres</h1>");
|
|
||||||
sb.append("<ul><li><a href='http://localhost:8088/membres/all'>Liste des <strong>membres</strong></a></li>");
|
|
||||||
return sb.toString();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Rechercher tous les membres
|
* Rechercher tous les membres
|
||||||
* @return
|
*
|
||||||
* http://localhost:8088/membres/all
|
* @return http://localhost:8088/membres/all
|
||||||
*/
|
*/
|
||||||
@GetMapping(value = "/all")
|
@GetMapping(value = "/all")
|
||||||
//@PreAuthorize("hasRole('ROLE_PARENT') or hasRole('ROLE_ENFANT')")
|
//@PreAuthorize("hasRole('ROLE_PARENT') or hasRole('ROLE_ENFANT')")
|
||||||
public ResponseEntity<?> getAllMembres(){
|
public ResponseEntity<?> getAllMembres() {
|
||||||
List<Membre> listeMembres;
|
List<Membre> listeMembres;
|
||||||
try
|
try {
|
||||||
{
|
listeMembres = membreRepository.findAll();
|
||||||
listeMembres = membreRepo.findAll();
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
MembreNotFoundException commandeNotFoundException = new MembreNotFoundException();
|
MembreNotFoundException commandeNotFoundException = new MembreNotFoundException();
|
||||||
return ResponseEntity.status(HttpStatus.NOT_FOUND).body(commandeNotFoundException.getMessage());
|
return ResponseEntity.status(HttpStatus.NOT_FOUND).body(commandeNotFoundException.getMessage());
|
||||||
|
@ -70,11 +65,11 @@ public class MembreController {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Rechercher tous les membres admin
|
* Rechercher tous les membres admin
|
||||||
* @return
|
*
|
||||||
* http://localhost:8088/membres/admin/all
|
* @return http://localhost:8088/membres/admin/all
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@GetMapping(value="/admin/all")
|
@GetMapping(value = "/admin/all")
|
||||||
@PreAuthorize("hasRole('ROLE_PARENT')")
|
@PreAuthorize("hasRole('ROLE_PARENT')")
|
||||||
public List<MembreDto> getAllAdminUsers() {
|
public List<MembreDto> getAllAdminUsers() {
|
||||||
return membreService.findAllUsers().stream().map(appUser ->
|
return membreService.findAllUsers().stream().map(appUser ->
|
||||||
|
@ -84,16 +79,16 @@ public class MembreController {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Rechercher un membre par son Id
|
* Rechercher un membre par son Id
|
||||||
* @return
|
*
|
||||||
* http://localhost:8088/membres/1
|
* @return http://localhost:8088/membres/1
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@GetMapping(value="/{id}")
|
@GetMapping(value = "/{id}")
|
||||||
//@PreAuthorize("hasRole('ROLE_PARENT') or hasRole('ROLE_ENFANT')")
|
//@PreAuthorize("hasRole('ROLE_PARENT') or hasRole('ROLE_ENFANT')")
|
||||||
public ResponseEntity<?> getMembreById(@PathVariable int id) {
|
public ResponseEntity<?> getMembreById(@PathVariable int id) {
|
||||||
Optional<Membre> membre;
|
Optional<Membre> membre;
|
||||||
try {
|
try {
|
||||||
membre = membreRepo.findById(id);
|
membre = membreRepository.findById(id);
|
||||||
if (membre.isPresent()) {
|
if (membre.isPresent()) {
|
||||||
return ResponseEntity.status(HttpStatus.OK).body(membre);
|
return ResponseEntity.status(HttpStatus.OK).body(membre);
|
||||||
} else {
|
} else {
|
||||||
|
@ -107,15 +102,15 @@ public class MembreController {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Rechercher un membre par l'Id de sa team
|
* Rechercher un membre par l'Id de sa team
|
||||||
* @return
|
*
|
||||||
* http://localhost:8088/membres/1
|
* @return http://localhost:8088/membres/1
|
||||||
*/
|
*/
|
||||||
@GetMapping(value = "team/{team_id}")
|
@GetMapping(value = "team/{team_id}")
|
||||||
//@PreAuthorize("hasRole('ROLE_PARENT') or hasRole('ROLE_ENFANT')")
|
//@PreAuthorize("hasRole('ROLE_PARENT') or hasRole('ROLE_ENFANT')")
|
||||||
public ResponseEntity<?> findByTeamId(@PathVariable int team_id) {
|
public ResponseEntity<?> findByTeamId(@PathVariable int team_id) {
|
||||||
List<Membre> membres = null;
|
List<Membre> membres = null;
|
||||||
try {
|
try {
|
||||||
membres = membreRepo.FindMembresByTeam(team_id);
|
membres = membreRepository.FindMembresByTeam(team_id);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
return ResponseEntity.status(HttpStatus.NOT_FOUND).body(null);
|
return ResponseEntity.status(HttpStatus.NOT_FOUND).body(null);
|
||||||
}
|
}
|
||||||
|
@ -124,11 +119,11 @@ public class MembreController {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Inscription
|
* Inscription
|
||||||
* @return
|
*
|
||||||
* http://localhost:8088/membres/sign-up
|
* @return http://localhost:8088/membres/sign-up
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@PostMapping(value="/sign-up")
|
@PostMapping(value = "/sign-up")
|
||||||
public ResponseEntity<JsonWebToken> signUp(@RequestBody Membre membre) {
|
public ResponseEntity<JsonWebToken> signUp(@RequestBody Membre membre) {
|
||||||
try {
|
try {
|
||||||
return ResponseEntity.ok(new JsonWebToken(membreService.signup(membre)));
|
return ResponseEntity.ok(new JsonWebToken(membreService.signup(membre)));
|
||||||
|
@ -139,18 +134,18 @@ public class MembreController {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Ajout d'un membre
|
* Ajout d'un membre
|
||||||
* @return
|
*
|
||||||
* http://localhost:8088/membres/add
|
* @return http://localhost:8088/membres/add/1
|
||||||
*/
|
*/
|
||||||
@PostMapping(value="/add/{team_id}", produces="application/json", consumes= "application/json")
|
@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<?> addMembre(@RequestBody Membre membre, @PathVariable Integer team_id){
|
public ResponseEntity<?> addMembre(@RequestBody Membre membre, @PathVariable Integer team_id) {
|
||||||
Membre resultMembre = null;
|
Membre resultMembre = null;
|
||||||
try{
|
try {
|
||||||
Team team = new Team();
|
Team team = new Team();
|
||||||
team.setId(team_id);
|
team.setId(team_id);
|
||||||
membre.setTeam(team);
|
membre.setTeam(team);
|
||||||
//resultMembre = membreRepo.saveAndFlush(membre);
|
//resultMembre = membreRepository.saveAndFlush(membre);
|
||||||
return ResponseEntity.ok(new JsonWebToken(membreService.signup(membre)));
|
return ResponseEntity.ok(new JsonWebToken(membreService.signup(membre)));
|
||||||
} 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());
|
||||||
|
@ -160,24 +155,26 @@ public class MembreController {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Modifier une commande par son Id
|
* Modifier un membre par son Id
|
||||||
* @return
|
|
||||||
* http://localhost:8088/membres/update/1
|
|
||||||
*
|
*
|
||||||
|
* @return http://localhost:8088/membres/update/1
|
||||||
*/
|
*/
|
||||||
@PutMapping("/update/{id}")
|
@PutMapping("/update/{team_id}/{id}")
|
||||||
//@PreAuthorize("hasRole('ROLE_PARENT')")
|
//@PreAuthorize("hasRole('ROLE_PARENT')")
|
||||||
public ResponseEntity<?> updateMembre(@RequestBody Membre membre, @PathVariable int id){
|
public ResponseEntity<?> updateMembre(@RequestBody Membre membre, @PathVariable int id, @PathVariable int team_id) {
|
||||||
Optional<Membre> membreUpdate;
|
Optional<Membre> membreUpdate;
|
||||||
try {
|
try {
|
||||||
membreUpdate = membreRepo.findById(id);
|
membreUpdate = membreRepository.findById(id);
|
||||||
// membre trouvé
|
// membre trouvé
|
||||||
if(membreUpdate.isPresent()){
|
if (membreUpdate.isPresent()) {
|
||||||
membre.setId(membreUpdate.get().getId());
|
membre.setId(membreRepository.findById(id).get().getId());
|
||||||
membreRepo.save(membre);
|
Team team = new Team();
|
||||||
|
team.setId(team_id);
|
||||||
|
membre.setTeam(team);
|
||||||
|
membreRepository.save(membre);
|
||||||
}
|
}
|
||||||
//membre inconnu
|
//membre inconnu
|
||||||
else{
|
else {
|
||||||
MembreNotFoundException membreNotFoundException = new MembreNotFoundException(id);
|
MembreNotFoundException membreNotFoundException = new MembreNotFoundException(id);
|
||||||
return ResponseEntity.status(HttpStatus.NOT_FOUND).body(membreNotFoundException.getMessage());
|
return ResponseEntity.status(HttpStatus.NOT_FOUND).body(membreNotFoundException.getMessage());
|
||||||
}
|
}
|
||||||
|
@ -191,15 +188,15 @@ public class MembreController {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Supprimer un membre par son Id
|
* Supprimer un membre par son Id
|
||||||
* @return
|
*
|
||||||
* http://localhost:8088/membres/delete/1
|
* @return http://localhost:8088/membres/delete/1
|
||||||
*/
|
*/
|
||||||
@DeleteMapping(value = "/delete/{id}")
|
@DeleteMapping(value = "/delete/{id}")
|
||||||
//@PreAuthorize("hasRole('ROLE_PARENT')")
|
//@PreAuthorize("hasRole('ROLE_PARENT')")
|
||||||
public ResponseEntity<?> deleteMembre(@PathVariable int id){
|
public ResponseEntity<?> deleteMembre(@PathVariable int id) {
|
||||||
try {
|
try {
|
||||||
membreRepo.getById(id);
|
membreRepository.getById(id);
|
||||||
membreRepo.deleteById(id);
|
membreRepository.deleteById(id);
|
||||||
return ResponseEntity.status(HttpStatus.OK).body("Membre supprimé !");
|
return ResponseEntity.status(HttpStatus.OK).body("Membre supprimé !");
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
MembreNotFoundException membreNotFoundException = new MembreNotFoundException(id);
|
MembreNotFoundException membreNotFoundException = new MembreNotFoundException(id);
|
||||||
|
@ -219,16 +216,14 @@ public class MembreController {
|
||||||
}
|
}
|
||||||
|
|
||||||
/********************* Gestion Mot de Passe ************************************/
|
/********************* Gestion Mot de Passe ************************************/
|
||||||
//cette methode ne fonctionne pas parce que ça affiche "trouvé" dans tous les cas
|
|
||||||
@PostMapping("/forgot-password")
|
@PostMapping("/forgot-password")
|
||||||
//@PreAuthorize("hasRole('ROLE_PARENT') or hasRole('ROLE_ENFANT')")
|
|
||||||
public ResponseEntity<?> findUserByEmail(@RequestBody Membre membre) {
|
public ResponseEntity<?> findUserByEmail(@RequestBody Membre membre) {
|
||||||
Membre resultMembre = null;
|
Membre resultMembre = null;
|
||||||
try {
|
try {
|
||||||
resultMembre = membreRepo.chercheEmail(membre.getEmail());
|
resultMembre = membreRepository.chercheEmail(membre.getEmail());
|
||||||
String uuid = UUID.randomUUID().toString();
|
String uuid = UUID.randomUUID().toString();
|
||||||
resultMembre.setPassword(uuid);
|
resultMembre.setPassword(uuid);
|
||||||
membreRepo.saveAndFlush(resultMembre);
|
membreRepository.saveAndFlush(resultMembre);
|
||||||
return ResponseEntity.status(HttpStatus.OK).body(uuid);
|
return ResponseEntity.status(HttpStatus.OK).body(uuid);
|
||||||
} catch (EntityNotFoundException e) {
|
} catch (EntityNotFoundException e) {
|
||||||
|
|
||||||
|
@ -238,13 +233,12 @@ public class MembreController {
|
||||||
}
|
}
|
||||||
|
|
||||||
@PutMapping("/reset-password/{uuid}")
|
@PutMapping("/reset-password/{uuid}")
|
||||||
//@PreAuthorize("hasRole('ROLE_PARENT') or hasRole('ROLE_ENFANT')")
|
|
||||||
public ResponseEntity<?> updatePassword(@RequestBody Membre membre, @PathVariable String uuid) throws Exception {
|
public ResponseEntity<?> updatePassword(@RequestBody Membre membre, @PathVariable String uuid) throws Exception {
|
||||||
Membre resultMembre = null;
|
Membre resultMembre = null;
|
||||||
try {
|
try {
|
||||||
resultMembre = membreRepo.findByUUID(uuid);
|
resultMembre = membreRepository.findByUUID(uuid);
|
||||||
resultMembre.setPassword(passwordEncoder.encode(membre.getPassword()));
|
resultMembre.setPassword(passwordEncoder.encode(membre.getPassword()));
|
||||||
membreRepo.saveAndFlush(resultMembre);
|
membreRepository.saveAndFlush(resultMembre);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
return ResponseEntity.status(HttpStatus.NOT_FOUND).body(e.getMessage());
|
return ResponseEntity.status(HttpStatus.NOT_FOUND).body(e.getMessage());
|
||||||
}
|
}
|
||||||
|
|
|
@ -67,7 +67,7 @@ public class MenuController {
|
||||||
}
|
}
|
||||||
|
|
||||||
//Mise a jour d'un menu par son ID
|
//Mise a jour d'un menu par son ID
|
||||||
@PutMapping("/update/{team_id}/{id}")
|
@PutMapping(value="/update/{team_id}/{id}", produces="application/json", consumes= "application/json")
|
||||||
//@PreAuthorize("hasRole('ROLE_PARENT')")
|
//@PreAuthorize("hasRole('ROLE_PARENT')")
|
||||||
public ResponseEntity<?> updateMenu(@RequestBody Menu menu, @PathVariable Integer team_id, @PathVariable Integer id) throws Exception {
|
public ResponseEntity<?> updateMenu(@RequestBody Menu menu, @PathVariable Integer team_id, @PathVariable Integer id) throws Exception {
|
||||||
Menu resultMenu = null;
|
Menu resultMenu = null;
|
||||||
|
|
|
@ -2,43 +2,41 @@ package fr.organizee.controller;
|
||||||
|
|
||||||
import fr.organizee.model.Team;
|
import fr.organizee.model.Team;
|
||||||
import fr.organizee.repository.TeamRepository;
|
import fr.organizee.repository.TeamRepository;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
|
||||||
import org.springframework.http.HttpStatus;
|
import org.springframework.http.HttpStatus;
|
||||||
import org.springframework.http.ResponseEntity;
|
import org.springframework.http.ResponseEntity;
|
||||||
import org.springframework.security.access.prepost.PreAuthorize;
|
|
||||||
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
import javax.persistence.EntityNotFoundException;
|
import javax.persistence.EntityNotFoundException;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
|
|
||||||
/* toto */
|
|
||||||
@RestController
|
@CrossOrigin(origins = "*")
|
||||||
@CrossOrigin("*")
|
|
||||||
@RequestMapping("/teams")
|
@RequestMapping("/teams")
|
||||||
|
@RestController
|
||||||
public class TeamController {
|
public class TeamController {
|
||||||
|
|
||||||
@Autowired
|
private TeamRepository teamRepository;
|
||||||
private TeamRepository teamRepo;
|
|
||||||
|
|
||||||
// @RequestMapping("/teams")
|
/**
|
||||||
@ResponseBody
|
* Contrôleur Team
|
||||||
public String home()
|
*/
|
||||||
{
|
public TeamController(TeamRepository teamRepository) {
|
||||||
StringBuilder sb = new StringBuilder();
|
this.teamRepository = teamRepository;
|
||||||
sb.append("<h1>Affichages des teams</h1>");
|
|
||||||
sb.append("<ul><li><a href='http://localhost:8080/teams/all'>Liste des <strong>teams</strong></a></li>");
|
|
||||||
return sb.toString();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Récupération de toutes les teams
|
|
||||||
|
/**
|
||||||
|
* Rechercher toutes les teams
|
||||||
|
*
|
||||||
|
* @return http://localhost:8088/teams/all
|
||||||
|
*/
|
||||||
@GetMapping(value = "/all")
|
@GetMapping(value = "/all")
|
||||||
//@PreAuthorize("hasRole('ROLE_PARENT')")
|
//@PreAuthorize("hasRole('ROLE_PARENT')")
|
||||||
public ResponseEntity<?> getAllTeam(){
|
public ResponseEntity<?> getAllTeam() {
|
||||||
List<Team> liste = null;
|
List<Team> liste = null;
|
||||||
try
|
try {
|
||||||
{
|
liste = teamRepository.findAll();
|
||||||
liste = teamRepo.findAll();
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
return ResponseEntity.status(HttpStatus.NOT_FOUND).body(null);
|
return ResponseEntity.status(HttpStatus.NOT_FOUND).body(null);
|
||||||
}
|
}
|
||||||
|
@ -46,13 +44,18 @@ public class TeamController {
|
||||||
return ResponseEntity.status(HttpStatus.OK).body(liste);
|
return ResponseEntity.status(HttpStatus.OK).body(liste);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Rechercher une team par son Id
|
||||||
|
*
|
||||||
|
* @return http://localhost:8088/teams/1
|
||||||
|
*/
|
||||||
@GetMapping(value = "/{id}")
|
@GetMapping(value = "/{id}")
|
||||||
//@PreAuthorize("hasRole('ROLE_PARENT') or hasRole('ROLE_ENFANT')")
|
//@PreAuthorize("hasRole('ROLE_PARENT') or hasRole('ROLE_ENFANT')")
|
||||||
public ResponseEntity<?> findTeamById(@PathVariable int id){
|
public ResponseEntity<?> findTeamById(@PathVariable int id) {
|
||||||
Optional<Team> liste = null;
|
Optional<Team> liste = null;
|
||||||
try
|
try {
|
||||||
{
|
liste = teamRepository.findById(id);
|
||||||
liste = teamRepo.findById(id);
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
return ResponseEntity.status(HttpStatus.NOT_FOUND).body(null);
|
return ResponseEntity.status(HttpStatus.NOT_FOUND).body(null);
|
||||||
}
|
}
|
||||||
|
@ -60,12 +63,17 @@ public class TeamController {
|
||||||
return ResponseEntity.status(HttpStatus.OK).body(liste);
|
return ResponseEntity.status(HttpStatus.OK).body(liste);
|
||||||
}
|
}
|
||||||
|
|
||||||
@PostMapping(value="/add", produces="application/json", consumes="application/json")
|
/**
|
||||||
|
* Création d'une team
|
||||||
|
*
|
||||||
|
* @return http://localhost:8088/teams/add
|
||||||
|
*/
|
||||||
|
@PostMapping(value = "/add", produces = "application/json", consumes = "application/json")
|
||||||
//@PreAuthorize("hasRole('ROLE_PARENT')")
|
//@PreAuthorize("hasRole('ROLE_PARENT')")
|
||||||
public ResponseEntity<?> addTeam(@RequestBody Team team){
|
public ResponseEntity<?> addTeam(@RequestBody Team team) {
|
||||||
Team resultTeam = null;
|
Team resultTeam = null;
|
||||||
try {
|
try {
|
||||||
resultTeam = teamRepo.saveAndFlush(team);
|
resultTeam = teamRepository.saveAndFlush(team);
|
||||||
} 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());
|
||||||
}
|
}
|
||||||
|
@ -73,12 +81,17 @@ public class TeamController {
|
||||||
return ResponseEntity.status(HttpStatus.CREATED).body(resultTeam);
|
return ResponseEntity.status(HttpStatus.CREATED).body(resultTeam);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Modifier une teamm par son Id
|
||||||
|
*
|
||||||
|
* @return http://localhost:8088/teams/update/1
|
||||||
|
*/
|
||||||
@PutMapping("/update/{id}")
|
@PutMapping("/update/{id}")
|
||||||
//@PreAuthorize("hasRole('ROLE_PARENT')")
|
//@PreAuthorize("hasRole('ROLE_PARENT')")
|
||||||
public ResponseEntity<?> updateTeam(@RequestBody Team team, @PathVariable Integer id) throws Exception {
|
public ResponseEntity<?> updateTeam(@RequestBody Team team, @PathVariable Integer id) throws Exception {
|
||||||
Team resultTeam = null;
|
Team resultTeam = null;
|
||||||
try {
|
try {
|
||||||
resultTeam = teamRepo.save(team);
|
resultTeam = teamRepository.save(team);
|
||||||
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
return ResponseEntity.status(HttpStatus.NOT_FOUND).body(e.getMessage());
|
return ResponseEntity.status(HttpStatus.NOT_FOUND).body(e.getMessage());
|
||||||
|
@ -87,12 +100,17 @@ public class TeamController {
|
||||||
return ResponseEntity.status(HttpStatus.OK).body(resultTeam);
|
return ResponseEntity.status(HttpStatus.OK).body(resultTeam);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Supprimer une team par son Id
|
||||||
|
*
|
||||||
|
* @return http://localhost:8088/teams/delete/1
|
||||||
|
*/
|
||||||
@DeleteMapping(value = "/delete/{id}")
|
@DeleteMapping(value = "/delete/{id}")
|
||||||
//@PreAuthorize("hasRole('ROLE_PARENT')")
|
//@PreAuthorize("hasRole('ROLE_PARENT')")
|
||||||
public ResponseEntity<?> deleteTeam(@PathVariable int id){
|
public ResponseEntity<?> deleteTeam(@PathVariable int id) {
|
||||||
try {
|
try {
|
||||||
teamRepo.delete(teamRepo.getById(id));
|
teamRepository.delete(teamRepository.getById(id));
|
||||||
//membreRepo.deleteById(id);
|
//membreRepository.deleteById(id);
|
||||||
return ResponseEntity.status(HttpStatus.OK).body("Team effacée !");
|
return ResponseEntity.status(HttpStatus.OK).body("Team effacée !");
|
||||||
|
|
||||||
} catch (EntityNotFoundException e) {
|
} catch (EntityNotFoundException e) {
|
||||||
|
|
|
@ -1,8 +1,9 @@
|
||||||
package fr.organizee.model;
|
package fr.organizee.model;
|
||||||
|
|
||||||
import com.fasterxml.jackson.annotation.JsonIgnore;
|
|
||||||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
|
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
|
||||||
import com.sun.istack.NotNull;
|
import com.sun.istack.NotNull;
|
||||||
|
import org.hibernate.annotations.SQLDelete;
|
||||||
|
import org.hibernate.annotations.Where;
|
||||||
|
|
||||||
import javax.persistence.*;
|
import javax.persistence.*;
|
||||||
import java.time.LocalDate;
|
import java.time.LocalDate;
|
||||||
|
@ -10,6 +11,9 @@ import java.util.List;
|
||||||
|
|
||||||
|
|
||||||
@Entity
|
@Entity
|
||||||
|
@Table(name = "membre")
|
||||||
|
@SQLDelete(sql = "UPDATE membre SET deleted = true WHERE id=?")
|
||||||
|
@Where(clause = "deleted=false")
|
||||||
public class Membre {
|
public class Membre {
|
||||||
@Id
|
@Id
|
||||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||||
|
@ -33,14 +37,14 @@ public class Membre {
|
||||||
private String isAdmin;
|
private String isAdmin;
|
||||||
private String couleur;
|
private String couleur;
|
||||||
private String smiley;
|
private String smiley;
|
||||||
// @ManyToOne
|
|
||||||
// @JoinColumn(name="TEAM_ID")
|
|
||||||
// @JsonIgnore
|
|
||||||
@ManyToOne
|
@ManyToOne
|
||||||
@JoinColumn(name="TEAM_ID")
|
@JoinColumn(name = "TEAM_ID")
|
||||||
@JsonIgnoreProperties("membre")
|
@JsonIgnoreProperties("membre")
|
||||||
private Team team;
|
private Team team;
|
||||||
|
|
||||||
|
private boolean deleted = Boolean.FALSE;
|
||||||
|
|
||||||
public Membre() {
|
public Membre() {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -52,56 +56,77 @@ public class Membre {
|
||||||
this.email = email;
|
this.email = email;
|
||||||
this.password = password;
|
this.password = password;
|
||||||
this.team = team;
|
this.team = team;
|
||||||
this.roleList=roleList;
|
this.roleList = roleList;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean isDeleted() {
|
||||||
|
return deleted;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setDeleted(boolean deleted) {
|
||||||
|
this.deleted = deleted;
|
||||||
|
}
|
||||||
|
|
||||||
public int getId() {
|
public int getId() {
|
||||||
return id;
|
return id;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setId(int id) {
|
public void setId(int id) {
|
||||||
this.id = id;
|
this.id = id;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getNom() {
|
public String getNom() {
|
||||||
return nom;
|
return nom;
|
||||||
}
|
}
|
||||||
public String getCouleur() {
|
|
||||||
return couleur;
|
|
||||||
}
|
|
||||||
public void setCouleur(String couleur) {
|
|
||||||
this.couleur = couleur;
|
|
||||||
}
|
|
||||||
public void setNom(String nom) {
|
public void setNom(String nom) {
|
||||||
this.nom = nom;
|
this.nom = nom;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String getCouleur() {
|
||||||
|
return couleur;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setCouleur(String couleur) {
|
||||||
|
this.couleur = couleur;
|
||||||
|
}
|
||||||
|
|
||||||
public String getPrenom() {
|
public String getPrenom() {
|
||||||
return prenom;
|
return prenom;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setPrenom(String prenom) {
|
public void setPrenom(String prenom) {
|
||||||
this.prenom = prenom;
|
this.prenom = prenom;
|
||||||
}
|
}
|
||||||
|
|
||||||
public LocalDate getDateNaissance() {
|
public LocalDate getDateNaissance() {
|
||||||
return dateNaissance;
|
return dateNaissance;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setDateNaissance(LocalDate dateNaissance) {
|
public void setDateNaissance(LocalDate dateNaissance) {
|
||||||
this.dateNaissance = dateNaissance;
|
this.dateNaissance = dateNaissance;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getEmail() {
|
public String getEmail() {
|
||||||
return email;
|
return email;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setEmail(String email) {
|
public void setEmail(String email) {
|
||||||
this.email = email;
|
this.email = email;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getPassword() {
|
public String getPassword() {
|
||||||
return password;
|
return password;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setPassword(String password) {
|
public void setPassword(String password) {
|
||||||
this.password = password;
|
this.password = password;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getIsAdmin() {
|
public String getIsAdmin() {
|
||||||
return isAdmin;
|
return isAdmin;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setIsAdmin(String isAdmin) {
|
public void setIsAdmin(String isAdmin) {
|
||||||
this.isAdmin = isAdmin;
|
this.isAdmin = isAdmin;
|
||||||
}
|
}
|
||||||
|
@ -109,6 +134,7 @@ public class Membre {
|
||||||
public Team getTeam() {
|
public Team getTeam() {
|
||||||
return team;
|
return team;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setTeam(Team team) {
|
public void setTeam(Team team) {
|
||||||
this.team = team;
|
this.team = team;
|
||||||
}
|
}
|
||||||
|
@ -116,6 +142,7 @@ public class Membre {
|
||||||
public List<Role> getRoleList() {
|
public List<Role> getRoleList() {
|
||||||
return roleList;
|
return roleList;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setRoleList(List<Role> roleList) {
|
public void setRoleList(List<Role> roleList) {
|
||||||
this.roleList = roleList;
|
this.roleList = roleList;
|
||||||
}
|
}
|
||||||
|
@ -136,4 +163,3 @@ public class Membre {
|
||||||
'}';
|
'}';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -15,7 +15,7 @@ public class Menu {
|
||||||
private String repasSoir;
|
private String repasSoir;
|
||||||
@ManyToOne
|
@ManyToOne
|
||||||
@JoinColumn(name="TEAM_ID")
|
@JoinColumn(name="TEAM_ID")
|
||||||
@JsonIgnoreProperties({"menu","membre"})
|
@JsonIgnoreProperties({"menu"})
|
||||||
private Team team;
|
private Team team;
|
||||||
|
|
||||||
public Menu() {
|
public Menu() {
|
||||||
|
|
|
@ -9,7 +9,6 @@ public enum Role implements GrantedAuthority {
|
||||||
|
|
||||||
ROLE_PARENT, ROLE_ENFANT;
|
ROLE_PARENT, ROLE_ENFANT;
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getAuthority() {
|
public String getAuthority() {
|
||||||
return name();
|
return name();
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,7 +12,7 @@ import java.util.List;
|
||||||
@Repository
|
@Repository
|
||||||
public interface MenuRepository extends JpaRepository <Menu, Integer> {
|
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 order by date_menu ASC", nativeQuery = true)
|
||||||
List<Menu> FindMenusByTeam(@Param("team_id") int team_id);
|
List<Menu> FindMenusByTeam(@Param("team_id") int team_id);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,8 +1,10 @@
|
||||||
package fr.organizee.service;
|
package fr.organizee.service;
|
||||||
|
|
||||||
import java.util.List;
|
import fr.organizee.exception.ExistingUsernameException;
|
||||||
import java.util.Optional;
|
import fr.organizee.exception.InvalidCredentialsException;
|
||||||
|
import fr.organizee.model.Membre;
|
||||||
|
import fr.organizee.repository.MembreRepository;
|
||||||
|
import fr.organizee.security.JwtTokenProvider;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.security.authentication.AuthenticationManager;
|
import org.springframework.security.authentication.AuthenticationManager;
|
||||||
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
|
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
|
||||||
|
@ -10,11 +12,8 @@ import org.springframework.security.core.AuthenticationException;
|
||||||
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
|
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
import fr.organizee.exception.ExistingUsernameException;
|
import java.util.List;
|
||||||
import fr.organizee.exception.InvalidCredentialsException;
|
import java.util.Optional;
|
||||||
import fr.organizee.model.Membre;
|
|
||||||
import fr.organizee.repository.MembreRepository;
|
|
||||||
import fr.organizee.security.JwtTokenProvider;
|
|
||||||
|
|
||||||
@Service
|
@Service
|
||||||
public class
|
public class
|
||||||
|
@ -59,6 +58,7 @@ MembreServiceImpl implements MembreService {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<Membre> findAllUsers() {
|
public List<Membre> findAllUsers() {
|
||||||
return membreRepository.findAll();
|
return membreRepository.findAll();
|
||||||
|
@ -81,4 +81,3 @@ MembreServiceImpl implements MembreService {
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue