Add API calls for profile component
This commit is contained in:
parent
16ad83ae40
commit
4c7506d8b2
@ -13,19 +13,4 @@ export class BotService {
|
|||||||
private http: HttpClient,
|
private http: HttpClient,
|
||||||
private tokenStorage: TokenStorageService
|
private tokenStorage: TokenStorageService
|
||||||
) {}
|
) {}
|
||||||
|
|
||||||
/**
|
|
||||||
* @param {string} telegramUserID
|
|
||||||
* @returns Observable
|
|
||||||
*/
|
|
||||||
public createTransaction(telegram_user_id: string): Observable<any> {
|
|
||||||
return this.http.post(API_URL + 'telegram', {
|
|
||||||
headers: new HttpHeaders({
|
|
||||||
'Content-Type': 'application/json',
|
|
||||||
Authorization: 'Bearer ' + this.tokenStorage.getToken(),
|
|
||||||
}),
|
|
||||||
responseType: 'text',
|
|
||||||
telegram_user_id,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -16,42 +16,6 @@ export class DataService {
|
|||||||
private tokenStorage: TokenStorageService
|
private tokenStorage: TokenStorageService
|
||||||
) {}
|
) {}
|
||||||
|
|
||||||
/**
|
|
||||||
* @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} email
|
|
||||||
* @param {string} username
|
|
||||||
* @param {string} password
|
|
||||||
* @returns Observable
|
|
||||||
*/
|
|
||||||
public updateUserData(
|
|
||||||
email: string,
|
|
||||||
username: string,
|
|
||||||
password: string
|
|
||||||
): Observable<any> {
|
|
||||||
return this.http.put(API_URL + 'user', {
|
|
||||||
headers: new HttpHeaders({
|
|
||||||
'Content-Type': 'application/json',
|
|
||||||
Authorization: 'Bearer ' + this.tokenStorage.getToken(),
|
|
||||||
}),
|
|
||||||
responseType: 'text',
|
|
||||||
email,
|
|
||||||
username,
|
|
||||||
password,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @returns Observable
|
* @returns Observable
|
||||||
*/
|
*/
|
||||||
|
16
frontend/src/app/Services/profile.service.spec.ts
Normal file
16
frontend/src/app/Services/profile.service.spec.ts
Normal 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();
|
||||||
|
});
|
||||||
|
});
|
69
frontend/src/app/Services/profile.service.ts
Normal file
69
frontend/src/app/Services/profile.service.ts
Normal 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(),
|
||||||
|
}),
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
@ -53,14 +53,12 @@ export class DashboardComponent implements OnInit {
|
|||||||
for (let i = 0; i < data.data.length; i++) {
|
for (let i = 0; i < data.data.length; i++) {
|
||||||
STOCK_DATA.push({
|
STOCK_DATA.push({
|
||||||
count: data.data[i].count,
|
count: data.data[i].count,
|
||||||
// price: data.data[i].price,
|
|
||||||
symbol: data.data[i].symbol,
|
symbol: data.data[i].symbol,
|
||||||
time: data.data[i].last_transaction,
|
time: data.data[i].last_transaction,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
console.log(STOCK_DATA);
|
console.log(STOCK_DATA);
|
||||||
this.dataSourceStocks = STOCK_DATA;
|
this.dataSourceStocks = STOCK_DATA;
|
||||||
//TODO map data on array for display
|
|
||||||
//TODO move to helper service
|
//TODO move to helper service
|
||||||
});
|
});
|
||||||
this.dataService.getTransactionData().subscribe((response: any) => {
|
this.dataService.getTransactionData().subscribe((response: any) => {
|
||||||
@ -76,7 +74,6 @@ export class DashboardComponent implements OnInit {
|
|||||||
}
|
}
|
||||||
console.log(TRANSACTION_DATA);
|
console.log(TRANSACTION_DATA);
|
||||||
this.dataSourceTransactions = TRANSACTION_DATA;
|
this.dataSourceTransactions = TRANSACTION_DATA;
|
||||||
//TODO map data on array for display
|
|
||||||
//TODO move to helper service
|
//TODO move to helper service
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -114,7 +114,7 @@
|
|||||||
[formControl]="telegramIdFormControl"
|
[formControl]="telegramIdFormControl"
|
||||||
[(ngModel)]="userId"
|
[(ngModel)]="userId"
|
||||||
required
|
required
|
||||||
placeholder="Ex. 123456789"
|
#telegramId
|
||||||
/>
|
/>
|
||||||
<mat-error *ngIf="telegramIdFormControl.hasError('required')">
|
<mat-error *ngIf="telegramIdFormControl.hasError('required')">
|
||||||
Id is <strong>required</strong>
|
Id is <strong>required</strong>
|
||||||
|
@ -1,8 +1,10 @@
|
|||||||
|
import { i18nMetaToJSDoc } from '@angular/compiler/src/render3/view/i18n/meta';
|
||||||
import { Component, OnInit } from '@angular/core';
|
import { Component, OnInit } from '@angular/core';
|
||||||
import { FormControl, PatternValidator, Validators } from '@angular/forms';
|
import { FormControl, PatternValidator, Validators } from '@angular/forms';
|
||||||
import { MatDialog } from '@angular/material/dialog';
|
import { MatDialog } from '@angular/material/dialog';
|
||||||
import { BotService } from 'src/app/Services/bot.service';
|
import { BotService } from 'src/app/Services/bot.service';
|
||||||
import { DataService } from 'src/app/Services/data.service';
|
import { DataService } from 'src/app/Services/data.service';
|
||||||
|
import { ProfileService } from 'src/app/Services/profile.service';
|
||||||
import { ConfirmationDialogComponent } from './confirmation-dialog/confirmation-dialog.component';
|
import { ConfirmationDialogComponent } from './confirmation-dialog/confirmation-dialog.component';
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
@ -23,24 +25,40 @@ export class ProfileComponent implements OnInit {
|
|||||||
form: any = {
|
form: any = {
|
||||||
username: null,
|
username: null,
|
||||||
email: 'example@web.com',
|
email: 'example@web.com',
|
||||||
password: null,
|
password: 'password',
|
||||||
};
|
};
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
private botService: BotService,
|
private profileService: ProfileService,
|
||||||
private dataService: DataService,
|
|
||||||
public dialog: MatDialog
|
public dialog: MatDialog
|
||||||
) {}
|
) {}
|
||||||
|
|
||||||
ngOnInit(): void {}
|
ngOnInit(): void {
|
||||||
|
this.profileService.getUserData().subscribe((result) => {
|
||||||
|
console.log(result);
|
||||||
|
result = JSON.parse(result);
|
||||||
|
this.form.username = result.data.username;
|
||||||
|
this.form.password = result.data.password;
|
||||||
|
this.userId = result.data.telegram_user_id;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
onSubmit() {
|
onSubmit() {
|
||||||
console.log('NASE1');
|
if (this.userId != '') {
|
||||||
|
console.log(this.userId);
|
||||||
|
this.profileService.addTelegramId(this.userId).subscribe((result) => {
|
||||||
|
console.log(result);
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
updateUser() {
|
updateUser() {
|
||||||
const { username, email, password } = this.form;
|
const { username, email, password } = this.form;
|
||||||
console.log('NASE2');
|
this.profileService
|
||||||
|
.updateProfile(this.form.username, this.form.password)
|
||||||
|
.subscribe((result) => {
|
||||||
|
console.log(result);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
openDialog(action: string) {
|
openDialog(action: string) {
|
||||||
@ -57,7 +75,6 @@ export class ProfileComponent implements OnInit {
|
|||||||
this.updateUser();
|
this.updateUser();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
console.log(`Dialog result: ${result}`);
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
import { NgModule } from '@angular/core';
|
import { NgModule } from '@angular/core';
|
||||||
import { RouterModule, Routes } from '@angular/router';
|
import { RouterModule, Routes } from '@angular/router';
|
||||||
|
import { BotService } from './Services/bot.service';
|
||||||
|
import { BotSettingsComponent } from './Views/bot-settings/bot-settings.component';
|
||||||
import { DashboardComponent } from './Views/dashboard/dashboard.component';
|
import { DashboardComponent } from './Views/dashboard/dashboard.component';
|
||||||
import { LoginComponent } from './Views/login/login.component';
|
import { LoginComponent } from './Views/login/login.component';
|
||||||
import { ProfileComponent } from './Views/profile/profile.component';
|
import { ProfileComponent } from './Views/profile/profile.component';
|
||||||
@ -24,7 +26,7 @@ const routes: Routes = [
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
path: 'settings',
|
path: 'settings',
|
||||||
component: ProfileComponent,
|
component: BotSettingsComponent,
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user