Merge remote-tracking branch 'origin/dev' into dev

# Conflicts:
#	src/app/component/detail/detail.component.html
This commit is contained in:
tito
2023-04-30 14:51:46 +02:00
28 changed files with 885 additions and 193 deletions

View File

@@ -1,25 +0,0 @@
import { Injectable } from '@angular/core';
import { HttpClient, HttpParams } from '@angular/common/http';
import { Observable } from 'rxjs';
import { environment } from '../../environments/environment';
@Injectable({
providedIn: 'root'
})
export class DeepLService {
private apiUrl = 'https://api-free.deepl.com/v2/translate';
private apiKey = environment.deepLApiKey;
constructor(private http: HttpClient) { }
translate(text: string, targetLang: string): Observable<any> {
const params = new HttpParams()
.set('auth_key', this.apiKey)
.set('text', text)
.set('target_lang', targetLang);
return this.http.post(this.apiUrl, params);
}
}

View File

@@ -0,0 +1,39 @@
import {Injectable} from "@angular/core";
import {HttpClient} from "@angular/common/http";
import {LocationEntity} from "../../interface/LocationEntity";
const BASE_URL = "progetto152";
const LOCATION = BASE_URL + "/location";
@Injectable({
providedIn: 'root',
})
export class LocationService {
constructor(
private http: HttpClient,
) {
}
getLocations() {
return this.http.get<LocationEntity[]>(LOCATION);
}
getLocation(location: string) {
return this.http.get<LocationEntity>(LOCATION + "/" + location);
}
createLocation(location: LocationEntity) {
return this.http.post<LocationEntity>(LOCATION, location);
}
updateLocation(location: LocationEntity) {
return this.http.put<LocationEntity>(LOCATION, location);
}
deleteLocation(id: number) {
return this.http.delete<LocationEntity>(LOCATION + id);
}
}

View File

@@ -0,0 +1,43 @@
import {Injectable} from "@angular/core";
import {HttpClient} from "@angular/common/http";
import {UserEntity} from "../../interface/UserEntity";
const BASE_URL = "progetto152";
const USER = BASE_URL + "/user";
const GET_USER_BY_ID = USER + "/id";
@Injectable({
providedIn: 'root',
})
export class UserService {
constructor(
private http: HttpClient,
) {
}
getUsers() {
return this.http.get<UserEntity[]>(USER);
}
getUser(username: string) {
return this.http.get<UserEntity>(USER + "/" + username);
}
getUserById(id: number) {
return this.http.get<UserEntity>(GET_USER_BY_ID + "/" + id);
}
createUser(user: UserEntity) {
return this.http.post<UserEntity>(USER, user);
}
updateUser(user: UserEntity, id: number) {
return this.http.put<UserEntity>(USER + id, user);
}
deleteUser(id: number) {
return this.http.delete<UserEntity>(USER + id);
}
}

View File

@@ -0,0 +1,49 @@
import {Injectable} from "@angular/core";
import {HttpClient} from "@angular/common/http";
import {WaypointsEntity} from "../../interface/WaypointsEntity";
import {catchError, throwError} from "rxjs";
const BASE_URL = "progetto152";
const WAYPOINT = BASE_URL + "/waypoint";
const GET_WAYPOINT_BY_ID = WAYPOINT + "id/";
@Injectable({
providedIn: 'root',
})
export class WaypointService {
constructor(
private http: HttpClient,
) {
}
getAllWaypoints() {
return this.http.get<WaypointsEntity[]>(WAYPOINT);
}
getWaypoints(location: string) {
return this.http.get<WaypointsEntity[]>(WAYPOINT + "/" + location)
}
getWaypoint(location: string, id: number) {
return this.http.get<WaypointsEntity>(WAYPOINT + "/" + location + "/" + id);
}
getWaypointById(id: number) {
return this.http.get<WaypointsEntity>(GET_WAYPOINT_BY_ID + id);
}
createWaypoint(waypoint: WaypointsEntity) {
return this.http.post<WaypointsEntity>(WAYPOINT, waypoint);
}
updateWaypoint(waypoint: WaypointsEntity, id: number) {
return this.http.put<WaypointsEntity>(WAYPOINT + "/" + id, waypoint);
}
deleteWaypoint(id: number) {
return this.http.delete<WaypointsEntity>(WAYPOINT + id);
}
}

