275 lines
8.4 KiB
Dart
275 lines
8.4 KiB
Dart
import 'dart:convert';
|
|
import 'dart:developer';
|
|
|
|
import 'package:dio/dio.dart';
|
|
import 'package:regroup/Common/api_urls.dart';
|
|
import 'package:regroup/Common/base_manager.dart';
|
|
import 'package:regroup/Common/controller/data/network/network_api.dart';
|
|
import 'package:shared_preferences/shared_preferences.dart';
|
|
import 'package:http/http.dart' as http;
|
|
|
|
class Profilepostmethod {
|
|
Profilepostmethod();
|
|
Dio dio = Dio();
|
|
|
|
String basicAuth = 'Basic ' +
|
|
base64.encode(
|
|
utf8.encode('RegroupUserName:71%@L%es^bUX94`J9XT*@bh,._WWM{\$%^^&&'));
|
|
|
|
Future<ResponseData<dynamic>> postContactus(updata) async {
|
|
print("updata is $updata");
|
|
final response = await NetworkApiServices().postApi(
|
|
updata,
|
|
ApiUrls.postcontactus,
|
|
);
|
|
print("response is ${response.data}");
|
|
print("response message is ${response.message}");
|
|
return response;
|
|
}
|
|
|
|
Future<ResponseData<dynamic>> postReportandbug(updata) async {
|
|
print("updata is $updata");
|
|
final response = await NetworkApiServices().postApi(
|
|
updata,
|
|
ApiUrls.postreportbug,
|
|
);
|
|
print("response is ${response.data}");
|
|
print("response message is ${response.message}");
|
|
return response;
|
|
}
|
|
|
|
Future<ResponseData<dynamic>> postBlockuser(updata) async {
|
|
print("updata is $updata");
|
|
final response = await NetworkApiServices().postApi(
|
|
updata,
|
|
ApiUrls.postblock,
|
|
);
|
|
print("response is ${response.data}");
|
|
print("response message is ${response.message}");
|
|
return response;
|
|
}
|
|
|
|
Future<ResponseData<dynamic>> postunfollowuser(updata) async {
|
|
print("updata is $updata");
|
|
final response = await NetworkApiServices().postApi(
|
|
updata,
|
|
ApiUrls.postunfollow,
|
|
);
|
|
print("response is ${response.data}");
|
|
print("response message is ${response.message}");
|
|
return response;
|
|
}
|
|
|
|
Future<ResponseData<dynamic>> postRemoveuser(updata) async {
|
|
print("updata is $updata");
|
|
final response = await NetworkApiServices().postApi(
|
|
updata,
|
|
ApiUrls.postremoveuser,
|
|
);
|
|
print("response is ${response.data}");
|
|
print("response message is ${response.message}");
|
|
return response;
|
|
}
|
|
|
|
Future<ResponseData<dynamic>> postChangepassword(updata) async {
|
|
print("updata is $updata");
|
|
final response = await NetworkApiServices().postApi(
|
|
updata,
|
|
ApiUrls.postchangepassword,
|
|
);
|
|
print("response is ${response.data}");
|
|
print("response message is ${response.message}");
|
|
return response;
|
|
}
|
|
|
|
Future<ResponseData<dynamic>> postChangepassverifyotp(updata) async {
|
|
print("updata is $updata");
|
|
final response = await NetworkApiServices().postApi(
|
|
updata,
|
|
ApiUrls.postchangepassverify,
|
|
);
|
|
print("response is ${response.data}");
|
|
print("response message is ${response.message}");
|
|
return response;
|
|
}
|
|
|
|
Future<ResponseData<dynamic>> postTimeline(updata) async {
|
|
print("updata is $updata");
|
|
final response = await NetworkApiServices().postApi(
|
|
updata,
|
|
ApiUrls.posttimeline,
|
|
);
|
|
print("response is ${response.data}");
|
|
print("response message is ${response.message}");
|
|
return response;
|
|
}
|
|
|
|
Future<ResponseData<dynamic>> postAccountvisibility(updata) async {
|
|
print("updata is $updata");
|
|
final response = await NetworkApiServices().postApi(
|
|
updata,
|
|
ApiUrls.postaccountvisibility,
|
|
);
|
|
print("response is ${response.data}");
|
|
print("response message is ${response.message}");
|
|
return response;
|
|
}
|
|
|
|
Future<ResponseData<dynamic>> postDeleteaccount(updata) async {
|
|
print("updata is $updata");
|
|
final response = await NetworkApiServices().postApi(
|
|
updata,
|
|
ApiUrls.postdeleteaccount,
|
|
);
|
|
print("response is ${response.data}");
|
|
print("response message is ${response.message}");
|
|
return response;
|
|
}
|
|
|
|
Future<ResponseData<dynamic>> postLogoutaccount() async {
|
|
Response response;
|
|
SharedPreferences prefs = await SharedPreferences.getInstance();
|
|
String? token = prefs.getString('access-token');
|
|
|
|
try {
|
|
response = await dio.post(
|
|
ApiUrls.postlogoutaccount,
|
|
options: Options(
|
|
headers: {'authorization': basicAuth, 'access-token': token},
|
|
),
|
|
);
|
|
log(response.toString());
|
|
} on Exception catch (e) {
|
|
if (e is DioException) {
|
|
log(e.response.toString());
|
|
if (e.response == null) {
|
|
return ResponseData<dynamic>(
|
|
'Oops something Went Wrong, Please try again!',
|
|
ResponseStatus.FAILED,
|
|
);
|
|
}
|
|
if (e.response!.statusCode == 401) {
|
|
prefs.remove('token');
|
|
prefs.remove('refreshToken');
|
|
// Get.toNamed(RouteName.login);
|
|
return ResponseData<dynamic>(
|
|
'Oops something Went Wrong, Please try again!',
|
|
ResponseStatus.FAILED,
|
|
);
|
|
}
|
|
if (e.response!.statusCode == 403) {
|
|
if (e.response!.data['message'] is List) {
|
|
return ResponseData<dynamic>(
|
|
e.response!.data['message'][0]!, ResponseStatus.FAILED,
|
|
data: e.response!.data);
|
|
} else {
|
|
return ResponseData<dynamic>(
|
|
e.response!.data['message'], ResponseStatus.FAILED,
|
|
data: e.response!.data);
|
|
}
|
|
}
|
|
}
|
|
return ResponseData<dynamic>(
|
|
'Oops something Went Wrong',
|
|
ResponseStatus.FAILED,
|
|
);
|
|
}
|
|
|
|
if (response.statusCode == 200 || response.statusCode == 201) {
|
|
return ResponseData<dynamic>("success", ResponseStatus.SUCCESS,
|
|
data: response.data);
|
|
} else if (response.statusCode == 203) {
|
|
print(response.data);
|
|
return ResponseData<dynamic>("success", ResponseStatus.PRIVATE,
|
|
data: response.data);
|
|
} else {
|
|
try {
|
|
return ResponseData<dynamic>(
|
|
response.data['message'].toString(), ResponseStatus.FAILED);
|
|
} catch (_) {
|
|
return ResponseData<dynamic>(
|
|
response.statusMessage!, ResponseStatus.FAILED);
|
|
}
|
|
}
|
|
}
|
|
|
|
Future<ResponseData<dynamic>> postEditTimeline(updata) async {
|
|
print("updata is $updata");
|
|
final response = await NetworkApiServices().postApi(
|
|
updata,
|
|
ApiUrls.postedittimeline,
|
|
);
|
|
print("response is ${response.data}");
|
|
print("response message is ${response.message}");
|
|
return response;
|
|
}
|
|
|
|
Future<ResponseData<dynamic>> postRemoveTimeline(updata) async {
|
|
print("updata is $updata");
|
|
final response = await NetworkApiServices().postApi(
|
|
updata,
|
|
ApiUrls.postremovetimeline,
|
|
);
|
|
print("response is ${response.data}");
|
|
print("response message is ${response.message}");
|
|
return response;
|
|
}
|
|
|
|
Future<ResponseData<dynamic>> postRemoveCertification(updata) async {
|
|
print("updata is $updata");
|
|
final response = await NetworkApiServices().postApi(
|
|
updata,
|
|
ApiUrls.postremovecertification,
|
|
);
|
|
print("response is ${response.data}");
|
|
print("response message is ${response.message}");
|
|
return response;
|
|
}
|
|
|
|
Future<ResponseData<dynamic>> postCertification(updata) async {
|
|
print("updata is $updata");
|
|
final response = await NetworkApiServices().postApi(
|
|
updata,
|
|
ApiUrls.postcertification,
|
|
);
|
|
print("response is ${response.data}");
|
|
print("response message is ${response.message}");
|
|
return response;
|
|
}
|
|
|
|
// Future guestFollowuser(int userId) async {
|
|
// print("followRecipe");
|
|
// final apiUrl = ApiUrls.postunfollow;
|
|
// // final body = {"following_iam_principal_xid": userId};
|
|
// Map<String, dynamic> updata = {
|
|
// "following_iam_principal_xid": userId,
|
|
// };
|
|
// SharedPreferences prefs = await SharedPreferences.getInstance();
|
|
// String? token = prefs.getString('access-token');
|
|
// Response response;
|
|
|
|
// try {
|
|
// response = await dio.post(
|
|
// apiUrl,
|
|
// data: updata,
|
|
// options:
|
|
// Options(
|
|
// headers: {'authorization': basicAuth, 'access-token': token},
|
|
// ),
|
|
// );
|
|
// log(response.toString());
|
|
// if (response.statusCode == 200) {
|
|
// final jsonResponse = json.decode(response.data);
|
|
// print("resp from api ${jsonResponse["message"]}");
|
|
// return jsonResponse["success"];
|
|
// } else {
|
|
// // API call failed
|
|
// throw Exception('Failed to follow user');
|
|
// }
|
|
// } catch (e) {
|
|
// // Error occurred while making the API call
|
|
// throw Exception('Error: $e');
|
|
// }
|
|
// }
|
|
}
|