added rog local data
This commit is contained in:
@ -1,11 +1,19 @@
|
||||
import 'dart:io';
|
||||
import 'package:get/get.dart';
|
||||
import 'package:http/http.dart' as http;
|
||||
import 'package:intl/intl.dart';
|
||||
import 'package:rogapp/model/rog.dart';
|
||||
import 'package:rogapp/pages/index/index_controller.dart';
|
||||
import 'package:rogapp/utils/database_helper.dart';
|
||||
import 'package:sqflite/sqlite_api.dart';
|
||||
import 'dart:convert';
|
||||
|
||||
import '../utils/const.dart';
|
||||
|
||||
//
|
||||
// Rog type 0- start 1- checkin 2- goal
|
||||
//
|
||||
|
||||
class ExternalService {
|
||||
static final ExternalService _instance = ExternalService._internal();
|
||||
|
||||
@ -15,35 +23,56 @@ class ExternalService {
|
||||
|
||||
ExternalService._internal();
|
||||
|
||||
String getFormatedTime(DateTime datetime){
|
||||
return DateFormat('yyyy-MM-dd HH:mm:ss').format(datetime);
|
||||
}
|
||||
|
||||
Future<Map<String, dynamic>> StartRogaining() async {
|
||||
Map<String, dynamic> _res = {};
|
||||
|
||||
final IndexController indexController = Get.find<IndexController>();
|
||||
|
||||
|
||||
Map<String, dynamic> _res = {};
|
||||
|
||||
int user_id = indexController.currentUser[0]["user"]["id"];
|
||||
//print("--- Pressed -----");
|
||||
String _team = indexController.currentUser[0]["user"]['team_name'];
|
||||
//print("--- _team : ${_team}-----");
|
||||
String _event_code = indexController.currentUser[0]["user"]["event_code"];
|
||||
|
||||
String url = 'https://natnats.mobilous.com/start_from_rogapp';
|
||||
//print('---- toekn is ${token} -----');
|
||||
final http.Response response = await http.post(
|
||||
Uri.parse(url),
|
||||
headers: <String, String>{
|
||||
'Content-Type': 'application/json; charset=UTF-8',
|
||||
},
|
||||
body: jsonEncode(<String, String>{
|
||||
'team_name': _team,
|
||||
'event_code': _event_code
|
||||
}),
|
||||
);
|
||||
if(indexController.connectionStatusName != "wifi" || indexController.connectionStatusName != "mobile"){
|
||||
DatabaseHelper db = DatabaseHelper.instance;
|
||||
Rog _rog = Rog(
|
||||
id:1,
|
||||
team_name: _team,
|
||||
event_code : _event_code,
|
||||
user_id: user_id,
|
||||
cp_number: -1,
|
||||
checkintime: DateTime.now().toUtc().microsecondsSinceEpoch,
|
||||
image: null,
|
||||
rog_action_type: 0
|
||||
);
|
||||
db.insertRogaining(_rog);
|
||||
}
|
||||
else {
|
||||
String url = 'https://natnats.mobilous.com/start_from_rogapp';
|
||||
//print('---- toekn is ${token} -----');
|
||||
final http.Response response = await http.post(
|
||||
Uri.parse(url),
|
||||
headers: <String, String>{
|
||||
'Content-Type': 'application/json; charset=UTF-8',
|
||||
},
|
||||
body: jsonEncode(<String, String>{
|
||||
'team_name': _team,
|
||||
'event_code': _event_code
|
||||
}),
|
||||
);
|
||||
|
||||
print("---- start rogianing api status ---- ${response.statusCode}");
|
||||
print("---- start rogianing api status ---- ${response.statusCode}");
|
||||
|
||||
if (response.statusCode == 200) {
|
||||
_res = json.decode(utf8.decode(response.bodyBytes));
|
||||
print('----_res : ${_res} ----');
|
||||
if (response.statusCode == 200) {
|
||||
_res = json.decode(utf8.decode(response.bodyBytes));
|
||||
print('----_res : ${_res} ----');
|
||||
}
|
||||
}
|
||||
return _res;
|
||||
}
|
||||
@ -51,56 +80,89 @@ class ExternalService {
|
||||
Future<Map<String, dynamic>> makeCheckpoint(int user_id, String token, String checkin_time, String teamname, int cp, String eventcode, String imageurl) async {
|
||||
Map<String, dynamic> _res = {};
|
||||
String url = 'https://natnats.mobilous.com/checkin_from_rogapp';
|
||||
final IndexController indexController = Get.find<IndexController>();
|
||||
|
||||
if(imageurl != null){
|
||||
String server_url = ConstValues.currentServer();
|
||||
String url1 = "${server_url}/api/checkinimage/";
|
||||
final im1Bytes = File(imageurl!).readAsBytesSync();
|
||||
String im1_64 = base64Encode(im1Bytes);
|
||||
|
||||
final http.Response response = await http.post(
|
||||
Uri.parse(url1),
|
||||
headers: <String, String>{
|
||||
'Content-Type': 'application/json; charset=UTF-8',
|
||||
'Authorization': 'Token ${token}'
|
||||
},
|
||||
// 'id', 'user', 'goalimage', 'goaltime', 'team_name', 'event_code','cp_number'
|
||||
body: jsonEncode(<String, String>{
|
||||
'user' : user_id.toString(),
|
||||
'team_name': teamname,
|
||||
'event_code': eventcode,
|
||||
'checkinimage' : im1_64,
|
||||
'checkintime' : checkin_time,
|
||||
'cp_number' : cp.toString()
|
||||
}),
|
||||
if(indexController.connectionStatusName != "wifi" || indexController.connectionStatusName != "mobile"){
|
||||
DatabaseHelper db = DatabaseHelper.instance;
|
||||
Rog _rog = Rog(
|
||||
id:1,
|
||||
team_name: teamname,
|
||||
event_code : eventcode,
|
||||
user_id: user_id,
|
||||
cp_number: cp,
|
||||
checkintime: DateTime.now().toUtc().microsecondsSinceEpoch,
|
||||
image: imageurl,
|
||||
rog_action_type: 1,
|
||||
);
|
||||
db.insertRogaining(_rog);
|
||||
}
|
||||
else {
|
||||
String server_url = ConstValues.currentServer();
|
||||
String url1 = "${server_url}/api/checkinimage/";
|
||||
final im1Bytes = File(imageurl!).readAsBytesSync();
|
||||
String im1_64 = base64Encode(im1Bytes);
|
||||
|
||||
_res = json.decode(utf8.decode(response.bodyBytes));
|
||||
final http.Response response = await http.post(
|
||||
Uri.parse(url1),
|
||||
headers: <String, String>{
|
||||
'Content-Type': 'application/json; charset=UTF-8',
|
||||
'Authorization': 'Token ${token}'
|
||||
},
|
||||
// 'id', 'user', 'goalimage', 'goaltime', 'team_name', 'event_code','cp_number'
|
||||
body: jsonEncode(<String, String>{
|
||||
'user' : user_id.toString(),
|
||||
'team_name': teamname,
|
||||
'event_code': eventcode,
|
||||
'checkinimage' : im1_64,
|
||||
'checkintime' : checkin_time,
|
||||
'cp_number' : cp.toString()
|
||||
}),
|
||||
);
|
||||
|
||||
print("-----@@@@@ ${_res} -----");
|
||||
_res = json.decode(utf8.decode(response.bodyBytes));
|
||||
|
||||
if(response.statusCode == 201){
|
||||
//print('---- toekn is ${token} -----');
|
||||
final http.Response response2 = await http.post(
|
||||
Uri.parse(url),
|
||||
headers: <String, String>{
|
||||
'Content-Type': 'application/json; charset=UTF-8',
|
||||
},
|
||||
body: jsonEncode(<String, String>{
|
||||
'team_name': teamname,
|
||||
'cp_number': cp.toString(),
|
||||
'event_code': eventcode,
|
||||
'image': _res["checkinimage"].toString().replaceAll('http://localhost:8100', 'http://rogaining.sumasen.net')
|
||||
}),
|
||||
);
|
||||
print("--- checnin response ${response2.statusCode}----");
|
||||
if (response2.statusCode == 200) {
|
||||
_res = json.decode(utf8.decode(response2.bodyBytes));
|
||||
print('----checkin res _res : ${_res} ----');
|
||||
}
|
||||
}
|
||||
print("-----@@@@@ ${_res} -----");
|
||||
|
||||
if(response.statusCode == 201){
|
||||
//print('---- toekn is ${token} -----');
|
||||
final http.Response response2 = await http.post(
|
||||
Uri.parse(url),
|
||||
headers: <String, String>{
|
||||
'Content-Type': 'application/json; charset=UTF-8',
|
||||
},
|
||||
body: jsonEncode(<String, String>{
|
||||
'team_name': teamname,
|
||||
'cp_number': cp.toString(),
|
||||
'event_code': eventcode,
|
||||
'image': _res["checkinimage"].toString().replaceAll('http://localhost:8100', 'http://rogaining.sumasen.net')
|
||||
}),
|
||||
);
|
||||
print("--- checnin response ${response2.statusCode}----");
|
||||
if (response2.statusCode == 200) {
|
||||
_res = json.decode(utf8.decode(response2.bodyBytes));
|
||||
print('----checkin res _res : ${_res} ----');
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else{
|
||||
if(indexController.connectionStatusName != "wifi" || indexController.connectionStatusName != "mobile"){
|
||||
DatabaseHelper db = DatabaseHelper.instance;
|
||||
Rog _rog = Rog(
|
||||
id:1,
|
||||
team_name: teamname,
|
||||
event_code : eventcode,
|
||||
user_id: user_id,
|
||||
cp_number: cp,
|
||||
checkintime: DateTime.now().toUtc().microsecondsSinceEpoch,
|
||||
image: null,
|
||||
rog_action_type: 1,
|
||||
);
|
||||
db.insertRogaining(_rog);
|
||||
}
|
||||
else {
|
||||
final http.Response response3 = await http.post(
|
||||
Uri.parse(url),
|
||||
headers: <String, String>{
|
||||
@ -118,6 +180,7 @@ class ExternalService {
|
||||
_res = json.decode(utf8.decode(response3.bodyBytes));
|
||||
print('----checkin res _res : ${_res} ----');
|
||||
}
|
||||
}
|
||||
}
|
||||
return _res;
|
||||
}
|
||||
@ -125,52 +188,70 @@ class ExternalService {
|
||||
|
||||
Future<Map<String, dynamic>> makeGoal(int user_id, String token, String teamname, String image, String goal_time, String eventcode) async {
|
||||
Map<String, dynamic> _res2 = {};
|
||||
|
||||
String server_url = ConstValues.currentServer();
|
||||
String url1 = "${server_url}/api/goalimage/";
|
||||
final im1Bytes = File(image!).readAsBytesSync();
|
||||
String im1_64 = base64Encode(im1Bytes);
|
||||
|
||||
final http.Response response = await http.post(
|
||||
Uri.parse(url1),
|
||||
headers: <String, String>{
|
||||
'Content-Type': 'application/json; charset=UTF-8',
|
||||
'Authorization': 'Token ${token}'
|
||||
},
|
||||
// 'id', 'user', 'goalimage', 'goaltime', 'team_name', 'event_code','cp_number'
|
||||
body: jsonEncode(<String, String>{
|
||||
'user' : user_id.toString(),
|
||||
'team_name': teamname,
|
||||
'event_code': eventcode,
|
||||
'goaltime' : goal_time,
|
||||
'goalimage' : im1_64,
|
||||
'cp_number' : "-1"
|
||||
}),
|
||||
);
|
||||
final IndexController indexController = Get.find<IndexController>();
|
||||
|
||||
String url = 'https://natnats.mobilous.com/goal_from_rogapp';
|
||||
//print("---response is : ${response.statusCode}----");
|
||||
if (response.statusCode == 201) {
|
||||
Map<String, dynamic> _res = json.decode(utf8.decode(response.bodyBytes));
|
||||
print('----_res : ${_res} ----');
|
||||
print('---- image url ${_res["goalimage"]} ----');
|
||||
final http.Response response2 = await http.post(
|
||||
Uri.parse(url),
|
||||
headers: <String, String>{
|
||||
'Content-Type': 'application/json; charset=UTF-8',
|
||||
},
|
||||
body: jsonEncode(<String, String>{
|
||||
'team_name': teamname,
|
||||
'event_code': eventcode,
|
||||
'goal_time' : goal_time,
|
||||
'image' : _res["goalimage"].toString().replaceAll('http://localhost:8100', 'http://rogaining.sumasen.net')
|
||||
}
|
||||
),
|
||||
if(indexController.connectionStatusName != "wifi" || indexController.connectionStatusName != "mobile"){
|
||||
DatabaseHelper db = DatabaseHelper.instance;
|
||||
Rog _rog = Rog(
|
||||
id:1,
|
||||
team_name: teamname,
|
||||
event_code : eventcode,
|
||||
user_id: user_id,
|
||||
cp_number: -1,
|
||||
checkintime: DateTime.now().toUtc().microsecondsSinceEpoch,
|
||||
image: image,
|
||||
rog_action_type: 1,
|
||||
);
|
||||
db.insertRogaining(_rog);
|
||||
}
|
||||
else{
|
||||
String server_url = ConstValues.currentServer();
|
||||
String url1 = "${server_url}/api/goalimage/";
|
||||
final im1Bytes = File(image!).readAsBytesSync();
|
||||
String im1_64 = base64Encode(im1Bytes);
|
||||
|
||||
final http.Response response = await http.post(
|
||||
Uri.parse(url1),
|
||||
headers: <String, String>{
|
||||
'Content-Type': 'application/json; charset=UTF-8',
|
||||
'Authorization': 'Token ${token}'
|
||||
},
|
||||
// 'id', 'user', 'goalimage', 'goaltime', 'team_name', 'event_code','cp_number'
|
||||
body: jsonEncode(<String, String>{
|
||||
'user' : user_id.toString(),
|
||||
'team_name': teamname,
|
||||
'event_code': eventcode,
|
||||
'goaltime' : goal_time,
|
||||
'goalimage' : im1_64,
|
||||
'cp_number' : "-1"
|
||||
}),
|
||||
);
|
||||
print('----- response2 is ${response2} --------');
|
||||
if (response2.statusCode == 200) {
|
||||
_res2 = json.decode(utf8.decode(response2.bodyBytes));
|
||||
}
|
||||
|
||||
String url = 'https://natnats.mobilous.com/goal_from_rogapp';
|
||||
//print("---response is : ${response.statusCode}----");
|
||||
if (response.statusCode == 201) {
|
||||
Map<String, dynamic> _res = json.decode(utf8.decode(response.bodyBytes));
|
||||
print('----_res : ${_res} ----');
|
||||
print('---- image url ${_res["goalimage"]} ----');
|
||||
final http.Response response2 = await http.post(
|
||||
Uri.parse(url),
|
||||
headers: <String, String>{
|
||||
'Content-Type': 'application/json; charset=UTF-8',
|
||||
},
|
||||
body: jsonEncode(<String, String>{
|
||||
'team_name': teamname,
|
||||
'event_code': eventcode,
|
||||
'goal_time' : goal_time,
|
||||
'image' : _res["goalimage"].toString().replaceAll('http://localhost:8100', 'http://rogaining.sumasen.net')
|
||||
}
|
||||
),
|
||||
);
|
||||
print('----- response2 is ${response2} --------');
|
||||
if (response2.statusCode == 200) {
|
||||
_res2 = json.decode(utf8.decode(response2.bodyBytes));
|
||||
}
|
||||
}
|
||||
}
|
||||
return _res2;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user