feat(mobile): use cached asset info if unchanged instead of downloading all assets (#1017)

* feat(mobile): use cached asset info if unchanged instead of downloading all assets

This adds an HTTP ETag to the getAllAssets endpoint and client-side support in the app.
If locally cache content is identical to the content on the server, the potentially large list of all assets does not need to be downloaded.

* use ts import instead of require
This commit is contained in:
Fynn Petersen-Frey
2022-11-26 17:16:02 +01:00
committed by GitHub
parent efa7b3ba54
commit 47f5e4134e
18 changed files with 322 additions and 201 deletions

View File

@@ -297,7 +297,12 @@ class AssetApi {
/// Get all AssetEntity belong to the user
///
/// Note: This method returns the HTTP [Response].
Future<Response> getAllAssetsWithHttpInfo() async {
///
/// Parameters:
///
/// * [String] ifNoneMatch:
/// ETag of data already cached on the client
Future<Response> getAllAssetsWithHttpInfo({ String? ifNoneMatch, }) async {
// ignore: prefer_const_declarations
final path = r'/asset';
@@ -308,6 +313,10 @@ class AssetApi {
final headerParams = <String, String>{};
final formParams = <String, String>{};
if (ifNoneMatch != null) {
headerParams[r'if-none-match'] = parameterToString(ifNoneMatch);
}
const contentTypes = <String>[];
@@ -325,8 +334,13 @@ class AssetApi {
///
///
/// Get all AssetEntity belong to the user
Future<List<AssetResponseDto>?> getAllAssets() async {
final response = await getAllAssetsWithHttpInfo();
///
/// Parameters:
///
/// * [String] ifNoneMatch:
/// ETag of data already cached on the client
Future<List<AssetResponseDto>?> getAllAssets({ String? ifNoneMatch, }) async {
final response = await getAllAssetsWithHttpInfo( ifNoneMatch: ifNoneMatch, );
if (response.statusCode >= HttpStatus.badRequest) {
throw ApiException(response.statusCode, await _decodeBodyBytes(response));
}