Merge remote-tracking branch 'origin/dev' into dev
# Conflicts: # src/app/component/detail/detail.component.html
This commit is contained in:
@@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
39
src/app/service/http/location.service.ts
Normal file
39
src/app/service/http/location.service.ts
Normal 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);
|
||||
}
|
||||
|
||||
}
|
||||
43
src/app/service/http/user.service.ts
Normal file
43
src/app/service/http/user.service.ts
Normal 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);
|
||||
}
|
||||
}
|
||||
49
src/app/service/http/waypoint.service.ts
Normal file
49
src/app/service/http/waypoint.service.ts
Normal 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);
|
||||
}
|
||||
}
|
||||
45
src/app/service/http/waypointVisited.service.ts
Normal file
45
src/app/service/http/waypointVisited.service.ts
Normal 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);
|
||||
}
|
||||
}
|
||||
30
src/app/service/language/deepL.service.ts
Normal file
30
src/app/service/language/deepL.service.ts
Normal 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);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user