favoris avec coeur rempli

This commit is contained in:
Thomas Cardon 2022-03-03 14:46:09 +01:00
parent ea3e2ad2ae
commit c70e3bab94
9 changed files with 95 additions and 31 deletions

View File

@ -23,6 +23,7 @@ import { AddRestauComponent } from './admin-component/add-restau/add-restau.comp
import { UpdateDelRestauComponent } from './admin-component/update-del-restau/update-del-restau.component';
import { HeaderLogoComponent } from './header/components/header-logo/header-logo.component';
import { AuthInterceptor } from './services/auth.interceptor';
import { FavorisUserComponent } from './pages/favoris-user/favoris-user.component';
@NgModule({
declarations: [
@ -44,7 +45,8 @@ import { AuthInterceptor } from './services/auth.interceptor';
AdminPageComponent,
AddRestauComponent,
UpdateDelRestauComponent,
HeaderLogoComponent
HeaderLogoComponent,
FavorisUserComponent
],
imports: [
BrowserModule,

View File

@ -3,7 +3,7 @@
<img class="card-img-top " src="assets/ImagesRestos/photo.jpg" alt="Card image cap">
<div class="rond position-absolute">
<app-icon class="heart"
[iconName]="isLiked ? 'heart-fill' : 'heart'"
[iconName]="restaurant.restauLike ? 'heart-fill' : 'heart'"
[iconColor]="'#e35d6a'"
(click)="onClickLike()"></app-icon></div>
<div class="card-body rounded-bottom">

View File

@ -30,10 +30,12 @@ export class CardRestoComponent implements OnInit {
this.restaurant.longitude)
);
}
onClickLike() {
console.log('click');
this.isLiked = !this.isLiked;
//this.isLiked = !this.isLiked;
this.clickLike.emit(this.isLiked);
}

View File

@ -1,8 +1,5 @@
<h2 class="titre ">Mes favoris :</h2>
<div class="separation"></div>
<div class="parent d-flex justify-content-center align-items-center">
<div class="card">
<h3>Mon top</h3>
</div>
<app-template-page [title]="'Favoris :'">
<div *ngFor="let pref of restaurantData">
<app-card-resto [restaurant]= "pref"></app-card-resto>
</div>
</app-template-page>

View File

@ -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,22 +10,39 @@ import { TokenService } from 'src/app/services/token.service';
})
export class FavorisUserComponent implements OnInit {
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;
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;
});
this.personneConnectee = resp;
}
);
console.log(this.personneConnectee);
}

View File

@ -4,4 +4,5 @@ export interface User {
lastName: string;
email: string;
password?: string;
preference ?: object;
}

View File

@ -1,6 +1,6 @@
<app-template-page [title]="'Résultats :'">
<div *ngFor="let restaurantData of listRestaurants">
<app-card-resto [restaurant]= "restaurantData"></app-card-resto>
<app-card-resto [restaurant]= "restaurantData" (clickLike)="onEventLike()"></app-card-resto>
</div>
</app-template-page>

View File

@ -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,14 +11,21 @@ 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"){
this.listRestaurants = this.apiBackService.restoFilter;
@ -26,15 +36,48 @@ 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.restauLiked();
}
}
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']);
}
console.log(this.apiBackService);
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;
});
}
);
}

View File

@ -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<any[]>(`${environment.apiUrl}/user/${id}`);
return this.httpClient.get<User>(`${environment.apiUrl}/user/${id}`);
}
}