producto_service.dart 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. import 'package:conalep_pos/data/api_response.dart';
  2. import 'package:sqflite/sqflite.dart';
  3. import '../models/models.dart';
  4. import '../services/base_service.dart';
  5. class ProductoService extends BaseService {
  6. String endPoint = '/admin/categoria';
  7. //Consulta de la lista de Sala
  8. Map<String, String> defaultQueryParameters = {
  9. "limite": "10",
  10. "ordenar": "id-desc",
  11. "pagina": "1"
  12. };
  13. Future<List<Producto>> fetchList() async {
  14. final response =
  15. await get(endPoint, queryParameters: defaultQueryParameters);
  16. final respuesta = ApiResponse(response);
  17. List<Producto> productos = [];
  18. if (respuesta.isOk && respuesta.resultados!.isNotEmpty) {
  19. for (var x in respuesta.resultados!) {
  20. final producto = Producto.fromJson(x);
  21. productos.add(producto);
  22. }
  23. }
  24. return productos;
  25. }
  26. Future<ApiResponse> postProducto({
  27. required String nombre,
  28. required String descripcion,
  29. String? descuento,
  30. required int existencia,
  31. required int idCategoria,
  32. required String precio,
  33. String? venceDescuento,
  34. }) async {
  35. var response = await post(
  36. '$endPoint/guardar',
  37. body: {
  38. 'descripcion': descripcion,
  39. 'nombre': nombre,
  40. 'descuento': descuento,
  41. 'existencia': existencia,
  42. 'idCategoria': idCategoria,
  43. 'precio': precio,
  44. 'venceDescuento': venceDescuento,
  45. },
  46. withAuth: true,
  47. );
  48. return ApiResponse(response);
  49. }
  50. Future<ApiResponse> editProducto({
  51. required int id,
  52. required String nombre,
  53. required String descripcion,
  54. String? descuento,
  55. required int existencia,
  56. required int idCategoria,
  57. required String precio,
  58. String? venceDescuento,
  59. }) async {
  60. var response = await post(
  61. endPoint,
  62. body: {
  63. 'id': id,
  64. 'descripcion': descripcion,
  65. 'nombre': nombre,
  66. 'descuento': descuento,
  67. 'existencia': existencia,
  68. 'idCategoria': idCategoria,
  69. 'precio': precio,
  70. 'venceDescuento': venceDescuento,
  71. },
  72. withAuth: true,
  73. );
  74. return ApiResponse(response);
  75. }
  76. Future<ApiResponse> deleteProducto({required int id}) async {
  77. var response = await delete(
  78. '$endPoint/eliminar',
  79. body: {
  80. 'id': id,
  81. },
  82. withAuth: true,
  83. );
  84. return ApiResponse(response);
  85. }
  86. }