refactor: simplify user service and update routes

This commit is contained in:
Constantin Simonis 2025-05-07 14:39:10 +02:00
commit 3b95725d88
No known key found for this signature in database
GPG key ID: 3878FF77C24AF4D2
12 changed files with 24 additions and 115 deletions

View file

@ -1,4 +1,4 @@
import { Injectable } from '@angular/core';
import { inject, Injectable } from '@angular/core';
import { HttpClient } from '@angular/common/http';
import { BehaviorSubject, catchError, EMPTY, Observable, tap } from 'rxjs';
import { User } from '../model/User';
@ -8,18 +8,11 @@ import { environment } from '@environments/environment';
providedIn: 'root',
})
export class UserService {
private apiUrl = `${environment.apiUrl}/api/users`;
private apiUrl = `${environment.apiUrl}/users`;
private currentUserSubject = new BehaviorSubject<User | null>(null);
private http: HttpClient = inject(HttpClient);
constructor(private http: HttpClient) {}
public getUserById(id: number): Observable<User> {
return this.http.get<User>(`${this.apiUrl}/${id}`);
}
public getUserByUsername(username: string): Observable<User> {
return this.http.get<User>(`${this.apiUrl}/username/${username}`);
}
public getCurrentUser(): Observable<User | null> {
return this.http.get<User | null>('/backend/user').pipe(