From 7863599652ac3b72b051d4f4cc888895d1ba0d01 Mon Sep 17 00:00:00 2001
From: Boburmirzo <137428656+Boburm1rzo@users.noreply.github.com>
Date: Sat, 1 Mar 2025 17:38:10 +0500
Subject: [PATCH 1/3] manager checkpoint

---
 .../DTOs/CheckPoint/CheckPointDto.cs          |  8 +++--
 .../ManagerReview/CreateManagerReviewDto.cs   |  4 +--
 .../Mappings/CheckPointMappings.cs            |  6 ++--
 .../Services/DashboardService.cs              |  2 +-
 .../Services/Review/ManagerReviewService.cs   |  4 +++
 .../Services/MechanicHandoverTests.cs         | 30 +++++++++++++++++++
 6 files changed, 46 insertions(+), 8 deletions(-)
 create mode 100644 CheckDrive.Api/Tests/CheckDrive.Tests.Unit/Services/MechanicHandoverTests.cs

diff --git a/CheckDrive.Api/CheckDrive.Application/DTOs/CheckPoint/CheckPointDto.cs b/CheckDrive.Api/CheckDrive.Application/DTOs/CheckPoint/CheckPointDto.cs
index 544c156..892d179 100644
--- a/CheckDrive.Api/CheckDrive.Application/DTOs/CheckPoint/CheckPointDto.cs
+++ b/CheckDrive.Api/CheckDrive.Application/DTOs/CheckPoint/CheckPointDto.cs
@@ -9,15 +9,17 @@ public sealed record CheckPointDto(
     CheckPointStatus Status,
     string Driver,
     string CarModel,
-    decimal CurrentFuelAmount,
-    string Mechanic,
     decimal InitialMillage,
-    decimal FinalMileage,
+    decimal CurrentFuelAmount,
+    string MechanicAcceptance,
+    string MechanicHandover,
     string Operator,
     decimal InitialOilAmount,
     decimal OilRefillAmount,
     string Oil,
     string Dispatcher,
+    decimal FinalMileage,
     decimal FuelConsumptionAdjustment,
+    decimal RemainingFuelAmount,
     decimal DebtAmount
 );
diff --git a/CheckDrive.Api/CheckDrive.Application/DTOs/ManagerReview/CreateManagerReviewDto.cs b/CheckDrive.Api/CheckDrive.Application/DTOs/ManagerReview/CreateManagerReviewDto.cs
index 4cdbed4..750e7f8 100644
--- a/CheckDrive.Api/CheckDrive.Application/DTOs/ManagerReview/CreateManagerReviewDto.cs
+++ b/CheckDrive.Api/CheckDrive.Application/DTOs/ManagerReview/CreateManagerReviewDto.cs
@@ -6,8 +6,8 @@ public sealed record CreateManagerReviewDto(
     int CheckPointId,
     int ReviewerId,
     string? Notes,
-    int InitialMileage,
-    int FinalMileage,
+    decimal InitialMileage,
+    decimal FinalMileage,
     decimal FuelConsumption,
     decimal RemainingFuelAmount,
     decimal DebtAmount)
diff --git a/CheckDrive.Api/CheckDrive.Application/Mappings/CheckPointMappings.cs b/CheckDrive.Api/CheckDrive.Application/Mappings/CheckPointMappings.cs
index 3e9b058..74ca74a 100644
--- a/CheckDrive.Api/CheckDrive.Application/Mappings/CheckPointMappings.cs
+++ b/CheckDrive.Api/CheckDrive.Application/Mappings/CheckPointMappings.cs
@@ -12,15 +12,17 @@ public CheckPointMappings()
             .ForCtorParam(nameof(CheckPointDto.Driver), opt => opt.MapFrom(src => $"{src.DoctorReview.Driver.FirstName} {src.DoctorReview.Driver.LastName}"))
             .ForCtorParam(nameof(CheckPointDto.CarModel), opt => opt.MapFrom(src => $"{src.MechanicHandover!.Car.Model}"))
             .ForCtorParam(nameof(CheckPointDto.CurrentFuelAmount), opt => opt.MapFrom(src => src.OperatorReview!.InitialOilAmount))
