Initial commit - app-padrao-1.0

This commit is contained in:
Erik Silva
2025-12-19 23:29:24 -03:00
commit ec76d3d633
205 changed files with 13131 additions and 0 deletions

View File

@@ -0,0 +1,94 @@
import 'package:hive/hive.dart';
part 'product_model.g.dart';
@HiveType(typeId: 2)
class ProductModel extends HiveObject {
@HiveField(0)
final String id;
@HiveField(1)
final String userId;
@HiveField(2)
final String name;
@HiveField(3)
final String category; // 'pastas', 'bebidas', 'acessorios', 'outros'
@HiveField(4)
final int quantity;
@HiveField(5)
final double purchasePrice;
@HiveField(6)
final double salePrice;
@HiveField(7)
final int minStock;
@HiveField(8)
final String? imagePath;
ProductModel({
required this.id,
required this.userId,
required this.name,
required this.category,
required this.quantity,
required this.purchasePrice,
required this.salePrice,
required this.minStock,
this.imagePath,
});
bool get isLowStock => quantity <= minStock;
ProductModel copyWith({
String? id,
String? userId,
String? name,
String? category,
int? quantity,
double? purchasePrice,
double? salePrice,
int? minStock,
String? imagePath,
}) {
return ProductModel(
id: id ?? this.id,
userId: userId ?? this.userId,
name: name ?? this.name,
category: category ?? this.category,
quantity: quantity ?? this.quantity,
purchasePrice: purchasePrice ?? this.purchasePrice,
salePrice: salePrice ?? this.salePrice,
minStock: minStock ?? this.minStock,
imagePath: imagePath ?? this.imagePath,
);
}
}
class ProductCategories {
static const String pastes = 'pastas';
static const String beverages = 'bebidas';
static const String accessories = 'acessorios';
static const String other = 'outros';
static List<String> get all => [pastes, beverages, accessories, other];
static String getDisplayName(String category) {
switch (category) {
case pastes:
return 'Pastas e Pomadas';
case beverages:
return 'Bebidas (Frigobar)';
case accessories:
return 'Acessórios';
case other:
return 'Outros';
default:
return category;
}
}
}

View File

@@ -0,0 +1,65 @@
// GENERATED CODE - DO NOT MODIFY BY HAND
part of 'product_model.dart';
// **************************************************************************
// TypeAdapterGenerator
// **************************************************************************
class ProductModelAdapter extends TypeAdapter<ProductModel> {
@override
final int typeId = 2;
@override
ProductModel read(BinaryReader reader) {
final numOfFields = reader.readByte();
final fields = <int, dynamic>{
for (int i = 0; i < numOfFields; i++) reader.readByte(): reader.read(),
};
return ProductModel(
id: fields[0] as String,
userId: fields[1] as String,
name: fields[2] as String,
category: fields[3] as String,
quantity: fields[4] as int,
purchasePrice: fields[5] as double,
salePrice: fields[6] as double,
minStock: fields[7] as int,
imagePath: fields[8] as String?,
);
}
@override
void write(BinaryWriter writer, ProductModel obj) {
writer
..writeByte(9)
..writeByte(0)
..write(obj.id)
..writeByte(1)
..write(obj.userId)
..writeByte(2)
..write(obj.name)
..writeByte(3)
..write(obj.category)
..writeByte(4)
..write(obj.quantity)
..writeByte(5)
..write(obj.purchasePrice)
..writeByte(6)
..write(obj.salePrice)
..writeByte(7)
..write(obj.minStock)
..writeByte(8)
..write(obj.imagePath);
}
@override
int get hashCode => typeId.hashCode;
@override
bool operator ==(Object other) =>
identical(this, other) ||
other is ProductModelAdapter &&
runtimeType == other.runtimeType &&
typeId == other.typeId;
}

View File

@@ -0,0 +1,90 @@
import 'package:uuid/uuid.dart';
import 'package:barber_app/core/database/database_service.dart';
import 'package:barber_app/features/products/data/models/product_model.dart';
class ProductRepository {
final _uuid = const Uuid();
String? get _currentUserId => DatabaseService.getCurrentUserId();
// Criar produto
Future<ProductModel?> createProduct({
required String name,
required String category,
required int quantity,
required double purchasePrice,
required double salePrice,
int minStock = 5,
String? imagePath,
}) async {
if (_currentUserId == null) return null;
final product = ProductModel(
id: _uuid.v4(),
userId: _currentUserId!,
name: name.trim(),
category: category,
quantity: quantity,
purchasePrice: purchasePrice,
salePrice: salePrice,
minStock: minStock,
imagePath: imagePath,
);
await DatabaseService.productsBoxInstance.put(product.id, product);
return product;
}
// Listar todos os produtos
List<ProductModel> getAllProducts() {
if (_currentUserId == null) return [];
return DatabaseService.productsBoxInstance.values
.where((p) => p.userId == _currentUserId)
.toList()
..sort((a, b) => a.name.compareTo(b.name));
}
// Produtos por categoria
List<ProductModel> getProductsByCategory(String category) {
return getAllProducts().where((p) => p.category == category).toList();
}
// Produtos com estoque baixo
List<ProductModel> getLowStockProducts() {
return getAllProducts().where((p) => p.isLowStock).toList();
}
// Atualizar produto
Future<ProductModel?> updateProduct(ProductModel product) async {
await DatabaseService.productsBoxInstance.put(product.id, product);
return product;
}
// Atualizar quantidade
Future<ProductModel?> updateQuantity(String id, int newQuantity) async {
final product = DatabaseService.productsBoxInstance.get(id);
if (product == null) return null;
final updated = product.copyWith(quantity: newQuantity);
await DatabaseService.productsBoxInstance.put(id, updated);
return updated;
}
// Deletar produto
Future<void> deleteProduct(String id) async {
await DatabaseService.productsBoxInstance.delete(id);
}
// Buscar por ID
ProductModel? getProductById(String id) {
return DatabaseService.productsBoxInstance.get(id);
}
// Total em estoque (valor de compra)
double getTotalStockValue() {
return getAllProducts().fold(
0.0,
(sum, p) => sum + (p.purchasePrice * p.quantity),
);
}
}