1
0
Fork 0

Reafactor: for routing, Add: navbar & footer

This commit is contained in:
Aroy-Art 2025-05-16 14:18:16 +02:00
parent 32851bead5
commit ebdfd2f5e3
Signed by: Aroy
GPG key ID: 583642324A1D2070
16 changed files with 586 additions and 243 deletions

View 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 };
}
}