added edit job api

This commit is contained in:
Vaibhav Surve 2025-11-17 11:15:17 +05:30
parent d530077444
commit a39af6519a
2 changed files with 77 additions and 28 deletions

View File

@ -2,8 +2,7 @@ class ApiEndpoints {
static const String baseUrl = "https://stageapi.marcoaiot.com/api"; static const String baseUrl = "https://stageapi.marcoaiot.com/api";
// static const String baseUrl = "https://api.marcoaiot.com/api"; // static const String baseUrl = "https://api.marcoaiot.com/api";
// static const String baseUrl = "https://devapi.marcoaiot.com/api"; // static const String baseUrl = "https://devapi.marcoaiot.com/api";
// static const String baseUrl = "https://mapi.marcoaiot.com/api"; // static const String baseUrl = "https://mapi.marcoaiot.com/api";
static const String getMasterCurrencies = "/Master/currencies/list"; static const String getMasterCurrencies = "/Master/currencies/list";
static const String getMasterExpensesCategories = static const String getMasterExpensesCategories =
@ -140,6 +139,8 @@ class ApiEndpoints {
static const String getServiceProjectsList = "/serviceproject/list"; static const String getServiceProjectsList = "/serviceproject/list";
static const String getServiceProjectDetail = "/serviceproject/details"; static const String getServiceProjectDetail = "/serviceproject/details";
static const String getServiceProjectJobList = "/serviceproject/job/list"; static const String getServiceProjectJobList = "/serviceproject/job/list";
static const String getServiceProjectJobDetail = "/serviceproject/job/details"; static const String getServiceProjectJobDetail =
"/serviceproject/job/details";
static const String editServiceProjectJob = "/serviceproject/job/edit";
static const String createServiceProjectJob = "/serviceproject/job/create"; static const String createServiceProjectJob = "/serviceproject/job/create";
} }

View File

@ -307,35 +307,83 @@ class ApiService {
} }
// Service Project Module APIs // Service Project Module APIs
/// Edit a Service Project Job
static Future<bool> editServiceProjectJobApi({
required String jobId,
required List<Map<String, dynamic>>
operations,
}) async {
final endpoint = "${ApiEndpoints.editServiceProjectJob}/$jobId";
logSafe("Editing Service Project Job: $jobId with operations: $operations");
/// Get details for a single Service Project Job try {
static Future<JobDetailsResponse?> getServiceProjectJobDetailApi(String jobId) async { // PATCH request is usually similar to PUT, but with http.patch
final endpoint = "${ApiEndpoints.getServiceProjectJobDetail}/$jobId"; String? token = await _getToken();
logSafe("Fetching Job Detail for Job ID: $jobId"); if (token == null) return false;
try { final uri = Uri.parse("${ApiEndpoints.baseUrl}$endpoint");
final response = await _getRequest(endpoint);
if (response == null) { final headers = _headers(token);
logSafe("Service Project Job Detail request failed: null response", level: LogLevel.error);
return null; final response = await http
.patch(uri, headers: headers, body: jsonEncode(operations))
.timeout(extendedTimeout);
logSafe(
"Edit Service Project Job response status: ${response.statusCode}");
logSafe("Edit Service Project Job response body: ${response.body}");
final json = jsonDecode(response.body);
if (response.statusCode == 200 && json['success'] == true) {
logSafe("Service Project Job edited successfully: ${json['data']}");
return true;
} else {
logSafe(
"Failed to edit Service Project Job: ${json['message'] ?? 'Unknown error'}",
level: LogLevel.warning,
);
return false;
}
} catch (e, stack) {
logSafe("Exception during editServiceProjectJobApi: $e",
level: LogLevel.error);
logSafe("StackTrace: $stack", level: LogLevel.debug);
return false;
} }
final jsonResponse = _parseResponseForAllData(
response,
label: "Service Project Job Detail",
);
if (jsonResponse != null) {
return JobDetailsResponse.fromJson(jsonResponse);
}
} catch (e, stack) {
logSafe("Exception during getServiceProjectJobDetailApi: $e", level: LogLevel.error);
logSafe("StackTrace: $stack", level: LogLevel.debug);
} }
return null; /// Get details for a single Service Project Job
} static Future<JobDetailsResponse?> getServiceProjectJobDetailApi(
String jobId) async {
final endpoint = "${ApiEndpoints.getServiceProjectJobDetail}/$jobId";
logSafe("Fetching Job Detail for Job ID: $jobId");
try {
final response = await _getRequest(endpoint);
if (response == null) {
logSafe("Service Project Job Detail request failed: null response",
level: LogLevel.error);
return null;
}
final jsonResponse = _parseResponseForAllData(
response,
label: "Service Project Job Detail",
);
if (jsonResponse != null) {
return JobDetailsResponse.fromJson(jsonResponse);
}
} catch (e, stack) {
logSafe("Exception during getServiceProjectJobDetailApi: $e",
level: LogLevel.error);
logSafe("StackTrace: $stack", level: LogLevel.debug);
}
return null;
}
/// Create a new Service Project Job /// Create a new Service Project Job
static Future<bool> createServiceProjectJobApi({ static Future<bool> createServiceProjectJobApi({