mirror of
https://github.com/SyncrowIOT/syncrow-app.git
synced 2025-11-26 18:34:55 +00:00
Updated the API Endpoints, API Calls, Data Models and cubits to the lateset changes from the backend
This commit is contained in:
@ -1,7 +1,9 @@
|
||||
abstract class ApiEndpoints {
|
||||
static const String baseUrl = 'https://syncrow.azurewebsites.net';
|
||||
// static const String baseUrl = 'http://100.107.182.63:4001'; //Localhost
|
||||
|
||||
////////////////////////////////////// Authentication ///////////////////////////////
|
||||
|
||||
// Authentication
|
||||
static const String signUp = '$baseUrl/authentication/user/signup';
|
||||
static const String login = '$baseUrl/authentication/user/login';
|
||||
static const String deleteUser = '$baseUrl/authentication/user/delete/{id}';
|
||||
@ -10,16 +12,100 @@ abstract class ApiEndpoints {
|
||||
static const String forgetPassword =
|
||||
'$baseUrl/authentication/user/forget-password';
|
||||
|
||||
// Spaces
|
||||
static const String spaces = '$baseUrl/home';
|
||||
static const String rooms = '$baseUrl/room';
|
||||
////////////////////////////////////// Spaces ///////////////////////////////////////
|
||||
|
||||
// Devices
|
||||
static const String control = '$baseUrl/device/control';
|
||||
static const String devicesByRoom = '$baseUrl/device/room';
|
||||
// static const String deviceStatus = '$baseUrl/device/status/';
|
||||
static const String deviceStatus = '$baseUrl/device/';
|
||||
///Community Module
|
||||
//POST
|
||||
static const String addCommunity = '$baseUrl/community';
|
||||
static const String addCommunityToUser = '$baseUrl/community/user';
|
||||
//GET
|
||||
static const String communityByUuid = '$baseUrl/community/{communityUuid}';
|
||||
static const String communityChild =
|
||||
'$baseUrl/community/child/{communityUuid}';
|
||||
static const String communityUser = '$baseUrl/community/user/{userUuid}';
|
||||
//PUT
|
||||
static const String renameCommunity =
|
||||
'$baseUrl/community/rename/{communityUuid}';
|
||||
|
||||
//groups
|
||||
static const String groups = '$baseUrl/group';
|
||||
///Building Module
|
||||
//POST
|
||||
static const String addBuilding = '$baseUrl/building';
|
||||
static const String addBuildingToUser = '$baseUrl/building/user';
|
||||
//GET
|
||||
static const String buildingByUuid = '$baseUrl/building/{buildingUuid}';
|
||||
static const String buildingChild = '$baseUrl/building/child/{buildingUuid}';
|
||||
static const String buildingParent =
|
||||
'$baseUrl/building/parent/{buildingUuid}';
|
||||
static const String buildingUser = '$baseUrl/building/user/{userUuid}';
|
||||
//PUT
|
||||
static const String renameBuilding =
|
||||
'$baseUrl/building/rename/{buildingUuid}';
|
||||
|
||||
///Floor Module
|
||||
//POST
|
||||
static const String addFloor = '$baseUrl/floor';
|
||||
static const String addFloorToUser = '$baseUrl/floor/user';
|
||||
//GET
|
||||
static const String floorByUuid = '$baseUrl/floor/{floorUuid}';
|
||||
static const String floorChild = '$baseUrl/floor/child/{floorUuid}';
|
||||
static const String floorParent = '$baseUrl/floor/parent/{floorUuid}';
|
||||
static const String floorUser = '$baseUrl/floor/user/{userUuid}';
|
||||
//PUT
|
||||
static const String renameFloor = '$baseUrl/floor/rename/{floorUuid}';
|
||||
|
||||
///Unit Module
|
||||
//POST
|
||||
static const String addUnit = '$baseUrl/unit';
|
||||
static const String addUnitToUser = '$baseUrl/unit/user';
|
||||
//GET
|
||||
static const String unitByUuid = '$baseUrl/unit/';
|
||||
static const String unitChild = '$baseUrl/unit/child/';
|
||||
static const String unitParent = '$baseUrl/unit/parent/{unitUuid}';
|
||||
static const String unitUser = '$baseUrl/unit/user/';
|
||||
//PUT
|
||||
static const String renameUnit = '$baseUrl/unit/rename/{unitUuid}';
|
||||
|
||||
///Room Module
|
||||
//POST
|
||||
static const String addRoom = '$baseUrl/room';
|
||||
static const String addRoomToUser = '$baseUrl/room/user';
|
||||
//GET
|
||||
static const String roomByUuid = '$baseUrl/room/{roomUuid}';
|
||||
static const String roomParent = '$baseUrl/room/parent/{roomUuid}';
|
||||
static const String roomUser = '$baseUrl/room/user/{userUuid}';
|
||||
//PUT
|
||||
static const String renameRoom = '$baseUrl/room/rename/{roomUuid}';
|
||||
|
||||
///Group Module
|
||||
//POST
|
||||
static const String addGroup = '$baseUrl/group';
|
||||
static const String controlGroup = '$baseUrl/group/control';
|
||||
//GET
|
||||
static const String groupBySpace = '$baseUrl/group/space/{spaceUuid}';
|
||||
static const String groupByUuid = '$baseUrl/group/{groupUuid}';
|
||||
//DELETE
|
||||
static const String deleteGroup = '$baseUrl/group/{groupUuid}';
|
||||
|
||||
////////////////////////////////////// Devices ///////////////////////////////////////
|
||||
///Device Module
|
||||
//POST
|
||||
static const String addDeviceToRoom = '$baseUrl/device/room';
|
||||
static const String addDeviceToGroup = '$baseUrl/device/group';
|
||||
static const String controlDevice = '$baseUrl/device/control';
|
||||
//GET
|
||||
static const String deviceByRoom = '$baseUrl/device/room';
|
||||
static const String deviceByUuid = '$baseUrl/device/{deviceUuid}';
|
||||
static const String deviceFunctions =
|
||||
'$baseUrl/device/{deviceUuid}/functions';
|
||||
static const String deviceFunctionsStatus =
|
||||
'$baseUrl/device/{deviceUuid}/functions/status';
|
||||
|
||||
///Device Permission Module
|
||||
//POST
|
||||
static const String addDevicePermission = '$baseUrl/device-permission/add';
|
||||
//GET
|
||||
static const String devicePermissionList = '$baseUrl/device-permission/list';
|
||||
//PUT
|
||||
static const String editDevicePermission =
|
||||
'$baseUrl/device-permission/edit/{userId}';
|
||||
}
|
||||
|
||||
@ -1,3 +1,5 @@
|
||||
import 'dart:async';
|
||||
|
||||
import 'package:syncrow_app/features/devices/model/device_category_model.dart';
|
||||
import 'package:syncrow_app/features/devices/model/device_control_model.dart';
|
||||
import 'package:syncrow_app/features/devices/model/device_model.dart';
|
||||
@ -11,7 +13,7 @@ class DevicesAPI {
|
||||
DeviceControlModel controlModel) async {
|
||||
try {
|
||||
final response = await _httpService.post(
|
||||
path: ApiEndpoints.control,
|
||||
path: ApiEndpoints.controlDevice,
|
||||
body: controlModel.toJson(),
|
||||
showServerMessage: false,
|
||||
expectedResponseModel: (json) {
|
||||
@ -24,7 +26,7 @@ class DevicesAPI {
|
||||
}
|
||||
}
|
||||
|
||||
static Future<List<DevicesCategoryModel>> fetchGroups(int spaceId) async {
|
||||
static Future<List<DevicesCategoryModel>> fetchGroups(String spaceId) async {
|
||||
Map<String, dynamic> params = {
|
||||
"homeId": spaceId,
|
||||
"pageSize": 100,
|
||||
@ -32,7 +34,7 @@ class DevicesAPI {
|
||||
};
|
||||
|
||||
final response = await _httpService.get(
|
||||
path: ApiEndpoints.groups,
|
||||
path: ApiEndpoints.groupBySpace.replaceAll("{spaceUuid}", spaceId),
|
||||
queryParameters: params,
|
||||
showServerMessage: false,
|
||||
expectedResponseModel: (json) =>
|
||||
@ -43,7 +45,8 @@ class DevicesAPI {
|
||||
|
||||
static Future<Map<String, dynamic>> getDeviceStatus(String deviceId) async {
|
||||
final response = await _httpService.get(
|
||||
path: '${ApiEndpoints.deviceStatus}/$deviceId/functions/status',
|
||||
path: ApiEndpoints.deviceFunctionsStatus
|
||||
.replaceAll('{deviceUuid}', deviceId),
|
||||
showServerMessage: false,
|
||||
expectedResponseModel: (json) {
|
||||
return json;
|
||||
@ -52,14 +55,20 @@ class DevicesAPI {
|
||||
return response;
|
||||
}
|
||||
|
||||
static Future<List<DeviceModel>> getDevicesByRoomId(int roomId) async {
|
||||
static Future<List<DeviceModel>> getDevicesByRoomId(String roomId) async {
|
||||
// print("Room ID: $roomId");
|
||||
final response = await _httpService.get(
|
||||
path: ApiEndpoints.devicesByRoom,
|
||||
queryParameters: {"roomId": roomId, "pageSize": 10},
|
||||
path: ApiEndpoints.deviceByRoom,
|
||||
queryParameters: {"roomUuid": roomId},
|
||||
showServerMessage: false,
|
||||
expectedResponseModel: (json) {
|
||||
if (json == null || json.isEmpty || json == []) {
|
||||
print('json: $json');
|
||||
return <DeviceModel>[];
|
||||
}
|
||||
print('json: $json');
|
||||
List<DeviceModel> devices = [];
|
||||
for (var device in json['devices']) {
|
||||
for (var device in json) {
|
||||
devices.add(DeviceModel.fromJson(device));
|
||||
}
|
||||
return devices;
|
||||
|
||||
@ -8,29 +8,25 @@ import 'package:syncrow_app/services/api/http_service.dart';
|
||||
class SpacesAPI {
|
||||
static final HTTPService _httpService = HTTPService();
|
||||
|
||||
static Future<List<SpaceModel>> getSpaces() async {
|
||||
static Future<List<SpaceModel>> getUnitsByUserId() async {
|
||||
var uuid =
|
||||
await const FlutterSecureStorage().read(key: UserModel.userUuidKey);
|
||||
final response = await _httpService.get(
|
||||
path: ApiEndpoints.spaces,
|
||||
queryParameters: {
|
||||
"userUuid": uuid,
|
||||
},
|
||||
path: "${ApiEndpoints.unitUser}$uuid",
|
||||
showServerMessage: false,
|
||||
expectedResponseModel: (json) => SpaceModel.fromJsonList(json),
|
||||
);
|
||||
return response;
|
||||
}
|
||||
|
||||
//get rooms by space id
|
||||
static Future<List<RoomModel>> getRoomsBySpaceId(int spaceId) async {
|
||||
static Future<List<RoomModel>> getRoomsBySpaceId(String unitId) async {
|
||||
final response = await _httpService.get(
|
||||
path: ApiEndpoints.rooms,
|
||||
queryParameters: {"homeId": spaceId},
|
||||
path: "${ApiEndpoints.unitChild}$unitId",
|
||||
queryParameters: {"page": 1, "pageSize": 10},
|
||||
showServerMessage: false,
|
||||
expectedResponseModel: (json) {
|
||||
List<RoomModel> rooms = [];
|
||||
for (var room in json) {
|
||||
for (var room in json['children']) {
|
||||
rooms.add(RoomModel.fromJson(room));
|
||||
}
|
||||
return rooms;
|
||||
|
||||
Reference in New Issue
Block a user