correção de bugs, creação propria para turmas, e preparação para criar quizzes

This commit is contained in:
2026-05-15 12:40:38 +01:00
parent 62b9a107bc
commit 2775205f9e
14 changed files with 970 additions and 604 deletions

View File

@@ -58,14 +58,16 @@ class AppRouter {
GoRoute(
path: login,
name: 'login',
builder: (context, state) => const LoginPage(),
builder: (context, state) =>
LoginPage(selectedRole: state.uri.queryParameters['role']),
),
// Signup
GoRoute(
path: signup,
name: 'signup',
builder: (context, state) => const SignupPage(),
builder: (context, state) =>
SignupPage(selectedRole: state.uri.queryParameters['role']),
),
// Student Dashboard

View File

@@ -13,13 +13,29 @@ class AuthService {
}
/// Criar documento do usuário na Firestore após signup
static Future<void> createUserRole(String uid, String role) async {
static Future<void> createUserRole(
String uid,
String role, {
String? classId,
String? schoolClassId,
String? displayName,
}) async {
try {
print('DEBUG: Criando documento users/$uid com role: $role');
await _firestore.collection('users').doc(uid).set({
final Map<String, dynamic> data = {
'role': role,
'createdAt': FieldValue.serverTimestamp(),
});
};
if (classId != null && classId.isNotEmpty) {
data['classId'] = classId;
}
if (schoolClassId != null && schoolClassId.isNotEmpty) {
data['schoolClassId'] = schoolClassId;
}
if (displayName != null && displayName.isNotEmpty) {
data['displayName'] = displayName;
}
await _firestore.collection('users').doc(uid).set(data);
print('DEBUG: Documento criado com sucesso');
} catch (e) {
print('DEBUG: Erro ao criar documento: $e');
@@ -27,6 +43,53 @@ class AuthService {
}
}
/// Criar inscrição do aluno na turma escolhida
static Future<void> createEnrollment({
required String studentId,
required String classId,
required String studentName,
}) async {
try {
print(
'DEBUG: Criando enrollment para student=$studentId, class=$classId',
);
final existing = await _firestore
.collection('enrollments')
.where('studentId', isEqualTo: studentId)
.where('classId', isEqualTo: classId)
.limit(1)
.get();
if (existing.docs.isNotEmpty) {
print('DEBUG: Enrollment já existe, ignorando');
return;
}
await _firestore.collection('enrollments').add({
'classId': classId,
'studentId': studentId,
'studentName': studentName,
'joinedAt': FieldValue.serverTimestamp(),
});
print('DEBUG: Enrollment criado com sucesso');
} catch (e) {
print('DEBUG: Erro ao criar enrollment: $e');
throw Exception('Erro ao associar aluno à turma');
}
}
/// Ler classId do aluno na Firestore
static Future<String?> getStudentClassId(String uid) async {
try {
final doc = await _firestore.collection('users').doc(uid).get();
if (doc.exists) {
return doc.data()?['classId'] as String?;
}
return null;
} catch (e) {
print('DEBUG: Erro ao ler classId: $e');
return null;
}
}
/// Ler role do usuário na Firestore
static Future<String?> getUserRole(String uid) async {
try {
@@ -56,6 +119,8 @@ class AuthService {
required String password,
String? displayName,
String? role,
String? classId,
String? schoolClassId,
}) async {
try {
print('DEBUG: Tentando criar conta para email: $email');
@@ -76,9 +141,15 @@ class AuthService {
print('DEBUG: Display name atualizado para: $displayName');
}
// Criar documento na Firestore com role
// Criar documento na Firestore com role (e classId se aluno)
if (role != null && result.user != null) {
await createUserRole(result.user!.uid, role);
await createUserRole(
result.user!.uid,
role,
classId: classId,
schoolClassId: schoolClassId,
displayName: displayName,
);
}
// Verificar se o email foi verificado