113 lines
2.6 KiB
TypeScript
113 lines
2.6 KiB
TypeScript
import { HttpClient, HttpHeaders } from '@angular/common/http';
|
|
import { Injectable } from '@angular/core';
|
|
import { Observable } from 'rxjs';
|
|
import { TokenStorageService } from './token.service';
|
|
|
|
const API_URL = 'https://gruppe1.testsites.info/api/';
|
|
|
|
@Injectable({
|
|
providedIn: 'root',
|
|
})
|
|
export class BotService {
|
|
constructor(
|
|
private http: HttpClient,
|
|
private tokenStorage: TokenStorageService
|
|
) {}
|
|
|
|
/**
|
|
* @returns Observable
|
|
*/
|
|
public getKeywords(): Observable<any> {
|
|
return this.http.get(API_URL + 'keywords', {
|
|
headers: new HttpHeaders({
|
|
'Content-Type': 'application/json',
|
|
Authorization: 'Bearer ' + this.tokenStorage.getToken(),
|
|
}),
|
|
responseType: 'text',
|
|
});
|
|
}
|
|
|
|
/**
|
|
* @param {string} keyword
|
|
* @returns Observable
|
|
*/
|
|
public createKeyword(keyword: string): Observable<any> {
|
|
return this.http.post(
|
|
API_URL + 'keyword',
|
|
{
|
|
keyword,
|
|
},
|
|
{
|
|
headers: new HttpHeaders({
|
|
'Content-Type': 'application/json',
|
|
Authorization: 'Bearer ' + this.tokenStorage.getToken(),
|
|
}),
|
|
}
|
|
);
|
|
}
|
|
|
|
/**
|
|
* @param {string} keyword
|
|
* @returns Observable
|
|
*/
|
|
public deleteKeyword(keyword: string): Observable<any> {
|
|
return this.http.delete(API_URL + 'keyword', {
|
|
headers: new HttpHeaders({
|
|
'Content-Type': 'application/json',
|
|
Authorization: 'Bearer ' + this.tokenStorage.getToken(),
|
|
}),
|
|
body: {
|
|
keyword,
|
|
},
|
|
});
|
|
}
|
|
|
|
/**
|
|
* @returns Observable
|
|
*/
|
|
public getSymbols(): Observable<any> {
|
|
return this.http.get(API_URL + 'shares', {
|
|
headers: new HttpHeaders({
|
|
'Content-Type': 'application/json',
|
|
Authorization: 'Bearer ' + this.tokenStorage.getToken(),
|
|
}),
|
|
responseType: 'text',
|
|
});
|
|
}
|
|
|
|
/**
|
|
* @param {string} keyword
|
|
* @returns Observable
|
|
*/
|
|
public createShare(symbol: string): Observable<any> {
|
|
return this.http.post(
|
|
API_URL + 'share',
|
|
{
|
|
symbol,
|
|
},
|
|
{
|
|
headers: new HttpHeaders({
|
|
'Content-Type': 'application/json',
|
|
Authorization: 'Bearer ' + this.tokenStorage.getToken(),
|
|
}),
|
|
}
|
|
);
|
|
}
|
|
|
|
/**
|
|
* @param {string} symbol
|
|
* @returns Observable
|
|
*/
|
|
public deleteShare(symbol: string): Observable<any> {
|
|
return this.http.delete(API_URL + 'share', {
|
|
headers: new HttpHeaders({
|
|
'Content-Type': 'application/json',
|
|
Authorization: 'Bearer ' + this.tokenStorage.getToken(),
|
|
}),
|
|
body: {
|
|
symbol,
|
|
},
|
|
});
|
|
}
|
|
}
|