From 9fbf55eeb58f518169343a75628ad9674a1686fb Mon Sep 17 00:00:00 2001 From: "ashutosh.nehete" Date: Wed, 21 May 2025 10:28:17 +0530 Subject: [PATCH] Implemented an API to retrieve a list of organizations provided in the contacts. --- Marco.Pms.Services/Controllers/DirectoryController.cs | 7 +++++++ Marco.Pms.Services/Helpers/DirectoryHelper.cs | 9 +++++++++ 2 files changed, 16 insertions(+) diff --git a/Marco.Pms.Services/Controllers/DirectoryController.cs b/Marco.Pms.Services/Controllers/DirectoryController.cs index 12317d3..8f2cb5c 100644 --- a/Marco.Pms.Services/Controllers/DirectoryController.cs +++ b/Marco.Pms.Services/Controllers/DirectoryController.cs @@ -113,6 +113,13 @@ namespace Marco.Pms.Services.Controllers } } + [HttpGet("organization")] + public async Task GetOrganizationList() + { + var response = await _directoryHelper.GetOrganizationList(); + return Ok(response); + } + // -------------------------------- Contact Notes -------------------------------- [HttpPost("note")] diff --git a/Marco.Pms.Services/Helpers/DirectoryHelper.cs b/Marco.Pms.Services/Helpers/DirectoryHelper.cs index 20e21a7..51ca0d8 100644 --- a/Marco.Pms.Services/Helpers/DirectoryHelper.cs +++ b/Marco.Pms.Services/Helpers/DirectoryHelper.cs @@ -743,6 +743,15 @@ namespace Marco.Pms.Services.Helpers _logger.LogInfo("Employee ID {EmployeeId} sent an empty contact id", LoggedInEmployee.Id); return ApiResponse.ErrorResponse("Contact ID is empty", "Contact ID is empty", 400); } + public async Task> GetOrganizationList() + { + Guid tenantId = _userHelper.GetTenantId(); + var LoggedInEmployee = await _userHelper.GetCurrentEmployeeAsync(); + + var organizationList = await _context.Contacts.Where(c => c.TenantId == tenantId).Select(c => c.Organization).Distinct().ToListAsync(); + _logger.LogInfo("Employee {EmployeeId} fetched list of organizations in a tenant {TenantId}", LoggedInEmployee.Id, tenantId); + return ApiResponse.SuccessResponse(organizationList, $"{organizationList.Count} records of organization names fetched from contacts", 200); + } // -------------------------------- Contact Notes --------------------------------