Add API calls for profile component
This commit is contained in:
@@ -13,19 +13,4 @@ export class BotService {
|
||||
private http: HttpClient,
|
||||
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
|
||||
) {}
|
||||
|
||||
/**
|
||||
* @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
|
||||
*/
|
||||
|
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(),
|
||||
}),
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user