Fix all features

This commit is contained in:
2024-07-30 02:15:04 +09:00
parent 9c98d3ed53
commit 3d7a5ae0c1
11 changed files with 268 additions and 69 deletions

View File

@ -466,6 +466,43 @@ class ApiService extends GetxService{
}
}
Future<void> updateUserInfo(int userId, Entry entry) async {
init();
getToken();
final entryId = entry.id;
DateTime? date = entry.date;
String? formattedDate;
if (date != null) {
formattedDate = DateFormat('yyyy-MM-dd').format(date);
}
final response = await http.put(
Uri.parse('$baseUrl/userinfo/$userId/'),
headers: {
'Authorization': 'Token $token',
'Content-Type': 'application/json; charset=UTF-8',
},
body: json.encode({
'zekken_number': entry.team.zekkenNumber,
'event_code': entry.event.eventName,
'group': entry.team.category.categoryName,
'team_name': entry.team.teamName,
'date': formattedDate,
}),
);
if (response.statusCode == 200) {
final decodedResponse = utf8.decode(response.bodyBytes);
final updatedUserInfo = json.decode(decodedResponse);
//Get.find<IndexController>().updateUserInfo(updatedUserInfo);
} else {
throw Exception('Failed to update entry');
}
}
Future<Entry> updateEntry(int entryId, int eventId, int categoryId, DateTime date) async {
init();
getToken();

View File

@ -82,59 +82,93 @@ class LocationService {
double lon3,
double lat4,
double lon4,
String cat) async {
String cat,
String event_code) async {
//print("-------- in location for bound -------------");
final IndexController indexController = Get.find<IndexController>();
String url = "";
String serverUrl = ConstValues.currentServer();
if (cat.isNotEmpty) {
if (indexController.currentUser.isNotEmpty) {
bool rog = indexController.currentUser[0]['user']['is_rogaining'];
String r = rog == true ? 'True' : 'False';
var grp = indexController.currentUser[0]['user']['event_code'];
url =
'$serverUrl/api/inbound?rog=$r&grp=$grp&ln1=$lon1&la1=$lat1&ln2=$lon2&la2=$lat2&ln3=$lon3&la3=$lat3&ln4=$lon4&la4=$lat4&cat=$cat';
} else {
url =
'$serverUrl/api/inbound?ln1=$lon1&la1=$lat1&ln2=$lon2&la2=$lat2&ln3=$lon3&la3=$lat3&ln4=$lon4&la4=$lat4&cat=$cat';
}
} else {
if (indexController.currentUser.isNotEmpty) {
bool rog = indexController.currentUser[0]['user']['is_rogaining'];
String r = rog == true ? 'True' : 'False';
var grp = indexController.currentUser[0]['user']['event_code'];
//print("-------- requested user group $grp -------------");
url =
'$serverUrl/api/inbound?rog=$r&grp=$grp&ln1=$lon1&la1=$lat1&ln2=$lon2&la2=$lat2&ln3=$lon3&la3=$lat3&ln4=$lon4&la4=$lat4';
} else {
url =
'$serverUrl/api/inbound?ln1=$lon1&la1=$lat1&ln2=$lon2&la2=$lat2&ln3=$lon3&la3=$lat3&ln4=$lon4&la4=$lat4';
}
}
//print('++++++++$url');
final response = await http.get(
Uri.parse(url),
headers: <String, String>{
'Content-Type': 'application/json; charset=UTF-8',
},
);
final updateTime = indexController.lastUserUpdateTime.value;
if (response.statusCode == 500) {
return null; //featuresFromGeoJson(utf8.decode(response.bodyBytes));
}
// ユーザー情報の更新を最大5秒間待つ
if (response.statusCode == 200) {
DestinationController destinationController =
Get.find<DestinationController>();
GeoJSONFeatureCollection cc =
GeoJSONFeatureCollection.fromJSON(utf8.decode(response.bodyBytes));
if (cc.features.isEmpty) {
try {
/*
// ユーザー情報の更新を最大5秒間待つ
final newUpdateTime = await indexController.lastUserUpdateTime.stream
.firstWhere(
(time) => time.isAfter(updateTime),
orElse: () => updateTime,
).timeout(Duration(seconds: 5));
if (newUpdateTime == updateTime) {
print('ユーザー情報の更新がタイムアウトしました');
// タイムアウト時の処理(例:エラー表示やリトライ)
return null;
} else {
//print("---- feature got from server is ${cc.collection[0].properties} ------");
return cc;
}
*/
/*
await indexController.lastUserUpdateTime.stream.firstWhere(
(time) => time.isAfter(updateTime),
orElse: () => updateTime,
).timeout(Duration(seconds: 2), onTimeout: () => updateTime);
*/
String url = "";
String serverUrl = ConstValues.currentServer();
if (cat.isNotEmpty) {
if (indexController.currentUser.isNotEmpty) {
bool rog = indexController.currentUser[0]['user']['is_rogaining'];
String r = rog == true ? 'True' : 'False';
var grp = event_code; //indexController.currentUser[0]['user']['event_code'];
print("Group=$grp");
url =
'$serverUrl/api/inbound?rog=$r&grp=$grp&ln1=$lon1&la1=$lat1&ln2=$lon2&la2=$lat2&ln3=$lon3&la3=$lat3&ln4=$lon4&la4=$lat4&cat=$cat';
} else {
url =
'$serverUrl/api/inbound?ln1=$lon1&la1=$lat1&ln2=$lon2&la2=$lat2&ln3=$lon3&la3=$lat3&ln4=$lon4&la4=$lat4&cat=$cat';
}
} else {
if (indexController.currentUser.isNotEmpty) {
bool rog = indexController.currentUser[0]['user']['is_rogaining'];
String r = rog == true ? 'True' : 'False';
var grp = indexController.currentUser[0]['user']['event_code'];
print("-------- requested user group $grp -------------");
url =
'$serverUrl/api/inbound?rog=$r&grp=$grp&ln1=$lon1&la1=$lat1&ln2=$lon2&la2=$lat2&ln3=$lon3&la3=$lat3&ln4=$lon4&la4=$lat4';
} else {
url =
'$serverUrl/api/inbound?ln1=$lon1&la1=$lat1&ln2=$lon2&la2=$lat2&ln3=$lon3&la3=$lat3&ln4=$lon4&la4=$lat4';
}
print('++++++++$url');
final response = await http.get(
Uri.parse(url),
headers: <String, String>{
'Content-Type': 'application/json; charset=UTF-8',
},
);
if (response.statusCode == 500) {
return null; //featuresFromGeoJson(utf8.decode(response.bodyBytes));
}
if (response.statusCode == 200) {
DestinationController destinationController =
Get.find<DestinationController>();
GeoJSONFeatureCollection cc =
GeoJSONFeatureCollection.fromJSON(utf8.decode(response.bodyBytes));
if (cc.features.isEmpty) {
return null;
} else {
//print("---- feature got from server is ${cc.collection[0].properties} ------");
return cc;
}
}
}
} catch(e) {
print("Error: $e");
}
return null;
}