diff --git a/amplify/backend/function/backupSymbolInfo/src/index.py b/amplify/backend/function/backupSymbolInfo/src/index.py index 6bdc3a9..083437f 100644 --- a/amplify/backend/function/backupSymbolInfo/src/index.py +++ b/amplify/backend/function/backupSymbolInfo/src/index.py @@ -49,6 +49,11 @@ def operation_put(items): try: with table.batch_writer() as batch: for item in items: + # カラム名 Typo の吸収 + if 'longitude' in item: + longitude = item['longitude'] + else: + longitude = item['longtitude'] baseItem={ 'backupTitle': item['backupTitle'], 'id': item['id'], @@ -56,7 +61,7 @@ def operation_put(items): 'describe': item['describe'], 'dateTime': item['dateTime'], 'latitude': item['latitude'], - 'longtitude': item['longtitude'], + 'longitude': longitude, 'prefecture': item['prefecture'], 'municipalities': item['municipalities'] } diff --git a/lib/aws_access.dart b/lib/aws_access.dart index e03cc57..62879b7 100644 --- a/lib/aws_access.dart +++ b/lib/aws_access.dart @@ -83,7 +83,7 @@ Future backupSymbolInfos(AmplifyClass amplify, String backupTitle) async { ', "describe": ${jsonEncode(describe)}' ', "dateTime": ${jsonEncode(dateTime)}' ', "latitude": ${jsonEncode(latitude)}' - ', "longtitude": ${jsonEncode(longitude)}' + ', "longitude": ${jsonEncode(longitude)}' ', "prefecture": ${jsonEncode(prefecture)}' ', "municipalities": ${jsonEncode(municipalities)}' '}, '; @@ -269,8 +269,12 @@ Future> _fetchBackupSymbolInfos( PrefMuni( item['prefecture'] as String, item['municipalities'] as String), ); + // カラム名 Typo の吸収 + final num longitude = (item.containsKey('longitude') + ? item['longitude'] as num + : item['longtitude'] as num); final LatLng latLng = - LatLng(item['latitude'] as double, item['longtitude'] as double); + LatLng((item['latitude'] as num).toDouble(), longitude.toDouble()); final SymbolInfoWithLatLng infoLatLng = SymbolInfoWithLatLng(item['id'] as int, info, latLng); resultList.add(infoLatLng); diff --git a/lib/db_access.dart b/lib/db_access.dart index c54562d..d78eb01 100644 --- a/lib/db_access.dart +++ b/lib/db_access.dart @@ -14,7 +14,7 @@ Future createDatabase() async { ' describe TEXT NOT NULL,' ' date_time INTEGER NOT NULL,' ' latitude REAL NOT NULL,' - ' longtitude REAL NOT NULL,' + ' longitude REAL NOT NULL,' ' prefecture TEXT NOT NULL DEFAULT "",' ' municipalities TEXT NOT NULL DEFAULT ""' ')'; @@ -27,7 +27,7 @@ Future createDatabase() async { ' cloud_path TEXT NOT NULL' ')'; // DB テーブル作成 - _database = await openDatabase('maptool.db', version: 6, + _database = await openDatabase('maptool.db', version: 7, onCreate: (db, version) async { await db.execute( createSymbolInfo, @@ -51,6 +51,32 @@ Future createDatabase() async { // ignore: avoid_print print('alter table add column (symbol_info)'); } + if (oldVersion < 7) { + // await db.execute( + // 'BEGIN TRANSACTION', + // ); + await db.execute( + 'ALTER TABLE symbol_info RENAME TO symbol_info_temp', + ); + await db.execute( + createSymbolInfo, + ); + await db.execute( + 'INSERT INTO ' + ' symbol_info(id, title, describe, date_time, latitude, longitude, prefecture, municipalities) ' + 'SELECT' + ' id, title, describe, date_time, latitude, longtitude, prefecture, municipalities ' + 'FROM symbol_info_temp', + ); + await db.execute( + 'DROP TABLE symbol_info_temp', + ); + // await db.execute( + // 'COMMIT', + // ); + // ignore: avoid_print + print('alter table rename column (symbol_info)'); + } }); } @@ -75,7 +101,7 @@ Future> fetchRecords() async { 'describe', 'date_time', 'latitude', - 'longtitude', + 'longitude', 'prefecture', 'municipalities', ], @@ -88,7 +114,7 @@ Future> fetchRecords() async { map['describe'], DateTime.fromMillisecondsSinceEpoch(map['date_time'], isUtc: false), PrefMuni(map['prefecture'], map['municipalities'])); - final LatLng latLng = LatLng(map['latitude'], map['longtitude']); + final LatLng latLng = LatLng(map['latitude'], map['longitude']); final SymbolInfoWithLatLng symbolInfoWithLatLng = SymbolInfoWithLatLng(map['id'], symbolInfo, latLng); symbolInfoWithLatLngs.add(symbolInfoWithLatLng); @@ -124,7 +150,7 @@ Future addRecord(SymbolInfoWithLatLng symbolInfoWithLatLng) async { 'date_time': symbolInfoWithLatLng.symbolInfo.dateTime.millisecondsSinceEpoch, 'latitude': symbolInfoWithLatLng.latLng.latitude, - 'longtitude': symbolInfoWithLatLng.latLng.longitude, + 'longitude': symbolInfoWithLatLng.latLng.longitude, 'prefecture': symbolInfoWithLatLng.symbolInfo.prefMuni.prefecture, 'municipalities': symbolInfoWithLatLng.symbolInfo.prefMuni.municipalities }, @@ -142,7 +168,7 @@ Future addRecordWithId(SymbolInfoWithLatLng symbolInfoWithLatLng) async { 'date_time': symbolInfoWithLatLng.symbolInfo.dateTime.millisecondsSinceEpoch, 'latitude': symbolInfoWithLatLng.latLng.latitude, - 'longtitude': symbolInfoWithLatLng.latLng.longitude, + 'longitude': symbolInfoWithLatLng.latLng.longitude, 'prefecture': symbolInfoWithLatLng.symbolInfo.prefMuni.prefecture, 'municipalities': symbolInfoWithLatLng.symbolInfo.prefMuni.municipalities }, diff --git a/lib/supabase_access.dart b/lib/supabase_access.dart index bbd4c2e..9fdc13d 100644 --- a/lib/supabase_access.dart +++ b/lib/supabase_access.dart @@ -23,7 +23,8 @@ Future> searchNearSpot( item['category_name'] as String, item['title'] as String, item['describe'] as String, - LatLng(item['latitude'] as double, item['longitude'] as double), + LatLng((item['latitude'] as num).toDouble(), + (item['longitude'] as num).toDouble()), PrefMuni(item['prefecture'] as String, item['municipality'] as String)); resultList.add(spotData); }