Merge branch 'dev' into cecile
This commit is contained in:
		
						commit
						9be7dc59e5
					
				
					 33 changed files with 1004 additions and 197 deletions
				
			
		
							
								
								
									
										
											BIN
										
									
								
								.file.swp
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										
											BIN
										
									
								
								.file.swp
									
										
									
									
									
										Normal file
									
								
							
										
											Binary file not shown.
										
									
								
							
							
								
								
									
										1
									
								
								.idea/compiler.xml
									
										
									
										generated
									
									
									
								
							
							
						
						
									
										1
									
								
								.idea/compiler.xml
									
										
									
										generated
									
									
									
								
							| 
						 | 
				
			
			@ -7,6 +7,7 @@
 | 
			
		|||
        <sourceTestOutputDir name="target/generated-test-sources/test-annotations" />
 | 
			
		||||
        <outputRelativeToContentRoot value="true" />
 | 
			
		||||
        <module name="Organizee" />
 | 
			
		||||
        <module name="organizee" />
 | 
			
		||||
      </profile>
 | 
			
		||||
    </annotationProcessing>
 | 
			
		||||
  </component>
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
							
								
								
									
										3
									
								
								.idea/misc.xml
									
										
									
										generated
									
									
									
								
							
							
						
						
									
										3
									
								
								.idea/misc.xml
									
										
									
										generated
									
									
									
								
							| 
						 | 
				
			
			@ -11,4 +11,7 @@
 | 
			
		|||
  <component name="ProjectRootManager" version="2" languageLevel="JDK_17" default="true" project-jdk-name="openjdk-17" project-jdk-type="JavaSDK">
 | 
			
		||||
    <output url="file://$PROJECT_DIR$/out" />
 | 
			
		||||
  </component>
 | 
			
		||||
  <component name="ProjectType">
 | 
			
		||||
    <option name="id" value="jpab" />
 | 
			
		||||
  </component>
 | 
			
		||||
</project>
 | 
			
		||||
							
								
								
									
										18
									
								
								pom.xml
									
										
									
									
									
								
							
							
						
						
									
										18
									
								
								pom.xml
									
										
									
									
									
								
							| 
						 | 
				
			
			@ -2,12 +2,7 @@
 | 
			
		|||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 | 
			
		||||
	xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
 | 
			
		||||
	<modelVersion>4.0.0</modelVersion>
 | 
			
		||||
	<parent>
 | 
			
		||||
		<groupId>org.springframework.boot</groupId>
 | 
			
		||||
		<artifactId>spring-boot-starter-parent</artifactId>
 | 
			
		||||
		<version>2.6.1</version>
 | 
			
		||||
		<relativePath/> <!-- lookup parent from repository -->
 | 
			
		||||
	</parent>
 | 
			
		||||
 | 
			
		||||
	<groupId>fr.organizee</groupId>
 | 
			
		||||
	<artifactId>organizee</artifactId>
 | 
			
		||||
	<version>0.0.1-SNAPSHOT</version>
 | 
			
		||||
| 
						 | 
				
			
			@ -16,6 +11,12 @@
 | 
			
		|||
	<properties>
 | 
			
		||||
		<java.version>11</java.version>
 | 
			
		||||
	</properties>
 | 
			
		||||
	<parent>
 | 
			
		||||
		<groupId>org.springframework.boot</groupId>
 | 
			
		||||
		<artifactId>spring-boot-starter-parent</artifactId>
 | 
			
		||||
		<version>2.6.1</version>
 | 
			
		||||
		<relativePath/> <!-- lookup parent from repository -->
 | 
			
		||||
	</parent>
 | 
			
		||||
	<dependencies>
 | 
			
		||||
		<dependency>
 | 
			
		||||
			<groupId>org.springframework.boot</groupId>
 | 
			
		||||
| 
						 | 
				
			
			@ -38,7 +39,10 @@
 | 
			
		|||
			<groupId>org.springframework.boot</groupId>
 | 
			
		||||
			<artifactId>spring-boot-starter-web</artifactId>
 | 
			
		||||
		</dependency>
 | 
			
		||||
 | 
			
		||||
		<dependency>
 | 
			
		||||
			<groupId>org.springframework.boot</groupId>
 | 
			
		||||
			<artifactId>spring-boot-starter-mail</artifactId>
 | 
			
		||||
		</dependency>
 | 
			
		||||
		<dependency>
 | 
			
		||||
			<groupId>mysql</groupId>
 | 
			
		||||
			<artifactId>mysql-connector-java</artifactId>
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -1,10 +1,7 @@
 | 
			
		|||
package fr.organizee.controller;
 | 
			
		||||
 | 
			
		||||
import fr.organizee.model.Contact;
 | 
			
		||||
import fr.organizee.model.Membre;
 | 
			
		||||
import fr.organizee.model.Team;
 | 
			
		||||
import fr.organizee.repository.ContactRepository;
 | 
			
		||||
import fr.organizee.repository.TeamRepository;
 | 
			
		||||
import org.springframework.beans.factory.annotation.Autowired;
 | 
			
		||||
import org.springframework.http.HttpStatus;
 | 
			
		||||
import org.springframework.http.ResponseEntity;
 | 
			
		||||
