This commit is contained in:
mohammad
2024-07-23 16:16:31 +03:00
parent 8a4a158af5
commit e5e839248d
17 changed files with 457 additions and 516 deletions
+12 -1
View File
@@ -1,5 +1,5 @@
abstract class ApiEndpoints {
static const String baseUrl = 'https://syncrow.azurewebsites.net';
static const String baseUrl = 'https://syncrow-dev.azurewebsites.net';
// static const String baseUrl = 'http://100.107.182.63:4001'; //Localhost
////////////////////////////////////// Authentication ///////////////////////////////
@@ -151,4 +151,15 @@ abstract class ApiEndpoints {
//multiple-time offline
static const String deleteTemporaryPassword =
'$baseUrl/door-lock/temporary-password/{doorLockUuid}/{passwordId}';
//user
static const String getUser = '$baseUrl/user/{userUuid}';
static const String saveRegion = '$baseUrl/user/region/{userUuid}';
static const String saveTimeZone = '$baseUrl/user/timezone/{userUuid}';
static const String saveName = '$baseUrl/user/name/{userUuid}';
static const String sendPicture = '$baseUrl/user/profile-picture/{userUuid}';
static const String getRegion = '$baseUrl/region';
static const String getTimezone = '$baseUrl/timezone';
}
+78 -24
View File
@@ -1,23 +1,22 @@
import 'dart:async';
import 'dart:io';
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';
import 'package:syncrow_app/features/devices/model/function_model.dart';
import 'package:syncrow_app/features/auth/bloc/auth_cubit.dart';
import 'package:syncrow_app/features/auth/model/user_model.dart';
import 'package:syncrow_app/features/menu/bloc/profile_bloc/region_model.dart';
import 'package:syncrow_app/features/menu/bloc/profile_bloc/time_zone_model.dart';
import 'package:syncrow_app/services/api/api_links_endpoints.dart';
import 'package:syncrow_app/services/api/http_service.dart';
import '../../features/devices/model/create_temporary_password_model.dart';
class ProfileApi {
static final HTTPService _httpService = HTTPService();
static Future<Map<String, dynamic>> saveName(
String newName, String userId) async {
static Future<Map<String, dynamic>> saveName({String? firstName, String? lastName,}) async {
try {
final response = await _httpService.post(
path: ApiEndpoints.controlDevice.replaceAll('{deviceUuid}', userId),
body: newName,
showServerMessage: false,
final response = await _httpService.put(
path: ApiEndpoints.saveName.replaceAll('{userUuid}', AuthCubit.user!.uuid!),
body: {
"firstName": firstName,
"lastName": lastName
},
expectedResponseModel: (json) {
return json;
},
@@ -28,13 +27,29 @@ class ProfileApi {
}
}
static Future<Map<String, dynamic>> saveImage(
File newName, String userId) async {
static Future saveRegion({String? regionUuid,}) async {
try {
final response = await _httpService.post(
path: ApiEndpoints.controlDevice.replaceAll('{deviceUuid}', userId),
body: newName,
showServerMessage: false,
final response = await _httpService.put(
path: ApiEndpoints.saveRegion.replaceAll('{userUuid}', AuthCubit.user!.uuid!),
body: {
"regionUuid": regionUuid,
},
expectedResponseModel: (json) {
return json;
},
);
return response;
} catch (e) {
rethrow;
}
}
static Future saveTimeZone({String? regionUuid,}) async {
try {
final response = await _httpService.put(
path: ApiEndpoints.saveTimeZone.replaceAll('{userUuid}', AuthCubit.user!.uuid!),
body: {
"timezoneUuid": regionUuid,
},
expectedResponseModel: (json) {
return json;
},
@@ -45,15 +60,54 @@ class ProfileApi {
}
}
static Future fetchUserInfo(String userId) async {
static Future<Map<String, dynamic>> saveImage(String image) async {
try {
final response = await _httpService.put(
path: ApiEndpoints.sendPicture.replaceAll('{userUuid}', AuthCubit.user!.uuid!),
body: {
"profilePicture": 'data:image/png;base64,$image'
},
expectedResponseModel: (json) {
return json;
},
);
return response;
} catch (e) {
rethrow;
}
}
static Future fetchUserInfo(userId) async {
final response = await _httpService.get(
path: ApiEndpoints.groupBySpace.replaceAll('{unitUuid}', userId),
// queryParameters: params,
showServerMessage: false,
expectedResponseModel: (json) => DevicesCategoryModel.fromJsonList(json),
path: ApiEndpoints.getUser.replaceAll('{userUuid}', userId!),
showServerMessage: true,
expectedResponseModel: (json) =>UserModel.fromJson(json)
);
return response;
}
static Future<List<RegionModel>> fetchRegion() async {
final response = await _httpService.get(
path: ApiEndpoints.getRegion,
showServerMessage: true,
expectedResponseModel: (json) {
return (json as List).map((zone) => RegionModel.fromJson(zone)).toList();
}
);
return response as List<RegionModel>;
}
static Future<List<TimeZone>> fetchTimeZone() async {
final response = await _httpService.get(
path: ApiEndpoints.getTimezone,
showServerMessage: true,
expectedResponseModel: (json) {
return (json as List).map((zone) => TimeZone.fromJson(zone)).toList();
}
);
return response as List<TimeZone>;
}
}