Skip to content

Commit

Permalink
Merge pull request #33 from Sameera-Perera/feature/cart
Browse files Browse the repository at this point in the history
Feature/cart
  • Loading branch information
Sameera-Perera authored Jan 11, 2025
2 parents 5e7310b + 00edbe5 commit da8ff75
Show file tree
Hide file tree
Showing 52 changed files with 412 additions and 418 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
java-version: '12.x'
- uses: subosito/flutter-action@v1
with:
flutter-version: '3.10.0'
flutter-version: '3.24.3'
- run: flutter pub get
- run: flutter test
- run: flutter build apk --debug --split-per-abi
Expand Down
4 changes: 4 additions & 0 deletions lib/core/constant/app_sizes.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@

const double kPaddingSmall = 8;
const double kPaddingMedium = 16;
const double paddingLarge = 24;
3 changes: 2 additions & 1 deletion lib/core/constant/strings.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
const String appTitle = 'EShop';

// Networking and APIs
const String baseUrl = 'https://e-commerce-mock-api-webservice.onrender.com';
// const String baseUrl = 'https://e-commerce-mock-api-webservice.onrender.com';
const String baseUrl = 'http://192.168.1.43:4000';
const String defaultApiKey = '';
const String defaultSources = '';

Expand Down
4 changes: 2 additions & 2 deletions lib/data/data_sources/remote/cart_remote_data_source.dart
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class CartRemoteDataSourceSourceImpl implements CartRemoteDataSource {

@override
Future<CartItemModel> addToCart(CartItemModel cartItem, String token) async {
final response = await client.post(Uri.parse('$baseUrl/users/cart'),
final response = await client.post(Uri.parse('$baseUrl/carts'),
headers: {
'Content-Type': 'application/json',
'Authorization': 'Bearer $token',
Expand All @@ -34,7 +34,7 @@ class CartRemoteDataSourceSourceImpl implements CartRemoteDataSource {
@override
Future<List<CartItemModel>> syncCart(
List<CartItemModel> cart, String token) async {
final response = await client.post(Uri.parse('$baseUrl/users/cart/sync'),
final response = await client.post(Uri.parse('$baseUrl/carts/sync'),
headers: {
'Content-Type': 'application/json',
'Authorization': 'Bearer $token',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class DeliveryInfoRemoteDataSourceImpl implements DeliveryInfoRemoteDataSource {
@override
Future<List<DeliveryInfoModel>> getDeliveryInfo(token) async {
final response = await client.get(
Uri.parse('$baseUrl/users/delivery-info'),
Uri.parse('$baseUrl/delivery-info'),
headers: {
'Content-Type': 'application/json',
'Authorization': 'Bearer $token',
Expand Down
8 changes: 4 additions & 4 deletions lib/data/models/cart/cart_item_model.dart
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@ String cartItemModelToJson(List<CartItemModel> data) =>

class CartItemModel extends CartItem {
const CartItemModel({
String? id,
required ProductModel product,
required PriceTagModel priceTag,
}) : super(id: id, product: product, priceTag: priceTag);
super.id,
required ProductModel super.product,
required PriceTagModel super.priceTag,
});

factory CartItemModel.fromJson(Map<String, dynamic> json) {
return CartItemModel(
Expand Down
12 changes: 4 additions & 8 deletions lib/data/models/category/category_model.dart
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,10 @@ String categoryModelListToJson(List<CategoryModel> data) =>

class CategoryModel extends Category {
const CategoryModel({
required String id,
required String name,
required String image,
}) : super(
id: id,
name: name,
image: image,
);
required super.id,
required super.name,
required super.image,
});

factory CategoryModel.fromJson(Map<String, dynamic> json) => CategoryModel(
id: json["_id"],
Expand Down
19 changes: 7 additions & 12 deletions lib/data/models/order/order_details_model.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@ import 'order_item_model.dart';

List<OrderDetailsModel> orderDetailsModelListFromJson(String str) =>
List<OrderDetailsModel>.from(
json.decode(str)['data'].map((x) => OrderDetailsModel.fromJson(x)));
json.decode(str).map((x) => OrderDetailsModel.fromJson(x)));

List<OrderDetailsModel> orderDetailsModelListFromLocalJson(String str) =>
List<OrderDetailsModel>.from(
json.decode(str).map((x) => OrderDetailsModel.fromJson(x)));

OrderDetailsModel orderDetailsModelFromJson(String str) =>
OrderDetailsModel.fromJson(json.decode(str)['data']);
OrderDetailsModel.fromJson(json.decode(str));

String orderModelListToJsonBody(List<OrderDetailsModel> data) =>
json.encode(List<dynamic>.from(data.map((x) => x.toJsonBody())));
Expand All @@ -26,16 +26,11 @@ String orderDetailsModelToJson(OrderDetailsModel data) =>

class OrderDetailsModel extends OrderDetails {
const OrderDetailsModel({
required String id,
required List<OrderItemModel> orderItems,
required DeliveryInfoModel deliveryInfo,
required num discount,
}) : super(
id: id,
orderItems: orderItems,
deliveryInfo: deliveryInfo,
discount: discount,
);
required super.id,
required List<OrderItemModel> super.orderItems,
required DeliveryInfoModel super.deliveryInfo,
required super.discount,
});

factory OrderDetailsModel.fromJson(Map<String, dynamic> json) =>
OrderDetailsModel(
Expand Down
18 changes: 6 additions & 12 deletions lib/data/models/order/order_item_model.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,12 @@ import '../product/product_model.dart';

class OrderItemModel extends OrderItem {
const OrderItemModel({
required String id,
required ProductModel product,
required PriceTagModel priceTag,
required num price,
required num quantity,
}) : super(
id: id,
product: product,
priceTag: priceTag,
price: price,
quantity: quantity,
);
required super.id,
required ProductModel super.product,
required PriceTagModel super.priceTag,
required super.price,
required super.quantity,
});

factory OrderItemModel.fromJson(Map<String, dynamic> json) => OrderItemModel(
id: json["_id"],
Expand Down
6 changes: 2 additions & 4 deletions lib/data/models/product/pagination_data_model.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,10 @@ import '../../../domain/entities/product/pagination_meta_data.dart';
class PaginationMetaDataModel extends PaginationMetaData {
PaginationMetaDataModel({
required int page,
required int pageSize,
required int total,
required super.pageSize,
required super.total,
}): super(
limit: page,
pageSize: pageSize,
total: total,
);

factory PaginationMetaDataModel.fromJson(Map<String, dynamic> json) => PaginationMetaDataModel(
Expand Down
12 changes: 4 additions & 8 deletions lib/data/models/product/price_tag_model.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,10 @@ import 'package:eshop/domain/entities/product/price_tag.dart';

class PriceTagModel extends PriceTag {
PriceTagModel({
required String id,
required String name,
required num price,
}) : super(
id: id,
name: name,
price: price,
);
required super.id,
required super.name,
required super.price,
});

factory PriceTagModel.fromJson(Map<String, dynamic> json) => PriceTagModel(
id: json["_id"],
Expand Down
27 changes: 9 additions & 18 deletions lib/data/models/product/product_model.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,15 @@ import 'price_tag_model.dart';

class ProductModel extends Product {
const ProductModel({
required String id,
required String name,
required String description,
required List<PriceTagModel> priceTags,
required List<CategoryModel> categories,
required List<String> images,
required DateTime createdAt,
required DateTime updatedAt,
}) : super(
id: id,
name: name,
description: description,
priceTags: priceTags,
categories: categories,
images: images,
createdAt: createdAt,
updatedAt: updatedAt,
);
required super.id,
required super.name,
required super.description,
required List<PriceTagModel> super.priceTags,
required List<CategoryModel> super.categories,
required super.images,
required super.createdAt,
required super.updatedAt,
});

factory ProductModel.fromJson(Map<String, dynamic> json) => ProductModel(
id: json["_id"],
Expand Down
31 changes: 11 additions & 20 deletions lib/data/models/user/delivery_info_model.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@ import 'dart:convert';
import '../../../domain/entities/user/delivery_info.dart';

DeliveryInfoModel deliveryInfoModelFromRemoteJson(String str) =>
DeliveryInfoModel.fromJson(json.decode(str)['data']);
DeliveryInfoModel.fromJson(json.decode(str));

DeliveryInfoModel deliveryInfoModelFromLocalJson(String str) =>
DeliveryInfoModel.fromJson(json.decode(str));

List<DeliveryInfoModel> deliveryInfoModelListFromRemoteJson(String str) =>
List<DeliveryInfoModel>.from(
json.decode(str)['data'].map((x) => DeliveryInfoModel.fromJson(x)));
json.decode(str).map((x) => DeliveryInfoModel.fromJson(x)));

List<DeliveryInfoModel> deliveryInfoModelListFromLocalJson(String str) =>
List<DeliveryInfoModel>.from(
Expand All @@ -24,24 +24,15 @@ String deliveryInfoModelListToJson(List<DeliveryInfoModel> data) =>

class DeliveryInfoModel extends DeliveryInfo {
const DeliveryInfoModel({
required String id,
required String firstName,
required String lastName,
required String addressLineOne,
required String addressLineTwo,
required String city,
required String zipCode,
required String contactNumber,
}) : super(
id: id,
firstName: firstName,
lastName: lastName,
addressLineOne: addressLineOne,
addressLineTwo: addressLineTwo,
city: city,
zipCode: zipCode,
contactNumber: contactNumber,
);
required super.id,
required super.firstName,
required super.lastName,
required super.addressLineOne,
required super.addressLineTwo,
required super.city,
required super.zipCode,
required super.contactNumber,
});

factory DeliveryInfoModel.fromJson(Map<String, dynamic> json) =>
DeliveryInfoModel(
Expand Down
15 changes: 5 additions & 10 deletions lib/data/models/user/user_model.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,11 @@ String userModelToJson(UserModel data) => json.encode(data.toJson());

class UserModel extends User {
const UserModel({
required String id,
required String firstName,
required String lastName,
required String email,
}) : super(
id: id,
firstName: firstName,
lastName: lastName,
email: email,
);
required super.id,
required super.firstName,
required super.lastName,
required super.email,
});

factory UserModel.fromJson(Map<String, dynamic> json) => UserModel(
id: json["_id"],
Expand Down
4 changes: 2 additions & 2 deletions lib/domain/usecases/cart/add_cart_item_usecase.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ import '../../../../../core/usecases/usecase.dart';
import '../../entities/cart/cart_item.dart';
import '../../repositories/cart_repository.dart';

class AddCartUseCase implements UseCase<void, CartItem> {
class AddCartUseCase implements UseCase<CartItem, CartItem> {
final CartRepository repository;
AddCartUseCase(this.repository);

@override
Future<Either<Failure, void>> call(CartItem params) async {
Future<Either<Failure, CartItem>> call(CartItem params) async {
return await repository.addToCart(params);
}
}
22 changes: 13 additions & 9 deletions lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import 'package:flutter/material.dart';
import 'package:flutter_easyloading/flutter_easyloading.dart';
import 'package:oktoast/oktoast.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:sizer/sizer.dart';

import 'core/constant/strings.dart';
import 'core/router/app_router.dart';
Expand Down Expand Up @@ -58,21 +59,24 @@ class MyApp extends StatelessWidget {
create: (context) => di.sl<DeliveryInfoActionCubit>(),
),
BlocProvider(
create: (context) => di.sl<DeliveryInfoFetchCubit>()..fetchDeliveryInfo(),
create: (context) =>
di.sl<DeliveryInfoFetchCubit>()..fetchDeliveryInfo(),
),
BlocProvider(
create: (context) => di.sl<OrderFetchCubit>()..getOrders(),
),
],
child: OKToast(
child: MaterialApp(
debugShowCheckedModeBanner: false,
initialRoute: AppRouter.home,
onGenerateRoute: AppRouter.onGenerateRoute,
title: appTitle,
theme: AppTheme.lightTheme,
builder: EasyLoading.init(),
),
child: Sizer(builder: (context, orientation, deviceType) {
return MaterialApp(
debugShowCheckedModeBanner: false,
initialRoute: AppRouter.home,
onGenerateRoute: AppRouter.onGenerateRoute,
title: appTitle,
theme: AppTheme.lightTheme,
builder: EasyLoading.init(),
);
}),
),
);
}
Expand Down
2 changes: 1 addition & 1 deletion lib/presentation/views/authentication/signin_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import '../../widgets/input_form_button.dart';
import '../../widgets/input_text_form_field.dart';

class SignInView extends StatefulWidget {
const SignInView({Key? key}) : super(key: key);
const SignInView({super.key});

@override
State<SignInView> createState() => _SignInViewState();
Expand Down
2 changes: 1 addition & 1 deletion lib/presentation/views/authentication/signup_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import '../../widgets/input_form_button.dart';
import '../../widgets/input_text_form_field.dart';

class SignUpScreen extends StatefulWidget {
const SignUpScreen({Key? key}) : super(key: key);
const SignUpScreen({super.key});

@override
State<SignUpScreen> createState() => _SignUpScreenState();
Expand Down
Loading

0 comments on commit da8ff75

Please sign in to comment.