View File

@@ -0,0 +1,45 @@
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";
const BASE_URL = "progetto152";
const WAYPOINT_VISITED = BASE_URL + "/waypoint/visited/";
const GET_WAYPOINT_BY_USER = WAYPOINT_VISITED + "USER/";
@Injectable({
providedIn: 'root',
})
export class WaypointVisitedService {
constructor(
private http: HttpClient,
) {
}
getWaypoints() {
return this.http.get<WaypointsEntity[]>(WAYPOINT_VISITED);
}
getwaypointVisited(id: number) {
return this.http.get<WaypointsEntity>(WAYPOINT_VISITED + id);
}
getWaypointByUser(user: string) {
return this.http.get<WaypointsEntity[]>(GET_WAYPOINT_BY_USER + user);
}
createWaypoint(waypoint: WaypointsEntity) {
return this.http.post<WaypointsEntity>(WAYPOINT_VISITED, waypoint);
}
updateWaypoint(waypoint: WaypointsEntity, id: number) {
return this.http.put<WaypointsEntity>(WAYPOINT_VISITED + id, waypoint);
}
deleteWaypoint(id: number) {
return this.http.delete<WaypointsEntity>(WAYPOINT_VISITED + id);
}
}

View File

@@ -0,0 +1,30 @@
import {Injectable} from '@angular/core';
import {HttpClient, HttpParams} from '@angular/common/http';
import {Observable} from 'rxjs';
import {environment} from '../../../environments/environment';
@Injectable({
providedIn: 'root'
})
export class DeepLService {
// Define the base URL for the DeepL API and the API key, taken from the environment configuration
private apiUrl = 'https://api-free.deepl.com/v2/translate';
private apiKey = environment.deepLApiKey;
constructor(private http: HttpClient) {
}
// Define the method for translating text, which takes the text to be translated and the target language as parameters
translate(text: string, targetLang: string): Observable<any> {
// Define the parameters to be passed to the API, including the API key and the text and target language to be translated
const params = new HttpParams()
.set('auth_key', this.apiKey)
.set('text', text)
.set('target_lang', targetLang);
// Make a POST request to the API using the HttpClient and the defined parameters, and return the response as an Observable
return this.http.post(this.apiUrl, params);
}
}

View File

@@ -1,16 +1,17 @@
import {Injectable} from '@angular/core';
import {HttpClient} from "@angular/common/http";
import {homeTranslations} from "../interface/translations";
import {listTranslations} from "../interface/translations";
import {homeTranslations} from "../../interface/translations";
import {listTranslations} from "../../interface/translations";
@Injectable({
providedIn: 'root'
})
export class ReadTranslateJsonService {
private homeTranslations: homeTranslations = {} as homeTranslations;
private listTranslation: listTranslations = {} as listTranslations;
private homeTranslations: homeTranslations = {} as homeTranslations; // declares a private object to hold the home translations
private listTranslation: listTranslations = {} as listTranslations; // declares a private object to hold the list translations
constructor(private http: HttpClient) {
// loads the home translations from the assets file for the English language
this.http.get<homeTranslations>('assets/i18n/home/en.json').subscribe(data => {
this.homeTranslations.alertMessage = data.alertMessage;
this.homeTranslations.translate = data.translate;
@@ -20,6 +21,7 @@ export class ReadTranslateJsonService {
console.log("data loaded", this.homeTranslations)
});
// loads the list translations from the assets file for the English language
this.http.get<listTranslations>('assets/i18n/list/en.json').subscribe(data => {
this.listTranslation.translate = data.translate;
this.listTranslation.distance = data.distance;
@@ -29,10 +31,12 @@ export class ReadTranslateJsonService {
});
}
// returns the home translations object
getHomeTranslations(): homeTranslations {
return this.homeTranslations;
}
// returns the list translations object
getListTransaltions(): listTranslations {
return this.listTranslation;
}

View File

@@ -7,8 +7,11 @@ import {Injectable} from "@angular/core";
export class TranslateService {
constructor(private deepLService: DeepLService) {}
// Method for translating the given input to the given language
async getData(input: string, lang: string): Promise<string> {
// Translating the input using the DeepLService and waiting for the response
const response = await this.deepLService.translate(input, lang).toPromise();
// Returning the translated text from the response
return response.translations[0].text;
}
}