Commit d1d16f06a377ec961202f23e3bfdce64691e0d34

Authored by sfeutrie
1 parent deabfae9

implementation de l'ajout de maj

Il est possible d'entrer les paramètres de la maj puis de l'ajout dans la table de donnée. Le lien entre l'utilisateur et sa maj est fait automatiquement
PFE06/src/main/java/com/PFE/ServerManager/Customer.java
... ... @@ -29,9 +29,20 @@ public class Customer{
29 29 @JoinTable(name = "customer_role", joinColumns = @JoinColumn(name = "customer_id"), inverseJoinColumns = @JoinColumn(name = "role_id"))
30 30 private Set<Role> roles;
31 31  
  32 + @ManyToMany(cascade = CascadeType.ALL)
  33 + @JoinTable(name = "customer_maj", joinColumns = @JoinColumn(name = "customer_id"), inverseJoinColumns = @JoinColumn(name = "maj_id"))
  34 + private Set<Maj> maj;
  35 +
32 36 public void setRoles(Set<Role> roles) { this.roles = roles; }
33 37 public Set<Role> getRoles() { return roles; }
34 38  
  39 + public void setMaj(Set<Maj> maj) {
  40 + this.maj = maj;
  41 + }
  42 + public Set<Maj> getMaj() {
  43 + return maj;
  44 + }
  45 +
35 46 public String getRole(){
36 47 return roles.iterator().next().getRole();
37 48 }
... ...
PFE06/src/main/java/com/PFE/ServerManager/MainController.java
... ... @@ -28,6 +28,9 @@ public class MainController {
28 28 RoleRepository roleRepository;
29 29  
30 30 @Autowired
  31 + MajRepository majRepository;
  32 +
  33 + @Autowired
31 34 BCryptPasswordEncoder bCryptPasswordEncoder;
32 35  
33 36 @GetMapping(value="/")
... ... @@ -193,9 +196,20 @@ public class MainController {
193 196 }
194 197  
195 198 @PostMapping(path="/test")
196   - public String test() {
197   - //ModelAndView modelAndView = new ModelAndView();
198   - //modelAndView.setViewName("test");
199   - return "test";
  199 + public ModelAndView addNewUser(@RequestParam String maj, @RequestParam String date, @RequestParam String set1, @RequestParam String set2){
  200 + ModelAndView modelAndView = new ModelAndView();
  201 + modelAndView.setViewName("test");
  202 + Authentication auth = SecurityContextHolder.getContext().getAuthentication();
  203 + Customer customer = customerRepository.findByEmail(auth.getName());
  204 + Maj maj_c = new Maj();
  205 + maj_c.setMaj(maj);
  206 + maj_c.setDate(date);
  207 + String nodes=set1+';'+set2;
  208 + maj_c.setNodes(nodes);
  209 + maj_c.setMaj_id((int)(majRepository.count() + 1));
  210 + majRepository.save(maj_c); // ajouter la mise a jour dans la table
  211 + customer.setMaj(new HashSet<Maj>(Arrays.asList(maj_c)));
  212 + customerRepository.save(customer); // permet de rendre effective la jointure entre customer et maj
  213 + return modelAndView;
200 214 }
201 215 }
202 216 \ No newline at end of file
... ...
PFE06/src/main/java/com/PFE/ServerManager/Maj.java
... ... @@ -16,11 +16,16 @@ public class Maj {
16 16 @Column(name = "date")
17 17 private String date;
18 18  
  19 + /*
19 20 @Column(name = "nodes")
20 21 private String nodes;
21 22  
22 23 @Column(name = "file")
23 24 private String file;
  25 + */
  26 +
  27 + @Column(name = "nodes")
  28 + private String nodes;
24 29  
25 30 public void setMaj_id(Integer maj_id) { this.maj_id = maj_id; }
26 31 public Integer getMaj_id() { return maj_id; }
... ... @@ -30,6 +35,17 @@ public class Maj {
30 35 }
31 36 public String getMaj() { return maj; }
32 37  
  38 + public void setDate(String date) {
  39 + this.date = date;
  40 + }
  41 + public String getDate() {
  42 + return date;
  43 + }
33 44  
34   -
  45 + public void setNodes(String nodes) {
  46 + this.nodes = nodes;
  47 + }
  48 + public String getNodes() {
  49 + return nodes;
  50 + }
35 51 }
... ...
PFE06/src/main/java/com/PFE/ServerManager/MajRepository.java 0 → 100644
... ... @@ -0,0 +1,11 @@
  1 +package com.PFE.ServerManager;
  2 +
  3 +import org.springframework.data.jpa.repository.JpaRepository;
  4 +import org.springframework.stereotype.Repository;
  5 +
  6 +@Repository
  7 +public interface MajRepository extends JpaRepository<Maj, Integer> {
  8 +
  9 + //Customer findByEmail(String email);
  10 +
  11 +}
... ...
PFE06/src/main/resources/templates/home.html
... ... @@ -34,6 +34,7 @@
34 34 <a class="dropdown-item" th:href="@{/registration}">Enregistrer des utilisateurs</a>
35 35 <a class="dropdown-item" th:href="@{/all}">Listes des utilisateurs</a>
36 36 <a class="dropdown-item" th:href="@{/session}">Paramétrer une mise à jour</a>
  37 + <a class="dropdown-item" th:href="@{/test}">test maj</a>
37 38 </div>
38 39 <div th:case="'USER'">
39 40 <a class="dropdown-item" th:href="@{/session}">Paramétrer une mise à jour</a>
... ...
PFE06/src/main/resources/templates/registration.html
... ... @@ -58,7 +58,7 @@
58 58  
59 59 <form id="Login" th:action="@{/registration}" method="POST">
60 60 <div class="form-group">
61   - <input type="text" v-model="user.login" class="form-control" id="username" placeholder="Entrer le pseudo" name="pseudo">
  61 + <input type="text" v-model="user.login" class="form-control" id="username" placeholder="Entrer le pseudo" name="email">
62 62 </div>
63 63 <div class="form-group">
64 64 <input type="password" v-model="user.password" class="form-control" id="password" placeholder="Entrer le mot de passe" name="password">
... ...
PFE06/src/main/resources/templates/test.html
1 1 <!DOCTYPE html>
  2 +<html xmlns:th="http://www.thymeleaf.org">
2 3 <html lang="en">
3   -<head>
4   - <meta charset="UTF-8">
5   - <title>Data from js test</title>
6   -</head>
7   -<body>
8   - <div>
9   -
10   - </div>
11   -</body>
  4 + <head>
  5 + <meta charset="UTF-8">
  6 + <title>Data from js test</title>
  7 + </head>
  8 + <body>
  9 + <form id="Login" th:action="@{/test}" method="POST">
  10 + <div class="form-group">
  11 + <input type="text" class="form-control" id="maj" placeholder="Entrer le nom de la maj" name="maj">
  12 + </div>
  13 + <div class="form-group">
  14 + <input type="text" class="form-control" id="date" placeholder="Entrer la date" name="date">
  15 + </div>
  16 + <div class="form-group">
  17 + <input type="text" class="form-control" id="set1" placeholder="set1" name="set1">
  18 + </div>
  19 + <div class="form-group">
  20 + <input type="text" class="form-control" id="set2" placeholder="set2" name="set2">
  21 + </div>
  22 + <button @click.prevent="registration" type="submit" class="btn btn-primary">Ajouter</button>
  23 + </form>
  24 + </body>
12 25 </html>
13 26 \ No newline at end of file
... ...