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