merge conflicts

This commit is contained in:
Sana EL HIRI 2022-02-17 10:16:32 +01:00
commit 6cb4097588
26 changed files with 687 additions and 223 deletions

2
.idea/compiler.xml generated
View file

@ -6,12 +6,14 @@
<sourceOutputDir name="target/generated-sources/annotations" />
<sourceTestOutputDir name="target/generated-test-sources/test-annotations" />
<outputRelativeToContentRoot value="true" />
<module name="Organizee" />
<module name="organizee" />
</profile>
</annotationProcessing>
</component>
<component name="JavacSettings">
<option name="ADDITIONAL_OPTIONS_OVERRIDE">
<module name="Organizee" options="-parameters" />
<module name="organizee" options="-parameters" />
</option>
</component>

View file

@ -38,7 +38,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>

View file

@ -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;
@ -24,7 +21,7 @@ public class ContactController {
private ContactRepository contactRepo;
@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
@ -38,7 +35,7 @@ public class ContactController {
}
@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
@ -52,7 +49,7 @@ public class ContactController {
}
@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 {
@ -65,7 +62,7 @@ public class ContactController {
}
@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 {
@ -79,7 +76,7 @@ public class ContactController {
}
@DeleteMapping(value = "/delete/{id}")
@PreAuthorize("hasRole('ROLE_PARENT')")
//@PreAuthorize("hasRole('ROLE_PARENT')")
public ResponseEntity<?> deleteContact(@PathVariable int id){
try {
contactRepo.delete(contactRepo.getById(id));

View file

@ -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 !");
}
}
}

View file

@ -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);
}
}

View file

