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;
}
}
}

View File

@@ -0,0 +1,26 @@
// lib/domain/provider/order/create_order_provider.dart
import 'package:dio/dio.dart';
import '../../../modules/orders/create_order.dart';
import '../../../service/dio.dart';
import '../../repository/order/create_order_repo.dart';
class CreateOrderProvider implements CreateOrderRepository {
final CustomDio customDio = CustomDio();
@override
Future<CreateOrderResponse> createOrder(CreateOrderRequest request) async {
try {
final response = await customDio.postData(
'https://queue.workolik.com/live/api/v1/mob/orders/createorder',
request.toJson(),
);
print(response);
return CreateOrderResponse.fromJson(response);
} catch (e) {
return CreateOrderResponse(
status: "error", message_id: 0);
}
}
}

View File

@@ -0,0 +1,35 @@
import 'dart:convert';
import '../../../Helper/Logger.dart';
import '../../../modules/product/product.dart';
import '../../../service/dio.dart';
class ProductsProvider {
final CustomDio customDio = CustomDio();
Future<ProductResponse?> getProductsBySubCategory({
required int categoryId,
required int tenantId, required int locationId,
}) async {
final url =
"https://fiesta.nearle.app/live/api/v1/mob/products/getproductsbysubcategory?categoryid=2&tenantid=$tenantId&locationid=$locationId";
logger.i("GET ProductsBySubCategory URL: $url");
ProductResponse? responseModel;
try {
final response = await customDio.getData(url);
if (response != null) {
// logger.i(response);
responseModel = ProductResponse.fromJson(response);
// logger.i("GET Products Response: ${jsonEncode(responseModel.toJson())}");
}
} catch (e) {
logger.e("Error in getProductsBySubCategory: $e");
}
return responseModel;
}
}

View File

@@ -0,0 +1,78 @@
import 'package:flutter/material.dart';
import 'package:shared_preferences/shared_preferences.dart';
import '../../../modules/profile/customer_request.dart';
import '../../repository/profile/request_repo.dart';
class CustomerRequestProvider with ChangeNotifier {
final CustomerRequestRepository _repository = CustomerRequestRepository();
bool isLoading = false;
// List of fetched customer requests
List<CustomerRequestStatusModel> requests = [];
/// Create a new customer request
Future<bool> sendRequest(String subject, String remarks) async {
isLoading = true;
notifyListeners();
SharedPreferences prefs = await SharedPreferences.getInstance();
int? customerId = prefs.getInt('customerId');
if (customerId == null) {
isLoading = false;
notifyListeners();
throw Exception("Something went wrong");
}
final model = CustomerRequestModel(
referencedate: DateTime.now().toUtc().toIso8601String().split('.').first + 'Z',
referencetype: "general", // always set default value
customerid: customerId,
tenantid: 0,
locationid: 0,
subject: subject,
remarks: remarks,
status: 0,
apptypeid: 98,
);
final result = await _repository.createCustomerRequest(model);
isLoading = false;
notifyListeners();
if (result != null && result is Map<String, dynamic> && result["status"] != false) {
debugPrint("✅ API Success: $result");
// Optionally refresh the list after creating a request
await fetchCustomerRequests();
return true;
} else {
debugPrint("❌ API Failed: $result");
return false;
}
}
/// Fetch customer requests (status)
Future<void> fetchCustomerRequests({int pageNo = 1, int pageSize = 10}) async {
isLoading = true;
notifyListeners();
SharedPreferences prefs = await SharedPreferences.getInstance();
int? customerId = prefs.getInt('customerId');
if (customerId == null) {
isLoading = false;
notifyListeners();
return;
}
requests = await _repository.fetchCustomerRequests(
customerId: customerId,
pageNo: pageNo,
pageSize: pageSize,
);
isLoading = false;
notifyListeners();
}
}

View File

