Added an API to get a list of Invoice attachment types
This commit is contained in:
parent
8aace3e1d9
commit
c4653b557c
@ -71,16 +71,48 @@ namespace Marco.Pms.Services.Controllers
|
|||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region =================================================================== Purchase Invoice Status APIs ===================================================================
|
#region =================================================================== Purchase Invoice Status APIs ===================================================================
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Retrieves the purchase invoice status.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="ct">The cancellation token.</param>
|
||||||
|
/// <returns>The HTTP response containing the purchase invoice status.</returns>
|
||||||
[HttpGet("purchase-invoice-status/list")]
|
[HttpGet("purchase-invoice-status/list")]
|
||||||
public async Task<IActionResult> GetPurchaseInvoiceStatus(CancellationToken ct)
|
public async Task<IActionResult> GetPurchaseInvoiceStatus(CancellationToken ct)
|
||||||
{
|
{
|
||||||
|
// Get the currently logged-in employee.
|
||||||
var loggedInEmployee = await _userHelper.GetCurrentEmployeeAsync();
|
var loggedInEmployee = await _userHelper.GetCurrentEmployeeAsync();
|
||||||
|
|
||||||
|
// Retrieve the purchase invoice status asynchronously.
|
||||||
var response = await _masterService.GetPurchaseInvoiceStatusAsync(loggedInEmployee, ct);
|
var response = await _masterService.GetPurchaseInvoiceStatusAsync(loggedInEmployee, ct);
|
||||||
|
|
||||||
|
// Return the HTTP response with the purchase invoice status.
|
||||||
return StatusCode(response.StatusCode, response);
|
return StatusCode(response.StatusCode, response);
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
#region =================================================================== Invoice Attachment Type APIs ===================================================================
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Retrieves the invoice attachment types.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="ct">The cancellation token.</param>
|
||||||
|
/// <returns>The HTTP response containing the invoice attachment types.</returns>
|
||||||
|
[HttpGet("purchase-attachment-type/list")]
|
||||||
|
public async Task<IActionResult> GetInvoiceAttachmentType(CancellationToken ct)
|
||||||
|
{
|
||||||
|
// Get the currently logged-in employee.
|
||||||
|
var loggedInEmployee = await _userHelper.GetCurrentEmployeeAsync();
|
||||||
|
|
||||||
|
// Retrieve the invoice attachment types asynchronously.
|
||||||
|
var response = await _masterService.GetInvoiceAttachmentTypeAsync(loggedInEmployee, ct);
|
||||||
|
|
||||||
|
// Return the HTTP response with the invoice attachment types.
|
||||||
|
return StatusCode(response.StatusCode, response);
|
||||||
|
}
|
||||||
|
#endregion
|
||||||
|
|
||||||
#region =================================================================== Currency APIs ===================================================================
|
#region =================================================================== Currency APIs ===================================================================
|
||||||
|
|
||||||
[HttpGet("currencies/list")]
|
[HttpGet("currencies/list")]
|
||||||
|
|||||||
@ -244,6 +244,61 @@ namespace Marco.Pms.Services.Service
|
|||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
#region =================================================================== Invoice Attachment Type APIs ===================================================================
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Asynchronously retrieves the list of valid Invoice Attachment Types.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="loggedInEmployee">The current user context for audit logging.</param>
|
||||||
|
/// <param name="cancellationToken">Token to propagate notification that operations should be canceled.</param>
|
||||||
|
/// <returns>A standardized API response containing a list of attachment type DTOs.</returns>
|
||||||
|
public async Task<ApiResponse<object>> GetInvoiceAttachmentTypeAsync(Employee loggedInEmployee, CancellationToken cancellationToken = default)
|
||||||
|
{
|
||||||
|
// 1. Structured Logging: Audit WHO is requesting the data
|
||||||
|
_logger.LogInfo("Initiating fetch of Invoice Attachment Types. Requested by User ID: {UserId}", loggedInEmployee.Id);
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
// 2. Database Optimization:
|
||||||
|
// - AsNoTracking(): Crucial for read-only lists. Bypasses change tracking overhead.
|
||||||
|
// - Select(): Projects directly to DTO. Fetches ONLY needed columns (SQL optimization).
|
||||||
|
var attachmentTypes = await _context.InvoiceAttachmentTypes
|
||||||
|
.AsNoTracking()
|
||||||
|
.OrderBy(type => type.Name)
|
||||||
|
.ToListAsync(cancellationToken); // 3. Pass the token to EF Core
|
||||||
|
|
||||||
|
_logger.LogInfo("Successfully retrieved {Count} Invoice Attachment Types.", attachmentTypes.Count);
|
||||||
|
|
||||||
|
// 4. Strong Typing: Return IEnumerable<Dto> instead of 'object'
|
||||||
|
return ApiResponse<object>.SuccessResponse(
|
||||||
|
attachmentTypes,
|
||||||
|
$"{attachmentTypes.Count} record(s) of invoice attachment type fetched successfully",
|
||||||
|
200
|
||||||
|
);
|
||||||
|
}
|
||||||
|
catch (OperationCanceledException)
|
||||||
|
{
|
||||||
|
// Handle request cancellation (e.g., user navigated away)
|
||||||
|
_logger.LogWarning("Invoice Attachment Type fetch operation was canceled by the client.");
|
||||||
|
return ApiResponse<object>.ErrorResponse("Operation canceled", "Request canceled by user", 499);
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
// 5. Security & Error Handling:
|
||||||
|
// Log the real error with stack trace internally.
|
||||||
|
_logger.LogError(ex, "Critical error fetching Invoice Attachment Types for User ID: {UserId}", loggedInEmployee.Id);
|
||||||
|
|
||||||
|
// Return a sanitized message to the client. Never expose raw SQL errors or Stack Traces.
|
||||||
|
return ApiResponse<object>.ErrorResponse(
|
||||||
|
"An unexpected error occurred while processing your request.",
|
||||||
|
"Internal Server Error",
|
||||||
|
500
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
#region =================================================================== Currency APIs ===================================================================
|
#region =================================================================== Currency APIs ===================================================================
|
||||||
|
|
||||||
public async Task<ApiResponse<object>> GetCurrencyAsync(Employee loggedInEmployee, Guid tenantId)
|
public async Task<ApiResponse<object>> GetCurrencyAsync(Employee loggedInEmployee, Guid tenantId)
|
||||||
|
|||||||
@ -25,6 +25,10 @@ namespace Marco.Pms.Services.Service.ServiceInterfaces
|
|||||||
#region =================================================================== Purchase Invoice Status APIs ===================================================================
|
#region =================================================================== Purchase Invoice Status APIs ===================================================================
|
||||||
Task<ApiResponse<object>> GetPurchaseInvoiceStatusAsync(Employee loggedInEmployee, CancellationToken cancellationToken);
|
Task<ApiResponse<object>> GetPurchaseInvoiceStatusAsync(Employee loggedInEmployee, CancellationToken cancellationToken);
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
#region =================================================================== Invoice Attachment Type APIs ===================================================================
|
||||||
|
Task<ApiResponse<object>> GetInvoiceAttachmentTypeAsync(Employee loggedInEmployee, CancellationToken cancellationToken);
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
#region =================================================================== Currency APIs ===================================================================
|
#region =================================================================== Currency APIs ===================================================================
|
||||||
Task<ApiResponse<object>> GetCurrencyAsync(Employee loggedInEmployee, Guid tenantId);
|
Task<ApiResponse<object>> GetCurrencyAsync(Employee loggedInEmployee, Guid tenantId);
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user