From 9e0e1123a3811277a15faeec978025af20cc7329 Mon Sep 17 00:00:00 2001 From: Quildra Date: Thu, 23 Nov 2023 18:41:36 +0000 Subject: [PATCH] Update the server end point to come from a service --- .../src/app/services/auth.service.ts | 11 +++++---- .../src/app/services/race-result.service.ts | 8 +++++-- .../src/app/services/races.service.ts | 14 +++++++---- .../src/app/services/replays.service.ts | 9 ++++--- .../src/app/services/seasons.service.ts | 17 ++++++++----- .../services/server-endpoint.service.spec.ts | 16 +++++++++++++ .../app/services/server-endpoint.service.ts | 24 +++++++++++++++++++ 7 files changed, 79 insertions(+), 20 deletions(-) create mode 100644 packages/bridge-ui/src/app/services/server-endpoint.service.spec.ts create mode 100644 packages/bridge-ui/src/app/services/server-endpoint.service.ts diff --git a/packages/bridge-ui/src/app/services/auth.service.ts b/packages/bridge-ui/src/app/services/auth.service.ts index a9f231e..1bcf69e 100644 --- a/packages/bridge-ui/src/app/services/auth.service.ts +++ b/packages/bridge-ui/src/app/services/auth.service.ts @@ -2,24 +2,27 @@ import { Injectable } from '@angular/core'; import { HttpClient, HttpHeaders } from "@angular/common/http"; import { Observable } from 'rxjs'; import { jwtDecode } from "jwt-decode"; +import { ServerEndpointService } from './server-endpoint.service'; @Injectable({ providedIn: 'root' }) export class AuthService { - serverEndpoint = "http://172.16.40.146:3000/" - constructor(private httpClient: HttpClient) { } + constructor( + private httpClient: HttpClient, + private serverEndpointService: ServerEndpointService, + ) { } login(username: string, password: string): Observable { const headers = new HttpHeaders(); headers.append('Content-Type', 'application/json'); - return this.httpClient.post(this.serverEndpoint+"auth/login", { username, password }, { headers }) + return this.httpClient.post(this.serverEndpointService.getCurrentEndpoint()+"auth/login", { username, password }, { headers }) } testProfile(): Observable { console.log("SendTestProfile") - return this.httpClient.get(this.serverEndpoint+"auth/profile") + return this.httpClient.get(this.serverEndpointService.getCurrentEndpoint()+"auth/profile") } logout(): void { diff --git a/packages/bridge-ui/src/app/services/race-result.service.ts b/packages/bridge-ui/src/app/services/race-result.service.ts index 6c06a76..0ac14f7 100644 --- a/packages/bridge-ui/src/app/services/race-result.service.ts +++ b/packages/bridge-ui/src/app/services/race-result.service.ts @@ -3,13 +3,17 @@ import { HttpClient } from "@angular/common/http"; import { Observable, from } from "rxjs"; import { RaceEntry } from '../models/raceEntry.model'; +import { ServerEndpointService } from './server-endpoint.service'; @Injectable({ providedIn: 'root' }) export class RaceResultService { - constructor(private httpClient: HttpClient) { + constructor( + private httpClient: HttpClient, + private serverEndpointService: ServerEndpointService, + ) { } /* @@ -81,6 +85,6 @@ export class RaceResultService { const httpOptions = { responseType: 'blob' as 'json' }; - return this.httpClient.get("http://172.16.40.146:3000/race-results/"+raceResultId+"/get-ghost", httpOptions); + return this.httpClient.get(this.serverEndpointService.getCurrentEndpoint()+"race-results/"+raceResultId+"/get-ghost", httpOptions); } } diff --git a/packages/bridge-ui/src/app/services/races.service.ts b/packages/bridge-ui/src/app/services/races.service.ts index e6443e5..9493a19 100644 --- a/packages/bridge-ui/src/app/services/races.service.ts +++ b/packages/bridge-ui/src/app/services/races.service.ts @@ -3,13 +3,17 @@ import { HttpClient } from "@angular/common/http"; import { Observable, from } from "rxjs"; import { Race } from '../models/race.model'; +import { ServerEndpointService } from './server-endpoint.service'; @Injectable({ providedIn: 'root' }) export class RacesService { - constructor(private httpClient: HttpClient) { + constructor( + private httpClient: HttpClient, + private serverEndpointService: ServerEndpointService + ) { } getAllRaces(): Observable> { @@ -17,18 +21,18 @@ export class RacesService { } getRace(id: string) { - return this.httpClient.get("http://172.16.40.146:3000/races/"+id); + return this.httpClient.get(this.serverEndpointService.getCurrentEndpoint()+"races/"+id); } getRaceResults(id: string) { - return this.httpClient.get("http://172.16.40.146:3000/races/"+id+"/results"); + return this.httpClient.get(this.serverEndpointService.getCurrentEndpoint()+"races/"+id+"/results"); } getMapInfo(mapUID: string) { - return this.httpClient.get("http://172.16.40.146:3000/races/map/"+mapUID); + return this.httpClient.get(this.serverEndpointService.getCurrentEndpoint()+"races/map/"+mapUID); } create(mapUID: string, startDate: Date, endDate: Date, seasonId: number) { - return this.httpClient.post("http://172.16.40.146:3000/races", { mapUID: mapUID, startDate: startDate, endDate: endDate, seasonId: seasonId}); + return this.httpClient.post(this.serverEndpointService.getCurrentEndpoint()+"races", { mapUID: mapUID, startDate: startDate, endDate: endDate, seasonId: seasonId}); } } diff --git a/packages/bridge-ui/src/app/services/replays.service.ts b/packages/bridge-ui/src/app/services/replays.service.ts index 48030c9..e084281 100644 --- a/packages/bridge-ui/src/app/services/replays.service.ts +++ b/packages/bridge-ui/src/app/services/replays.service.ts @@ -1,19 +1,22 @@ import { Injectable } from '@angular/core'; import { HttpClient, HttpHeaders } from "@angular/common/http"; import { Observable } from "rxjs"; +import { ServerEndpointService } from './server-endpoint.service'; @Injectable({ providedIn: 'root' }) export class ReplaysService { - server_route: string = "http://172.16.40.146:3000/" - constructor(private httpClient: HttpClient) { + constructor( + private httpClient: HttpClient, + private serverEndpointService: ServerEndpointService + ) { } uploadReplay(newReplay: FormData) { const headers = new HttpHeaders(); headers.append('Content-Type', 'multipart/form-data'); - return this.httpClient.post(this.server_route+'upload/replay', newReplay, { headers }); + return this.httpClient.post(this.serverEndpointService.getCurrentEndpoint()+"upload/replay", newReplay, { headers }); } } diff --git a/packages/bridge-ui/src/app/services/seasons.service.ts b/packages/bridge-ui/src/app/services/seasons.service.ts index 095ec0c..b379eed 100644 --- a/packages/bridge-ui/src/app/services/seasons.service.ts +++ b/packages/bridge-ui/src/app/services/seasons.service.ts @@ -4,6 +4,8 @@ import { Observable, from } from "rxjs"; import { Season } from '../models/season.model'; +import { ServerEndpointService } from './server-endpoint.service'; + @Injectable({ providedIn: 'root' }) @@ -12,8 +14,11 @@ export class SeasonsService { seasons: Season[] = []; useTestData: boolean = false; - constructor(private httpClient: HttpClient) { - } + constructor( + private httpClient: HttpClient, + private serverEndpointService: ServerEndpointService, + ) + {} private convertToClientSeason(data: any): Season { let _season = new Season(); @@ -34,7 +39,7 @@ export class SeasonsService { } let promise = new Promise>((resolve, reject) =>{ - this.httpClient.get>("http://172.16.40.146:3000/seasons/").subscribe(data => { + this.httpClient.get>(this.serverEndpointService.getCurrentEndpoint()+"seasons/").subscribe(data => { let seasons: Season[] = []; for(let server_season of data) { let _season = this.convertToClientSeason(server_season); @@ -65,7 +70,7 @@ export class SeasonsService { } let promise = new Promise((resolve, reject) =>{ - this.httpClient.get>("http://172.16.40.146:3000/seasons/"+id).subscribe(data => { + this.httpClient.get>(this.serverEndpointService.getCurrentEndpoint()+"seasons/"+id).subscribe(data => { let _season = this.convertToClientSeason(data); console.log(data); console.log(_season); @@ -76,10 +81,10 @@ export class SeasonsService { } create(title: string, subTitle: string, startingDate: Date) { - return this.httpClient.post("http://172.16.40.146:3000/seasons/", {title, subTitle, startingDate}); + return this.httpClient.post(this.serverEndpointService.getCurrentEndpoint()+"seasons/", {title, subTitle, startingDate}); } updateSeason(id: string) { - this.httpClient.get("http://172.16.40.146:3000/seasons/"+id+"/refresh").subscribe(data => { }); + this.httpClient.get(this.serverEndpointService.getCurrentEndpoint()+"seasons/"+id+"/refresh").subscribe(data => { }); } } diff --git a/packages/bridge-ui/src/app/services/server-endpoint.service.spec.ts b/packages/bridge-ui/src/app/services/server-endpoint.service.spec.ts new file mode 100644 index 0000000..ce168a3 --- /dev/null +++ b/packages/bridge-ui/src/app/services/server-endpoint.service.spec.ts @@ -0,0 +1,16 @@ +import { TestBed } from '@angular/core/testing'; + +import { ServerEndpointService } from './server-endpoint.service'; + +describe('ServerEndpointService', () => { + let service: ServerEndpointService; + + beforeEach(() => { + TestBed.configureTestingModule({}); + service = TestBed.inject(ServerEndpointService); + }); + + it('should be created', () => { + expect(service).toBeTruthy(); + }); +}); diff --git a/packages/bridge-ui/src/app/services/server-endpoint.service.ts b/packages/bridge-ui/src/app/services/server-endpoint.service.ts new file mode 100644 index 0000000..10d99b2 --- /dev/null +++ b/packages/bridge-ui/src/app/services/server-endpoint.service.ts @@ -0,0 +1,24 @@ +import { Injectable } from '@angular/core'; + +@Injectable({ + providedIn: 'root' +}) +export class ServerEndpointService { + + currentHost: string; + currentPort: string; + + constructor() + { + this.currentHost = "localhost"; + this.currentPort = "3000"; + } + + testAndSetEndpoint() { + + } + + getCurrentEndpoint(): string { + return "http://" + this.currentHost + ":" + this.currentPort + "/"; + } +}