temporary update
This commit is contained in:
@ -1,6 +1,8 @@
|
||||
import 'dart:io';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:get/get.dart';
|
||||
import 'package:gifunavi/pages/entry/entry_controller.dart';
|
||||
import 'package:gifunavi/services/api_service.dart';
|
||||
import 'package:http/http.dart' as http;
|
||||
import 'package:intl/intl.dart';
|
||||
import 'package:gifunavi/model/rog.dart';
|
||||
@ -33,6 +35,8 @@ class ExternalService {
|
||||
Future<Map<String, dynamic>> startRogaining() async {
|
||||
final IndexController indexController = Get.find<IndexController>();
|
||||
//final TeamController teamController = Get.find<TeamController>();
|
||||
final ApiService apiService = Get.find<ApiService>();
|
||||
final EntryController entryController = Get.find<EntryController>();
|
||||
|
||||
debugPrint("== startRogaining ==");
|
||||
|
||||
@ -68,23 +72,42 @@ class ExternalService {
|
||||
} else {
|
||||
debugPrint("== startRogaining processing==");
|
||||
|
||||
String serverUrl = ConstValues.currentServer();
|
||||
String url = '$serverUrl/gifuroge/start_from_rogapp';
|
||||
print('++++++++$url');
|
||||
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': eventCode}),
|
||||
);
|
||||
try {
|
||||
// 新しい API 呼び出しを使用
|
||||
final updatedEntry = await apiService.updateEntryStatus(
|
||||
entryController.currentEntry.value!.id!,
|
||||
true, // hasParticipated を true に設定
|
||||
false // hasGoaled は変更しない
|
||||
);
|
||||
|
||||
print("---- start rogianing api status ---- ${response.statusCode}");
|
||||
// start_rogaining を本サーバーに送る。 TODO
|
||||
// // 'has_participated': true ... Server 側の修正が必要 TODO
|
||||
|
||||
if (response.statusCode == 200) {
|
||||
res = json.decode(utf8.decode(response.bodyBytes));
|
||||
//print('----_res : $res ----');
|
||||
|
||||
String serverUrl = ConstValues.currentServer();
|
||||
String url = '$serverUrl/gifuroge/start_from_rogapp';
|
||||
//print('++++++++$url');
|
||||
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': eventCode}),
|
||||
// 'has_participated': true ... Server 側の修正が必要 TODO
|
||||
);
|
||||
|
||||
print("---- start rogianing api status ---- ${response.statusCode}");
|
||||
|
||||
if (response.statusCode == 200) {
|
||||
res = json.decode(utf8.decode(response.bodyBytes));
|
||||
//print('----_res : $res ----');
|
||||
// ローカルのユーザーデータを更新
|
||||
indexController.updateUserParticipationStatus(true);
|
||||
}
|
||||
}catch (e) {
|
||||
print('Error in startRogaining: $e');
|
||||
Get.snackbar('エラー', 'ロゲイニングの開始に失敗しました');
|
||||
}
|
||||
}
|
||||
return res;
|
||||
@ -226,6 +249,8 @@ class ExternalService {
|
||||
final IndexController indexController = Get.find<IndexController>();
|
||||
final DestinationController destinationController =
|
||||
Get.find<DestinationController>();
|
||||
final ApiService apiService = Get.find<ApiService>();
|
||||
final EntryController entryController = Get.find<EntryController>();
|
||||
|
||||
// チームIDを取得
|
||||
|
||||
@ -253,65 +278,83 @@ class ExternalService {
|
||||
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': userId.toString(), //userId.toString(),
|
||||
'team_name': teamname,
|
||||
'event_code': eventcode,
|
||||
'goaltime': goalTime,
|
||||
'goalimage': im1_64,
|
||||
'cp_number': "-1"
|
||||
}),
|
||||
);
|
||||
try {
|
||||
// 新しい API呼び出しを使用
|
||||
final updatedEntry = await apiService.updateEntryStatus(
|
||||
entryController.currentEntry.value!.id!,
|
||||
true, // hasParticipated を true に設定
|
||||
true // hasGoaled を true に設定
|
||||
);
|
||||
|
||||
//String serverUrl = ConstValues.currentServer();
|
||||
String url = '$serverUrl/gifuroge/goal_from_rogapp';
|
||||
//print('++++++++$url');
|
||||
if (response.statusCode == 201) {
|
||||
try {
|
||||
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>{
|
||||
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': userId.toString(), //userId.toString(),
|
||||
'team_name': teamname,
|
||||
'event_code': eventcode,
|
||||
'goaltime': goalTime,
|
||||
'goalimage': im1_64,
|
||||
'cp_number': "-1"
|
||||
}),
|
||||
);
|
||||
|
||||
//String serverUrl = ConstValues.currentServer();
|
||||
String url = '$serverUrl/gifuroge/goal_from_rogapp';
|
||||
//print('++++++++$url');
|
||||
if (response.statusCode == 201) {
|
||||
try {
|
||||
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': goalTime,
|
||||
'image': res["goalimage"].toString().replaceAll(
|
||||
'http://localhost:8100', serverUrl)
|
||||
// 'has_goaled': true ... サーバー側の修正が必要 TODO
|
||||
//'http://rogaining.sumasen.net')
|
||||
}),
|
||||
);
|
||||
String rec = jsonEncode(<String, String>{
|
||||
'team_name': teamname,
|
||||
'event_code': eventcode,
|
||||
'goal_time': goalTime,
|
||||
'image': res["goalimage"].toString().replaceAll(
|
||||
'http://localhost:8100', serverUrl)
|
||||
'image': res["goalimage"]
|
||||
.toString()
|
||||
.replaceAll('http://localhost:8100', serverUrl)
|
||||
//'http://rogaining.sumasen.net')
|
||||
}),
|
||||
);
|
||||
String rec = jsonEncode(<String, String>{
|
||||
'team_name': teamname,
|
||||
'event_code': eventcode,
|
||||
'goal_time': goalTime,
|
||||
'image': res["goalimage"]
|
||||
.toString()
|
||||
.replaceAll('http://localhost:8100', serverUrl)
|
||||
//'http://rogaining.sumasen.net')
|
||||
});
|
||||
//print("-- json -- $rec");
|
||||
//print('----- response2 is $response2 --------');
|
||||
if (response2.statusCode == 200) {
|
||||
res2 = json.decode(utf8.decode(response2.bodyBytes));
|
||||
} else {
|
||||
res2 = json.decode(utf8.decode(response2.bodyBytes));
|
||||
});
|
||||
//print("-- json -- $rec");
|
||||
//print('----- response2 is $response2 --------');
|
||||
if (response2.statusCode == 200) {
|
||||
res2 = json.decode(utf8.decode(response2.bodyBytes));
|
||||
// ローカルのユーザーデータを更新
|
||||
indexController.updateUserGoalStatus(true);
|
||||
} else {
|
||||
res2 = json.decode(utf8.decode(response2.bodyBytes));
|
||||
// ここはどうする? TODO
|
||||
}
|
||||
} catch (e) {
|
||||
print("Error {$e}");
|
||||
}
|
||||
} catch(e){
|
||||
print( "Error {$e}" );
|
||||
}
|
||||
}catch(e) {
|
||||
print("Error in makeGoal: $e");
|
||||
Get.snackbar('エラー', 'ゴール処理に失敗しました');
|
||||
}
|
||||
|
||||
//}
|
||||
destinationController.resetRogaining(isgoal: true);
|
||||
return res2;
|
||||
|
||||
Reference in New Issue
Block a user