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 { Component,EventEmitter, Input, Output, OnInit } from '@angular/core';
|
||||||
import { ApiBackService } from '../services/api-back.service';
|
import { ApiBackService } from '../services/api-back.service';
|
||||||
|
import { TokenService } from '../services/token.service';
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'app-card-resto',
|
selector: 'app-card-resto',
|
||||||
@ -11,17 +12,20 @@ export class CardRestoComponent implements OnInit {
|
|||||||
@Input() restaurant : any ;
|
@Input() restaurant : any ;
|
||||||
distance : number;
|
distance : number;
|
||||||
@Input() likeResto: any;
|
@Input() likeResto: any;
|
||||||
@Output() clickLike = new EventEmitter<boolean>();
|
//@Output() clickLike = new EventEmitter<boolean>();
|
||||||
isLiked : boolean = false;
|
isLiked : boolean = false;
|
||||||
priceRef = ["Indisponible","1-10€ ","11-20€","21-30€","31-40€"];
|
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.distance = 0 ;
|
||||||
|
this.userId = 0;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ngOnInit(): void {
|
ngOnInit(): void {
|
||||||
|
|
||||||
|
this.userId = this.tokenService.getCurrentUserId();
|
||||||
this.distance = Math.round(
|
this.distance = Math.round(
|
||||||
this.apiBackService.setDistance(
|
this.apiBackService.setDistance(
|
||||||
48.86201110271593 , //latitude Simplon
|
48.86201110271593 , //latitude Simplon
|
||||||
@ -36,7 +40,13 @@ export class CardRestoComponent implements OnInit {
|
|||||||
onClickLike() {
|
onClickLike() {
|
||||||
console.log('click');
|
console.log('click');
|
||||||
this.restaurant.restauLike = !this.restaurant.restauLike;
|
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>
|
</div>
|
||||||
<div *ngFor="let restaurantData of listRestaurants">
|
<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>
|
</div>
|
||||||
</app-template-page>
|
</app-template-page>
|
||||||
|
@ -2,6 +2,7 @@ import { Component, OnInit } from '@angular/core';
|
|||||||
import { forkJoin } from 'rxjs';
|
import { forkJoin } from 'rxjs';
|
||||||
import { ApiBackService } from 'src/app/services/api-back.service';
|
import { ApiBackService } from 'src/app/services/api-back.service';
|
||||||
import { TokenService } from 'src/app/services/token.service';
|
import { TokenService } from 'src/app/services/token.service';
|
||||||
|
import { Preference } from '../models/preference';
|
||||||
import { Restaurant } from '../models/restaurant';
|
import { Restaurant } from '../models/restaurant';
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
@ -11,44 +12,39 @@ import { Restaurant } from '../models/restaurant';
|
|||||||
})
|
})
|
||||||
export class RestoPageComponent implements OnInit {
|
export class RestoPageComponent implements OnInit {
|
||||||
|
|
||||||
public listRestaurants : any;
|
public listRestaurants : Restaurant[];
|
||||||
public listPref : any;
|
public listPref : any;
|
||||||
public restaurantPref : any;
|
public restaurantPref : any;
|
||||||
public beforeRoute ?: string ;
|
public beforeRoute ?: string ;
|
||||||
|
private userId : number | null;
|
||||||
|
|
||||||
constructor(private apiBackService : ApiBackService,
|
constructor(private apiBackService : ApiBackService,
|
||||||
private tokenService : TokenService) {
|
private tokenService : TokenService) {
|
||||||
this.listRestaurants = [];
|
this.listRestaurants = [];
|
||||||
this.restaurantPref = [];
|
this.restaurantPref = [];
|
||||||
this.beforeRoute = this.apiBackService.routeParam;
|
this.beforeRoute = this.apiBackService.routeParam;
|
||||||
|
this.userId=0;
|
||||||
}
|
}
|
||||||
|
|
||||||
ngOnInit(): void {
|
ngOnInit(): void {
|
||||||
|
|
||||||
this.restauLiked();
|
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;
|
|
||||||
|
|
||||||
// }else if(this.apiBackService.routeParam === "categories"){
|
this.userId = this.tokenService.getCurrentUserId();
|
||||||
// this.apiBackService.restoByCat.subscribe((restaurants: any[]) => {
|
|
||||||
// this.listRestaurants = restaurants;
|
|
||||||
// });
|
|
||||||
// }else{ // si on arrive sur l'url /restaurants directement = tous les restau affichés
|
|
||||||
|
|
||||||
|
|
||||||
// this.restauLiked();
|
|
||||||
|
|
||||||
// }
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
onEventLike(){
|
// onEventLike(liked : any, idRestau : number | undefined){
|
||||||
this.apiBackService.restoLiked$.next(true);
|
// //this.apiBackService.restoLiked$.next(true);
|
||||||
console.log(this.apiBackService.restoLiked$);
|
// console.log(this.userId);
|
||||||
|
// console.log(idRestau);
|
||||||
|
|
||||||
}
|
// if(liked){
|
||||||
|
// this.apiBackService.addPreference(this.userId,idRestau).subscribe();
|
||||||
|
// }else{
|
||||||
|
// this.apiBackService.deletePreference(this.userId,idRestau).subscribe();
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
|
||||||
saveRestauList(event : any){
|
saveRestauList(event : any){
|
||||||
console.log(event);
|
console.log(event);
|
||||||
|
@ -80,5 +80,13 @@ export class ApiBackService {
|
|||||||
|
|
||||||
this.restauAModif.emit(restau);
|
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