Update chart-type.service.ts
This commit is contained in:
@@ -1,7 +1,6 @@
|
|||||||
import { Injectable } from '@angular/core';
|
import { Injectable } from '@angular/core';
|
||||||
import { HttpClient } from '@angular/common/http';
|
|
||||||
import { Observable } from 'rxjs';
|
import { Observable } from 'rxjs';
|
||||||
import { environment } from 'src/environments/environment';
|
import { ApiRequestService } from 'src/app/services/api/api-request.service';
|
||||||
|
|
||||||
export interface ChartType {
|
export interface ChartType {
|
||||||
id: number;
|
id: number;
|
||||||
@@ -17,33 +16,35 @@ export interface ChartType {
|
|||||||
providedIn: 'root'
|
providedIn: 'root'
|
||||||
})
|
})
|
||||||
export class ChartTypeService {
|
export class ChartTypeService {
|
||||||
private apiUrl = environment.apiUrl || 'http://localhost:8080/api';
|
private chartTypesUrl = 'api/chart-types';
|
||||||
private chartTypesUrl = `${this.apiUrl}/chart-types`;
|
|
||||||
|
|
||||||
constructor(private http: HttpClient) { }
|
constructor(private apiRequest: ApiRequestService) { }
|
||||||
|
|
||||||
// Get all chart types
|
// Get all chart types
|
||||||
getAllChartTypes(): Observable<ChartType[]> {
|
getAllChartTypes(): Observable<ChartType[]> {
|
||||||
return this.http.get<ChartType[]>(this.chartTypesUrl);
|
return this.apiRequest.get(this.chartTypesUrl);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get chart type by ID
|
// Get chart type by ID
|
||||||
getChartTypeById(id: number): Observable<ChartType> {
|
getChartTypeById(id: number): Observable<ChartType> {
|
||||||
return this.http.get<ChartType>(`${this.chartTypesUrl}/${id}`);
|
const url = `${this.chartTypesUrl}/${id}`;
|
||||||
|
return this.apiRequest.get(url);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create new chart type
|
// Create new chart type
|
||||||
createChartType(chartType: Partial<ChartType>): Observable<ChartType> {
|
createChartType(chartType: Partial<ChartType>): Observable<ChartType> {
|
||||||
return this.http.post<ChartType>(this.chartTypesUrl, chartType);
|
return this.apiRequest.post(this.chartTypesUrl, chartType);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Update chart type
|
// Update chart type
|
||||||
updateChartType(id: number, chartType: ChartType): Observable<ChartType> {
|
updateChartType(id: number, chartType: ChartType): Observable<ChartType> {
|
||||||
return this.http.put<ChartType>(`${this.chartTypesUrl}/${id}`, chartType);
|
const url = `${this.chartTypesUrl}/${id}`;
|
||||||
|
return this.apiRequest.put(url, chartType);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Delete chart type
|
// Delete chart type
|
||||||
deleteChartType(id: number): Observable<void> {
|
deleteChartType(id: number): Observable<void> {
|
||||||
return this.http.delete<void>(`${this.chartTypesUrl}/${id}`);
|
const url = `${this.chartTypesUrl}/${id}`;
|
||||||
|
return this.apiRequest.delete(url);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user