Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
mo7amedaliEbaid committed Jul 19, 2024
1 parent 03b86c0 commit bf2bde8
Show file tree
Hide file tree
Showing 13 changed files with 322 additions and 197 deletions.
30 changes: 0 additions & 30 deletions .github/workflows/flutter_build.yml

This file was deleted.

3 changes: 2 additions & 1 deletion lib/application/application.dart
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,5 @@ export 'cubits/search/search_cubit.dart';
export 'cubits/navigation_cubit/navigation_cubit.dart';
export 'cubits/cart/cart_cubit.dart';
export 'cubits/place_order/place_order_cubit.dart';
export 'cubits/payment/payment_cubit.dart';
export 'cubits/payment/payment_cubit.dart';
export 'cubits/get_orders/get_orders_cubit.dart';
17 changes: 17 additions & 0 deletions lib/application/cubits/cart/cart_cubit.dart
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,21 @@ class CartCubit extends Cubit<CartState> {

loadCart(userId);
}

void removeCart(String userId) async {
try {
await _repository.removeEntireCart(userId);
emit(
const CartLoaded(
[],
),
);
} catch (e) {
emit(
CartError(
e.toString(),
),
);
}
}
}
25 changes: 25 additions & 0 deletions lib/application/cubits/get_orders/get_orders_cubit.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import 'package:equatable/equatable.dart';
import 'package:flutter_bloc/flutter_bloc.dart';

import '../../../models/models.dart';
import 'package:garcon/repositories/repositories.dart';

part 'get_orders_state.dart';

class GetOrdersCubit extends Cubit<GetOrdersState> {
final BaseOrdersRepository ordersRepository;

GetOrdersCubit({required this.ordersRepository}) : super(GetOrdersInitial());

void getOrders(String userId) {
emit(GetOrdersLoading());
ordersRepository.getOrders(userId).listen(
(orders) {
emit(GetOrdersLoaded(orders: orders));
},
onError: (error) {
emit(GetOrdersError(errorMessage: error.toString()));
},
);
}
}
30 changes: 30 additions & 0 deletions lib/application/cubits/get_orders/get_orders_state.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
part of 'get_orders_cubit.dart';

abstract class GetOrdersState extends Equatable {
const GetOrdersState();

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

class GetOrdersInitial extends GetOrdersState {}

class GetOrdersLoading extends GetOrdersState {}

class GetOrdersLoaded extends GetOrdersState {
final List<PickupsOrder> orders;

const GetOrdersLoaded({required this.orders});

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

class GetOrdersError extends GetOrdersState {
final String errorMessage;

const GetOrdersError({required this.errorMessage});

@override
List<Object?> get props => [errorMessage];
}
5 changes: 5 additions & 0 deletions lib/core/app/app.dart
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,11 @@ class MyApp extends StatelessWidget {
BlocProvider(
create: (context) => PaymentCubit(),
),
BlocProvider(
create: (context) => GetOrdersCubit(
ordersRepository: OrdersRepository(),
),
)
],
child: MaterialApp(
title: 'Garcon',
Expand Down
3 changes: 2 additions & 1 deletion lib/core/core.dart
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,5 @@ export 'validator/validator.dart';

//functions
export 'functions/url_launcher.dart';
export 'functions/calculate_total_price.dart';
export 'functions/calculate_total_price.dart';
export 'functions/convert_currency.dart';
12 changes: 12 additions & 0 deletions lib/core/validator/validator.dart
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ class Validators {
}
return null;
}

String? validateUserName(String? value) {
if (value == null || value.isEmpty) return 'First name is required';
if (value.length < 2) {
Expand All @@ -44,6 +45,17 @@ class Validators {
return null;
}

String? validateCustomerName(String? value) {
if (value == null || value.isEmpty) return 'Customer name is required';
if (value.length < 2) {
return 'Customer name must be at least 2 characters long';
}
if (!RegExp(r'^[a-zA-Z ]+$').hasMatch(value)) {
return 'Customer name must be alphabetic';
}
return null;
}

/* String? validatePhoneNumber(String? value) {
if (value == null || value.isEmpty) return 'Phone number is required';
if (!RegExp(r'^[0-9]{11}$').hasMatch(value)) {
Expand Down
45 changes: 24 additions & 21 deletions lib/models/order.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,45 +5,48 @@ import 'package:firebase_auth/firebase_auth.dart';
class PickupsOrder extends Equatable {
final String name;
final String branch;
final String date;

// final String date;
final String time;
final String personsNumber;

// final String personsNumber;
final String userId;
final String restaurant;
final String amount;

// final String amount;

const PickupsOrder({
required this.time,
required this.personsNumber,
// required this.personsNumber,
required this.userId,
required this.name,
required this.branch,
required this.date,
// required this.date,
required this.restaurant,
required this.amount,
// required this.amount,
});

@override
List<Object?> get props => [
name,
branch,
date,
time,
personsNumber,
userId,
restaurant,
amount,
];
name,
branch,
// date,
time,
//personsNumber,
userId,
restaurant,
//amount,
];

factory PickupsOrder.fromSnapshot(DocumentSnapshot snapshot) {
Map<String, dynamic> data = snapshot.data() as Map<String, dynamic>;
return PickupsOrder(
name: data['name'],
branch: data['branch'],
date: data['date'],
//date: data['date'],
time: data['time'],
amount: data['amount'],
personsNumber: data['personsNumber'],
//amount: data['amount'],
//personsNumber: data['personsNumber'],
userId: data['userId'],
restaurant: data['restaurant'],
);
Expand All @@ -53,11 +56,11 @@ class PickupsOrder extends Equatable {
return {
'name': name,
'branch': branch,
'date': date,
'personsNumber': personsNumber,
//'date': date,
//'personsNumber': personsNumber,
'time': time,
'restaurant': restaurant,
'amount': amount,
//'amount': amount,
'userId': FirebaseAuth.instance.currentUser!.uid,
};
}
Expand Down
Loading

0 comments on commit bf2bde8

Please sign in to comment.