update to external apis

This commit is contained in:
Mohamed Nouffer
2022-10-19 08:53:17 +05:30
parent 8e30ee6ba7
commit 2d9f7a9633
13 changed files with 209 additions and 50 deletions

View File

@ -5,27 +5,6 @@ import 'package:rogapp/utils/const.dart';
class ActionService{
static Future<Map<String, dynamic>> postCheckin(String cp_num, String team_name) async{
Map<String, dynamic> checkin_res = {};
String url = 'https://natnats.mobilous.com/post_from_rogapp_ogaki';
//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_name,
'cp_number': cp_num.toString()
}),
);
if (response.statusCode == 200) {
checkin_res = json.decode(utf8.decode(response.bodyBytes));
}
return checkin_res;
}
static Future<Map<String, dynamic>> makeAction(int user_id, int location_id, bool wanttogo, bool like, bool checkin) async {
print("----- action is ---- ${like}-- ${wanttogo}-- ${checkin}");
Map<String, dynamic> cats = {};

View File

@ -0,0 +1,133 @@
import 'dart:io';
import 'package:flutter/foundation.dart';
import 'package:http/http.dart' as http;
import 'dart:convert';
import '../utils/const.dart';
class ExternalService {
static final ExternalService _instance = ExternalService._internal();
factory ExternalService(){
return _instance;
}
ExternalService._internal();
Future<Map<String, dynamic>> StartRogaining(String teamname, String eventcode) async {
Map<String, dynamic> _res = {};
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': teamname,
'event_code': eventcode
}),
);
if (response.statusCode == 200) {
_res = json.decode(utf8.decode(response.bodyBytes));
print('----_res : ${_res} ----');
}
return _res;
}
Future<Map<String, dynamic>> makeCheckpoint(String teamname, int cp, String eventcode) async {
Map<String, dynamic> _res = {};
String url = 'https://natnats.mobilous.com/checkin_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': teamname,
'cp_number': cp.toString(),
'event_code': eventcode
}),
);
if (response.statusCode == 200) {
_res = json.decode(utf8.decode(response.bodyBytes));
print('----_res : ${_res} ----');
}
return _res;
}
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"
}),
);
String url = 'https://natnats.mobilous.com/start_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"]
}
),
);
print('----- response2 is ${response2} --------');
if (response2.statusCode == 200) {
_res2 = json.decode(utf8.decode(response2.bodyBytes));
}
}
return _res2;
}
static Future<Map<String, dynamic>> usersEventCode(String teamcode, String password) async {
Map<String, dynamic> _res = {};
String url = "https://natnats.mobilous.com/check_event_code?zekken_number=${teamcode}&password=${password}";
print("url is ------ ${url}");
final http.Response response = await http.get(
Uri.parse(url),
headers: <String, String>{
'Content-Type': 'application/json; charset=UTF-8',
}
);
if (response.statusCode == 200) {
_res = json.decode(utf8.decode(response.bodyBytes));
}
return _res;
}
}

View File

