add 'assigned-projects' endpoint to retrieve all projects by employee ID
This commit is contained in:
parent
d049be9e49
commit
038e585253
@ -1,4 +1,5 @@
|
||||
using Marco.Pms.DataAccess.Data;
|
||||
using System.Collections.Generic;
|
||||
using Marco.Pms.DataAccess.Data;
|
||||
using Marco.Pms.Model.Dtos.Project;
|
||||
using Marco.Pms.Model.Employees;
|
||||
using Marco.Pms.Model.Entitlements;
|
||||
@ -653,5 +654,45 @@ namespace MarcoBMS.Services.Controllers
|
||||
|
||||
}
|
||||
|
||||
[HttpGet("assigned-projects/{employeeId}")]
|
||||
public async Task<IActionResult> GetProjectsByEmployee([FromRoute] Guid employeeId)
|
||||
{
|
||||
|
||||
Guid tenantId = _userHelper.GetTenantId();
|
||||
if (employeeId == Guid.Empty)
|
||||
{
|
||||
return BadRequest(ApiResponse<object>.ErrorResponse("Invalid details.", "Employee id not valid.", 400));
|
||||
}
|
||||
|
||||
List<Guid> projectList = await _context.ProjectAllocations
|
||||
.Where(c => c.TenantId == tenantId && c.EmployeeId == employeeId)
|
||||
.Select(c => c.ProjectId).Distinct()
|
||||
.ToListAsync();
|
||||
|
||||
if (!projectList.Any())
|
||||
{
|
||||
return NotFound(ApiResponse<object>.SuccessResponse(new List<object>(), "No projects found.",404));
|
||||
}
|
||||
|
||||
|
||||
List<Project> projectlist = await _context.Projects
|
||||
.Where(p => projectList.Contains(p.Id))
|
||||
.ToListAsync();
|
||||
|
||||
List<ProjectListVM> projects = new List<ProjectListVM>();
|
||||
|
||||
|
||||
foreach (var project in projectlist) {
|
||||
|
||||
projects.Add(project.ToProjectListVMFromProject());
|
||||
}
|
||||
|
||||
|
||||
|
||||
return Ok(ApiResponse<object>.SuccessResponse(projects, "Success.", 200));
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user