12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697 |
- import 'package:conalep_pos/data/api_response.dart';
- import 'package:sqflite/sqflite.dart';
- import '../models/models.dart';
- import '../services/base_service.dart';
- class ProductoService extends BaseService {
- String endPoint = '/admin/categoria';
- //Consulta de la lista de Sala
- Map<String, String> defaultQueryParameters = {
- "limite": "10",
- "ordenar": "id-desc",
- "pagina": "1"
- };
- Future<List<Producto>> fetchList() async {
- final response =
- await get(endPoint, queryParameters: defaultQueryParameters);
- final respuesta = ApiResponse(response);
- List<Producto> productos = [];
- if (respuesta.isOk && respuesta.resultados!.isNotEmpty) {
- for (var x in respuesta.resultados!) {
- final producto = Producto.fromJson(x);
- productos.add(producto);
- }
- }
- return productos;
- }
- Future<ApiResponse> postProducto({
- required String nombre,
- required String descripcion,
- String? descuento,
- required int existencia,
- required int idCategoria,
- required String precio,
- String? venceDescuento,
- }) async {
- var response = await post(
- '$endPoint/guardar',
- body: {
- 'descripcion': descripcion,
- 'nombre': nombre,
- 'descuento': descuento,
- 'existencia': existencia,
- 'idCategoria': idCategoria,
- 'precio': precio,
- 'venceDescuento': venceDescuento,
- },
- withAuth: true,
- );
- return ApiResponse(response);
- }
- Future<ApiResponse> editProducto({
- required int id,
- required String nombre,
- required String descripcion,
- String? descuento,
- required int existencia,
- required int idCategoria,
- required String precio,
- String? venceDescuento,
- }) async {
- var response = await post(
- endPoint,
- body: {
- 'id': id,
- 'descripcion': descripcion,
- 'nombre': nombre,
- 'descuento': descuento,
- 'existencia': existencia,
- 'idCategoria': idCategoria,
- 'precio': precio,
- 'venceDescuento': venceDescuento,
- },
- withAuth: true,
- );
- return ApiResponse(response);
- }
- Future<ApiResponse> deleteProducto({required int id}) async {
- var response = await delete(
- '$endPoint/eliminar',
- body: {
- 'id': id,
- },
- withAuth: true,
- );
- return ApiResponse(response);
- }
- }
|