Refactor and expose more information #1

Merged
Myxelium merged 1 commits from Rebase into master 2025-07-14 18:40:41 +00:00
Myxelium commented 2025-07-14 18:40:05 +00:00 (Migrated from github.com)

This pull request refactors the HomeApi project 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's Handler pattern. The HomeController now delegates the Get action to a GetWeather.Command, simplifying the controller and removing redundant methods.

Modularization of integration logic:

  • HomeApi/Integration/AuroraService.cs, HomeApi/Integration/GeocodingService.cs, and HomeApi/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, and HomeApi/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:

File renaming and reorganization:

  • Renamed several model files (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:

This pull request refactors the `HomeApi` project 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`](diffhunk://#diff-bcb176ac427abafade9171d89b837645f0b2301245822af60af2bf6575175fa5L1-R16): Replaced direct logic for fetching weather and aurora data with MediatR's `Handler` pattern. The `HomeController` now delegates the `Get` action to a `GetWeather.Command`, simplifying the controller and removing redundant methods. ### Modularization of integration logic: * `HomeApi/Integration/AuroraService.cs`, `HomeApi/Integration/GeocodingService.cs`, and `HomeApi/Integration/WeatherService.cs`: Introduced dedicated services (`IAuroraService`, `IGeocodingService`, `IWeatherService`) for external API calls, encapsulating integration logic and improving testability. [[1]](diffhunk://#diff-0aba1aa3668638baee5da249134a649b99ff7740466ab6153b2c66aeb4468b03R1-R17) [[2]](diffhunk://#diff-f68ebb3f1aa17130b444f3ee4358ae225466aa6adae8f676c8118608281696e4R1-R19) [[3]](diffhunk://#diff-e17ad6cf7ba341df9a19ea05e1db8ecdb625300a3dd07e710d8c8512c540514aR1-R22) * `HomeApi/Integration/Client/AuroraClient.cs`, `HomeApi/Integration/Client/NominatimClient.cs`, and `HomeApi/Integration/Client/WeatherClient.cs`: Added Refit-based API client interfaces for Aurora, Nominatim, and Weather APIs, reducing boilerplate code for HTTP requests. [[1]](diffhunk://#diff-f55878b4d91ebe1f02a95091716098e1fb61a753c2c910c87a368d7833f6e8f5R1-R15) [[2]](diffhunk://#diff-b1ed13e3fa35a9c4e018b143fb4c4539c021fa29de03d84840581bd4779152eeR1-R13) [[3]](diffhunk://#diff-1f50c9ef67bcb489a45e7453edae9392d9949f0868cec71ed944b18dc5f675dfR1-R17) ### Introduction of extension methods: * [`HomeApi/Extensions/ContractExtensions.cs`](diffhunk://#diff-eb5380d827de700a43ee4414aa6e6ac6d5f9ed7ab945d0225b99bbf28fadf7a7R1-R129): Added methods to map weather data and forecasts into the `WeatherInformation` contract, centralizing transformation logic for better code reuse. * [`HomeApi/Extensions/IntegrationExtensions.cs`](diffhunk://#diff-c196a49e4e895be04f65b98667edb31ad156df011b2a589eac8d428b881b3dedR1-R17): Added an extension method to configure base addresses for HTTP clients using `ApiConfiguration`, simplifying dependency injection setup. ### File renaming and reorganization: * Renamed several model files (`ApiConfiguration`, `AuroraForecastApiResponse`, `WeatherApiResponse`, `WeatherInformation`) to better reflect their purposes and moved them into appropriate namespaces (`HomeApi.Models.Response`, `HomeApi.Models.Configuration`). [[1]](diffhunk://#diff-dd9c1578547ac855792ea1d7c996d0f33b2529ffd51161fb1519dda076d304ceL1-R1) [[2]](diffhunk://#diff-d13dab5b1942addd377f3f0345558830d0928e386fae5358da8bd18179d665f1L1-R5) [[3]](diffhunk://#diff-1714310e98db9b83e83957528f9085eda685e0ac277b1ffe91bf6f6b8969a469R1-R2) [[4]](diffhunk://#diff-40cfe8cce144bb487de51c50e2a7cd2e396f54d9f5cd786e1d1ba8d97d7305fcR1-R5) ### Dependency updates: * [`HomeApi/HomeApi.csproj`](diffhunk://#diff-6dc377d1cd7add61ac0aaad835f9ea837c5f1566fc595c08d6b4be1173ce6641R11-R14): Added dependencies for MediatR and Refit to support the new architectural changes.
Sign in to join this conversation.