From 4ed12d2d28e6387cb9cb7f50a0842120b2afbc3a Mon Sep 17 00:00:00 2001
From: Germain Louis <germain.louis.80@gmail.com>
Date: Mon, 6 Jan 2020 16:54:23 +0100
Subject: [PATCH 1/6] Add some dao pff

---
 Dev/kinder/database.sql                       |  5 +++
 .../kinder/controllers/CompteController.java  |  1 +
 .../controllers/RegisterController.java       | 10 +++--
 .../insarouen/asi/kinder/model/Matches.java   | 37 +++++++++++++++++++
 .../kinder/repository/CompteRepository.java   |  7 ++++
 .../kinder/repository/MatchesRepository.java  | 20 ++++++++++
 6 files changed, 76 insertions(+), 4 deletions(-)
 create mode 100644 Dev/kinder/src/main/java/fr/insarouen/asi/kinder/model/Matches.java
 create mode 100644 Dev/kinder/src/main/java/fr/insarouen/asi/kinder/repository/MatchesRepository.java

diff --git a/Dev/kinder/database.sql b/Dev/kinder/database.sql
index ed62112..2393263 100644
--- a/Dev/kinder/database.sql
+++ b/Dev/kinder/database.sql
@@ -11,6 +11,11 @@ CREATE TABLE photo(id int(11) not null auto_increment primary key,
                     pref int(11),
                     nom varchar(255));
 
+CREATE TABLE matches(id int(11) not null auto_increment primary key,
+                    user varchar(255),
+                    letarget varchar(255),
+                    alike boolean);
+
 insert into compte (adresse, mot_de_passe, nom, statut, type) values ('adresse1',
  'pedo',  'Aminou', 'statutactuel', 'admin'
 );
