likeRestau = ok
This commit is contained in:
parent
7615cebc20
commit
e3585e4979
@ -1,5 +1,6 @@
|
||||
import { Component,EventEmitter, Input, Output, OnInit } from '@angular/core';
|
||||
import { ApiBackService } from '../services/api-back.service';
|
||||
import { TokenService } from '../services/token.service';
|
||||
|
||||
@Component({
|
||||
selector: 'app-card-resto',
|
||||
@ -11,17 +12,20 @@ export class CardRestoComponent implements OnInit {
|
||||
@Input() restaurant : any ;
|
||||
distance : number;
|
||||
@Input() likeResto: any;
|
||||
@Output() clickLike = new EventEmitter<boolean>();
|
||||
//@Output() clickLike = new EventEmitter<boolean>();
|
||||
isLiked : boolean = false;
|
||||
priceRef = ["Indisponible","1-10€ ","11-20€","21-30€","31-40€"];
|
||||
private userId : number | null;
|
||||
|
||||
constructor(private apiBackService : ApiBackService) {
|
||||
constructor(private apiBackService : ApiBackService, private tokenService : TokenService) {
|
||||
this.distance = 0 ;
|
||||
this.userId = 0;
|
||||
|
||||
}
|
||||
|
||||
ngOnInit(): void {
|
||||
|
||||
this.userId = this.tokenService.getCurrentUserId();
|
||||
this.distance = Math.round(
|
||||
this.apiBackService.setDistance(
|
||||
48.86201110271593 , //latitude Simplon
|
||||
@ -36,7 +40,13 @@ export class CardRestoComponent implements OnInit {
|
||||
onClickLike() {
|
||||
console.log('click');
|
||||
this.restaurant.restauLike = !this.restaurant.restauLike;
|
||||
this.clickLike.emit(this.restaurant.restauLike);
|
||||
//this.clickLike.emit(this.restaurant.restauLike);
|
||||
|
||||
if(this.restaurant.restauLike){
|
||||
this.apiBackService.addPreference(this.userId,this.restaurant.id).subscribe();
|
||||
}else{
|
||||
this.apiBackService.deletePreference(this.userId,this.restaurant.id).subscribe();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
11
src/app/pages/models/preference.ts
Normal file
11
src/app/pages/models/preference.ts
Normal file
@ -0,0 +1,11 @@
|
||||
export interface Preference {
|
||||
preferencePK:{
|
||||
personne: {
|
||||
id: number | null
|
||||
},
|
||||
restau: {
|
||||
id: number | undefined
|
||||
}},
|
||||
note?: null,
|
||||
favoris?: null
|
||||
}
|
@ -5,6 +5,7 @@
|
||||
</div>
|
||||
</div>
|
||||
<div *ngFor="let restaurantData of listRestaurants">
|
||||
<app-card-resto [restaurant]="restaurantData" (clickLike)="onEventLike()"></app-card-resto>
|
||||
<app-card-resto [restaurant]="restaurantData" ></app-card-resto>
|
||||
<!-- (clickLike)="onEventLike($event, restaurantData.id)" -->
|
||||
</div>
|
||||
</app-template-page>
|
||||
|
@ -2,6 +2,7 @@ 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 { Preference } from '../models/preference';
|
||||
import { Restaurant } from '../models/restaurant';
|
||||
|
||||
@Component({
|
||||
@ -11,44 +12,39 @@ import { Restaurant } from '../models/restaurant';
|
||||
})
|
||||
export class RestoPageComponent implements OnInit {
|
||||
|
||||
public listRestaurants : any;
|
||||
public listRestaurants : Restaurant[];
|
||||
public listPref : any;
|
||||
public restaurantPref : any;
|
||||
public beforeRoute ?: string ;
|
||||
private userId : number | null;
|
||||
|
||||
constructor(private apiBackService : ApiBackService,
|
||||
private tokenService : TokenService) {
|
||||
this.listRestaurants = [];
|
||||
this.restaurantPref = [];
|
||||
this.beforeRoute = this.apiBackService.routeParam;
|
||||
this.userId=0;
|
||||
}
|
||||
|
||||
ngOnInit(): void {
|
||||
|
||||
this.restauLiked();
|
||||
|
||||
// // 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;
|
||||
this.userId = this.tokenService.getCurrentUserId();
|
||||
|
||||
// }else if(this.apiBackService.routeParam === "categories"){
|
||||
// this.apiBackService.restoByCat.subscribe((restaurants: any[]) => {
|
||||
// this.listRestaurants = restaurants;
|
||||
// });
|
||||
// }else{ // si on arrive sur l'url /restaurants directement = tous les restau affichés
|
||||
}
|
||||
|
||||
// onEventLike(liked : any, idRestau : number | undefined){
|
||||
// //this.apiBackService.restoLiked$.next(true);
|
||||
// console.log(this.userId);
|
||||
// console.log(idRestau);
|
||||
|
||||
// this.restauLiked();
|
||||
|
||||
// if(liked){
|
||||
// this.apiBackService.addPreference(this.userId,idRestau).subscribe();
|
||||
// }else{
|
||||
// this.apiBackService.deletePreference(this.userId,idRestau).subscribe();
|
||||
// }
|
||||
// }
|
||||
|
||||
}
|
||||
|
||||
onEventLike(){
|
||||
this.apiBackService.restoLiked$.next(true);
|
||||
console.log(this.apiBackService.restoLiked$);
|
||||
|
||||
}
|
||||
|
||||
saveRestauList(event : any){
|
||||
console.log(event);
|
||||
|
@ -80,5 +80,13 @@ export class ApiBackService {
|
||||
|
||||
this.restauAModif.emit(restau);
|
||||
}
|
||||
|
||||
public addPreference(idUser : number|null, idRestau:number|undefined) : Observable<any>{
|
||||
return this.httpClient.post<any>(`${environment.apiUrl}/add-preference/${idUser}/${idRestau}`, {});
|
||||
}
|
||||
|
||||
deletePreference(idUser : number|null, idRestau:number|undefined): Observable<any> {
|
||||
return this.httpClient.delete<any>(`${environment.apiUrl}/delete-preference/${idUser}/${idRestau}`);
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user