diff --git a/src/app/card-resto/card-resto.component.ts b/src/app/card-resto/card-resto.component.ts
index 4f67a19..974c93b 100644
--- a/src/app/card-resto/card-resto.component.ts
+++ b/src/app/card-resto/card-resto.component.ts
@@ -29,11 +29,13 @@ export class CardRestoComponent implements OnInit {
this.restaurant.latitude,
this.restaurant.longitude)
);
+
+
}
onClickLike() {
console.log('click');
- this.isLiked = !this.isLiked;
+ //this.isLiked = !this.isLiked;
this.clickLike.emit(this.isLiked);
}
diff --git a/src/app/pages/favoris-user/favoris-user.component.html b/src/app/pages/favoris-user/favoris-user.component.html
index 427f2ac..fef1864 100644
--- a/src/app/pages/favoris-user/favoris-user.component.html
+++ b/src/app/pages/favoris-user/favoris-user.component.html
@@ -1,8 +1,5 @@
-
-
+
\ No newline at end of file
diff --git a/src/app/pages/favoris-user/favoris-user.component.ts b/src/app/pages/favoris-user/favoris-user.component.ts
index 84adea7..f372d10 100644
--- a/src/app/pages/favoris-user/favoris-user.component.ts
+++ b/src/app/pages/favoris-user/favoris-user.component.ts
@@ -1,4 +1,5 @@
import { Component, OnInit } from '@angular/core';
+import { forkJoin } from 'rxjs';
import { ApiBackService } from 'src/app/services/api-back.service';
import { TokenService } from 'src/app/services/token.service';
@@ -9,24 +10,41 @@ import { TokenService } from 'src/app/services/token.service';
})
export class FavorisUserComponent implements OnInit {
- personneConnectee : any;
- constructor(private apiBackService : ApiBackService,private tokenService : TokenService) {
+ personneConnectee : any;
+ restaurantData : any[];
+ public listRestaurants : any;
+ public listPref : any;
+ public restaurantPref : any;
+
+ constructor(private apiBackService : ApiBackService, private tokenService : TokenService) {
+
+this.restaurantData = []
}
ngOnInit(): void {
-
this.apiBackService.getPersonneById(this.tokenService.getCurrentUserId()).subscribe(
- resp =>{
- console.log(resp);
+ user =>{
+
+ this.listPref = user.preference;
- this.personneConnectee = resp;
+ console.log(this.listPref);
+
+ for (let i = 0; i < this.listPref.length; i++) {
+ this.restaurantData.push(this.listPref[i]['preferencePK']['restau']);
+
+ }
+
+ this.restaurantData.forEach((restau: any) => {
+ //console.log(restau);
+ restau.restauLike = true;
+ });
+
}
);
- console.log(this.personneConnectee);
-
+
}
-}
+}
\ No newline at end of file
diff --git a/src/app/pages/models/user.ts b/src/app/pages/models/user.ts
index cfedcad..ca281f8 100644
--- a/src/app/pages/models/user.ts
+++ b/src/app/pages/models/user.ts
@@ -4,4 +4,5 @@ export interface User {
lastName: string;
email: string;
password?: string;
+ preference ?: object;
}
diff --git a/src/app/pages/resto-page/resto-page.component.html b/src/app/pages/resto-page/resto-page.component.html
index 12adc1d..f1f4ff8 100644
--- a/src/app/pages/resto-page/resto-page.component.html
+++ b/src/app/pages/resto-page/resto-page.component.html
@@ -1,6 +1,6 @@
diff --git a/src/app/pages/resto-page/resto-page.component.ts b/src/app/pages/resto-page/resto-page.component.ts
index 4b1aee8..5f4d94f 100644
--- a/src/app/pages/resto-page/resto-page.component.ts
+++ b/src/app/pages/resto-page/resto-page.component.ts
@@ -1,5 +1,8 @@
import { Component, OnInit } from '@angular/core';
+import { forkJoin } from 'rxjs';
import { ApiBackService } from 'src/app/services/api-back.service';
+import { TokenService } from 'src/app/services/token.service';
+import { Restaurant } from '../models/restaurant';
@Component({
selector: 'app-resto-page',
@@ -8,13 +11,20 @@ import { ApiBackService } from 'src/app/services/api-back.service';
})
export class RestoPageComponent implements OnInit {
- public listRestaurants : any[];
+ public listRestaurants : any;
+ public listPref : any;
+ public restaurantPref : any;
+ public beforeRoute ?: string ;
- constructor(private apiBackService : ApiBackService) {
+ constructor(private apiBackService : ApiBackService,
+ private tokenService : TokenService) {
this.listRestaurants = [];
+ this.restaurantPref = [];
}
ngOnInit(): void {
+
+ this.beforeRoute = this.apiBackService.routeParam;
// arrivée sur la restau-page depuis filtres ou home(catégories) : appel a une méthode différente du service
if(this.apiBackService.routeParam === "filtres"){
@@ -26,17 +36,50 @@ export class RestoPageComponent implements OnInit {
});
}else{ // si on arrive sur l'url /restaurants directement = tous les restau affichés
- this.apiBackService.getRestaurants().subscribe((restaurants: any[]) => {
- this.listRestaurants = restaurants;
- })
+ this.restauLiked();
+
}
- console.log(this.apiBackService);
-
-
-
-
}
+ onEventLike(){
+ this.apiBackService.restoLiked$.next('');
+ console.log(this.apiBackService.restoLiked$);
+
+
+ }
+
+ restauLiked(){
+
+ forkJoin({
+ restaurants: this.apiBackService.getRestaurants(),
+ user: this.apiBackService.getPersonneById(this.tokenService.getCurrentUserId())
+ }).subscribe(({restaurants, user}) => {
+
+ this.listRestaurants = restaurants;
+
+ this.listPref = user.preference;
+
+ for (let i = 0; i < this.listPref.length; i++) {
+ this.restaurantPref.push(this.listPref[i]['preferencePK']['restau']);
+ }
+
+ const listRestauIdLike = this.restaurantPref.map((x: any) => x.id);
+
+ this.listRestaurants.forEach((restau: any) => {
+
+
+ if(listRestauIdLike.includes(restau.id))
+
+ //console.log(restau);
+ restau.restauLike = true;
+ });
+
+ }
+ );
+
+
+ }
+
}
diff --git a/src/app/services/api-back.service.ts b/src/app/services/api-back.service.ts
index 091ff2b..1c01325 100644
--- a/src/app/services/api-back.service.ts
+++ b/src/app/services/api-back.service.ts
@@ -3,6 +3,7 @@ import { Observable, of, Subject } from 'rxjs';
import { HttpClient } from '@angular/common/http';
import { environment } from 'src/environments/environment';
import { Restaurant } from '../pages/models/restaurant';
+import { User } from '../pages/models/user';
@Injectable({
providedIn: 'root'
@@ -71,6 +72,6 @@ export class ApiBackService {
}
getPersonneById(id: any) {
- return this.httpClient.get
(`${environment.apiUrl}/user/${id}`);
+ return this.httpClient.get(`${environment.apiUrl}/user/${id}`);
}
}
\ No newline at end of file