Skip to content

Commit

Permalink
M3-209 Feat : 즐겨찾기 삭제 구현
Browse files Browse the repository at this point in the history
  • Loading branch information
tkdals802 committed Aug 8, 2024
1 parent 22e10b1 commit 049a7ea
Show file tree
Hide file tree
Showing 7 changed files with 23 additions and 11 deletions.
3 changes: 3 additions & 0 deletions lib/controllers/main_controller.dart
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
import 'package:get/get.dart';

import '../service/fcm_service.dart';
import '../service/my_place_service.dart';

class MainController extends GetxController {
final FcmService fcmService = FcmService();
final MyPlaceService myPlaceService = MyPlaceService();

@override
void onInit() async {
super.onInit();
fcmService.registerFcmToken();
myPlaceService.getMyPlaceInfo();
}
}
5 changes: 2 additions & 3 deletions lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import 'screens/sign_up_screen.dart';
import 'service/location_service.dart';
import 'service/my_place_service.dart';
import 'utils/user_manager.dart';
import 'service/auth_service.dart';
import 'widgets/common/internet_disconnect.dart';

Future<void> main() async {
Expand All @@ -39,7 +40,7 @@ Future<void> main() async {

KakaoSdk.init(nativeAppKey: dotenv.env['NATIVE_APP_KEY']!);
LocationService().initBackgroundLocation();
String initialRoute = '/main';//await AuthService().isLogin() ? '/main' : '/permission';
String initialRoute = await AuthService().isLogin() ? '/main' : '/permission';
runApp(
MyApp(
initialRoute: initialRoute,
Expand All @@ -51,7 +52,6 @@ class MyApp extends StatelessWidget {
MyApp({super.key, required this.initialRoute});

final String initialRoute;
final MyPlaceService myPlaceService = MyPlaceService();
static bool checkInternet = true;

final listener =
Expand Down Expand Up @@ -80,7 +80,6 @@ class MyApp extends StatelessWidget {
Widget build(BuildContext context) {
final FirebaseAnalytics analytics = FirebaseAnalytics.instance;
analytics.logAppOpen();
myPlaceService.getMyPlaceInfo();

return MediaQuery(
data: MediaQuery.of(context).copyWith(textScaler: TextScaler.noScaling),
Expand Down
1 change: 0 additions & 1 deletion lib/screens/map_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ class MapScreen extends StatelessWidget {
},
myLocationEnabled: true,
style: mapController.mapStyle,
markers: Set<Marker>.of(mapController.markers),
polygons: Set<Polygon>.of(mapController.pixels),
),
);
Expand Down
14 changes: 12 additions & 2 deletions lib/service/my_place_service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,17 @@ class MyPlaceService {
myPlaces = MyPlace.listFromJson(response.data['data']);
for (var e in myPlaces) {
box.write(e.placeName.toString(), e.placePoint);
print('1111 ${e.placeName.toString()}, ${e.placePoint}');
print('1111');
}

return myPlaces;
}

Future<void> putMyPlaceInfo(
String placeName, double latitude, double longitude,) async {
String placeName,
double latitude,
double longitude,
) async {
int? userId = UserManager().getUserId();
await dio.put(
'/myplace',
Expand All @@ -42,4 +46,10 @@ class MyPlaceService {
},
);
}

Future<void> deleteMyPlaceInfo(String placeName) async {
int? userId = UserManager().getUserId();
await dio
.delete('/myplace', data: {"userId": userId, "placeName": placeName});
}
}
2 changes: 1 addition & 1 deletion lib/utils/dio_service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class DioService {
_dio.interceptors.add(
InterceptorsWrapper(
onRequest: (options, handler) async {
const accessToken = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpYXQiOjE3MjA3NTc5ODUsImV4cCI6MTgyMTYyMTk4NSwidXNlcklkIjo2MjJ9.HNTbCbz02o9-GsDxcdGG-VxJl0Q_xb1hBeu7ihg9oSY';//await secureStorage.readAccessToken();
final accessToken = await secureStorage.readAccessToken();
options.headers.addAll({
'Authorization': 'Bearer $accessToken',
});
Expand Down
8 changes: 4 additions & 4 deletions lib/widgets/map/my_place_bottom_sheet.dart
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,10 @@ class MyPlaceBottomSheet extends StatelessWidget {
child: InkWell(
borderRadius: BorderRadius.circular(16),
onTap: () async{
// await myPlaceService.putMyPlaceInfo(
// mapController.myPlaceName.value,
// mapController.selectedLatitude.value,
// mapController.selectedLongitude.value,);
await myPlaceService.putMyPlaceInfo(
mapController.myPlaceName.value,
mapController.selectedLatitude.value,
mapController.selectedLongitude.value,);

await mapController.writeLocalStorage(
mapController.myPlaceName.value,
Expand Down
1 change: 1 addition & 0 deletions lib/widgets/map/my_place_button_icon.dart
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ class MyPlaceButtonIcon extends StatelessWidget {
onPressed: () async {
mapController.deleteLocalStorage(place);
mapController.myPlaceButtonVisible.value = false;
myPlaceService.deleteMyPlaceInfo(place);
Get.back();
},
),
Expand Down

0 comments on commit 049a7ea

Please sign in to comment.