Reafactor: for routing, Add: navbar & footer
This commit is contained in:
parent
32851bead5
commit
ebdfd2f5e3
16 changed files with 586 additions and 243 deletions
32
src/app/services/energy-price.service.ts
Normal file
32
src/app/services/energy-price.service.ts
Normal file
|
@ -0,0 +1,32 @@
|
|||
import { Injectable, inject } from '@angular/core';
|
||||
import { HttpClient } from '@angular/common/http';
|
||||
import { Observable } from 'rxjs';
|
||||
|
||||
export interface EnergyPrice {
|
||||
SEK_per_kWh: number;
|
||||
EUR_per_kWh: number;
|
||||
EXR: number;
|
||||
time_start: string;
|
||||
time_end: string;
|
||||
}
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
})
|
||||
export class EnergyPriceService {
|
||||
private apiBaseUrl = 'https://www.elprisetjustnu.se/api/v1/prices';
|
||||
private http = inject(HttpClient);
|
||||
|
||||
getPrices(year: string, month: string, day: string, priceClass: string): Observable<EnergyPrice[]> {
|
||||
const url = `${this.apiBaseUrl}/${year}/${month}-${day}_${priceClass}.json`;
|
||||
return this.http.get<EnergyPrice[]>(url);
|
||||
}
|
||||
|
||||
formatDate(date: Date): { year: string, month: string, day: string } {
|
||||
const year = date.getFullYear().toString();
|
||||
const month = (date.getMonth() + 1).toString().padStart(2, '0');
|
||||
const day = date.getDate().toString().padStart(2, '0');
|
||||
|
||||
return { year, month, day };
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue