From 386b25c583c1a1632282beab91537ff54e1bce83 Mon Sep 17 00:00:00 2001 From: Syndamia Date: Wed, 7 Apr 2021 21:13:28 +0300 Subject: Added profile picture service and removed put profile picture from user service --- src/app/services/profile-picture.service.ts | 32 +++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 src/app/services/profile-picture.service.ts (limited to 'src/app/services/profile-picture.service.ts') diff --git a/src/app/services/profile-picture.service.ts b/src/app/services/profile-picture.service.ts new file mode 100644 index 0000000..8b9d0a3 --- /dev/null +++ b/src/app/services/profile-picture.service.ts @@ -0,0 +1,32 @@ +import { HttpClient, HttpHeaders, HttpParams } from '@angular/common/http'; +import { Injectable } from '@angular/core'; +import { Guid } from 'guid-typescript'; +import { Observable } from 'rxjs'; +import { AppConstants } from '../app-constants.module'; +import { TokenService } from './token.service'; + +@Injectable({ + providedIn: 'root' +}) +export class ProfilePictureService { + constructor(private _http: HttpClient, private _tokenService: TokenService) + { } + + putPictureWithSessionStorageRequest(newPicture: File): Observable { + const userId = this._tokenService.getUserIdFromSessionStorageToken(); + const token = this._tokenService.getTokenFromSessionStorage(); + + return this.putRatingRequest(userId, token, newPicture); + } + + putRatingRequest(userId: Guid, authToken: string, newPicture: File): Observable { + const options = { + params: new HttpParams().set('UserId', userId.toString()), + headers: new HttpHeaders().set('Authorization', 'Bearer ' + authToken) + }; + const form = new FormData(); + form.append('picture', newPicture); + + return this._http.put(AppConstants.API_PROFILE_PICTURE_URL, form, options); + } +} -- cgit v1.2.3