-            .ForCtorParam(nameof(CheckPointDto.Mechanic), opt => opt.MapFrom(src => $"{src.MechanicHandover!.Mechanic.FirstName} {src.MechanicHandover.Mechanic.LastName}"))
+            .ForCtorParam(nameof(CheckPointDto.MechanicHandover), opt => opt.MapFrom(src => $"{src.MechanicHandover!.Mechanic.FirstName} {src.MechanicHandover.Mechanic.LastName}"))
+            .ForCtorParam(nameof(CheckPointDto.MechanicAcceptance), opt => opt.MapFrom(src => $"{src.MechanicAcceptance!.Mechanic.FirstName} {src.MechanicAcceptance.Mechanic.LastName}"))
             .ForCtorParam(nameof(CheckPointDto.InitialMillage), opt => opt.MapFrom(src => src.MechanicHandover!.InitialMileage))
             .ForCtorParam(nameof(CheckPointDto.FinalMileage), opt => opt.MapFrom(src => src.DispatcherReview!.FinalMileage))
             .ForCtorParam(nameof(CheckPointDto.Operator), opt => opt.MapFrom(src => $"{src.OperatorReview!.Operator.FirstName} {src.OperatorReview.Operator.LastName}"))
             .ForCtorParam(nameof(CheckPointDto.InitialOilAmount), opt => opt.MapFrom(src => src.OperatorReview!.InitialOilAmount))
             .ForCtorParam(nameof(CheckPointDto.OilRefillAmount), opt => opt.MapFrom(src => src.OperatorReview!.OilRefillAmount))
-            .ForCtorParam(nameof(CheckPointDto.Oil), opt => opt.MapFrom(src => src.OperatorReview.OilMark.Name))
+            .ForCtorParam(nameof(CheckPointDto.Oil), opt => opt.MapFrom(src => src.OperatorReview!.OilMark.Name))
             .ForCtorParam(nameof(CheckPointDto.Dispatcher), opt => opt.MapFrom(src => $"{src.DispatcherReview!.Dispatcher.FirstName} {src.DispatcherReview.Dispatcher.LastName}"))
             .ForCtorParam(nameof(CheckPointDto.FuelConsumptionAdjustment), opt => opt.MapFrom(src => src.DispatcherReview!.FuelConsumptionAmount))
+            .ForCtorParam(nameof(CheckPointDto.RemainingFuelAmount), opt => opt.MapFrom(src => src.DispatcherReview!.RemainingFuelAmount))
             .ForCtorParam(nameof(CheckPointDto.DebtAmount), opt => opt.MapFrom(src => src.ManagerReview!.DebtAmount));
     }
 }
