Merge branch 'dev' into aline
This commit is contained in:
commit
9b5a8c065c
5
pom.xml
5
pom.xml
|
@ -39,7 +39,10 @@
|
||||||
<groupId>org.springframework.boot</groupId>
|
<groupId>org.springframework.boot</groupId>
|
||||||
<artifactId>spring-boot-starter-web</artifactId>
|
<artifactId>spring-boot-starter-web</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
<artifactId>spring-boot-starter-mail</artifactId>
|
||||||
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>mysql</groupId>
|
<groupId>mysql</groupId>
|
||||||
<artifactId>mysql-connector-java</artifactId>
|
<artifactId>mysql-connector-java</artifactId>
|
||||||
|
|
|
@ -1,15 +1,14 @@
|
||||||
package fr.organizee.controller;
|
package fr.organizee.controller;
|
||||||
|
|
||||||
import fr.organizee.model.Evenement;
|
import fr.organizee.model.Evenement;
|
||||||
import fr.organizee.model.Membre;
|
import fr.organizee.model.Menu;
|
||||||
import fr.organizee.model.Team;
|
|
||||||
import fr.organizee.repository.EvenementRepository;
|
import fr.organizee.repository.EvenementRepository;
|
||||||
import fr.organizee.repository.TeamRepository;
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.http.HttpStatus;
|
import org.springframework.http.HttpStatus;
|
||||||
import org.springframework.http.ResponseEntity;
|
import org.springframework.http.ResponseEntity;
|
||||||
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
|
import javax.persistence.EntityNotFoundException;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
|
|
||||||
|
@ -21,17 +20,59 @@ public class EvenementController {
|
||||||
@Autowired
|
@Autowired
|
||||||
private EvenementRepository evenementRepo;
|
private EvenementRepository evenementRepo;
|
||||||
|
|
||||||
// Recupérer tout les evenements pour une team {id}
|
// Recupérer tout les evenements pour une team {team_id}
|
||||||
@GetMapping(value = "/all/{id}")
|
@GetMapping(value = "/team/{team_id}")
|
||||||
public ResponseEntity<?> getAll(){
|
public ResponseEntity<?> findByTeamId(@PathVariable int team_id){
|
||||||
List<Evenement> liste = null;
|
List<Evenement> liste = null;
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
liste = evenementRepo.findAll();
|
liste = evenementRepo.FindEvenementsByTeam(team_id);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
return ResponseEntity.status(HttpStatus.NOT_FOUND).body(null);
|
return ResponseEntity.status(HttpStatus.NOT_FOUND).body(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
return ResponseEntity.status(HttpStatus.OK).body(liste);
|
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 !");
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -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<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);
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,5 +1,6 @@
|
||||||
package fr.organizee.model;
|
package fr.organizee.model;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.annotation.JsonIgnore;
|
||||||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
|
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
|
||||||
|
|
||||||
import javax.persistence.*;
|
import javax.persistence.*;
|
||||||
|
@ -18,7 +19,7 @@ public class Contact {
|
||||||
private LocalDate dateNaissance;
|
private LocalDate dateNaissance;
|
||||||
@ManyToOne
|
@ManyToOne
|
||||||
@JoinColumn(name="TEAM_ID")
|
@JoinColumn(name="TEAM_ID")
|
||||||
@JsonIgnoreProperties("contact")
|
@JsonIgnoreProperties({"contact","membre"})
|
||||||
private Team team;
|
private Team team;
|
||||||
|
|
||||||
public Contact() {
|
public Contact() {
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
package fr.organizee.model;
|
package fr.organizee.model;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.annotation.JsonIgnore;
|
||||||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
|
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
|
||||||
|
|
||||||
import javax.persistence.*;
|
import javax.persistence.*;
|
||||||
|
@ -10,28 +11,28 @@ public class Evenement {
|
||||||
@Id
|
@Id
|
||||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||||
private int id;
|
private int id;
|
||||||
private LocalDateTime eventDebut;
|
private LocalDateTime start;
|
||||||
private LocalDateTime eventFin;
|
private LocalDateTime end;
|
||||||
private int allDay;
|
private int allDay;
|
||||||
private String libelle;
|
private String text;
|
||||||
@ManyToOne(cascade = CascadeType.MERGE)
|
@ManyToOne
|
||||||
@JoinColumn(name="MEMBRE_ID")
|
@JoinColumn(name="MEMBRE_ID")
|
||||||
@JsonIgnoreProperties("evenement")
|
@JsonIgnoreProperties("evenement")
|
||||||
private Membre membre;
|
private Membre membre;
|
||||||
@ManyToOne(cascade = CascadeType.MERGE)
|
@ManyToOne
|
||||||
@JoinColumn(name="TEAM_ID")
|
@JoinColumn(name="TEAM_ID")
|
||||||
@JsonIgnoreProperties("evenement")
|
@JsonIgnoreProperties({"evenement", "membre"})
|
||||||
private Team team;
|
private Team team;
|
||||||
|
|
||||||
public Evenement() {
|
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.id = id;
|
||||||
this.eventDebut = eventDebut;
|
this.start = start;
|
||||||
this.eventFin = eventFin;
|
this.end = end;
|
||||||
this.allDay = allDay;
|
this.allDay = allDay;
|
||||||
this.libelle = libelle;
|
this.text = text;
|
||||||
this.membre = membre;
|
this.membre = membre;
|
||||||
this.team = team;
|
this.team = team;
|
||||||
}
|
}
|
||||||
|
@ -44,20 +45,20 @@ public class Evenement {
|
||||||
this.id = id;
|
this.id = id;
|
||||||
}
|
}
|
||||||
|
|
||||||
public LocalDateTime getEventDebut() {
|
public LocalDateTime getStart() {
|
||||||
return eventDebut;
|
return start;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setEventDebut(LocalDateTime eventDebut) {
|
public void setStart(LocalDateTime start) {
|
||||||
this.eventDebut = eventDebut;
|
this.start = start;
|
||||||
}
|
}
|
||||||
|
|
||||||
public LocalDateTime getEventFin() {
|
public LocalDateTime getEnd() {
|
||||||
return eventFin;
|
return end;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setEventFin(LocalDateTime eventFin) {
|
public void setEnd(LocalDateTime end) {
|
||||||
this.eventFin = eventFin;
|
this.end = end;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getAllDay() {
|
public int getAllDay() {
|
||||||
|
@ -68,12 +69,12 @@ public class Evenement {
|
||||||
this.allDay = allDay;
|
this.allDay = allDay;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getLibelle() {
|
public String getText() {
|
||||||
return libelle;
|
return text;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setLibelle(String libelle) {
|
public void setText(String text) {
|
||||||
this.libelle = libelle;
|
this.text = text;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Membre getMembre() {
|
public Membre getMembre() {
|
||||||
|
@ -96,10 +97,10 @@ public class Evenement {
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return "Evenement{" +
|
return "Evenement{" +
|
||||||
"id=" + id +
|
"id=" + id +
|
||||||
", eventDebut=" + eventDebut +
|
", start=" + start +
|
||||||
", eventFin=" + eventFin +
|
", end=" + end +
|
||||||
", allDay=" + allDay +
|
", allDay=" + allDay +
|
||||||
", libelle='" + libelle + '\'' +
|
", text='" + text + '\'' +
|
||||||
", membre=" + membre +
|
", membre=" + membre +
|
||||||
", team=" + team +
|
", team=" + team +
|
||||||
'}';
|
'}';
|
||||||
|
|
|
@ -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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -15,7 +15,7 @@ public class Menu {
|
||||||
private int validationProposition;
|
private int validationProposition;
|
||||||
@ManyToOne
|
@ManyToOne
|
||||||
@JoinColumn(name="TEAM_ID")
|
@JoinColumn(name="TEAM_ID")
|
||||||
@JsonIgnoreProperties("menu")
|
@JsonIgnoreProperties({"menu","membre"})
|
||||||
private Team team;
|
private Team team;
|
||||||
|
|
||||||
public Menu() {
|
public Menu() {
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
package fr.organizee.model;
|
package fr.organizee.model;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.annotation.JsonIgnore;
|
||||||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
|
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
|
||||||
|
|
||||||
import javax.persistence.*;
|
import javax.persistence.*;
|
||||||
|
@ -12,17 +13,24 @@ public class Team {
|
||||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||||
private int id;
|
private int id;
|
||||||
private String nom;
|
private String nom;
|
||||||
|
|
||||||
@OneToMany(mappedBy = "team", fetch=FetchType.LAZY, cascade = CascadeType.ALL)
|
@OneToMany(mappedBy = "team", fetch=FetchType.LAZY, cascade = CascadeType.ALL)
|
||||||
@JsonIgnoreProperties("team")
|
@JsonIgnoreProperties("team")
|
||||||
private List<Membre> membres = new ArrayList<>();
|
private List<Membre> membres = new ArrayList<>();
|
||||||
|
|
||||||
@OneToMany(mappedBy = "team", fetch=FetchType.LAZY, cascade = CascadeType.ALL)
|
@OneToMany(mappedBy = "team", fetch=FetchType.LAZY, cascade = CascadeType.ALL)
|
||||||
@JsonIgnoreProperties("team")
|
@JsonIgnoreProperties("team")
|
||||||
|
@JsonIgnore
|
||||||
private List<Contact> contacts = new ArrayList<>();
|
private List<Contact> contacts = new ArrayList<>();
|
||||||
|
|
||||||
@OneToMany(mappedBy = "team", fetch=FetchType.LAZY, cascade = CascadeType.ALL)
|
@OneToMany(mappedBy = "team", fetch=FetchType.LAZY, cascade = CascadeType.ALL)
|
||||||
@JsonIgnoreProperties("team")
|
@JsonIgnoreProperties("team")
|
||||||
|
@JsonIgnore
|
||||||
private List<TodoList> todolists = new ArrayList<>();
|
private List<TodoList> todolists = new ArrayList<>();
|
||||||
|
|
||||||
@OneToMany(mappedBy = "team", fetch=FetchType.LAZY, cascade = CascadeType.ALL)
|
@OneToMany(mappedBy = "team", fetch=FetchType.LAZY, cascade = CascadeType.ALL)
|
||||||
@JsonIgnoreProperties("team")
|
@JsonIgnoreProperties("team")
|
||||||
|
@JsonIgnore
|
||||||
private List<Menu> menus = new ArrayList<>();
|
private List<Menu> menus = new ArrayList<>();
|
||||||
|
|
||||||
public Team() {
|
public Team() {
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
package fr.organizee.model;
|
package fr.organizee.model;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.annotation.JsonIgnore;
|
||||||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
|
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
|
||||||
|
|
||||||
import javax.persistence.*;
|
import javax.persistence.*;
|
||||||
|
@ -14,7 +15,7 @@ public class TodoList {
|
||||||
private String nom;
|
private String nom;
|
||||||
@ManyToOne
|
@ManyToOne
|
||||||
@JoinColumn(name="TEAM_ID")
|
@JoinColumn(name="TEAM_ID")
|
||||||
@JsonIgnoreProperties("todolist")
|
@JsonIgnoreProperties({"todolist","membre"})
|
||||||
private Team team;
|
private Team team;
|
||||||
@OneToMany(mappedBy = "todolist", fetch=FetchType.LAZY, cascade = CascadeType.ALL)
|
@OneToMany(mappedBy = "todolist", fetch=FetchType.LAZY, cascade = CascadeType.ALL)
|
||||||
@JsonIgnoreProperties("todolist")
|
@JsonIgnoreProperties("todolist")
|
||||||
|
|
|
@ -2,8 +2,15 @@ package fr.organizee.repository;
|
||||||
|
|
||||||
import fr.organizee.model.Evenement;
|
import fr.organizee.model.Evenement;
|
||||||
import org.springframework.data.jpa.repository.JpaRepository;
|
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 org.springframework.stereotype.Repository;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
|
||||||
@Repository
|
@Repository
|
||||||
public interface EvenementRepository extends JpaRepository<Evenement, Integer> {
|
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);
|
||||||
}
|
}
|
||||||
|
|
|
@ -27,6 +27,8 @@ import io.jsonwebtoken.JwtException;
|
||||||
import io.jsonwebtoken.Jwts;
|
import io.jsonwebtoken.Jwts;
|
||||||
import io.jsonwebtoken.SignatureAlgorithm;
|
import io.jsonwebtoken.SignatureAlgorithm;
|
||||||
|
|
||||||
|
import fr.organizee.repository.MembreRepository;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* JWT : classe utilitaire chargée de fournir le Jeton (Token) et les vérifications
|
* JWT : classe utilitaire chargée de fournir le Jeton (Token) et les vérifications
|
||||||
*/
|
*/
|
||||||
|
@ -44,6 +46,8 @@ public class JwtTokenProvider {
|
||||||
@Autowired
|
@Autowired
|
||||||
private UserDetailsService userDetailsService;
|
private UserDetailsService userDetailsService;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private MembreRepository membreRepo;
|
||||||
/**
|
/**
|
||||||
* Cette méthode d'initialisation s'exécute avant le constructeur
|
* Cette méthode d'initialisation s'exécute avant le constructeur
|
||||||
* Elle encode notre code secret en base64 pour la transmission dans le header
|
* 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){
|
public String createToken(String email, List<Role> roles){
|
||||||
|
|
||||||
Claims claims = Jwts.claims().setSubject(email);
|
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()));
|
claims.put("auth", roles.stream().map(s -> new SimpleGrantedAuthority(s.getAuthority())).filter(Objects::nonNull).collect(Collectors.toList()));
|
||||||
|
|
||||||
System.out.println("claims = "+claims);
|
System.out.println("claims = "+claims);
|
||||||
|
|
|
@ -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;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
|
@ -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,10 @@ INSERT INTO `tache` (`id`, `etat`, `texte`, `todolist_id`) VALUES
|
||||||
(4, 0, 'Acheter un sapin', 3),
|
(4, 0, 'Acheter un sapin', 3),
|
||||||
(5, 0, 'Trouver un repas', 3);
|
(5, 0, 'Trouver un repas', 3);
|
||||||
|
|
||||||
INSERT INTO `evenement` (`id`, `all_day`, `event_debut`, `event_fin`, `libelle`, `membre_id`, `team_id`) VALUES
|
INSERT INTO `evenement` (`id`, `all_day`, `start`, `end`, `text`, `membre_id`, `team_id`) VALUES
|
||||||
(1, 0, '2022-01-13 09:00:33', '2022-01-13 13:04:38', 'Simplon', 1, 1);
|
(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`, `libelle`, `validation_proposition`, `team_id`) VALUES
|
||||||
|
(1, '2022-01-13', 'Lasagnes', 1, 1),
|
||||||
|
(2, '2022-01-03', 'Kebab', 1, 1);
|
Loading…
Reference in New Issue