Add api to list assets and get assets tags
This commit is contained in:
parent
46d8acd4a5
commit
51746097d5
3 changed files with 168 additions and 0 deletions
|
|
@ -7,6 +7,7 @@ import 'dart:async';
|
|||
import 'package:dio/dio.dart';
|
||||
|
||||
import 'package:tuuli_api/src/model/access_token_response.dart';
|
||||
import 'package:tuuli_api/src/model/asset.dart';
|
||||
import 'package:tuuli_api/src/model/auth_model.dart';
|
||||
import 'package:tuuli_api/src/model/items_selector.dart';
|
||||
import 'package:tuuli_api/src/model/item_update.dart';
|
||||
|
|
@ -927,4 +928,118 @@ class DefaultApi {
|
|||
extra: _response.extra,
|
||||
);
|
||||
}
|
||||
|
||||
/// Get assets
|
||||
///
|
||||
///
|
||||
/// Parameters:
|
||||
/// * [cancelToken] - A [CancelToken] that can be used to cancel the operation
|
||||
/// * [validateStatus] - A [ValidateStatus] callback that can be used to determine request success based on the HTTP status of the response
|
||||
/// * [onSendProgress] - A [ProgressCallback] that can be used to get the send progress
|
||||
/// * [onReceiveProgress] - A [ProgressCallback] that can be used to get the receive progress
|
||||
///
|
||||
/// Returns a [Future] containing a [Response] with a [List] of [Asset] as data
|
||||
/// Throws [DioError] if API call or serialization fails
|
||||
Future<Response<List<Asset>>> getAssets({
|
||||
CancelToken? cancelToken,
|
||||
ValidateStatus? validateStatus,
|
||||
ProgressCallback? onSendProgress,
|
||||
ProgressCallback? onReceiveProgress,
|
||||
}) async {
|
||||
final _path = '/api/assets';
|
||||
final _options = Options(
|
||||
method: 'GET',
|
||||
contentType: 'application/json',
|
||||
validateStatus: validateStatus,
|
||||
);
|
||||
|
||||
final _response = await _dio.request<List<dynamic>>(
|
||||
_path,
|
||||
options: _options,
|
||||
cancelToken: cancelToken,
|
||||
onSendProgress: onSendProgress,
|
||||
onReceiveProgress: onReceiveProgress,
|
||||
);
|
||||
|
||||
List<Map<String, dynamic>>? _responseData =
|
||||
_response.data?.map((dynamic e) => e as Map<String, dynamic>).toList();
|
||||
if (_responseData == null) {
|
||||
throw DioError(
|
||||
requestOptions: _options.compose(
|
||||
_dio.options,
|
||||
_path,
|
||||
),
|
||||
type: DioErrorType.unknown,
|
||||
error: 'Response was null',
|
||||
);
|
||||
}
|
||||
|
||||
return Response<List<Asset>>(
|
||||
data: _responseData.map((e) => Asset.fromJson(e)).toList(growable: false),
|
||||
headers: _response.headers,
|
||||
isRedirect: _response.isRedirect,
|
||||
requestOptions: _response.requestOptions,
|
||||
redirects: _response.redirects,
|
||||
statusCode: _response.statusCode,
|
||||
statusMessage: _response.statusMessage,
|
||||
extra: _response.extra,
|
||||
);
|
||||
}
|
||||
|
||||
/// Get assets tags
|
||||
///
|
||||
///
|
||||
/// Parameters:
|
||||
/// * [cancelToken] - A [CancelToken] that can be used to cancel the operation
|
||||
/// * [validateStatus] - A [ValidateStatus] callback that can be used to determine request success based on the HTTP status of the response
|
||||
/// * [onSendProgress] - A [ProgressCallback] that can be used to get the send progress
|
||||
/// * [onReceiveProgress] - A [ProgressCallback] that can be used to get the receive progress
|
||||
///
|
||||
/// Returns a [Future] containing a [Response] with a [List] of [String] as data
|
||||
/// Throws [DioError] if API call or serialization fails
|
||||
Future<Response<List<String>>> getAssetsTags({
|
||||
CancelToken? cancelToken,
|
||||
ValidateStatus? validateStatus,
|
||||
ProgressCallback? onSendProgress,
|
||||
ProgressCallback? onReceiveProgress,
|
||||
}) async {
|
||||
final _path = '/api/assets';
|
||||
final _options = Options(
|
||||
method: 'GET',
|
||||
contentType: 'application/json',
|
||||
validateStatus: validateStatus,
|
||||
);
|
||||
|
||||
final _response = await _dio.request<List<dynamic>>(
|
||||
_path,
|
||||
options: _options,
|
||||
cancelToken: cancelToken,
|
||||
onSendProgress: onSendProgress,
|
||||
onReceiveProgress: onReceiveProgress,
|
||||
);
|
||||
|
||||
List<String>? _responseData =
|
||||
_response.data?.map((dynamic e) => e as String).toList();
|
||||
if (_responseData == null) {
|
||||
throw DioError(
|
||||
requestOptions: _options.compose(
|
||||
_dio.options,
|
||||
_path,
|
||||
),
|
||||
type: DioErrorType.unknown,
|
||||
error: 'Response was null',
|
||||
);
|
||||
}
|
||||
|
||||
return Response<List<String>>(
|
||||
data: _responseData,
|
||||
headers: _response.headers,
|
||||
isRedirect: _response.isRedirect,
|
||||
requestOptions: _response.requestOptions,
|
||||
redirects: _response.redirects,
|
||||
statusCode: _response.statusCode,
|
||||
statusMessage: _response.statusMessage,
|
||||
extra: _response.extra,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
30
lib/src/model/asset.dart
Normal file
30
lib/src/model/asset.dart
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
import 'package:json_annotation/json_annotation.dart';
|
||||
|
||||
part 'asset.g.dart';
|
||||
|
||||
/// AssetModel
|
||||
///
|
||||
/// Properties:
|
||||
/// * [id]
|
||||
/// * [name]
|
||||
/// * [description]
|
||||
/// * [fid]
|
||||
/// * [tags]
|
||||
@JsonSerializable()
|
||||
class Asset {
|
||||
final int id;
|
||||
final String name;
|
||||
final String description;
|
||||
final String fid;
|
||||
final String tags;
|
||||
|
||||
const Asset(
|
||||
{required this.id,
|
||||
required this.name,
|
||||
required this.description,
|
||||
required this.fid,
|
||||
required this.tags});
|
||||
|
||||
factory Asset.fromJson(Map<String, dynamic> json) => _$AssetFromJson(json);
|
||||
Map<String, dynamic> toJson() => _$AssetToJson(this);
|
||||
}
|
||||
23
lib/src/model/asset.g.dart
Normal file
23
lib/src/model/asset.g.dart
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
// GENERATED CODE - DO NOT MODIFY BY HAND
|
||||
|
||||
part of 'asset.dart';
|
||||
|
||||
// **************************************************************************
|
||||
// JsonSerializableGenerator
|
||||
// **************************************************************************
|
||||
|
||||
Asset _$AssetFromJson(Map<String, dynamic> json) => Asset(
|
||||
id: json['id'] as int,
|
||||
name: json['name'] as String,
|
||||
description: json['description'] as String,
|
||||
fid: json['fid'] as String,
|
||||
tags: json['tags'] as String,
|
||||
);
|
||||
|
||||
Map<String, dynamic> _$AssetToJson(Asset instance) => <String, dynamic>{
|
||||
'id': instance.id,
|
||||
'name': instance.name,
|
||||
'description': instance.description,
|
||||
'fid': instance.fid,
|
||||
'tags': instance.tags,
|
||||
};
|
||||
Loading…
Add table
Add a link
Reference in a new issue