Closed marfavi closed 10 months ago
Patch coverage: 88.09%
and project coverage change: +5.27%
:tada:
Comparison is base (
4aed248
) 79.58% compared to head (03cc4a6
) 84.85%. Report is 2 commits behind head on develop.
:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.
Overview:
This PR refactors the
NetworkRequestExecutor
class to improve its readability, maintainability, and testability. It also updates all dependent components to align with the new executor methods.Notably, it also removes the need to provide dummy values for certain
dynamic
types, e.g. for the typeEither<NetworkFailure, dynamic>
, which triggered linter warnings.Changes to
NetworkRequestExecutor
:Added New Typedefs: Introduced
_NetworkRequest<BodyType>
and_ExecutorResult<R>
to avoid repetition.Method Renaming and Refactoring:
call
toexecute
and updated its signature.logResponse
to_logResponse
and slightly simplified its logic.executeAndDiscard
for requests where the response body is not needed.dynamic
types as mentioned in the overview.New Mapping Extensions:
ExecutorMapX
andExecutorMapAllX
to handle mapping of results. The call tomap()
ormapAll()
should be chained after anexecute()
call.mapAll()
is only possible when dealing with executor calls where the expected response body is anIterable
.TaskEither
class in the future.network_request_executor_mapping.dart
, which is a part ofnetwork_request_executor.dart
.Added Documentation: Added doc comments to all methods above.
How it affects code
Take a look at how code is affected by this refactor:
await
keyword in code means noasync
tag is needed in the method signature.call
, the return type ofexecute
can be easily accessed with your preferred code editor. This aims to improve DX and fits well alongside the new similarly named methodexecuteAndDiscard
.call
, the Dart formatter will automatically format chained method calls in a way that better conveys what's happening.Other changes
Updates in Other Components:
EnvironmentRemoteDataSource
,OpeningHoursRemoteDataSource
,ProductRemoteDataSource
, etc., to use the new executor methods.map()
/mapAll()
extensions removeeither_extensions.dart
as a dependency to these files.OpeningHoursRepository
(and Impl); replaced with new classOpeningHoursModel
to better align with the rest of the codebase.OpeningHoursRemoteDataSource.getOpeningHours()
to return an entity rather than a generated DTO class to better align the rest of the codebase.Test Updates: Updated tests to align with the new executor methods.
Removed a barrel file that wasn't supposed to exist in feature Opening Hours
ticket_remote_data_source.dart
: Moved mapper method out of the large chain of calls to improve readability.Why This is Necessary:
Readability: Method renaming and new typedefs make the code easier to understand.
Testability: The
executeAndDiscard
method simplifies testing for requests where the response body is not important.Maintainability: Improved documentation and more descriptive method names make the code easier to maintain.
Please review and let me know if any changes are required.