diff --git a/pom.xml b/pom.xml
index f735a7c..6704f63 100644
--- a/pom.xml
+++ b/pom.xml
@@ -39,7 +39,10 @@
org.springframework.boot
spring-boot-starter-web
-
+
+ org.springframework.boot
+ spring-boot-starter-mail
+
mysql
mysql-connector-java
diff --git a/src/main/java/fr/organizee/controller/EvenementController.java b/src/main/java/fr/organizee/controller/EvenementController.java
index a5c3673..f6a32a8 100644
--- a/src/main/java/fr/organizee/controller/EvenementController.java
+++ b/src/main/java/fr/organizee/controller/EvenementController.java
@@ -1,15 +1,14 @@
package fr.organizee.controller;
import fr.organizee.model.Evenement;
-import fr.organizee.model.Membre;
-import fr.organizee.model.Team;
+import fr.organizee.model.Menu;
import fr.organizee.repository.EvenementRepository;
-import fr.organizee.repository.TeamRepository;
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;
@@ -21,17 +20,59 @@ public class EvenementController {
@Autowired
private EvenementRepository evenementRepo;
- // Recupérer tout les evenements pour une team {id}
- @GetMapping(value = "/all/{id}")
- public ResponseEntity> getAll(){
+ // Recupérer tout les evenements pour une team {team_id}
+ @GetMapping(value = "/team/{team_id}")
+ public ResponseEntity> findByTeamId(@PathVariable int team_id){
List liste = null;
try
{
- liste = evenementRepo.findAll();
+ 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 !");
+ }
+ }
}
diff --git a/src/main/java/fr/organizee/controller/MailController.java b/src/main/java/fr/organizee/controller/MailController.java
new file mode 100644
index 0000000..3543668
--- /dev/null
+++ b/src/main/java/fr/organizee/controller/MailController.java
@@ -0,0 +1,43 @@
+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.PostMapping;
+import org.springframework.web.bind.annotation.RequestBody;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RestController;
+
+import javax.mail.MessagingException;
+
+@RestController
+@RequestMapping("/sendmail")
+public class MailController {
+ SendMailService service;
+
+ public MailController(SendMailService service) {
+ this.service = service;
+ }
+
+ // Envoi de mail en text brut
+ @PostMapping("/text")
+ public ResponseEntity 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 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 sendAttachmentEmail(@RequestBody Mail mail) throws MessagingException {
+ service.sendMailWithAttachments(mail);
+ return new ResponseEntity<>("Attachment mail sent successfully", HttpStatus.OK);
+ }
+}
\ No newline at end of file
diff --git a/src/main/java/fr/organizee/model/Contact.java b/src/main/java/fr/organizee/model/Contact.java
index 2c5ffb2..826b2db 100644
--- a/src/main/java/fr/organizee/model/Contact.java
+++ b/src/main/java/fr/organizee/model/Contact.java
@@ -1,5 +1,6 @@
package fr.organizee.model;
+import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import javax.persistence.*;
@@ -18,7 +19,7 @@ public class Contact {
private LocalDate dateNaissance;
@ManyToOne
@JoinColumn(name="TEAM_ID")
- @JsonIgnoreProperties("contact")
+ @JsonIgnoreProperties({"contact","membre"})
private Team team;
public Contact() {
diff --git a/src/main/java/fr/organizee/model/Evenement.java b/src/main/java/fr/organizee/model/Evenement.java
index 15a355f..f2f83fd 100644
--- a/src/main/java/fr/organizee/model/Evenement.java
+++ b/src/main/java/fr/organizee/model/Evenement.java
@@ -1,5 +1,6 @@
package fr.organizee.model;
+import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import javax.persistence.*;
@@ -10,28 +11,28 @@ public class Evenement {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private int id;
- private LocalDateTime eventDebut;
- private LocalDateTime eventFin;
+ private LocalDateTime start;
+ private LocalDateTime end;
private int allDay;
- private String libelle;
- @ManyToOne(cascade = CascadeType.MERGE)
+ private String text;
+ @ManyToOne
@JoinColumn(name="MEMBRE_ID")
@JsonIgnoreProperties("evenement")
private Membre membre;
- @ManyToOne(cascade = CascadeType.MERGE)
+ @ManyToOne
@JoinColumn(name="TEAM_ID")
- @JsonIgnoreProperties("evenement")
+ @JsonIgnoreProperties({"evenement", "membre"})
private Team team;
public Evenement() {
}
- public Evenement(int id, LocalDateTime eventDebut, LocalDateTime eventFin, int allDay, String libelle, Membre membre, Team team) {
+ public Evenement(int id, LocalDateTime start, LocalDateTime end, int allDay, String text, Membre membre, Team team) {
this.id = id;
- this.eventDebut = eventDebut;
- this.eventFin = eventFin;
+ this.start = start;
+ this.end = end;
this.allDay = allDay;
- this.libelle = libelle;
+ this.text = text;
this.membre = membre;
this.team = team;
}
@@ -44,20 +45,20 @@ public class Evenement {
this.id = id;
}
- public LocalDateTime getEventDebut() {
- return eventDebut;
+ public LocalDateTime getStart() {
+ return start;
}
- public void setEventDebut(LocalDateTime eventDebut) {
- this.eventDebut = eventDebut;
+ public void setStart(LocalDateTime start) {
+ this.start = start;
}
- public LocalDateTime getEventFin() {
- return eventFin;
+ public LocalDateTime getEnd() {
+ return end;
}
- public void setEventFin(LocalDateTime eventFin) {
- this.eventFin = eventFin;
+ public void setEnd(LocalDateTime end) {
+ this.end = end;
}
public int getAllDay() {
@@ -68,12 +69,12 @@ public class Evenement {
this.allDay = allDay;
}
- public String getLibelle() {
- return libelle;
+ public String getText() {
+ return text;
}
- public void setLibelle(String libelle) {
- this.libelle = libelle;
+ public void setText(String text) {
+ this.text = text;
}
public Membre getMembre() {
@@ -96,10 +97,10 @@ public class Evenement {
public String toString() {
return "Evenement{" +
"id=" + id +
- ", eventDebut=" + eventDebut +
- ", eventFin=" + eventFin +
+ ", start=" + start +
+ ", end=" + end +
", allDay=" + allDay +
- ", libelle='" + libelle + '\'' +
+ ", text='" + text + '\'' +
", membre=" + membre +
", team=" + team +
'}';
diff --git a/src/main/java/fr/organizee/model/Mail.java b/src/main/java/fr/organizee/model/Mail.java
new file mode 100644
index 0000000..cbd551b
--- /dev/null
+++ b/src/main/java/fr/organizee/model/Mail.java
@@ -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;
+ }
+}
+
diff --git a/src/main/java/fr/organizee/model/Menu.java b/src/main/java/fr/organizee/model/Menu.java
index e11cba4..dcc5cb0 100644
--- a/src/main/java/fr/organizee/model/Menu.java
+++ b/src/main/java/fr/organizee/model/Menu.java
@@ -15,7 +15,7 @@ public class Menu {
private int validationProposition;
@ManyToOne
@JoinColumn(name="TEAM_ID")
- @JsonIgnoreProperties("menu")
+ @JsonIgnoreProperties({"menu","membre"})
private Team team;
public Menu() {
diff --git a/src/main/java/fr/organizee/model/Team.java b/src/main/java/fr/organizee/model/Team.java
index ded5837..14ff97e 100644
--- a/src/main/java/fr/organizee/model/Team.java
+++ b/src/main/java/fr/organizee/model/Team.java
@@ -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, cascade = CascadeType.ALL)
@JsonIgnoreProperties("team")
private List membres = new ArrayList<>();
+
@OneToMany(mappedBy = "team", fetch=FetchType.LAZY, cascade = CascadeType.ALL)
@JsonIgnoreProperties("team")
+ @JsonIgnore
private List contacts = new ArrayList<>();
+
@OneToMany(mappedBy = "team", fetch=FetchType.LAZY, cascade = CascadeType.ALL)
@JsonIgnoreProperties("team")
+ @JsonIgnore
private List todolists = new ArrayList<>();
+
@OneToMany(mappedBy = "team", fetch=FetchType.LAZY, cascade = CascadeType.ALL)
@JsonIgnoreProperties("team")
+ @JsonIgnore
private List