Skip to content

Commit

Permalink
Merge branch 'cevheri:main' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
yusuf-gundogdu authored Nov 26, 2024
2 parents 50d2fb8 + 055bca2 commit 96c311e
Show file tree
Hide file tree
Showing 23 changed files with 1,070 additions and 445 deletions.
156 changes: 78 additions & 78 deletions docs/unittest.excalidraw

Large diffs are not rendered by default.

6 changes: 6 additions & 0 deletions lib/configuration/app_key_constants.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,9 @@ const Key loginButtonForgotPasswordKey = Key("loginButtonForgotPasswordKey");
const Key loginButtonRegisterKey = Key("loginButtonRegisterKey");
const Key loginButtonPasswordVisibilityKey = Key("loginButtonPasswordVisibilityKey");
const Key forgotPasswordButtonSubmit = Key("forgotPasswordButtonSubmit");

// register screen
const Key registerSubmitButtonKey = Key("registerSubmitButtonKey");
const Key registerFirstNameTextFieldKey = Key("registerFirstNameTextFieldKey");
const Key registerLastNameTextFieldKey = Key("registerLastNameTextFieldKey");
const Key registerEmailTextFieldKey = Key("registerEmailTextFieldKey");
7 changes: 5 additions & 2 deletions lib/data/repository/account_repository.dart
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,11 @@ class AccountRepository {
if (newUser == null) {
throw BadRequestException("User null");
}
if (newUser.email == null || newUser.email!.isEmpty || newUser.login == null || newUser.login!.isEmpty) {
throw BadRequestException("User email or login null");
if (newUser.email == null || newUser.email!.isEmpty) {
throw BadRequestException("User email null");
}
if (newUser.login == null || newUser.login!.isEmpty) {
newUser = newUser.copyWith(login: newUser.email);
}
if (newUser.langKey == null || newUser.langKey!.isEmpty) {
newUser = newUser.copyWith(langKey: "en");
Expand Down
7 changes: 4 additions & 3 deletions lib/generated/intl/messages_en.dart
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,10 @@ class MessageLookup extends MessageLookupByLibrary {
"account": MessageLookupByLibrary.simpleMessage("Account"),
"active": MessageLookupByLibrary.simpleMessage("Active"),
"admin": MessageLookupByLibrary.simpleMessage("Admin"),
"authority": MessageLookupByLibrary.simpleMessage("Authority"),
"authorities": MessageLookupByLibrary.simpleMessage("Authorities"),
"authorities_required":
MessageLookupByLibrary.simpleMessage("Authority is required"),
MessageLookupByLibrary.simpleMessage("Authorities is required"),
"authority": MessageLookupByLibrary.simpleMessage("Authority"),
"change_password":
MessageLookupByLibrary.simpleMessage("Change Password"),
"create_user": MessageLookupByLibrary.simpleMessage("Create User"),
Expand Down Expand Up @@ -117,7 +118,7 @@ class MessageLookup extends MessageLookupByLibrary {
"phone_number": MessageLookupByLibrary.simpleMessage("Phone Number"),
"register": MessageLookupByLibrary.simpleMessage("Register"),
"required_field":
MessageLookupByLibrary.simpleMessage("Required Field!"),
MessageLookupByLibrary.simpleMessage("Required Field"),
"required_phone_type": MessageLookupByLibrary.simpleMessage(
"Phone Type Required 5** *** ** ** "),
"required_range":
Expand Down
5 changes: 3 additions & 2 deletions lib/generated/intl/messages_tr.dart
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,10 @@ class MessageLookup extends MessageLookupByLibrary {
"account": MessageLookupByLibrary.simpleMessage("Hesabım"),
"active": MessageLookupByLibrary.simpleMessage("Aktif"),
"admin": MessageLookupByLibrary.simpleMessage("Admin"),
"authority": MessageLookupByLibrary.simpleMessage("Yetkiler"),
"authorities": MessageLookupByLibrary.simpleMessage("Roller"),
"authorities_required":
MessageLookupByLibrary.simpleMessage("Yetki gereklidir"),
"authority": MessageLookupByLibrary.simpleMessage("Rol"),
"change_password":
MessageLookupByLibrary.simpleMessage("Şifre Değiştir"),
"create_user":
Expand Down Expand Up @@ -119,7 +120,7 @@ class MessageLookup extends MessageLookupByLibrary {
"Password changed successfully"),
"phone_number": MessageLookupByLibrary.simpleMessage("Tel No"),
"register": MessageLookupByLibrary.simpleMessage("Kayıt Ol"),
"required_field": MessageLookupByLibrary.simpleMessage("Zorunlu Alan!"),
"required_field": MessageLookupByLibrary.simpleMessage("Zorunlu Alan"),
"required_phone_type": MessageLookupByLibrary.simpleMessage(
"Telefon numarası 5** *** ** ** formatında ve 10 karakter olmalıdır"),
"required_range":
Expand Down
17 changes: 13 additions & 4 deletions lib/generated/l10n.dart

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

2 changes: 1 addition & 1 deletion lib/l10n/intl_en.arb
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"name": "Name",
"success": "Success",
"failed": "Failed",
"required_field": "Required Field!",
"required_field": "Required Field",
"required_range": "Range is required",
"list": "List",
"edit_user": "Edit User",
Expand Down
2 changes: 1 addition & 1 deletion lib/l10n/intl_tr.arb
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"name": "İsim",
"success": "Başarılı",
"failed": "Başarısız",
"required_field": "Zorunlu Alan!",
"required_field": "Zorunlu Alan",
"required_range": "Aralık gereklidir",
"list": "Listele",
"edit_user": "Kullanıcı Düzenle",
Expand Down
2 changes: 1 addition & 1 deletion lib/main/app.dart
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ class App extends StatelessWidget {
},
ApplicationRoutes.settings: (context) {
return BlocProvider<SettingsBloc>(
create: (context) => SettingsBloc(accountRepository: AccountRepository()), child: const SettingsScreen());
create: (context) => SettingsBloc(), child: SettingsScreen());
},
ApplicationRoutes.forgotPassword: (context) {
return BlocProvider<ForgotPasswordBloc>(
Expand Down
29 changes: 22 additions & 7 deletions lib/presentation/screen/register/bloc/register_bloc.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,35 +2,50 @@ import 'dart:async';

import 'package:equatable/equatable.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:flutter_bloc_advance/configuration/app_logger.dart';
import 'package:flutter_bloc_advance/data/app_api_exception.dart';

import '../../../../data/models/user.dart';
import '../../../../data/repository/account_repository.dart';

part 'register_event.dart';

part 'register_state.dart';

class RegisterBloc extends Bloc<RegisterEvent, RegisterState> {
RegisterBloc({required AccountRepository accountRepository})
: _accountRepository = accountRepository,
super(const RegisterState()) {
on<RegisterEmailChanged>(_onSubmit);
super(const RegisterInitialState()) {
on<RegisterFormSubmitted>(_onSubmit);
}

static final _log = AppLogger.getLogger("RegisterBloc");

final AccountRepository _accountRepository;

@override
void onTransition(Transition<RegisterEvent, RegisterState> transition) {
super.onTransition(transition);
_log.trace("current state: ${transition.currentState.toString()}");
_log.trace("event: ${transition.event.toString()}");
_log.trace("next state: ${transition.nextState.toString()}");
}

FutureOr<void> _onSubmit(RegisterEmailChanged event, Emitter<RegisterState> emit) async {
emit(RegisterInitialState());
FutureOr<void> _onSubmit(RegisterFormSubmitted event, Emitter<RegisterState> emit) async {
_log.debug("BEGIN: onSubmit RegisterFormSubmitted event: {}", [event.createUser.toString()]);
emit(const RegisterLoadingState());
try {
await _accountRepository.register(event.createUser);
emit(RegisterCompletedState());
var user = await _accountRepository.register(event.createUser);
if (user != null) {
emit(RegisterCompletedState(user: user));
_log.debug("END:onSubmit RegisterFormSubmitted event success: {}", [user.toString()]);
} else {
_log.error("END:onSubmit RegisterFormSubmitted event failure: {}", ["Register Error"]);
throw BadRequestException("Register Error");
}
} catch (e) {
emit(const RegisterErrorState(message: "Register Error"));
rethrow;
_log.error("END:onSubmit RegisterFormSubmitted event failure: {}", ["Register Error"]);
}
}
}
14 changes: 6 additions & 8 deletions lib/presentation/screen/register/bloc/register_event.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,16 @@ part of 'register_bloc.dart';

abstract class RegisterEvent extends Equatable {
const RegisterEvent();

@override
List<Object> get props => [];

@override
bool get stringify => true;
}

class RegisterEmailChanged extends RegisterEvent {
class RegisterFormSubmitted extends RegisterEvent {
final User createUser;

const RegisterEmailChanged({
const RegisterFormSubmitted({
required this.createUser,
});

@override
List<Object> get props => [createUser];
}

30 changes: 18 additions & 12 deletions lib/presentation/screen/register/bloc/register_state.dart
Original file line number Diff line number Diff line change
@@ -1,41 +1,47 @@
part of 'register_bloc.dart';

enum RegisterStatus { none, authenticating, authenticated, failure }
enum RegisterStatus { initial, loading, success, error }

class RegisterState extends Equatable {
final String email;
final User? user;
final RegisterStatus status;

static const String authenticationFailKey = 'error.authenticate';

const RegisterState({
this.email = '',
this.status = RegisterStatus.none,
this.user,
this.status = RegisterStatus.initial,
});

RegisterState copyWith({
String? email,
User? user,
RegisterStatus? status,
}) {
return RegisterState(
email: email ?? this.email,
user: user ?? this.user,
status: status ?? this.status,
);
}

@override
List<Object> get props => [email, status];
List<Object> get props => [status, user ?? ''];

@override
bool get stringify => true;
}

class RegisterInitialState extends RegisterState {}
class RegisterInitialState extends RegisterState {
const RegisterInitialState() : super(status: RegisterStatus.initial);
}

class RegisterCompletedState extends RegisterState {}
class RegisterLoadingState extends RegisterState {
const RegisterLoadingState() : super(status: RegisterStatus.loading);
}

class RegisterCompletedState extends RegisterState {
const RegisterCompletedState({required User user}) : super(user: user, status: RegisterStatus.success);
}

class RegisterErrorState extends RegisterState {
final String message;

const RegisterErrorState({required this.message});
const RegisterErrorState({required this.message}) : super(status: RegisterStatus.error);
}
Loading

0 comments on commit 96c311e

Please sign in to comment.