Last active
December 4, 2020 17:42
-
-
Save jonathanwoahn/4f63bfbfd61d60f6aa9e8f1b920dd5a3 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { HttpClient } from '@angular/common/http'; | |
import { Observable } from 'rxjs'; | |
import { DefaultDataService } from '@woahn/ezngrx'; | |
import { Injectable } from '@angular/core'; | |
import { Todo } from './app.module'; | |
import { map } from 'rxjs/operators'; | |
@Injectable({ | |
providedIn: 'root' | |
}) | |
export class TodoDataService extends DefaultDataService<Todo> { | |
entity = 'Todo'; | |
private url = `http://localhost:3000/todo`; | |
constructor(private http: HttpClient) { | |
super(); | |
} | |
load(): Observable<Todo[]> { | |
return this.http.get<Todo[]>(this.url); | |
} | |
addOneEntity(todo: Todo): Observable<Todo> { | |
return this.http.post<Todo>(this.url, todo); | |
} | |
removeOneEntity(key: string): Observable<string> { | |
return this.http.delete<Todo>(`${this.url}/${key}`).pipe(map(() => key)); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment