Added an API to Get a list of buckets Assigned to that employee

This commit is contained in:
ashutosh.nehete 2025-05-15 19:26:55 +05:30
parent 6e0cdbcfe3
commit 9e813c1e51
3 changed files with 39 additions and 0 deletions

View File

@ -178,5 +178,16 @@ namespace Marco.Pms.Model.Mapper
Description = contactType.Description ?? string.Empty, Description = contactType.Description ?? string.Empty,
}; };
} }
// Bucket
public static BucketVM ToBucketVMFromBucket(this Bucket bucket)
{
return new BucketVM
{
Id = bucket.Id,
Name = bucket.Name,
Description = bucket.Description
};
}
} }
} }

View File

@ -83,5 +83,11 @@ namespace Marco.Pms.Services.Controllers
} }
[HttpGet("buckets")]
public async Task<IActionResult> GetBucketList()
{
var response = await _directoryHelper.GetBucketList();
return Ok(response);
}
} }
} }

View File

@ -1772,5 +1772,27 @@ namespace Marco.Pms.Services.Helpers
_logger.LogWarning("Employee with ID {LoggedInEmployeeId} sended empty payload", LoggedInEmployee.Id); _logger.LogWarning("Employee with ID {LoggedInEmployeeId} sended empty payload", LoggedInEmployee.Id);
return ApiResponse<object>.ErrorResponse("User Send empty Payload", "User Send empty Payload", 400); return ApiResponse<object>.ErrorResponse("User Send empty Payload", "User Send empty Payload", 400);
} }
// -------------------------------- Bucket --------------------------------
public async Task<ApiResponse<object>> GetBucketList()
{
Guid tenantId = _userHelper.GetTenantId();
var LoggedInEmployee = await _userHelper.GetCurrentEmployeeAsync();
List<EmployeeBucketMapping> employeeBuckets = await _context.EmployeeBucketMappings.Where(b => b.EmployeeId == LoggedInEmployee.Id).ToListAsync();
var bucketIds = employeeBuckets.Select(b => b.BucketId).ToList();
List<Bucket> bucketList = await _context.Buckets.Where(b => bucketIds.Contains(b.Id)).ToListAsync();
List<BucketVM> bucketVMs = new List<BucketVM>();
foreach (var bucket in bucketList)
{
BucketVM bucketVM = bucket.ToBucketVMFromBucket();
bucketVMs.Add(bucketVM);
}
_logger.LogInfo("{count} Buckets are fetched by Employee with ID {LoggedInEmployeeId}", bucketVMs.Count, LoggedInEmployee.Id);
return ApiResponse<object>.SuccessResponse(bucketVMs, System.String.Format("{0} buckets fetched successfully", bucketVMs.Count), 200);
}
} }
} }