first commit

This commit is contained in:
Anbarasu
2026-05-26 18:01:57 +05:30
commit 6d59c8daf6
297 changed files with 35238 additions and 0 deletions

View File

@@ -0,0 +1,121 @@
import 'dart:convert';
import 'package:nearledaily/constants/api_constants.dart';
import '../../../Helper/Logger.dart';
import '../../../data/authentication/auth_request.dart';
import '../../../data/authentication/auth_response.dart';
import '../../../modules/authentication/auth.dart';
import '../../../modules/authentication/getbyid.dart';
import '../../../service/dio.dart';
class LoginProvider {
final CustomDio _customDio = CustomDio(); // ✅ Declare the CustomDio instance
Future<LoginResponse?> signIn(String urlData, LoginRequest data) async {
logger.i('signInUrlData $urlData');
LoginResponse? loginResponse;
final customDio = CustomDio();
try {
final response = await customDio.postData(
urlData,
data.toJson(),
);
logger.i("Raw response type: ${response.runtimeType}");
logger.i("Raw response: $response");
if (response != null) {
if (response is Map<String, dynamic>) {
loginResponse = LoginResponse.fromJson(response);
} else if (response is String) {
try {
final Map<String, dynamic> jsonMap = jsonDecode(response);
loginResponse = LoginResponse.fromJson(jsonMap);
} catch (e) {
loginResponse = LoginResponse(
status: false,
message: "Something went wrong",
);
}
} else {
loginResponse = LoginResponse(
status: false,
message: "something went wrong",
);
}
logger.i('loginResponse: ${loginResponse.toJson()}');
}
} catch (e, stacktrace) {
logger.e("Error occurred in signIn: $e");
logger.e(stacktrace);
loginResponse = LoginResponse(
status: false,
message: "Something went wrong",
);
}
return loginResponse;
}
Future<CustomerFullView?> getProfile(String customerId) async {
logger.i('🔹 GetProfile API customerId: $customerId');
CustomerFullView? profile;
final customDio = CustomDio();
final url = "${ApiConstants.fetchProfile}customerid=$customerId&contactno=''";
try {
final response = await customDio.getData(url,
headers: {
'x-hasura-admin-secret': 'nearle-admin-secret',
},
);
logger.i("Raw response type: ${response.runtimeType}");
logger.i("Raw response: $response");
if (response != null) {
Map<String, dynamic> jsonMap;
if (response is Map<String, dynamic>) {
jsonMap = response;
} else if (response is String) {
jsonMap = jsonDecode(response);
} else {
throw Exception("Something went wrong");
}
// Parse the list and take the first item
final list = jsonMap['customer_full_view'] as List?;
logger.i('🔹 Full jsonMap keys: ${jsonMap.keys.toList()}'); // ← see all keys
logger.i('🔹 customerFullView list: $list'); // ← see the list
logger.i('🔹 list length: ${list?.length}');
if (list != null && list.isNotEmpty) {
profile = CustomerFullView.fromJson(list[0] as Map<String, dynamic>);
logger.i('Profile parsed successfully');
}
}
} catch (e, stacktrace) {
logger.e("Error occurred in ProfileProvider.getProfile: $e");
logger.e(stacktrace);
}
return profile;
}
Future<dynamic> putData(String endpoint, Map<String, dynamic> data) async {
try {
final response = await _customDio.putData(endpoint, data);
return response;
} catch (e) {
return {"status": false, "message": e.toString()};
}
}
}

View File

@@ -0,0 +1,98 @@
import 'dart:convert';
import 'package:nearledaily/service/dio.dart';
import 'package:nearledaily/helper/logger.dart';
import '../../../constants/api_constants.dart';
import '../../../modules/authentication/auth.dart';
import '../../repository/authentication/location_repo.dart';
class CustomerLocationProvider implements CustomerLocationRepository {
final CustomDio customDio = CustomDio();
@override
Future<List<Authentication>> fetchCustomerLocations(int customerId) async {
final url = "${ApiConstants.getCustomerLocations}?customerid=$customerId";
logger.i("GET CustomerLocation URL: $url");
try {
final response = await customDio.getData(
url,
headers: {
"x-hasura-admin-secret": "nearle-admin-secret",
"Content-Type": "application/json",
},
);
if (response != null &&
response['customerlocations'] != null &&
(response['customerlocations'] as List).isNotEmpty) {
final locations = (response['customerlocations'] as List)
.map((e) => Authentication.fromLocationJson(e))
.toList();
logger.i("Locations count: ${locations.length}");
return locations;
} else {
logger.w("No customer locations found for customerId $customerId");
return [];
}
} catch (e) {
logger.e("Error in fetchCustomerLocations: $e");
return [];
}
}
// Create new customer location
@override
Future<bool> createCustomerLocation({
required int customerId,
required String address,
required String doorNo,
required String landmark,
String suburb = "",
String city = "",
String state = "",
String postcode = "",
String latitude = "",
String longitude = "",
String defaultAddress = "Yes",
int primaryAddress = 1,
int status = 1,
}) async {
final url = "https://fiesta.nearle.app/live/api/v1/mob/customers/createlocations";
final body = {
"customerid": customerId,
"address": address,
"suburb": suburb,
"city": city,
"state": state,
"landmark": landmark,
"doorno": doorNo,
"postcode": postcode,
"latitude": latitude,
"longitude": longitude,
"defaultaddress": defaultAddress,
"primaryaddress": primaryAddress,
"status": status
};
logger.i("POST CustomerLocation URL: $url");
logger.i("Request Body: ${jsonEncode(body)}");
try {
final response = await customDio.postData(url, body);
if (response != null && (response['code'] == 200 || response['code'] == 201)) {
logger.i("CustomerLocation created successfully: ${jsonEncode(response)}");
return true;
} else {
logger.w("Failed to create CustomerLocation: ${jsonEncode(response)}");
return false;
}
} catch (e) {
logger.e("Error in createCustomerLocation: $e");
return false;
}
}
}