diff options
| author | Syndamia <kamen.d.mladenov@protonmail.com> | 2021-04-07 21:13:28 +0300 |
|---|---|---|
| committer | Syndamia <kamen.d.mladenov@protonmail.com> | 2021-04-07 21:13:28 +0300 |
| commit | 386b25c583c1a1632282beab91537ff54e1bce83 (patch) | |
| tree | bd9ce7422b31cd79b412dc12433555c60d42f4bb /src/app/services/profile-picture.service.ts | |
| parent | b9d5225b7e9f820c28690c243b067cfeb5251d74 (diff) | |
| download | DevHive-Angular-386b25c583c1a1632282beab91537ff54e1bce83.tar DevHive-Angular-386b25c583c1a1632282beab91537ff54e1bce83.tar.gz DevHive-Angular-386b25c583c1a1632282beab91537ff54e1bce83.zip | |
Added profile picture service and removed put profile picture from user service
Diffstat (limited to 'src/app/services/profile-picture.service.ts')
| -rw-r--r-- | src/app/services/profile-picture.service.ts | 32 |
1 files changed, 32 insertions, 0 deletions
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<object> { + const userId = this._tokenService.getUserIdFromSessionStorageToken(); + const token = this._tokenService.getTokenFromSessionStorage(); + + return this.putRatingRequest(userId, token, newPicture); + } + + putRatingRequest(userId: Guid, authToken: string, newPicture: File): Observable<object> { + 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); + } +} |
