Skip to content

Commit

Permalink
add crud operation and realization
Browse files Browse the repository at this point in the history
  • Loading branch information
Taverz committed Aug 23, 2024
1 parent 918aacf commit 4f3ac89
Show file tree
Hide file tree
Showing 17 changed files with 493 additions and 25 deletions.
4 changes: 2 additions & 2 deletions lib/main.dart
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import 'package:flutter/material.dart';
import 'package:ui_kit/ui_kit.dart';
import 'package:waiter_test/src/features/sales_mode/pages/sales_page.dart';
import 'package:waiter_test/src/features/area/pages/area_page.dart';

void main() {
runApp(
MaterialApp(
theme: ThemeData(
scaffoldBackgroundColor: ColorsApp.colorsApp.whiteSimple,
),
home: const SalesPage(),
home: const AreaSelectPage(),
),
);
}
30 changes: 26 additions & 4 deletions lib/src/features/area/pages/area_page.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import 'package:flutter/material.dart';
import 'package:ui_kit/ui_kit.dart';

import '../../sales_mode/pages/sales_page.dart';

class AreaSelectPage extends StatelessWidget {
const AreaSelectPage({super.key});
@override
Expand All @@ -20,14 +22,24 @@ class AreaSelectPage extends StatelessWidget {
title: 'Основной зал',
backgroundColor: Colors.yellow.shade100,
onTap: () {
//TODO:
Navigator.push(
context,
MaterialPageRoute(
builder: (_) => const SalesPage(),
),
);
},
),
AreSelectionButton.active(
title: 'Летка',
backgroundColor: Colors.yellow.shade100,
onTap: () {
//TODO:
Navigator.push(
context,
MaterialPageRoute(
builder: (_) => const SalesPage(),
),
);
},
),
AreaSelectionButtonWithIcon.active(
Expand All @@ -36,7 +48,12 @@ class AreaSelectPage extends StatelessWidget {
backgroundColor: Colors.white,
backgroundIconColor: Colors.yellow.shade100,
onTap: () {
//TODO:
Navigator.push(
context,
MaterialPageRoute(
builder: (_) => const SalesPage(),
),
);
},
),
AreaSelectionButtonWithIcon.active(
Expand All @@ -45,7 +62,12 @@ class AreaSelectPage extends StatelessWidget {
backgroundColor: Colors.white,
backgroundIconColor: Colors.blue.shade100,
onTap: () {
//TODO:
Navigator.push(
context,
MaterialPageRoute(
builder: (_) => const SalesPage(),
),
);
},
),
],
Expand Down
2 changes: 2 additions & 0 deletions packages/api_client/lib/api_client.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
library api_client;

export 'models/models.dart';

// Call this
export 'core/core.dart';
// ->
Expand Down
6 changes: 6 additions & 0 deletions packages/api_client/lib/core/database/databas_local.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import '../../interface/crud/crud_operation_interface.dart';
import '../../mock/fixture_crud_operation_interface.dart';

class DatabBaseLocal {
static GroupCRUDOperation get currentDataBase => SQLORMFixture();
}
31 changes: 31 additions & 0 deletions packages/api_client/lib/interface/crud/crud_operation.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import '../../models/models.dart';

abstract class CRUDoperationDBProductGroup {
Future<int> createGroup(ProductGroup item);

Future<List<ProductGroup>> readAllGroup();

Future<int> updateGroup(ProductGroup item);

Future<int> deleteGroup(int id);
}

abstract class CRUDoperationDBProduct {
Future<int> createProduct(Product item);

Future<List<Product>> readAllProduct();

Future<int> updateProduct(Product item);

Future<int> deleteProduct(int id);
}

abstract class CRUDoperationDBOrder {
Future<int> createOrder(Order item);

Future<List<Order>> readAllOrder();

Future<int> updateOrder(Order item);

Future<int> deleteOrder(int id);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
import 'package:api_client/models/models.dart';

import 'crud_operation.dart';

abstract class GroupCRUDOperation
implements
CRUDoperationDBProductGroup,
CRUDoperationDBProduct,
CRUDoperationDBOrder {
@override
Future<int> createGroup(ProductGroup item) {
throw UnimplementedError();
}

@override
Future<int> createOrder(Order item) {
throw UnimplementedError();
}

@override
Future<int> createProduct(Product item) {
throw UnimplementedError();
}

@override
Future<int> deleteGroup(int id) {
throw UnimplementedError();
}

@override
Future<int> deleteOrder(int id) {
throw UnimplementedError();
}

@override
Future<int> deleteProduct(int id) {
throw UnimplementedError();
}

@override
Future<List<ProductGroup>> readAllGroup() {
throw UnimplementedError();
}

@override
Future<List<Order>> readAllOrder() {
throw UnimplementedError();
}

@override
Future<List<Product>> readAllProduct() {
throw UnimplementedError();
}

@override
Future<int> updateGroup(ProductGroup item) {
throw UnimplementedError();
}

@override
Future<int> updateOrder(Order item) {
throw UnimplementedError();
}

@override
Future<int> updateProduct(Product item) {
throw UnimplementedError();
}
}
104 changes: 104 additions & 0 deletions packages/api_client/lib/mock/fixture_crud_operation_interface.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
import 'package:api_client/interface/crud/crud_operation_interface.dart';
import 'package:api_client/models/models.dart';

class SQLORMFixture implements GroupCRUDOperation {
final List<ProductGroup> _productGroups = [
ProductGroup(name: "Группа 1"),
ProductGroup(name: "Группа 2"),
];
final List<Product> _products = [
Product(name: "Товар 1.2", groupId: 1),
Product(name: "Товар 2.3", groupId: 1),
Product(name: "Товар 3.3", groupId: 2),
];
final List<Order> _orders = [
Order(productId: 1, quantity: 2),
Order(productId: 2, quantity: 1),
];

@override
Future<int> createGroup(ProductGroup item) async {
_productGroups
.add(ProductGroup(id: _productGroups.length + 1, name: item.name));
return _productGroups.length;
}

@override
Future<List<ProductGroup>> readAllGroup() async {
return _productGroups;
}

@override
Future<int> updateGroup(ProductGroup item) async {
final index = _productGroups.indexWhere((group) => group.id == item.id);
if (index != -1) {
_productGroups[index] = item;
return 1;
}
return 0;
}

@override
Future<int> deleteGroup(int id) async {
_productGroups.removeWhere((group) => group.id == id);
return 1;
}

@override
Future<int> createProduct(Product item) async {
_products.add(Product(
id: _products.length + 1, name: item.name, groupId: item.groupId));
return _products.length;
}

@override
Future<List<Product>> readAllProduct() async {
return _products;
}

@override
Future<int> updateProduct(Product item) async {
final index = _products.indexWhere((product) => product.id == item.id);
if (index != -1) {
_products[index] = item;
return 1;
}
return 0;
}

@override
Future<int> deleteProduct(int id) async {
_products.removeWhere((product) => product.id == id);
return 1;
}

@override
Future<int> createOrder(Order item) async {
_orders.add(Order(
id: _orders.length + 1,
productId: item.productId,
quantity: item.quantity));
return _orders.length;
}

@override
Future<List<Order>> readAllOrder() async {
return _orders;
}

@override
Future<int> updateOrder(Order item) async {
final index = _orders.indexWhere((order) => order.id == item.id);
if (index != -1) {
_orders[index] = item;
return 1;
}
return 0;
}

@override
Future<int> deleteOrder(int id) async {
_orders.removeWhere((order) => order.id == id);
return 1;
}
}
35 changes: 35 additions & 0 deletions packages/api_client/lib/models/model_order.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
class Order {
final int? id;
final int productId;
final int quantity;

Order({this.id, required this.productId, required this.quantity});

Map<String, dynamic> toMap() {
return {
'id': id,
'product_id': productId,
'quantity': quantity,
};
}

static Order fromMap(Map<String, dynamic> map) {
return Order(
id: map['id'],
productId: map['product_id'],
quantity: map['quantity'],
);
}

@override
bool operator ==(covariant Order other) {
if (identical(this, other)) return true;

return other.id == id &&
other.productId == productId &&
other.quantity == quantity;
}

@override
int get hashCode => id.hashCode ^ productId.hashCode ^ quantity.hashCode;
}
33 changes: 33 additions & 0 deletions packages/api_client/lib/models/model_product.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
class Product {
final int? id;
final String name;
final int groupId;

Product({this.id, required this.name, required this.groupId});

Map<String, dynamic> toMap() {
return {
'id': id,
'name': name,
'group_id': groupId,
};
}

static Product fromMap(Map<String, dynamic> map) {
return Product(
id: map['id'],
name: map['name'],
groupId: map['group_id'],
);
}

@override
bool operator ==(covariant Product other) {
if (identical(this, other)) return true;

return other.id == id && other.name == name && other.groupId == groupId;
}

@override
int get hashCode => id.hashCode ^ name.hashCode ^ groupId.hashCode;
}
Loading

0 comments on commit 4f3ac89

Please sign in to comment.