mirror of
https://github.com/SyncrowIOT/web.git
synced 2025-07-10 07:07:19 +00:00
added product api and model
This commit is contained in:
26
lib/services/product_api.dart
Normal file
26
lib/services/product_api.dart
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:syncrow_web/pages/spaces_management/model/product_model.dart';
|
||||||
|
import 'package:syncrow_web/services/api/http_service.dart';
|
||||||
|
import 'package:syncrow_web/utils/constants/api_const.dart';
|
||||||
|
|
||||||
|
class ProductApi {
|
||||||
|
Future<List<ProductModel>> fetchProducts() async {
|
||||||
|
try {
|
||||||
|
final response = await HTTPService().get(
|
||||||
|
path: ApiEndpoints.listProducts,
|
||||||
|
expectedResponseModel: (json) {
|
||||||
|
List<dynamic> jsonData = json['data'];
|
||||||
|
|
||||||
|
List<ProductModel> productList = jsonData.map((jsonItem) {
|
||||||
|
return ProductModel.fromMap(jsonItem);
|
||||||
|
}).toList();
|
||||||
|
return productList;
|
||||||
|
},
|
||||||
|
);
|
||||||
|
return response;
|
||||||
|
} catch (e) {
|
||||||
|
debugPrint('Error fetching products: $e');
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -157,7 +157,6 @@ class CommunitySpaceManagementApi {
|
|||||||
if (parentId != null) {
|
if (parentId != null) {
|
||||||
body['parentUuid'] = parentId;
|
body['parentUuid'] = parentId;
|
||||||
}
|
}
|
||||||
print(ApiEndpoints.createSpace.replaceAll('{communityId}', communityId));
|
|
||||||
final response = await HTTPService().post(
|
final response = await HTTPService().post(
|
||||||
path: ApiEndpoints.createSpace.replaceAll('{communityId}', communityId),
|
path: ApiEndpoints.createSpace.replaceAll('{communityId}', communityId),
|
||||||
body: body,
|
body: body,
|
||||||
|
@ -78,4 +78,7 @@ abstract class ApiEndpoints {
|
|||||||
static const String factoryReset = '/device/factory/reset/{deviceUuid}';
|
static const String factoryReset = '/device/factory/reset/{deviceUuid}';
|
||||||
static const String powerClamp =
|
static const String powerClamp =
|
||||||
'/device/{powerClampUuid}/power-clamp/status';
|
'/device/{powerClampUuid}/power-clamp/status';
|
||||||
|
|
||||||
|
//product
|
||||||
|
static const String listProducts = '/products';
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user