import { Injectable } from '@angular/core'; import { HttpClient } from '@angular/common/http'; import { Observable, catchError, of, retry } from 'rxjs'; import { ConfigService } from './config.service'; export interface Todo { _id: string; title: string; completed: boolean; } export type CreateTodo = Omit; @Injectable({ providedIn: 'root' }) export class TodosService { constructor( private http: HttpClient, private config: ConfigService, ) {} getAllTodos(): Observable { return this.http .get(`${this.config.getBackendBaseUrl()}/todos`) .pipe( retry(3), catchError(() => of([])), ); } addTodo(todo: CreateTodo): Observable { return this.http.post( `${this.config.getBackendBaseUrl()}/todos`, todo, ); } updateTodo(todo: Todo): Observable { return this.http.patch( `${this.config.getBackendBaseUrl()}/todos/${todo._id}`, todo, ); } removeTodo(todo: Todo): Observable { return this.http.delete( `${this.config.getBackendBaseUrl()}/todos/${todo._id}`, ); } }