diff --git a/src/weather/controllers/index.ts b/src/weather/controllers/index.ts deleted file mode 100644 index 8157369..0000000 --- a/src/weather/controllers/index.ts +++ /dev/null @@ -1 +0,0 @@ -export * from './weather.controller'; diff --git a/src/weather/controllers/weather.controller.ts b/src/weather/controllers/weather.controller.ts deleted file mode 100644 index 280e09d..0000000 --- a/src/weather/controllers/weather.controller.ts +++ /dev/null @@ -1,28 +0,0 @@ -import { Controller, Get, Query } from '@nestjs/common'; -import { ApiOperation, ApiTags } from '@nestjs/swagger'; -import { EnableDisableStatusEnum } from '@app/common/constants/days.enum'; -import { ControllerRoute } from '@app/common/constants/controller-route'; // Assuming this is where the routes are defined -import { WeatherService } from '../services'; -import { BaseResponseDto } from '@app/common/dto/base.response.dto'; -import { GetWeatherDetailsDto } from '../dto/get.weather.dto'; - -@ApiTags('Weather Module') -@Controller({ - version: EnableDisableStatusEnum.ENABLED, - path: ControllerRoute.WEATHER.ROUTE, // use the static route constant -}) -export class WeatherController { - constructor(private readonly weatherService: WeatherService) {} - - @Get() - @ApiOperation({ - summary: ControllerRoute.WEATHER.ACTIONS.FETCH_WEATHER_DETAILS_SUMMARY, - description: - ControllerRoute.WEATHER.ACTIONS.FETCH_WEATHER_DETAILS_DESCRIPTION, - }) - async fetchWeatherDetails( - @Query() query: GetWeatherDetailsDto, - ): Promise { - return await this.weatherService.fetchWeatherDetails(query); - } -} diff --git a/src/weather/dto/get.weather.dto.ts b/src/weather/dto/get.weather.dto.ts deleted file mode 100644 index 86aefdd..0000000 --- a/src/weather/dto/get.weather.dto.ts +++ /dev/null @@ -1,21 +0,0 @@ -import { ApiProperty } from '@nestjs/swagger'; -import { Type } from 'class-transformer'; -import { IsNumber } from 'class-validator'; - -export class GetWeatherDetailsDto { - @ApiProperty({ - description: 'Latitude coordinate', - example: 35.6895, - }) - @IsNumber() - @Type(() => Number) - lat: number; - - @ApiProperty({ - description: 'Longitude coordinate', - example: 139.6917, - }) - @IsNumber() - @Type(() => Number) - lon: number; -} diff --git a/src/weather/services/index.ts b/src/weather/services/index.ts deleted file mode 100644 index 9b2cb64..0000000 --- a/src/weather/services/index.ts +++ /dev/null @@ -1 +0,0 @@ -export * from './weather.service'; diff --git a/src/weather/services/weather.service.ts b/src/weather/services/weather.service.ts deleted file mode 100644 index 3463b5c..0000000 --- a/src/weather/services/weather.service.ts +++ /dev/null @@ -1,51 +0,0 @@ -import { HttpException, HttpStatus, Injectable } from '@nestjs/common'; -import { HttpService } from '@nestjs/axios'; -import { ConfigService } from '@nestjs/config'; -import { firstValueFrom } from 'rxjs'; -import { GetWeatherDetailsDto } from '../dto/get.weather.dto'; -import { calculateAQI } from '@app/common/util/calculate.aqi'; -import { BaseResponseDto } from '@app/common/dto/base.response.dto'; -import { SuccessResponseDto } from '@app/common/dto/success.response.dto'; - -@Injectable() -export class WeatherService { - private readonly weatherApiUrl: string; - constructor( - private readonly configService: ConfigService, - private readonly httpService: HttpService, - ) { - this.weatherApiUrl = this.configService.get('WEATHER_API_URL'); - } - - async fetchWeatherDetails( - query: GetWeatherDetailsDto, - ): Promise { - try { - const { lat, lon } = query; - const weatherApiKey = this.configService.get( - 'OPEN_WEATHER_MAP_API_KEY', - ); - const url = `${this.weatherApiUrl}/current.json?key=${weatherApiKey}&q=${lat},${lon}&aqi=yes`; - - const response = await firstValueFrom(this.httpService.get(url)); - const pm2_5 = response.data.current.air_quality.pm2_5; // Raw PM2.5 (µg/m³) - - return new SuccessResponseDto({ - message: `Weather details fetched successfully`, - data: { - aqi: calculateAQI(pm2_5), // Converted AQI (0-500) - temperature: response.data.current.temp_c, - humidity: response.data.current.humidity, - }, - statusCode: HttpStatus.OK, - }); - } catch (error) { - console.log(`Error fetching weather data: ${error}`); - - throw new HttpException( - `Api can't handle these lat and lon values`, - error.response?.status || HttpStatus.INTERNAL_SERVER_ERROR, - ); - } - } -} diff --git a/src/weather/weather.module.ts b/src/weather/weather.module.ts deleted file mode 100644 index eb65b5b..0000000 --- a/src/weather/weather.module.ts +++ /dev/null @@ -1,12 +0,0 @@ -import { Module } from '@nestjs/common'; -import { ConfigModule } from '@nestjs/config'; -import { HttpModule } from '@nestjs/axios'; // <-- Import this! -import { WeatherController } from './controllers'; -import { WeatherService } from './services'; - -@Module({ - imports: [ConfigModule, HttpModule], - controllers: [WeatherController], - providers: [WeatherService], -}) -export class WeatherModule {}