Added an API to Get a list of buckets Assigned to that employee
This commit is contained in:
parent
967488e9c1
commit
532e0ff16d
@ -178,5 +178,16 @@ namespace Marco.Pms.Model.Mapper
|
||||
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
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
9
Marco.Pms.Model/ViewModels/Directory/BucketVM.cs
Normal file
9
Marco.Pms.Model/ViewModels/Directory/BucketVM.cs
Normal file
@ -0,0 +1,9 @@
|
||||
namespace Marco.Pms.Model.ViewModels.Directory
|
||||
{
|
||||
public class BucketVM
|
||||
{
|
||||
public Guid Id { get; set; }
|
||||
public string? Name { get; set; }
|
||||
public string? Description { get; set; }
|
||||
}
|
||||
}
|
@ -83,5 +83,11 @@ namespace Marco.Pms.Services.Controllers
|
||||
}
|
||||
|
||||
|
||||
[HttpGet("buckets")]
|
||||
public async Task<IActionResult> GetBucketList()
|
||||
{
|
||||
var response = await _directoryHelper.GetBucketList();
|
||||
return Ok(response);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -433,5 +433,27 @@ namespace Marco.Pms.Services.Helpers
|
||||
_logger.LogWarning("Employee with ID {LoggedInEmployeeId} sended empty payload", LoggedInEmployee.Id);
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user