@@ -0,0 +1,222 @@
import 'dart:convert';
import 'package:shared_preferences/shared_preferences.dart';
import '../../../Helper/Logger.dart';
import '../../../constants/api_constants.dart';
import '../../../modules/orders/getcustomerorders.dart';
import '../../../modules/tenant/get_tenant.dart';
import '../../../service/dio.dart';
class CustomerTenantsProvider {
final CustomDio customDio = CustomDio();
Future<CustomerTenantsResponse?> getCustomerTenants(int customerId, int i) async {
SharedPreferences prefs = await SharedPreferences.getInstance();
double? la = prefs.getDouble('lat');
double? lo = prefs.getDouble('long');
final url = "${ApiConstants.tenantCustomers}?customerid=$customerId&tenant=0&latitude=$la&longitude=$lo&categoryid=$i";
logger.i("GET CustomerTenants URL: $url");
CustomerTenantsResponse? responseModel;
try {
final response = await customDio.getData(url);
if (response != null) {
logger.i(response);
responseModel = CustomerTenantsResponse.fromJson(response);
logger.i("GET CustomerTenants Response: ${jsonEncode(responseModel.toJson())}");
}
} catch (e) {
logger.e("Error in getCustomerTenants: $e");
}
return responseModel;
}
// Future<OrdersResponse?> getCustomerOrders(int customerId, {required int pageNo, required int pageSize}) async {
//
// print(pageNo);
// print(pageSize);
// print('ee');
// final url = "https://fiesta.nearle.app/live/api/v1/mob/orders/getcustomerorders/?customerid=$customerId&pageno=$pageNo&pagesize=$pageSize";
// logger.i("GET CustomerOrders URL: $url"); // Should now show pagesize=8
//
// OrdersResponse? responseModel;
//
// try {
// final response = await customDio.getData(url);
//
// if (response != null) {
// responseModel = OrdersResponse.fromJson(response);
// logger.i("GET CustomerOrders Response: ${jsonEncode(responseModel.toJson())}");
// }
// } catch (e) {
// logger.e("Error in getCustomerOrders: $e");
// }
//
// return responseModel;
// }
Future<OrdersResponse?> getCustomerOrders(
int customerId, {
required int pageNo,
required int pageSize,
}) async {
print(pageNo);
print(pageSize);
print('ee');
final url =
"https://api.workolik.com/api/rest/getcustomerorders/?customerid=$customerId&pageno=$pageNo&pagesize=$pageSize";
// final url =
// "${ApiConstants.getCustomerOrders}"
// "?customerid=$customerId"
// "&limit=$pageSize"
// "&offset=$pageNo";
logger.i("GET CustomerOrders URL: $url");
OrdersResponse? responseModel;
try {
final response = await customDio.getData(url);
// 👇 Add this to see what actually came back
logger.i("🔍 Raw response type: ${response.runtimeType}");
logger.i("🔍 Raw response: $response");
dynamic jsonResponse;
if (response is String) {
try {
jsonResponse = jsonDecode(response);
} catch (e) {
logger.e("❌ JSON decode failed: $e");
return null;
}
} else {
jsonResponse = response;
}
if (jsonResponse != null && jsonResponse is Map<String, dynamic>) {
responseModel = OrdersResponse.fromJson(jsonResponse);
logger.i("✅ Parsed Orders Response: ${jsonEncode(responseModel.toJson())}");
} else {
logger.w("⚠️ Unexpected response format: $jsonResponse");
}
} catch (e) {
logger.e("⛔ Error in getCustomerOrders: $e");
}
return responseModel;
}
Future<OrderResponse?> getCustomerOrderss(
int customerId, {
required int pageNo,
required int pageSize,
}) async {
final offset = (pageNo - 1) * pageSize;
final url =
"https://api.workolik.com/api/rest/getcustomerorders"
"?customerid=$customerId"
"&tenantid=1087"
"&moduleid=2"
"&fromdate=2025-08-01T00:00:00"
"&todate=2026-12-31T23:59:59"
"&orderstatus=delivered"
"&keyword=%%"
"&limit=$pageSize"
"&offset=$offset";
try {
logger.i("➡️ API Request: $url");
final response = await customDio.getData(url, headers: {
"x-hasura-admin-secret": "nearle-admin-secret",
// OR
// "x-hasura-access-key": "YOUR_ACCESS_KEY",
},);
logger.d("✅ API Response: $response");
if (response != null) {
return OrderResponse.fromJson(response);
} else {
logger.w("⚠️ API returned null");
return null;
}
} catch (e, stackTrace) {
logger.e("❌ API Error", error: e, stackTrace: stackTrace);
return null;
}
}
Future<Map<String, dynamic>?> createTenantCustomer({
required int tenantId,
required int locationId,
required int customerId,
required int status,
}) async {
final url = "https://fiesta.nearle.app/live/api/v1/mob/tenants/createtenantcustomer";
final body = {
"tenantid": tenantId,
"locationid": locationId,
"customerid": customerId,
"status": status,
};
logger.i("POST CreateTenantCustomer URL: $url, Body: $body");
try {
final response = await customDio.postData(url, body);
logger.i("POST CreateTenantCustomer Response: $response");
// Ensure response is a Map<String, dynamic>
if (response is Map<String, dynamic>) {
return response;
} else {
// If API returned string or other type, wrap it
return {'message': 'Something went wrong'};
}
} catch (e) {
logger.e("Error in createTenantCustomer: $e");
// Wrap exception in map
return {'error':'Something went wrong'};
}
}
Future<TenantLocationsResponse?> getTenantLocations(int tenantId) async {
final url = "https://fiesta.nearle.app/live/api/v1/mob/tenants/gettenantlocations/?tenantid=$tenantId";
logger.i("GET TenantLocations URL: $url");
try {
final response = await customDio.getData(url);
if (response != null) {
final responseModel = TenantLocationsResponse.fromJson(response);
logger.i("GET TenantLocations Response: ${jsonEncode(responseModel.toJson())}");
return responseModel; // <--- return the parsed modules
}
} catch (e) {
logger.e("Error in getTenantLocations: $e");
}
return null; // <--- return null if request fails
}
}