diff --git a/CheckDrive.Api/CheckDrive.Application/Services/DashboardService.cs b/CheckDrive.Api/CheckDrive.Application/Services/DashboardService.cs
index be20a57..8c0f681 100644
--- a/CheckDrive.Api/CheckDrive.Application/Services/DashboardService.cs
+++ b/CheckDrive.Api/CheckDrive.Application/Services/DashboardService.cs
@@ -74,7 +74,7 @@ private async Task<List<CheckPointSummary>> GetCheckPointsSummariesAsync()
     {
         var checkPoints = await _context.CheckPoints
                 .OrderByDescending(x => x.Id)
-                .Where(x => x.Status == CheckPointStatus.InProgress)
+                .Where(x => x.StartDate == DateTime.UtcNow || x.Status == CheckPointStatus.InProgress)
                 .Select(x => new CheckPointSummary(
                     x.Id,
                     x.StartDate,
diff --git a/CheckDrive.Api/CheckDrive.Application/Services/Review/ManagerReviewService.cs b/CheckDrive.Api/CheckDrive.Application/Services/Review/ManagerReviewService.cs
index 4c2ceef..cdce8c5 100644
--- a/CheckDrive.Api/CheckDrive.Application/Services/Review/ManagerReviewService.cs
+++ b/CheckDrive.Api/CheckDrive.Application/Services/Review/ManagerReviewService.cs
@@ -33,6 +33,10 @@ public async Task<ManagerReviewDto> CreateAsync(CreateManagerReviewDto review)
         CreateDebt(review, checkPoint);
         UpdateDriver(checkPoint);
         UpdateCar(review, checkPoint);
+
+        checkPoint.Stage = CheckPointStage.ManagerReview;
+        checkPoint.Status = CheckPointStatus.Completed;
+
         var reviewEntity = CreateReview(review, checkPoint, manager);
 
         context.ManagerReviews.Add(reviewEntity);
diff --git a/CheckDrive.Api/Tests/CheckDrive.Tests.Unit/Services/MechanicHandoverTests.cs b/CheckDrive.Api/Tests/CheckDrive.Tests.Unit/Services/MechanicHandoverTests.cs
new file mode 100644
index 0000000..16dfc2d
--- /dev/null
+++ b/CheckDrive.Api/Tests/CheckDrive.Tests.Unit/Services/MechanicHandoverTests.cs
@@ -0,0 +1,30 @@
+using AutoMapper;
+using CheckDrive.Application.Hubs;
+using CheckDrive.Application.Services.Review;
+using CheckDrive.Domain.Interfaces;
+using Microsoft.AspNetCore.SignalR;
+using Moq;
+
+namespace CheckDrive.Tests.Unit.Services;
+public class MechanicHandoverTests : ServiceTestBase
+{
+    private readonly Mock<ICheckDriveDbContext> _mockContext;
+    private readonly Mock<IMapper> _mockMapper;
+    private readonly Mock<IHubContext<ReviewHub, IReviewHub>> _mockHubContext;
+    private readonly MechanicHandoverService _service;
+
+    public MechanicHandoverTests()
+    {
+        _mockContext = new Mock<ICheckDriveDbContext>();
+        _mockMapper = new Mock<IMapper>();
+        _mockHubContext = new Mock<IHubContext<ReviewHub, IReviewHub>>();
+        _service = new MechanicHandoverService(_mockContext.Object, _mockMapper.Object, _mockHubContext.Object);
+    }
+
+    [Fact]
+    public async Task GetAndValidateReviewAsync_ShouldCallServiceGetAsync_Once()
+    {
+        //Arrange
+        var
+    }
+}
\ No newline at end of file

From 3d1caf44cf6b782c6d9fbff17bf8f541c8e27d3a Mon Sep 17 00:00:00 2001
From: Boburmirzo <137428656+Boburm1rzo@users.noreply.github.com>
Date: Sun, 2 Mar 2025 17:55:21 +0500
Subject: [PATCH 2/3] delete test file

---
 .../Services/MechanicHandoverTests.cs         | 30 -------------------
 1 file changed, 30 deletions(-)
 delete mode 100644 CheckDrive.Api/Tests/CheckDrive.Tests.Unit/Services/MechanicHandoverTests.cs

diff --git a/CheckDrive.Api/Tests/CheckDrive.Tests.Unit/Services/MechanicHandoverTests.cs b/CheckDrive.Api/Tests/CheckDrive.Tests.Unit/Services/MechanicHandoverTests.cs
deleted file mode 100644
index 16dfc2d..0000000
--- a/CheckDrive.Api/Tests/CheckDrive.Tests.Unit/Services/MechanicHandoverTests.cs
+++ /dev/null
@@ -1,30 +0,0 @@
-using AutoMapper;
-using CheckDrive.Application.Hubs;
-using CheckDrive.Application.Services.Review;
-using CheckDrive.Domain.Interfaces;
-using Microsoft.AspNetCore.SignalR;
-using Moq;
-
-namespace CheckDrive.Tests.Unit.Services;
-public class MechanicHandoverTests : ServiceTestBase
-{
-    private readonly Mock<ICheckDriveDbContext> _mockContext;
-    private readonly Mock<IMapper> _mockMapper;
-    private readonly Mock<IHubContext<ReviewHub, IReviewHub>> _mockHubContext;
-    private readonly MechanicHandoverService _service;
-
-    public MechanicHandoverTests()
-    {
-        _mockContext = new Mock<ICheckDriveDbContext>();
-        _mockMapper = new Mock<IMapper>();
-        _mockHubContext = new Mock<IHubContext<ReviewHub, IReviewHub>>();
-        _service = new MechanicHandoverService(_mockContext.Object, _mockMapper.Object, _mockHubContext.Object);
-    }
-
-    [Fact]
-    public async Task GetAndValidateReviewAsync_ShouldCallServiceGetAsync_Once()
-    {
-        //Arrange
-        var
-    }
-}
\ No newline at end of file

From 36e811dec4f878c4b0da6d047be7f2600a332e38 Mon Sep 17 00:00:00 2001
From: Boburmirzo <137428656+Boburm1rzo@users.noreply.github.com>
Date: Tue, 4 Mar 2025 14:46:42 +0500
Subject: [PATCH 3/3] Update DashboardService.cs

---
 .../CheckDrive.Application/Services/DashboardService.cs         | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/CheckDrive.Api/CheckDrive.Application/Services/DashboardService.cs b/CheckDrive.Api/CheckDrive.Application/Services/DashboardService.cs
index 8c0f681..50fcb15 100644
--- a/CheckDrive.Api/CheckDrive.Application/Services/DashboardService.cs
+++ b/CheckDrive.Api/CheckDrive.Application/Services/DashboardService.cs
@@ -73,7 +73,6 @@ private async Task<List<OilConsumptionSummary>> GetOilConsumptionSummariesAsync(
     private async Task<List<CheckPointSummary>> GetCheckPointsSummariesAsync()
     {
         var checkPoints = await _context.CheckPoints
-                .OrderByDescending(x => x.Id)
                 .Where(x => x.StartDate == DateTime.UtcNow || x.Status == CheckPointStatus.InProgress)
                 .Select(x => new CheckPointSummary(
                     x.Id,
@@ -82,6 +81,7 @@ private async Task<List<CheckPointSummary>> GetCheckPointsSummariesAsync()
                     x.MechanicHandover != null ? x.MechanicHandover.Car.Model : "",
                     x.Stage,
                     x.Status))
+                .OrderByDescending(x => x.Id)
                 .ToListAsync();
 
         return checkPoints;