大幅変更&環境バージョンアップ
This commit is contained in:
55
lib/services/DatabaseService.dart
Normal file
55
lib/services/DatabaseService.dart
Normal file
@ -0,0 +1,55 @@
|
||||
import 'dart:async';
|
||||
|
||||
import 'package:gifunavi/model/destination.dart';
|
||||
import 'package:gifunavi/utils/database_helper.dart';
|
||||
|
||||
class DatabaseService {
|
||||
// Private constructor
|
||||
DatabaseService._privateConstructor();
|
||||
|
||||
// Static instance
|
||||
static final DatabaseService _instance =
|
||||
DatabaseService._privateConstructor();
|
||||
|
||||
// Factory constructor to return the instance
|
||||
factory DatabaseService() {
|
||||
return _instance;
|
||||
}
|
||||
|
||||
// StreamController for updates
|
||||
final StreamController<List<Destination>> _dbUpdateController =
|
||||
StreamController<List<Destination>>.broadcast();
|
||||
|
||||
// Getter for the stream
|
||||
Stream<List<Destination>> get destinationUpdatesStream =>
|
||||
_dbUpdateController.stream;
|
||||
|
||||
// Method to fetch destinations
|
||||
Future<List<Destination>> fetchDestinations() async {
|
||||
// Your database fetch logic here
|
||||
List<Destination> destinations = await _fetchFromDb();
|
||||
_dbUpdateController.add(destinations);
|
||||
return destinations;
|
||||
}
|
||||
|
||||
// Method to update the database and emit an update through the stream
|
||||
Future<void> updateDatabase() async {
|
||||
// Your update logic here
|
||||
|
||||
// After updating, fetch the updated list and add it to the stream
|
||||
fetchDestinations();
|
||||
}
|
||||
|
||||
// Method to fetch data from the database (placeholder)
|
||||
Future<List<Destination>> _fetchFromDb() async {
|
||||
// Simulate fetching data with a delay
|
||||
DatabaseHelper db = DatabaseHelper.instance;
|
||||
List<Destination> destinations = await db.getDestinations();
|
||||
return destinations; // Replace with your actual fetch operation
|
||||
}
|
||||
|
||||
// Dispose method to close the stream controller
|
||||
void dispose() {
|
||||
_dbUpdateController.close();
|
||||
}
|
||||
}
|
||||
@ -1,24 +1,22 @@
|
||||
import 'dart:convert';
|
||||
import 'package:http/http.dart' as http;
|
||||
import 'package:rogapp/utils/const.dart';
|
||||
import 'package:gifunavi/utils/const.dart';
|
||||
|
||||
|
||||
class ActionService{
|
||||
|
||||
static Future<Map<String, dynamic>> makeAction(int userId, int locationId, bool wanttogo, bool like, bool checkin) async {
|
||||
print("----- action is ---- $like-- $wanttogo-- $checkin");
|
||||
class ActionService {
|
||||
static Future<Map<String, dynamic>> makeAction(int userId, int locationId,
|
||||
bool wanttogo, bool like, bool checkin) async {
|
||||
//print("----- action is ---- $like-- $wanttogo-- $checkin");
|
||||
Map<String, dynamic> cats = {};
|
||||
String serverUrl = ConstValues.currentServer();
|
||||
String url = "$serverUrl/api/makeaction/?user_id=$userId&location_id=$locationId&wanttogo=$wanttogo&like=$like&checkin=$checkin";
|
||||
String url =
|
||||
"$serverUrl/api/makeaction/?user_id=$userId&location_id=$locationId&wanttogo=$wanttogo&like=$like&checkin=$checkin";
|
||||
//String url = "http://localhost:8100/api/makeaction/?user_id=${user_id}&location_id=${location_id}&wanttogo=${wanttogo}&like=${like}&checkin=${checkin}";
|
||||
print('++++++++$url');
|
||||
print("url is ------ $url");
|
||||
final http.Response response = await http.get(
|
||||
Uri.parse(url),
|
||||
headers: <String, String>{
|
||||
'Content-Type': 'application/json; charset=UTF-8',
|
||||
}
|
||||
);
|
||||
//print('++++++++$url');
|
||||
//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) {
|
||||
cats = json.decode(utf8.decode(response.bodyBytes));
|
||||
@ -26,27 +24,23 @@ class ActionService{
|
||||
return cats;
|
||||
}
|
||||
|
||||
|
||||
static Future<List<dynamic>?> userAction(int userId, int locationId) async {
|
||||
static Future<List<dynamic>?> userAction(int userId, int locationId) async {
|
||||
List<dynamic> cats = [];
|
||||
String serverUrl = ConstValues.currentServer();
|
||||
String url = '$serverUrl/api/useraction/?user_id=$userId&location_id=$locationId';
|
||||
print('++++++++$url');
|
||||
String url =
|
||||
'$serverUrl/api/useraction/?user_id=$userId&location_id=$locationId';
|
||||
//print('++++++++$url');
|
||||
//String url = 'http://localhost:8100/api/useraction/?user_id=${user_id}&location_id=${location_id}';
|
||||
final response = await http.get(Uri.parse(url),
|
||||
final response = await http.get(
|
||||
Uri.parse(url),
|
||||
headers: <String, String>{
|
||||
'Content-Type': 'application/json; charset=UTF-8',
|
||||
},
|
||||
);
|
||||
|
||||
if (response.statusCode == 200) {
|
||||
|
||||
cats = json.decode(utf8.decode(response.bodyBytes));
|
||||
}
|
||||
return cats;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
705
lib/services/api_service.dart
Normal file
705
lib/services/api_service.dart
Normal file
@ -0,0 +1,705 @@
|
||||
// lib/services/api_service.dart
|
||||
import 'package:get/get.dart';
|
||||
import 'dart:convert';
|
||||
import 'package:http/http.dart' as http;
|
||||
|
||||
import 'package:gifunavi/model/entry.dart';
|
||||
import 'package:gifunavi/model/event.dart';
|
||||
import 'package:gifunavi/model/team.dart';
|
||||
import 'package:gifunavi/model/category.dart';
|
||||
import 'package:gifunavi/model/user.dart';
|
||||
import 'package:gifunavi/pages/index/index_controller.dart';
|
||||
import '../utils/const.dart';
|
||||
import 'package:intl/intl.dart';
|
||||
|
||||
|
||||
|
||||
class ApiService extends GetxService{
|
||||
static ApiService get to => Get.find<ApiService>();
|
||||
String serverUrl = '';
|
||||
String baseUrl = '';
|
||||
String token = 'your-auth-token';
|
||||
|
||||
Future<ApiService> init() async {
|
||||
try {
|
||||
// ここで必要な初期化処理を行う
|
||||
serverUrl = ConstValues.currentServer();
|
||||
baseUrl = '$serverUrl/api';
|
||||
//await Future.delayed(Duration(seconds: 2)); // 仮の遅延(実際の初期化処理に置き換えてください)
|
||||
print('ApiService initialized successfully');
|
||||
return this;
|
||||
} catch(e) {
|
||||
print('Error in ApiService initialization: $e');
|
||||
rethrow; // エラーを再スローして、呼び出し元で処理できるようにする
|
||||
//return this;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
このメソッドは以下のように動作します:
|
||||
|
||||
まず、渡された type パラメータに基づいて、どのクラスのフィールドを扱っているかを判断します。
|
||||
次に、クラス内で fieldName に対応する期待される型を返します。
|
||||
クラスや フィールド名が予期されていないものである場合、'Unknown' または 'Unknown Type' を返します。
|
||||
|
||||
このメソッドを ApiService クラスに追加することで、_printDataComparison メソッドは各フィールドの期待される型を正確に表示できるようになります。
|
||||
さらに、このメソッドを使用することで、API レスポンスのデータ型が期待と異なる場合に簡単に検出できるようになります。例えば、Category クラスの duration フィールドが整数型(秒数)で期待されているのに対し、API が文字列を返した場合、すぐに問題を特定できます。
|
||||
注意点として、API のレスポンス形式が変更された場合や、新しいフィールドが追加された場合は、このメソッドも更新する必要があります。そのため、API の変更とクライアントサイドのコードの同期を保つことが重要です。
|
||||
*/
|
||||
|
||||
String getToken()
|
||||
{
|
||||
// IndexControllerの初期化を待つ
|
||||
final indexController = Get.find<IndexController>();
|
||||
|
||||
if (indexController.currentUser.isNotEmpty) {
|
||||
token = indexController.currentUser[0]['token'] ?? '';
|
||||
print("Get token = $token");
|
||||
}else{
|
||||
token = "";
|
||||
}
|
||||
return token;
|
||||
}
|
||||
|
||||
Future<List<Team>> getTeams() async {
|
||||
init();
|
||||
getToken();
|
||||
|
||||
try {
|
||||
final response = await http.get(
|
||||
Uri.parse('$baseUrl/teams/'),
|
||||
headers: {'Authorization': 'Token $token',"Content-Type": "application/json; charset=UTF-8"},
|
||||
);
|
||||
|
||||
if (response.statusCode == 200) {
|
||||
// UTF-8でデコード
|
||||
final decodedResponse = utf8.decode(response.bodyBytes);
|
||||
//print('User Response body: $decodedResponse');
|
||||
List<dynamic> teamsJson = json.decode(decodedResponse);
|
||||
|
||||
List<Team> teams = [];
|
||||
for (var teamJson in teamsJson) {
|
||||
//print('\nTeam Data:');
|
||||
//_printDataComparison(teamJson, Team);
|
||||
teams.add(Team.fromJson(teamJson));
|
||||
}
|
||||
return teams;
|
||||
} else {
|
||||
throw Exception('Failed to load teams. Status code: ${response.statusCode}');
|
||||
}
|
||||
} catch (e, stackTrace) {
|
||||
print('Error in getTeams: $e');
|
||||
print('Stack trace: $stackTrace');
|
||||
rethrow;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
Future<List<NewCategory>> getCategories() async {
|
||||
init();
|
||||
getToken();
|
||||
|
||||
try {
|
||||
final response = await http.get(
|
||||
Uri.parse('$baseUrl/categories/'),
|
||||
headers: {'Authorization': 'Token $token',"Content-Type": "application/json; charset=UTF-8"},
|
||||
);
|
||||
|
||||
if (response.statusCode == 200) {
|
||||
final decodedResponse = utf8.decode(response.bodyBytes);
|
||||
print('User Response body: $decodedResponse');
|
||||
List<dynamic> categoriesJson = json.decode(decodedResponse);
|
||||
|
||||
List<NewCategory> categories = [];
|
||||
for (var categoryJson in categoriesJson) {
|
||||
try {
|
||||
//print('\nCategory Data:');
|
||||
//_printDataComparison(categoryJson, NewCategory);
|
||||
categories.add(NewCategory.fromJson(categoryJson));
|
||||
}catch(e){
|
||||
print('Error parsing category: $e');
|
||||
print('Problematic JSON: $categoryJson');
|
||||
}
|
||||
}
|
||||
|
||||
return categories;
|
||||
} else {
|
||||
throw Exception(
|
||||
'Failed to load categories. Status code: ${response.statusCode}');
|
||||
}
|
||||
}catch(e, stackTrace){
|
||||
print('Error in getCategories: $e');
|
||||
print('Stack trace: $stackTrace');
|
||||
rethrow;
|
||||
}
|
||||
}
|
||||
|
||||
Future<NewCategory> getZekkenNumber(int categoryId) async {
|
||||
try {
|
||||
final response = await http.post(
|
||||
Uri.parse('$baseUrl/categories-viewset/$categoryId/get_zekken_number/'),
|
||||
headers: {'Authorization': 'Token $token',"Content-Type": "application/json; charset=UTF-8"},
|
||||
);
|
||||
if (response.statusCode == 200) {
|
||||
final decodedResponse = utf8.decode(response.bodyBytes);
|
||||
print('User Response body: $decodedResponse');
|
||||
final categoriesJson = json.decode(decodedResponse);
|
||||
|
||||
return NewCategory.fromJson(categoriesJson);
|
||||
} else {
|
||||
throw Exception('Failed to increment category number');
|
||||
}
|
||||
} catch (e) {
|
||||
throw Exception('Error incrementing category number: $e');
|
||||
}
|
||||
}
|
||||
|
||||
Future<User> getCurrentUser() async {
|
||||
init();
|
||||
getToken();
|
||||
|
||||
try {
|
||||
final response = await http.get(
|
||||
Uri.parse('$baseUrl/user/'),
|
||||
headers: {'Authorization': 'Token $token',"Content-Type": "application/json; charset=UTF-8"},
|
||||
);
|
||||
|
||||
if (response.statusCode == 200) {
|
||||
final decodedResponse = utf8.decode(response.bodyBytes);
|
||||
//print('User Response body: $decodedResponse');
|
||||
final jsonData = json.decode(decodedResponse);
|
||||
|
||||
//print('\nUser Data Comparison:');
|
||||
//_printDataComparison(jsonData, User);
|
||||
|
||||
return User.fromJson(jsonData);
|
||||
} else {
|
||||
throw Exception('Failed to get current user. Status code: ${response.statusCode}');
|
||||
}
|
||||
} catch (e, stackTrace) {
|
||||
print('Error in getCurrentUser: $e');
|
||||
print('Stack trace: $stackTrace');
|
||||
rethrow;
|
||||
}
|
||||
}
|
||||
|
||||
void _printDataComparison(Map<String, dynamic> data, Type expectedType) {
|
||||
print('Field\t\t| Expected Type\t| Actual Type\t| Actual Value');
|
||||
print('------------------------------------------------------------');
|
||||
data.forEach((key, value) {
|
||||
String expectedFieldType = _getExpectedFieldType(expectedType, key);
|
||||
_printComparison(key, expectedFieldType, value);
|
||||
});
|
||||
}
|
||||
|
||||
String _getExpectedFieldType(Type type, String fieldName) {
|
||||
// This method should return the expected type for each field based on the class definition
|
||||
// You might need to implement this based on your class structures
|
||||
|
||||
switch (type) {
|
||||
case NewCategory:
|
||||
switch (fieldName) {
|
||||
case 'id': return 'int';
|
||||
case 'category_name': return 'String';
|
||||
case 'category_number': return 'int';
|
||||
case 'duration': return 'int (seconds)';
|
||||
case 'num_of_member': return 'int';
|
||||
case 'family': return 'bool';
|
||||
case 'female': return 'bool';
|
||||
default: return 'Unknown';
|
||||
}
|
||||
case Team:
|
||||
switch (fieldName) {
|
||||
case 'id': return 'int';
|
||||
case 'zekken_number': return 'String';
|
||||
case 'team_name': return 'String';
|
||||
case 'category': return 'NewCategory (Object)';
|
||||
case 'owner': return 'User (Object)';
|
||||
default: return 'Unknown';
|
||||
}
|
||||
case User:
|
||||
switch (fieldName) {
|
||||
case 'id': return 'int';
|
||||
case 'email': return 'String';
|
||||
case 'firstname': return 'String';
|
||||
case 'lastname': return 'String';
|
||||
case 'date_of_birth': return 'String (ISO8601)';
|
||||
case 'female': return 'bool';
|
||||
case 'is_active': return 'bool';
|
||||
default: return 'Unknown';
|
||||
}
|
||||
default:
|
||||
return 'Unknown Type';
|
||||
}
|
||||
}
|
||||
|
||||
void _printComparison(String fieldName, String expectedType, dynamic actualValue) {
|
||||
String actualType = actualValue?.runtimeType.toString() ?? 'null';
|
||||
String displayValue = actualValue.toString();
|
||||
if (displayValue.length > 50) {
|
||||
displayValue = '${displayValue.substring(0, 47)}...';
|
||||
}
|
||||
print('$fieldName\t\t| $expectedType\t\t| $actualType\t\t| $displayValue');
|
||||
}
|
||||
|
||||
Future<Team> createTeam(String teamName, int categoryId) async {
|
||||
init();
|
||||
getToken();
|
||||
|
||||
final response = await http.post(
|
||||
Uri.parse('$baseUrl/teams/'),
|
||||
headers: {
|
||||
'Authorization': 'Token $token',
|
||||
"Content-Type": "application/json; charset=UTF-8",
|
||||
},
|
||||
body: json.encode({
|
||||
'team_name': teamName,
|
||||
'category': categoryId,
|
||||
}),
|
||||
);
|
||||
|
||||
if (response.statusCode == 201) {
|
||||
final decodedResponse = utf8.decode(response.bodyBytes);
|
||||
return Team.fromJson(json.decode(decodedResponse));
|
||||
} else {
|
||||
throw Exception('Failed to create team');
|
||||
}
|
||||
}
|
||||
|
||||
Future<Team> updateTeam(int teamId, String teamName, int categoryId) async {
|
||||
init();
|
||||
getToken();
|
||||
|
||||
final response = await http.put(
|
||||
Uri.parse('$baseUrl/teams/$teamId/'),
|
||||
headers: {
|
||||
'Authorization': 'Token $token',
|
||||
'Content-Type': 'application/json; charset=UTF-8',
|
||||
},
|
||||
body: json.encode({
|
||||
'team_name': teamName,
|
||||
'category': categoryId,
|
||||
}),
|
||||
);
|
||||
|
||||
if (response.statusCode == 200) {
|
||||
final decodedResponse = utf8.decode(response.bodyBytes);
|
||||
|
||||
return Team.fromJson(json.decode(decodedResponse));
|
||||
} else {
|
||||
throw Exception('Failed to update team');
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> deleteTeam(int teamId) async {
|
||||
init();
|
||||
getToken();
|
||||
|
||||
final response = await http.delete(
|
||||
Uri.parse('$baseUrl/teams/$teamId/'),
|
||||
headers: {'Authorization': 'Token $token','Content-Type': 'application/json; charset=UTF-8'},
|
||||
);
|
||||
|
||||
if( response.statusCode == 400) {
|
||||
final decodedResponse = utf8.decode(response.bodyBytes);
|
||||
print('User Response body: $decodedResponse');
|
||||
throw Exception('まだメンバーが残っているので、チームを削除できません。');
|
||||
}else if (response.statusCode != 204) {
|
||||
throw Exception('Failed to delete team');
|
||||
}
|
||||
}
|
||||
|
||||
Future<List<User>> getTeamMembers(int teamId) async {
|
||||
init();
|
||||
getToken();
|
||||
|
||||
final response = await http.get(
|
||||
Uri.parse('$baseUrl/teams/$teamId/members/'),
|
||||
headers: {'Authorization': 'Token $token','Content-Type': 'application/json; charset=UTF-8'},
|
||||
);
|
||||
|
||||
if (response.statusCode == 200) {
|
||||
final decodedResponse = utf8.decode(response.bodyBytes);
|
||||
print('User Response body: $decodedResponse');
|
||||
List<dynamic> membersJson = json.decode(decodedResponse);
|
||||
|
||||
return membersJson.map((json) => User.fromJson(json)).toList();
|
||||
} else {
|
||||
throw Exception('Failed to load team members');
|
||||
}
|
||||
}
|
||||
|
||||
Future<User> createTeamMember(int teamId, String? email, String? firstname, String? lastname, DateTime? dateOfBirth,bool? female) async {
|
||||
init();
|
||||
getToken();
|
||||
|
||||
// emailが値を持っている場合の処理
|
||||
if (email != null && email.isNotEmpty) {
|
||||
firstname ??= "dummy";
|
||||
lastname ??= "dummy";
|
||||
dateOfBirth ??= DateTime.now();
|
||||
female ??= false;
|
||||
}
|
||||
|
||||
String? formattedDateOfBirth;
|
||||
if (dateOfBirth != null) {
|
||||
formattedDateOfBirth = DateFormat('yyyy-MM-dd').format(dateOfBirth);
|
||||
}
|
||||
|
||||
final response = await http.post(
|
||||
Uri.parse('$baseUrl/teams/$teamId/members/'),
|
||||
headers: {
|
||||
'Authorization': 'Token $token',
|
||||
'Content-Type': 'application/json; charset=UTF-8',
|
||||
},
|
||||
body: json.encode({
|
||||
'email': email,
|
||||
'firstname': firstname,
|
||||
'lastname': lastname,
|
||||
'date_of_birth': formattedDateOfBirth,
|
||||
'female': female,
|
||||
}),
|
||||
);
|
||||
|
||||
if (response.statusCode == 200 || response.statusCode == 201) {
|
||||
final decodedResponse = utf8.decode(response.bodyBytes);
|
||||
return User.fromJson(json.decode(decodedResponse));
|
||||
} else {
|
||||
throw Exception('Failed to create team member');
|
||||
}
|
||||
}
|
||||
|
||||
Future<User> updateTeamMember(int teamId,int? memberId, String firstname, String lastname, DateTime? dateOfBirth,bool? female) async {
|
||||
init();
|
||||
getToken();
|
||||
|
||||
String? formattedDateOfBirth;
|
||||
if (dateOfBirth != null) {
|
||||
formattedDateOfBirth = DateFormat('yyyy-MM-dd').format(dateOfBirth);
|
||||
}
|
||||
|
||||
final response = await http.put(
|
||||
Uri.parse('$baseUrl/teams/$teamId/members/$memberId/'),
|
||||
headers: {
|
||||
'Authorization': 'Token $token',
|
||||
'Content-Type': 'application/json; charset=UTF-8',
|
||||
},
|
||||
body: json.encode({
|
||||
'firstname': firstname,
|
||||
'lastname': lastname,
|
||||
'date_of_birth': formattedDateOfBirth,
|
||||
'female': female,
|
||||
}),
|
||||
);
|
||||
|
||||
if (response.statusCode == 200) {
|
||||
final decodedResponse = utf8.decode(response.bodyBytes);
|
||||
return User.fromJson(json.decode(decodedResponse));
|
||||
} else {
|
||||
throw Exception('Failed to update team member');
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> deleteTeamMember(int teamId,int memberId) async {
|
||||
init();
|
||||
getToken();
|
||||
|
||||
final response = await http.delete(
|
||||
Uri.parse('$baseUrl/teams/$teamId/members/$memberId/'),
|
||||
headers: {'Authorization': 'Token $token'},
|
||||
);
|
||||
|
||||
if (response.statusCode != 204) {
|
||||
throw Exception('Failed to delete team member');
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> deleteAllTeamMembers(int teamId) async {
|
||||
final response = await http.delete(
|
||||
Uri.parse('$baseUrl/teams/$teamId/members/destroy_all/?confirm=true'),
|
||||
headers: {'Authorization': 'Token $token'},
|
||||
);
|
||||
|
||||
if (response.statusCode != 200) {
|
||||
throw Exception('Failed to delete team members');
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> resendMemberInvitation(int memberId) async {
|
||||
init();
|
||||
getToken();
|
||||
|
||||
final response = await http.post(
|
||||
Uri.parse('$baseUrl/members/$memberId/resend-invitation/'),
|
||||
headers: {'Authorization': 'Token $token', 'Content-Type': 'application/json; charset=UTF-8',
|
||||
},
|
||||
);
|
||||
|
||||
if (response.statusCode != 200) {
|
||||
throw Exception('Failed to resend invitation');
|
||||
}
|
||||
}
|
||||
|
||||
Future<List<Entry>> getEntries() async {
|
||||
init();
|
||||
getToken();
|
||||
|
||||
final response = await http.get(
|
||||
Uri.parse('$baseUrl/entry/'),
|
||||
headers: {'Authorization': 'Token $token', 'Content-Type': 'application/json; charset=UTF-8',
|
||||
},
|
||||
);
|
||||
|
||||
if (response.statusCode == 200) {
|
||||
final decodedResponse = utf8.decode(response.bodyBytes);
|
||||
List<dynamic> entriesJson = json.decode(decodedResponse);
|
||||
return entriesJson.map((json) => Entry.fromJson(json)).toList();
|
||||
} else {
|
||||
throw Exception('Failed to load entries');
|
||||
}
|
||||
}
|
||||
|
||||
Future<List<Entry>> getTeamEntries(int teamId) async {
|
||||
try {
|
||||
final response = await http.get(
|
||||
Uri.parse('$baseUrl/teams/$teamId/entries'),
|
||||
headers: {'Authorization': 'Token $token'},
|
||||
);
|
||||
|
||||
if (response.statusCode == 200) {
|
||||
List<dynamic> entriesJson = jsonDecode(response.body);
|
||||
return entriesJson.map((json) => Entry.fromJson(json)).toList();
|
||||
} else {
|
||||
throw Exception('Failed to load team entries: ${response.statusCode}');
|
||||
}
|
||||
} catch (e) {
|
||||
print('Error in getTeamEntries: $e');
|
||||
rethrow;
|
||||
}
|
||||
}
|
||||
|
||||
Future<List<Event>> getEvents() async {
|
||||
init();
|
||||
getToken();
|
||||
|
||||
final response = await http.get(
|
||||
Uri.parse('$baseUrl/new-events/',),
|
||||
headers: {'Authorization': 'Token $token', 'Content-Type': 'application/json; charset=UTF-8',
|
||||
},
|
||||
);
|
||||
|
||||
if (response.statusCode == 200) {
|
||||
final decodedResponse = utf8.decode(response.bodyBytes);
|
||||
print('Response body: $decodedResponse');
|
||||
List<dynamic> eventsJson = json.decode(decodedResponse);
|
||||
|
||||
return eventsJson.map((json) => Event.fromJson(json)).toList();
|
||||
} else {
|
||||
throw Exception('Failed to load events');
|
||||
}
|
||||
}
|
||||
|
||||
Future<Entry> createEntry(int teamId, int eventId, int categoryId, DateTime date,String zekkenNumber) async {
|
||||
init();
|
||||
getToken();
|
||||
|
||||
String? formattedDate;
|
||||
formattedDate = DateFormat('yyyy-MM-dd').format(date);
|
||||
|
||||
final response = await http.post(
|
||||
Uri.parse('$baseUrl/entry/'),
|
||||
headers: {
|
||||
'Authorization': 'Token $token',
|
||||
'Content-Type': 'application/json; charset=UTF-8',
|
||||
},
|
||||
body: json.encode({
|
||||
'team': teamId,
|
||||
'event': eventId,
|
||||
'category': categoryId,
|
||||
'date': formattedDate,
|
||||
'zekken_number':zekkenNumber,
|
||||
}),
|
||||
);
|
||||
|
||||
if (response.statusCode == 201) {
|
||||
final decodedResponse = utf8.decode(response.bodyBytes);
|
||||
|
||||
return Entry.fromJson(json.decode(decodedResponse));
|
||||
} else {
|
||||
final decodedResponse = utf8.decode(response.bodyBytes);
|
||||
print("decodedResponse = $decodedResponse");
|
||||
throw Exception('Failed to create entry');
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> updateUserInfo(int userId, Entry entry) async {
|
||||
init();
|
||||
getToken();
|
||||
|
||||
final entryId = entry.id;
|
||||
|
||||
DateTime? date = entry.date;
|
||||
String? formattedDate;
|
||||
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.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 teamId, int eventId, int categoryId, DateTime date,int zekkenNumber) async {
|
||||
init();
|
||||
getToken();
|
||||
|
||||
String? formattedDate;
|
||||
formattedDate = DateFormat('yyyy-MM-dd').format(date);
|
||||
|
||||
final response = await http.put(
|
||||
Uri.parse('$baseUrl/entry/$entryId/'),
|
||||
headers: {
|
||||
'Authorization': 'Token $token',
|
||||
'Content-Type': 'application/json; charset=UTF-8',
|
||||
},
|
||||
body: json.encode({
|
||||
'team': teamId,
|
||||
'event': eventId,
|
||||
'category': categoryId,
|
||||
'date': formattedDate,
|
||||
'zekken_number': zekkenNumber,
|
||||
}),
|
||||
);
|
||||
|
||||
if (response.statusCode == 200) {
|
||||
final decodedResponse = utf8.decode(response.bodyBytes);
|
||||
|
||||
return Entry.fromJson(json.decode(decodedResponse));
|
||||
} else {
|
||||
final decodedResponse = utf8.decode(response.bodyBytes);
|
||||
final blk = json.decode(decodedResponse);
|
||||
|
||||
throw Exception('Failed to update entry');
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> deleteEntry(int entryId) async {
|
||||
init();
|
||||
getToken();
|
||||
|
||||
final response = await http.delete(
|
||||
Uri.parse('$baseUrl/entry/$entryId/'),
|
||||
headers: {'Authorization': 'Token $token'},
|
||||
);
|
||||
|
||||
if (response.statusCode != 204) {
|
||||
throw Exception('Failed to delete entry');
|
||||
}
|
||||
}
|
||||
|
||||
static Future<bool> updateUserDetail(User user, String token) async {
|
||||
String serverUrl = ConstValues.currentServer();
|
||||
int? userid = user.id;
|
||||
String url = '$serverUrl/api/userdetail/$userid/';
|
||||
|
||||
try {
|
||||
String? formattedDate;
|
||||
if (user.dateOfBirth != null) {
|
||||
formattedDate = DateFormat('yyyy-MM-dd').format(user.dateOfBirth!);
|
||||
}
|
||||
final http.Response response = await http.put(
|
||||
Uri.parse(url),
|
||||
headers: <String, String>{
|
||||
'Content-Type': 'application/json; charset=UTF-8',
|
||||
'Authorization': 'Token $token'
|
||||
},
|
||||
body: jsonEncode({
|
||||
'firstname': user.firstname,
|
||||
'lastname': user.lastname,
|
||||
'date_of_birth': formattedDate,
|
||||
'female': user.female,
|
||||
}),
|
||||
);
|
||||
|
||||
if (response.statusCode == 200) {
|
||||
return true;
|
||||
} else {
|
||||
print('Update failed with status code: ${response.statusCode}');
|
||||
return false;
|
||||
}
|
||||
} catch (e) {
|
||||
print('Error in updateUserDetail: $e');
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
Future<bool> resetPassword(String email) async {
|
||||
init();
|
||||
|
||||
try {
|
||||
final response = await http.post(
|
||||
Uri.parse('$baseUrl/password-reset/'),
|
||||
headers: {
|
||||
'Content-Type': 'application/json; charset=UTF-8',
|
||||
},
|
||||
body: json.encode({
|
||||
'email': email,
|
||||
}),
|
||||
);
|
||||
|
||||
if (response.statusCode == 200) {
|
||||
return true;
|
||||
} else {
|
||||
print('Password reset failed with status code: ${response.statusCode}');
|
||||
return false;
|
||||
}
|
||||
} catch (e) {
|
||||
print('Error in resetPassword: $e');
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
Future<DateTime?> getLastGoalTime(int userId) async {
|
||||
try {
|
||||
final response = await http.get(
|
||||
Uri.parse('$baseUrl/users/$userId/last-goal/'),
|
||||
headers: {
|
||||
'Authorization': 'Token $token',
|
||||
'Content-Type': 'application/json; charset=UTF-8',
|
||||
},
|
||||
);
|
||||
|
||||
if (response.statusCode == 200) {
|
||||
final decodedResponse = json.decode(utf8.decode(response.bodyBytes));
|
||||
if (decodedResponse['last_goal_time'] != null) {
|
||||
return DateTime.parse(decodedResponse['last_goal_time']).toLocal();
|
||||
}
|
||||
} else {
|
||||
print('Failed to get last goal time. Status code: ${response.statusCode}');
|
||||
}
|
||||
} catch (e) {
|
||||
print('Error in getLastGoalTime: $e');
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
@ -1,16 +1,74 @@
|
||||
import 'dart:convert';
|
||||
import 'package:http/http.dart' as http;
|
||||
import 'package:gifunavi/model/auth_user.dart';
|
||||
import 'package:get/get.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import '../utils/const.dart';
|
||||
//import 'package:rogapp/services/team_service.dart';
|
||||
//import 'package:rogapp/services/member_service.dart';
|
||||
|
||||
|
||||
class AuthService{
|
||||
class AuthService {
|
||||
Future<AuthUser?> userLogin(String email, String password) async {
|
||||
final serverUrl = ConstValues.currentServer();
|
||||
final url = '$serverUrl/api/login/';
|
||||
|
||||
static Future<Map<String, dynamic>> changePassword(String oldpassword, String newpassword, String token) async {
|
||||
try {
|
||||
final http.Response response = await http.post(
|
||||
Uri.parse(url),
|
||||
headers: <String, String>{
|
||||
'Content-Type': 'application/json; charset=UTF-8',
|
||||
},
|
||||
body:
|
||||
jsonEncode(<String, String>{'email': email, 'password': password}),
|
||||
);
|
||||
switch (response.statusCode) {
|
||||
case 200:
|
||||
final data = json.decode(utf8.decode(response.bodyBytes));
|
||||
AuthUser user = AuthUser.fromMap(data["user"]);
|
||||
final String token = data["token"];
|
||||
user.auth_token = token;
|
||||
return user;
|
||||
default:
|
||||
return null;
|
||||
//throw Exception(response.reasonPhrase);
|
||||
}
|
||||
} on Exception catch (_) {
|
||||
rethrow;
|
||||
}
|
||||
}
|
||||
|
||||
Future<AuthUser?> userFromToken(String token) async {
|
||||
final serverUrl = ConstValues.currentServer();
|
||||
final url = '$serverUrl/api/user/';
|
||||
try {
|
||||
final http.Response response =
|
||||
await http.get(Uri.parse(url), headers: <String, String>{
|
||||
'Content-Type': 'application/json; charset=UTF-8',
|
||||
'Authorization': 'Token $token'
|
||||
});
|
||||
switch (response.statusCode) {
|
||||
case 200:
|
||||
final data = json.decode(utf8.decode(response.bodyBytes));
|
||||
AuthUser user = AuthUser.fromMap(data);
|
||||
user.auth_token = token;
|
||||
return user;
|
||||
default:
|
||||
return null;
|
||||
//throw Exception(response.reasonPhrase);
|
||||
}
|
||||
} on Exception catch (_) {
|
||||
rethrow;
|
||||
}
|
||||
}
|
||||
|
||||
static Future<Map<String, dynamic>> changePassword(
|
||||
String oldpassword, String newpassword, String token) async {
|
||||
Map<String, dynamic> changePassword = {};
|
||||
String serverUrl = ConstValues.currentServer();
|
||||
String url = '$serverUrl/api/change-password/';
|
||||
print('++++++++$url');
|
||||
//print('++++++++$url');
|
||||
final http.Response response = await http.put(
|
||||
Uri.parse(url),
|
||||
headers: <String, String>{
|
||||
@ -24,71 +82,106 @@ class AuthService{
|
||||
);
|
||||
|
||||
if (response.statusCode == 200) {
|
||||
changePassword = json.decode(utf8.decode(response.bodyBytes));
|
||||
changePassword = json.decode(utf8.decode(response.bodyBytes));
|
||||
}
|
||||
return changePassword;
|
||||
}
|
||||
|
||||
|
||||
static Future<Map<String, dynamic>> login(String email, String password) async {
|
||||
print("------- in logged email $email pwd $password ###### --------");
|
||||
static Future<Map<String, dynamic>> login(
|
||||
String email, String password) async {
|
||||
//print("------- in logged email $email pwd $password ###### --------");
|
||||
Map<String, dynamic> cats = {};
|
||||
String serverUrl = ConstValues.currentServer();
|
||||
String url = '$serverUrl/api/login/';
|
||||
print('++++++++$url');
|
||||
//print('++++++++$url');
|
||||
//String url = 'http://localhost:8100/api/login/';
|
||||
final http.Response response = await http.post(
|
||||
Uri.parse(url),
|
||||
headers: <String, String>{
|
||||
'Content-Type': 'application/json; charset=UTF-8',
|
||||
},
|
||||
body: jsonEncode(<String, String>{
|
||||
'email': email,
|
||||
'password': password
|
||||
}),
|
||||
);
|
||||
try {
|
||||
final http.Response response = await http.post(
|
||||
Uri.parse(url),
|
||||
headers: <String, String>{
|
||||
'Content-Type': 'application/json; charset=UTF-8',
|
||||
},
|
||||
body: jsonEncode(
|
||||
<String, String>{'email': email, 'password': password}),
|
||||
);
|
||||
|
||||
if (response.statusCode == 200) {
|
||||
cats = json.decode(utf8.decode(response.bodyBytes));
|
||||
if (response.statusCode == 200) {
|
||||
cats = json.decode(utf8.decode(response.bodyBytes));
|
||||
} else {
|
||||
print('Login failed with status code: ${response.statusCode}');
|
||||
cats = {};
|
||||
}
|
||||
} catch( e ){
|
||||
print('Error in login: $e');
|
||||
Get.snackbar("通信エラーがおきました", "サーバーと通信できませんでした",
|
||||
backgroundColor: Colors.red,
|
||||
colorText: Colors.white);
|
||||
Get.snackbar(
|
||||
"通信エラーがおきました",
|
||||
"サーバーと通信できませんでした",
|
||||
backgroundColor: Colors.red,
|
||||
colorText: Colors.white,
|
||||
icon: const Icon(
|
||||
Icons.assistant_photo_outlined, size: 40.0, color: Colors.blue),
|
||||
snackPosition: SnackPosition.TOP,
|
||||
duration: const Duration(seconds: 3),
|
||||
//backgroundColor: Colors.yellow,
|
||||
);
|
||||
cats = {};
|
||||
}
|
||||
return cats;
|
||||
}
|
||||
|
||||
|
||||
static Future<Map<String, dynamic>> register(String email, String password) async {
|
||||
|
||||
// ユーザー登録
|
||||
//
|
||||
/*
|
||||
Future<void> registerUser(String email, String password, bool isFemale) async {
|
||||
final user = await register(email, password);
|
||||
if (user != null) {
|
||||
final _teamController = TeamController();
|
||||
_teamController.createTeam(String teamName, int categoryId) ;
|
||||
final teamService = TeamService();
|
||||
final memberService = MemberService();
|
||||
|
||||
final team = await teamService.createSoloTeam(user.id, isFemale);
|
||||
await memberService.addMember(team.id, user.id);
|
||||
}
|
||||
}
|
||||
|
||||
*/
|
||||
|
||||
static Future<Map<String, dynamic>> register(
|
||||
String email, String password, String password2) async {
|
||||
Map<String, dynamic> cats = {};
|
||||
String serverUrl = ConstValues.currentServer();
|
||||
String url = '$serverUrl/api/register/';
|
||||
print('++++++++$url');
|
||||
debugPrint('++++++++$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>{
|
||||
'email': email,
|
||||
'password': password
|
||||
}),
|
||||
body: jsonEncode(<String, String>{'email': email, 'password': password, 'password2': password2}),
|
||||
);
|
||||
|
||||
if (response.statusCode == 200) {
|
||||
cats = json.decode(utf8.decode(response.bodyBytes));
|
||||
cats = json.decode(utf8.decode(response.bodyBytes));
|
||||
print("result=$cats");
|
||||
if (response.statusCode == 201) {
|
||||
}else{
|
||||
}
|
||||
return cats;
|
||||
}
|
||||
|
||||
static Future<Map<String, dynamic>> deleteUser(String token) async {
|
||||
static Future<Map<String, dynamic>> deleteUser(String token) async {
|
||||
Map<String, dynamic> cats = {};
|
||||
String serverUrl = ConstValues.currentServer();
|
||||
String url = '$serverUrl/api/delete-account/';
|
||||
print('++++++++$url');
|
||||
final http.Response response = await http.get(
|
||||
Uri.parse(url),
|
||||
headers: <String, String>{
|
||||
'Content-Type': 'application/json; charset=UTF-8',
|
||||
'Authorization': 'Token $token'
|
||||
}
|
||||
);
|
||||
//print('++++++++$url');
|
||||
final http.Response response =
|
||||
await http.get(Uri.parse(url), headers: <String, String>{
|
||||
'Content-Type': 'application/json; charset=UTF-8',
|
||||
'Authorization': 'Token $token'
|
||||
});
|
||||
|
||||
if (response.statusCode == 200) {
|
||||
cats = json.decode(utf8.decode(response.bodyBytes));
|
||||
@ -96,52 +189,46 @@ class AuthService{
|
||||
return cats;
|
||||
}
|
||||
|
||||
|
||||
static Future<List<dynamic>?> UserDetails(int userid) async {
|
||||
|
||||
static Future<List<dynamic>?> userDetails(int userid) async {
|
||||
List<dynamic> cats = [];
|
||||
String serverUrl = ConstValues.currentServer();
|
||||
String url = '$serverUrl/api/userdetials?user_id=$userid';
|
||||
print('++++++++$url');
|
||||
print("---- UserDetails url is $url");
|
||||
final response = await http.get(Uri.parse(url),
|
||||
//print('++++++++$url');
|
||||
//print("---- UserDetails url is $url");
|
||||
final response = await http.get(
|
||||
Uri.parse(url),
|
||||
headers: <String, String>{
|
||||
'Content-Type': 'application/json; charset=UTF-8',
|
||||
},
|
||||
);
|
||||
|
||||
if (response.statusCode == 200) {
|
||||
|
||||
cats = json.decode(utf8.decode(response.bodyBytes));
|
||||
}
|
||||
return cats;
|
||||
}
|
||||
|
||||
|
||||
static Future<List<dynamic>?> userForToken(String token) async {
|
||||
Map<String, dynamic> cats = {};
|
||||
String serverUrl = ConstValues.currentServer();
|
||||
String url = '$serverUrl/api/user/';
|
||||
print('++++++++$url');
|
||||
print("---- UserDetails url is $url");
|
||||
final response = await http.get(Uri.parse(url),
|
||||
//print('++++++++$url');
|
||||
//print("---- UserDetails url is $url");
|
||||
final response = await http.get(
|
||||
Uri.parse(url),
|
||||
headers: <String, String>{
|
||||
'Content-Type': 'application/json; charset=UTF-8',
|
||||
'Authorization': 'Token $token'
|
||||
'Authorization': 'Token $token'
|
||||
},
|
||||
);
|
||||
|
||||
if (response.statusCode == 200) {
|
||||
|
||||
cats = json.decode(utf8.decode(response.bodyBytes));
|
||||
print("--- eeeeee $cats ----");
|
||||
//print("--- eeeeee $cats ----");
|
||||
}
|
||||
return [{"user":cats}];
|
||||
return [
|
||||
{"user": cats, "token": token}
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
@ -3,50 +3,42 @@ import 'package:http/http.dart' as http;
|
||||
|
||||
import '../utils/const.dart';
|
||||
|
||||
|
||||
class CatService{
|
||||
|
||||
static Future<List<dynamic>?> loadCats(double lat1, double lon1, double lat2, double lon2, double lat3, double lon3, double lat4, double lon4) async {
|
||||
class CatService {
|
||||
static Future<List<dynamic>?> loadCats(double lat1, double lon1, double lat2,
|
||||
double lon2, double lat3, double lon3, double lat4, double lon4) async {
|
||||
List<dynamic> cats = [];
|
||||
String serverUrl = ConstValues.currentServer();
|
||||
String url = '$serverUrl/api/cats/?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),
|
||||
String url =
|
||||
'$serverUrl/api/cats/?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 == 200) {
|
||||
|
||||
cats = json.decode(utf8.decode(response.bodyBytes));
|
||||
}
|
||||
return cats;
|
||||
}
|
||||
|
||||
|
||||
static Future<List<dynamic>?> loadCatByCity(String cityname)async {
|
||||
static Future<List<dynamic>?> loadCatByCity(String cityname) async {
|
||||
List<dynamic> cats = [];
|
||||
String serverUrl = ConstValues.currentServer();
|
||||
String url = '$serverUrl/api/catbycity/?$cityname';
|
||||
print('++++++++$url');
|
||||
final response = await http.get(Uri.parse(url),
|
||||
//print('++++++++$url');
|
||||
final response = await http.get(
|
||||
Uri.parse(url),
|
||||
headers: <String, String>{
|
||||
'Content-Type': 'application/json; charset=UTF-8',
|
||||
},
|
||||
);
|
||||
|
||||
if (response.statusCode == 200) {
|
||||
|
||||
cats = json.decode(utf8.decode(response.bodyBytes));
|
||||
}
|
||||
return cats;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@ -3,25 +3,21 @@ import 'package:flutter_polyline_points/flutter_polyline_points.dart';
|
||||
import 'package:get/get.dart';
|
||||
//import 'package:google_maps_webservice/directions.dart';
|
||||
import 'package:http/http.dart' as http;
|
||||
import 'package:rogapp/model/destination.dart';
|
||||
import 'package:rogapp/pages/destination/destination_controller.dart';
|
||||
import 'package:gifunavi/model/destination.dart';
|
||||
import 'package:gifunavi/pages/destination/destination_controller.dart';
|
||||
|
||||
import '../utils/const.dart';
|
||||
|
||||
|
||||
class DestinationService{
|
||||
|
||||
static Future<List<dynamic>> getDestinations(int userId) async {
|
||||
class DestinationService {
|
||||
static Future<List<dynamic>> getDestinations(int userId) async {
|
||||
List<dynamic> cats = [];
|
||||
String serverUrl = ConstValues.currentServer();
|
||||
String url = "$serverUrl/api/destinations/?user_id=$userId";
|
||||
print('++++++++$url');
|
||||
final http.Response response = await http.get(
|
||||
Uri.parse(url),
|
||||
headers: <String, String>{
|
||||
'Content-Type': 'application/json; charset=UTF-8',
|
||||
}
|
||||
);
|
||||
//print('++++++++$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) {
|
||||
cats = json.decode(utf8.decode(response.bodyBytes));
|
||||
@ -29,36 +25,33 @@ class DestinationService{
|
||||
return cats;
|
||||
}
|
||||
|
||||
static Future<Map<String, dynamic>> deleteDestination(int destId) async {
|
||||
static Future<Map<String, dynamic>> deleteDestination(int destId) async {
|
||||
Map<String, dynamic> cats = {};
|
||||
String serverUrl = ConstValues.currentServer();
|
||||
String url = "$serverUrl/api/delete_destination/?dest_id=$destId";
|
||||
print('++++++++$url');
|
||||
final http.Response response = await http.get(
|
||||
Uri.parse(url),
|
||||
headers: <String, String>{
|
||||
'Content-Type': 'application/json; charset=UTF-8',
|
||||
}
|
||||
);
|
||||
//print('++++++++$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) {
|
||||
cats = json.decode(utf8.decode(response.bodyBytes));
|
||||
}
|
||||
print("####### ---- $cats");
|
||||
//print("####### ---- $cats");
|
||||
return cats;
|
||||
}
|
||||
|
||||
static Future<int> updateOrder(int actionId, int order, String dir) async {
|
||||
static Future<int> updateOrder(int actionId, int order, String dir) async {
|
||||
int cats = 0;
|
||||
String serverUrl = ConstValues.currentServer();
|
||||
String url = "$serverUrl/api/updateorder/?user_action_id=$actionId&order=$order&dir=$dir";
|
||||
print('++++++++$url');
|
||||
final http.Response response = await http.get(
|
||||
Uri.parse(url),
|
||||
headers: <String, String>{
|
||||
'Content-Type': 'application/json; charset=UTF-8',
|
||||
}
|
||||
);
|
||||
String url =
|
||||
"$serverUrl/api/updateorder/?user_action_id=$actionId&order=$order&dir=$dir";
|
||||
//print('++++++++$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) {
|
||||
cats = json.decode(utf8.decode(response.bodyBytes));
|
||||
@ -66,23 +59,25 @@ class DestinationService{
|
||||
return cats;
|
||||
}
|
||||
|
||||
static Future<List<PointLatLng>>? getDestinationLine(List<Destination> destinations, Map<String, dynamic> mtx) async{
|
||||
static Future<List<PointLatLng>>? getDestinationLine(
|
||||
List<Destination> destinations, Map<String, dynamic> mtx) async {
|
||||
PolylinePoints polylinePoints = PolylinePoints();
|
||||
|
||||
if(destinations.isEmpty){
|
||||
if (destinations.isEmpty) {
|
||||
return [];
|
||||
}
|
||||
|
||||
|
||||
//print("##### @@@@@ ${destinations[0].lat}");
|
||||
PointLatLng origin = PointLatLng(destinations[0].lat!, destinations[0].lon!);
|
||||
PointLatLng dest = PointLatLng(destinations[destinations.length -1].lat!, destinations[destinations.length -1].lon!);
|
||||
|
||||
PointLatLng origin =
|
||||
PointLatLng(destinations[0].lat!, destinations[0].lon!);
|
||||
PointLatLng dest = PointLatLng(destinations[destinations.length - 1].lat!,
|
||||
destinations[destinations.length - 1].lon!);
|
||||
|
||||
List<PolylineWayPoint> wayPoints = [];
|
||||
int i=0;
|
||||
for(dynamic d in destinations){
|
||||
if(i == 0 || i == (destinations.length -1)){
|
||||
i+=1;
|
||||
int i = 0;
|
||||
for (dynamic d in destinations) {
|
||||
if (i == 0 || i == (destinations.length - 1)) {
|
||||
i += 1;
|
||||
continue;
|
||||
}
|
||||
double la = d.lat;
|
||||
@ -90,39 +85,36 @@ class DestinationService{
|
||||
|
||||
int j = 0;
|
||||
|
||||
PolylineWayPoint pwp = PolylineWayPoint(location: "$la,$ln", stopOver: false);
|
||||
|
||||
PolylineWayPoint pwp =
|
||||
PolylineWayPoint(location: "$la,$ln", stopOver: false);
|
||||
|
||||
//print("----- UUUUUU ${pwp}");
|
||||
//PointLatLng wp = PointLatLng(d["Location"]["geometry"][0][1], d["Location"]["geometry"][0][0]);
|
||||
wayPoints.add(pwp);
|
||||
i+=1;
|
||||
i += 1;
|
||||
j += 4;
|
||||
}
|
||||
|
||||
final DestinationController destinationController = Get.find<DestinationController>();
|
||||
int travMode = destinationController.travelMode.value;
|
||||
String mode = "WALKING";
|
||||
if(travMode == 1){
|
||||
//_mode = TravelMode.driving;
|
||||
mode = "DRIVING";
|
||||
}
|
||||
else if(travMode == 2) {
|
||||
//_mode = TravelMode.transit;
|
||||
mode = "TRANSIT";
|
||||
}
|
||||
|
||||
final DestinationController destinationController =
|
||||
Get.find<DestinationController>();
|
||||
// int travMode = destinationController.travelMode.value;
|
||||
// String mode = "WALKING";
|
||||
// if (travMode == 1) {
|
||||
// //_mode = TravelMode.driving;
|
||||
// mode = "DRIVING";
|
||||
// } else if (travMode == 2) {
|
||||
// //_mode = TravelMode.transit;
|
||||
// mode = "TRANSIT";
|
||||
// }
|
||||
|
||||
//PolylineResult result = await polylinePoints.getRouteBetweenCoordinates("AIzaSyAUBI1ablMKuJwGj2-kSuEhvYxvB1A-mOE", PointLatLng(35.389282, 136.498027), PointLatLng(36.285848, 137.575186));
|
||||
Map<String, dynamic> pl = destinationController.matrix["routes"][0]["overview_polyline"];
|
||||
Map<String, dynamic> pl =
|
||||
destinationController.matrix["routes"][0]["overview_polyline"];
|
||||
List<PointLatLng> result = polylinePoints.decodePolyline(pl["points"]);
|
||||
//List<PointLatLng> result = polylinePoints.decodePolyline("qkyvEq`z`Yp@DBMr@XL@Td@Eb@PREd@IFe@rKIzCY|GEvCBzCHvS@xC?HnBHtBHlBFnBFhGRtDVW~BE`@ICHLk@dE_ClPgAtHu@bFsAhPg@~Ge@bFaEtg@kEpi@oCd\\w@nIw@hGe@fBy@nBqAjC{@zBgBtFOd@M@Wv@i@`BQf@ITKCuE`@yDZqBRCHa@DKG_AHwBRiBR_Fp@y@LYBY]M@KJo@v@M@cAGoGN_Cx@}Cf@}@@mM~@qF`@gCLwBj@sBrAeAhAsAtCoF|MmAbD{@fBwAdBw@p@_Ax@BFOHAl@?`@MAQCEAOIQSaBx@{Ah@eATsAHSB?d@A`D?f@IdWy@AS??V?|BCJ}@?cA?k@Au@wBqDuKQaACg@z@gELg@GK~@uEp@{A@q@y@CHwFHcG?KDqCDK^ABABEH{AE{B{@_Ho@uFIaBFQhBaC@SQSg@k@g@q@Yw@qA{De@}B]uDCsAMEWDqAFu@@^A@TDjA@vDA`CETK|AEtAIFY@o@ALpBZ~HBlCBn@EDGPu@pASJO`@Qf@?ROr@K?qDLHnEUTsDNkENYB{Ab@I^?zA}CrCkBfBw@t@@LwA`Bo@r@eGvD}BrAGGuAj@[?i@rBVi@P}@T?F?^MxDuBhDsBzAcAn@s@zCgDAI~A{A|CsC?{A?UHItA_@DCXC~J_@TUIoEvDKTm@?Y^iALIb@k@f@aAE}AA_BC{@\\Cv@CxAEj@ExCwDDc@CYFANCh@WHEIIRQhB}B|C_E\\w@Hq@JE?a@O}CGkAIwEGmDEmDAKLA^?A}@C{@?e@E_DFQNi@LcB\\eBPsADGKOEWBOH[GCPs@Pq@\\cANs@^q@jAu@fCqAf@]HCXoCV_BVmAZmBVcDBeCCgDAaB?s@RE?aCCaEAyHAoDd@EJiD@_@AaAj@A\\A?Gp@@r@oBXm@LQ?IEy@Fy@tA[n@Gj@Tz@[~ACdAAx@Lp@Kr@]hAa@HAQoCMwCSwGSiGK_CCCKaBCgCOoCOgECwGB_OB{JHkBEmC?yCDyFF{QFue@BsYByE?oAEgAByLBiL?gLBuGXsEd@cCNA?OHa@jAuCn@eAtCyDh@k@v@EvBKr@EEkACUKaC?G~@gAlCeDFBT[jFeGZAfBEh@UpBM`AEMaFjFYIhE?hEPpCJzAPt@Fj@GNUFu@N[FyBbAuB`@_@LEIOB}@HUBQFk@FcAACGQA}@Bi@F@F[Dc@D[FQHELGhBMtDGR?D");
|
||||
//PolylineResult result = await polylinePoints.getRouteBetweenCoordinates("AIzaSyAUBI1ablMKuJwGj2-kSuEhvYxvB1A-mOE", origin,dest, travelMode: _mode, wayPoints: wayPoints);
|
||||
|
||||
|
||||
//print("#####@@@@@ ${result.points}");
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
63
lib/services/error_service.dart
Normal file
63
lib/services/error_service.dart
Normal file
@ -0,0 +1,63 @@
|
||||
import 'dart:async';
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:http/http.dart' as http;
|
||||
|
||||
class ErrorService {
|
||||
static Future<void> reportError(dynamic error, StackTrace stackTrace, Map<String, dynamic> deviceInfo, List<String> operationLogs) async {
|
||||
try {
|
||||
final String errorMessage = error.toString();
|
||||
final String stackTraceString = stackTrace.toString();
|
||||
final String estimatedCause = _estimateErrorCause(errorMessage);
|
||||
//final String deviceInfo = await _getDeviceInfo();
|
||||
|
||||
final Uri url = Uri.parse('https://rogaining.sumasen.net/report-error');
|
||||
final response = await http.post(
|
||||
url,
|
||||
body: {
|
||||
'error_message': errorMessage,
|
||||
'stack_trace': stackTraceString,
|
||||
'estimated_cause': estimatedCause,
|
||||
'device_info': deviceInfo,
|
||||
'operation_logs': operationLogs.join('\n'), // オペレーションログを改行で結合して送信
|
||||
},
|
||||
);
|
||||
|
||||
if (response.statusCode == 200) {
|
||||
// エラー報告が成功した場合の処理(必要に応じて)
|
||||
debugPrint("===== エラーログ送信成功しました。 ====");
|
||||
} else {
|
||||
// エラー報告が失敗した場合の処理(必要に応じて)
|
||||
debugPrint("===== エラーログ送信失敗しました。 ====");
|
||||
}
|
||||
} catch (e) {
|
||||
// エラー報告中にエラーが発生した場合の処理(必要に応じて)
|
||||
debugPrint("===== エラーログ送信中にエラーになりました。 ====");
|
||||
}
|
||||
}
|
||||
|
||||
static String _estimateErrorCause(String errorMessage) {
|
||||
// エラーメッセージに基づいてエラーの原因を推定するロジックを追加する
|
||||
if (errorMessage.contains('NetworkException')) {
|
||||
return 'ネットワーク接続エラー';
|
||||
} else if (errorMessage.contains('DatabaseException')) {
|
||||
return 'データベースエラー';
|
||||
} else if (errorMessage.contains('AuthenticationException')) {
|
||||
return '認証エラー';
|
||||
} else {
|
||||
return '不明なエラー';
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
// 2024-4-8 Akira: メモリ使用量のチェックのため追加 See #2810
|
||||
//
|
||||
static void reportMemoryError(String message, StackTrace stackTrace) async {
|
||||
final errorDetails = FlutterErrorDetails(
|
||||
exception: Exception(message),
|
||||
stack: stackTrace,
|
||||
);
|
||||
await reportError(errorDetails.exception, errorDetails.stack ?? StackTrace.current, deviceInfo);
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
||||
@ -1,280 +1,443 @@
|
||||
import 'dart:io';
|
||||
import 'package:flutter/material.dart';
|
||||
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/destination/destination_controller.dart';
|
||||
import 'package:rogapp/pages/index/index_controller.dart';
|
||||
import 'package:rogapp/utils/database_helper.dart';
|
||||
import 'package:gifunavi/model/rog.dart';
|
||||
import 'package:gifunavi/pages/destination/destination_controller.dart';
|
||||
import 'package:gifunavi/pages/index/index_controller.dart';
|
||||
import 'package:gifunavi/utils/database_gps.dart';
|
||||
import 'package:gifunavi/utils/database_helper.dart';
|
||||
import 'dart:convert';
|
||||
|
||||
import '../model/gps_data.dart';
|
||||
import '../utils/const.dart';
|
||||
|
||||
//
|
||||
//
|
||||
// Rog type 0- start 1- checkin 2- goal
|
||||
//
|
||||
//
|
||||
|
||||
class ExternalService {
|
||||
static final ExternalService _instance = ExternalService._internal();
|
||||
|
||||
factory ExternalService(){
|
||||
factory ExternalService() {
|
||||
return _instance;
|
||||
}
|
||||
|
||||
ExternalService._internal();
|
||||
|
||||
String getFormatedTime(DateTime datetime){
|
||||
return DateFormat('yyyy-MM-dd HH:mm:ss').format(datetime);
|
||||
String getFormatedTime(DateTime datetime) {
|
||||
return DateFormat('yyyy-MM-dd HH:mm:ss').format(datetime);
|
||||
}
|
||||
|
||||
Future<Map<String, dynamic>> StartRogaining() async {
|
||||
|
||||
Future<Map<String, dynamic>> startRogaining() async {
|
||||
final IndexController indexController = Get.find<IndexController>();
|
||||
//final TeamController teamController = Get.find<TeamController>();
|
||||
|
||||
debugPrint("== startRogaining ==");
|
||||
|
||||
Map<String, dynamic> res = {};
|
||||
|
||||
//final teamController = TeamController();
|
||||
|
||||
//Team team0 = teamController.teams[0];
|
||||
//print("team={team0}");
|
||||
|
||||
//int teamId = indexController.currentUser[0]["user"]["team"]["id"];
|
||||
|
||||
int userId = indexController.currentUser[0]["user"]["id"];
|
||||
//print("--- Pressed -----");
|
||||
String team = indexController.currentUser[0]["user"]['team_name'];
|
||||
//print("--- _team : ${_team}-----");
|
||||
String eventCode = indexController.currentUser[0]["user"]["event_code"];
|
||||
|
||||
if(indexController.connectionStatusName != "wifi" && indexController.connectionStatusName != "mobile"){
|
||||
if (indexController.connectionStatusName.value != "wifi" &&
|
||||
indexController.connectionStatusName.value != "mobile") {
|
||||
debugPrint("== No network ==");
|
||||
DatabaseHelper db = DatabaseHelper.instance;
|
||||
Rog rog = Rog(
|
||||
id:1,
|
||||
team_name: team,
|
||||
event_code : eventCode,
|
||||
user_id: userId,
|
||||
cp_number: -1,
|
||||
checkintime: DateTime.now().toUtc().microsecondsSinceEpoch,
|
||||
image: null,
|
||||
rog_action_type: 0
|
||||
);
|
||||
id: 1,
|
||||
team_name: team,
|
||||
event_code: eventCode,
|
||||
user_id: userId,
|
||||
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';
|
||||
} 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
|
||||
}),
|
||||
body: jsonEncode(
|
||||
<String, String>{'team_name': team, 'event_code': eventCode}),
|
||||
);
|
||||
|
||||
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 ----');
|
||||
res = json.decode(utf8.decode(response.bodyBytes));
|
||||
//print('----_res : $res ----');
|
||||
}
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
Future<Map<String, dynamic>> makeCheckpoint(int userId, String token, String checkinTime, String teamname, int cp, String eventcode, String imageurl) async {
|
||||
Future<Map<String, dynamic>> makeCheckpoint(
|
||||
int userId, // 中身はteamId
|
||||
String token,
|
||||
String checkinTime,
|
||||
String teamname,
|
||||
int cp,
|
||||
String eventcode,
|
||||
String imageurl) async {
|
||||
// print("~~~~ in API call function ~~~~");
|
||||
// print("~~~~ cp is $cp ~~~~");
|
||||
//print("--cpcp-- ${cp}");
|
||||
Map<String, dynamic> res = {};
|
||||
String url = 'https://natnats.mobilous.com/checkin_from_rogapp';
|
||||
print('++++++++$url');
|
||||
String serverUrl = ConstValues.currentServer();
|
||||
String url = '$serverUrl/gifuroge/checkin_from_rogapp';
|
||||
//print('++++++++$url');
|
||||
final IndexController indexController = Get.find<IndexController>();
|
||||
//final TeamController teamController = Get.find<TeamController>();
|
||||
|
||||
if(imageurl != null){
|
||||
|
||||
if(indexController.connectionStatusName != "wifi" && indexController.connectionStatusName != "mobile"){
|
||||
DatabaseHelper db = DatabaseHelper.instance;
|
||||
Rog rog = Rog(
|
||||
id:1,
|
||||
team_name: teamname,
|
||||
event_code : eventcode,
|
||||
user_id: userId,
|
||||
cp_number: cp,
|
||||
checkintime: DateTime.now().toUtc().microsecondsSinceEpoch,
|
||||
image: imageurl,
|
||||
rog_action_type: 1,
|
||||
);
|
||||
db.insertRogaining(rog);
|
||||
}
|
||||
else {
|
||||
String serverUrl = ConstValues.currentServer();
|
||||
String url1 = "$serverUrl/api/checkinimage/";
|
||||
final im1Bytes = File(imageurl).readAsBytesSync();
|
||||
String im1_64 = base64Encode(im1Bytes);
|
||||
// Team team0 = indexController.teamController.teams[0];
|
||||
// print("team={team0}");
|
||||
|
||||
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(),
|
||||
'team_name': teamname,
|
||||
'event_code': eventcode,
|
||||
'checkinimage' : im1_64,
|
||||
'checkintime' : checkinTime,
|
||||
'cp_number' : cp.toString()
|
||||
}),
|
||||
);
|
||||
//int teamId = indexController.teamController.teams[0];
|
||||
|
||||
res = json.decode(utf8.decode(response.bodyBytes));
|
||||
if (indexController.connectionStatusName.value != "wifi" &&
|
||||
indexController.connectionStatusName.value != "mobile") {
|
||||
debugPrint("== checkin without network ==");
|
||||
|
||||
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: userId,
|
||||
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>{
|
||||
'Content-Type': 'application/json; charset=UTF-8',
|
||||
},
|
||||
body: jsonEncode(<String, String>{
|
||||
'team_name': teamname,
|
||||
'cp_number': cp.toString(),
|
||||
'event_code': eventcode,
|
||||
'image': ""
|
||||
}),
|
||||
);
|
||||
print("--- checnin response ${response3.statusCode}----");
|
||||
if (response3.statusCode == 200) {
|
||||
res = json.decode(utf8.decode(response3.bodyBytes));
|
||||
print('----checkin res _res : $res ----');
|
||||
}
|
||||
}
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
|
||||
Future<Map<String, dynamic>> makeGoal(int userId, String token, String teamname, String image, String goalTime, String eventcode) async {
|
||||
Map<String, dynamic> res2 = {};
|
||||
|
||||
final IndexController indexController = Get.find<IndexController>();
|
||||
final DestinationController destinationController = Get.find<DestinationController>();
|
||||
|
||||
//if(indexController.connectionStatusName != "wifi" && indexController.connectionStatusName != "mobile"){
|
||||
DatabaseHelper db = DatabaseHelper.instance;
|
||||
Rog rog = Rog(
|
||||
id:1,
|
||||
team_name: teamname,
|
||||
event_code : eventcode,
|
||||
user_id: userId,
|
||||
cp_number: -1,
|
||||
checkintime: DateTime.now().toUtc().microsecondsSinceEpoch,
|
||||
image: image,
|
||||
rog_action_type: 1,
|
||||
);
|
||||
db.insertRogaining(rog);
|
||||
// }
|
||||
// else{
|
||||
DatabaseHelper db = DatabaseHelper.instance;
|
||||
Rog rog = Rog(
|
||||
id: 1,
|
||||
team_name: teamname,
|
||||
event_code: eventcode,
|
||||
user_id: userId,
|
||||
cp_number: cp,
|
||||
checkintime: DateTime.now().toUtc().microsecondsSinceEpoch,
|
||||
image: imageurl,
|
||||
rog_action_type: 1,
|
||||
);
|
||||
db.insertRogaining(rog);
|
||||
} else {
|
||||
debugPrint("== Normal Check in ===");
|
||||
String serverUrl = ConstValues.currentServer();
|
||||
String url1 = "$serverUrl/api/goalimage/";
|
||||
final im1Bytes = File(image).readAsBytesSync();
|
||||
String url1 = "$serverUrl/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' : userId.toString(),
|
||||
'team_name': teamname,
|
||||
'event_code': eventcode,
|
||||
'goaltime' : goalTime,
|
||||
'goalimage' : im1_64,
|
||||
'cp_number' : "-1"
|
||||
}),
|
||||
);
|
||||
//print("~~~~ before calling api 1 ~~~~");
|
||||
|
||||
String url = 'https://natnats.mobilous.com/goal_from_rogapp';
|
||||
print('++++++++$url');
|
||||
if (response.statusCode == 201) {
|
||||
Map<String, dynamic> res = json.decode(utf8.decode(response.bodyBytes));
|
||||
print('----_res : $res ----');
|
||||
print('---- image url ${res["goalimage"]} ----');
|
||||
try {
|
||||
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(),
|
||||
'team_name': teamname,
|
||||
'event_code': eventcode,
|
||||
'checkinimage': im1_64,
|
||||
'checkintime': checkinTime,
|
||||
'cp_number': cp.toString()
|
||||
}),
|
||||
);
|
||||
|
||||
res = json.decode(utf8.decode(response.bodyBytes));
|
||||
//print("~~~~ api1 result $res ~~~~");
|
||||
//print("-----@@@@@ checkin $_res -----");
|
||||
|
||||
if (response.statusCode == 201) {
|
||||
//print("~~~~ image from api1 ${res["checkinimage"].toString()} ~~~~");
|
||||
//print('---- toekn is ${token} -----');
|
||||
//print("~~~~ token is $token ~~~~");
|
||||
//print("~~~~ before callling api2 ~~~~");
|
||||
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', 'http://rogaining.sumasen.net')
|
||||
}
|
||||
),
|
||||
'team_name': teamname,
|
||||
'cp_number': cp.toString(),
|
||||
'event_code': eventcode,
|
||||
'image': res["checkinimage"].toString().replaceAll(
|
||||
'http://localhost:8100', serverUrl) //'http://rogaining.sumasen.net')
|
||||
}),
|
||||
);
|
||||
var vv = jsonEncode(<String, String>{
|
||||
'team_name': teamname,
|
||||
'cp_number': cp.toString(),
|
||||
'event_code': eventcode,
|
||||
'image': res["checkinimage"].toString().replaceAll(
|
||||
'http://localhost:8100', serverUrl) //'http://rogaining.sumasen.net')
|
||||
});
|
||||
//print("~~~~ api 2 values $vv ~~~~");
|
||||
//print("--json-- $vv");
|
||||
//print("--- checnin response ${response2.statusCode}----");
|
||||
if (response2.statusCode == 200) {
|
||||
res = json.decode(utf8.decode(response2.bodyBytes));
|
||||
//print('----checkin res _res : $res ----');
|
||||
if (res["status"] == "ERROR" && cp>0 ) {
|
||||
// スタート・ゴールはエラー除外。
|
||||
Get.snackbar("エラーがおきました", res["detail"],
|
||||
backgroundColor: Colors.red,
|
||||
colorText: Colors.white
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
} else {
|
||||
Get.snackbar("サーバーエラーがおきました", "サーバーと通信できませんでした",
|
||||
backgroundColor: Colors.red,
|
||||
colorText: Colors.white
|
||||
);
|
||||
}
|
||||
} catch( e ) {
|
||||
print('Error in makeCheckpoint: $e');
|
||||
Get.snackbar("通信エラーがおきました", "サーバーと通信できませんでした",
|
||||
backgroundColor: Colors.red,
|
||||
colorText: Colors.white
|
||||
);
|
||||
print('----- response2 is $response2 --------');
|
||||
}
|
||||
}
|
||||
//print("~~~~ done checkin ~~~~");
|
||||
return res;
|
||||
}
|
||||
|
||||
Future<Map<String, dynamic>> makeGoal(int userId, String token,
|
||||
String teamname, String image, String goalTime, String eventcode) async {
|
||||
Map<String, dynamic> res2 = {};
|
||||
|
||||
final IndexController indexController = Get.find<IndexController>();
|
||||
final DestinationController destinationController =
|
||||
Get.find<DestinationController>();
|
||||
|
||||
// チームIDを取得
|
||||
|
||||
//int teamId = indexController.currentUser[0]["user"]["team"]["id"];
|
||||
|
||||
debugPrint("== goal Rogaining ==");
|
||||
|
||||
//if(indexController.connectionStatusName != "wifi" && indexController.connectionStatusName != "mobile"){
|
||||
DatabaseHelper db = DatabaseHelper.instance;
|
||||
Rog rog = Rog(
|
||||
id: 1,
|
||||
team_name: teamname,
|
||||
event_code: eventcode,
|
||||
user_id: userId, // 中身はteamid
|
||||
cp_number: -1,
|
||||
checkintime: DateTime.now().toUtc().microsecondsSinceEpoch,
|
||||
image: image,
|
||||
rog_action_type: 1,
|
||||
);
|
||||
db.insertRogaining(rog);
|
||||
// }
|
||||
// else{
|
||||
String serverUrl = ConstValues.currentServer();
|
||||
String url1 = "$serverUrl/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': 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)
|
||||
//'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));
|
||||
}
|
||||
}
|
||||
} catch(e){
|
||||
print( "Error {$e}" );
|
||||
}
|
||||
}
|
||||
//}
|
||||
destinationController.resetRogaining();
|
||||
destinationController.resetRogaining(isgoal: true);
|
||||
return res2;
|
||||
}
|
||||
|
||||
Future<bool> removeCheckin(int cp) async {
|
||||
final IndexController indexController = Get.find<IndexController>();
|
||||
|
||||
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');
|
||||
final http.Response response = await http.get(
|
||||
Uri.parse(url),
|
||||
headers: <String, String>{
|
||||
'Content-Type': 'application/json; charset=UTF-8',
|
||||
//int userId = indexController.currentUser[0]["user"]["id"];
|
||||
//print("--- Pressed -----");
|
||||
String team = indexController.currentUser[0]["user"]['team_name'];
|
||||
//print("--- _team : ${_team}-----");
|
||||
String eventCode = indexController.currentUser[0]["user"]["event_code"];
|
||||
|
||||
if (indexController.connectionStatusName.value != "wifi" &&
|
||||
indexController.connectionStatusName.value != "mobile") {
|
||||
return Future.value(false);
|
||||
} else {
|
||||
String serverUrl = ConstValues.currentServer();
|
||||
String url = '$serverUrl/gifuroge/remove_checkin_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>{
|
||||
'event_code': eventCode,
|
||||
'team_name': team,
|
||||
'cp_number': cp.toString()
|
||||
}),
|
||||
);
|
||||
|
||||
//print("---- remove checkin ---- ${response.statusCode}");
|
||||
|
||||
if (response.statusCode == 200) {
|
||||
return Future.value(true);
|
||||
//print('----_res : $res ----');
|
||||
}
|
||||
);
|
||||
}
|
||||
return Future.value(false);
|
||||
}
|
||||
|
||||
String timestampToTimeString(int timestamp) {
|
||||
// Convert timestamp to DateTime and format it as needed
|
||||
var dateTime = DateTime.fromMillisecondsSinceEpoch(timestamp);
|
||||
//print("^^^^ time ${dateTime}");
|
||||
// Format dateTime to a time string (e.g., '12:00:00')
|
||||
// Adjust the format as needed
|
||||
return "${dateTime.hour}:${dateTime.minute}:${dateTime.second}";
|
||||
}
|
||||
|
||||
Future<bool> pushGPS() async {
|
||||
//print("^^^^ pushed ^^^");
|
||||
final IndexController indexController = Get.find<IndexController>();
|
||||
|
||||
//int userId = indexController.currentUser[0]["user"]["id"];
|
||||
//print("--- Pressed -----");
|
||||
String team = indexController.currentUser[0]["user"]['team_name'];
|
||||
//print("--- _team : ${_team}-----");
|
||||
String eventCode = indexController.currentUser[0]["user"]["event_code"];
|
||||
|
||||
List<GpsData> gpsDataList = [];
|
||||
|
||||
if (indexController.connectionStatusName.value != "wifi" &&
|
||||
indexController.connectionStatusName.value != "mobile") {
|
||||
return Future.value(false);
|
||||
} else {
|
||||
// Step 1: Fetch data from the local database
|
||||
gpsDataList =
|
||||
await GpsDatabaseHelper.instance.getUnsyncedGPSData(team, eventCode);
|
||||
|
||||
// Step 2: Transform data into the required format
|
||||
var payload = {
|
||||
'team_name': team,
|
||||
'event_code': eventCode,
|
||||
'waypoints': gpsDataList.map((gpsData) {
|
||||
return {
|
||||
'latitude': gpsData.lat.toString(),
|
||||
'longitude': gpsData.lon.toString(),
|
||||
// Convert the timestamp to a formatted time string
|
||||
'time': timestampToTimeString(gpsData.created_at),
|
||||
};
|
||||
}).toList(),
|
||||
};
|
||||
|
||||
//print("calling push gps step 2 ${payload}");
|
||||
|
||||
String serverUrl = ConstValues.currentServer();
|
||||
String urlS = '$serverUrl/gifuroge/get_waypoint_datas_from_rogapp';
|
||||
//print('++++++++$url');
|
||||
var url = Uri.parse(urlS); // Replace with your server URL
|
||||
var response = await http.post(
|
||||
url,
|
||||
headers: {"Content-Type": "application/json"},
|
||||
body: json.encode(payload),
|
||||
);
|
||||
|
||||
//print("GPS Data res ${response.statusCode}");
|
||||
if (response.statusCode == 200) {
|
||||
// Handle success
|
||||
// make local data as synced
|
||||
await GpsDatabaseHelper.instance.setSyncData(gpsDataList);
|
||||
//print("GPS Data sent successfully");
|
||||
} else {
|
||||
// Handle error
|
||||
//print("Failed to send data");
|
||||
}
|
||||
}
|
||||
return Future.value(false);
|
||||
}
|
||||
|
||||
static Future<Map<String, dynamic>> usersEventCode(
|
||||
String teamcode, String password) async {
|
||||
Map<String, dynamic> res = {};
|
||||
String serverUrl = ConstValues.currentServer();
|
||||
String url = "$serverUrl/gifuroge/check_event_code?zekken_number=$teamcode&password=$password";
|
||||
//print('++++++++$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;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,35 +1,32 @@
|
||||
import 'package:geojson/geojson.dart';
|
||||
import 'package:http/http.dart' as http;
|
||||
// import 'package:geojson/geojson.dart';
|
||||
// import 'package:http/http.dart' as http;
|
||||
|
||||
import '../utils/const.dart';
|
||||
// import '../utils/const.dart';
|
||||
|
||||
class LocationLineService{
|
||||
// class LocationLineService {
|
||||
// static Future<GeoJsonFeature?> loadLocationLines() async {
|
||||
// final geo = GeoJson();
|
||||
// GeoJsonFeature? fs;
|
||||
// String serverUrl = ConstValues.currentServer();
|
||||
// String url = '$serverUrl/api/location_line/';
|
||||
// //print('++++++++$url');
|
||||
// final response = await http.get(
|
||||
// Uri.parse(url),
|
||||
// headers: <String, String>{
|
||||
// 'Content-Type': 'application/json; charset=UTF-8',
|
||||
// },
|
||||
// );
|
||||
|
||||
static Future<GeoJsonFeature?> loadLocationLines() async {
|
||||
final geo = GeoJson();
|
||||
GeoJsonFeature? fs;
|
||||
String serverUrl = ConstValues.currentServer();
|
||||
String url = '$serverUrl/api/location_line/';
|
||||
print('++++++++$url');
|
||||
final response = await http.get(Uri.parse(url),
|
||||
headers: <String, String>{
|
||||
'Content-Type': 'application/json; charset=UTF-8',
|
||||
},
|
||||
);
|
||||
// if (response.statusCode == 200) {
|
||||
// geo.processedFeatures.listen((fst) {
|
||||
// fs = fst;
|
||||
// });
|
||||
|
||||
if (response.statusCode == 200) {
|
||||
// await geo.parse(response.body, verbose: true);
|
||||
|
||||
geo.processedFeatures.listen((fst) {
|
||||
fs = fst;
|
||||
});
|
||||
|
||||
await geo.parse(response.body, verbose:true);
|
||||
|
||||
return fs;
|
||||
|
||||
} else {
|
||||
throw Exception('Failed to create album.');
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
// return fs;
|
||||
// } else {
|
||||
// throw Exception('Failed to create album.');
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
||||
@ -1,36 +1,33 @@
|
||||
import 'package:geojson/geojson.dart';
|
||||
import 'package:http/http.dart' as http;
|
||||
// import 'package:geojson/geojson.dart';
|
||||
// import 'package:http/http.dart' as http;
|
||||
|
||||
import '../utils/const.dart';
|
||||
// import '../utils/const.dart';
|
||||
|
||||
class LocationPolygonervice{
|
||||
// class LocationPolygonervice {
|
||||
// static Future<GeoJsonFeature?> loadLocationLines() async {
|
||||
// final geo = GeoJson();
|
||||
// GeoJsonFeature? fs;
|
||||
|
||||
static Future<GeoJsonFeature?> loadLocationLines() async {
|
||||
final geo = GeoJson();
|
||||
GeoJsonFeature? fs;
|
||||
// String serverUrl = ConstValues.currentServer();
|
||||
// String url = '$serverUrl/api/location_polygon/';
|
||||
// //print('++++++++$url');
|
||||
// final response = await http.get(
|
||||
// Uri.parse(url),
|
||||
// headers: <String, String>{
|
||||
// 'Content-Type': 'application/json; charset=UTF-8',
|
||||
// },
|
||||
// );
|
||||
|
||||
String serverUrl = ConstValues.currentServer();
|
||||
String url = '$serverUrl/api/location_polygon/';
|
||||
print('++++++++$url');
|
||||
final response = await http.get(Uri.parse(url),
|
||||
headers: <String, String>{
|
||||
'Content-Type': 'application/json; charset=UTF-8',
|
||||
},
|
||||
);
|
||||
// if (response.statusCode == 200) {
|
||||
// geo.processedFeatures.listen((fst) {
|
||||
// fs = fst;
|
||||
// });
|
||||
|
||||
if (response.statusCode == 200) {
|
||||
// await geo.parse(response.body, verbose: true);
|
||||
|
||||
geo.processedFeatures.listen((fst) {
|
||||
fs = fst;
|
||||
});
|
||||
|
||||
await geo.parse(response.body, verbose:true);
|
||||
|
||||
return fs;
|
||||
|
||||
} else {
|
||||
throw Exception('Failed to create album.');
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
// return fs;
|
||||
// } else {
|
||||
// throw Exception('Failed to create album.');
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
||||
@ -1,75 +1,52 @@
|
||||
import 'dart:convert';
|
||||
|
||||
import 'package:geojson/geojson.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:geojson_vi/geojson_vi.dart';
|
||||
import 'package:get/get.dart';
|
||||
import 'package:http/http.dart' as http;
|
||||
import 'package:rogapp/pages/index/index_controller.dart';
|
||||
import 'package:rogapp/utils/const.dart';
|
||||
import 'package:gifunavi/pages/destination/destination_controller.dart';
|
||||
import 'package:gifunavi/pages/index/index_controller.dart';
|
||||
import 'package:gifunavi/utils/const.dart';
|
||||
|
||||
class LocationService{
|
||||
class LocationService {
|
||||
|
||||
// static Future<GeoJsonFeatureCollection?> loadLocations() async {
|
||||
|
||||
// final IndexController indexController = Get.find<IndexController>();
|
||||
|
||||
// String server_url = ConstValues.currentServer();
|
||||
// String url = "";
|
||||
// if(indexController.currentUser.length > 0){
|
||||
// url = '${server_url}/api/location/?is_rog=True';
|
||||
// }
|
||||
// else {
|
||||
// url = '${server_url}/api/location/';
|
||||
// }
|
||||
// //String url = 'http://localhost:8100/api/location/';
|
||||
// final response = await http.get(Uri.parse(url),
|
||||
// headers: <String, String>{
|
||||
// 'Content-Type': 'application/json; charset=UTF-8',
|
||||
// },
|
||||
// );
|
||||
|
||||
// if (response.statusCode == 200) {
|
||||
|
||||
// return featuresFromGeoJson(utf8.decode(response.bodyBytes));
|
||||
// }
|
||||
// return null;
|
||||
// }
|
||||
|
||||
static Future<GeoJsonFeatureCollection?> loadLocationsFor(String perfecture, String cat) async {
|
||||
static Future<GeoJSONFeatureCollection?> loadLocationsFor(
|
||||
String perfecture, String cat) async {
|
||||
final IndexController indexController = Get.find<IndexController>();
|
||||
String url = "";
|
||||
String serverUrl = ConstValues.currentServer();
|
||||
|
||||
if(cat.isNotEmpty){
|
||||
if(indexController.currentUser.isNotEmpty){
|
||||
|
||||
if (cat.isNotEmpty) {
|
||||
if (indexController.currentUser.isNotEmpty) {
|
||||
bool rog = indexController.currentUser[0]['user']['is_rogaining'];
|
||||
String r = rog == true ? 'True': 'False';
|
||||
String r = rog == true ? 'True' : 'False';
|
||||
var grp = indexController.currentUser[0]['user']['event_code'];
|
||||
url = '$serverUrl/api/inperf/?rog=$r&perf=$perfecture&cat=$cat';
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
url = '$serverUrl/api/inperf/?perf=$perfecture&cat=$cat';
|
||||
}
|
||||
}
|
||||
else{
|
||||
if(indexController.currentUser.isNotEmpty){
|
||||
} else {
|
||||
if (indexController.currentUser.isNotEmpty) {
|
||||
bool rog = indexController.currentUser[0]['user']['is_rogaining'];
|
||||
String r = rog == true ? 'True': 'False';
|
||||
String r = rog == true ? 'True' : 'False';
|
||||
var grp = indexController.currentUser[0]['user']['event_code'];
|
||||
url = '$serverUrl/api/inperf/?rog=$r&perf=$perfecture';
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
url = '$serverUrl/api/inperf/?perf=$perfecture';
|
||||
}
|
||||
}
|
||||
print('++++++++$url');
|
||||
final response = await http.get(Uri.parse(url),
|
||||
//print('++++++++$url');
|
||||
final response = await http.get(
|
||||
Uri.parse(url),
|
||||
headers: <String, String>{
|
||||
'Content-Type': 'application/json; charset=UTF-8',
|
||||
},
|
||||
);
|
||||
|
||||
if (response.statusCode == 200) {
|
||||
GeoJsonFeatureCollection cc = await featuresFromGeoJson(utf8.decode(response.bodyBytes));
|
||||
GeoJSONFeatureCollection cc =
|
||||
GeoJSONFeatureCollection.fromJSON(utf8.decode(response.bodyBytes));
|
||||
//print(cc);
|
||||
return cc; //featuresFromGeoJson(utf8.decode(response.bodyBytes));
|
||||
}
|
||||
@ -80,175 +57,182 @@ class LocationService{
|
||||
List<dynamic> ext = [];
|
||||
String serverUrl = ConstValues.currentServer();
|
||||
String url = '$serverUrl/api/locsext/';
|
||||
print('++++++++$url');
|
||||
//print('++++++++$url');
|
||||
final response = await http.post(Uri.parse(url),
|
||||
headers: <String, String>{
|
||||
'Content-Type': 'application/json; charset=UTF-8',
|
||||
'Authorization': 'Token $token'
|
||||
},
|
||||
body: jsonEncode(<String, String>{
|
||||
'token': token,
|
||||
})
|
||||
);
|
||||
headers: <String, String>{
|
||||
'Content-Type': 'application/json; charset=UTF-8',
|
||||
'Authorization': 'Token $token'
|
||||
},
|
||||
body: jsonEncode(<String, String>{
|
||||
'token': token,
|
||||
}));
|
||||
|
||||
if (response.statusCode == 200) {
|
||||
|
||||
ext = json.decode(utf8.decode(response.bodyBytes));
|
||||
}
|
||||
return ext;
|
||||
}
|
||||
|
||||
|
||||
static Future<GeoJsonFeatureCollection?> loadLocationsSubFor(String subperfecture, String cat) async {
|
||||
static Future<GeoJSONFeatureCollection?> loadLocationsBound(
|
||||
double lat1,
|
||||
double lon1,
|
||||
double lat2,
|
||||
double lon2,
|
||||
double lat3,
|
||||
double lon3,
|
||||
double lat4,
|
||||
double lon4,
|
||||
String cat,
|
||||
String eventCode) 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/insubperf?rog=$r&subperf=$subperfecture&cat=$cat';
|
||||
}
|
||||
else{
|
||||
url = '$serverUrl/api/insubperf?subperf=$subperfecture&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'];
|
||||
url = '$serverUrl/api/insubperf?rog=$r&subperf=$subperfecture';
|
||||
}
|
||||
else{
|
||||
url = '$serverUrl/api/insubperf?subperf=$subperfecture';
|
||||
}
|
||||
}
|
||||
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 == 200) {
|
||||
GeoJsonFeatureCollection cc = await featuresFromGeoJson(utf8.decode(response.bodyBytes));
|
||||
//print(cc);
|
||||
return cc; //featuresFromGeoJson(utf8.decode(response.bodyBytes));
|
||||
}
|
||||
return null;
|
||||
}
|
||||
// ユーザー情報の更新を最大5秒間待つ
|
||||
|
||||
try {
|
||||
/*
|
||||
// ユーザー情報の更新を最大5秒間待つ
|
||||
final newUpdateTime = await indexController.lastUserUpdateTime.stream
|
||||
.firstWhere(
|
||||
(time) => time.isAfter(updateTime),
|
||||
orElse: () => updateTime,
|
||||
).timeout(Duration(seconds: 5));
|
||||
|
||||
static Future<GeoJsonFeatureCollection?> loadLocationsBound(double lat1, double lon1, double lat2, double lon2, double lat3, double lon3, double lat4, double lon4, String cat) async {
|
||||
final IndexController indexController = Get.find<IndexController>();
|
||||
print("-------- in location for bound -------------");
|
||||
print("-------- in location for bound current user ${indexController.currentUser} -------------");
|
||||
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',
|
||||
},
|
||||
);
|
||||
|
||||
if (response.statusCode == 500) {
|
||||
return GeoJsonFeatureCollection(); //featuresFromGeoJson(utf8.decode(response.bodyBytes));
|
||||
}
|
||||
|
||||
if (response.statusCode == 200) {
|
||||
GeoJsonFeatureCollection cc = await featuresFromGeoJson(utf8.decode(response.bodyBytes));
|
||||
if(cc.collection.isEmpty){
|
||||
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 = eventCode; //indexController.currentUser[0]['user']['event_code'];
|
||||
print("Group=$grp");
|
||||
url =
|
||||
'$serverUrl/api/inbound2?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/inbound2?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/inbound2?rog=$r&grp=$grp&ln1=$lon1&la1=$lat1&ln2=$lon2&la2=$lat2&ln3=$lon3&la3=$lat3&ln4=$lon4&la4=$lat4';
|
||||
} else {
|
||||
url =
|
||||
'$serverUrl/api/inbound2?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;
|
||||
}
|
||||
|
||||
|
||||
static Future<GeoJsonFeatureCollection?> loadCustomLocations(String name, String cat) async {
|
||||
static Future<GeoJSONFeatureCollection?> loadCustomLocations(
|
||||
String name, String cat) async {
|
||||
final IndexController indexController = Get.find<IndexController>();
|
||||
String url = "";
|
||||
if(cat == "-all-"){
|
||||
if (cat == "-all-") {
|
||||
cat = "";
|
||||
}
|
||||
String serverUrl = ConstValues.currentServer();
|
||||
print("loadCustomLocations url is ----- $cat");
|
||||
if(cat.isNotEmpty){
|
||||
if(indexController.currentUser.isNotEmpty){
|
||||
//print("loadCustomLocations url is ----- $cat");
|
||||
if (cat.isNotEmpty) {
|
||||
if (indexController.currentUser.isNotEmpty) {
|
||||
bool rog = indexController.currentUser[0]['user']['is_rogaining'];
|
||||
String r = rog == true ? 'True': 'False';
|
||||
String r = rog == true ? 'True' : 'False';
|
||||
var grp = indexController.currentUser[0]['user']['event_code'];
|
||||
url = '$serverUrl/api/custom_area/?rog=$r&&cat=$cat';
|
||||
}
|
||||
else{
|
||||
} else {
|
||||
url = '$serverUrl/api/custom_area/?&cat=$cat';
|
||||
}
|
||||
}
|
||||
else{
|
||||
if(indexController.currentUser.isNotEmpty){
|
||||
} else {
|
||||
if (indexController.currentUser.isNotEmpty) {
|
||||
bool rog = indexController.currentUser[0]['user']['is_rogaining'];
|
||||
String r = rog == true ? 'True': 'False';
|
||||
String r = rog == true ? 'True' : 'False';
|
||||
var grp = indexController.currentUser[0]['user']['event_code'];
|
||||
url = '$serverUrl/api/customarea?rog=$r&name=$name';
|
||||
}
|
||||
else{
|
||||
} else {
|
||||
url = '$serverUrl/api/customarea?name=$name';
|
||||
}
|
||||
}
|
||||
print('++++++++$url');
|
||||
final response = await http.get(Uri.parse(url),
|
||||
//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 GeoJsonFeatureCollection(); //featuresFromGeoJson(utf8.decode(response.bodyBytes));
|
||||
return null; //featuresFromGeoJson(utf8.decode(response.bodyBytes));
|
||||
}
|
||||
|
||||
if (response.statusCode == 200) {
|
||||
GeoJsonFeatureCollection cc = await featuresFromGeoJson(utf8.decode(response.bodyBytes));
|
||||
if(cc.collection.isEmpty){
|
||||
GeoJSONFeatureCollection cc =
|
||||
GeoJSONFeatureCollection.fromJSON(utf8.decode(response.bodyBytes));
|
||||
if (cc.features.isEmpty) {
|
||||
return null;
|
||||
}
|
||||
else{
|
||||
return cc;
|
||||
} else {
|
||||
return cc;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
static const platform = MethodChannel('location');
|
||||
|
||||
|
||||
|
||||
}
|
||||
static Future<bool> isLocationServiceRunning() async {
|
||||
try {
|
||||
final bool isRunning = await platform.invokeMethod('isLocationServiceRunning');
|
||||
return isRunning;
|
||||
} catch (e) {
|
||||
print("Failed to check if location service is running: $e");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,38 +1,35 @@
|
||||
|
||||
import 'dart:convert';
|
||||
import 'package:get/get.dart';
|
||||
import 'package:http/http.dart' as http;
|
||||
import 'package:rogapp/model/destination.dart';
|
||||
import 'package:rogapp/pages/destination/destination_controller.dart';
|
||||
import 'package:gifunavi/model/destination.dart';
|
||||
import 'package:gifunavi/pages/destination/destination_controller.dart';
|
||||
|
||||
|
||||
class MatrixService{
|
||||
|
||||
static Future<Map<String, dynamic>> getDestinations(List<Destination> destinations) async {
|
||||
|
||||
final DestinationController destinationController = Get.find<DestinationController>();
|
||||
class MatrixService {
|
||||
static Future<Map<String, dynamic>> getDestinations(
|
||||
List<Destination> destinations) async {
|
||||
final DestinationController destinationController =
|
||||
Get.find<DestinationController>();
|
||||
|
||||
String locs = "";
|
||||
String origin = "";
|
||||
String destination = "";
|
||||
int i = 0;
|
||||
for(Destination d in destinations){
|
||||
for (Destination d in destinations) {
|
||||
//print("---- getting matrix for $d ------------");
|
||||
|
||||
print("---- getting matrix for $d ------------");
|
||||
|
||||
if(i==0){
|
||||
if (i == 0) {
|
||||
origin = "${d.lat}, ${d.lon}";
|
||||
i++;
|
||||
continue;
|
||||
}
|
||||
|
||||
if(i == (destinations.length - 1)){
|
||||
if (i == (destinations.length - 1)) {
|
||||
destination = "${d.lat}, ${d.lon}";
|
||||
i++;
|
||||
continue;
|
||||
}
|
||||
|
||||
print("lat is ${d.lat}, long is ${d.lon}");
|
||||
//print("lat is ${d.lat}, long is ${d.lon}");
|
||||
locs += "${d.lat}, ${d.lon}|";
|
||||
i++;
|
||||
}
|
||||
@ -46,28 +43,24 @@ class MatrixService{
|
||||
break;
|
||||
case 2:
|
||||
mode = "transit";
|
||||
break;
|
||||
break;
|
||||
default:
|
||||
mode = "walking";
|
||||
break;
|
||||
}
|
||||
|
||||
Map<String, dynamic> cats = {};
|
||||
String url = "https://maps.googleapis.com/maps/api/directions/json?destination=$destination&mode=$mode&waypoints=$locs&origin=$origin&key=AIzaSyAUBI1ablMKuJwGj2-kSuEhvYxvB1A-mOE";
|
||||
print('++++++++$url');
|
||||
final http.Response response = await http.get(
|
||||
Uri.parse(url),
|
||||
headers: <String, String>{
|
||||
'Content-Type': 'application/json; charset=UTF-8',
|
||||
}
|
||||
);
|
||||
String url =
|
||||
"https://maps.googleapis.com/maps/api/directions/json?destination=$destination&mode=$mode&waypoints=$locs&origin=$origin&key=AIzaSyCN2xFsqFyadWwpjiFxymrxzS6G1tNzraI";
|
||||
//print('++++++++$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) {
|
||||
cats = json.decode(utf8.decode(response.bodyBytes));
|
||||
}
|
||||
return cats;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
@ -1,23 +1,21 @@
|
||||
import 'dart:convert';
|
||||
import 'package:http/http.dart' as http;
|
||||
import 'package:rogapp/utils/const.dart';
|
||||
|
||||
|
||||
class PerfectureService{
|
||||
import 'package:gifunavi/utils/const.dart';
|
||||
|
||||
class PerfectureService {
|
||||
static Future<List<dynamic>?> loadPerfectures() async {
|
||||
List<dynamic> perfs = [];
|
||||
String serverUrl = ConstValues.currentServer();
|
||||
String url = '$serverUrl/api/perf_main/';
|
||||
print('++++++++$url');
|
||||
final response = await http.get(Uri.parse(url),
|
||||
//print('++++++++$url');
|
||||
final response = await http.get(
|
||||
Uri.parse(url),
|
||||
headers: <String, String>{
|
||||
'Content-Type': 'application/json; charset=UTF-8',
|
||||
},
|
||||
);
|
||||
|
||||
if (response.statusCode == 200) {
|
||||
|
||||
perfs = json.decode(utf8.decode(response.bodyBytes));
|
||||
}
|
||||
return perfs;
|
||||
@ -27,34 +25,33 @@ class PerfectureService{
|
||||
List<dynamic> perfs = [];
|
||||
String serverUrl = ConstValues.currentServer();
|
||||
String url = '$serverUrl/api/subperfinmain/?area=$area';
|
||||
print('++++++++$url');
|
||||
final response = await http.get(Uri.parse(url),
|
||||
//print('++++++++$url');
|
||||
final response = await http.get(
|
||||
Uri.parse(url),
|
||||
headers: <String, String>{
|
||||
'Content-Type': 'application/json; charset=UTF-8',
|
||||
},
|
||||
);
|
||||
|
||||
if (response.statusCode == 200) {
|
||||
|
||||
perfs = json.decode(utf8.decode(response.bodyBytes));
|
||||
}
|
||||
return perfs;
|
||||
}
|
||||
|
||||
|
||||
static Future<List<dynamic>?> getMainPerfExt(String id) async {
|
||||
List<dynamic> perfs = [];
|
||||
String serverUrl = ConstValues.currentServer();
|
||||
String url = '$serverUrl/api/mainperfext/?perf=$id';
|
||||
print('++++++++$url');
|
||||
final response = await http.get(Uri.parse(url),
|
||||
//print('++++++++$url');
|
||||
final response = await http.get(
|
||||
Uri.parse(url),
|
||||
headers: <String, String>{
|
||||
'Content-Type': 'application/json; charset=UTF-8',
|
||||
},
|
||||
);
|
||||
|
||||
if (response.statusCode == 200) {
|
||||
|
||||
perfs = json.decode(utf8.decode(response.bodyBytes));
|
||||
}
|
||||
return perfs;
|
||||
@ -64,15 +61,15 @@ class PerfectureService{
|
||||
List<dynamic> perfs = [];
|
||||
String serverUrl = ConstValues.currentServer();
|
||||
String url = '$serverUrl/api/allgifuareas/?perf=$perf';
|
||||
print('++++++++$url');
|
||||
final response = await http.get(Uri.parse(url),
|
||||
//print('++++++++$url');
|
||||
final response = await http.get(
|
||||
Uri.parse(url),
|
||||
headers: <String, String>{
|
||||
'Content-Type': 'application/json; charset=UTF-8',
|
||||
},
|
||||
);
|
||||
|
||||
if (response.statusCode == 200) {
|
||||
|
||||
perfs = json.decode(utf8.decode(response.bodyBytes));
|
||||
}
|
||||
return perfs;
|
||||
@ -82,40 +79,35 @@ class PerfectureService{
|
||||
List<dynamic> perfs = [];
|
||||
String serverUrl = ConstValues.currentServer();
|
||||
String url = '$serverUrl/api/customareanames';
|
||||
print('++++++++$url');
|
||||
final response = await http.get(Uri.parse(url),
|
||||
//print('++++++++$url');
|
||||
final response = await http.get(
|
||||
Uri.parse(url),
|
||||
headers: <String, String>{
|
||||
'Content-Type': 'application/json; charset=UTF-8',
|
||||
},
|
||||
);
|
||||
|
||||
if (response.statusCode == 200) {
|
||||
|
||||
perfs = json.decode(utf8.decode(response.bodyBytes));
|
||||
}
|
||||
return perfs;
|
||||
}
|
||||
|
||||
|
||||
static Future<List<dynamic>?> getSubExt(String id) async {
|
||||
List<dynamic> perfs = [];
|
||||
String serverUrl = ConstValues.currentServer();
|
||||
String url = '$serverUrl/api/perfext/?sub_perf=$id';
|
||||
print('++++++++$url');
|
||||
final response = await http.get(Uri.parse(url),
|
||||
//print('++++++++$url');
|
||||
final response = await http.get(
|
||||
Uri.parse(url),
|
||||
headers: <String, String>{
|
||||
'Content-Type': 'application/json; charset=UTF-8',
|
||||
},
|
||||
);
|
||||
|
||||
if (response.statusCode == 200) {
|
||||
|
||||
perfs = json.decode(utf8.decode(response.bodyBytes));
|
||||
}
|
||||
return perfs;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
@ -1,27 +1,22 @@
|
||||
|
||||
import 'dart:convert';
|
||||
|
||||
import 'package:http/http.dart' as http;
|
||||
import 'package:rogapp/utils/const.dart';
|
||||
|
||||
import 'package:gifunavi/utils/const.dart';
|
||||
|
||||
class TrackingService {
|
||||
|
||||
static Future<Map<String, dynamic>> addTrack(String userId, double lat, double lon) async {
|
||||
static Future<Map<String, dynamic>> addTrack(
|
||||
String userId, double lat, double lon) async {
|
||||
Map<String, dynamic> cats = {};
|
||||
String serverUrl = ConstValues.currentServer();
|
||||
String url = '$serverUrl/api/track/';
|
||||
print('++++++++$url');
|
||||
//print('++++++++$url');
|
||||
final geom = '{"type": "MULTIPOINT", "coordinates": [[$lon, $lat]]}';
|
||||
final http.Response response = await http.post(
|
||||
Uri.parse(url),
|
||||
headers: <String, String>{
|
||||
'Content-Type': 'application/json; charset=UTF-8',
|
||||
},
|
||||
body: jsonEncode(<String, String>{
|
||||
'user_id': userId,
|
||||
'geom': geom
|
||||
}),
|
||||
body: jsonEncode(<String, String>{'user_id': userId, 'geom': geom}),
|
||||
);
|
||||
|
||||
if (response.statusCode == 200) {
|
||||
@ -29,5 +24,4 @@ class TrackingService {
|
||||
}
|
||||
return cats;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user