Skip to content

Commit

Permalink
chore: merged new + old
Browse files Browse the repository at this point in the history
  • Loading branch information
IamMuuo committed Feb 5, 2025
1 parent 11f4736 commit 2c67a6a
Show file tree
Hide file tree
Showing 37 changed files with 441 additions and 742 deletions.
3 changes: 0 additions & 3 deletions android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,7 @@ android {
}

defaultConfig {
// TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
applicationId = "com.dita.academia"
// You can update the following values to match your application needs.
// For more information, see: https://docs.flutter.dev/deployment/android#reviewing-the-gradle-build-configuration.
minSdk = 29
targetSdk = 34
versionCode = 10
Expand Down
Binary file added assets/images/school-of-athens.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion lib/app.dart
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class Academia extends StatelessWidget {
);
return MultiBlocProvider(
providers: [
BlocProvider(create: (_) => AuthCubit()),
BlocProvider(create: (_) => AuthBloc()),
BlocProvider(create: (_) => ProfileCubit()),
BlocProvider(create: (_) => CourseCubit()),
],
Expand Down
1 change: 1 addition & 0 deletions lib/core/core.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export 'user/user.dart';
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ final class UserLocalRepository {
/// Fetches all users from the local cache
/// incase of an error it will return a [String] to the left
/// and a [List<UserData>] to the right incase users were retrived
Future<Either<String, List<UserData>>> fetchAllUsers() async {
Future<Either<String, UserData?>> fetchUser() async {
try {
final users = await _localDb.user.select().get();
return right(users);
final user = await _localDb.user.select().getSingleOrNull();
return right(user);
} catch (e) {
return left("Failed to retrieve users with message ${e.toString()}");
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
import 'package:academia/database/database.dart';
import 'package:academia/features/auth/repository/user_local_repository.dart';
import 'package:academia/features/auth/repository/user_remote_repository.dart';
import 'package:dartz/dartz.dart';
import 'package:get_it/get_it.dart';
import 'package:magnet/magnet.dart';
import 'user_local_repository.dart';
import 'user_remote_repository.dart';

final class UserRepository {
final UserLocalRepository _userLocalRepository = UserLocalRepository();
Expand All @@ -12,8 +10,8 @@ final class UserRepository {
/// Fetches all users from the local cache
/// incase of an error it will return a [String] to the left
/// and a [List<UserData>] to the right incase users were retrived
Future<Either<String, List<UserData>>> fetchAllUsersFromCache() async {
return await _userLocalRepository.fetchAllUsers();
Future<Either<String, UserData?>> fetchUserFromCache() async {
return await _userLocalRepository.fetchUser();
}

/// Adds or updates a user's information into local cache depending
Expand Down
4 changes: 4 additions & 0 deletions lib/core/user/user.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export 'models/user.dart';
export 'models/user_profile.dart';
export 'models/user_credentials.dart';
export 'repository/user_repository.dart';
4 changes: 1 addition & 3 deletions lib/database/database.dart
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
import 'dart:io';

import 'package:academia/features/auth/models/user.dart';
import 'package:academia/features/auth/models/user_credentials.dart';
import 'package:academia/features/auth/models/user_profile.dart';
import 'package:academia/features/courses/models/course.dart';
import 'package:academia/features/todo/models/todo.dart';
import 'package:academia/core/core.dart';
import 'package:drift/drift.dart';
import 'package:drift/native.dart';
import 'package:drift_flutter/drift_flutter.dart';
Expand Down
51 changes: 29 additions & 22 deletions lib/database/database.g.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 1 addition & 3 deletions lib/features/auth/auth.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,2 @@
export 'cubit/auth_cubit.dart';
export 'cubit/auth_states.dart';
export './views/login_page.dart';
export './views/user_selection_page.dart';
export 'bloc/auth_bloc.dart';
42 changes: 42 additions & 0 deletions lib/features/auth/bloc/auth_bloc.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import 'package:academia/core/user/repository/user_repository.dart';
import 'package:academia/database/database.dart';
import 'package:academia/exports/barrel.dart';
import 'package:flutter_bloc/flutter_bloc.dart';

part 'auth_event.dart';
part 'auth_state.dart';

final class AuthBloc extends Bloc<AuthEvent, AuthState> {
final UserRepository _userRepository = UserRepository();

AuthBloc() : super(AuthInitialState()) {
on<AppLaunchDetected>((event, emit) async {
emit(AuthLoadingState());
final result = await _userRepository.fetchUserFromCache();
return result.fold((error) {
return emit(AuthErrorState(error: error));
}, (user) {
if (user == null) {
return emit(AuthErrorState(error: "No such user"));
}
return emit(AuthenticatedState(user: user));
});
});

on<AuthenticationRequested>((event, emit) {
if (event.password.trim().isEmpty) {
return emit(AuthErrorState(error: "Please enter a valid password"));
}
if (event.admno.trim().isEmpty) {
return emit(
AuthErrorState(error: "Please enter a valid admission number"),
);
}

emit(AuthLoadingState());
final result = await _userRepository.authenticateRemotely(

)
});
}
}
10 changes: 10 additions & 0 deletions lib/features/auth/bloc/auth_event.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
part of 'auth_bloc.dart';

sealed class AuthEvent {}

final class AppLaunchDetected extends AuthEvent {}

final class AuthenticationRequested extends AuthEvent {
final String admno, password;
AuthenticationRequested({required this.admno, required this.password});
}
18 changes: 18 additions & 0 deletions lib/features/auth/bloc/auth_state.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
part of 'auth_bloc.dart';

@immutable
sealed class AuthState {}

final class AuthInitialState extends AuthState {}

final class AuthLoadingState extends AuthState {}

final class AuthErrorState extends AuthState {
final String error;
AuthErrorState({required this.error});
}

final class AuthenticatedState extends AuthState {
final UserData user;
AuthenticatedState({required this.user});
}
89 changes: 0 additions & 89 deletions lib/features/auth/cubit/auth_cubit.dart

This file was deleted.

Loading

0 comments on commit 2c67a6a

Please sign in to comment.