Browse Source

Update the server end point to come from a service

new_auth
Quildra 2 years ago
parent
commit
9e0e1123a3
  1. 11
      packages/bridge-ui/src/app/services/auth.service.ts
  2. 8
      packages/bridge-ui/src/app/services/race-result.service.ts
  3. 14
      packages/bridge-ui/src/app/services/races.service.ts
  4. 9
      packages/bridge-ui/src/app/services/replays.service.ts
  5. 17
      packages/bridge-ui/src/app/services/seasons.service.ts
  6. 16
      packages/bridge-ui/src/app/services/server-endpoint.service.spec.ts
  7. 24
      packages/bridge-ui/src/app/services/server-endpoint.service.ts

11
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<any> {
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<any> {
console.log("SendTestProfile")
return this.httpClient.get(this.serverEndpoint+"auth/profile")
return this.httpClient.get(this.serverEndpointService.getCurrentEndpoint()+"auth/profile")
}
logout(): void {

8
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);
}
}

14
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<Array<Race>> {
@ -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});
}
}

9
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 });
}
}

17
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<Array<Season>>((resolve, reject) =>{
this.httpClient.get<Array<Season>>("http://172.16.40.146:3000/seasons/").subscribe(data => {
this.httpClient.get<Array<Season>>(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<Season|undefined>((resolve, reject) =>{
this.httpClient.get<Array<Season>>("http://172.16.40.146:3000/seasons/"+id).subscribe(data => {
this.httpClient.get<Array<Season>>(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 => { });
}
}

16
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();
});
});

24
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 + "/";
}
}
Loading…
Cancel
Save