Refactor and expose more information #1
Reference in New Issue
Block a user
Delete Branch "Rebase"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
This pull request refactors the
HomeApiproject to adopt a cleaner architecture by introducing MediatR for request handling, extracting integration logic into dedicated services, and improving code modularity with extension methods. Additionally, it renames and reorganizes several models and files for better clarity and alignment with their purposes.Refactoring for cleaner architecture:
HomeApi/Controllers/HomeController.cs: Replaced direct logic for fetching weather and aurora data with MediatR'sHandlerpattern. TheHomeControllernow delegates theGetaction to aGetWeather.Command, simplifying the controller and removing redundant methods.Modularization of integration logic:
HomeApi/Integration/AuroraService.cs,HomeApi/Integration/GeocodingService.cs, andHomeApi/Integration/WeatherService.cs: Introduced dedicated services (IAuroraService,IGeocodingService,IWeatherService) for external API calls, encapsulating integration logic and improving testability. [1] [2] [3]HomeApi/Integration/Client/AuroraClient.cs,HomeApi/Integration/Client/NominatimClient.cs, andHomeApi/Integration/Client/WeatherClient.cs: Added Refit-based API client interfaces for Aurora, Nominatim, and Weather APIs, reducing boilerplate code for HTTP requests. [1] [2] [3]Introduction of extension methods:
HomeApi/Extensions/ContractExtensions.cs: Added methods to map weather data and forecasts into theWeatherInformationcontract, centralizing transformation logic for better code reuse.HomeApi/Extensions/IntegrationExtensions.cs: Added an extension method to configure base addresses for HTTP clients usingApiConfiguration, simplifying dependency injection setup.File renaming and reorganization:
ApiConfiguration,AuroraForecastApiResponse,WeatherApiResponse,WeatherInformation) to better reflect their purposes and moved them into appropriate namespaces (HomeApi.Models.Response,HomeApi.Models.Configuration). [1] [2] [3] [4]Dependency updates:
HomeApi/HomeApi.csproj: Added dependencies for MediatR and Refit to support the new architectural changes.