View File

@@ -0,0 +1,42 @@
import 'dart:convert';
import 'package:nearledaily/service/dio.dart';
import 'package:nearledaily/helper/logger.dart';
import '../../../modules/product/product.dart';
import '../../repository/varient/varient_repo.dart';
class ProductVariantProvider implements ProductVariantRepository {
final CustomDio customDio = CustomDio();
@override
Future<List<Product>?> getProductVariant({
required int tenantId,
required int variantId,
}) async {
final url =
"https://fiesta.nearle.app/live/api/v1/mob/products/getproductbyvariant?tenantid=$tenantId&variantid=$variantId";
logger.i("GET ProductVariant URL: $url");
try {
final response = await customDio.getData(url);
if (response != null &&
response['code'] == 200 &&
response['details'] != null &&
response['details'].isNotEmpty) {
// Map JSON using new Product.fromJson factory
final products = (response['details'] as List)
.map((e) => Product.fromJson(e as Map<String, dynamic>))
.toList();
logger.i("GET ProductVariant Response: ${jsonEncode(products)}");
return products;
} else {
logger.w("No product variants found for variantId $variantId");
return [];
}
} catch (e) {
logger.e("Error in getProductVariant: $e");
return [];
}
}
}

View File

@@ -0,0 +1,42 @@
import 'package:dio/dio.dart';
import '../../../constants/api_constants.dart';
import '../../../data/authentication/auth_request.dart';
import '../../../data/authentication/auth_response.dart';
import '../../../modules/authentication/auth.dart';
import '../../../modules/authentication/getbyid.dart';
import '../../provider/authentication/auth_provider.dart';
class LoginRepository{
LoginProvider loginProvider = LoginProvider();
final LoginProvider _profileProvider = LoginProvider();
Future<LoginResponse?> signIn(LoginRequest data) async {
return await loginProvider.signIn('${ApiConstants.login}',data);
}
Future<CustomerFullView?> fetchProfile(String customerId) async {
return await _profileProvider.getProfile(customerId);
}
Future<dynamic> updateProfile(dynamic data) async {
final String url = ApiConstants.updateCustomer;
try {
final dio = Dio();
// print(url);
final response = await dio.put(url, data: data);
return response.data;
} catch (e) {
print("Error updating profile: $e");
return null;
}
}
}

