Skip to content

Commit

Permalink
wip migration;
Browse files Browse the repository at this point in the history
  • Loading branch information
FlorianPix committed Oct 24, 2023
1 parent 3631a10 commit 92f08b8
Showing 1 changed file with 16 additions and 4 deletions.
20 changes: 16 additions & 4 deletions src/flutter_app/lib/services/admin_service.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
import 'dart:typed_data';

import 'package:climbing_diary/components/common/my_notifications.dart';
import 'package:climbing_diary/interfaces/media/media.dart';
import 'package:climbing_diary/services/cache_service.dart';
import 'package:climbing_diary/services/error_service.dart';
import 'package:climbing_diary/services/media_service.dart';
import '../config/environment.dart';
import 'package:dio/dio.dart';

Expand All @@ -14,6 +18,7 @@ class AdminService {
final sharedPrefLocator = getIt.get<SharedPreferenceHelper>();
final String climbingApiHost = Environment().config.climbingApiHost;
final String mediaApiHost = Environment().config.mediaApiHost;
MediaService mediaService = MediaService();

Future<void> deleteAll() async {
try {
Expand All @@ -39,11 +44,18 @@ class AdminService {
final idUrl = mediumResponse.data!;
String url = idUrl['url'];
// download image
var uri = Uri.https(url);
var response = await http.get(uri);
print('Response status: ${response.statusCode}');
// convert to UInt8List
var uri = Uri.parse(url);
http.Response response = await http.get(uri);
Uint8List image = response.bodyBytes;
// create medium
Media createMedium = Media(
id: medium['id'],
userId: medium['user_id'],
title: medium['title'],
createdAt: DateTime.parse(medium['created_at']).toIso8601String(),
image: image
);
await mediaService.createMedium(createMedium);
}
} catch (e) {
ErrorService.handleConnectionErrors(e);
Expand Down

0 comments on commit 92f08b8

Please sign in to comment.