Last active
April 16, 2020 20:17
-
-
Save filipemansano/658fab511f84d57397e407f3e07bc486 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 { Injectable } from "@angular/core"; | |
import { HttpClient } from "@angular/common/http"; | |
import { CrudInterface } from "@app/core/crud.interface"; | |
import { environment } from "@env/environment"; | |
import { Observable } from "rxjs/Observable"; | |
@Injectable() | |
export class CRUD<T> implements CrudInterface<T>{ | |
endpoint: string; | |
constructor(private http: HttpClient, routeDir: string){ | |
this.endpoint = `${environment.endpoint}/${routeDir}`; | |
} | |
getAll(): Observable<T[]> { | |
return this.http.get<T[]>(`${this.endpoint}`); | |
} | |
get(id: number): Observable<T> { | |
return this.http.get<T>(`${this.endpoint}/${id}`); | |
} | |
create(object: T): Observable<T> { | |
return this.http.post<T>(`${this.endpoint}`, object); | |
} | |
update(object: T): Observable<T> { | |
return this.http.put<T>(`${this.endpoint}`, object); | |
} | |
delete(id: number): Observable<any> { | |
return this.http.delete<T>(`${this.endpoint}/${id}`); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment