This repository has been archived by the owner on Oct 28, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
command.service.ts
53 lines (42 loc) · 1.56 KB
/
command.service.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
import { Injectable } from '@angular/core';
import { HttpClient, HttpHeaders } from '@angular/common/http';
//
import { Observable } from 'rxjs';
//
import { CommandRequest } from '../../models/angular-command-request';
import { CommandStatusResponse } from '../../models/command-status-response.interface';
@Injectable({
providedIn: 'root'
})
export class CommandService {
private readonly BASE_URL = 'http://localhost';
private readonly PORT = 3000;
constructor(private http: HttpClient) { }
isAngularProject() {
return this.http.get(`${this.BASE_URL}:${this.PORT}/isAngularProject`);
}
getProjects() {
return this.http.get(`${this.BASE_URL}:${this.PORT}/projects`);
}
checkCommandStatus(commandId: string): Observable<CommandStatusResponse> {
return this.http.get<CommandStatusResponse>(`${this.BASE_URL}:${this.PORT}/status?id=${commandId}`);
}
chooseProject(projectName: string) {
return this.http.get(`${this.BASE_URL}:${this.PORT}/chooseProject?name=${projectName}`);
}
keepAlive() {
return this.http.get(`${this.BASE_URL}:${this.PORT}/keepAlive`);
}
stopServing(serveCommandId: string) {
return this.http.get(`${this.BASE_URL}:${this.PORT}/stopServing?id=${serveCommandId}`);
}
leaveProject() {
return this.http.get(`${this.BASE_URL}:${this.PORT}/leaveProject`);
}
sendCommand(command: CommandRequest) {
const headers = new HttpHeaders({
'Content-Type': 'application/json'
});
return this.http.post(`${this.BASE_URL}:${this.PORT}/command`, command, {headers: headers, responseType: 'text'});
}
}