diff --git a/.version b/.version
index 951b434..cbe80f6 100644
--- a/.version
+++ b/.version
@@ -1 +1 @@
-0.2.5.1
\ No newline at end of file
+0.3.6.5
\ No newline at end of file
diff --git a/Brizco.Api/Brizco.Api.csproj b/Brizco.Api/Brizco.Api.csproj
index dc03ef0..241581f 100644
--- a/Brizco.Api/Brizco.Api.csproj
+++ b/Brizco.Api/Brizco.Api.csproj
@@ -6,8 +6,8 @@
enable
Linux
..\docker-compose.dcproj
- 0.2.5.1
- 0.2.5.1
+ 0.3.6.5
+ 0.3.6.5
diff --git a/Brizco.Api/Controllers/ReportController.cs b/Brizco.Api/Controllers/ReportController.cs
index bc3378f..3b97b9a 100644
--- a/Brizco.Api/Controllers/ReportController.cs
+++ b/Brizco.Api/Controllers/ReportController.cs
@@ -14,7 +14,7 @@ public class ReportController : ICarterModule
.WithDisplayName("Get Tasks Report")
.HasApiVersion(1.0);
- group.MapGet("shit/plan/{shiftPLanId}", GetShiftPlanReportAsync)
+ group.MapGet("shift/plan/{shiftPLanId}", GetShiftPlanReportAsync)
.WithDisplayName("Get ShiftPlan Report")
.HasApiVersion(1.0);
}
diff --git a/Brizco.Api/Controllers/ShiftPlanController.cs b/Brizco.Api/Controllers/ShiftPlanController.cs
index 33fd7d7..97e6137 100644
--- a/Brizco.Api/Controllers/ShiftPlanController.cs
+++ b/Brizco.Api/Controllers/ShiftPlanController.cs
@@ -1,4 +1,6 @@
-namespace Brizco.Api.Controllers;
+using Brizco.Domain.Enums;
+
+namespace Brizco.Api.Controllers;
public class ShiftPlanController : ICarterModule
{
@@ -37,8 +39,8 @@ public class ShiftPlanController : ICarterModule
// GET:Get All Entity
- public async Task GetAllAsync([FromQuery] int page, [FromQuery] long? selectedDate, ISender sender, CancellationToken cancellationToken)
- => TypedResults.Ok(await sender.Send(new GetShiftPlansQuery(page , selectedDate ?? 0), cancellationToken));
+ public async Task GetAllAsync([FromQuery] int page, [FromQuery] long? selectedDate, [FromQuery] DateTimeQueryFilter? dateFilter , ISender sender, CancellationToken cancellationToken)
+ => TypedResults.Ok(await sender.Send(new GetShiftPlansQuery(page , selectedDate ?? 0 , DateTimeQueryFilter: dateFilter), cancellationToken));
// GET:Get An Entity By Id
public async Task GetAsync(Guid id, ISender sender, CancellationToken cancellationToken)
diff --git a/Brizco.Api/Program.cs b/Brizco.Api/Program.cs
index 88f111b..911b1c3 100644
--- a/Brizco.Api/Program.cs
+++ b/Brizco.Api/Program.cs
@@ -91,6 +91,11 @@ builder.Host.ConfigureContainer(builder =>
.Create(typeof(DomainConfig).Assembly)
.WithAllOpenGenericHandlerTypesRegistered()
.Build());
+
+ builder.RegisterMediatR(MediatRConfigurationBuilder
+ .Create(typeof(CoreConfig).Assembly)
+ .WithAllOpenGenericHandlerTypesRegistered()
+ .Build());
});
var app = builder.Build();
diff --git a/Brizco.Core/CoreServices/ReportServices/ShiftPlanReportCommandHandler.cs b/Brizco.Core/CoreServices/ReportServices/ShiftPlanReportCommandHandler.cs
index b01f036..485e541 100644
--- a/Brizco.Core/CoreServices/ReportServices/ShiftPlanReportCommandHandler.cs
+++ b/Brizco.Core/CoreServices/ReportServices/ShiftPlanReportCommandHandler.cs
@@ -27,7 +27,7 @@ public class ShiftPlanReportCommandHandler : IRequestHandler>;
public sealed record GetShiftPlanQuery(Guid Id) :
diff --git a/Brizco.Domain/Enums/DateTimeQueryFilter.cs b/Brizco.Domain/Enums/DateTimeQueryFilter.cs
new file mode 100644
index 0000000..1bd4065
--- /dev/null
+++ b/Brizco.Domain/Enums/DateTimeQueryFilter.cs
@@ -0,0 +1,12 @@
+namespace Brizco.Domain.Enums;
+
+public enum DateTimeQueryFilter
+{
+ CustomDate = 0,
+ Today = 1,
+ Yesterday = 2,
+ PastWeek = 10,
+ NextWeek = 11,
+ PastMonth = 20,
+ NextMonth = 21
+}
\ No newline at end of file
diff --git a/Brizco.Repository/Handlers/ShiftPlan/GetShiftPlansQueryHandler.cs b/Brizco.Repository/Handlers/ShiftPlan/GetShiftPlansQueryHandler.cs
index 43dcb90..234037f 100644
--- a/Brizco.Repository/Handlers/ShiftPlan/GetShiftPlansQueryHandler.cs
+++ b/Brizco.Repository/Handlers/ShiftPlan/GetShiftPlansQueryHandler.cs
@@ -14,41 +14,102 @@ public class GetShiftPlansQueryHandler : IRequestHandler> Handle(GetShiftPlansQuery request, CancellationToken cancellationToken)
{
- List shiftPlans;
- if (request.SelectedDate > 0)
+ if (_currentUserService.ComplexId == null)
+ throw new AppException("ComplexId is null", ApiResultStatusCode.NotFound);
+ if (!Guid.TryParse(_currentUserService.ComplexId, out Guid complexId))
+ throw new AppException("ComplexId is wrong", ApiResultStatusCode.NotFound);
+
+ IQueryable baseQuery = _repositoryWrapper.SetRepository()
+ .TableNoTracking
+ .OrderByDescending(s => s.CreatedAt)
+ .Where(s => s.ComplexId == complexId);
+
+ List shiftPlans = new List();
+
+ if (request.SelectedDate == 0)
{
- var selectedDate = DateTimeExtensions.UnixTimeStampToDateTime(request.SelectedDate);
- shiftPlans = await _repositoryWrapper.SetRepository()
- .TableNoTracking
- .Where(s => s.PlanFor.Date == selectedDate.Date)
- .OrderByDescending(s => s.CreatedAt)
+ return await baseQuery
.Skip(request.Page * 15).Take(15)
.Select(ShiftPlanMapper.ProjectToSDto)
.ToListAsync(cancellationToken);
+
+ }
+ else if (request.SelectedDate > 0)
+ {
+ if (request.SelectedDate > 0)
+ {
+ var selectedDate = DateTimeExtensions.UnixTimeStampToDateTime(request.SelectedDate);
+ shiftPlans = await baseQuery.Where(s => s.PlanFor.Date == selectedDate.Date)
+ .Skip(request.Page * 15).Take(15)
+ .Select(ShiftPlanMapper.ProjectToSDto)
+ .ToListAsync(cancellationToken);
+ }
+ else
+ {
+ switch (request.DateTimeQueryFilter)
+ {
+ case DateTimeQueryFilter.Today:
+ shiftPlans = await baseQuery.Where(s => s.PlanFor.Date == DateTime.Now.Date)
+ .Skip(request.Page * 15).Take(15)
+ .Select(ShiftPlanMapper.ProjectToSDto)
+ .ToListAsync(cancellationToken);
+ break;
+ case DateTimeQueryFilter.Yesterday:
+ shiftPlans = await baseQuery.Where(s => s.PlanFor.Date == DateTime.Now.AddDays(-1).Date)
+ .Skip(request.Page * 15).Take(15)
+ .Select(ShiftPlanMapper.ProjectToSDto)
+ .ToListAsync(cancellationToken);
+ break;
+ case DateTimeQueryFilter.PastWeek:
+ shiftPlans = await baseQuery.Where(s => s.PlanFor.Date >= DateTime.Now.AddDays(-7).Date)
+ .OrderByDescending(s => s.CreatedAt)
+ .Skip(request.Page * 15).Take(15)
+ .Select(ShiftPlanMapper.ProjectToSDto)
+ .ToListAsync(cancellationToken);
+ break;
+ case DateTimeQueryFilter.NextWeek:
+ shiftPlans = await baseQuery.Where(s => s.PlanFor.Date >= DateTime.Now.Date && s.PlanFor.Date <= DateTime.Today.AddDays(+7))
+ .OrderByDescending(s => s.CreatedAt)
+ .Skip(request.Page * 15).Take(15)
+ .Select(ShiftPlanMapper.ProjectToSDto)
+ .ToListAsync(cancellationToken);
+ break;
+ case DateTimeQueryFilter.PastMonth:
+ shiftPlans = await baseQuery.Where(s => s.PlanFor.Date >= DateTime.Now.AddDays(-31).Date)
+ .OrderByDescending(s => s.CreatedAt)
+ .Skip(request.Page * 15).Take(15)
+ .Select(ShiftPlanMapper.ProjectToSDto)
+ .ToListAsync(cancellationToken);
+ break;
+ case DateTimeQueryFilter.NextMonth:
+ shiftPlans = await baseQuery.Where(s => s.PlanFor.Date >= DateTime.Now.Date && s.PlanFor.Date <= DateTime.Today.AddDays(+31))
+ .OrderByDescending(s => s.CreatedAt)
+ .Skip(request.Page * 15).Take(15)
+ .Select(ShiftPlanMapper.ProjectToSDto)
+ .ToListAsync(cancellationToken);
+ break;
+ case null:
+ break;
+ default:
+ throw new ArgumentOutOfRangeException();
+ }
+ }
+
foreach (var shiftPlan in shiftPlans)
{
var activitiesCount = await _repositoryWrapper.SetRepository()
.TableNoTracking
- .CountAsync(a => a.SetFor.Date == selectedDate.Date && a.ShiftId == shiftPlan.Id, cancellationToken);
+ .CountAsync(a => a.SetFor.Date == shiftPlan.PlanFor.Date && a.ShiftId == shiftPlan.Id, cancellationToken);
var doneActivitiesCount = await _repositoryWrapper.SetRepository()
.TableNoTracking
- .CountAsync(a => a.Status == ActivityStatus.Done && a.SetFor.Date == selectedDate.Date && a.ShiftId == shiftPlan.Id, cancellationToken);
+ .CountAsync(a => a.Status == ActivityStatus.Done && a.SetFor.Date == shiftPlan.PlanFor.Date && a.ShiftId == shiftPlan.Id, cancellationToken);
var undoneActivitiesCount = await _repositoryWrapper.SetRepository()
.TableNoTracking
- .CountAsync(a => a.Status == ActivityStatus.UnDone && a.SetFor.Date == selectedDate.Date && a.ShiftId == shiftPlan.Id, cancellationToken);
+ .CountAsync(a => a.Status == ActivityStatus.UnDone && a.SetFor.Date == shiftPlan.PlanFor.Date && a.ShiftId == shiftPlan.Id, cancellationToken);
shiftPlan.UndoneActivitiesCount = undoneActivitiesCount;
shiftPlan.DoneActivitiesCount = doneActivitiesCount;
shiftPlan.TotalActivitiesCount = activitiesCount;
}
-
- }
- else
- {
- shiftPlans = await _repositoryWrapper.SetRepository().TableNoTracking
- .OrderByDescending(s => s.CreatedAt)
- .Skip(request.Page * 15).Take(15)
- .Select(ShiftPlanMapper.ProjectToSDto)
- .ToListAsync(cancellationToken);
}
return shiftPlans;