mirror of
https://github.com/SyncrowIOT/web.git
synced 2025-07-10 07:07:19 +00:00
formatted all files.
This commit is contained in:
@ -12,7 +12,8 @@ class AccessMangApi {
|
||||
|
||||
void _validateEndpoints() {
|
||||
if (!ApiEndpoints.getDevices.contains('{projectId}')) {
|
||||
throw Exception("Endpoint 'getDevices' must contain '{projectId}' placeholder.");
|
||||
throw Exception(
|
||||
"Endpoint 'getDevices' must contain '{projectId}' placeholder.");
|
||||
}
|
||||
}
|
||||
|
||||
@ -22,8 +23,8 @@ class AccessMangApi {
|
||||
path: ApiEndpoints.visitorPassword,
|
||||
showServerMessage: true,
|
||||
expectedResponseModel: (json) {
|
||||
List<dynamic> jsonData = json['data'] ?? [];
|
||||
List<PasswordModel> passwordList = jsonData.map((jsonItem) {
|
||||
final List<dynamic> jsonData = json['data'] ?? [];
|
||||
final passwordList = jsonData.map((jsonItem) {
|
||||
return PasswordModel.fromJson(jsonItem);
|
||||
}).toList();
|
||||
return passwordList;
|
||||
@ -46,8 +47,8 @@ class AccessMangApi {
|
||||
},
|
||||
showServerMessage: true,
|
||||
expectedResponseModel: (json) {
|
||||
List<dynamic> jsonData = json['data'] ?? [];
|
||||
List<DeviceModel> deviceList = jsonData.map((jsonItem) {
|
||||
final List<dynamic> jsonData = json['data'] ?? [];
|
||||
final deviceList = jsonData.map((jsonItem) {
|
||||
return DeviceModel.fromJson(jsonItem);
|
||||
}).toList();
|
||||
return deviceList;
|
||||
@ -69,13 +70,13 @@ class AccessMangApi {
|
||||
final response = await HTTPService().post(
|
||||
path: ApiEndpoints.visitorPassword,
|
||||
body: jsonEncode({
|
||||
"email": email,
|
||||
"passwordName": passwordName,
|
||||
"password": password,
|
||||
"devicesUuid": devicesUuid,
|
||||
"effectiveTime": effectiveTime,
|
||||
"invalidTime": invalidTime,
|
||||
"operationType": "ONLINE_ONE_TIME",
|
||||
'email': email,
|
||||
'passwordName': passwordName,
|
||||
'password': password,
|
||||
'devicesUuid': devicesUuid,
|
||||
'effectiveTime': effectiveTime,
|
||||
'invalidTime': invalidTime,
|
||||
'operationType': 'ONLINE_ONE_TIME',
|
||||
}),
|
||||
showServerMessage: true,
|
||||
expectedResponseModel: (json) {
|
||||
@ -93,17 +94,18 @@ class AccessMangApi {
|
||||
String? passwordName,
|
||||
List<Schedule>? scheduleList,
|
||||
List<String>? devicesUuid}) async {
|
||||
Map<String, dynamic> body = {
|
||||
"email": email,
|
||||
"devicesUuid": devicesUuid,
|
||||
"passwordName": passwordName,
|
||||
"password": password,
|
||||
"effectiveTime": effectiveTime,
|
||||
"invalidTime": invalidTime,
|
||||
"operationType": "ONLINE_MULTIPLE_TIME",
|
||||
final body = <String, dynamic>{
|
||||
'email': email,
|
||||
'devicesUuid': devicesUuid,
|
||||
'passwordName': passwordName,
|
||||
'password': password,
|
||||
'effectiveTime': effectiveTime,
|
||||
'invalidTime': invalidTime,
|
||||
'operationType': 'ONLINE_MULTIPLE_TIME',
|
||||
};
|
||||
if (scheduleList != null) {
|
||||
body["scheduleList"] = scheduleList.map((schedule) => schedule.toJson()).toList();
|
||||
body['scheduleList'] =
|
||||
scheduleList.map((schedule) => schedule.toJson()).toList();
|
||||
}
|
||||
final response = await HTTPService().post(
|
||||
path: ApiEndpoints.visitorPassword,
|
||||
@ -123,10 +125,10 @@ class AccessMangApi {
|
||||
final response = await HTTPService().post(
|
||||
path: ApiEndpoints.visitorPassword,
|
||||
body: jsonEncode({
|
||||
"operationType": "OFFLINE_ONE_TIME",
|
||||
"email": email,
|
||||
"passwordName": passwordName,
|
||||
"devicesUuid": devicesUuid
|
||||
'operationType': 'OFFLINE_ONE_TIME',
|
||||
'email': email,
|
||||
'passwordName': passwordName,
|
||||
'devicesUuid': devicesUuid
|
||||
}),
|
||||
showServerMessage: true,
|
||||
expectedResponseModel: (json) {
|
||||
@ -145,12 +147,12 @@ class AccessMangApi {
|
||||
final response = await HTTPService().post(
|
||||
path: ApiEndpoints.visitorPassword,
|
||||
body: jsonEncode({
|
||||
"email": email,
|
||||
"devicesUuid": devicesUuid,
|
||||
"passwordName": passwordName,
|
||||
"effectiveTime": effectiveTime,
|
||||
"invalidTime": invalidTime,
|
||||
"operationType": "OFFLINE_MULTIPLE_TIME",
|
||||
'email': email,
|
||||
'devicesUuid': devicesUuid,
|
||||
'passwordName': passwordName,
|
||||
'effectiveTime': effectiveTime,
|
||||
'invalidTime': invalidTime,
|
||||
'operationType': 'OFFLINE_MULTIPLE_TIME',
|
||||
}),
|
||||
showServerMessage: true,
|
||||
expectedResponseModel: (json) {
|
||||
|
@ -1,10 +1,10 @@
|
||||
import 'dart:async';
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:dio/dio.dart';
|
||||
import 'package:flutter_secure_storage/flutter_secure_storage.dart';
|
||||
import 'package:syncrow_web/pages/auth/model/token.dart';
|
||||
import 'package:syncrow_web/services/api/network_exception.dart';
|
||||
import 'dart:async';
|
||||
import 'package:syncrow_web/utils/constants/api_const.dart';
|
||||
import 'package:syncrow_web/utils/snack_bar.dart';
|
||||
|
||||
@ -18,7 +18,8 @@ class HTTPInterceptor extends InterceptorsWrapper {
|
||||
];
|
||||
|
||||
@override
|
||||
void onResponse(Response response, ResponseInterceptorHandler handler) async {
|
||||
Future<void> onResponse(
|
||||
Response response, ResponseInterceptorHandler handler) async {
|
||||
if (await validateResponse(response)) {
|
||||
super.onResponse(response, handler);
|
||||
} else {
|
||||
@ -28,26 +29,27 @@ class HTTPInterceptor extends InterceptorsWrapper {
|
||||
}
|
||||
|
||||
@override
|
||||
void onRequest(
|
||||
Future<void> onRequest(
|
||||
RequestOptions options, RequestInterceptorHandler handler) async {
|
||||
var storage = const FlutterSecureStorage();
|
||||
var token = await storage.read(key: Token.loginAccessTokenKey);
|
||||
const storage = FlutterSecureStorage();
|
||||
final token = await storage.read(key: Token.loginAccessTokenKey);
|
||||
if (checkHeaderExclusionListOfAddedParameters(options.path)) {
|
||||
options.headers
|
||||
.putIfAbsent(HttpHeaders.authorizationHeader, () => "Bearer $token");
|
||||
.putIfAbsent(HttpHeaders.authorizationHeader, () => 'Bearer $token');
|
||||
}
|
||||
// options.headers['Authorization'] = 'Bearer ${'${token!}123'}';
|
||||
super.onRequest(options, handler);
|
||||
}
|
||||
|
||||
@override
|
||||
void onError(DioException err, ErrorInterceptorHandler handler) async {
|
||||
ServerFailure failure = ServerFailure.fromDioError(err);
|
||||
Future<void> onError(
|
||||
DioException err, ErrorInterceptorHandler handler) async {
|
||||
final failure = ServerFailure.fromDioError(err);
|
||||
if (failure.toString().isNotEmpty) {
|
||||
CustomSnackBar.displaySnackBar(failure.toString());
|
||||
}
|
||||
var storage = const FlutterSecureStorage();
|
||||
var token = await storage.read(key: Token.loginAccessTokenKey);
|
||||
const storage = FlutterSecureStorage();
|
||||
final token = await storage.read(key: Token.loginAccessTokenKey);
|
||||
if (err.response?.statusCode == 401 && token != null) {
|
||||
// await AuthCubit.get(NavigationService.navigatorKey.currentContext!).logout();
|
||||
}
|
||||
@ -72,10 +74,10 @@ class HTTPInterceptor extends InterceptorsWrapper {
|
||||
}
|
||||
}
|
||||
|
||||
checkHeaderExclusionListOfAddedParameters(String path) {
|
||||
bool shouldAddHeader = true;
|
||||
bool checkHeaderExclusionListOfAddedParameters(String path) {
|
||||
var shouldAddHeader = true;
|
||||
|
||||
for (var urlConstant in headerExclusionListOfAddedParameters) {
|
||||
for (final urlConstant in headerExclusionListOfAddedParameters) {
|
||||
if (path.contains(urlConstant)) {
|
||||
shouldAddHeader = false;
|
||||
}
|
||||
|
@ -8,10 +8,10 @@ class HTTPService {
|
||||
|
||||
// final navigatorKey = GlobalKey<NavigatorState>();
|
||||
|
||||
String certificateString = "";
|
||||
String certificateString = '';
|
||||
|
||||
static Dio setupDioClient() {
|
||||
Dio client = Dio(
|
||||
final client = Dio(
|
||||
BaseOptions(
|
||||
baseUrl: ApiEndpoints.baseUrl,
|
||||
receiveDataWhenStatusError: true,
|
||||
|
@ -17,34 +17,34 @@ class ServerFailure extends Failure {
|
||||
factory ServerFailure.fromDioError(DioException dioError) {
|
||||
switch (dioError.type) {
|
||||
case DioExceptionType.connectionTimeout:
|
||||
return ServerFailure("Connection timeout with the Server.");
|
||||
return ServerFailure('Connection timeout with the Server.');
|
||||
case DioExceptionType.sendTimeout:
|
||||
return ServerFailure("Send timeout with the Server.");
|
||||
return ServerFailure('Send timeout with the Server.');
|
||||
|
||||
case DioExceptionType.receiveTimeout:
|
||||
return ServerFailure("Receive timeout with the Server.");
|
||||
return ServerFailure('Receive timeout with the Server.');
|
||||
|
||||
case DioExceptionType.badCertificate:
|
||||
return ServerFailure("Bad certificate!");
|
||||
return ServerFailure('Bad certificate!');
|
||||
|
||||
case DioExceptionType.badResponse:
|
||||
{
|
||||
// var document = parser.parse(dioError.response!.data.toString());
|
||||
// var message = document.body!.text;
|
||||
return ServerFailure.fromResponse(dioError.response!.statusCode!,
|
||||
dioError.response?.data['message'] ?? "Error");
|
||||
return ServerFailure.fromResponse(dioError.response!.statusCode,
|
||||
dioError.response?.data['message'] ?? 'Error');
|
||||
}
|
||||
case DioExceptionType.cancel:
|
||||
return ServerFailure("The request to ApiServer was canceled");
|
||||
return ServerFailure('The request to ApiServer was canceled');
|
||||
|
||||
case DioExceptionType.connectionError:
|
||||
return ServerFailure("No Internet Connection");
|
||||
return ServerFailure('No Internet Connection');
|
||||
|
||||
case DioExceptionType.unknown:
|
||||
return ServerFailure("Unexpected Error, Please try again!");
|
||||
return ServerFailure('Unexpected Error, Please try again!');
|
||||
|
||||
default:
|
||||
return ServerFailure("Unexpected Error, Please try again!");
|
||||
return ServerFailure('Unexpected Error, Please try again!');
|
||||
}
|
||||
}
|
||||
|
||||
@ -54,9 +54,9 @@ class ServerFailure extends Failure {
|
||||
case 403:
|
||||
return ServerFailure(responseMessage);
|
||||
case 400:
|
||||
List<String> errors = [];
|
||||
final errors = <String>[];
|
||||
if (responseMessage is List) {
|
||||
for (var error in responseMessage) {
|
||||
for (final error in responseMessage) {
|
||||
errors.add(error);
|
||||
}
|
||||
} else {
|
||||
@ -64,11 +64,11 @@ class ServerFailure extends Failure {
|
||||
}
|
||||
return ServerFailure(errors.join('\n'));
|
||||
case 404:
|
||||
return ServerFailure("");
|
||||
return ServerFailure('');
|
||||
case 500:
|
||||
return ServerFailure(responseMessage);
|
||||
default:
|
||||
return ServerFailure("Opps there was an Error, Please try again!");
|
||||
return ServerFailure('Opps there was an Error, Please try again!');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -31,7 +31,7 @@ class AuthenticationAPI {
|
||||
try {
|
||||
final response = await HTTPService().post(
|
||||
path: ApiEndpoints.forgetPassword,
|
||||
body: {"email": email, "password": password, "otpCode": otpCode},
|
||||
body: {'email': email, 'password': password, 'otpCode': otpCode},
|
||||
showServerMessage: true,
|
||||
expectedResponseModel: (json) {});
|
||||
return response;
|
||||
@ -45,7 +45,7 @@ class AuthenticationAPI {
|
||||
static Future<int?> sendOtp({required String email}) async {
|
||||
final response = await HTTPService().post(
|
||||
path: ApiEndpoints.sendOtp,
|
||||
body: {"email": email, "type": "PASSWORD"},
|
||||
body: {'email': email, 'type': 'PASSWORD'},
|
||||
showServerMessage: true,
|
||||
expectedResponseModel: (json) {
|
||||
return json['data']['cooldown'];
|
||||
@ -58,7 +58,7 @@ class AuthenticationAPI {
|
||||
try {
|
||||
final response = await HTTPService().post(
|
||||
path: ApiEndpoints.verifyOtp,
|
||||
body: {"email": email, "type": "PASSWORD", "otpCode": otpCode},
|
||||
body: {'email': email, 'type': 'PASSWORD', 'otpCode': otpCode},
|
||||
showServerMessage: true,
|
||||
expectedResponseModel: (json) {
|
||||
if (json['message'] == 'Otp Verified Successfully') {
|
||||
|
@ -11,7 +11,8 @@ abstract interface class BatchControlDevicesService {
|
||||
});
|
||||
}
|
||||
|
||||
final class RemoteBatchControlDevicesService implements BatchControlDevicesService {
|
||||
final class RemoteBatchControlDevicesService
|
||||
implements BatchControlDevicesService {
|
||||
@override
|
||||
Future<bool> batchControlDevices({
|
||||
required List<String> uuids,
|
||||
|
@ -23,8 +23,8 @@ class DevicesManagementApi {
|
||||
: ApiEndpoints.getAllDevices.replaceAll('{projectId}', projectId),
|
||||
showServerMessage: true,
|
||||
expectedResponseModel: (json) {
|
||||
List<dynamic> jsonData = json['data'];
|
||||
List<AllDevicesModel> devicesList = jsonData.map((jsonItem) {
|
||||
final List<dynamic> jsonData = json['data'];
|
||||
final devicesList = jsonData.map((jsonItem) {
|
||||
return AllDevicesModel.fromJson(jsonItem);
|
||||
}).toList();
|
||||
return devicesList;
|
||||
@ -123,11 +123,11 @@ class DevicesManagementApi {
|
||||
path: ApiEndpoints.gatewayApi.replaceAll('{gatewayUuid}', gatewayId),
|
||||
showServerMessage: false,
|
||||
expectedResponseModel: (json) {
|
||||
List<DeviceModel> devices = [];
|
||||
final devices = <DeviceModel>[];
|
||||
if (json == null || json.isEmpty || json == []) {
|
||||
return devices;
|
||||
}
|
||||
for (var device in json['data']['devices']) {
|
||||
for (final device in json['data']['devices']) {
|
||||
devices.add(DeviceModel.fromJson(device));
|
||||
}
|
||||
return devices;
|
||||
@ -203,7 +203,7 @@ class DevicesManagementApi {
|
||||
}
|
||||
}
|
||||
|
||||
getPowerStatus(List<String> uuids) async {
|
||||
Future getPowerStatus(List<String> uuids) async {
|
||||
try {
|
||||
final queryParameters = {
|
||||
'devicesUuid': uuids.join(','),
|
||||
@ -254,8 +254,8 @@ class DevicesManagementApi {
|
||||
.replaceAll('{category}', category),
|
||||
showServerMessage: true,
|
||||
expectedResponseModel: (json) {
|
||||
List<ScheduleModel> schedules = [];
|
||||
for (var schedule in json) {
|
||||
final schedules = <ScheduleModel>[];
|
||||
for (final schedule in json) {
|
||||
schedules.add(ScheduleModel.fromMap(schedule));
|
||||
}
|
||||
return schedules;
|
||||
@ -350,7 +350,7 @@ class DevicesManagementApi {
|
||||
try {
|
||||
final response = await HTTPService().put(
|
||||
path: ApiEndpoints.deviceByUuid.replaceAll('{deviceUuid}', deviceId),
|
||||
body: {"deviceName": deviceName},
|
||||
body: {'deviceName': deviceName},
|
||||
expectedResponseModel: (json) {
|
||||
return json['data'];
|
||||
},
|
||||
@ -378,7 +378,7 @@ class DevicesManagementApi {
|
||||
path: ApiEndpoints.resetDevice.replaceAll('{deviceUuid}', devicesUuid!),
|
||||
showServerMessage: false,
|
||||
body: {
|
||||
"devicesUuid": [devicesUuid]
|
||||
'devicesUuid': [devicesUuid]
|
||||
},
|
||||
expectedResponseModel: (json) {
|
||||
return json;
|
||||
|
@ -5,7 +5,7 @@ import 'package:syncrow_web/services/api/http_service.dart';
|
||||
|
||||
final GetIt serviceLocator = GetIt.instance;
|
||||
//setupLocator() // to search for dependency injection in flutter
|
||||
initialSetup() {
|
||||
void initialSetup() {
|
||||
serviceLocator.registerSingleton<HTTPInterceptor>(HTTPInterceptor());
|
||||
//Base classes
|
||||
serviceLocator.registerSingleton<Dio>(HTTPService.setupDioClient());
|
||||
|
@ -9,9 +9,9 @@ class ProductApi {
|
||||
final response = await HTTPService().get(
|
||||
path: ApiEndpoints.listProducts,
|
||||
expectedResponseModel: (json) {
|
||||
List<dynamic> jsonData = json['data'];
|
||||
final List<dynamic> jsonData = json['data'];
|
||||
|
||||
List<ProductModel> productList = jsonData.map((jsonItem) {
|
||||
final productList = jsonData.map((jsonItem) {
|
||||
return ProductModel.fromMap(jsonItem);
|
||||
}).toList();
|
||||
return productList;
|
||||
|
@ -29,7 +29,7 @@ class SceneApi {
|
||||
debugPrint('create scene response: $response');
|
||||
return response;
|
||||
} on DioException catch (e) {
|
||||
String errorMessage =
|
||||
final String errorMessage =
|
||||
e.response?.data['error']['message'][0] ?? 'something went wrong';
|
||||
throw APIException(errorMessage);
|
||||
}
|
||||
@ -52,7 +52,7 @@ class SceneApi {
|
||||
debugPrint('create automation response: $response');
|
||||
return response;
|
||||
} on DioException catch (e) {
|
||||
String errorMessage =
|
||||
final String errorMessage =
|
||||
e.response?.data['error']['message'][0] ?? 'something went wrong';
|
||||
throw APIException(errorMessage);
|
||||
}
|
||||
@ -63,7 +63,7 @@ class SceneApi {
|
||||
path: ApiEndpoints.getIconScene,
|
||||
showServerMessage: false,
|
||||
expectedResponseModel: (json) {
|
||||
List<IconModel> iconsList = [];
|
||||
final iconsList = <IconModel>[];
|
||||
json.forEach((element) {
|
||||
iconsList.add(IconModel.fromJson(element));
|
||||
});
|
||||
@ -89,8 +89,8 @@ class SceneApi {
|
||||
expectedResponseModel: (json) {
|
||||
final scenesJson = json['data'] as List;
|
||||
|
||||
List<ScenesModel> scenes = [];
|
||||
for (var scene in scenesJson) {
|
||||
final scenes = <ScenesModel>[];
|
||||
for (final scene in scenesJson) {
|
||||
scenes.add(ScenesModel.fromJson(scene, isAutomation: false));
|
||||
}
|
||||
return scenes;
|
||||
@ -114,8 +114,8 @@ class SceneApi {
|
||||
.replaceAll('{projectId}', projectId),
|
||||
showServerMessage: false,
|
||||
expectedResponseModel: (json) {
|
||||
List<ScenesModel> scenes = [];
|
||||
for (var scene in json) {
|
||||
final scenes = <ScenesModel>[];
|
||||
for (final scene in json) {
|
||||
scenes.add(ScenesModel.fromJson(scene, isAutomation: true));
|
||||
}
|
||||
return scenes;
|
||||
@ -158,7 +158,8 @@ class SceneApi {
|
||||
}
|
||||
|
||||
//update Scene
|
||||
static updateScene(CreateSceneModel createSceneModel, String sceneId) async {
|
||||
static Future updateScene(
|
||||
CreateSceneModel createSceneModel, String sceneId) async {
|
||||
try {
|
||||
final response = await _httpService.put(
|
||||
path: ApiEndpoints.updateScene.replaceAll('{sceneId}', sceneId),
|
||||
@ -170,14 +171,14 @@ class SceneApi {
|
||||
);
|
||||
return response;
|
||||
} on DioException catch (e) {
|
||||
String errorMessage =
|
||||
final String errorMessage =
|
||||
e.response?.data['error']['message'][0] ?? 'something went wrong';
|
||||
throw APIException(errorMessage);
|
||||
}
|
||||
}
|
||||
|
||||
//update automation
|
||||
static updateAutomation(CreateAutomationModel createAutomationModel,
|
||||
static Future updateAutomation(CreateAutomationModel createAutomationModel,
|
||||
String automationId, String projectId) async {
|
||||
try {
|
||||
final response = await _httpService.put(
|
||||
@ -192,7 +193,7 @@ class SceneApi {
|
||||
);
|
||||
return response;
|
||||
} on DioException catch (e) {
|
||||
String errorMessage =
|
||||
final String errorMessage =
|
||||
e.response?.data['error']['message'][0] ?? 'something went wrong';
|
||||
throw APIException(errorMessage);
|
||||
}
|
||||
@ -226,7 +227,7 @@ class SceneApi {
|
||||
);
|
||||
return response;
|
||||
} on DioException catch (e) {
|
||||
String errorMessage =
|
||||
final String errorMessage =
|
||||
e.response?.data['error']['message'][0] ?? 'something went wrong';
|
||||
throw APIException(errorMessage);
|
||||
}
|
||||
@ -247,7 +248,7 @@ class SceneApi {
|
||||
);
|
||||
return response;
|
||||
} on DioException catch (e) {
|
||||
String errorMessage =
|
||||
final String errorMessage =
|
||||
e.response?.data['error']['message'][0] ?? 'something went wrong';
|
||||
throw APIException(errorMessage);
|
||||
}
|
||||
@ -295,8 +296,8 @@ class SceneApi {
|
||||
.replaceAll('{projectId}', projectId),
|
||||
showServerMessage: false,
|
||||
expectedResponseModel: (json) {
|
||||
List<ScenesModel> scenes = [];
|
||||
for (var scene in json) {
|
||||
final scenes = <ScenesModel>[];
|
||||
for (final scene in json) {
|
||||
scenes.add(ScenesModel.fromJson(scene));
|
||||
}
|
||||
return scenes;
|
||||
|
@ -5,22 +5,19 @@ import 'package:syncrow_web/pages/spaces_management/all_spaces/model/community_m
|
||||
import 'package:syncrow_web/pages/spaces_management/all_spaces/model/create_subspace_model.dart';
|
||||
import 'package:syncrow_web/pages/spaces_management/all_spaces/model/space_model.dart';
|
||||
import 'package:syncrow_web/pages/spaces_management/all_spaces/model/space_response_model.dart';
|
||||
import 'package:syncrow_web/pages/spaces_management/all_spaces/model/subspace_model.dart';
|
||||
import 'package:syncrow_web/pages/spaces_management/all_spaces/model/tag.dart';
|
||||
import 'package:syncrow_web/pages/spaces_management/space_model/models/space_template_model.dart';
|
||||
import 'package:syncrow_web/pages/spaces_management/space_model/models/tag_body_model.dart';
|
||||
import 'package:syncrow_web/pages/spaces_management/space_model/models/tag_update_model.dart';
|
||||
import 'package:syncrow_web/services/api/http_service.dart';
|
||||
import 'package:syncrow_web/utils/constants/api_const.dart';
|
||||
|
||||
import '../pages/spaces_management/all_spaces/model/subspace_model.dart';
|
||||
|
||||
class CommunitySpaceManagementApi {
|
||||
// Community Management APIs
|
||||
Future<List<CommunityModel>> fetchCommunities(String projectId,
|
||||
{int page = 1}) async {
|
||||
try {
|
||||
List<CommunityModel> allCommunities = [];
|
||||
bool hasNext = true;
|
||||
final allCommunities = <CommunityModel>[];
|
||||
var hasNext = true;
|
||||
|
||||
while (hasNext) {
|
||||
await HTTPService().get(
|
||||
@ -31,10 +28,10 @@ class CommunitySpaceManagementApi {
|
||||
},
|
||||
expectedResponseModel: (json) {
|
||||
try {
|
||||
List<dynamic> jsonData = json['data'] ?? [];
|
||||
final List<dynamic> jsonData = json['data'] ?? [];
|
||||
hasNext = json['hasNext'] ?? false;
|
||||
int currentPage = json['page'] ?? 1;
|
||||
List<CommunityModel> communityList = jsonData.map((jsonItem) {
|
||||
final int currentPage = json['page'] ?? 1;
|
||||
final communityList = jsonData.map((jsonItem) {
|
||||
return CommunityModel.fromJson(jsonItem);
|
||||
}).toList();
|
||||
allCommunities.addAll(communityList);
|
||||
@ -56,10 +53,10 @@ class CommunitySpaceManagementApi {
|
||||
|
||||
Future<PaginationModel> fetchCommunitiesAndSpaces(
|
||||
{required String projectId, int page = 1, String search = ''}) async {
|
||||
PaginationModel paginationModel = const PaginationModel.emptyConstructor();
|
||||
var paginationModel = const PaginationModel.emptyConstructor();
|
||||
|
||||
try {
|
||||
bool hasNext = false;
|
||||
var hasNext = false;
|
||||
await HTTPService().get(
|
||||
path:
|
||||
ApiEndpoints.getCommunityList.replaceAll('{projectId}', projectId),
|
||||
@ -71,10 +68,10 @@ class CommunitySpaceManagementApi {
|
||||
},
|
||||
expectedResponseModel: (json) {
|
||||
try {
|
||||
List<dynamic> jsonData = json['data'] ?? [];
|
||||
final List<dynamic> jsonData = json['data'] ?? [];
|
||||
hasNext = json['hasNext'] ?? false;
|
||||
int currentPage = json['page'] ?? 1;
|
||||
List<CommunityModel> communityList = jsonData.map((jsonItem) {
|
||||
final int currentPage = json['page'] ?? 1;
|
||||
final communityList = jsonData.map((jsonItem) {
|
||||
return CommunityModel.fromJson(jsonItem);
|
||||
}).toList();
|
||||
|
||||
@ -379,12 +376,12 @@ class CommunitySpaceManagementApi {
|
||||
|
||||
final response = await HTTPService().get(
|
||||
path: path,
|
||||
queryParameters: {"page": 1, "pageSize": 10},
|
||||
queryParameters: {'page': 1, 'pageSize': 10},
|
||||
showServerMessage: false,
|
||||
expectedResponseModel: (json) {
|
||||
List<SubSpaceModel> rooms = [];
|
||||
final rooms = <SubSpaceModel>[];
|
||||
if (json['data'] != null) {
|
||||
for (var subspace in json['data']) {
|
||||
for (final subspace in json['data']) {
|
||||
rooms.add(SubSpaceModel.fromJson(subspace));
|
||||
}
|
||||
}
|
||||
@ -393,7 +390,7 @@ class CommunitySpaceManagementApi {
|
||||
);
|
||||
|
||||
return response;
|
||||
} catch (error, stackTrace) {
|
||||
} catch (error) {
|
||||
return [];
|
||||
}
|
||||
}
|
||||
|
@ -79,7 +79,7 @@ class SpaceModelManagementApi {
|
||||
.replaceAll('{projectId}', projectId)
|
||||
.replaceAll('{spaceModelUuid}', spaceModelUuid),
|
||||
showServerMessage: true,
|
||||
body: {"spaceUuids": spaceUuids, "overwrite": isOverWrite},
|
||||
body: {'spaceUuids': spaceUuids, 'overwrite': isOverWrite},
|
||||
expectedResponseModel: (json) {
|
||||
return json;
|
||||
},
|
||||
@ -92,7 +92,7 @@ class SpaceModelManagementApi {
|
||||
path: ApiEndpoints.validateSpaceModel
|
||||
.replaceAll('{projectId}', projectId),
|
||||
showServerMessage: true,
|
||||
body: {"spacesUuids": spaceUuids},
|
||||
body: {'spacesUuids': spaceUuids},
|
||||
expectedResponseModel: (json) {
|
||||
return json;
|
||||
});
|
||||
@ -116,7 +116,7 @@ class SpaceModelManagementApi {
|
||||
final response = await HTTPService().get(
|
||||
path: ApiEndpoints.listTags.replaceAll('{projectId}', projectId),
|
||||
expectedResponseModel: (json) {
|
||||
List<dynamic> jsonData = json['data'];
|
||||
final List<dynamic> jsonData = json['data'];
|
||||
return jsonData.map((jsonItem) {
|
||||
return Tag.fromJson(jsonItem);
|
||||
}).toList();
|
||||
|
@ -23,18 +23,18 @@ class UserPermissionApi {
|
||||
},
|
||||
);
|
||||
return response;
|
||||
} catch (e, stackTrace) {
|
||||
} catch (e) {
|
||||
debugPrint('Error in fetchUsers: $e');
|
||||
rethrow;
|
||||
}
|
||||
}
|
||||
|
||||
fetchRoles() async {
|
||||
Future<List<RoleTypeModel>> fetchRoles() async {
|
||||
final response = await _httpService.get(
|
||||
path: ApiEndpoints.roleTypes,
|
||||
showServerMessage: true,
|
||||
expectedResponseModel: (json) {
|
||||
final List<RoleTypeModel> fetchedRoles = (json['data'] as List)
|
||||
final fetchedRoles = (json['data'] as List)
|
||||
.map((item) => RoleTypeModel.fromJson(item))
|
||||
.toList();
|
||||
return fetchedRoles;
|
||||
@ -45,7 +45,7 @@ class UserPermissionApi {
|
||||
|
||||
Future<List<PermissionOption>> fetchPermission(roleUuid) async {
|
||||
final response = await _httpService.get(
|
||||
path: ApiEndpoints.permission.replaceAll("roleUuid", roleUuid),
|
||||
path: ApiEndpoints.permission.replaceAll('roleUuid', roleUuid),
|
||||
showServerMessage: true,
|
||||
expectedResponseModel: (json) {
|
||||
return (json as List)
|
||||
@ -68,14 +68,14 @@ class UserPermissionApi {
|
||||
}) async {
|
||||
try {
|
||||
final body = <String, dynamic>{
|
||||
"firstName": firstName,
|
||||
"lastName": lastName,
|
||||
"email": email,
|
||||
"jobTitle": jobTitle != '' ? jobTitle : null,
|
||||
"phoneNumber": phoneNumber != '' ? phoneNumber : null,
|
||||
"roleUuid": roleUuid,
|
||||
"projectUuid": projectUuid,
|
||||
"spaceUuids": spaceUuids,
|
||||
'firstName': firstName,
|
||||
'lastName': lastName,
|
||||
'email': email,
|
||||
'jobTitle': jobTitle != '' ? jobTitle : null,
|
||||
'phoneNumber': phoneNumber != '' ? phoneNumber : null,
|
||||
'roleUuid': roleUuid,
|
||||
'projectUuid': projectUuid,
|
||||
'spaceUuids': spaceUuids,
|
||||
};
|
||||
final response = await _httpService.post(
|
||||
path: ApiEndpoints.inviteUser,
|
||||
@ -83,7 +83,7 @@ class UserPermissionApi {
|
||||
body: jsonEncode(body),
|
||||
expectedResponseModel: (json) {
|
||||
if (json['statusCode'] != 400) {
|
||||
return json["success"];
|
||||
return json['success'];
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
@ -91,7 +91,7 @@ class UserPermissionApi {
|
||||
);
|
||||
|
||||
return response ?? [];
|
||||
} on DioException catch (e) {
|
||||
} on DioException {
|
||||
return false;
|
||||
} catch (e) {
|
||||
return false;
|
||||
@ -103,10 +103,10 @@ class UserPermissionApi {
|
||||
final response = await _httpService.post(
|
||||
path: ApiEndpoints.checkEmail,
|
||||
showServerMessage: true,
|
||||
body: {"email": email},
|
||||
body: {'email': email},
|
||||
expectedResponseModel: (json) {
|
||||
if (json['statusCode'] != 400) {
|
||||
var message = json["message"];
|
||||
final message = json['message'];
|
||||
if (message is String) {
|
||||
return message;
|
||||
} else {
|
||||
@ -128,11 +128,11 @@ class UserPermissionApi {
|
||||
Future<EditUserModel?> fetchUserById(userUuid, String projectId) async {
|
||||
final response = await _httpService.get(
|
||||
path: ApiEndpoints.getUserById
|
||||
.replaceAll("{userUuid}", userUuid)
|
||||
.replaceAll("{projectId}", projectId),
|
||||
.replaceAll('{userUuid}', userUuid)
|
||||
.replaceAll('{projectId}', projectId),
|
||||
showServerMessage: true,
|
||||
expectedResponseModel: (json) {
|
||||
EditUserModel res = EditUserModel.fromJson(json['data']);
|
||||
final res = EditUserModel.fromJson(json['data']);
|
||||
return res;
|
||||
},
|
||||
);
|
||||
@ -151,27 +151,27 @@ class UserPermissionApi {
|
||||
}) async {
|
||||
try {
|
||||
final body = <String, dynamic>{
|
||||
"firstName": firstName,
|
||||
"lastName": lastName,
|
||||
"jobTitle": jobTitle != '' ? jobTitle : " ",
|
||||
"phoneNumber": phoneNumber != '' ? phoneNumber : " ",
|
||||
"roleUuid": roleUuid,
|
||||
"projectUuid": projectUuid,
|
||||
"spaceUuids": spaceUuids,
|
||||
'firstName': firstName,
|
||||
'lastName': lastName,
|
||||
'jobTitle': jobTitle != '' ? jobTitle : ' ',
|
||||
'phoneNumber': phoneNumber != '' ? phoneNumber : ' ',
|
||||
'roleUuid': roleUuid,
|
||||
'projectUuid': projectUuid,
|
||||
'spaceUuids': spaceUuids,
|
||||
};
|
||||
final response = await _httpService.put(
|
||||
path: ApiEndpoints.editUser.replaceAll('{inviteUserUuid}', userId!),
|
||||
body: jsonEncode(body),
|
||||
expectedResponseModel: (json) {
|
||||
if (json['statusCode'] != 400) {
|
||||
return json["success"];
|
||||
return json['success'];
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
},
|
||||
);
|
||||
return response;
|
||||
} on DioException catch (e) {
|
||||
} on DioException {
|
||||
return false;
|
||||
} catch (e) {
|
||||
return false;
|
||||
@ -181,7 +181,7 @@ class UserPermissionApi {
|
||||
Future<bool> deleteUserById(userUuid) async {
|
||||
try {
|
||||
final response = await _httpService.delete(
|
||||
path: ApiEndpoints.deleteUser.replaceAll("{inviteUserUuid}", userUuid),
|
||||
path: ApiEndpoints.deleteUser.replaceAll('{inviteUserUuid}', userUuid),
|
||||
showServerMessage: true,
|
||||
expectedResponseModel: (json) {
|
||||
return json['success'];
|
||||
@ -193,16 +193,17 @@ class UserPermissionApi {
|
||||
}
|
||||
}
|
||||
|
||||
Future<bool> changeUserStatusById(userUuid, status, String projectUuid) async {
|
||||
Future<bool> changeUserStatusById(
|
||||
userUuid, status, String projectUuid) async {
|
||||
try {
|
||||
Map<String, dynamic> bodya = {
|
||||
"disable": status,
|
||||
"projectUuid": projectUuid
|
||||
final bodya = <String, dynamic>{
|
||||
'disable': status,
|
||||
'projectUuid': projectUuid
|
||||
};
|
||||
|
||||
final response = await _httpService.put(
|
||||
path: ApiEndpoints.changeUserStatus
|
||||
.replaceAll("{invitedUserUuid}", userUuid),
|
||||
.replaceAll('{invitedUserUuid}', userUuid),
|
||||
body: bodya,
|
||||
expectedResponseModel: (json) {
|
||||
return json['success'];
|
||||
|
Reference in New Issue
Block a user