Implemented an API to retrieve a list of organizations provided in the contacts.

This commit is contained in:
ashutosh.nehete 2025-05-21 10:28:17 +05:30
parent fbfd04c898
commit 635654890e
2 changed files with 16 additions and 0 deletions

View File

@ -113,6 +113,13 @@ namespace Marco.Pms.Services.Controllers
}
}
[HttpGet("organization")]
public async Task<IActionResult> GetOrganizationList()
{
var response = await _directoryHelper.GetOrganizationList();
return Ok(response);
}
// -------------------------------- Contact Notes --------------------------------
[HttpPost("note")]

View File

@ -743,6 +743,15 @@ namespace Marco.Pms.Services.Helpers
_logger.LogInfo("Employee ID {EmployeeId} sent an empty contact id", LoggedInEmployee.Id);
return ApiResponse<object>.ErrorResponse("Contact ID is empty", "Contact ID is empty", 400);
}
public async Task<ApiResponse<object>> 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<object>.SuccessResponse(organizationList, $"{organizationList.Count} records of organization names fetched from contacts", 200);
}
// -------------------------------- Contact Notes --------------------------------