From d86cfb2e87248d9389339f8f21328ae7d5810c53 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joe=20Ku=CC=88ng?= Date: Wed, 3 May 2023 12:15:13 +0200 Subject: [PATCH 1/2] progress for cookie --- src/app/component/login/login.component.html | 2 +- src/app/component/login/login.component.ts | 25 ++++++- src/app/home/home.component.ts | 2 - src/app/service/cookie.service.ts | 4 +- src/app/service/readjson.service.ts | 71 -------------------- 5 files changed, 26 insertions(+), 78 deletions(-) delete mode 100644 src/app/service/readjson.service.ts diff --git a/src/app/component/login/login.component.html b/src/app/component/login/login.component.html index f656508..f681a9d 100644 --- a/src/app/component/login/login.component.html +++ b/src/app/component/login/login.component.html @@ -9,7 +9,7 @@
-
diff --git a/src/app/component/login/login.component.ts b/src/app/component/login/login.component.ts index 80a60e8..93f098b 100644 --- a/src/app/component/login/login.component.ts +++ b/src/app/component/login/login.component.ts @@ -1,10 +1,31 @@ -import { Component } from '@angular/core'; +import {Component, OnInit} from '@angular/core'; +import {Router} from "@angular/router"; +import {TranslateService} from "../../service/language/translate.service"; +import {ReadTranslateJsonService} from "../../service/language/readTranslateJson.service"; +import {cookieService} from "../../service/cookie.service"; @Component({ selector: 'app-login', templateUrl: './login.component.html', styleUrls: ['./login.component.css'] }) -export class LoginComponent { +export class LoginComponent implements OnInit{ + + constructor( + private router: Router, + private translateService: TranslateService, + private readTranslationJsonService: ReadTranslateJsonService, + private cookieService: cookieService, + ) { + } + + ngOnInit(): void { + + + } + + submit(username: string, password: string) { + + } } diff --git a/src/app/home/home.component.ts b/src/app/home/home.component.ts index 2f5c906..c1255ff 100644 --- a/src/app/home/home.component.ts +++ b/src/app/home/home.component.ts @@ -1,6 +1,5 @@ import {AfterViewInit, Component, ElementRef, OnDestroy, OnInit, ViewChild} from '@angular/core'; import {distinctUntilChanged, fromEvent, Subject, Subscription} from "rxjs"; -import {ReadjsonService} from "../service/readjson.service"; import {Router} from "@angular/router"; import {TranslateService} from '../service/language/translate.service'; import {ReadTranslateJsonService} from "../service/language/readTranslateJson.service"; @@ -34,7 +33,6 @@ export class HomeComponent implements OnInit, AfterViewInit, OnDestroy { constructor( - private readjsonService: ReadjsonService, private router: Router, private translateService: TranslateService, private readTranslationJsonService: ReadTranslateJsonService, diff --git a/src/app/service/cookie.service.ts b/src/app/service/cookie.service.ts index 2bf6a1e..cb0843a 100644 --- a/src/app/service/cookie.service.ts +++ b/src/app/service/cookie.service.ts @@ -19,8 +19,8 @@ export class cookieService { getUsername(): string { let username = this.coockieService.get('username'); - if (username == null) { - this.router.navigate(['/login']); + if (username == '' || username == undefined) { + this.router.navigate(['/login']).then(r => console.log("redirect to login")); return ''; } else { return username; diff --git a/src/app/service/readjson.service.ts b/src/app/service/readjson.service.ts deleted file mode 100644 index d9b65cf..0000000 --- a/src/app/service/readjson.service.ts +++ /dev/null @@ -1,71 +0,0 @@ -import {Injectable} from '@angular/core'; -import {HttpClient} from "@angular/common/http"; -import {Locations, waypoint} from "../interface/data"; -import {BehaviorSubject, map, Observable, tap} from "rxjs"; - - -@Injectable({ - providedIn: 'root' -}) -export class ReadjsonService{ - private locations: BehaviorSubject = new BehaviorSubject([]); - - constructor(private http: HttpClient) { - this.http.get('assets/data.json').subscribe(data => { - this.locations.next(data) - console.log("data loaded", data) - }); - } - getLocations(): Observable[]> { - return this.locations.pipe( - map((locations) => { - return locations.map((loc: Locations) => ({ - location: loc.location, - region: loc.region, - lat: loc.lat, - lon: loc.lon - })) - }), - tap(data => console.log("data requested", data))) - } - - getLocation(location: string): Observable { - return this.locations.pipe( - map((locations) => { - const foundLocation: Locations | undefined = locations.find((loc: Locations) => loc.location === location); - return foundLocation ? foundLocation : {location: '', region: '', lat: 0, lon: 0, waypoints: []}; - }), - tap(data => console.log("data requested", data)) - ); - } - - - getWaypoint(location: string, id: number): Observable { - return this.locations.pipe( - map((locations) => { - const foundLocation: Locations | undefined = locations.find((loc: Locations) => loc.location === location); - if (foundLocation?.waypoints) { - return foundLocation ? foundLocation.waypoints.filter((way: waypoint) => way.id === id) : []; - } else { - return [] - } - }), - tap(data => console.log("data requested", data)) - ); - } - - getWaypoints(location: string): Observable { - return this.locations.pipe( - map((locations) => { - const foundLocation: Locations | undefined = locations.find((loc: Locations) => loc.location === location); - if (foundLocation?.waypoints) { - return foundLocation ? foundLocation.waypoints : []; - } else { - return [] - } - }), - tap(data => console.log("data requested", data)) - ); - } - -} From f7d6d19b5b255e215234ff992e4ebd47304c0110 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joe=20Ku=CC=88ng?= Date: Wed, 3 May 2023 15:04:39 +0200 Subject: [PATCH 2/2] fix waypointVisited --- .../service/http/waypointVisited.service.ts | 23 +++++++++---------- 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/src/app/service/http/waypointVisited.service.ts b/src/app/service/http/waypointVisited.service.ts index 9e0bff7..41ee165 100644 --- a/src/app/service/http/waypointVisited.service.ts +++ b/src/app/service/http/waypointVisited.service.ts @@ -1,12 +1,11 @@ import {Injectable} from "@angular/core"; import {HttpClient} from "@angular/common/http"; -import {catchError, Observable} from "rxjs"; -import {LocationEntity} from "../../interface/LocationEntity"; import {WaypointsEntity} from "../../interface/WaypointsEntity"; +import {WaypointsVisitedEntity} from "../../interface/WaypointsVisitedEntity"; const BASE_URL = "progetto152"; -const WAYPOINT_VISITED = BASE_URL + "/waypoint/visited/"; -const GET_WAYPOINT_BY_USER = WAYPOINT_VISITED + "USER/"; +const WAYPOINT_VISITED = BASE_URL + "/waypoint/visited"; +const GET_WAYPOINT_BY_USER = WAYPOINT_VISITED + "/USER/"; @Injectable({ @@ -20,26 +19,26 @@ export class WaypointVisitedService { } getWaypoints() { - return this.http.get(WAYPOINT_VISITED); + return this.http.get(WAYPOINT_VISITED); } getwaypointVisited(id: number) { - return this.http.get(WAYPOINT_VISITED + id); + return this.http.get(WAYPOINT_VISITED +"/"+ id); } getWaypointByUser(user: string) { - return this.http.get(GET_WAYPOINT_BY_USER + user); + return this.http.get(GET_WAYPOINT_BY_USER + user); } - createWaypoint(waypoint: WaypointsEntity) { - return this.http.post(WAYPOINT_VISITED, waypoint); + createWaypoint(waypointvisited: WaypointsVisitedEntity) { + return this.http.post(WAYPOINT_VISITED, waypointvisited); } - updateWaypoint(waypoint: WaypointsEntity, id: number) { - return this.http.put(WAYPOINT_VISITED + id, waypoint); + updateWaypoint(waypoint: WaypointsVisitedEntity, id: number) { + return this.http.put(WAYPOINT_VISITED +"/"+ id, waypoint); } deleteWaypoint(id: number) { - return this.http.delete(WAYPOINT_VISITED + id); + return this.http.delete(WAYPOINT_VISITED + id); } }