Added the date in project report API in market controller

This commit is contained in:
ashutosh.nehete 2025-11-24 12:01:56 +05:30
parent 457e3b411e
commit e73413c849
2 changed files with 12 additions and 21 deletions

View File

@ -133,30 +133,13 @@ namespace Marco.Pms.Services.Controllers
} }
[HttpGet("get/project/report/{projectId}")] [HttpGet("get/project/report/{projectId}")]
public async Task<IActionResult> GetProjectReport(Guid projectId)
{
using var scope = _serviceScopeFactory.CreateScope();
var _reportHelper = scope.ServiceProvider.GetRequiredService<ReportHelper>();
var _logger = scope.ServiceProvider.GetRequiredService<ILoggingService>();
var resonse = await _reportHelper.GetDailyProjectReportWithOutTenant(projectId);
if (resonse == null)
{
_logger.LogWarning("Project report not found");
return NotFound(ApiResponse<object>.ErrorResponse("Project report not found", "Project report not found", 404));
}
_logger.LogInfo("Report for the project fetched successfully");
return Ok(ApiResponse<object>.SuccessResponse(resonse, "Report for the project fetched successfully", 200));
}
/// <summary> /// <summary>
/// Retrieves a daily project report by its unique identifier. /// Retrieves a daily project report by its unique identifier.
/// </summary> /// </summary>
/// <param name="projectId">The GUID of the project for which to generate the report.</param> /// <param name="projectId">The GUID of the project for which to generate the report.</param>
/// <returns>An IActionResult containing the project report or an appropriate error response.</returns> /// <returns>An IActionResult containing the project report or an appropriate error response.</returns>
[HttpGet("{projectId}/report")] public async Task<IActionResult> GetProjectReportAsync(Guid projectId, [FromQuery] DateTime? date)
public async Task<IActionResult> GetProjectReportAsync(Guid projectId)
{ {
using var scope = _serviceScopeFactory.CreateScope(); using var scope = _serviceScopeFactory.CreateScope();
var _reportHelper = scope.ServiceProvider.GetRequiredService<ReportHelper>(); var _reportHelper = scope.ServiceProvider.GetRequiredService<ReportHelper>();
@ -167,8 +150,17 @@ namespace Marco.Pms.Services.Controllers
try try
{ {
DateTime reportDate;
if (date.HasValue)
{
reportDate = date.Value;
}
else
{
reportDate = DateTime.UtcNow.AddDays(-1).Date;
}
// Call the helper service, which is now available as a class member. // Call the helper service, which is now available as a class member.
var response = await _reportHelper.GetDailyProjectReportWithOutTenant(projectId); var response = await _reportHelper.GetDailyProjectReportWithOutTenant(projectId, reportDate);
// Check if the report data was found. // Check if the report data was found.
if (response == null) if (response == null)

View File

@ -25,10 +25,9 @@ namespace Marco.Pms.Services.Helpers
_cache = cache; _cache = cache;
} }
public async Task<ProjectStatisticReport?> GetDailyProjectReportWithOutTenant(Guid projectId) public async Task<ProjectStatisticReport?> GetDailyProjectReportWithOutTenant(Guid projectId, DateTime reportDate)
{ {
// await _cache.GetBuildingAndFloorByWorkAreaId(); // await _cache.GetBuildingAndFloorByWorkAreaId();
DateTime reportDate = DateTime.UtcNow.AddDays(-1).Date;
var project = await _cache.GetProjectDetailsWithBuildings(projectId); var project = await _cache.GetProjectDetailsWithBuildings(projectId);
if (project == null) if (project == null)
{ {