melhorar o tem por filtro de ano
This commit is contained in:
44
lib/controllers/team_controllers.dart
Normal file
44
lib/controllers/team_controllers.dart
Normal file
@@ -0,0 +1,44 @@
|
||||
import 'package:cloud_firestore/cloud_firestore.dart';
|
||||
import 'package:playmaker/service/auth_service.dart';
|
||||
|
||||
class TeamController {
|
||||
final AuthService _authService = AuthService();
|
||||
final CollectionReference _teamsRef = FirebaseFirestore.instance.collection('teams');
|
||||
|
||||
|
||||
Stream<QuerySnapshot> get teamsStream {
|
||||
final uid = _authService.currentUid;
|
||||
return _teamsRef
|
||||
.where('userId', isEqualTo: uid)
|
||||
.orderBy('createdAt', descending: true)
|
||||
.snapshots();
|
||||
}
|
||||
|
||||
// --- CRIAR EQUIPA ---
|
||||
Future<void> createTeam(String name, String season, String imageUrl) async {
|
||||
final uid = _authService.currentUid;
|
||||
|
||||
if (uid != null) {
|
||||
try {
|
||||
await _teamsRef.add({
|
||||
'name': name,
|
||||
'season': season,
|
||||
'imageUrl': imageUrl,
|
||||
'userId': uid,
|
||||
'createdAt': FieldValue.serverTimestamp(),
|
||||
});
|
||||
} catch (e) {
|
||||
print("Erro ao criar equipa: $e");
|
||||
}
|
||||
} else {
|
||||
print("Erro: Utilizador não autenticado.");
|
||||
}
|
||||
}
|
||||
Future<void> deleteTeam(String docId) async {
|
||||
try {
|
||||
await _teamsRef.doc(docId).delete();
|
||||
} catch (e) {
|
||||
print("Erro ao eliminar: $e");
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user