small case integration
This commit is contained in:
@@ -1,9 +1,14 @@
|
||||
import 'dart:convert';
|
||||
import 'dart:developer';
|
||||
|
||||
import 'package:dio/dio.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:http/http.dart' as http;
|
||||
import 'package:scgateway_flutter_plugin/scgateway_flutter_plugin.dart';
|
||||
|
||||
import '../../Utils/api_urls.dart';
|
||||
import '../../Utils/base_manager.dart';
|
||||
import '../../data/network/network_api_services.dart';
|
||||
import '../../model/SmallCaseModel/broker_account_model.dart';
|
||||
|
||||
// void openDashboardPage(BuildContext context) {
|
||||
@@ -19,83 +24,142 @@ import '../../model/SmallCaseModel/broker_account_model.dart';
|
||||
// }
|
||||
|
||||
//broker account table
|
||||
//fetch broker accounts
|
||||
Future<List<BrokerAccountModel>> fetchBrokerAccounts() async {
|
||||
final response = await http.Client()
|
||||
.get(Uri.parse('${ApiUrls.pieBase}api/get_broker_account_data'));
|
||||
final parsed = jsonDecode(response.body);
|
||||
return parsed
|
||||
.map<BrokerAccountModel>((json) => BrokerAccountModel.fromJson(json))
|
||||
.toList();
|
||||
}
|
||||
|
||||
//delete broker account
|
||||
Future<bool> deleteBrokerAccount(int id) async {
|
||||
final response = await http.Client()
|
||||
.get(Uri.parse('${ApiUrls.pieBase}api/delete_brokerage_account/$id'));
|
||||
.get(Uri.parse('${ApiUrls.base}api/delete_brokerage_account/$id'));
|
||||
if (response.statusCode == 200) return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
//post broker account
|
||||
Future<bool> postBrokerAccount({
|
||||
required String userId,
|
||||
required String brokerName,
|
||||
required String authToken,
|
||||
required String txnId,
|
||||
}) async {
|
||||
var response = await http.post(
|
||||
Uri.parse('${ApiUrls.pieBase}api/add_broker_account'),
|
||||
body: <String, String>{
|
||||
"user_id": userId,
|
||||
final response = await NetworkApiServices().postApi(
|
||||
FormData.fromMap({
|
||||
"broker_name": brokerName,
|
||||
"auth_token": authToken,
|
||||
"transaction_id": txnId,
|
||||
},
|
||||
}),
|
||||
'${ApiUrls.base}add-broker-account',
|
||||
);
|
||||
if (response.statusCode == 200) return true;
|
||||
|
||||
if (response.status == ResponseStatus.SUCCESS) {
|
||||
Map<String, dynamic> responseData =
|
||||
Map<String, dynamic>.from(response.data);
|
||||
if (responseData['status'] == "success") {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
Future<String> fetchAuthToken() async {
|
||||
var response = await http.get(
|
||||
Uri.parse(
|
||||
'${ApiUrls.pieBase}api/get_small_case_auth_token/',
|
||||
),
|
||||
//fetch broker accounts
|
||||
Future<List<Data>> fetchBrokerAccounts() async {
|
||||
final response = await NetworkApiServices().getApi(
|
||||
'${ApiUrls.base}get-broker-account-data',
|
||||
);
|
||||
return jsonDecode(response.body)['data'];
|
||||
// log(response.data.toString());
|
||||
if (response.status == ResponseStatus.SUCCESS) {
|
||||
Map<String, dynamic> responseData =
|
||||
Map<String, dynamic>.from(response.data);
|
||||
if (responseData['status'] == "success") {
|
||||
BrokerAccountModel brokerAccountModel =
|
||||
BrokerAccountModel.fromJson(responseData);
|
||||
|
||||
return brokerAccountModel.data!;
|
||||
} else {
|
||||
return [];
|
||||
}
|
||||
}
|
||||
return [];
|
||||
}
|
||||
|
||||
Future<String> fetchAuthToken() async {
|
||||
final response = await NetworkApiServices().getApi(
|
||||
'${ApiUrls.base}get-small-case-auth-token',
|
||||
);
|
||||
// log(response.data.toString());
|
||||
if (response.status == ResponseStatus.SUCCESS) {
|
||||
Map<String, dynamic> responseData =
|
||||
Map<String, dynamic>.from(response.data);
|
||||
if (responseData['status'] == "success") {
|
||||
return response.data['data'];
|
||||
} else {
|
||||
return "Failed";
|
||||
}
|
||||
}
|
||||
return "Failed";
|
||||
}
|
||||
|
||||
Future<String> fetchBrokerConnectTxnId({required String authToken}) async {
|
||||
var response = await http.get(
|
||||
Uri.parse(
|
||||
'${ApiUrls.pieBase}api/get_small_case_broker_connect_transaction/$authToken',
|
||||
),
|
||||
final response = await NetworkApiServices().postApi(
|
||||
FormData.fromMap({"auth_token": authToken}),
|
||||
'${ApiUrls.base}get-transaction-id',
|
||||
);
|
||||
return jsonDecode(response.body)['data']['transactionId'];
|
||||
log(response.data.toString());
|
||||
if (response.status == ResponseStatus.SUCCESS) {
|
||||
Map<String, dynamic> responseData =
|
||||
Map<String, dynamic>.from(response.data);
|
||||
if (responseData['status'] == "success") {
|
||||
return response.data['data']["data"]
|
||||
['transactionId']; // jsonDecode(response.body)
|
||||
} else {
|
||||
return "Failed";
|
||||
}
|
||||
}
|
||||
return "Failed";
|
||||
}
|
||||
|
||||
Future<http.Response> fetchHoldingsImportTxnId(String authToken) async {
|
||||
var response = await http.get(
|
||||
Uri.parse(
|
||||
'${ApiUrls.pieBase}api/get_small_case_holding_import_transaction_id/$authToken',
|
||||
),
|
||||
Future<String> fetchHoldingsImportTxnId(String authToken) async {
|
||||
log(authToken);
|
||||
final response = await NetworkApiServices().postApi(
|
||||
FormData.fromMap({"auth_token": authToken}),
|
||||
'${ApiUrls.base}create-transaction-holdings-import',
|
||||
);
|
||||
return response;
|
||||
log(response.data.toString());
|
||||
if (response.status == ResponseStatus.SUCCESS) {
|
||||
Map<String, dynamic> responseData =
|
||||
Map<String, dynamic>.from(response.data);
|
||||
if (responseData['status'] == "success" &&
|
||||
!responseData.toString().contains(
|
||||
"{status: error, status_code: 500, message: Something went wrong.}")) {
|
||||
return response.data['data']["data"]
|
||||
['transactionId']; // jsonDecode(response.body)
|
||||
} else {
|
||||
return "Failed";
|
||||
}
|
||||
}
|
||||
return "Failed";
|
||||
}
|
||||
|
||||
Future<Map<String, dynamic>> fetchHoldings(String authToken) async {
|
||||
var response = await http.get(
|
||||
Uri.parse(
|
||||
'${ApiUrls.pieBase}api/fetch_small_case_holding/$authToken',
|
||||
),
|
||||
final response = await NetworkApiServices().postApi(
|
||||
FormData.fromMap({"auth_token": authToken}),
|
||||
'${ApiUrls.base}fetch-holdings',
|
||||
);
|
||||
return jsonDecode(response.body)['data'];
|
||||
log(response.data.toString());
|
||||
if (response.status == ResponseStatus.SUCCESS) {
|
||||
Map<String, dynamic> responseData =
|
||||
Map<String, dynamic>.from(response.data);
|
||||
if (responseData['status'] == "success") {
|
||||
return responseData;
|
||||
} else {
|
||||
return {};
|
||||
}
|
||||
}
|
||||
return {};
|
||||
}
|
||||
|
||||
Future<String> fetchStocksOrderTxnId(String authToken, String body) async {
|
||||
var response = await http.post(Uri.parse(
|
||||
'${ApiUrls.pieBase}api/create_post_transaction_stock_order?body=$body&auth_token=$authToken'));
|
||||
'${ApiUrls.base}api/create_post_transaction_stock_order?body=$body&auth_token=$authToken'));
|
||||
var txnId = jsonDecode(response.body)['data']['transactionId'];
|
||||
return txnId;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user