From 4161506defc415f52083e73984d095c19d72e00c Mon Sep 17 00:00:00 2001 From: "ashutosh.nehete" Date: Thu, 28 Aug 2025 12:48:13 +0530 Subject: [PATCH] Added the get list of Document type API --- .../DocumentManager/DocumentTypeVM.cs | 1 + .../Controllers/MasterController.cs | 11 +++++ .../MappingProfiles/MappingProfile.cs | 3 +- Marco.Pms.Services/Service/MasterService.cs | 48 +++++++++++++++++++ .../ServiceInterfaces/IMasterService.cs | 9 +++- 5 files changed, 70 insertions(+), 2 deletions(-) diff --git a/Marco.Pms.Model/ViewModels/DocumentManager/DocumentTypeVM.cs b/Marco.Pms.Model/ViewModels/DocumentManager/DocumentTypeVM.cs index a7c3d0a..369e962 100644 --- a/Marco.Pms.Model/ViewModels/DocumentManager/DocumentTypeVM.cs +++ b/Marco.Pms.Model/ViewModels/DocumentManager/DocumentTypeVM.cs @@ -9,6 +9,7 @@ public int MaxFilesAllowed { get; set; } public double MaxSizeAllowedInKB { get; set; } public bool IsValidationRequired { get; set; } + public bool IsMandatory { get; set; } public bool IsSystem { get; set; } public bool IsActive { get; set; } public DocumentCategoryVM? DocumentCategory { get; set; } diff --git a/Marco.Pms.Services/Controllers/MasterController.cs b/Marco.Pms.Services/Controllers/MasterController.cs index 0c374d6..bab2a5c 100644 --- a/Marco.Pms.Services/Controllers/MasterController.cs +++ b/Marco.Pms.Services/Controllers/MasterController.cs @@ -960,6 +960,17 @@ namespace Marco.Pms.Services.Controllers return StatusCode(response.StatusCode, response); } + #endregion + #region =================================================================== Document Type APIs =================================================================== + + [HttpGet("document-type/list")] + public async Task GetDocumentTypeMasterList([FromQuery] Guid? documentCategoryId) + { + var loggedInEmployee = await _userHelper.GetCurrentEmployeeAsync(); + var response = await _masterService.GetDocumentTypeMasterListAsync(documentCategoryId, loggedInEmployee, tenantId); + return StatusCode(response.StatusCode, response); + } + #endregion } } diff --git a/Marco.Pms.Services/MappingProfiles/MappingProfile.cs b/Marco.Pms.Services/MappingProfiles/MappingProfile.cs index f283bd8..fb55f03 100644 --- a/Marco.Pms.Services/MappingProfiles/MappingProfile.cs +++ b/Marco.Pms.Services/MappingProfiles/MappingProfile.cs @@ -315,7 +315,8 @@ namespace Marco.Pms.Services.MappingProfiles CreateMap(); CreateMap(); - CreateMap(); + + CreateMap(); CreateMap(); #endregion diff --git a/Marco.Pms.Services/Service/MasterService.cs b/Marco.Pms.Services/Service/MasterService.cs index 11e64ba..290ec3d 100644 --- a/Marco.Pms.Services/Service/MasterService.cs +++ b/Marco.Pms.Services/Service/MasterService.cs @@ -544,6 +544,54 @@ namespace Marco.Pms.Services.Service } + #endregion + + #region =================================================================== Document Type APIs =================================================================== + + + public async Task> GetDocumentTypeMasterListAsync(Guid? documentCategoryId, Employee loggedInEmployee, Guid tenantId) + { + try + { + // ✅ Tenant validation + if (tenantId != loggedInEmployee.TenantId) + { + _logger.LogWarning("Access denied. Employee {EmployeeId} (TenantId: {EmployeeTenantId}) attempted to fetch document types for TenantId: {RequestedTenantId}", + loggedInEmployee.Id, loggedInEmployee.TenantId, tenantId); + + return ApiResponse.ErrorResponse("Access Denied", "You do not have access to this information", 403); + } + + // ✅ Build query + IQueryable documentTypeQuery = _context.DocumentTypeMasters + .AsNoTracking() // optimization: read-only + .Where(dc => dc.TenantId == tenantId); + + // ✅ Apply optional filter + if (documentCategoryId.HasValue) + { + documentTypeQuery = documentTypeQuery.Where(dc => dc.DocumentCategoryId == documentCategoryId.Value); + } + + // ✅ Fetch and map + var documentType = await documentTypeQuery.ToListAsync(); + var response = _mapper.Map>(documentType); + + _logger.LogInfo("{Count} document type fetched successfully for TenantId: {TenantId} by Employee {EmployeeId}", + response.Count, tenantId, loggedInEmployee.Id); + + return ApiResponse.SuccessResponse(response, $"{response.Count} document type have been fetched successfully.", 200); + } + catch (Exception ex) + { + _logger.LogError(ex, "Error occurred while fetching document type for TenantId: {TenantId} by Employee {EmployeeId}", + tenantId, loggedInEmployee.Id); + + return ApiResponse.ErrorResponse("Internal Server Error", "Server Error occured", 500); + } + } + + #endregion #region =================================================================== Helper Function =================================================================== diff --git a/Marco.Pms.Services/Service/ServiceInterfaces/IMasterService.cs b/Marco.Pms.Services/Service/ServiceInterfaces/IMasterService.cs index 23f3c51..c85b183 100644 --- a/Marco.Pms.Services/Service/ServiceInterfaces/IMasterService.cs +++ b/Marco.Pms.Services/Service/ServiceInterfaces/IMasterService.cs @@ -27,12 +27,19 @@ namespace Marco.Pms.Services.Service.ServiceInterfaces #endregion - #region =================================================================== Payment mode APIs =================================================================== + #region =================================================================== Document Category APIs =================================================================== Task> GetDocumentCategoryMasterListAsync(Guid? entityTypeId, Employee loggedInEmployee, Guid tenantId); //Task> CreatePaymentModeAsync(PaymentModeMatserDto model, Employee loggedInEmployee, Guid tenantId); //Task> UpdatePaymentModeAsync(Guid id, PaymentModeMatserDto model, Employee loggedInEmployee, Guid tenantId); //Task> DeletePaymentModeAsync(Guid id, bool isActive, Employee loggedInEmployee, Guid tenantId); + #endregion + #region =================================================================== Document Type APIs =================================================================== + Task> GetDocumentTypeMasterListAsync(Guid? documentCategoryId, Employee loggedInEmployee, Guid tenantId); + //Task> CreatePaymentModeAsync(PaymentModeMatserDto model, Employee loggedInEmployee, Guid tenantId); + //Task> UpdatePaymentModeAsync(Guid id, PaymentModeMatserDto model, Employee loggedInEmployee, Guid tenantId); + //Task> DeletePaymentModeAsync(Guid id, bool isActive, Employee loggedInEmployee, Guid tenantId); + #endregion } } -- 2.43.0