fix: removed useless dependencies
This commit is contained in:
parent
981dce5bfe
commit
48bcf0b1f8
10 changed files with 5 additions and 37 deletions
|
|
@ -1,6 +1,5 @@
|
|||
import 'dart:convert';
|
||||
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter_secure_storage/flutter_secure_storage.dart';
|
||||
import 'package:http/http.dart';
|
||||
import 'package:seshat/config/constants.dart';
|
||||
|
|
@ -50,17 +49,13 @@ class ApiClient {
|
|||
Uri.parse("https://$apiBasePath/book/ean/$ean"),
|
||||
headers: headers,
|
||||
);
|
||||
debugPrint("\n\n\n\nGOT : ${response.statusCode}\n\n\n\n");
|
||||
if (response.statusCode == 200) {
|
||||
debugPrint("\n\n\n\nWITH : ${response.body}\n\n\n\n");
|
||||
final json = jsonDecode(response.body);
|
||||
return Result.ok(Book.fromJSON(json));
|
||||
} else {
|
||||
debugPrintStack();
|
||||
return Result.error(Exception("The book was not found"));
|
||||
}
|
||||
} catch (e, stackTrace) {
|
||||
debugPrintStack(stackTrace: stackTrace);
|
||||
} catch (e) {
|
||||
return Result.error(Exception("API $e"));
|
||||
} finally {
|
||||
client.close();
|
||||
|
|
@ -88,7 +83,6 @@ class ApiClient {
|
|||
"owner_id": owner.id,
|
||||
"price": price,
|
||||
});
|
||||
debugPrint("\n\n\n\nSENDING : ${body}\n\n\n\n");
|
||||
final response = await client.post(
|
||||
Uri.parse("https://$apiBasePath/book_instance"),
|
||||
headers: headers,
|
||||
|
|
@ -96,15 +90,13 @@ class ApiClient {
|
|||
);
|
||||
if (response.statusCode == 201) {
|
||||
final json = jsonDecode(response.body);
|
||||
debugPrint("\n\n\n\nRECEIVED : ${json}\n\n\n\n");
|
||||
return Result.ok(BookInstance.fromJSON(json));
|
||||
} else if (response.statusCode == 403) {
|
||||
return Result.error(Exception("You don't own that book instance"));
|
||||
} else {
|
||||
return Result.error(Exception("Something wrong happened"));
|
||||
}
|
||||
} catch (e, stack) {
|
||||
debugPrintStack(stackTrace: stack);
|
||||
} catch (e) {
|
||||
return Result.error(Exception(e));
|
||||
} finally {
|
||||
client.close();
|
||||
|
|
|
|||
|
|
@ -1,6 +1,5 @@
|
|||
import 'dart:convert';
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_secure_storage/flutter_secure_storage.dart';
|
||||
import 'package:seshat/config/constants.dart';
|
||||
import 'package:seshat/utils/result.dart';
|
||||
|
|
@ -61,7 +60,7 @@ class AuthClient {
|
|||
} else {
|
||||
return Result.error(Exception("Token creation error"));
|
||||
}
|
||||
} catch (e, stackTrace) {
|
||||
} catch (e) {
|
||||
return Result.error(Exception(e));
|
||||
} finally {
|
||||
client.close();
|
||||
|
|
|
|||
|
|
@ -1,7 +1,6 @@
|
|||
import 'dart:async';
|
||||
import 'dart:convert';
|
||||
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:flutter_secure_storage/flutter_secure_storage.dart';
|
||||
import 'package:rxdart/rxdart.dart';
|
||||
import 'package:seshat/config/constants.dart';
|
||||
|
|
@ -27,32 +26,24 @@ class WebsocketClient {
|
|||
|
||||
Future<void> connect() async {
|
||||
await _initStore();
|
||||
debugPrint("\n\n\n\nWEBSOCKET STORE IS READY\n\n\n\n");
|
||||
if (_channel != null) return;
|
||||
|
||||
debugPrint("\n\n\n\nWEBSOCKET WILL CONNECT\n\n\n\n");
|
||||
_channel = WebSocketChannel.connect(Uri.parse("wss://$apiBasePath/ws"));
|
||||
debugPrint("\n\n\n\nWEBSOCKET IS CONNECTING\n\n\n\n");
|
||||
|
||||
await _channel!.ready;
|
||||
debugPrint("\n\n\n\nWEBSOCKET IS READY\n\n\n\n");
|
||||
var token = await _secureStorage!.read(key: "token");
|
||||
|
||||
_channel!.sink.add(jsonEncode({"token": "$token"}));
|
||||
_channel!.stream.listen((message) {
|
||||
debugPrint("\n\n\n\n[1] Received : $message\n\n\n\n");
|
||||
_baseController.add(message);
|
||||
});
|
||||
var data = await _baseController.stream.first;
|
||||
debugPrint("\n\n\n\n$data\n\n\n\n");
|
||||
var result = jsonDecode(data);
|
||||
|
||||
if (result["type"] == "auth_success") {
|
||||
debugPrint("\n\n\n\nSUCCESS !\n\n\n\n");
|
||||
sub = _baseController.stream.listen(
|
||||
(message) {
|
||||
final Map<String, dynamic> data = jsonDecode(message);
|
||||
debugPrint("\n\n\n\n[2] Transfered : $message\n\n\n\n");
|
||||
switch (data["type"]) {
|
||||
case "new_owner":
|
||||
final owner = Owner.fromJSON(data["data"]);
|
||||
|
|
|
|||
Reference in a new issue