Skip to content

Commit

Permalink
chore: add next days api
Browse files Browse the repository at this point in the history
  • Loading branch information
MishaZhem committed Jul 22, 2024
1 parent c373799 commit 8a760f4
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ <h1 class="tui-space_top-3 tui-space_bottom-3">{{ info?.current?.temp_c }}°</h1
</div>
<div class="list-days">
<div
*ngFor="let card of weatherService.weatherData"
*ngFor="let card of weatherService.weatherData; let ind = index"
class="small-card"
>
<tui-icon
Expand All @@ -66,9 +66,13 @@ <h1 class="tui-space_top-3 tui-space_bottom-3">{{ info?.current?.temp_c }}°</h1
class="tui-space_top-0 tui-space_bottom-0"
[style.font-weight]="'600'"
>
{{ card.day }}
{{ weatherService.getWeekDay(info.forecast.forecastday[ind + 1].date) }}
</p>
<p class="tui-space_top-0 tui-space_bottom-0">
{{ info.forecast.forecastday[ind + 1].day.mintemp_c }}°/{{
info.forecast.forecastday[ind + 1].day.maxtemp_c
}}°
</p>
<p class="tui-space_top-0 tui-space_bottom-0">{{ card.temp }}</p>
</div>
</div>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,13 @@ export interface ResponseCurrent {
wind_kph: string;
}

export interface ForecastDay {
mintemp_c: string;
maxtemp_c: string;
}

export interface ResponseData {
location: ResponseLocation;
current: ResponseCurrent;
forecast: ForecastDay;
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,29 @@ export class WeatherService {
public readonly weatherData = INITIAL_DATA;

public getTest(): Observable<ResponseData> {
return this.http.get<ResponseData>('http://api.weatherapi.com/v1/current.json', {
return this.http.get<ResponseData>('http://api.weatherapi.com/v1/forecast.json', {
params: {
key: this.API_KEY,
q: this.city,
api: 'yes',
days: '4',
},
});
}

public getWeekDay(value: string): string {
const days = ['Sun', 'Mon', 'Tues', 'Wed', 'Thurs', 'Fri', 'Sat'];

const valueSplit = value.split('-');
const date = new Date(
parseInt(valueSplit[0], 10),
parseInt(valueSplit[1], 10) - 1,
parseInt(valueSplit[2], 10),
);

return days[date.getDay()];
}

public getTypeOfWeather(value: number): string {
const clouds = [1003, 1006, 1030, 1087, 1135];
const rain = [
Expand Down

0 comments on commit 8a760f4

Please sign in to comment.