diff --git a/Dev/kinder/src/main/java/fr/insarouen/asi/kinder/controllers/CompteController.java b/Dev/kinder/src/main/java/fr/insarouen/asi/kinder/controllers/CompteController.java
index bcc8876..fe6fd2e 100644
--- a/Dev/kinder/src/main/java/fr/insarouen/asi/kinder/controllers/CompteController.java
+++ b/Dev/kinder/src/main/java/fr/insarouen/asi/kinder/controllers/CompteController.java
@@ -28,6 +28,7 @@ public class CompteController{
     //home utilisateur
     @RequestMapping("/me")
     public String mePage(Model model){
+        System.out.println(compteRepository.findByCriteria("Nina", "Rouen", "white"));
         Compte compte= compteRepository.findByNom(SecurityContextHolder.getContext().getAuthentication().getName());
         System.out.println(compte);
         model.addAttribute("compte", compte);
diff --git a/Dev/kinder/src/main/java/fr/insarouen/asi/kinder/controllers/RegisterController.java b/Dev/kinder/src/main/java/fr/insarouen/asi/kinder/controllers/RegisterController.java
index 75e499e..d7dfd96 100644
--- a/Dev/kinder/src/main/java/fr/insarouen/asi/kinder/controllers/RegisterController.java
+++ b/Dev/kinder/src/main/java/fr/insarouen/asi/kinder/controllers/RegisterController.java
@@ -64,10 +64,12 @@ public class RegisterController{
         compte.setRegion(upgradedAccount.getRegion());
         System.out.println(photos);
         int i=0;
-        for(MultipartFile file : photos){
-            storageService.store(file, compte.getNom());
-            photoRepository.save(new Photo(compte.getNom(), compte.getNom()+"_"+file.getOriginalFilename(), i));
-            i++;
+        if(photos.size()>0){
+            for(MultipartFile file : photos){
+                storageService.store(file, compte.getNom());
+                photoRepository.save(new Photo(compte.getNom(), compte.getNom()+"_"+file.getOriginalFilename(), i));
+                i++;
+            }
         }
         compteRepository.save(compte);
         return "redirect:/me";
diff --git a/Dev/kinder/src/main/java/fr/insarouen/asi/kinder/model/Matches.java b/Dev/kinder/src/main/java/fr/insarouen/asi/kinder/model/Matches.java
new file mode 100644
index 0000000..5ed168d
--- /dev/null
+++ b/Dev/kinder/src/main/java/fr/insarouen/asi/kinder/model/Matches.java
@@ -0,0 +1,37 @@
+package fr.insarouen.asi.kinder.model;
+
+import javax.persistence.Entity;
+import javax.persistence.GeneratedValue;
+import javax.persistence.Id;
+import javax.persistence.GenerationType;
+
+
+@Entity
+public class Matches{
+
+    @Id
+    @GeneratedValue(strategy = GenerationType.AUTO)
+    private long id;
+
+    private String user;
+    private String latarget;
+    private boolean alike;
+
+    public String getUser(){return user;}
+    public String getLatarget(){return latarget;}
+    public boolean getAlike(){return alike;}
+
+    public void setUser(String user){this.user=user;}
+    public void setLatarget(String latarget){this.latarget=latarget;}
+    public void setAlike(boolean alike){this.alike=alike;}
+
+
+    public Matches(){};
+
+    public Matches(String user, String target, Boolean alike){
+        this.user=user;
+        this.latarget=target;
+        this.alike=alike;
+    }
+
+}
\ No newline at end of file
diff --git a/Dev/kinder/src/main/java/fr/insarouen/asi/kinder/repository/CompteRepository.java b/Dev/kinder/src/main/java/fr/insarouen/asi/kinder/repository/CompteRepository.java
index e9b37df..c4a3307 100644
--- a/Dev/kinder/src/main/java/fr/insarouen/asi/kinder/repository/CompteRepository.java
+++ b/Dev/kinder/src/main/java/fr/insarouen/asi/kinder/repository/CompteRepository.java
@@ -1,6 +1,10 @@
 package fr.insarouen.asi.kinder.repository;
 
+import org.springframework.data.jpa.repository.Query;
 import org.springframework.data.repository.CrudRepository;
+import org.springframework.data.repository.query.Param;
+
+import java.util.List;
 
 import fr.insarouen.asi.kinder.model.Compte;
 
@@ -11,4 +15,7 @@ import fr.insarouen.asi.kinder.model.Compte;
 
 public interface CompteRepository extends CrudRepository<Compte, Integer> {
     public Compte findByNom(String nom);
+
+    @Query(value="select * from compte c where c.region=?2 and c.race=?3 and not(c.nom=?1)", nativeQuery = true)
+    public List<Compte> findByCriteria(@Param("user") String user, @Param("region") String location, @Param("race") String race);
 }
\ No newline at end of file
diff --git a/Dev/kinder/src/main/java/fr/insarouen/asi/kinder/repository/MatchesRepository.java b/Dev/kinder/src/main/java/fr/insarouen/asi/kinder/repository/MatchesRepository.java
new file mode 100644
index 0000000..f438e08
--- /dev/null
+++ b/Dev/kinder/src/main/java/fr/insarouen/asi/kinder/repository/MatchesRepository.java
@@ -0,0 +1,20 @@
+package fr.insarouen.asi.kinder.repository;
+
+import java.util.List;
+
+import org.springframework.data.repository.query.Param;
+import org.springframework.data.jpa.repository.Query;
+import org.springframework.data.repository.CrudRepository;
+
+import fr.insarouen.asi.kinder.model.Matches;
+
+public interface MatchesRepository extends CrudRepository<Matches, Integer>{
+
+
+    @Query(value="select * from matches m where m.user=?1", nativeQuery=true)
+    List<String> findSeenUsers(@Param("user") String user);
+
+    @Query(value="select n.user from matches m, matches n where n.user = m.target and m.user = n.target and n.like=true and m.like=true and m.user=?1", nativeQuery = true)
+    List<String> findMatches(@Param("user") String user);
+    
+}
\ No newline at end of file
-- 
GitLab


From 214439f920b12c685854954c5189b167964a5f3e Mon Sep 17 00:00:00 2001
From: Germain Louis <germain.louis.80@gmail.com>
Date: Mon, 6 Jan 2020 17:12:08 +0100
Subject: [PATCH 2/6] Add dao

---
 .../insarouen/asi/kinder/controllers/CompteController.java  | 5 +++++
 .../insarouen/asi/kinder/repository/MatchesRepository.java  | 6 +++---
 2 files changed, 8 insertions(+), 3 deletions(-)

diff --git a/Dev/kinder/src/main/java/fr/insarouen/asi/kinder/controllers/CompteController.java b/Dev/kinder/src/main/java/fr/insarouen/asi/kinder/controllers/CompteController.java
index fe6fd2e..dd14f63 100644
--- a/Dev/kinder/src/main/java/fr/insarouen/asi/kinder/controllers/CompteController.java
+++ b/Dev/kinder/src/main/java/fr/insarouen/asi/kinder/controllers/CompteController.java
@@ -12,6 +12,7 @@ import org.springframework.web.bind.annotation.RequestMapping;
 import fr.insarouen.asi.kinder.model.Compte;
 import fr.insarouen.asi.kinder.model.Photo;
 import fr.insarouen.asi.kinder.repository.CompteRepository;
+import fr.insarouen.asi.kinder.repository.MatchesRepository;
 import fr.insarouen.asi.kinder.repository.PhotoRepository;
 
 import org.springframework.web.bind.annotation.PathVariable;
@@ -25,10 +26,14 @@ public class CompteController{
     @Autowired
     PhotoRepository photoRepository;
 
+    @Autowired
+    MatchesRepository matchesRepository;
+
     //home utilisateur
     @RequestMapping("/me")
     public String mePage(Model model){
         System.out.println(compteRepository.findByCriteria("Nina", "Rouen", "white"));
+        System.out.println(matchesRepository.findSeenUsers("u1").get(0).getLatarget());
         Compte compte= compteRepository.findByNom(SecurityContextHolder.getContext().getAuthentication().getName());
         System.out.println(compte);
         model.addAttribute("compte", compte);
diff --git a/Dev/kinder/src/main/java/fr/insarouen/asi/kinder/repository/MatchesRepository.java b/Dev/kinder/src/main/java/fr/insarouen/asi/kinder/repository/MatchesRepository.java
index f438e08..924605f 100644
--- a/Dev/kinder/src/main/java/fr/insarouen/asi/kinder/repository/MatchesRepository.java
+++ b/Dev/kinder/src/main/java/fr/insarouen/asi/kinder/repository/MatchesRepository.java
@@ -12,9 +12,9 @@ public interface MatchesRepository extends CrudRepository<Matches, Integer>{
 
 
     @Query(value="select * from matches m where m.user=?1", nativeQuery=true)
-    List<String> findSeenUsers(@Param("user") String user);
+    List<Matches> findSeenUsers(@Param("user") String user);
 
     @Query(value="select n.user from matches m, matches n where n.user = m.target and m.user = n.target and n.like=true and m.like=true and m.user=?1", nativeQuery = true)
-    List<String> findMatches(@Param("user") String user);
-    
+    List<Matches> findMatches(@Param("user") String user);
+ 
 }
\ No newline at end of file
-- 
GitLab


From 84d446bb965436f0bb619b2315ae47d827f0a26c Mon Sep 17 00:00:00 2001
From: Germain Louis <germain.louis.80@gmail.com>
Date: Mon, 6 Jan 2020 17:35:47 +0100
Subject: [PATCH 3/6] Add search next to swipe

---
 .../kinder/controllers/CompteController.java  | 23 +++++++++++++++++--
 1 file changed, 21 insertions(+), 2 deletions(-)

diff --git a/Dev/kinder/src/main/java/fr/insarouen/asi/kinder/controllers/CompteController.java b/Dev/kinder/src/main/java/fr/insarouen/asi/kinder/controllers/CompteController.java
index dd14f63..0401985 100644
--- a/Dev/kinder/src/main/java/fr/insarouen/asi/kinder/controllers/CompteController.java
+++ b/Dev/kinder/src/main/java/fr/insarouen/asi/kinder/controllers/CompteController.java
@@ -10,6 +10,7 @@ import org.springframework.ui.Model;
 import org.springframework.web.bind.annotation.RequestMapping;
 
 import fr.insarouen.asi.kinder.model.Compte;
+import fr.insarouen.asi.kinder.model.Matches;
 import fr.insarouen.asi.kinder.model.Photo;
 import fr.insarouen.asi.kinder.repository.CompteRepository;
 import fr.insarouen.asi.kinder.repository.MatchesRepository;
@@ -34,6 +35,7 @@ public class CompteController{
     public String mePage(Model model){
         System.out.println(compteRepository.findByCriteria("Nina", "Rouen", "white"));
         System.out.println(matchesRepository.findSeenUsers("u1").get(0).getLatarget());
+        System.out.println(nextSwipedUser("u1", "Rouen", "white"));
         Compte compte= compteRepository.findByNom(SecurityContextHolder.getContext().getAuthentication().getName());
         System.out.println(compte);
         model.addAttribute("compte", compte);
@@ -43,8 +45,7 @@ public class CompteController{
         model.addAttribute("photoUser", photoRepository.findByUserOrderByIndexAsc(compte.getNom()).get(0).getNom());
         return "homePage";
     }
-
-
+    
     //gestionprofil
     @RequestMapping("/me/gestion")
     public String gestionPage(Model model){
@@ -68,4 +69,22 @@ public class CompteController{
         return "userInfosPage";
     }
 
+    private Compte nextSwipedUser(String user, String location, String race){
+        List<Compte> crit = compteRepository.findByCriteria(user, location, race);
+        List<Matches> seen = matchesRepository.findSeenUsers(user);
+        Boolean comp;
+        for(Compte compte : crit){
+            comp = true;
+            for(Matches match : seen){
+                if(match.getLatarget().equals(compte.getNom())){
+                    comp = false;
+                }
+            }
+            if(comp){
+                return compte;
+            }
+        }
+        return null;
+    }
+
 }
\ No newline at end of file
-- 
GitLab


From 0b27781cab7926879c7fc90b927e51b90e5f28b2 Mon Sep 17 00:00:00 2001
From: Germain Louis <germain.louis.80@gmail.com>
Date: Mon, 6 Jan 2020 17:44:11 +0100
Subject: [PATCH 4/6] Add swiped user interface

---
 .../fr/insarouen/asi/kinder/controllers/CompteController.java | 4 +++-
 Dev/kinder/src/main/resources/templates/homePage.html         | 4 ++--
 2 files changed, 5 insertions(+), 3 deletions(-)

diff --git a/Dev/kinder/src/main/java/fr/insarouen/asi/kinder/controllers/CompteController.java b/Dev/kinder/src/main/java/fr/insarouen/asi/kinder/controllers/CompteController.java
index 0401985..f3841d7 100644
--- a/Dev/kinder/src/main/java/fr/insarouen/asi/kinder/controllers/CompteController.java
+++ b/Dev/kinder/src/main/java/fr/insarouen/asi/kinder/controllers/CompteController.java
@@ -35,8 +35,10 @@ public class CompteController{
     public String mePage(Model model){
         System.out.println(compteRepository.findByCriteria("Nina", "Rouen", "white"));
         System.out.println(matchesRepository.findSeenUsers("u1").get(0).getLatarget());
-        System.out.println(nextSwipedUser("u1", "Rouen", "white"));
         Compte compte= compteRepository.findByNom(SecurityContextHolder.getContext().getAuthentication().getName());
+        Compte swipe = nextSwipedUser(compte.getNom(), "Rouen", "white");
+        model.addAttribute("nextSwipe",swipe);
+        model.addAttribute("photoSwipe", photoRepository.findByUserOrderByIndexAsc(swipe.getNom()).get(0).getNom());
         System.out.println(compte);
         model.addAttribute("compte", compte);
         if(compte.getOrientation()==null){
diff --git a/Dev/kinder/src/main/resources/templates/homePage.html b/Dev/kinder/src/main/resources/templates/homePage.html
index 83c8dfc..6085ea9 100644
--- a/Dev/kinder/src/main/resources/templates/homePage.html
+++ b/Dev/kinder/src/main/resources/templates/homePage.html
@@ -126,8 +126,8 @@
             </div>
             <div class="content-search-match">
                 <div class="content-search-match-picture">
-                    <img th:src="@{/images/placeholder-pp.png}" alt="">
-                    <div class="content-search-match-picture-name">Tonton</div>
+                    <img th:src="@{${'~/photos/'+photoSwipe}}" alt="">
+                    <div class="content-search-match-picture-name"><span th:text="${nextSwipe.getNom()}"></span></div>
                 </div>
                 <div class="content-search-match-choices">
                     <div class="content-search-match-choices-dislike">
-- 
GitLab


From f3ce06518e4c66f5f20fe6648e54e526af0e5557 Mon Sep 17 00:00:00 2001
From: Germain Louis <germain.louis.80@gmail.com>
Date: Mon, 6 Jan 2020 22:18:35 +0100
Subject: [PATCH 5/6] add matching buttons

---
 .../kinder/controllers/CompteController.java  | 17 ++++++----
 .../kinder/controllers/MatchController.java   | 33 +++++++++++++++++++
 .../asi/kinder/utils/ComptePlusPhoto.java     | 27 +++++++++++++++
 .../main/resources/templates/homePage.html    | 11 ++++---
 4 files changed, 76 insertions(+), 12 deletions(-)
 create mode 100644 Dev/kinder/src/main/java/fr/insarouen/asi/kinder/controllers/MatchController.java
 create mode 100644 Dev/kinder/src/main/java/fr/insarouen/asi/kinder/utils/ComptePlusPhoto.java

diff --git a/Dev/kinder/src/main/java/fr/insarouen/asi/kinder/controllers/CompteController.java b/Dev/kinder/src/main/java/fr/insarouen/asi/kinder/controllers/CompteController.java
index f3841d7..3dee17d 100644
--- a/Dev/kinder/src/main/java/fr/insarouen/asi/kinder/controllers/CompteController.java
+++ b/Dev/kinder/src/main/java/fr/insarouen/asi/kinder/controllers/CompteController.java
@@ -15,6 +15,7 @@ import fr.insarouen.asi.kinder.model.Photo;
 import fr.insarouen.asi.kinder.repository.CompteRepository;
 import fr.insarouen.asi.kinder.repository.MatchesRepository;
 import fr.insarouen.asi.kinder.repository.PhotoRepository;
+import fr.insarouen.asi.kinder.utils.ComptePlusPhoto;
 
 import org.springframework.web.bind.annotation.PathVariable;
 
@@ -36,15 +37,15 @@ public class CompteController{
         System.out.println(compteRepository.findByCriteria("Nina", "Rouen", "white"));
         System.out.println(matchesRepository.findSeenUsers("u1").get(0).getLatarget());
         Compte compte= compteRepository.findByNom(SecurityContextHolder.getContext().getAuthentication().getName());
-        Compte swipe = nextSwipedUser(compte.getNom(), "Rouen", "white");
-        model.addAttribute("nextSwipe",swipe);
-        model.addAttribute("photoSwipe", photoRepository.findByUserOrderByIndexAsc(swipe.getNom()).get(0).getNom());
-        System.out.println(compte);
-        model.addAttribute("compte", compte);
         if(compte.getOrientation()==null){
-            return "profilePage";
+            return "redirect:/me/gestion";
         }
-        model.addAttribute("photoUser", photoRepository.findByUserOrderByIndexAsc(compte.getNom()).get(0).getNom());
+        Compte swipe = nextSwipedUser(compte.getNom(), "Rouen", "white");
+        model.addAttribute("nextSwipe",new ComptePlusPhoto(swipe, photoRepository));
+        model.addAttribute("likeLink", "window.location.href='/me/like/"+swipe.getNom()+"'");
+        model.addAttribute("dislikeLink", "window.location.href='/me/like/"+swipe.getNom()+"'");
+        model.addAttribute("compte", new ComptePlusPhoto(compte, photoRepository));
+        System.out.println(compte);
         return "homePage";
     }
     
@@ -89,4 +90,6 @@ public class CompteController{
         return null;
     }
 
+    
+
 }
\ No newline at end of file
diff --git a/Dev/kinder/src/main/java/fr/insarouen/asi/kinder/controllers/MatchController.java b/Dev/kinder/src/main/java/fr/insarouen/asi/kinder/controllers/MatchController.java
new file mode 100644
index 0000000..31bee40
--- /dev/null
+++ b/Dev/kinder/src/main/java/fr/insarouen/asi/kinder/controllers/MatchController.java
@@ -0,0 +1,33 @@
+package fr.insarouen.asi.kinder.controllers;
+
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.security.core.context.SecurityContextHolder;
+import org.springframework.stereotype.Controller;
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.PathVariable;
+import org.springframework.web.bind.annotation.PostMapping;
+
+import fr.insarouen.asi.kinder.model.Matches;
+import fr.insarouen.asi.kinder.repository.MatchesRepository;
+
+@Controller
+public class MatchController{
+
+    @Autowired
+    MatchesRepository matchesRepository;
+
+    @GetMapping("/me/like/{user}")
+    public String userLikes(@PathVariable String user){
+        String compte = SecurityContextHolder.getContext().getAuthentication().getName();
+        matchesRepository.save(new Matches(compte, user, true));
+        return "redirect:/me";
+    }
+
+    @GetMapping("/me/dislike/{user}")
+    public String userDislikes(@PathVariable String user){
+        String compte = SecurityContextHolder.getContext().getAuthentication().getName();
+        matchesRepository.save(new Matches(compte, user, false));
+        return "redirect:/me";
+    }
+
+}
\ No newline at end of file
diff --git a/Dev/kinder/src/main/java/fr/insarouen/asi/kinder/utils/ComptePlusPhoto.java b/Dev/kinder/src/main/java/fr/insarouen/asi/kinder/utils/ComptePlusPhoto.java
new file mode 100644
index 0000000..6f1fe1f
--- /dev/null
+++ b/Dev/kinder/src/main/java/fr/insarouen/asi/kinder/utils/ComptePlusPhoto.java
@@ -0,0 +1,27 @@
+package fr.insarouen.asi.kinder.utils;
+
+import java.util.List;
+import java.util.stream.Collectors;
+
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.beans.factory.annotation.Configurable;
+
+import fr.insarouen.asi.kinder.model.Compte;
+import fr.insarouen.asi.kinder.repository.PhotoRepository;
+
+@Configurable
+public class ComptePlusPhoto{
+    private Compte compte;
+    private String photo;
+
+    private PhotoRepository photoRepository;
+
+    public Compte getCompte(){return this.compte;}
+    public String getPhoto(){return photoRepository.findByUserOrderByIndexAsc(compte.getNom()).get(0).getNom();}
+    public List<String> getPhotos(){return photoRepository.findByUserOrderByIndexAsc(compte.getNom()).stream().map(p->p.getNom()).collect(Collectors.toList());}
+
+    public ComptePlusPhoto(Compte compte, PhotoRepository repo){
+        this.compte=compte;
+        this.photoRepository=repo;
+    }
+}
\ No newline at end of file
diff --git a/Dev/kinder/src/main/resources/templates/homePage.html b/Dev/kinder/src/main/resources/templates/homePage.html
index 6085ea9..5f48fff 100644
--- a/Dev/kinder/src/main/resources/templates/homePage.html
+++ b/Dev/kinder/src/main/resources/templates/homePage.html
@@ -16,7 +16,7 @@
         <div class="content-user">
             <div class="content-user-header">
                 <div class="content-user-header-pp">
-                    <img th:src="@{${'~/photos/'+photoUser}}" alt="">
+                    <img th:src="@{${'~/photos/'+compte.getPhoto()}}" alt="">
                 </div>
                 <div class="content-user-header-params">
                     <img th:src="@{/images/gear.png}" alt="" onclick="location.href='/me/gestion'">
@@ -126,18 +126,19 @@
             </div>
             <div class="content-search-match">
                 <div class="content-search-match-picture">
-                    <img th:src="@{${'~/photos/'+photoSwipe}}" alt="">
-                    <div class="content-search-match-picture-name"><span th:text="${nextSwipe.getNom()}"></span></div>
+                    <img th:src="@{${'~/photos/'+nextSwipe.photo}}" alt="">
+                    <div class="content-search-match-picture-name"><span th:text="${nextSwipe.compte.getNom()}"></span></div>
                 </div>
                 <div class="content-search-match-choices">
                     <div class="content-search-match-choices-dislike">
-                        <img th:src="@{/images/close.svg}" alt="">
+                            <img th:src="@{/images/close.svg}" alt="" th:onclick="'window.location.href = \'' + @{/me/dislike/{id}(id=${nextSwipe.compte.nom})} + '\''">
+                        
                     </div>
                     <div class="content-search-match-choices-discuss">
                         <img th:src="@{/images/speech-bubble.svg}" style="opacity: 50%">
                     </div>
                     <div class="content-search-match-choices-like">
-                        <img th:src="@{/images/tick.svg}" alt="">
+                        <img th:src="@{/images/tick.svg}" alt="" th:onclick="'window.location.href = \'' + @{/me/like/{id}(id=${nextSwipe.compte.nom})} + '\''">
                     </div>
                 </div>
             </div>
-- 
GitLab


From 01c619ee8a6e288aabe730d2c0824d632941b917 Mon Sep 17 00:00:00 2001
From: Germain Louis <germain.louis.80@gmail.com>
Date: Mon, 6 Jan 2020 23:13:11 +0100
Subject: [PATCH 6/6] Systemes de matches fonctionnel

---
 .../kinder/controllers/CompteController.java  | 26 +++++++++++++++----
 .../kinder/repository/MatchesRepository.java  |  7 +++--
 .../main/resources/templates/homePage.html    |  5 +++-
 3 files changed, 30 insertions(+), 8 deletions(-)

diff --git a/Dev/kinder/src/main/java/fr/insarouen/asi/kinder/controllers/CompteController.java b/Dev/kinder/src/main/java/fr/insarouen/asi/kinder/controllers/CompteController.java
index 3dee17d..3051157 100644
--- a/Dev/kinder/src/main/java/fr/insarouen/asi/kinder/controllers/CompteController.java
+++ b/Dev/kinder/src/main/java/fr/insarouen/asi/kinder/controllers/CompteController.java
@@ -1,5 +1,6 @@
 package fr.insarouen.asi.kinder.controllers;
 
+import java.util.ArrayList;
 import java.util.List;
 import java.util.stream.Collectors;
 
@@ -34,16 +35,15 @@ public class CompteController{
     //home utilisateur
     @RequestMapping("/me")
     public String mePage(Model model){
-        System.out.println(compteRepository.findByCriteria("Nina", "Rouen", "white"));
-        System.out.println(matchesRepository.findSeenUsers("u1").get(0).getLatarget());
         Compte compte= compteRepository.findByNom(SecurityContextHolder.getContext().getAuthentication().getName());
+        System.out.println(makeMatches(compte.getNom()));
         if(compte.getOrientation()==null){
             return "redirect:/me/gestion";
         }
         Compte swipe = nextSwipedUser(compte.getNom(), "Rouen", "white");
-        model.addAttribute("nextSwipe",new ComptePlusPhoto(swipe, photoRepository));
-        model.addAttribute("likeLink", "window.location.href='/me/like/"+swipe.getNom()+"'");
-        model.addAttribute("dislikeLink", "window.location.href='/me/like/"+swipe.getNom()+"'");
+        if(swipe!=null){
+            model.addAttribute("nextSwipe",new ComptePlusPhoto(swipe, photoRepository));
+        }
         model.addAttribute("compte", new ComptePlusPhoto(compte, photoRepository));
         System.out.println(compte);
         return "homePage";
@@ -90,6 +90,22 @@ public class CompteController{
         return null;
     }
 
+    private List<Compte> makeMatches(String user){
+        List<Matches> targets = matchesRepository.findPeopleLikedByUser(user);
+        List<Matches> users = matchesRepository.findPeopleLinkingUser(user);
+        System.out.println("users"+users);
+        System.out.println("targets"+targets);
+        List<Compte> results = new ArrayList<Compte>();
+        for(Matches target : targets){
+            for(Matches theuser : users){
+                if(target.getUser().equals(theuser.getLatarget())){
+                    results.add(compteRepository.findByNom(target.getUser()));
+                }
+            }   
+        }
+        return results;
+    }
+
     
 
 }
\ No newline at end of file
diff --git a/Dev/kinder/src/main/java/fr/insarouen/asi/kinder/repository/MatchesRepository.java b/Dev/kinder/src/main/java/fr/insarouen/asi/kinder/repository/MatchesRepository.java
index 924605f..d97f2ec 100644
--- a/Dev/kinder/src/main/java/fr/insarouen/asi/kinder/repository/MatchesRepository.java
+++ b/Dev/kinder/src/main/java/fr/insarouen/asi/kinder/repository/MatchesRepository.java
@@ -14,7 +14,10 @@ public interface MatchesRepository extends CrudRepository<Matches, Integer>{
     @Query(value="select * from matches m where m.user=?1", nativeQuery=true)
     List<Matches> findSeenUsers(@Param("user") String user);
 
-    @Query(value="select n.user from matches m, matches n where n.user = m.target and m.user = n.target and n.like=true and m.like=true and m.user=?1", nativeQuery = true)
-    List<Matches> findMatches(@Param("user") String user);
+    @Query(value="select * from matches m where m.alike=1 and m.latarget=?1", nativeQuery = true)
+    List<Matches> findPeopleLikedByUser(@Param("user") String user);
+
+    @Query(value="select * from matches m where m.alike=1 and m.user=?1", nativeQuery=true)
+    List<Matches> findPeopleLinkingUser(@Param("user") String user);
  
 }
\ No newline at end of file
diff --git a/Dev/kinder/src/main/resources/templates/homePage.html b/Dev/kinder/src/main/resources/templates/homePage.html
index 5f48fff..a78d0b9 100644
--- a/Dev/kinder/src/main/resources/templates/homePage.html
+++ b/Dev/kinder/src/main/resources/templates/homePage.html
@@ -124,7 +124,7 @@
                     </div>
                 </form>
             </div>
-            <div class="content-search-match">
+            <div th:if="${nextSwipe}" class="content-search-match">
                 <div class="content-search-match-picture">
                     <img th:src="@{${'~/photos/'+nextSwipe.photo}}" alt="">
                     <div class="content-search-match-picture-name"><span th:text="${nextSwipe.compte.getNom()}"></span></div>
@@ -142,6 +142,9 @@
                     </div>
                 </div>
             </div>
+            <div th:otherwise="${nextSwipe}" class="content-search-match">
+                <span>Plus de profils à présenter</span>
+            </div>
         </div>
     </div>
 </body>
-- 
GitLab