View File

@@ -0,0 +1,21 @@
import '../../../modules/authentication/auth.dart';
abstract class CustomerLocationRepository {
Future<List<Authentication>> fetchCustomerLocations(int customerId);
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,
int primaryAddress,
int status,
});
}

View File

@@ -0,0 +1,7 @@
// lib/domain/repository/order/create_order_repo.dart
import '../../../modules/orders/create_order.dart';
abstract class CreateOrderRepository {
Future<CreateOrderResponse> createOrder(CreateOrderRequest request);
}

View File

@@ -0,0 +1,8 @@
import '../../../modules/product/product.dart';
abstract class ProductsRepository {
Future<ProductResponse?> getProductsBySubCategory({
required int categoryId,
required int tenantId,
});
}

View File

@@ -0,0 +1,45 @@
import '../../../modules/profile/customer_request.dart';
import '../../../service/dio.dart';
class CustomerRequestRepository {
final CustomDio _dio = CustomDio();
/// Create a new customer request
Future<dynamic> createCustomerRequest(CustomerRequestModel model) async {
const String url = "https://fiesta.nearle.app/live/api/v1/mob/customers/createcustomerrequest";
try {
final response = await _dio.postData(url, model.toJson());
print("POST URL: $url");
print("Payload: ${model.toJson()}");
print("Response: $response");
return response;
} catch (e) {
return {"status": false, "message": e.toString()};
}
}
/// Fetch customer requests (status)
Future<List<CustomerRequestStatusModel>> fetchCustomerRequests({
required int customerId,
int pageNo = 1,
int pageSize = 10,
}) async {
final String url = "https://fiesta.nearle.app/live/api/v1/mob/customers/getcustomerrequests"
"?customerid=$customerId&pageno=$pageNo&pagesize=$pageSize";
try {
final response = await _dio.getData(url); // assuming getData exists
print("GET URL: $url");
print("Response: $response");
if (response != null && response['status'] == true) {
final List data = response['data'] ?? [];
return data.map((e) => CustomerRequestStatusModel.fromJson(e)).toList();
}
return [];
} catch (e) {
print("❌ Fetch error: $e");
return [];
}
}
}

View File

@@ -0,0 +1,24 @@
import '../../../modules/tenant/get_tenant.dart';
import '../../provider/tenant/get_tenant_pro.dart';
abstract class CustomerTenantsRepository {
Future<CustomerTenantsResponse?> getCustomerTenants(int customerId);
Future<OrdersResponse?> getCustomerOrders(int customerId);
Future<Map<String, dynamic>?> createTenantCustomer({
required int tenantId,
required int locationId,
required int customerId,
required int status,
});
final CustomerTenantsProvider provider;
CustomerTenantsRepository({required this.provider});
Future<TenantLocationsResponse?> getTenantLocations(int tenantId) async {
final response = await provider.getTenantLocations(tenantId);
return response;
}
}

View File

@@ -0,0 +1,19 @@
import '../../../modules/product/product.dart';
// abstract class ProductVariantRepository {
// Future<ProductVariant?> getProductVariant({
// required int tenantId,
// required int variantId,
// });
// }
abstract class ProductVariantRepository {
Future<List<Product>?> getProductVariant({
required int tenantId,
required int variantId,
});
}