- Add UserController with GET/PUT /me, PUT /me/password, PUT /me/email - Add UserService with profile update, password change, email change - Add UserServiceTest with 7 unit tests - Add IamDtos: UpdateProfileRequest, ChangePasswordRequest, ChangeEmailRequest - Add Angular profile page with edit profile, change password, change email - Add Angular UserService for profile API calls - Add profile route and navigation item
52 lines
1.3 KiB
TypeScript
52 lines
1.3 KiB
TypeScript
import {inject, Injectable} from '@angular/core';
|
|
import {HttpClient} from '@angular/common/http';
|
|
import {Observable} from 'rxjs';
|
|
|
|
export interface UserProfile {
|
|
id: string;
|
|
participantType: string;
|
|
firstName: string;
|
|
lastName: string;
|
|
organizationName: string | null;
|
|
email: string;
|
|
status: string;
|
|
}
|
|
|
|
export interface UpdateProfileRequest {
|
|
firstName: string;
|
|
lastName: string;
|
|
organizationName?: string;
|
|
participantType: 'PRIVATE' | 'COMPANY';
|
|
}
|
|
|
|
export interface ChangePasswordRequest {
|
|
currentPassword: string;
|
|
newPassword: string;
|
|
}
|
|
|
|
export interface ChangeEmailRequest {
|
|
newEmail: string;
|
|
}
|
|
|
|
@Injectable({providedIn: 'root'})
|
|
export class UserService {
|
|
private http = inject(HttpClient);
|
|
private apiUrl = 'http://localhost:8080/api';
|
|
|
|
getProfile(): Observable<UserProfile> {
|
|
return this.http.get<UserProfile>(`${this.apiUrl}/users/me`);
|
|
}
|
|
|
|
updateProfile(request: UpdateProfileRequest): Observable<UserProfile> {
|
|
return this.http.put<UserProfile>(`${this.apiUrl}/users/me`, request);
|
|
}
|
|
|
|
changePassword(request: ChangePasswordRequest): Observable<void> {
|
|
return this.http.put<void>(`${this.apiUrl}/users/me/password`, request);
|
|
}
|
|
|
|
changeEmail(request: ChangeEmailRequest): Observable<void> {
|
|
return this.http.put<void>(`${this.apiUrl}/users/me/email`, request);
|
|
}
|
|
}
|