diff --git a/lib/src/api/default_api.dart b/lib/src/api/default_api.dart index 41e7c1b..8d5b623 100644 --- a/lib/src/api/default_api.dart +++ b/lib/src/api/default_api.dart @@ -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>> 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>( + _path, + options: _options, + cancelToken: cancelToken, + onSendProgress: onSendProgress, + onReceiveProgress: onReceiveProgress, + ); + + List>? _responseData = + _response.data?.map((dynamic e) => e as Map).toList(); + if (_responseData == null) { + throw DioError( + requestOptions: _options.compose( + _dio.options, + _path, + ), + type: DioErrorType.unknown, + error: 'Response was null', + ); + } + + return Response>( + 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>> 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>( + _path, + options: _options, + cancelToken: cancelToken, + onSendProgress: onSendProgress, + onReceiveProgress: onReceiveProgress, + ); + + List? _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>( + data: _responseData, + headers: _response.headers, + isRedirect: _response.isRedirect, + requestOptions: _response.requestOptions, + redirects: _response.redirects, + statusCode: _response.statusCode, + statusMessage: _response.statusMessage, + extra: _response.extra, + ); + } } diff --git a/lib/src/model/asset.dart b/lib/src/model/asset.dart new file mode 100644 index 0000000..665b724 --- /dev/null +++ b/lib/src/model/asset.dart @@ -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 json) => _$AssetFromJson(json); + Map toJson() => _$AssetToJson(this); +} diff --git a/lib/src/model/asset.g.dart b/lib/src/model/asset.g.dart new file mode 100644 index 0000000..9bc44b4 --- /dev/null +++ b/lib/src/model/asset.g.dart @@ -0,0 +1,23 @@ +// GENERATED CODE - DO NOT MODIFY BY HAND + +part of 'asset.dart'; + +// ************************************************************************** +// JsonSerializableGenerator +// ************************************************************************** + +Asset _$AssetFromJson(Map 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 _$AssetToJson(Asset instance) => { + 'id': instance.id, + 'name': instance.name, + 'description': instance.description, + 'fid': instance.fid, + 'tags': instance.tags, + };