182. Update profile image back end call (#26)
This commit is contained in:
@ -18,6 +18,7 @@ import org.springframework.validation.BindException;
|
|||||||
import org.springframework.web.HttpRequestMethodNotSupportedException;
|
import org.springframework.web.HttpRequestMethodNotSupportedException;
|
||||||
import org.springframework.web.bind.annotation.ExceptionHandler;
|
import org.springframework.web.bind.annotation.ExceptionHandler;
|
||||||
import org.springframework.web.bind.annotation.RestControllerAdvice;
|
import org.springframework.web.bind.annotation.RestControllerAdvice;
|
||||||
|
import org.springframework.web.multipart.MaxUploadSizeExceededException;
|
||||||
|
|
||||||
import javax.persistence.NoResultException;
|
import javax.persistence.NoResultException;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
@ -65,7 +66,8 @@ public class ExceptionHandling {
|
|||||||
|
|
||||||
@ExceptionHandler({
|
@ExceptionHandler({
|
||||||
EmailExistsException.class, UsernameExistsException.class,
|
EmailExistsException.class, UsernameExistsException.class,
|
||||||
EmailNotFoundException.class, UserNotFoundException.class
|
EmailNotFoundException.class, UserNotFoundException.class,
|
||||||
|
MaxUploadSizeExceededException.class
|
||||||
})
|
})
|
||||||
public ResponseEntity<HttpResponse> badRequestExceptionHandler(Exception exception) {
|
public ResponseEntity<HttpResponse> badRequestExceptionHandler(Exception exception) {
|
||||||
return createHttpResponse(BAD_REQUEST, exception.getMessage());
|
return createHttpResponse(BAD_REQUEST, exception.getMessage());
|
||||||
|
|||||||
@ -4,7 +4,7 @@ import {User} from "../../model/user";
|
|||||||
import {UserService} from "../../service/user.service";
|
import {UserService} from "../../service/user.service";
|
||||||
import {NotificationService} from "../../service/notification.service";
|
import {NotificationService} from "../../service/notification.service";
|
||||||
import {NotificationType} from "../../notification/notification-type";
|
import {NotificationType} from "../../notification/notification-type";
|
||||||
import {HttpErrorResponse} from "@angular/common/http";
|
import {HttpErrorResponse, HttpEvent} from "@angular/common/http";
|
||||||
import {NgForm} from "@angular/forms";
|
import {NgForm} from "@angular/forms";
|
||||||
import {CustomHttpResponse} from "../../dto/custom-http-response";
|
import {CustomHttpResponse} from "../../dto/custom-http-response";
|
||||||
import {AuthenticationService} from "../../service/authentication.service";
|
import {AuthenticationService} from "../../service/authentication.service";
|
||||||
@ -234,6 +234,23 @@ export class UserComponent implements OnInit, OnDestroy {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public onUpdateProfileImage(): void {
|
public onUpdateProfileImage(): void {
|
||||||
|
if (!this.profileImage) return;
|
||||||
|
this.refreshing = true;
|
||||||
|
const formData = new FormData();
|
||||||
|
formData.append("profileImage", this.profileImage);
|
||||||
|
let user = this.authenticationService.getUserFromLocalStorage();
|
||||||
|
let subscription = this.userService.updateProfileImage(user.username, formData)
|
||||||
|
.subscribe(
|
||||||
|
(event: HttpEvent<any>) => {
|
||||||
|
this.notificationService.notify(NotificationType.SUCCESS, `Profile image updated successfully: ${event}`);
|
||||||
|
this.refreshing = false;
|
||||||
|
this.getUsers(false);
|
||||||
|
},
|
||||||
|
(errorResponse: HttpErrorResponse) => {
|
||||||
|
this.sendErrorNotification(errorResponse.error.message);
|
||||||
|
this.refreshing = false;
|
||||||
|
}
|
||||||
|
);
|
||||||
|
this.subscriptions.push(subscription);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
import {Injectable} from '@angular/core';
|
import {Injectable} from '@angular/core';
|
||||||
import {environment} from "../../environments/environment";
|
import {environment} from "../../environments/environment";
|
||||||
import {HttpClient, HttpErrorResponse, HttpEvent} from "@angular/common/http";
|
import {HttpClient, HttpEvent} from "@angular/common/http";
|
||||||
import {Observable} from "rxjs";
|
import {Observable} from "rxjs";
|
||||||
import {User} from "../model/user";
|
import {User} from "../model/user";
|
||||||
import {CustomHttpResponse} from "../dto/custom-http-response";
|
import {CustomHttpResponse} from "../dto/custom-http-response";
|
||||||
@ -37,9 +37,9 @@ export class UserService {
|
|||||||
.post<CustomHttpResponse>(`${this.host}/user/resetPassword/${email}`, null);
|
.post<CustomHttpResponse>(`${this.host}/user/resetPassword/${email}`, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
public updateProfileImage(username: string, formData: FormData): Observable<HttpEvent<User | HttpErrorResponse>> {
|
public updateProfileImage(username: string, formData: FormData): Observable<HttpEvent<User>> {
|
||||||
return this.httpClient
|
return this.httpClient
|
||||||
.put<User | HttpErrorResponse>(`${this.host}/user/${username}/profileImage`, formData,
|
.put<User>(`${this.host}/user/${username}/profileImage`, formData,
|
||||||
{
|
{
|
||||||
reportProgress: true,
|
reportProgress: true,
|
||||||
observe: 'events'
|
observe: 'events'
|
||||||
|
|||||||
Reference in New Issue
Block a user