Added an API to get list of job tags
This commit is contained in:
parent
a9f1a99e6f
commit
883a65d124
@ -121,6 +121,15 @@ namespace Marco.Pms.Services.Controllers
|
|||||||
return StatusCode(response.StatusCode, response);
|
return StatusCode(response.StatusCode, response);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[HttpGet("job/tag/list")]
|
||||||
|
public async Task<IActionResult> GetJobTagList()
|
||||||
|
{
|
||||||
|
Employee loggedInEmploee = await _userHelper.GetCurrentEmployeeAsync();
|
||||||
|
var response = await _serviceProject.GetJobTagListAsync(loggedInEmploee, tenantId);
|
||||||
|
|
||||||
|
return StatusCode(response.StatusCode, response);
|
||||||
|
}
|
||||||
|
|
||||||
[HttpPost("job/create")]
|
[HttpPost("job/create")]
|
||||||
public async Task<IActionResult> CreateJobTicket(CreateJobTicketDto model)
|
public async Task<IActionResult> CreateJobTicket(CreateJobTicketDto model)
|
||||||
{
|
{
|
||||||
|
|||||||
@ -18,8 +18,9 @@ namespace Marco.Pms.Services.Service.ServiceInterfaces
|
|||||||
#region =================================================================== Job Tickets Functions ===================================================================
|
#region =================================================================== Job Tickets Functions ===================================================================
|
||||||
Task<ApiResponse<object>> GetJobTicketsListAsync(Guid? projectId, int pageNumber, int pageSize, bool isActive, Employee loggedInEmployee, Guid tenantId);
|
Task<ApiResponse<object>> GetJobTicketsListAsync(Guid? projectId, int pageNumber, int pageSize, bool isActive, Employee loggedInEmployee, Guid tenantId);
|
||||||
Task<ApiResponse<object>> GetJobTicketDetailsAsync(Guid id, Employee loggedInEmployee, Guid tenantId);
|
Task<ApiResponse<object>> GetJobTicketDetailsAsync(Guid id, Employee loggedInEmployee, Guid tenantId);
|
||||||
Task<ApiResponse<object>> CreateJobTicketAsync(CreateJobTicketDto model, Employee loggedInEmployee, Guid tenantId);
|
|
||||||
Task<ApiResponse<object>> GetCommentListByJobTicketAsync(Guid? jobTicketId, int pageNumber, int pageSize, Employee loggedInEmployee, Guid tenantId);
|
Task<ApiResponse<object>> GetCommentListByJobTicketAsync(Guid? jobTicketId, int pageNumber, int pageSize, Employee loggedInEmployee, Guid tenantId);
|
||||||
|
Task<ApiResponse<object>> GetJobTagListAsync(Employee loggedInEmployee, Guid tenantId);
|
||||||
|
Task<ApiResponse<object>> CreateJobTicketAsync(CreateJobTicketDto model, Employee loggedInEmployee, Guid tenantId);
|
||||||
Task<ApiResponse<object>> AddCommentToJobTicketAsync(JobCommentDto model, Employee loggedInEmployee, Guid tenantId);
|
Task<ApiResponse<object>> AddCommentToJobTicketAsync(JobCommentDto model, Employee loggedInEmployee, Guid tenantId);
|
||||||
#endregion
|
#endregion
|
||||||
}
|
}
|
||||||
|
|||||||
@ -622,6 +622,7 @@ namespace Marco.Pms.Services.Service
|
|||||||
return ApiResponse<object>.ErrorResponse("Internal Server Error", "Failed to retrieve job details. Please try again later.", 500);
|
return ApiResponse<object>.ErrorResponse("Internal Server Error", "Failed to retrieve job details. Please try again later.", 500);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Retrieves a paginated list of comments for a specified job ticket within a tenant context.
|
/// Retrieves a paginated list of comments for a specified job ticket within a tenant context.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -707,6 +708,46 @@ namespace Marco.Pms.Services.Service
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Retrieves all job tags associated with the tenant, ordered alphabetically by name.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="loggedInEmployee">Employee making the request (for audit/logging).</param>
|
||||||
|
/// <param name="tenantId">Tenant identifier for multi-tenant data scoping.</param>
|
||||||
|
/// <returns>ApiResponse containing the list of job tag view models or error details.</returns>
|
||||||
|
public async Task<ApiResponse<object>> GetJobTagListAsync(Employee loggedInEmployee, Guid tenantId)
|
||||||
|
{
|
||||||
|
if (tenantId == Guid.Empty)
|
||||||
|
{
|
||||||
|
_logger.LogWarning("Attempt to fetch job tags with missing tenant context by employee {EmployeeId}", loggedInEmployee.Id);
|
||||||
|
return ApiResponse<object>.ErrorResponse("Access Denied", "Invalid tenant context.", 403);
|
||||||
|
}
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
_logger.LogInfo("Fetching job tags for tenant {TenantId} requested by employee {EmployeeId}", tenantId, loggedInEmployee.Id);
|
||||||
|
|
||||||
|
// Query job tags via JobTagMappings ensuring tenant isolation
|
||||||
|
var tags = await _context.JobTagMappings
|
||||||
|
.AsNoTracking()
|
||||||
|
.Include(jtm => jtm.JobTag)
|
||||||
|
.Where(jtm => jtm.JobTag != null && jtm.TenantId == tenantId)
|
||||||
|
.Select(jtm => jtm.JobTag!)
|
||||||
|
.Distinct() // Avoid duplicates if any tag maps multiple times
|
||||||
|
.OrderBy(jt => jt.Name)
|
||||||
|
.ToListAsync();
|
||||||
|
|
||||||
|
var response = _mapper.Map<List<TagVM>>(tags);
|
||||||
|
|
||||||
|
_logger.LogInfo("{Count} job tags fetched successfully for tenant {TenantId}", response.Count, tenantId);
|
||||||
|
|
||||||
|
return ApiResponse<object>.SuccessResponse(response, $"{response.Count} job tag record(s) fetched successfully.", 200);
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "Failed to fetch job tags for tenant {TenantId} requested by employee {EmployeeId}", tenantId, loggedInEmployee.Id);
|
||||||
|
return ApiResponse<object>.ErrorResponse("Internal Server Error", "Failed to retrieve job tags. Please try again later.", 500);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Creates a new job ticket with optional assignees and tags within a transactional scope.
|
/// Creates a new job ticket with optional assignees and tags within a transactional scope.
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user