LCOV - code coverage report
Current view: top level - src/database/repository - project_repository.dart (source / functions) Hit Total Coverage
Test: lcov.info Lines: 2 28 7.1 %
Date: 2020-12-04 18:41:24 Functions: 0 0 -

          Line data    Source code
       1             : import 'dart:convert';
       2             : import 'dart:typed_data';
       3             : 
       4             : import 'package:flutter/cupertino.dart';
       5             : import 'package:http/http.dart';
       6             : import 'package:pal/src/database/adapter/app_icon_entity.dart';
       7             : import 'package:pal/src/database/entity/app_icon_entity.dart';
       8             : import 'package:pal/src/database/repository/base_repository.dart';
       9             : import 'package:pal/src/services/http_client/base_client.dart';
      10             : 
      11             : class ProjectRepository extends BaseHttpRepository {
      12             :   final AppIconEntityAdapter _adapter = AppIconEntityAdapter();
      13             : 
      14           6 :   ProjectRepository({@required HttpClient httpClient})
      15           6 :       : super(httpClient: httpClient);
      16             : 
      17           0 :   Future<AppIconEntity> createAppIcon(
      18             :     Uint8List imageData,
      19             :     String imageType,
      20             :   ) async {
      21           0 :     var result = await httpClient
      22           0 :         .multipartImage(
      23             :           'editor/app-icon',
      24           0 :           fileData: imageData.toList(),
      25             :           imageType: imageType,
      26             :           fileFieldName: 'appIcon',
      27             :           filename: 'appIcon',
      28             :         )
      29           0 :         .timeout(Duration(seconds: 60))
      30           0 :         .catchError((onError) {
      31             :       throw 'ERROR_UPLOADING_APP_ICON';
      32             :     });
      33           0 :     var stream = result.stream.transform(utf8.decoder);
      34           0 :     var jsonResult = await stream.first;
      35           0 :     if (result.statusCode >= 300) {
      36           0 :       print(' reason : $jsonResult');
      37             :       throw 'ERROR_UPLOADING_APP_ICON';
      38             :     }
      39           0 :     return _adapter.parse(jsonResult);
      40             :   }
      41             : 
      42           0 :   Future<AppIconEntity> updateAppIcon(
      43             :     String appIconId,
      44             :     Uint8List imageData,
      45             :     String imageType,
      46             :   ) async {
      47           0 :     var result = await httpClient
      48           0 :         .multipartImage(
      49           0 :           'editor/app-icon/$appIconId',
      50           0 :           fileData: imageData.toList(),
      51             :           imageType: imageType,
      52             :           fileFieldName: 'appIcon',
      53             :           filename: 'appIcon',
      54             :         )
      55           0 :         .timeout(Duration(seconds: 60))
      56           0 :         .catchError((onError) {
      57             :       throw 'ERROR_UPLOADING_APP_ICON';
      58             :     });
      59           0 :     var stream = result.stream.transform(utf8.decoder);
      60           0 :     var jsonResult = await stream.first;
      61           0 :     if (result.statusCode >= 300) {
      62           0 :       print(' reason : $jsonResult');
      63             :       throw 'ERROR_UPLOADING_APP_ICON';
      64             :     }
      65           0 :     return _adapter.parse(jsonResult);
      66             :   }
      67             : 
      68           0 :   Future<AppIconEntity> getAppIcon() async {
      69             :     final Response response =
      70           0 :         await this.httpClient.get('editor/app-icon');
      71           0 :     return this._adapter.parse(response.body);
      72             :   }
      73             : }

Generated by: LCOV version 1.14