feat: add user selection and todos fetching functionality
This commit is contained in:
26
src/app/user.service.ts
Normal file
26
src/app/user.service.ts
Normal 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}`)
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user