| 
						 | 
				
			
			@ -23,8 +20,10 @@ public class ContactController {
 | 
			
		|||
    @Autowired
 | 
			
		||||
    private ContactRepository contactRepo;
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
    //Récupère les infos d'un contact par son ID
 | 
			
		||||
    @GetMapping(value = "/{id}")
 | 
			
		||||
    @PreAuthorize("hasRole('ROLE_PARENT') or hasRole('ROLE_ENFANT')")
 | 
			
		||||
    //@PreAuthorize("hasRole('ROLE_PARENT') or hasRole('ROLE_ENFANT')")
 | 
			
		||||
    public ResponseEntity<?> findById(@PathVariable int id){
 | 
			
		||||
        Optional<Contact> contact = null;
 | 
			
		||||
        try
 | 
			
		||||
| 
						 | 
				
			
			@ -37,8 +36,9 @@ public class ContactController {
 | 
			
		|||
        return ResponseEntity.status(HttpStatus.OK).body(contact);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    //Récupère les infos d'un contact par la 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){
 | 
			
		||||
        List<Contact> contacts = null;
 | 
			
		||||
        try
 | 
			
		||||
| 
						 | 
				
			
			@ -47,12 +47,12 @@ public class ContactController {
 | 
			
		|||
        } catch (Exception e) {
 | 
			
		||||
            return ResponseEntity.status(HttpStatus.NOT_FOUND).body(null);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        return ResponseEntity.status(HttpStatus.OK).body(contacts);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    //Ajoute un nouveau contact
 | 
			
		||||
    @PostMapping(value="/add")
 | 
			
		||||
    @PreAuthorize("hasRole('ROLE_PARENT') or hasRole('ROLE_ENFANT')")
 | 
			
		||||
    //@PreAuthorize("hasRole('ROLE_PARENT') or hasRole('ROLE_ENFANT')")
 | 
			
		||||
    public ResponseEntity<?> addContact(@RequestBody Contact contact){
 | 
			
		||||
        Contact resultContact = null;
 | 
			
		||||
        try {
 | 
			
		||||
| 
						 | 
				
			
			@ -64,8 +64,9 @@ public class ContactController {
 | 
			
		|||
        return ResponseEntity.status(HttpStatus.CREATED).body(resultContact);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    //Mise à jour du contact par son ID
 | 
			
		||||
    @PutMapping("/update/{id}")
 | 
			
		||||
    @PreAuthorize("hasRole('ROLE_PARENT') or hasRole('ROLE_ENFANT')")
 | 
			
		||||
    //@PreAuthorize("hasRole('ROLE_PARENT') or hasRole('ROLE_ENFANT')")
 | 
			
		||||
    public ResponseEntity<?> updateContact(@RequestBody Contact contact, @PathVariable Integer id) throws Exception {
 | 
			
		||||
        Contact resultContact = null;
 | 
			
		||||
        try {
 | 
			
		||||
| 
						 | 
				
			
			@ -78,8 +79,9 @@ public class ContactController {
 | 
			
		|||
        return ResponseEntity.status(HttpStatus.OK).body(resultContact);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    //Efface le contact par on ID
 | 
			
		||||
    @DeleteMapping(value = "/delete/{id}")
 | 
			
		||||
    @PreAuthorize("hasRole('ROLE_PARENT')")
 | 
			
		||||
    //@PreAuthorize("hasRole('ROLE_PARENT')")
 | 
			
		||||
    public ResponseEntity<?> deleteContact(@PathVariable int id){
 | 
			
		||||
        try {
 | 
			
		||||
            contactRepo.delete(contactRepo.getById(id));
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -0,0 +1,78 @@
 | 
			
		|||
package fr.organizee.controller;
 | 
			
		||||
 | 
			
		||||
import fr.organizee.model.Evenement;
 | 
			
		||||
import fr.organizee.model.Menu;
 | 
			
		||||
import fr.organizee.repository.EvenementRepository;
 | 
			
		||||
import org.springframework.beans.factory.annotation.Autowired;
 | 
			
		||||
import org.springframework.http.HttpStatus;
 | 
			
		||||
import org.springframework.http.ResponseEntity;
 | 
			
		||||
import org.springframework.web.bind.annotation.*;
 | 
			
		||||
 | 
			
		||||
import javax.persistence.EntityNotFoundException;
 | 
			
		||||
import java.util.List;
 | 
			
		||||
import java.util.Optional;
 | 
			
		||||
 | 
			
		||||
@RestController
 | 
			
		||||
@CrossOrigin("*")
 | 
			
		||||
@RequestMapping("/evenements")
 | 
			
		||||
public class EvenementController {
 | 
			
		||||
 | 
			
		||||
    @Autowired
 | 
			
		||||
    private EvenementRepository evenementRepo;
 | 
			
		||||
 | 
			
		||||
    // Recupérer tout les evenements pour une team {team_id}
 | 
			
		||||
    @GetMapping(value = "/team/{team_id}")
 | 
			
		||||
    public ResponseEntity<?> findByTeamId(@PathVariable int team_id){
 | 
			
		||||
        List<Evenement> liste = null;
 | 
			
		||||
        try
 | 
			
		||||
        {
 | 
			
		||||
            liste = evenementRepo.FindEvenementsByTeam(team_id);
 | 
			
		||||
        } catch (Exception e) {
 | 
			
		||||
            return ResponseEntity.status(HttpStatus.NOT_FOUND).body(null);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        return ResponseEntity.status(HttpStatus.OK).body(liste);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    // Ajoute un evenement au calendrier
 | 
			
		||||
    @PostMapping(value="/add", produces="application/json", consumes="application/json")
 | 
			
		||||
    public ResponseEntity<?> addTache(@RequestBody Evenement event){
 | 
			
		||||
        Evenement resultEvent = null;
 | 
			
		||||
        try {
 | 
			
		||||
            resultEvent = evenementRepo.saveAndFlush(event);
 | 
			
		||||
        } catch (Exception e) {
 | 
			
		||||
            return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(e.getMessage());
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        return ResponseEntity.status(HttpStatus.CREATED).body(resultEvent);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    //Mise a jour d'un evenement par son ID
 | 
			
		||||
    @PutMapping("/update/{id}")
 | 
			
		||||
    //@PreAuthorize("hasRole('ROLE_PARENT')")
 | 
			
		||||
    public ResponseEntity<?> updateEvenement(@RequestBody Evenement event, @PathVariable Integer id) throws Exception {
 | 
			
		||||
        Evenement resultEvenement = null;
 | 
			
		||||
        try {
 | 
			
		||||
            resultEvenement = evenementRepo.save(event);
 | 
			
		||||
 | 
			
		||||
        } catch (Exception e) {
 | 
			
		||||
            return ResponseEntity.status(HttpStatus.NOT_FOUND).body(e.getMessage());
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        return ResponseEntity.status(HttpStatus.OK).body(resultEvenement);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    //Efface un evenement par son ID
 | 
			
		||||
    @DeleteMapping(value = "/delete/{id}")
 | 
			
		||||
    //@PreAuthorize("hasRole('ROLE_PARENT')")
 | 
			
		||||
    public ResponseEntity<?> deleteEvenement(@PathVariable int id){
 | 
			
		||||
        try {
 | 
			
		||||
            evenementRepo.delete(evenementRepo.getById(id));
 | 
			
		||||
            return ResponseEntity.status(HttpStatus.OK).body("Evenement effacé !");
 | 
			
		||||
 | 
			
		||||
        } catch (EntityNotFoundException e) {
 | 
			
		||||
 | 
			
		||||
            return ResponseEntity.status(HttpStatus.OK).body("Evenement introuvable !");
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										41
									
								
								src/main/java/fr/organizee/controller/MailController.java
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										41
									
								
								src/main/java/fr/organizee/controller/MailController.java
									
										
									
									
									
										Normal file
									
								
							| 
						 | 
				
			
			@ -0,0 +1,41 @@
 | 
			
		|||
package fr.organizee.controller;
 | 
			
		||||
 | 
			
		||||
import fr.organizee.model.Mail;
 | 
			
		||||
import fr.organizee.service.SendMailService;
 | 
			
		||||
import org.springframework.http.HttpStatus;
 | 
			
		||||
import org.springframework.http.ResponseEntity;
 | 
			
		||||
import org.springframework.web.bind.annotation.*;
 | 
			
		||||
 | 
			
		||||
import javax.mail.MessagingException;
 | 
			
		||||
 | 
			
		||||
@RestController
 | 
			
		||||
@CrossOrigin("*")
 | 
			
		||||
@RequestMapping("/sendmail")
 | 
			
		||||
public class MailController {
 | 
			
		||||
    SendMailService service;
 | 
			
		||||
 | 
			
		||||
    public MailController(SendMailService service) {
 | 
			
		||||
        this.service = service;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    // Envoi de mail en text brut
 | 
			
		||||
    @PostMapping("/text")
 | 
			
		||||
    public ResponseEntity<String> sendMail(@RequestBody Mail mail) {
 | 
			
		||||
        service.sendMail(mail);
 | 
			
		||||
        return new ResponseEntity<>("Email Sent successfully", HttpStatus.OK);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    // Envoi de mail au format HTML
 | 
			
		||||
    @PostMapping("/html")
 | 
			
		||||
    public ResponseEntity<String> sendMailHTML(@RequestBody Mail mail) throws MessagingException {
 | 
			
		||||
        service.sendMailHTML(mail);
 | 
			
		||||
        return new ResponseEntity<>("HTML mail sent successfully", HttpStatus.OK);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    // Envoi du mail avec une piece jointe
 | 
			
		||||
    @PostMapping("/attachment")
 | 
			
		||||
    public ResponseEntity<String> sendAttachmentEmail(@RequestBody Mail mail) throws MessagingException {
 | 
			
		||||
        service.sendMailWithAttachments(mail);
 | 
			
		||||
        return new ResponseEntity<>("Attachment mail sent successfully", HttpStatus.OK);
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			@ -4,26 +4,29 @@ import fr.organizee.dto.JsonWebToken;
 | 
			
		|||
import fr.organizee.dto.MembreDto;
 | 
			
		||||
import fr.organizee.exception.ExistingUsernameException;
 | 
			
		||||
import fr.organizee.exception.InvalidCredentialsException;
 | 
			
		||||
import fr.organizee.exception.MembreNotFoundException;
 | 
			
		||||
import fr.organizee.model.Membre;
 | 
			
		||||
//import fr.organizee.model.Team;
 | 
			
		||||
import fr.organizee.model.Menu;
 | 
			
		||||
import fr.organizee.model.Team;
 | 
			
		||||
import fr.organizee.repository.MembreRepository;
 | 
			
		||||
//import fr.organizee.repository.TeamRepository;
 | 
			
		||||
import fr.organizee.service.MembreService;
 | 
			
		||||
import org.springframework.beans.factory.annotation.Autowired;
 | 
			
		||||
import org.springframework.http.HttpStatus;
 | 
			
		||||
import org.springframework.http.ResponseEntity;
 | 
			
		||||
import org.springframework.security.access.prepost.PreAuthorize;
 | 
			
		||||
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
 | 
			
		||||
import org.springframework.web.bind.annotation.*;
 | 
			
		||||
 | 
			
		||||
import javax.persistence.EntityNotFoundException;
 | 
			
		||||
import java.util.List;
 | 
			
		||||
import java.util.Optional;
 | 
			
		||||
import java.util.UUID;
 | 
			
		||||
import java.util.stream.Collectors;
 | 
			
		||||
 | 
			
		||||
/* toto */
 | 
			
		||||
 | 
			
		||||
@RestController
 | 
			
		||||
@CrossOrigin("*")
 | 
			
		||||
@RequestMapping("/membres")
 | 
			
		||||
@RequestMapping(value="/membres")
 | 
			
		||||
public class MembreController {
 | 
			
		||||
 | 
			
		||||
    @Autowired
 | 
			
		||||
| 
						 | 
				
			
			@ -31,90 +34,101 @@ public class MembreController {
 | 
			
		|||
  
 | 
			
		||||
    @Autowired
 | 
			
		||||
    private MembreService membreService;
 | 
			
		||||
    @Autowired
 | 
			
		||||
    private BCryptPasswordEncoder passwordEncoder;
 | 
			
		||||
 | 
			
		||||
//    @Autowired
 | 
			
		||||
//    private TeamRepository teamRepo;
 | 
			
		||||
    public MembreController() {}
 | 
			
		||||
  
 | 
			
		||||
//    @RequestMapping("/membres")
 | 
			
		||||
    @ResponseBody
 | 
			
		||||
    public String home()
 | 
			
		||||
    {
 | 
			
		||||
        StringBuilder sb = new StringBuilder();
 | 
			
		||||
        sb.append("<h1>Affichages des membres</h1>");
 | 
			
		||||
        sb.append("<ul><li><a href='http://localhost:8080/membres/all'>Liste des <strong>membres</strong></a></li>");
 | 
			
		||||
        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
 | 
			
		||||
     * @return
 | 
			
		||||
     * http://localhost:8088/membres/all
 | 
			
		||||
     */
 | 
			
		||||
    @GetMapping(value = "/all")
 | 
			
		||||
    @PreAuthorize("hasRole('ROLE_PARENT') or hasRole('ROLE_ENFANT')")
 | 
			
		||||
    public ResponseEntity<?> getAll(){
 | 
			
		||||
        List<Membre> liste = null;
 | 
			
		||||
    //@PreAuthorize("hasRole('ROLE_PARENT') or hasRole('ROLE_ENFANT')")
 | 
			
		||||
    public ResponseEntity<?> getAllMembres(){
 | 
			
		||||
        List<Membre> listeMembres;
 | 
			
		||||
        try
 | 
			
		||||
        {
 | 
			
		||||
            liste = membreRepo.findAll();
 | 
			
		||||
            listeMembres = membreRepo.findAll();
 | 
			
		||||
        } catch (Exception e) {
 | 
			
		||||
            return ResponseEntity.status(HttpStatus.NOT_FOUND).body(null);
 | 
			
		||||
            MembreNotFoundException commandeNotFoundException = new MembreNotFoundException();
 | 
			
		||||
            return ResponseEntity.status(HttpStatus.NOT_FOUND).body(commandeNotFoundException.getMessage());
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        return ResponseEntity.status(HttpStatus.OK).body(liste);
 | 
			
		||||
        return ResponseEntity.status(HttpStatus.OK).body(listeMembres);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @GetMapping("/admin/all")
 | 
			
		||||
    /**
 | 
			
		||||
     * Rechercher tous les membres admin
 | 
			
		||||
     * @return
 | 
			
		||||
     * http://localhost:8088/membres/admin/all
 | 
			
		||||
     */
 | 
			
		||||
 | 
			
		||||
    @GetMapping(value="/admin/all")
 | 
			
		||||
    @PreAuthorize("hasRole('ROLE_PARENT')")
 | 
			
		||||
    public List<MembreDto> getAllAdminUsers() {
 | 
			
		||||
        return membreService.findAllUsers().stream().map(appUser -> new MembreDto(appUser.getEmail(), appUser.getRoleList())).collect(Collectors.toList());
 | 
			
		||||
 | 
			
		||||
        return membreService.findAllUsers().stream().map(appUser ->
 | 
			
		||||
                new MembreDto(appUser.getEmail(),
 | 
			
		||||
                        appUser.getRoleList())).collect(Collectors.toList());
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
//    @GetMapping(value = "/team/all")
 | 
			
		||||
//    public ResponseEntity<?> getAllTeam(){
 | 
			
		||||
//        List<Team> liste = null;
 | 
			
		||||
//        try
 | 
			
		||||
//        {
 | 
			
		||||
//            liste = teamRepo.findAll();
 | 
			
		||||
//        } catch (Exception e) {
 | 
			
		||||
//            return ResponseEntity.status(HttpStatus.NOT_FOUND).body(null);
 | 
			
		||||
//        }
 | 
			
		||||
//
 | 
			
		||||
//        return ResponseEntity.status(HttpStatus.OK).body(liste);
 | 
			
		||||
//    }
 | 
			
		||||
    /**
 | 
			
		||||
     * Rechercher un membre par son Id
 | 
			
		||||
     * @return
 | 
			
		||||
     * http://localhost:8088/membres/1
 | 
			
		||||
     */
 | 
			
		||||
 | 
			
		||||
    @GetMapping(value="/{id}")
 | 
			
		||||
    @PreAuthorize("hasRole('ROLE_PARENT') or hasRole('ROLE_ENFANT')")
 | 
			
		||||
    public ResponseEntity<?> findById(@PathVariable int id){
 | 
			
		||||
        Optional<Membre> membre = null;
 | 
			
		||||
        try
 | 
			
		||||
        {
 | 
			
		||||
    //@PreAuthorize("hasRole('ROLE_PARENT') or hasRole('ROLE_ENFANT')")
 | 
			
		||||
    public ResponseEntity<?> getMembreById(@PathVariable int id) {
 | 
			
		||||
        Optional<Membre> membre;
 | 
			
		||||
        try {
 | 
			
		||||
            membre = membreRepo.findById(id);
 | 
			
		||||
            if (membre.isPresent()) {
 | 
			
		||||
                return ResponseEntity.status(HttpStatus.OK).body(membre);
 | 
			
		||||
            } else {
 | 
			
		||||
                MembreNotFoundException membreNotFoundException = new MembreNotFoundException(id);
 | 
			
		||||
                return ResponseEntity.status(HttpStatus.NOT_FOUND).body(membreNotFoundException.getMessage());
 | 
			
		||||
            }
 | 
			
		||||
        } catch (Exception e) {
 | 
			
		||||
            return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).build();
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Rechercher un membre par l'Id de sa team
 | 
			
		||||
     * @return
 | 
			
		||||
     * http://localhost:8088/membres/1
 | 
			
		||||
     */
 | 
			
		||||
    @GetMapping(value = "team/{team_id}")
 | 
			
		||||
    //@PreAuthorize("hasRole('ROLE_PARENT') or hasRole('ROLE_ENFANT')")
 | 
			
		||||
    public ResponseEntity<?> findByTeamId(@PathVariable int team_id) {
 | 
			
		||||
        List<Membre> membres = null;
 | 
			
		||||
        try {
 | 
			
		||||
            membres = membreRepo.FindMembresByTeam(team_id);
 | 
			
		||||
        } catch (Exception e) {
 | 
			
		||||
            return ResponseEntity.status(HttpStatus.NOT_FOUND).body(null);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        return ResponseEntity.status(HttpStatus.OK).body(membre);
 | 
			
		||||
        return ResponseEntity.status(HttpStatus.OK).body(membres);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
//    @GetMapping(value = "/membres/delete/{id}")
 | 
			
		||||
//    public void deleteMembreId(@PathVariable("id") Integer id) {
 | 
			
		||||
//
 | 
			
		||||
//            membreRepo.deleteById(id);
 | 
			
		||||
//
 | 
			
		||||
//    }
 | 
			
		||||
    /**
 | 
			
		||||
     * Inscription
 | 
			
		||||
     * @return
 | 
			
		||||
     * http://localhost:8088/membres/sign-up
 | 
			
		||||
     */
 | 
			
		||||
 | 
			
		||||
    @DeleteMapping(value = "/delete/{id}")
 | 
			
		||||
    @PreAuthorize("hasRole('ROLE_PARENT')")
 | 
			
		||||
    public ResponseEntity<?> deleteMembre(@PathVariable int id){
 | 
			
		||||
        try {
 | 
			
		||||
            membreRepo.delete(membreRepo.getById(id));
 | 
			
		||||
            //membreRepo.deleteById(id);
 | 
			
		||||
            return ResponseEntity.status(HttpStatus.OK).body("Membre effacé !");
 | 
			
		||||
 | 
			
		||||
        } catch (EntityNotFoundException e) {
 | 
			
		||||
 | 
			
		||||
            return ResponseEntity.status(HttpStatus.OK).body("Membre introuvable !");
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @PostMapping("/sign-up")
 | 
			
		||||
    @PostMapping(value="/sign-up")
 | 
			
		||||
    public ResponseEntity<JsonWebToken> signUp(@RequestBody Membre membre) {
 | 
			
		||||
        try {
 | 
			
		||||
            return ResponseEntity.ok(new JsonWebToken(membreService.signup(membre)));
 | 
			
		||||
| 
						 | 
				
			
			@ -123,6 +137,78 @@ public class MembreController {
 | 
			
		|||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Ajout d'un membre
 | 
			
		||||
     * @return
 | 
			
		||||
     * http://localhost:8088/membres/add
 | 
			
		||||
     */
 | 
			
		||||
    @PostMapping(value="/add/{team_id}", produces="application/json", consumes= "application/json")
 | 
			
		||||
    //@PreAuthorize("hasRole('ROLE_PARENT') or hasRole('ROLE_ENFANT')")
 | 
			
		||||
    public ResponseEntity<?> addMembre(@RequestBody Membre membre, @PathVariable Integer team_id){
 | 
			
		||||
        Membre resultMembre = null;
 | 
			
		||||
        try{
 | 
			
		||||
            Team team = new Team();
 | 
			
		||||
            team.setId(team_id);
 | 
			
		||||
            membre.setTeam(team);
 | 
			
		||||
            //resultMembre = membreRepo.saveAndFlush(membre);
 | 
			
		||||
            return ResponseEntity.ok(new JsonWebToken(membreService.signup(membre)));
 | 
			
		||||
        } catch (Exception e) {
 | 
			
		||||
            return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(e.getMessage());
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        //return ResponseEntity.status(HttpStatus.CREATED).body(resultMembre);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Modifier une commande par son Id
 | 
			
		||||
     * @return
 | 
			
		||||
     * http://localhost:8088/membres/update/1
 | 
			
		||||
     *
 | 
			
		||||
     */
 | 
			
		||||
    @PutMapping("/update/{id}")
 | 
			
		||||
    //@PreAuthorize("hasRole('ROLE_PARENT')")
 | 
			
		||||
    public ResponseEntity<?> updateMembre(@RequestBody Membre membre, @PathVariable int id){
 | 
			
		||||
        Optional<Membre> membreUpdate;
 | 
			
		||||
        try {
 | 
			
		||||
            membreUpdate = membreRepo.findById(id);
 | 
			
		||||
            // membre trouvé
 | 
			
		||||
            if(membreUpdate.isPresent()){
 | 
			
		||||
                membre.setId(membreUpdate.get().getId());
 | 
			
		||||
                membreRepo.save(membre);
 | 
			
		||||
            }
 | 
			
		||||
            //membre inconnu
 | 
			
		||||
            else{
 | 
			
		||||
                MembreNotFoundException membreNotFoundException = new MembreNotFoundException(id);
 | 
			
		||||
                return ResponseEntity.status(HttpStatus.NOT_FOUND).body(membreNotFoundException.getMessage());
 | 
			
		||||
            }
 | 
			
		||||
            //gestion de l'erreur
 | 
			
		||||
        } catch (Exception e) {
 | 
			
		||||
            return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).build();
 | 
			
		||||
        }
 | 
			
		||||
        // retour membre
 | 
			
		||||
        return ResponseEntity.status(HttpStatus.OK).body(membre);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Supprimer un membre par son Id
 | 
			
		||||
     * @return
 | 
			
		||||
     *  http://localhost:8088/membres/delete/1
 | 
			
		||||
     */
 | 
			
		||||
    @DeleteMapping(value = "/delete/{id}")
 | 
			
		||||
    //@PreAuthorize("hasRole('ROLE_PARENT')")
 | 
			
		||||
    public ResponseEntity<?> deleteMembre(@PathVariable int id){
 | 
			
		||||
        try {
 | 
			
		||||
            membreRepo.getById(id);
 | 
			
		||||
            membreRepo.deleteById(id);
 | 
			
		||||
            return ResponseEntity.status(HttpStatus.OK).body("Membre supprimé !");
 | 
			
		||||
        } catch (Exception e) {
 | 
			
		||||
            MembreNotFoundException membreNotFoundException = new MembreNotFoundException(id);
 | 
			
		||||
            return ResponseEntity.status(HttpStatus.NOT_FOUND).body(membreNotFoundException.getMessage());
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
    /**************************** Login / Se connceter ****************************/
 | 
			
		||||
    @PostMapping("/sign-in")
 | 
			
		||||
    public ResponseEntity<JsonWebToken> signIn(@RequestBody Membre membre) {
 | 
			
		||||
        try {
 | 
			
		||||
| 
						 | 
				
			
			@ -132,47 +218,37 @@ public class MembreController {
 | 
			
		|||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @PutMapping("/update/{id}")
 | 
			
		||||
    @PreAuthorize("hasRole('ROLE_PARENT')")
 | 
			
		||||
    public ResponseEntity<?> updateMembre(@RequestBody Membre membre, @PathVariable Integer id) throws Exception {
 | 
			
		||||
    /********************* Gestion Mot de Passe ************************************/
 | 
			
		||||
    //cette methode ne fonctionne pas parce que ça affiche "trouvé" dans tous les cas
 | 
			
		||||
    @PostMapping("/forgot-password")
 | 
			
		||||
    //@PreAuthorize("hasRole('ROLE_PARENT') or hasRole('ROLE_ENFANT')")
 | 
			
		||||
    public ResponseEntity<?> findUserByEmail(@RequestBody Membre membre) {
 | 
			
		||||
        Membre resultMembre = null;
 | 
			
		||||
        try {
 | 
			
		||||
            resultMembre = membreRepo.save(membre);
 | 
			
		||||
            resultMembre = membreRepo.chercheEmail(membre.getEmail());
 | 
			
		||||
            String uuid = UUID.randomUUID().toString();
 | 
			
		||||
            resultMembre.setPassword(uuid);
 | 
			
		||||
            membreRepo.saveAndFlush(resultMembre);
 | 
			
		||||
            return ResponseEntity.status(HttpStatus.OK).body(uuid);
 | 
			
		||||
        } catch (EntityNotFoundException e) {
 | 
			
		||||
 | 
			
		||||
            return ResponseEntity.status(HttpStatus.OK).body("Email introuvable !");
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @PutMapping("/reset-password/{uuid}")
 | 
			
		||||
    //@PreAuthorize("hasRole('ROLE_PARENT') or hasRole('ROLE_ENFANT')")
 | 
			
		||||
    public ResponseEntity<?> updatePassword(@RequestBody Membre membre, @PathVariable String uuid) throws Exception {
 | 
			
		||||
        Membre resultMembre = null;
 | 
			
		||||
        try {
 | 
			
		||||
            resultMembre = membreRepo.findByUUID(uuid);
 | 
			
		||||
            resultMembre.setPassword(passwordEncoder.encode(membre.getPassword()));
 | 
			
		||||
            membreRepo.saveAndFlush(resultMembre);
 | 
			
		||||
        } catch (Exception e) {
 | 
			
		||||
            return ResponseEntity.status(HttpStatus.NOT_FOUND).body(e.getMessage());
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        return ResponseEntity.status(HttpStatus.OK).body(resultMembre);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
//    UPDATE SUR UN CHAMPS
 | 
			
		||||
//    @PutMapping("/update/{id}")
 | 
			
		||||
//    public ResponseEntity<?> updateMembre(@RequestBody Membre membre, @PathVariable Integer id) throws Exception {
 | 
			
		||||
//        Membre resultMembre = null;
 | 
			
		||||
//        Membre oldMembre = membreRepo.getById(id);
 | 
			
		||||
//        oldMembre.setNom(membre.getNom());
 | 
			
		||||
//        //Membre resultMembre = membreRepo.getById(id);
 | 
			
		||||
//        try {
 | 
			
		||||
//            resultMembre = membreRepo.save(oldMembre);
 | 
			
		||||
//
 | 
			
		||||
//        } catch (Exception e) {
 | 
			
		||||
//            return ResponseEntity.status(HttpStatus.NOT_FOUND).body(e.getMessage());
 | 
			
		||||
//        }
 | 
			
		||||
//
 | 
			
		||||
//        return ResponseEntity.status(HttpStatus.OK).body(resultMembre);
 | 
			
		||||
//    }
 | 
			
		||||
 | 
			
		||||
//    @GetMapping(value = "/team/{id}")
 | 
			
		||||
//    public ResponseEntity<?> findTeamById(@PathVariable int id){
 | 
			
		||||
//        Optional<Team> liste = null;
 | 
			
		||||
//        try
 | 
			
		||||
//        {
 | 
			
		||||
//            liste = teamRepo.findById(id);
 | 
			
		||||
//        } catch (Exception e) {
 | 
			
		||||
//            return ResponseEntity.status(HttpStatus.NOT_FOUND).body(null);
 | 
			
		||||
//        }
 | 
			
		||||
//
 | 
			
		||||
//        return ResponseEntity.status(HttpStatus.OK).body(liste);
 | 
			
		||||
//    }
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -1,7 +1,7 @@
 | 
			
		|||
package fr.organizee.controller;
 | 
			
		||||
 | 
			
		||||
import fr.organizee.model.Contact;
 | 
			
		||||
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;
 | 
			
		||||
| 
						 | 
				
			
			@ -21,8 +21,9 @@ public class MenuController {
 | 
			
		|||
    @Autowired
 | 
			
		||||
    private MenuRepository menuRepository;
 | 
			
		||||
 | 
			
		||||
    //Récupère les infos d'un menu par son ID
 | 
			
		||||
    @GetMapping(value = "/{id}")
 | 
			
		||||
    @PreAuthorize("hasRole('ROLE_PARENT') or hasRole('ROLE_ENFANT')")
 | 
			
		||||
    //@PreAuthorize("hasRole('ROLE_PARENT') or hasRole('ROLE_ENFANT')")
 | 
			
		||||
    public ResponseEntity<?> findById(@PathVariable int id){
 | 
			
		||||
        Optional<Menu> menu = null;
 | 
			
		||||
        try
 | 
			
		||||
| 
						 | 
				
			
			@ -35,8 +36,9 @@ public class MenuController {
 | 
			
		|||
        return ResponseEntity.status(HttpStatus.OK).body(menu);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    //Récupère les infos des menus par la 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) {
 | 
			
		||||
        List<Menu> menus = null;
 | 
			
		||||
        try {
 | 
			
		||||
| 
						 | 
				
			
			@ -47,11 +49,15 @@ public class MenuController {
 | 
			
		|||
        return ResponseEntity.status(HttpStatus.OK).body(menus);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @PostMapping(value="/add")
 | 
			
		||||
    @PreAuthorize("hasRole('ROLE_PARENT') or hasRole('ROLE_ENFANT')")
 | 
			
		||||
    public ResponseEntity<?> addMenu(@RequestBody Menu menu){
 | 
			
		||||
    //Ajoute un nouveau menu
 | 
			
		||||
    @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, @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());
 | 
			
		||||
| 
						 | 
				
			
			@ -60,22 +66,28 @@ public class MenuController {
 | 
			
		|||
        return ResponseEntity.status(HttpStatus.CREATED).body(resultMenu);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @PutMapping("/update/{id}")
 | 
			
		||||
    @PreAuthorize("hasRole('ROLE_PARENT')")
 | 
			
		||||
    public ResponseEntity<?> updateMenu(@RequestBody Menu menu, @PathVariable Integer id) throws Exception {
 | 
			
		||||
    //Mise a jour d'un menu par son ID
 | 
			
		||||
    @PutMapping("/update/{team_id}/{id}")
 | 
			
		||||
    //@PreAuthorize("hasRole('ROLE_PARENT')")
 | 
			
		||||
    public ResponseEntity<?> updateMenu(@RequestBody Menu menu, @PathVariable Integer team_id, @PathVariable Integer id) throws Exception {
 | 
			
		||||
        Menu resultMenu = null;
 | 
			
		||||
        try {
 | 
			
		||||
            menu.setId(menuRepository.findById(id).get().getId());
 | 
			
		||||
            Team team=new Team();
 | 
			
		||||
            team.setId(team_id);
 | 
			
		||||
            menu.setTeam(team);
 | 
			
		||||
            resultMenu = menuRepository.save(menu);
 | 
			
		||||
 | 
			
		||||
        } catch (Exception e) {
 | 
			
		||||
            return ResponseEntity.status(HttpStatus.NOT_FOUND).body(e.getMessage());
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        return ResponseEntity.status(HttpStatus.OK).body(menuRepository);
 | 
			
		||||
        return ResponseEntity.status(HttpStatus.OK).body(resultMenu);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    //Efface un menu par son ID
 | 
			
		||||
    @DeleteMapping(value = "/delete/{id}")
 | 
			
		||||
    @PreAuthorize("hasRole('ROLE_PARENT')")
 | 
			
		||||
    //@PreAuthorize("hasRole('ROLE_PARENT')")
 | 
			
		||||
    public ResponseEntity<?> deleteMenu(@PathVariable int id){
 | 
			
		||||
        try {
 | 
			
		||||
            menuRepository.delete(menuRepository.getById(id));
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
							
								
								
									
										110
									
								
								src/main/java/fr/organizee/controller/TacheController.java
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										110
									
								
								src/main/java/fr/organizee/controller/TacheController.java
									
										
									
									
									
										Normal file
									
								
							| 
						 | 
				
			
			@ -0,0 +1,110 @@
 | 
			
		|||
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;
 | 
			
		||||
import org.springframework.http.ResponseEntity;
 | 
			
		||||
import org.springframework.security.access.prepost.PreAuthorize;
 | 
			
		||||
import org.springframework.web.bind.annotation.*;
 | 
			
		||||
 | 
			
		||||
import javax.persistence.EntityNotFoundException;
 | 
			
		||||
import java.util.List;
 | 
			
		||||
import java.util.Optional;
 | 
			
		||||
 | 
			
		||||
@RestController
 | 
			
		||||
@CrossOrigin("*")
 | 
			
		||||
@RequestMapping("/taches")
 | 
			
		||||
public class TacheController {
 | 
			
		||||
    @Autowired
 | 
			
		||||
    private TacheRepository tacheRepo;
 | 
			
		||||
 | 
			
		||||
    // Récupère toutes les taches de toutes la base toutes team confondu
 | 
			
		||||
    @GetMapping(value = "/all")
 | 
			
		||||
    public ResponseEntity<?> getAll(){
 | 
			
		||||
        List<Tache> liste = null;
 | 
			
		||||
        try
 | 
			
		||||
        {
 | 
			
		||||
            liste = tacheRepo.findAll();
 | 
			
		||||
        } catch (Exception e) {
 | 
			
		||||
            return ResponseEntity.status(HttpStatus.NOT_FOUND).body(null);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        return ResponseEntity.status(HttpStatus.OK).body(liste);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    // Récupère les infos d'une tache avec son ID
 | 
			
		||||
    @GetMapping(value = "/{id}")
 | 
			
		||||
    public ResponseEntity<?> findById(@PathVariable int id){
 | 
			
		||||
        Optional<Tache> tache = null;
 | 
			
		||||
        try
 | 
			
		||||
        {
 | 
			
		||||
            tache = tacheRepo.findById(id);
 | 
			
		||||
        } catch (Exception e) {
 | 
			
		||||
            return ResponseEntity.status(HttpStatus.NOT_FOUND).body(null);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        return ResponseEntity.status(HttpStatus.OK).body(tache);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    // Efface une tache avec son ID
 | 
			
		||||
    @DeleteMapping(value = "/delete/{id}")
 | 
			
		||||
    public ResponseEntity<?> deleteTache(@PathVariable int id){
 | 
			
		||||
        try {
 | 
			
		||||
            tacheRepo.delete(tacheRepo.getById(id));
 | 
			
		||||
            return ResponseEntity.status(HttpStatus.OK).body("Tache effacée !");
 | 
			
		||||
 | 
			
		||||
        } catch (EntityNotFoundException e) {
 | 
			
		||||
 | 
			
		||||
            return ResponseEntity.status(HttpStatus.OK).body("Tache introuvable !");
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    // Ajoute une 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());
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        return ResponseEntity.status(HttpStatus.CREATED).body(resultTache);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    //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) {
 | 
			
		||||
            return ResponseEntity.status(HttpStatus.NOT_FOUND).body(e.getMessage());
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        return ResponseEntity.status(HttpStatus.OK).body(resultTache);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    //A revoir, résultat a chier, passez par la todolist
 | 
			
		||||
    @GetMapping(value = "team/{team_id}")
 | 
			
		||||
    public ResponseEntity<?> findByTeamId(@PathVariable int team_id){
 | 
			
		||||
        List<Tache> taches = null;
 | 
			
		||||
        try
 | 
			
		||||
        {
 | 
			
		||||
            taches = tacheRepo.FindTachesByTeam(team_id);
 | 
			
		||||
        } catch (Exception e) {
 | 
			
		||||
            return ResponseEntity.status(HttpStatus.NOT_FOUND).body(null);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        return ResponseEntity.status(HttpStatus.OK).body(taches);
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			@ -1,6 +1,5 @@
 | 
			
		|||
package fr.organizee.controller;
 | 
			
		||||
 | 
			
		||||
import fr.organizee.model.Membre;
 | 
			
		||||
import fr.organizee.model.Team;
 | 
			
		||||
import fr.organizee.repository.TeamRepository;
 | 
			
		||||
import org.springframework.beans.factory.annotation.Autowired;
 | 
			
		||||
| 
						 | 
				
			
			@ -34,7 +33,7 @@ public class TeamController {
 | 
			
		|||
 | 
			
		||||
    // Récupération de toutes les teams
 | 
			
		||||
    @GetMapping(value = "/all")
 | 
			
		||||
    @PreAuthorize("hasRole('ROLE_PARENT')")
 | 
			
		||||
    //@PreAuthorize("hasRole('ROLE_PARENT')")
 | 
			
		||||
    public ResponseEntity<?> getAllTeam(){
 | 
			
		||||
        List<Team> liste = null;
 | 
			
		||||
        try
 | 
			
		||||
| 
						 | 
				
			
			@ -48,7 +47,7 @@ public class TeamController {
 | 
			
		|||
    }
 | 
			
		||||
 | 
			
		||||
    @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){
 | 
			
		||||
        Optional<Team> liste = null;
 | 
			
		||||
        try
 | 
			
		||||
| 
						 | 
				
			
			@ -62,7 +61,7 @@ public class TeamController {
 | 
			
		|||
    }
 | 
			
		||||
 | 
			
		||||
    @PostMapping(value="/add", produces="application/json", consumes="application/json")
 | 
			
		||||
    @PreAuthorize("hasRole('ROLE_PARENT')")
 | 
			
		||||
    //@PreAuthorize("hasRole('ROLE_PARENT')")
 | 
			
		||||
    public ResponseEntity<?> addTeam(@RequestBody Team team){
 | 
			
		||||
        Team resultTeam = null;
 | 
			
		||||
        try {
 | 
			
		||||
| 
						 | 
				
			
			@ -75,7 +74,7 @@ public class TeamController {
 | 
			
		|||
    }
 | 
			
		||||
 | 
			
		||||
    @PutMapping("/update/{id}")
 | 
			
		||||
    @PreAuthorize("hasRole('ROLE_PARENT')")
 | 
			
		||||
    //@PreAuthorize("hasRole('ROLE_PARENT')")
 | 
			
		||||
    public ResponseEntity<?> updateTeam(@RequestBody Team team, @PathVariable Integer id) throws Exception {
 | 
			
		||||
        Team resultTeam = null;
 | 
			
		||||
        try {
 | 
			
		||||
| 
						 | 
				
			
			@ -89,7 +88,7 @@ public class TeamController {
 | 
			
		|||
    }
 | 
			
		||||
 | 
			
		||||
    @DeleteMapping(value = "/delete/{id}")
 | 
			
		||||
    @PreAuthorize("hasRole('ROLE_PARENT')")
 | 
			
		||||
    //@PreAuthorize("hasRole('ROLE_PARENT')")
 | 
			
		||||
    public ResponseEntity<?> deleteTeam(@PathVariable int id){
 | 
			
		||||
        try {
 | 
			
		||||
            teamRepo.delete(teamRepo.getById(id));
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -0,0 +1,94 @@
 | 
			
		|||
package fr.organizee.controller;
 | 
			
		||||
 | 
			
		||||
import fr.organizee.model.TodoList;
 | 
			
		||||
import fr.organizee.model.Team;
 | 
			
		||||
import fr.organizee.repository.TodoListRepository;
 | 
			
		||||
import org.springframework.beans.factory.annotation.Autowired;
 | 
			
		||||
import org.springframework.http.HttpStatus;
 | 
			
		||||
import org.springframework.http.ResponseEntity;
 | 
			
		||||
import org.springframework.security.access.prepost.PreAuthorize;
 | 
			
		||||
import org.springframework.web.bind.annotation.*;
 | 
			
		||||
 | 
			
		||||
import javax.persistence.EntityNotFoundException;
 | 
			
		||||
import java.util.List;
 | 
			
		||||
 | 
			
		||||
@RestController
 | 
			
		||||
@CrossOrigin("*")
 | 
			
		||||
@RequestMapping("/todolist")
 | 
			
		||||
public class TodoListController {
 | 
			
		||||
 | 
			
		||||
    @Autowired
 | 
			
		||||
    private TodoListRepository todolistRepo;
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
    @GetMapping(value = "/all")
 | 
			
		||||
    public ResponseEntity<?> getAll(){
 | 
			
		||||
        List<TodoList> liste = null;
 | 
			
		||||
        try
 | 
			
		||||
        {
 | 
			
		||||
            liste = todolistRepo.findAll();
 | 
			
		||||
        } catch (Exception e) {
 | 
			
		||||
            return ResponseEntity.status(HttpStatus.NOT_FOUND).body(null);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        return ResponseEntity.status(HttpStatus.OK).body(liste);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
  //Ajoute une nouvelle ToDoList
 | 
			
		||||
    @PostMapping(value="/add/{team_id}", produces="application/json", consumes= "application/json")
 | 
			
		||||
    //@PreAuthorize("hasRole('ROLE_PARENT') or hasRole('ROLE_ENFANT')")
 | 
			
		||||
    public ResponseEntity<?> addTodolist(@RequestBody TodoList todolist, @PathVariable Integer team_id) {
 | 
			
		||||
         TodoList resultTodolist = null;
 | 
			
		||||
        try {
 | 
			
		||||
            Team team = new Team();
 | 
			
		||||
            team.setId(team_id);
 | 
			
		||||
            todolist.setTeam(team);
 | 
			
		||||
            resultTodolist = todolistRepo.saveAndFlush(todolist);
 | 
			
		||||
        } catch (Exception e) {
 | 
			
		||||
            return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(e.getMessage());
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        return ResponseEntity.status(HttpStatus.CREATED).body(resultTodolist);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @DeleteMapping(value = "/delete/{id}")
 | 
			
		||||
    //@PreAuthorize("hasRole('ROLE_PARENT')")
 | 
			
		||||
    public ResponseEntity<?> deleteTodolist(@PathVariable int id){
 | 
			
		||||
        try {
 | 
			
		||||
            todolistRepo.delete(todolistRepo.getById(id));
 | 
			
		||||
            //membreRepo.deleteById(id);
 | 
			
		||||
            return ResponseEntity.status(HttpStatus.OK).body("Todolist effacée !");
 | 
			
		||||
 | 
			
		||||
        } catch (EntityNotFoundException e) {
 | 
			
		||||
 | 
			
		||||
            return ResponseEntity.status(HttpStatus.OK).body("Todolist introuvable !");
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @GetMapping(value = "/team/{team_id}")
 | 
			
		||||
    public ResponseEntity<?> findByTeamId(@PathVariable int team_id){
 | 
			
		||||
        List<TodoList> todoLists = null;
 | 
			
		||||
        try
 | 
			
		||||
        {
 | 
			
		||||
            todoLists = todolistRepo.FindTodolistByTeam(team_id);
 | 
			
		||||
        } catch (Exception e) {
 | 
			
		||||
            return ResponseEntity.status(HttpStatus.NOT_FOUND).body(null);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        return ResponseEntity.status(HttpStatus.OK).body(todoLists);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    //Met a jour les informations d'une date avec son ID
 | 
			
		||||
    @PutMapping("/update/{id}")
 | 
			
		||||
    public ResponseEntity<?> updateTodolist(@RequestBody TodoList todolist, @PathVariable Integer id) throws Exception {
 | 
			
		||||
        TodoList resultTodolist = null;
 | 
			
		||||
        try {
 | 
			
		||||
            resultTodolist = todolistRepo.save(todolist);
 | 
			
		||||
 | 
			
		||||
        } catch (Exception e) {
 | 
			
		||||
            return ResponseEntity.status(HttpStatus.NOT_FOUND).body(e.getMessage());
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        return ResponseEntity.status(HttpStatus.OK).body(resultTodolist);
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			@ -0,0 +1,13 @@
 | 
			
		|||
package fr.organizee.exception;
 | 
			
		||||
 | 
			
		||||
import org.springframework.http.HttpStatus;
 | 
			
		||||
import org.springframework.web.bind.annotation.ExceptionHandler;
 | 
			
		||||
import org.springframework.web.bind.annotation.ResponseBody;
 | 
			
		||||
import org.springframework.web.bind.annotation.ResponseStatus;
 | 
			
		||||
 | 
			
		||||
public class MembreNotFoundAdvice {
 | 
			
		||||
    @ResponseBody
 | 
			
		||||
    @ExceptionHandler(MembreNotFoundException.class)
 | 
			
		||||
    @ResponseStatus(HttpStatus.NOT_FOUND)
 | 
			
		||||
    String membreNotFoundHandler(MembreNotFoundException ex){return ex.getMessage();}
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			@ -0,0 +1,7 @@
 | 
			
		|||
package fr.organizee.exception;
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
public class MembreNotFoundException  extends RuntimeException{
 | 
			
		||||
    public MembreNotFoundException(int id){ super("Membre" + id + " introuvable");}
 | 
			
		||||
    public MembreNotFoundException(){ super("Membres introuvables");}
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			@ -1,5 +1,6 @@
 | 
			
		|||
package fr.organizee.model;
 | 
			
		||||
 | 
			
		||||
import com.fasterxml.jackson.annotation.JsonIgnore;
 | 
			
		||||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
 | 
			
		||||
 | 
			
		||||
import javax.persistence.*;
 | 
			
		||||
| 
						 | 
				
			
			@ -10,21 +11,23 @@ public class Contact {
 | 
			
		|||
    @Id
 | 
			
		||||
    @GeneratedValue(strategy = GenerationType.IDENTITY)
 | 
			
		||||
    private int id;
 | 
			
		||||
    private String couleur;
 | 
			
		||||
    private String nom;
 | 
			
		||||
    private String prenom;
 | 
			
		||||
    private String telephone;
 | 
			
		||||
    private String email;
 | 
			
		||||
    private String adresse;
 | 
			
		||||
    private LocalDate dateNaissance;
 | 
			
		||||
    @ManyToOne(cascade = CascadeType.MERGE)
 | 
			
		||||
    @ManyToOne
 | 
			
		||||
    @JoinColumn(name = "TEAM_ID")
 | 
			
		||||
    @JsonIgnoreProperties("contact")
 | 
			
		||||
    @JsonIgnoreProperties({"contact", "membre"})
 | 
			
		||||
    private Team team;
 | 
			
		||||
 | 
			
		||||
    public Contact() {
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public Contact(String nom, String prenom, String telephone, String email, String adresse, LocalDate dateNaissance, Team team) {
 | 
			
		||||
    public Contact(String couleur, String nom, String prenom, String telephone, String email, String adresse, LocalDate dateNaissance, Team team) {
 | 
			
		||||
        this.couleur = couleur;
 | 
			
		||||
        this.nom = nom;
 | 
			
		||||
        this.prenom = prenom;
 | 
			
		||||
        this.telephone = telephone;
 | 
			
		||||
| 
						 | 
				
			
			@ -42,6 +45,14 @@ public class Contact {
 | 
			
		|||
        this.id = id;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public String getCouleur() {
 | 
			
		||||
        return couleur;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public void setCouleur(String couleur) {
 | 
			
		||||
        this.couleur = couleur;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public String getNom() {
 | 
			
		||||
        return nom;
 | 
			
		||||
    }
 | 
			
		||||
| 
						 | 
				
			
			@ -93,6 +104,7 @@ public class Contact {
 | 
			
		|||
    public Team getTeam() {
 | 
			
		||||
        return team;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public void setTeam(Team team) {
 | 
			
		||||
        this.team = team;
 | 
			
		||||
    }
 | 
			
		||||
| 
						 | 
				
			
			@ -101,6 +113,7 @@ public class Contact {
 | 
			
		|||
    public String toString() {
 | 
			
		||||
        return "Contact{" +
 | 
			
		||||
                "id=" + id +
 | 
			
		||||
                ", couleur='" + couleur + '\'' +
 | 
			
		||||
                ", nom='" + nom + '\'' +
 | 
			
		||||
                ", prenom='" + prenom + '\'' +
 | 
			
		||||
                ", telephone='" + telephone + '\'' +
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
							
								
								
									
										108
									
								
								src/main/java/fr/organizee/model/Evenement.java
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										108
									
								
								src/main/java/fr/organizee/model/Evenement.java
									
										
									
									
									
										Normal file
									
								
							| 
						 | 
				
			
			@ -0,0 +1,108 @@
 | 
			
		|||
package fr.organizee.model;
 | 
			
		||||
 | 
			
		||||
import com.fasterxml.jackson.annotation.JsonIgnore;
 | 
			
		||||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
 | 
			
		||||
 | 
			
		||||
import javax.persistence.*;
 | 
			
		||||
import java.time.LocalDateTime;
 | 
			
		||||
 | 
			
		||||
@Entity
 | 
			
		||||
public class Evenement {
 | 
			
		||||
    @Id
 | 
			
		||||
    @GeneratedValue(strategy = GenerationType.IDENTITY)
 | 
			
		||||
    private int id;
 | 
			
		||||
    private LocalDateTime start;
 | 
			
		||||
    private LocalDateTime end;
 | 
			
		||||
    private int allDay;
 | 
			
		||||
    private String text;
 | 
			
		||||
    @ManyToOne
 | 
			
		||||
    @JoinColumn(name="MEMBRE_ID")
 | 
			
		||||
    @JsonIgnoreProperties("evenement")
 | 
			
		||||
    private Membre membre;
 | 
			
		||||
    @ManyToOne
 | 
			
		||||
    @JoinColumn(name="TEAM_ID")
 | 
			
		||||
    @JsonIgnoreProperties({"evenement", "membre"})
 | 
			
		||||
    private Team team;
 | 
			
		||||
 | 
			
		||||
    public Evenement() {
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public Evenement(int id, LocalDateTime start, LocalDateTime end, int allDay, String text, Membre membre, Team team) {
 | 
			
		||||
        this.id = id;
 | 
			
		||||
        this.start = start;
 | 
			
		||||
        this.end = end;
 | 
			
		||||
        this.allDay = allDay;
 | 
			
		||||
        this.text = text;
 | 
			
		||||
        this.membre = membre;
 | 
			
		||||
        this.team = team;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public int getId() {
 | 
			
		||||
        return id;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public void setId(int id) {
 | 
			
		||||
        this.id = id;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public LocalDateTime getStart() {
 | 
			
		||||
        return start;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public void setStart(LocalDateTime start) {
 | 
			
		||||
        this.start = start;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public LocalDateTime getEnd() {
 | 
			
		||||
        return end;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public void setEnd(LocalDateTime end) {
 | 
			
		||||
        this.end = end;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public int getAllDay() {
 | 
			
		||||
        return allDay;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public void setAllDay(int allDay) {
 | 
			
		||||
        this.allDay = allDay;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public String getText() {
 | 
			
		||||
        return text;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public void setText(String text) {
 | 
			
		||||
        this.text = text;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public Membre getMembre() {
 | 
			
		||||
        return membre;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public void setMembre(Membre membre) {
 | 
			
		||||
        this.membre = membre;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public Team getTeam() {
 | 
			
		||||
        return team;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public void setTeam(Team team) {
 | 
			
		||||
        this.team = team;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public String toString() {
 | 
			
		||||
        return "Evenement{" +
 | 
			
		||||
                "id=" + id +
 | 
			
		||||
                ", start=" + start +
 | 
			
		||||
                ", end=" + end +
 | 
			
		||||
                ", allDay=" + allDay +
 | 
			
		||||
                ", text='" + text + '\'' +
 | 
			
		||||
                ", membre=" + membre +
 | 
			
		||||
                ", team=" + team +
 | 
			
		||||
                '}';
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										41
									
								
								src/main/java/fr/organizee/model/Mail.java
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										41
									
								
								src/main/java/fr/organizee/model/Mail.java
									
										
									
									
									
										Normal file
									
								
							| 
						 | 
				
			
			@ -0,0 +1,41 @@
 | 
			
		|||
package fr.organizee.model;
 | 
			
		||||
 | 
			
		||||
public class Mail {
 | 
			
		||||
    private String recipient;
 | 
			
		||||
    private String subject;
 | 
			
		||||
    private String message;
 | 
			
		||||
 | 
			
		||||
    public Mail() {
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public Mail(String recipient, String subject, String message) {
 | 
			
		||||
        this.recipient = recipient;
 | 
			
		||||
        this.subject = subject;
 | 
			
		||||
        this.message = message;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public String getRecipient() {
 | 
			
		||||
        return recipient;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public void setRecipient(String recipient) {
 | 
			
		||||
        this.recipient = recipient;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public String getSubject() {
 | 
			
		||||
        return subject;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public void setSubject(String subject) {
 | 
			
		||||
        this.subject = subject;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public String getMessage() {
 | 
			
		||||
        return message;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public void setMessage(String message) {
 | 
			
		||||
        this.message = message;
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -36,7 +36,7 @@ public class Membre {
 | 
			
		|||
    //    @ManyToOne
 | 
			
		||||
//    @JoinColumn(name="TEAM_ID")
 | 
			
		||||
//    @JsonIgnore
 | 
			
		||||
    @ManyToOne(cascade = CascadeType.MERGE)
 | 
			
		||||
    @ManyToOne
 | 
			
		||||
    @JoinColumn(name="TEAM_ID")
 | 
			
		||||
    @JsonIgnoreProperties("membre")
 | 
			
		||||
    private Team team;
 | 
			
		||||
| 
						 | 
				
			
			@ -44,24 +44,17 @@ public class Membre {
 | 
			
		|||
    public Membre() {
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public Membre(String nom, String prenom, LocalDate dateNaissance, @NotNull String email, @NotNull String password, String isAdmin, String couleur, String smiley, Team team, List<Role> roleList) {
 | 
			
		||||
    public Membre(String nom, String prenom, String couleur, LocalDate dateNaissance, Team team, @NotNull String email, @NotNull String password, List<Role> roleList) {
 | 
			
		||||
        this.nom = nom;
 | 
			
		||||
        this.prenom = prenom;
 | 
			
		||||
        this.couleur = couleur;
 | 
			
		||||
        this.dateNaissance = dateNaissance;
 | 
			
		||||
        this.email = email;
 | 
			
		||||
        this.password = password;
 | 
			
		||||
        this.isAdmin = isAdmin;
 | 
			
		||||
        this.couleur = couleur;
 | 
			
		||||
        this.smiley = smiley;
 | 
			
		||||
        this.team = team;
 | 
			
		||||
        this.roleList=roleList;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public Membre(@NotNull String email, @NotNull String password, List<Role> roleList) {
 | 
			
		||||
        this.email = email;
 | 
			
		||||
        this.password = password;
 | 
			
		||||
        this.roleList=roleList;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
    public int getId() {
 | 
			
		||||
| 
						 | 
				
			
			@ -73,6 +66,12 @@ public class Membre {
 | 
			
		|||
    public String getNom() {
 | 
			
		||||
        return nom;
 | 
			
		||||
    }
 | 
			
		||||
    public String getCouleur() {
 | 
			
		||||
        return couleur;
 | 
			
		||||
    }
 | 
			
		||||
    public void setCouleur(String couleur) {
 | 
			
		||||
        this.couleur = couleur;
 | 
			
		||||
    }
 | 
			
		||||
    public void setNom(String nom) {
 | 
			
		||||
        this.nom = nom;
 | 
			
		||||
    }
 | 
			
		||||
| 
						 | 
				
			
			@ -114,22 +113,6 @@ public class Membre {
 | 
			
		|||
        this.team = team;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public String getCouleur() {
 | 
			
		||||
        return couleur;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public void setCouleur(String couleur) {
 | 
			
		||||
        this.couleur = couleur;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public String getSmiley() {
 | 
			
		||||
        return smiley;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public void setSmiley(String smiley) {
 | 
			
		||||
        this.smiley = smiley;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public List<Role> getRoleList() {
 | 
			
		||||
        return roleList;
 | 
			
		||||
    }
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -10,23 +10,22 @@ public class Menu {
 | 
			
		|||
    @Id
 | 
			
		||||
    @GeneratedValue(strategy = GenerationType.IDENTITY)
 | 
			
		||||
    private int id;
 | 
			
		||||
    private String libelle;
 | 
			
		||||
    private LocalDate dateMenu;
 | 
			
		||||
    private int validationProposition;
 | 
			
		||||
    @ManyToOne(cascade = CascadeType.MERGE)
 | 
			
		||||
    @JoinColumn(name="TEAM_ID")
 | 
			
		||||
    @JsonIgnoreProperties("menu")
 | 
			
		||||
    private Team team;
 | 
			
		||||
    private String repasMidi;
 | 
			
		||||
    private String repasSoir;
 | 
			
		||||
    @ManyToOne
 | 
			
		||||
    private Membre membre;
 | 
			
		||||
    @JoinColumn(name="TEAM_ID")
 | 
			
		||||
    @JsonIgnoreProperties({"menu","membre"})
 | 
			
		||||
    private Team team;
 | 
			
		||||
 | 
			
		||||
    public Menu() {
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public Menu(String libelle, LocalDate dateMenu, int validationProposition) {
 | 
			
		||||
        this.libelle = libelle;
 | 
			
		||||
    public Menu(LocalDate dateMenu,String repasMidi, String repasSoir, Team team) {
 | 
			
		||||
        this.dateMenu = dateMenu;
 | 
			
		||||
        this.validationProposition=validationProposition;
 | 
			
		||||
        this.repasMidi= repasMidi;
 | 
			
		||||
        this.repasSoir= repasSoir;
 | 
			
		||||
        this.team = team;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public int getId() {
 | 
			
		||||
| 
						 | 
				
			
			@ -37,14 +36,6 @@ public class Menu {
 | 
			
		|||
        this.id = id;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public String getLibelle() {
 | 
			
		||||
        return libelle;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public void setLibelle(String libelle) {
 | 
			
		||||
        this.libelle = libelle;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public LocalDate getDateMenu() {
 | 
			
		||||
        return dateMenu;
 | 
			
		||||
    }
 | 
			
		||||
| 
						 | 
				
			
			@ -53,12 +44,39 @@ public class Menu {
 | 
			
		|||
        this.dateMenu = dateMenu;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public String getRepasMidi() {
 | 
			
		||||
        return repasMidi;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public void setRepasMidi(String repasMidi) {
 | 
			
		||||
        this.repasMidi = repasMidi;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public String getRepasSoir() {
 | 
			
		||||
        return repasSoir;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public void setRepasSoir(String repasSoir) {
 | 
			
		||||
        this.repasSoir = repasSoir;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public Team getTeam() {
 | 
			
		||||
        return team;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public void setTeam(Team team) {
 | 
			
		||||
        this.team = team;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public String toString() {
 | 
			
		||||
        return "Menu{" +
 | 
			
		||||
                "id=" + id +
 | 
			
		||||
                ", libelle='" + libelle + '\'' +
 | 
			
		||||
                ", dateMenu=" + dateMenu +
 | 
			
		||||
                ", repasMidi='" + repasMidi + '\'' +
 | 
			
		||||
                ", repasSoir='" + repasSoir + '\'' +
 | 
			
		||||
                ", team=" + team +
 | 
			
		||||
                '}';
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -11,7 +11,7 @@ public class Tache {
 | 
			
		|||
    private int id;
 | 
			
		||||
    private String texte;
 | 
			
		||||
    private Boolean etat;
 | 
			
		||||
    @ManyToOne(cascade = CascadeType.MERGE)
 | 
			
		||||
    @ManyToOne
 | 
			
		||||
    @JoinColumn(name="TODOLIST_ID")
 | 
			
		||||
    @JsonIgnoreProperties("tache")
 | 
			
		||||
    private TodoList todolist;
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -1,5 +1,6 @@
 | 
			
		|||
package fr.organizee.model;
 | 
			
		||||
 | 
			
		||||
import com.fasterxml.jackson.annotation.JsonIgnore;
 | 
			
		||||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
 | 
			
		||||
 | 
			
		||||
import javax.persistence.*;
 | 
			
		||||
| 
						 | 
				
			
			@ -12,17 +13,24 @@ public class Team {
 | 
			
		|||
    @GeneratedValue(strategy = GenerationType.IDENTITY)
 | 
			
		||||
    private int id;
 | 
			
		||||
    private String nom;
 | 
			
		||||
    @OneToMany(mappedBy = "team", fetch=FetchType.LAZY)
 | 
			
		||||
 | 
			
		||||
    @OneToMany(mappedBy = "team", fetch=FetchType.LAZY, cascade = CascadeType.ALL)
 | 
			
		||||
    @JsonIgnoreProperties("team")
 | 
			
		||||
    private List<Membre> membres = new ArrayList<>();
 | 
			
		||||
    @OneToMany(mappedBy = "team", fetch=FetchType.LAZY)
 | 
			
		||||
 | 
			
		||||
    @OneToMany(mappedBy = "team", fetch=FetchType.LAZY, cascade = CascadeType.ALL)
 | 
			
		||||
    @JsonIgnoreProperties("team")
 | 
			
		||||
    @JsonIgnore
 | 
			
		||||
    private List<Contact> contacts = new ArrayList<>();
 | 
			
		||||
    @OneToMany(mappedBy = "team", fetch=FetchType.LAZY)
 | 
			
		||||
 | 
			
		||||
    @OneToMany(mappedBy = "team", fetch=FetchType.LAZY, cascade = CascadeType.ALL)
 | 
			
		||||
    @JsonIgnoreProperties("team")
 | 
			
		||||
    @JsonIgnore
 | 
			
		||||
    private List<TodoList> todolists = new ArrayList<>();
 | 
			
		||||
    @OneToMany(mappedBy = "team", fetch=FetchType.LAZY)
 | 
			
		||||
 | 
			
		||||
    @OneToMany(mappedBy = "team", fetch=FetchType.LAZY, cascade = CascadeType.ALL)
 | 
			
		||||
    @JsonIgnoreProperties("team")
 | 
			
		||||
    @JsonIgnore
 | 
			
		||||
    private List<Menu> menus = new ArrayList<>();
 | 
			
		||||
 | 
			
		||||
    public Team() {
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -1,5 +1,6 @@
 | 
			
		|||
package fr.organizee.model;
 | 
			
		||||
 | 
			
		||||
import com.fasterxml.jackson.annotation.JsonIgnore;
 | 
			
		||||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
 | 
			
		||||
 | 
			
		||||
import javax.persistence.*;
 | 
			
		||||
| 
						 | 
				
			
			@ -12,10 +13,13 @@ public class TodoList {
 | 
			
		|||
    @GeneratedValue(strategy = GenerationType.IDENTITY)
 | 
			
		||||
    private int id;
 | 
			
		||||
    private String nom;
 | 
			
		||||
    @ManyToOne(cascade = CascadeType.MERGE)
 | 
			
		||||
    @ManyToOne
 | 
			
		||||
    @JoinColumn(name="TEAM_ID")
 | 
			
		||||
    @JsonIgnoreProperties("todolist")
 | 
			
		||||
    @JsonIgnoreProperties({"todolist","membre"})
 | 
			
		||||
    private Team team;
 | 
			
		||||
    @OneToMany(mappedBy = "todolist", fetch=FetchType.LAZY, cascade = CascadeType.ALL)
 | 
			
		||||
    @JsonIgnoreProperties("todolist")
 | 
			
		||||
    private List<Tache> taches = new ArrayList<>();
 | 
			
		||||
 | 
			
		||||
    public TodoList() {
 | 
			
		||||
    }
 | 
			
		||||
| 
						 | 
				
			
			@ -40,11 +44,26 @@ public class TodoList {
 | 
			
		|||
        this.nom = nom;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public List<Tache> getTaches() {
 | 
			
		||||
        return taches;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public void setTaches(List<Tache> taches) {
 | 
			
		||||
        this.taches = taches;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public Team getTeam() {
 | 
			
		||||
        return team;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public void setTeam(Team team) {
 | 
			
		||||
        this.team = team;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public String toString() {
 | 
			
		||||
        return "TodoList{" +
 | 
			
		||||
                "id=" + id +
 | 
			
		||||
                ", nom='" + nom + '\'' +
 | 
			
		||||
                '}';
 | 
			
		||||
                ", nom='" + nom + ", taches='" + taches + "}";
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -0,0 +1,16 @@
 | 
			
		|||
package fr.organizee.repository;
 | 
			
		||||
 | 
			
		||||
import fr.organizee.model.Evenement;
 | 
			
		||||
import org.springframework.data.jpa.repository.JpaRepository;
 | 
			
		||||
import org.springframework.data.jpa.repository.Query;
 | 
			
		||||
import org.springframework.data.repository.query.Param;
 | 
			
		||||
import org.springframework.stereotype.Repository;
 | 
			
		||||
 | 
			
		||||
import java.util.List;
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@Repository
 | 
			
		||||
public interface EvenementRepository extends JpaRepository<Evenement, Integer> {
 | 
			
		||||
    @Query(value = "select * from evenement where team_id = :team_id", nativeQuery = true)
 | 
			
		||||
    List<Evenement> FindEvenementsByTeam(@Param("team_id") int team_id);
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			@ -1,18 +1,35 @@
 | 
			
		|||
package fr.organizee.repository;
 | 
			
		||||
 | 
			
		||||
import fr.organizee.model.Contact;
 | 
			
		||||
import fr.organizee.model.Membre;
 | 
			
		||||
import fr.organizee.model.Menu;
 | 
			
		||||
import org.springframework.data.jpa.repository.JpaRepository;
 | 
			
		||||
import org.springframework.data.jpa.repository.Query;
 | 
			
		||||
import org.springframework.data.repository.query.Param;
 | 
			
		||||
import org.springframework.stereotype.Repository;
 | 
			
		||||
 | 
			
		||||
import java.util.List;
 | 
			
		||||
import java.util.Optional;
 | 
			
		||||
 | 
			
		||||
@Repository
 | 
			
		||||
public interface MembreRepository extends JpaRepository<Membre, Integer> {
 | 
			
		||||
 | 
			
		||||
    @Query(value = "select * from membre where team_id = :team_id", nativeQuery = true)
 | 
			
		||||
    List<Membre> FindMembresByTeam(@Param("team_id") int team_id);
 | 
			
		||||
 | 
			
		||||
    Membre findByNom(String nom);
 | 
			
		||||
 | 
			
		||||
    Optional<Membre> findByEmail(String email);
 | 
			
		||||
 | 
			
		||||
    @Query(value = "select * from membre where password = :uuid", nativeQuery = true)
 | 
			
		||||
    Membre findByUUID(@Param("uuid") String uuid);
 | 
			
		||||
 | 
			
		||||
    @Query(value = "select * from membre where email = :email", nativeQuery = true)
 | 
			
		||||
    Membre chercheEmail(@Param("email") String email);
 | 
			
		||||
 | 
			
		||||
    boolean existsByEmail(String email);
 | 
			
		||||
 | 
			
		||||
    void deleteByEmail(String email);
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -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);
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -1,4 +1,18 @@
 | 
			
		|||
package fr.organizee.repository;
 | 
			
		||||
 | 
			
		||||
public interface TacheRepository {
 | 
			
		||||
import fr.organizee.model.Tache;
 | 
			
		||||
import org.springframework.data.jpa.repository.JpaRepository;
 | 
			
		||||
import org.springframework.data.jpa.repository.Query;
 | 
			
		||||
import org.springframework.data.repository.query.Param;
 | 
			
		||||
import org.springframework.stereotype.Repository;
 | 
			
		||||
 | 
			
		||||
import java.util.List;
 | 
			
		||||
 | 
			
		||||
@Repository
 | 
			
		||||
public interface
 | 
			
		||||
TacheRepository extends JpaRepository<Tache, Integer> {
 | 
			
		||||
 | 
			
		||||
    // N'est plus utilisé normalement
 | 
			
		||||
    @Query(value = "select * from todo_list, tache where todo_list.team_id = :team_id and todo_list.id = tache.todolist_id", nativeQuery = true)
 | 
			
		||||
    List<Tache> FindTachesByTeam(@Param("team_id") int team_id);
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -1,9 +1,16 @@
 | 
			
		|||
package fr.organizee.repository;
 | 
			
		||||
 | 
			
		||||
import fr.organizee.model.Menu;
 | 
			
		||||
import fr.organizee.model.TodoList;
 | 
			
		||||
import org.springframework.data.jpa.repository.JpaRepository;
 | 
			
		||||
import org.springframework.data.jpa.repository.Query;
 | 
			
		||||
import org.springframework.data.repository.query.Param;
 | 
			
		||||
import org.springframework.stereotype.Repository;
 | 
			
		||||
 | 
			
		||||
import java.util.List;
 | 
			
		||||
 | 
			
		||||
@Repository
 | 
			
		||||
public interface TodoListRepository extends JpaRepository<TodoList, Integer> {
 | 
			
		||||
    @Query(value = "select * from todo_list where team_id = :team_id", nativeQuery = true)
 | 
			
		||||
    List<TodoList> FindTodolistByTeam(@Param("team_id") int team_id);
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -27,6 +27,8 @@ import io.jsonwebtoken.JwtException;
 | 
			
		|||
import io.jsonwebtoken.Jwts;
 | 
			
		||||
import io.jsonwebtoken.SignatureAlgorithm;
 | 
			
		||||
 | 
			
		||||
import fr.organizee.repository.MembreRepository;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * JWT : classe utilitaire chargée de fournir le Jeton (Token) et les vérifications
 | 
			
		||||
 */
 | 
			
		||||
| 
						 | 
				
			
			@ -44,6 +46,8 @@ public class JwtTokenProvider {
 | 
			
		|||
    @Autowired
 | 
			
		||||
    private UserDetailsService userDetailsService;
 | 
			
		||||
 | 
			
		||||
    @Autowired
 | 
			
		||||
    private MembreRepository membreRepo;
 | 
			
		||||
    /**
 | 
			
		||||
     * Cette méthode d'initialisation s'exécute avant le constructeur
 | 
			
		||||
     * Elle encode notre code secret en base64 pour la transmission dans le header
 | 
			
		||||
| 
						 | 
				
			
			@ -104,6 +108,10 @@ public class JwtTokenProvider {
 | 
			
		|||
    public String createToken(String email, List<Role> roles){
 | 
			
		||||
 | 
			
		||||
        Claims claims = Jwts.claims().setSubject(email);
 | 
			
		||||
        claims.put("userId", membreRepo.findByEmail(email).get().getId());
 | 
			
		||||
        if(membreRepo.findByEmail(email).get().getTeam() != null){
 | 
			
		||||
            claims.put("teamId", membreRepo.findByEmail(email).get().getTeam().getId());
 | 
			
		||||
        }
 | 
			
		||||
        claims.put("auth", roles.stream().map(s -> new SimpleGrantedAuthority(s.getAuthority())).filter(Objects::nonNull).collect(Collectors.toList()));
 | 
			
		||||
 | 
			
		||||
        System.out.println("claims = "+claims);
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -13,7 +13,7 @@ import fr.organizee.model.Membre;
 | 
			
		|||
public interface MembreService {
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Methode qui permet à un utilisateur de se connecter.
 | 
			
		||||
     * Methode qui permet à un utilisateur de se connecter.
 | 
			
		||||
     * @param email : nom de l'utilisateur.
 | 
			
		||||
     * @param password : mot de passe de l'utilisateur.
 | 
			
		||||
     * @returnun JWT si credentials est valide, throws InvalidCredentialsException otherwise.
 | 
			
		||||
| 
						 | 
				
			
			@ -24,11 +24,12 @@ public interface MembreService {
 | 
			
		|||
    /**
 | 
			
		||||
     * Methode qui permet de s'inscrire.
 | 
			
		||||
     * @param membre nouvel utilisateur.
 | 
			
		||||
     * @return un JWT si user n'existe pas déjà !
 | 
			
		||||
     * @return un JWT si user n'existe pas déjà !
 | 
			
		||||
     * @throws ExistingUsernameException
 | 
			
		||||
     */
 | 
			
		||||
    String signup(Membre membre) throws ExistingUsernameException;
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Methode qui retourne tous les utilisateurs de la bd
 | 
			
		||||
     * @return the list of all application users.
 | 
			
		||||
| 
						 | 
				
			
			@ -36,10 +37,14 @@ public interface MembreService {
 | 
			
		|||
    List<Membre> findAllUsers();
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Methode qui retourne un utilisateur à partir de son username
 | 
			
		||||
     * Methode qui retourne un utilisateur à partir de son username
 | 
			
		||||
     * @param email the username to look for.
 | 
			
		||||
     * @return an Optional object containing user if found, empty otherwise.
 | 
			
		||||
     */
 | 
			
		||||
    Optional<Membre> findUserByEmail(String email);
 | 
			
		||||
    Optional<Membre> findUserByEmail(Membre membre);
 | 
			
		||||
    Optional<Membre> findByEmail(String email);
 | 
			
		||||
 | 
			
		||||
    Membre chercheEmail(String email);
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -17,7 +17,8 @@ import fr.organizee.repository.MembreRepository;
 | 
			
		|||
import fr.organizee.security.JwtTokenProvider;
 | 
			
		||||
 | 
			
		||||
@Service
 | 
			
		||||
public class MembreServiceImpl implements MembreService {
 | 
			
		||||
public class
 | 
			
		||||
MembreServiceImpl implements MembreService {
 | 
			
		||||
 | 
			
		||||
    @Autowired
 | 
			
		||||
    private MembreRepository membreRepository; // permet communication avec la BD
 | 
			
		||||
| 
						 | 
				
			
			@ -48,7 +49,9 @@ public class MembreServiceImpl implements MembreService {
 | 
			
		|||
    @Override
 | 
			
		||||
    public String signup(Membre membre) throws ExistingUsernameException {
 | 
			
		||||
        if (!membreRepository.existsByEmail(membre.getEmail())) {
 | 
			
		||||
            Membre membreToSave = new Membre(membre.getEmail(), passwordEncoder.encode(membre.getPassword()), membre.getRoleList());
 | 
			
		||||
            Membre membreToSave = new Membre(membre.getNom(), membre.getPrenom(), membre.getCouleur(),
 | 
			
		||||
                    membre.getDateNaissance(), membre.getTeam(), membre.getEmail(),
 | 
			
		||||
                    passwordEncoder.encode(membre.getPassword()), membre.getRoleList());
 | 
			
		||||
            membreRepository.save(membreToSave);
 | 
			
		||||
            return jwtTokenProvider.createToken(membre.getEmail(), membre.getRoleList());
 | 
			
		||||
        } else {
 | 
			
		||||
| 
						 | 
				
			
			@ -62,8 +65,20 @@ public class MembreServiceImpl implements MembreService {
 | 
			
		|||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public Optional<Membre> findUserByEmail(String email) {
 | 
			
		||||
        return membreRepository.findByEmail(email);
 | 
			
		||||
    }
 | 
			
		||||
    public Optional<Membre> findUserByEmail(Membre membre) {
 | 
			
		||||
        return this.membreRepository.findByEmail(membre.getEmail());
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public Optional<Membre> findByEmail(String email) {
 | 
			
		||||
        return this.membreRepository.findByEmail(email);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public Membre chercheEmail(String email) {
 | 
			
		||||
        return this.membreRepository.chercheEmail(email);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
							
								
								
									
										15
									
								
								src/main/java/fr/organizee/service/SendMailService.java
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										15
									
								
								src/main/java/fr/organizee/service/SendMailService.java
									
										
									
									
									
										Normal file
									
								
							| 
						 | 
				
			
			@ -0,0 +1,15 @@
 | 
			
		|||
package fr.organizee.service;
 | 
			
		||||
 | 
			
		||||
import fr.organizee.model.Mail;
 | 
			
		||||
 | 
			
		||||
import javax.mail.MessagingException;
 | 
			
		||||
 | 
			
		||||
public interface SendMailService {
 | 
			
		||||
    void sendMail(Mail mail);
 | 
			
		||||
 | 
			
		||||
    void sendMailHTML(Mail mail) throws MessagingException;
 | 
			
		||||
 | 
			
		||||
    void sendMailWithAttachments(Mail mail) throws MessagingException;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										68
									
								
								src/main/java/fr/organizee/service/SendMailServiceImpl.java
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										68
									
								
								src/main/java/fr/organizee/service/SendMailServiceImpl.java
									
										
									
									
									
										Normal file
									
								
							| 
						 | 
				
			
			@ -0,0 +1,68 @@
 | 
			
		|||
package fr.organizee.service;
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
import fr.organizee.model.Mail;
 | 
			
		||||
import org.springframework.core.io.ClassPathResource;
 | 
			
		||||
import org.springframework.mail.SimpleMailMessage;
 | 
			
		||||
import org.springframework.mail.javamail.JavaMailSender;
 | 
			
		||||
import org.springframework.mail.javamail.MimeMessageHelper;
 | 
			
		||||
import org.springframework.stereotype.Service;
 | 
			
		||||
 | 
			
		||||
import javax.mail.MessagingException;
 | 
			
		||||
import javax.mail.internet.MimeMessage;
 | 
			
		||||
 | 
			
		||||
@Service
 | 
			
		||||
public class SendMailServiceImpl implements SendMailService {
 | 
			
		||||
    private final JavaMailSender javaMailSender;
 | 
			
		||||
 | 
			
		||||
    public SendMailServiceImpl(JavaMailSender javaMailSender) {
 | 
			
		||||
        this.javaMailSender = javaMailSender;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public void sendMail(Mail mail) {
 | 
			
		||||
 | 
			
		||||
        SimpleMailMessage msg = new SimpleMailMessage();
 | 
			
		||||
        msg.setTo(mail.getRecipient(), mail.getRecipient());
 | 
			
		||||
 | 
			
		||||
        msg.setSubject(mail.getSubject());
 | 
			
		||||
        msg.setText(mail.getMessage());
 | 
			
		||||
 | 
			
		||||
        javaMailSender.send(msg);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public void sendMailHTML(Mail mail) throws MessagingException {
 | 
			
		||||
        MimeMessage msg = javaMailSender.createMimeMessage();
 | 
			
		||||
 | 
			
		||||
        MimeMessageHelper helper = new MimeMessageHelper(msg, true, "utf-8");
 | 
			
		||||
 | 
			
		||||
        helper.setTo(mail.getRecipient());
 | 
			
		||||
 | 
			
		||||
        helper.setSubject(mail.getSubject());
 | 
			
		||||
 | 
			
		||||
        String htmlMsg = "<h3>Test d'envoi de mail au format HTML</h3>"
 | 
			
		||||
                +"<img src='http://www.apache.org/images/asf_logo_wide.gif'>";
 | 
			
		||||
 | 
			
		||||
        msg.setContent(htmlMsg, "text/html");
 | 
			
		||||
 | 
			
		||||
        javaMailSender.send(msg);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public void sendMailWithAttachments(Mail mail) throws MessagingException {
 | 
			
		||||
        MimeMessage msg = javaMailSender.createMimeMessage();
 | 
			
		||||
 | 
			
		||||
        MimeMessageHelper helper = new MimeMessageHelper(msg, true);
 | 
			
		||||
 | 
			
		||||
        helper.setTo("destinataire@email");
 | 
			
		||||
 | 
			
		||||
        helper.setSubject("Testing from Spring Boot");
 | 
			
		||||
 | 
			
		||||
        helper.setText("Find the attached image", true);
 | 
			
		||||
 | 
			
		||||
        helper.addAttachment("hero.jpg", new ClassPathResource("hero.jpg"));
 | 
			
		||||
 | 
			
		||||
        javaMailSender.send(msg);
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			@ -37,5 +37,16 @@ INSERT INTO `tache` (`id`, `etat`, `texte`, `todolist_id`) VALUES
 | 
			
		|||
	(4, 0, 'Acheter un sapin', 3),
 | 
			
		||||
	(5, 0, 'Trouver un repas', 3);
 | 
			
		||||
 | 
			
		||||
INSERT INTO `evenement` (`id`, `all_day`, `event_debut`, `event_fin`, `libelle`, `membre_id`, `team_id`) VALUES
 | 
			
		||||
	(1, 0, '2022-01-13 09:00:33', '2022-01-13 13:04:38', 'Simplon', 1, 1);
 | 
			
		||||
INSERT INTO `evenement` (`id`, `all_day`, `start`, `end`, `text`, `membre_id`, `team_id`) VALUES
 | 
			
		||||
	(1, 0, '2022-02-04 09:00:00', '2022-02-04 13:00:00', 'Simplon', 1, 1),
 | 
			
		||||
	(2, 0, '2022-02-03 12:00:00', '2022-02-03 13:00:00', 'Footing', 2, 1);
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
INSERT INTO menu (id, date_menu, repas_midi, team_id, repas_soir) VALUES
 | 
			
		||||
(1, '2022-02-21', 'canard à l orange', 4, 'pâtes au beurre'),
 | 
			
		||||
(4, '2022-02-22', 'lasagnes', 4, 'riz sauté'),
 | 
			
		||||
(11, '2022-02-23', 'roti de dinde orloff', 4, 'choucroute'),
 | 
			
		||||
(13, '2022-02-24', 'hachis parmentier', 4, 'salade composée'),
 | 
			
		||||
(15, '2022-02-25', 'legumes', 4, 'croque monsieurs'),
 | 
			
		||||
(17, '2022-02-26', 'sauté de veau', 4, 'soupe et jambon'),
 | 
			
		||||
(21, '2022-02-27', 'lasagnes', 4, 'pizza');
 | 
			
		||||
		Loading…
	
	Add table
		
		Reference in a new issue