@ -5,9 +5,7 @@ import fr.organizee.dto.MembreDto;
import fr.organizee.exception.ExistingUsernameException;
import fr.organizee.exception.InvalidCredentialsException;
import fr.organizee.model.Membre;
//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;
@ -36,10 +34,6 @@ public class MembreController {
@Autowired
private BCryptPasswordEncoder passwordEncoder;
// @Autowired
// private TeamRepository teamRepo;
// @RequestMapping("/membres")
@ResponseBody
public String home()
{
@ -49,6 +43,7 @@ public class MembreController {
return sb.toString();
}
// Récupère tout les membres de la base
@GetMapping(value = "/all")
@PreAuthorize("hasRole('ROLE_PARENT') or hasRole('ROLE_ENFANT')")
public ResponseEntity<?> getAll(){
@ -109,21 +104,9 @@ public class MembreController {
}
// @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);
// }
//Récupérer les informations d'un membre 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<Membre> membre = null;
try
@ -136,15 +119,9 @@ public class MembreController {
return ResponseEntity.status(HttpStatus.OK).body(membre);
}
// @GetMapping(value = "/membres/delete/{id}")
// public void deleteMembreId(@PathVariable("id") Integer id) {
//
// membreRepo.deleteById(id);
//
// }
//Efface un membre par son ID
@DeleteMapping(value = "/delete/{id}")
@PreAuthorize("hasRole('ROLE_PARENT')")
//@PreAuthorize("hasRole('ROLE_PARENT')")
public ResponseEntity<?> deleteMembre(@PathVariable int id){
try {
membreRepo.delete(membreRepo.getById(id));
@ -157,6 +134,7 @@ public class MembreController {
}
}
//Ajouter un membre et inscription
@PostMapping("/sign-up")
public ResponseEntity<JsonWebToken> signUp(@RequestBody Membre membre) {
try {
@ -166,6 +144,7 @@ public class MembreController {
}
}
//Login
@PostMapping("/sign-in")
public ResponseEntity<JsonWebToken> signIn(@RequestBody Membre membre) {
try {
@ -175,8 +154,9 @@ public class MembreController {
}
}
//Met a jour les informations d'un membre par son ID
@PutMapping("/update/{id}")
@PreAuthorize("hasRole('ROLE_PARENT')")
//@PreAuthorize("hasRole('ROLE_PARENT')")
public ResponseEntity<?> updateMembre(@RequestBody Membre membre, @PathVariable Integer id) throws Exception {
Membre resultMembre = null;
try {

View file

@ -1,6 +1,5 @@
package fr.organizee.controller;
import fr.organizee.model.Contact;
import fr.organizee.model.Menu;
import fr.organizee.repository.MenuRepository;
import org.springframework.beans.factory.annotation.Autowired;
@ -21,8 +20,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 +35,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,8 +48,9 @@ public class MenuController {
return ResponseEntity.status(HttpStatus.OK).body(menus);
}
//Ajoute un nouveau menu
@PostMapping(value="/add")
@PreAuthorize("hasRole('ROLE_PARENT') or hasRole('ROLE_ENFANT')")
//@PreAuthorize("hasRole('ROLE_PARENT') or hasRole('ROLE_ENFANT')")
public ResponseEntity<?> addMenu(@RequestBody Menu menu){
Menu resultMenu = null;
try {
@ -60,8 +62,9 @@ public class MenuController {
return ResponseEntity.status(HttpStatus.CREATED).body(resultMenu);
}
//Mise a jour d'un menu par son ID
@PutMapping("/update/{id}")
@PreAuthorize("hasRole('ROLE_PARENT')")
//@PreAuthorize("hasRole('ROLE_PARENT')")
public ResponseEntity<?> updateMenu(@RequestBody Menu menu, @PathVariable Integer id) throws Exception {
Menu resultMenu = null;
try {
@ -71,11 +74,12 @@ public class MenuController {
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));

View file

@ -0,0 +1,103 @@
package fr.organizee.controller;
import fr.organizee.model.Tache;
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", produces="application/json", consumes="application/json")
public ResponseEntity<?> addTache(@RequestBody Tache tache){
Tache resultTache = null;
try {
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 date avec son ID
@PutMapping("/update/{id}")
public ResponseEntity<?> updateTache(@RequestBody Tache tache, @PathVariable Integer id) throws Exception {
Tache resultTache = null;
try {
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);
}
}

View file

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

View file

@ -0,0 +1,75 @@
package fr.organizee.controller;
import fr.organizee.model.TodoList;
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);
}
@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);
}
}

View file

@ -1,5 +1,6 @@
package fr.organizee.model;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import javax.persistence.*;
@ -16,9 +17,9 @@ public class Contact {
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() {

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

View 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;
}
}

View file

@ -33,10 +33,10 @@ public class Membre {
private String isAdmin;
private String couleur;
private String smiley;
// @ManyToOne
// @ManyToOne
// @JoinColumn(name="TEAM_ID")
// @JsonIgnore
@ManyToOne(cascade = CascadeType.MERGE)
@ManyToOne
@JoinColumn(name="TEAM_ID")
@JsonIgnoreProperties("membre")
private Team team;
@ -113,7 +113,7 @@ public class Membre {
this.team = team;
}
public List<Role> getRoleList() {
public List<Role> getRoleList() {
return roleList;
}
public void setRoleList(List<Role> roleList) {

View file

@ -13,20 +13,19 @@ public class Menu {
private String libelle;
private LocalDate dateMenu;
private int validationProposition;
@ManyToOne(cascade = CascadeType.MERGE)
@JoinColumn(name="TEAM_ID")
@JsonIgnoreProperties("menu")
private Team team;
@ManyToOne
private Membre membre;
@JoinColumn(name="TEAM_ID")
@JsonIgnoreProperties({"menu","membre"})
private Team team;
public Menu() {
}
public Menu(String libelle, LocalDate dateMenu, int validationProposition) {
public Menu(String libelle, LocalDate dateMenu, int validationProposition, Team team) {
this.libelle = libelle;
this.dateMenu = dateMenu;
this.validationProposition=validationProposition;
this.team = team;
}
public int getId() {
@ -53,12 +52,30 @@ public class Menu {
this.dateMenu = dateMenu;
}
public int getValidationProposition() {
return validationProposition;
}
public void setValidationProposition(int validationProposition) {
this.validationProposition = validationProposition;
}
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 +
", validationProposition=" + validationProposition +
", team=" + team +
'}';
}
}

View file

@ -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;

View file

@ -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() {

View file

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

View file

@ -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);
}

View file

@ -1,4 +1,17 @@
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);
}

View file

@ -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);
}

View file

@ -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 ©rifications
*/
@ -44,6 +46,8 @@ public class JwtTokenProvider {
@Autowired
private UserDetailsService userDetailsService;
@Autowired
private MembreRepository membreRepo;
/**
* Cette ©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);

View file

@ -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,7 +24,7 @@ public interface MembreService {
/**
* Methode qui permet de s'inscrire.
* @param membre nouvel utilisateur.
* @return un JWT si user n'existe pas ©  !
* @return un JWT si user n'existe pas © !
* @throws ExistingUsernameException
*/
String signup(Membre membre) throws ExistingUsernameException;
@ -37,7 +37,7 @@ 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.
*/

View 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;
}

View 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);
}
}

View file

@ -1,67 +1,3 @@
<<<<<<< HEAD
-- --------------------------------------------------------
-- Hôte : 192.168.1.16
-- Version du serveur: 10.3.32-MariaDB-0ubuntu0.20.04.1 - Ubuntu 20.04
-- SE du serveur: debian-linux-gnu
-- HeidiSQL Version: 9.5.0.5196
-- --------------------------------------------------------
/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
/*!40101 SET NAMES utf8 */;
/*!50503 SET NAMES utf8mb4 */;
/*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */;
/*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */;
-- Export de la structure de la table organizee.contact
CREATE TABLE IF NOT EXISTS `contact` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`adresse` varchar(255) DEFAULT NULL,
`date_naissance` date DEFAULT NULL,
`email` varchar(255) DEFAULT NULL,
`nom` varchar(255) DEFAULT NULL,
`prenom` varchar(255) DEFAULT NULL,
`telephone` varchar(255) DEFAULT NULL,
`team_id` int(11) DEFAULT NULL,
PRIMARY KEY (`id`),
KEY `FK7gyd9s84tx9eeuigeu3uv984x` (`team_id`),
CONSTRAINT `FK7gyd9s84tx9eeuigeu3uv984x` FOREIGN KEY (`team_id`) REFERENCES `team` (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=11 DEFAULT CHARSET=utf8mb4;
-- Export de données de la table organizee.contact : ~0 rows (environ)
/*!40000 ALTER TABLE `contact` DISABLE KEYS */;
INSERT INTO `contact` (`id`, `adresse`, `date_naissance`, `email`, `nom`, `prenom`, `telephone`, `team_id`) VALUES
(1, '7554 Messerschmidt Center', '2021-01-24', 'oogleasane0@cargocollective.com', 'Ophelia', 'O\'Gleasane', '913-198-6499', 1),
(2, '534 Jay Way', '2021-03-26', 'fmowett1@ocn.ne.jp', 'Fiann', 'Mowett', '248-224-7233', 1),
(3, '077 Buell Place', '2021-06-24', 'vlewknor2@spotify.com', 'Vladamir', 'Lewknor', '922-822-3626', 1),
(4, '6226 Esker Street', '2021-04-13', 'jbarmadier3@opensource.org', 'Jervis', 'Barmadier', '838-581-8112', 2),
(5, '28531 Luster Circle', '2021-06-15', 'tmee4@ameblo.jp', 'Tuesday', 'Mee', '761-975-7324', 2),
(6, '96 Hallows Avenue', '2021-08-13', 'tcolvine5@elegantthemes.com', 'Toni', 'Colvine', '348-778-7679', 2),
(7, '6401 Jay Crossing', '2021-01-14', 'rrielly6@netlog.com', 'Riane', 'Rielly', '740-571-0835', 3),
(8, '3273 Cascade Pass', '2021-03-22', 'jlauder7@rambler.ru', 'Juieta', 'Lauder', '928-408-6855', 3),
(9, '1170 Burning Wood Road', '2021-05-31', 'tbolver8@google.ca', 'Thibaut', 'Bolver', '681-860-8291', 4),
(10, '1 Westridge Road', '2021-03-11', 'emebs9@uol.com.br', 'Evered', 'Mebs', '898-483-6075', 4);
/*!40000 ALTER TABLE `contact` ENABLE KEYS */;
-- Export de la structure de la table organizee.membre
CREATE TABLE IF NOT EXISTS `membre` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`couleur` varchar(255) DEFAULT NULL,
`date_naissance` date DEFAULT NULL,
`email` varchar(255) DEFAULT NULL,
`is_admin` varchar(255) DEFAULT NULL,
`nom` varchar(255) DEFAULT NULL,
`password` varchar(255) DEFAULT NULL,
`prenom` varchar(255) DEFAULT NULL,
`smiley` varchar(255) DEFAULT NULL,
`team_id` int(11) DEFAULT NULL,
PRIMARY KEY (`id`),
KEY `FKll5mmgkw1h2kmxnuo4885x2fn` (`team_id`),
CONSTRAINT `FKll5mmgkw1h2kmxnuo4885x2fn` FOREIGN KEY (`team_id`) REFERENCES `team` (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=7 DEFAULT CHARSET=utf8mb4;
-- Export de données de la table organizee.membre : ~0 rows (environ)
/*!40000 ALTER TABLE `membre` DISABLE KEYS */;
=======
INSERT INTO `team` (`id`, `nom`) VALUES
(1, 'Team JAVA'),
(2, 'Team Angular'),
@ -80,7 +16,6 @@ INSERT INTO `contact` (`id`, `adresse`, `date_naissance`, `email`, `nom`, `preno
(9, '1170 Burning Wood Road', '2021-05-31', 'tbolver8@google.ca', 'Thibaut', 'Bolver', '681-860-8291','4'),
(10, '1 Westridge Road', '2021-03-11', 'emebs9@uol.com.br', 'Evered', 'Mebs', '898-483-6075','4');
>>>>>>> b147bc406c22caa9c817c7189a325058d8550a69
INSERT INTO `membre` (`id`, `couleur`, `date_naissance`, `email`, `is_admin`, `nom`, `password`, `prenom`, `smiley`, `team_id`) VALUES
(1, '#fcba03', '2021-12-13', 'hedi@simplon.com', '0', 'SKYWALKER', 'toto', 'Hédi', NULL, 1),
(2, '#8df505', '2021-07-03', 'aline@simplon.com', '0', 'FETT', 'tata', 'Aline', NULL, 1),
@ -88,86 +23,6 @@ INSERT INTO `membre` (`id`, `couleur`, `date_naissance`, `email`, `is_admin`, `n
(4, '#ed09de', '2021-06-29', 'blandine@simplon.com', '0', 'VADER', 'tutu', 'Blandine', NULL, 3),
(5, '#ed09de', '2021-08-29', 'sana@simplon.com', '0', 'C3PO', 'riri', 'Sana', NULL, 4),
(6, '#ed09de', '2021-10-29', 'cecile@simplon.com', '0', 'R2D2', 'loulou', 'Cecile', NULL, 4);
<<<<<<< HEAD
/*!40000 ALTER TABLE `membre` ENABLE KEYS */;
-- Export de la structure de la table organizee.menu
CREATE TABLE IF NOT EXISTS `menu` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`date_menu` date DEFAULT NULL,
`libelle` varchar(255) DEFAULT NULL,
`membre_id` int(11) DEFAULT NULL,
`team_id` int(11) DEFAULT NULL,
PRIMARY KEY (`id`),
KEY `FK9k2sad7pn2qsivwavhptvm3u6` (`membre_id`),
KEY `FKky2j5l3syborv9dtqtprgpr28` (`team_id`),
CONSTRAINT `FK9k2sad7pn2qsivwavhptvm3u6` FOREIGN KEY (`membre_id`) REFERENCES `membre` (`id`),
CONSTRAINT `FKky2j5l3syborv9dtqtprgpr28` FOREIGN KEY (`team_id`) REFERENCES `team` (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
-- Export de données de la table organizee.menu : ~0 rows (environ)
/*!40000 ALTER TABLE `menu` DISABLE KEYS */;
/*!40000 ALTER TABLE `menu` ENABLE KEYS */;
-- Export de la structure de la table organizee.tache
CREATE TABLE IF NOT EXISTS `tache` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`etat` bit(1) DEFAULT NULL,
`texte` varchar(255) DEFAULT NULL,
`todolist_id` int(11) DEFAULT NULL,
PRIMARY KEY (`id`),
KEY `FK50q0ja9qvoud7ujsudc9jj9yk` (`todolist_id`),
CONSTRAINT `FK50q0ja9qvoud7ujsudc9jj9yk` FOREIGN KEY (`todolist_id`) REFERENCES `todo_list` (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=6 DEFAULT CHARSET=utf8mb4;
-- Export de données de la table organizee.tache : ~0 rows (environ)
/*!40000 ALTER TABLE `tache` DISABLE KEYS */;
INSERT INTO `tache` (`id`, `etat`, `texte`, `todolist_id`) VALUES
(1, b'0', 'Apprendre le PHP', 1),
(2, b'0', 'Revoir CRUD', 1),
(3, b'0', 'Acheter des guirlandes', 3),
(4, b'0', 'Acheter un sapin', 3),
(5, b'0', 'Trouver un repas', 3);
/*!40000 ALTER TABLE `tache` ENABLE KEYS */;
-- Export de la structure de la table organizee.team
CREATE TABLE IF NOT EXISTS `team` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`nom` varchar(255) DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=5 DEFAULT CHARSET=utf8mb4;
-- Export de données de la table organizee.team : ~0 rows (environ)
/*!40000 ALTER TABLE `team` DISABLE KEYS */;
INSERT INTO `team` (`id`, `nom`) VALUES
(1, 'Team JAVA'),
(2, 'Team Angular'),
(3, 'Team PHP'),
(4, 'Team Bancal');
/*!40000 ALTER TABLE `team` ENABLE KEYS */;
-- Export de la structure de la table organizee.todo_list
CREATE TABLE IF NOT EXISTS `todo_list` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`nom` varchar(255) DEFAULT NULL,
`team_id` int(11) DEFAULT NULL,
PRIMARY KEY (`id`),
KEY `FK6ty40hkdysbql7xaewhujsjg` (`team_id`),
CONSTRAINT `FK6ty40hkdysbql7xaewhujsjg` FOREIGN KEY (`team_id`) REFERENCES `team` (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=utf8mb4;
-- Export de données de la table organizee.todo_list : ~0 rows (environ)
/*!40000 ALTER TABLE `todo_list` DISABLE KEYS */;
INSERT INTO `todo_list` (`id`, `nom`, `team_id`) VALUES
(1, 'Pour Blandine', 1),
(2, 'Corvées', 1),
(3, 'Noel', 1);
/*!40000 ALTER TABLE `todo_list` ENABLE KEYS */;
/*!40101 SET SQL_MODE=IFNULL(@OLD_SQL_MODE, '') */;
/*!40014 SET FOREIGN_KEY_CHECKS=IF(@OLD_FOREIGN_KEY_CHECKS IS NULL, 1, @OLD_FOREIGN_KEY_CHECKS) */;
/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
=======
INSERT INTO `todo_list` (`id`, `nom`, `team_id`) VALUES
(1, 'Pour Blandine',1),
@ -182,6 +37,10 @@ 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);
>>>>>>> b147bc406c22caa9c817c7189a325058d8550a69
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`, `libelle`, `validation_proposition`, `team_id`) VALUES
(1, '2022-01-13', 'Lasagnes', 1, 1),
(2, '2022-01-03', 'Kebab', 1, 1);