Add latest changes from frontend branch

This commit is contained in:
kevinpauer
2022-04-05 19:29:30 +02:00
28 changed files with 820 additions and 116 deletions

View File

@@ -1,7 +1,8 @@
import { Injectable } from '@angular/core';
import { HttpClient, HttpHeaders } from '@angular/common/http';
import { Observable } from 'rxjs';
const AUTH_API = 'https://aktienbot.flokaiser.com/api/user/';
const AUTH_API = 'https://gruppe1.testsites.info/api/user';
const httpOptions = {
headers: new HttpHeaders({ 'Content-Type': 'application/json' }),
};
@@ -11,12 +12,25 @@ const httpOptions = {
})
export class AuthService {
constructor(private http: HttpClient) {}
/**
* @param {string} email
* @param {string} password
* @returns Observable
*/
login(email: string, password: string): Observable<any> {
return this.http.post(AUTH_API + '/login', {
email,
password,
});
}
/**
* @param {string} email
* @param {string} username
* @param {string} password
* @returns Observable
*/
register(email: string, username: string, password: string): Observable<any> {
return this.http.post(
AUTH_API + '/register',

View File

@@ -0,0 +1,16 @@
import { TestBed } from '@angular/core/testing';
import { BotService } from './bot.service';
describe('BotService', () => {
let service: BotService;
beforeEach(() => {
TestBed.configureTestingModule({});
service = TestBed.inject(BotService);
});
it('should be created', () => {
expect(service).toBeTruthy();
});
});

View File

@@ -0,0 +1,16 @@
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
) {}
}

View File

@@ -2,16 +2,23 @@ import { Injectable, OnInit } from '@angular/core';
import { HttpClient, HttpHeaders } from '@angular/common/http';
import { delay, Observable } from 'rxjs';
import { TokenStorageService } from './token.service';
const API_URL = 'https://aktienbot.flokaiser.com/api/';
const API_URL = 'https://gruppe1.testsites.info/api/';
@Injectable({
providedIn: 'root',
})
export class DataService {
/**
* @param {HttpClient} privatehttp
* @param {TokenStorageService} privatetokenStorage
*/
constructor(
private http: HttpClient,
private tokenStorage: TokenStorageService
) {}
/**
* @returns Observable
*/
public getStockData(): Observable<any> {
return this.http.get(API_URL + 'portfolio', {
headers: new HttpHeaders({
@@ -22,6 +29,9 @@ export class DataService {
});
}
/**
* @returns Observable
*/
public getTransactionData(): Observable<any> {
return this.http.get(API_URL + 'transactions', {
headers: new HttpHeaders({
@@ -32,6 +42,42 @@ export class DataService {
});
}
/**
* @param {string} symbol
* @param {Date} time
* @param {number} count
* @param {number} price
* @returns Observable
*/
public createTransaction(
symbol: string,
time: string,
count: number,
price: number
): Observable<any> {
time = time + 'T12:00:00.000Z';
price.toFixed(2);
console.log(this.tokenStorage.getToken());
return this.http.post(
API_URL + 'transaction',
{
count,
price,
symbol,
time,
},
{
headers: new HttpHeaders({
'Content-Type': 'application/json',
Authorization: 'Bearer ' + this.tokenStorage.getToken(),
}),
}
);
}
/**
* @returns Observable
*/
public getKeywords(): Observable<any> {
return this.http.get(API_URL + 'keywords', {
headers: new HttpHeaders({

View File

@@ -0,0 +1,16 @@
import { TestBed } from '@angular/core/testing';
import { ProfileService } from './profile.service';
describe('ProfileService', () => {
let service: ProfileService;
beforeEach(() => {
TestBed.configureTestingModule({});
service = TestBed.inject(ProfileService);
});
it('should be created', () => {
expect(service).toBeTruthy();
});
});

View File

@@ -0,0 +1,69 @@
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 ProfileService {
constructor(
private tokenStorage: TokenStorageService,
private http: HttpClient
) {}
/**
* @returns Observable
*/
public getUserData(): Observable<any> {
return this.http.get(API_URL + 'user', {
headers: new HttpHeaders({
'Content-Type': 'application/json',
Authorization: 'Bearer ' + this.tokenStorage.getToken(),
}),
responseType: 'text',
});
}
/**
* @param {string} username
* @param {number} password
* @returns Observable
*/
public updateProfile(username: string, password: number): Observable<any> {
return this.http.put(
API_URL + 'user',
{
username,
password,
},
{
headers: new HttpHeaders({
'Content-Type': 'application/json',
Authorization: 'Bearer ' + this.tokenStorage.getToken(),
}),
}
);
}
/**
* @param {string} telegramUserID
* @returns Observable
*/
public addTelegramId(telegram_user_id: string): Observable<any> {
return this.http.post(
API_URL + 'telegram',
{
telegram_user_id,
},
{
headers: new HttpHeaders({
'Content-Type': 'application/json',
Authorization: 'Bearer ' + this.tokenStorage.getToken(),
}),
}
);
}
}

View File

@@ -1,13 +1,13 @@
import { TestBed } from '@angular/core/testing';
import { TokenService } from './token.service';
import { TokenStorageService } from './token.service';
describe('TokenService', () => {
let service: TokenService;
describe('TokenStorageService', () => {
let service: TokenStorageService;
beforeEach(() => {
TestBed.configureTestingModule({});
service = TestBed.inject(TokenService);
service = TestBed.inject(TokenStorageService);
});
it('should be created', () => {

View File

@@ -6,20 +6,42 @@ const USER_KEY = 'auth-user';
})
export class TokenStorageService {
constructor() {}
/**
* @returns void
*/
signOut(): void {
window.sessionStorage.clear();
}
/**
* @param {string} token
* @returns void
*/
public saveToken(token: string): void {
window.sessionStorage.removeItem(TOKEN_KEY);
window.sessionStorage.setItem(TOKEN_KEY, token);
}
/**
* @returns string
*/
public getToken(): string | null {
return window.sessionStorage.getItem(TOKEN_KEY);
}
/**
* @param {any} user
* @returns void
*/
public saveUser(user: any): void {
window.sessionStorage.removeItem(USER_KEY);
window.sessionStorage.setItem(USER_KEY, JSON.stringify(user));
}
/**
* @returns any
*/
public getUser(): any {
const user = window.sessionStorage.getItem(USER_KEY);
if (user) {