@ -44,7 +44,7 @@ class LocationService{
bool _rog = indexController.currentUser[0]['user']['is_rogaining'];
String r = _rog == true ? 'True': 'False';
var grp = indexController.currentUser[0]['user']['group'];
url = '${server_url}/api/inperf/?rog=${r}&perf=' + perfecture + '&cat=' + cat + "&grp=${grp}";
url = '${server_url}/api/inperf/?rog=${r}&perf=' + perfecture + '&cat=' + cat;
}
else {
url = '${server_url}/api/inperf/?perf=' + perfecture + '&cat=' + cat;
@ -55,7 +55,7 @@ class LocationService{
bool _rog = indexController.currentUser[0]['user']['is_rogaining'];
String r = _rog == true ? 'True': 'False';
var grp = indexController.currentUser[0]['user']['group'];
url = '${server_url}/api/inperf/?rog=${r}&perf=' + perfecture + "&grp=${grp}";
url = '${server_url}/api/inperf/?rog=${r}&perf=' + perfecture;
}
else {
url = '${server_url}/api/inperf/?perf=' + perfecture;
@ -86,7 +86,7 @@ class LocationService{
bool _rog = indexController.currentUser[0]['user']['is_rogaining'];
String r = _rog == true ? 'True': 'False';
var grp = indexController.currentUser[0]['user']['group'];
url = '${server_url}/api/insubperf?rog=${r}&subperf=' + subperfecture + '&cat=' + cat + "&grp=${grp}";
url = '${server_url}/api/insubperf?rog=${r}&subperf=' + subperfecture + '&cat=' + cat;
}
else{
url = '${server_url}/api/insubperf?subperf=' + subperfecture + '&cat=' + cat;
@ -97,7 +97,7 @@ class LocationService{
bool _rog = indexController.currentUser[0]['user']['is_rogaining'];
String r = _rog == true ? 'True': 'False';
var grp = indexController.currentUser[0]['user']['group'];
url = '${server_url}/api/insubperf?rog=${r}&subperf=' + subperfecture + "&grp=${grp}";
url = '${server_url}/api/insubperf?rog=${r}&subperf=' + subperfecture;
}
else{
url = '${server_url}/api/insubperf?subperf=' + subperfecture;
@ -129,7 +129,7 @@ class LocationService{
bool _rog = indexController.currentUser[0]['user']['is_rogaining'];
String r = _rog == true ? 'True': 'False';
var grp = indexController.currentUser[0]['user']['group'];
url = '${server_url}/api/inbound?rog=${r}&ln1=${lon1}&la1=${lat1}&ln2=${lon2}&la2=${lat2}&ln3=${lon3}&la3=${lat3}&ln4=${lon4}&la4=${lat4}' + '&cat=' + cat + "&grp=${grp}";
url = '${server_url}/api/inbound?rog=${r}&ln1=${lon1}&la1=${lat1}&ln2=${lon2}&la2=${lat2}&ln3=${lon3}&la3=${lat3}&ln4=${lon4}&la4=${lat4}' + '&cat=' + cat;
}
else{
url = '${server_url}/api/inbound?ln1=${lon1}&la1=${lat1}&ln2=${lon2}&la2=${lat2}&ln3=${lon3}&la3=${lat3}&ln4=${lon4}&la4=${lat4}' + '&cat=' + cat;
@ -141,7 +141,7 @@ class LocationService{
String r = _rog == true ? 'True': 'False';
var grp = indexController.currentUser[0]['user']['group'];
print("-------- requested user group ${grp} -------------");
url = '${server_url}/api/inbound?rog=${r}&ln1=${lon1}&la1=${lat1}&ln2=${lon2}&la2=${lat2}&ln3=${lon3}&la3=${lat3}&ln4=${lon4}&la4=${lat4}' + '&grp=${grp}';
url = '${server_url}/api/inbound?rog=${r}&ln1=${lon1}&la1=${lat1}&ln2=${lon2}&la2=${lat2}&ln3=${lon3}&la3=${lat3}&ln4=${lon4}&la4=${lat4}';
}
else{
url = '${server_url}/api/inbound?ln1=${lon1}&la1=${lat1}&ln2=${lon2}&la2=${lat2}&ln3=${lon3}&la3=${lat3}&ln4=${lon4}&la4=${lat4}';
@ -184,7 +184,7 @@ class LocationService{
bool _rog = indexController.currentUser[0]['user']['is_rogaining'];
String r = _rog == true ? 'True': 'False';
var grp = indexController.currentUser[0]['user']['group'];
url = '${server_url}/api/custom_area/?rog=${r}&&cat=' + cat + "&grp=${grp}";
url = '${server_url}/api/custom_area/?rog=${r}&&cat=' + cat;
}
else{
url = '${server_url}/api/custom_area/?&cat=' + cat;
@ -195,7 +195,7 @@ class LocationService{
bool _rog = indexController.currentUser[0]['user']['is_rogaining'];
String r = _rog == true ? 'True': 'False';
var grp = indexController.currentUser[0]['user']['group'];
url = '${server_url}/api/customarea?rog=${r}&name=${name}' + "&grp=${grp}";
url = '${server_url}/api/customarea?rog=${r}&name=${name}';
}
else{
url = '${server_url}/api/customarea?name=${name}';