aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/app/app-constants.module.ts1
-rw-r--r--src/app/services/profile-picture.service.ts32
-rw-r--r--src/app/services/user.service.ts17
3 files changed, 33 insertions, 17 deletions
diff --git a/src/app/app-constants.module.ts b/src/app/app-constants.module.ts
index 39538e0..d1bd9f5 100644
--- a/src/app/app-constants.module.ts
+++ b/src/app/app-constants.module.ts
@@ -2,6 +2,7 @@ export class AppConstants {
public static BASE_API_URL = 'http://localhost:5000/api';
public static API_USER_URL = AppConstants.BASE_API_URL + '/User';
+ public static API_PROFILE_PICTURE_URL = AppConstants.BASE_API_URL + '/ProfilePicture';
public static API_USER_LOGIN_URL = AppConstants.API_USER_URL + '/login';
public static API_USER_REGISTER_URL = AppConstants.API_USER_URL + '/register';
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);
+ }
+}
diff --git a/src/app/services/user.service.ts b/src/app/services/user.service.ts
index 10c8c59..e910ada 100644
--- a/src/app/services/user.service.ts
+++ b/src/app/services/user.service.ts
@@ -45,13 +45,6 @@ export class UserService {
return this.putUserRequest(userId, token, updateUserFormGroup, languages, technologies, userRoles, userFriends);
}
- putProfilePictureFromSessionStorageRequest(newPicture: File): Observable<object> {
- const userId = this._tokenService.getUserIdFromSessionStorageToken();
- const token = this._tokenService.getTokenFromSessionStorage();
-
- return this.putProfilePictureRequest(userId, token, newPicture);
- }
-
putBareUserFromSessionStorageRequest(user: User, password: string): Observable<object> {
const userId = this._tokenService.getUserIdFromSessionStorageToken();
const token = this._tokenService.getTokenFromSessionStorage();
@@ -150,16 +143,6 @@ export class UserService {
return this._http.put(AppConstants.API_USER_URL, body, options);
}
- putProfilePictureRequest(userId: Guid, authToken: string, newPicture: File): Observable<object> {
- const form = new FormData();
- form.append('picture', newPicture);
- const options = {
- params: new HttpParams().set('UserId', userId.toString()),
- headers: new HttpHeaders().set('Authorization', 'Bearer ' + authToken)
- };
- return this._http.put(AppConstants.API_USER_URL + '/ProfilePicture', form, options);
- }
-
deleteUserRequest(userId: Guid, authToken: string): Observable<object> {
const options = {
params: new HttpParams().set('Id', userId.toString()),