refactor: simplify user service and update routes
This commit is contained in:
parent
51540c930b
commit
3b95725d88
12 changed files with 24 additions and 115 deletions
|
@ -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(
|
||||
|
|
Reference in a new issue