Added an API to get Purchase invoice status list API
This commit is contained in:
parent
a6177adb43
commit
8aace3e1d9
@ -70,6 +70,17 @@ namespace Marco.Pms.Services.Controllers
|
||||
|
||||
#endregion
|
||||
|
||||
#region =================================================================== Purchase Invoice Status APIs ===================================================================
|
||||
[HttpGet("purchase-invoice-status/list")]
|
||||
public async Task<IActionResult> GetPurchaseInvoiceStatus(CancellationToken ct)
|
||||
{
|
||||
var loggedInEmployee = await _userHelper.GetCurrentEmployeeAsync();
|
||||
var response = await _masterService.GetPurchaseInvoiceStatusAsync(loggedInEmployee, ct);
|
||||
return StatusCode(response.StatusCode, response);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region =================================================================== Currency APIs ===================================================================
|
||||
|
||||
[HttpGet("currencies/list")]
|
||||
|
||||
@ -187,6 +187,63 @@ namespace Marco.Pms.Services.Service
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region =================================================================== Purchase Invoice Status APIs ===================================================================
|
||||
|
||||
/// <summary>
|
||||
/// Asynchronously retrieves a list of all available Purchase Invoice Statuses.
|
||||
/// </summary>
|
||||
/// <param name="loggedInEmployee">The employee context (used for logging or future permission checks).</param>
|
||||
/// <param name="cancellationToken">Token to observe while waiting for the task to complete.</param>
|
||||
/// <returns>A unified API response containing the list of status DTOs.</returns>
|
||||
public async Task<ApiResponse<object>> GetPurchaseInvoiceStatusAsync(Employee loggedInEmployee, CancellationToken cancellationToken = default)
|
||||
{
|
||||
// 1. Structural Logging: Capture the context of who is performing the action
|
||||
_logger.LogInfo("Initiating fetch of Purchase Invoice Statuses for User ID: {UserId}", loggedInEmployee.Id);
|
||||
|
||||
try
|
||||
{
|
||||
// 2. Performance & Security: Use AsNoTracking, Select specifically (Projection), and handle CancellationToken
|
||||
var invoiceStatuses = await _context.PurchaseInvoiceStatus
|
||||
.AsNoTracking() // Critical for read-only queries to avoid overhead of change tracker
|
||||
.OrderBy(status => status.Name)
|
||||
.ToListAsync(cancellationToken); // Respect request cancellation
|
||||
|
||||
// 3. Logging Success: Log the count for monitoring purposes
|
||||
_logger.LogInfo("Successfully fetched {Count} Purchase Invoice Status records.", invoiceStatuses.Count);
|
||||
|
||||
// 4. Strongly Typed Return: Return specific DTOs, not 'object'
|
||||
return ApiResponse<object>.SuccessResponse(
|
||||
invoiceStatuses,
|
||||
$"{invoiceStatuses.Count} record(s) of Purchase invoice status fetched successfully",
|
||||
200
|
||||
);
|
||||
}
|
||||
catch (OperationCanceledException)
|
||||
{
|
||||
// Handle cases where the user cancels the request (browser closed/timeout)
|
||||
_logger.LogWarning("Purchase Invoice Status fetch was cancelled by the user.");
|
||||
return ApiResponse<object>.ErrorResponse(
|
||||
"Request was cancelled",
|
||||
"Operation cancelled.",
|
||||
499 // Client Closed Request
|
||||
);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
// 5. Security & Error Handling: Log full stack trace securely, return generic message to client
|
||||
_logger.LogError(ex, "Critical error occurred while fetching Purchase Invoice Statuses for User ID: {UserId}", loggedInEmployee.Id);
|
||||
|
||||
// NEVER return 'ex.Message' directly to the client in production (security risk)
|
||||
return ApiResponse<object>.ErrorResponse(
|
||||
"An internal error occurred while processing your request. Please contact support.",
|
||||
"Internal Server Error",
|
||||
500
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region =================================================================== Currency APIs ===================================================================
|
||||
|
||||
public async Task<ApiResponse<object>> GetCurrencyAsync(Employee loggedInEmployee, Guid tenantId)
|
||||
|
||||
@ -22,6 +22,10 @@ namespace Marco.Pms.Services.Service.ServiceInterfaces
|
||||
Task<ApiResponse<object>> GetRecurringPaymentStatusAsync(Employee loggedInEmployee, Guid tenantId);
|
||||
#endregion
|
||||
|
||||
#region =================================================================== Purchase Invoice Status APIs ===================================================================
|
||||
Task<ApiResponse<object>> GetPurchaseInvoiceStatusAsync(Employee loggedInEmployee, CancellationToken cancellationToken);
|
||||
|
||||
#endregion
|
||||
#region =================================================================== Currency APIs ===================================================================
|
||||
Task<ApiResponse<object>> GetCurrencyAsync(Employee loggedInEmployee, Guid tenantId);
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user