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

6
.vscode/launch.json vendored
View File

@ -20,6 +20,12 @@
"request": "launch",
"type": "dart",
"flutterMode": "release"
},
{
"name": "Flutter (lib/main.dart)",
"type": "dart",
"request": "launch",
"program": "lib/main.dart"
}
]
}

View File

@ -1,10 +1,14 @@
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:intl/intl.dart';
import 'package:rogapp/pages/destination/destination_controller.dart';
import 'package:rogapp/pages/index/index_controller.dart';
import 'package:rogapp/services/external_service.dart';
class CameraPage extends StatelessWidget {
CameraPage({Key? key}) : super(key: key);
DestinationController destinationController = Get.find<DestinationController>();
IndexController indexController = Get.find<IndexController>();
ImageProvider getFinishImage(){
if(destinationController.photos.isNotEmpty){
@ -62,7 +66,27 @@ class CameraPage extends StatelessWidget {
primary: Colors.red
),
onPressed: (){
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"];
//print("--- _event_code : ${_event_code}-----");
String _token = indexController.currentUser[0]["token"];
//print("--- _token : ${_token}-----");
DateTime now = DateTime.now();
String formattedDate = DateFormat('yyyy-MM-dd HH:mm:ss').format(now);
ExternalService().makeGoal(user_id, _token, _team, destinationController.photos[0].path, formattedDate, _event_code).then((value){
print("---called ext api ${value['status']} ------");
if(value['status'] == 'OK'){
Get.back();
Get.snackbar("goal_saved", "goal_added_successfuly");
}
else{
Get.snackbar("goal_not_added", "please_try_again");
}
});
},
child: Text("finish_goal".tr)
):

View File

@ -16,6 +16,7 @@ import 'package:rogapp/pages/index/index_controller.dart';
import 'package:rogapp/routes/app_pages.dart';
import 'package:rogapp/services/action_service.dart';
import 'package:rogapp/services/destination_service.dart';
import 'package:rogapp/services/external_service.dart';
import 'package:rogapp/services/maxtrix_service.dart';
import 'package:rogapp/services/reacking_service.dart';
import 'package:rogapp/utils/database_helper.dart';
@ -72,7 +73,6 @@ class DestinationController extends GetxController {
}
else{
//finish rogiain
//is_in_rog.value = true;
if (rogaining_counted.value && distance <=250){
Get.toNamed(AppPages.CAMERA_PAGE);
}
@ -130,6 +130,8 @@ class DestinationController extends GetxController {
for(final d in destinations){
print("-----loc_id- ${d.location_id}----");
if(!checking_in)
{
checking_in = true;
@ -142,6 +144,10 @@ class DestinationController extends GetxController {
double rad = value!.checkin_radious ?? double.infinity;
bool auto_checkin = value.auto_checkin == 0 ? false : true;
print("-----rogaining_counted---${rogaining_counted.value}-----");
print("-----is_in_rog---${is_in_rog}-----");
print("-----dist is ---${dist}-----");
if(d.cp != -1 && is_in_rog == true){
rogaining_counted.value == true;
}
@ -215,24 +221,25 @@ class DestinationController extends GetxController {
}
void makeCheckin(Destination destination, bool action) async {
print("@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ ressssss ${action}@@@@@@@@@@@");
// print("@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ ressssss ${action}@@@@@@@@@@@");
DatabaseHelper db = DatabaseHelper.instance;
int res = await db.updateAction(destination, action);
List<Destination> ddd = await db.getDestinationByLatLon(destination.lat!, destination.lon!);
print("@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ ddddd ${ddd[0].checkedin} @@@@@@@@@@@");
// print("@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ ddddd ${ddd[0].checkedin} @@@@@@@@@@@");
print("@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ ressssss ${res}@@@@@@@@@@@");
// print("@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ ressssss ${res}@@@@@@@@@@@");
PopulateDestinations();
print("@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ after populating ${res} @@@@@@@@@@@");
print("---- database update resulr ------ res : ${res}-------");
// print("@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ after populating ${res} @@@@@@@@@@@");
// print("---- database update resulr ------ res : ${res}-------");
/// post to NATNAT
if(indexController.currentUser.length > 0){
String cp_num = destination.cp.toString();
String team_name = indexController.currentUser[0]['user']['group'];
ActionService.postCheckin(cp_num, team_name).then((value){
print('------- NATNAT RES ${value} ------------');
int cp_num = int.parse(destination.cp!.toString());
String _team = indexController.currentUser[0]["user"]["team_name"];
String _event_code = indexController.currentUser[0]["user"]["event_code"];
ExternalService().makeCheckpoint(_team, cp_num, _event_code).then((value){
print("------Ext service check point ${value} ------");
});
}
}

View File

@ -12,6 +12,7 @@ import 'package:rogapp/pages/destination_map/destination_map_page.dart';
import 'package:rogapp/pages/drawer/drawer_page.dart';
import 'package:rogapp/pages/index/index_controller.dart';
import 'package:rogapp/routes/app_pages.dart';
import 'package:rogapp/services/external_service.dart';
import 'package:rogapp/widgets/destination_widget.dart';
import 'package:timeline_tile/timeline_tile.dart';
@ -159,13 +160,14 @@ class DestnationPage extends StatelessWidget {
automaticallyImplyLeading: true,
title: Text("app_title".tr),
actions: [
// TextButton(
// onPressed: (){
// //destinationController.openCamera(context);
// Get.toNamed(AppPages.CAMERA_PAGE);
// },
// child: Icon(Icons.ac_unit),
// ),
TextButton(
onPressed: (){
//ExternalService().StartRogaining('team_name', "2222");
//destinationController.openCamera(context);
Get.toNamed(AppPages.CAMERA_PAGE);
},
child: Icon(Icons.ac_unit),
),
Obx(() =>
ToggleButtons(
disabledColor: Colors.grey.shade200,

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}';

View File

@ -8,6 +8,6 @@ class ConstValues{
static const dev_home_ip_server = "http://172.20.10.9:8100";
static String currentServer(){
return dev_server;
return server_uri;
}
}

View File

@ -55,6 +55,10 @@ class StringValues extends Translations{
'finishing_rogaining' : 'Finishing Rogaining',
'take_photo of the clock' : 'Take photo of the clock',
'finish_goal': 'finish Goal',
'goal_saved': "Goal Saved",
'goal_added_successfuly' : 'Goal added successfully',
'goal_not_added' : 'Goal not added',
'please_try_again' : 'Please try again'
},
'ja_JP': {
'drawer_title':'ロゲイニング参加者はログイン するとチェックポイントが参照 できます',
@ -110,6 +114,10 @@ class StringValues extends Translations{
'finishing_rogaining' : 'ロゲイニングを終えて',
'take_photo of the clock' : '時計の写真を撮る',
'finish_goal': 'フィニッシュゴール',
'goal_saved': "目標を保存しました",
'goal_added_successfuly' : '目標が正常に追加されました',
'goal_not_added' : '目標が追加されていません',
'please_try_again' : 'もう一度お試しください'
},
};
}

View File

@ -96,7 +96,6 @@ class BottomSheetNew extends GetView<BottomSheetController> {
@override
Widget build(BuildContext context) {
return indexController.rog_mode == 0 ? detailsSheet(context) : destinationSheet(context);
}

View File

@ -67,7 +67,7 @@ class ListWidget extends StatelessWidget {
leading: getImage(index),
title: indexController.locations[0].collection[index].properties!['location_name'] != null ? Text(indexController.locations[0].collection[index].properties!['location_name'].toString()) : Text(""),
subtitle: indexController.locations[0].collection[index].properties!['category'] != null ? Text(indexController.locations[0].collection[index].properties!['category']) : Text(""),
trailing: Text(indexController.locations[0].collection[index].properties!['sub_loc_id'] ),
trailing: indexController.locations[0].collection[index].properties!['sub_loc_id'] != null ? Text(indexController.locations[0].collection[index].properties!['sub_loc_id']) : Text(""),
),
);
},

View File

@ -472,7 +472,7 @@ packages:
source: hosted
version: "2.6.1"
intl:
dependency: transitive
dependency: "direct main"
description:
name: intl
url: "https://pub.dartlang.org"

View File

@ -70,6 +70,7 @@ dependencies:
rename: ^2.0.1
circular_menu: ^2.0.1
camera_camera: ^3.0.0-dev
intl: ^0.17.0
flutter_icons:
android: true