Merge add and delete Favorite Music Functions
continuous-integration/drone/push Build is passing Details

FAVORITE_MUSICS_EKA
Emre KARTAL 2 years ago
parent c8b93c51cd
commit e738a92cfd

@ -29,7 +29,7 @@ class MusicService {
} }
} }
addFavoriteMusic(String id) async { Future<bool> addOrDeleteFavoriteMusic(String id) async {
var userRef = await FirebaseFirestore.instance var userRef = await FirebaseFirestore.instance
.collection("users") .collection("users")
.doc(MyApp.userViewModel.userCurrent.id); .doc(MyApp.userViewModel.userCurrent.id);
@ -39,8 +39,11 @@ class MusicService {
if (!musicFavorite.contains(id)) { if (!musicFavorite.contains(id)) {
musicFavorite.add(id); musicFavorite.add(id);
await userRef.update({"musics_likes": musicFavorite}); await userRef.update({"musics_likes": musicFavorite});
return false;
} else { } else {
print("Add error: The music is not in the user's favorite music list"); musicFavorite.remove(id);
await userRef.update({"musics_likes": musicFavorite});
return true;
} }
} }
} }

@ -2,6 +2,7 @@ import 'dart:convert';
import 'package:http/http.dart' as http; import 'package:http/http.dart' as http;
import '../main.dart'; import '../main.dart';
import '../values/keys.dart';
class NotificationService { class NotificationService {
sendPushMessage(String token, String title, String body) async { sendPushMessage(String token, String title, String body) async {
@ -10,7 +11,7 @@ class NotificationService {
headers: <String, String>{ headers: <String, String>{
'Content-Type': 'application/json', 'Content-Type': 'application/json',
'Authorization': 'Authorization':
'key=AAAA56TmIPg:APA91bFeKMr_i6CbUuuUdFI1XkdaNE2A7OVHzxrPIsOSlDfhR6qzZwof7JNGxthWUKj1dRHQMheWNYaLbf3AtXUp9o4DX_gB2073yR4urqUEh9CjvnxVws_9g1cWMgmFS3EpaQEA3icC' 'key=$keyApiFirebase'
}, },
body: jsonEncode(<String, dynamic>{ body: jsonEncode(<String, dynamic>{
'priority': 'high', 'priority': 'high',

@ -1,3 +1,5 @@
const geoKey = "85a2724ad38b3994c2b7ebe1d239bbff"; const geoKey = "85a2724ad38b3994c2b7ebe1d239bbff";
const clientId = "d9b82921bbdf43efa15d0c34c28c6f93"; const clientId = "d9b82921bbdf43efa15d0c34c28c6f93";
const clientSecret = "ba01687f59ea4ab7ad00c769e89e44d8"; const clientSecret = "ba01687f59ea4ab7ad00c769e89e44d8";
const keyApiFirebase =
"AAAA56TmIPg:APA91bFeKMr_i6CbUuuUdFI1XkdaNE2A7OVHzxrPIsOSlDfhR6qzZwof7JNGxthWUKj1dRHQMheWNYaLbf3AtXUp9o4DX_gB2073yR4urqUEh9CjvnxVws_9g1cWMgmFS3EpaQEA3icC";

@ -245,18 +245,9 @@ class MusicViewModel {
} }
} }
addFavoriteMusic(String id) async { Future<bool> addOrDeleteFavoriteMusic(String id) async {
try { try {
await _musicService.addFavoriteMusic(id); return await _musicService.addOrDeleteFavoriteMusic(id);
} catch (e) {
print(e);
rethrow;
}
}
deleteFavoriteMusic(String id) async {
try {
await _musicService.deleteFavoriteMusic(id);
} catch (e) { } catch (e) {
print(e); print(e);
rethrow; rethrow;

Loading…
Cancel
Save