feat(App): update Finlytic Flutter app UI and blocs
This commit is contained in:
@@ -0,0 +1,43 @@
|
||||
import 'dart:async';
|
||||
import 'package:finlytic_app/core/network/api_client.dart';
|
||||
import 'package:finlytic_app/features/trades/models/trade_model.dart';
|
||||
import 'package:finlytic_app/features/trades/models/trade_acceptance_dto.dart';
|
||||
|
||||
class TradeRepository {
|
||||
final ApiClient apiClient;
|
||||
|
||||
TradeRepository({required this.apiClient});
|
||||
|
||||
Future<List<TradeModel>> fetchTrades({String? isin, String? status}) async {
|
||||
try {
|
||||
final queryParams = <String, dynamic>{};
|
||||
if (isin != null && isin.isNotEmpty) queryParams['isin'] = isin;
|
||||
if (status != null && status.isNotEmpty) queryParams['status'] = status;
|
||||
|
||||
final response = await apiClient.get('/api/v1/trades', queryParameters: queryParams);
|
||||
|
||||
if (response.statusCode == 200 && response.data != null) {
|
||||
final List<dynamic> data = response.data;
|
||||
return data.map((json) => TradeModel.fromJson(json)).toList();
|
||||
}
|
||||
return [];
|
||||
} catch (e) {
|
||||
print('Error fetching trades: $e');
|
||||
throw Exception('Trades konnten nicht geladen werden');
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> acceptTrade(TradeAcceptanceDto dto) async {
|
||||
final response = await apiClient.post('/api/v1/user/trades/accept', data: dto.toJson());
|
||||
if (response.statusCode != 200) {
|
||||
throw Exception('Trade konnte nicht akzeptiert werden');
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> closeTrade(String id) async {
|
||||
final response = await apiClient.post('/api/v1/user/trades/$id/close');
|
||||
if (response.statusCode != 200) {
|
||||
throw Exception('Trade konnte nicht geschlossen werden');
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user