feat: add user selection and todos fetching functionality

This commit is contained in:
2025-04-29 08:18:21 +02:00
parent 2104252b27
commit 17c955067e
4 changed files with 74 additions and 341 deletions

26
src/app/user.service.ts Normal file
View File

@ -0,0 +1,26 @@
import { Injectable } from '@angular/core';
import { HttpClient } from '@angular/common/http';
import { Observable, shareReplay } from 'rxjs';
@Injectable({
providedIn: 'root'
})
export class UserService {
constructor(private http: HttpClient) {}
getUsers(): Observable<any[]> {
return this.http.get<any[]>('https://jsonplaceholder.typicode.com/users')
}
getUser(id: number): Observable<any> {
return this.http.get<any>(`https://jsonplaceholder.typicode.com/users/${id}`)
}
getTodos(userId: number): Observable<any[]> {
return this.http.get<any[]>(`https://jsonplaceholder.typicode.com/todos?userId=${userId}`)
}
getTodo(id: number): Observable<any> {
return this.http.get<any>(`https://jsonplaceholder.typicode.com/todos/${id}`)
}
}