Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Api/DependencyInjection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public static void AddApplication(this IServiceCollection services, IConfigurati
services.AddTransient<SoftDeleteEntryHandler>();
services.AddTransient<SoftDeleteEntryCommand>();
services.AddTransient<GetEmployeesTrackedTaskHoursHandler>();
services.AddTransient<GetTaskEntriesQuery>();
services.AddTransient<IGetTaskEntriesQuery, GetTaskEntriesQuery>();
services.AddTransient<GetAllProjectsHandler>();
services.AddTransient<GetAllEmployeesHandler>();
services.AddTransient<GetPersonalReportHandler>();
Expand Down
7 changes: 7 additions & 0 deletions Application/Extensions/MinutesConverterExtensions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
public static class MinutesConverterExtensions
{
public static decimal ToHoursWithoutRounding(this int minutes)
{
return minutes / 60m;
}
}
36 changes: 36 additions & 0 deletions Application/Extensions/MinutesConverterExtensionsTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
using Core;
using Xunit;

[UnitTest]
public class MinutesConverterExtensionsTests
{
[Fact]
public void ToHoursWithoutRounding_ShouldReturnCorrectValueFor60Minutes()
{
int minutes = 60;

decimal hours = minutes.ToHoursWithoutRounding();

Assert.Equal(1m, hours);
}

[Fact]
public void ToHoursWithoutRounding_ShouldReturnCorrectValueFor90Minutes()
{
int minutes = 90;

decimal hours = minutes.ToHoursWithoutRounding();

Assert.Equal(1.5m, hours);
}

[Fact]
public void ToHoursWithoutRounding_ShouldReturnCorrectValueFor430Minutes()
{
int minutes = 430;

decimal hours = minutes.ToHoursWithoutRounding();

Assert.Equal(7.1666666666666666666666666667m, hours);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ namespace Application.Features.Internal.GetEmployeesTrackedTaskHours;

public class GetEmployeesTrackedTaskHoursHandler
{
private readonly GetTaskEntriesQuery _getTaskEntriesQuery;
private readonly IGetTaskEntriesQuery _getTaskEntriesQuery;

public GetEmployeesTrackedTaskHoursHandler(
GetTaskEntriesQuery getTaskEntriesQuery
IGetTaskEntriesQuery getTaskEntriesQuery
)
{
_getTaskEntriesQuery = getTaskEntriesQuery;
Expand All @@ -32,7 +32,7 @@ DateOnly endDate
x => new EmployeeTrackedTaskHourDto
{
EmployeeId = x.EmployeeId,
TrackedHours = x.TrackedMinutes / 60,
TrackedHours = x.TrackedMinutes.ToHoursWithoutRounding(),
})
.ToList();

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
using Core;
using Core.Entities;
using Moq;
using Xunit;

namespace Application.Features.Internal.GetEmployeesTrackedTaskHours;

[UnitTest]
public class GetEmployeesTrackedTaskHoursHandlerTests
{
[Fact]
public async Task GetEmployeesTrackedTaskHoursHandler_ShouldReturnCorrectResultWithoutRoundingTrackedHours()
{
const long projectId = 1;
const long employeeId = 1;

var taskEntries = new List<TaskEntry>{
new TaskEntry
{
EmployeeId = employeeId,
ProjectId = projectId,
StartTime = new DateTime(2025, 11, 24, 10, 0, 0),
EndTime = new DateTime(2025, 11, 24, 10, 30, 0),
},
new TaskEntry
{
EmployeeId = employeeId,
ProjectId = projectId,
StartTime = new DateTime(2025, 11, 24, 11, 0, 0),
EndTime = new DateTime(2025, 11, 24, 11, 40, 0),
},
};

var getTaskEntriesQueryMock = new Mock<IGetTaskEntriesQuery>();

getTaskEntriesQueryMock
.Setup(x => x.GetAsync(It.IsAny<long>(), It.IsAny<DateOnly>(), It.IsAny<DateOnly>()))
.ReturnsAsync(taskEntries);

var getEmployeesTrackedTaskHoursHandler = new GetEmployeesTrackedTaskHoursHandler(
getTaskEntriesQueryMock.Object
);

var result = await getEmployeesTrackedTaskHoursHandler.HandleAsync(projectId, new DateOnly(2025, 11, 1), new DateOnly(2025, 11, 28));

Assert.NotEmpty(result.EmployeesTrackedTaskHours);
Assert.Equal(1.1666666666666666666666666667m, result.EmployeesTrackedTaskHours[0].TrackedHours);
Assert.Equal(employeeId, result.EmployeesTrackedTaskHours[0].EmployeeId);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,16 @@

namespace Application.Features.Internal.GetEmployeesTrackedTaskHours;

public class GetTaskEntriesQuery
public interface IGetTaskEntriesQuery
{
Task<List<TaskEntry>> GetAsync(
long projectId,
DateOnly startDate,
DateOnly endDate
);
}

public class GetTaskEntriesQuery : IGetTaskEntriesQuery
{
private readonly TenantAppDbContext _context;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ int month
StartTime = x.StartTime,
EndTime = x.EndTime,
Hours = x.GetDurationInHours(),
TrackedHoursPerDay = TotalTrackedMinutesPerDayCalculator.Calculate(employeeTrackedEntries, x.StartTime) / 60,
TrackedHoursPerDay = TotalTrackedMinutesPerDayCalculator.Calculate(employeeTrackedEntries, x.StartTime).ToHoursWithoutRounding(),
EntryType = x.Type,
Project = new ProjectDto
{
Expand All @@ -71,7 +71,7 @@ int month
StartTime = x.StartTime,
EndTime = x.EndTime,
Hours = x.GetDurationInHours(),
TrackedHoursPerDay = TotalTrackedMinutesPerDayCalculator.Calculate(employeeTrackedEntries, x.StartTime) / 60,
TrackedHoursPerDay = TotalTrackedMinutesPerDayCalculator.Calculate(employeeTrackedEntries, x.StartTime).ToHoursWithoutRounding(),
EntryType = x.Type,
Project = null!,
Task = null!,
Expand All @@ -95,8 +95,8 @@ int month
return new GetPersonalReportResponse
{
TrackedEntries = sortedByDateAllEntries,
TaskHours = taskTotalMinutes / 60,
UnwellHours = unwellTotalMinutes / 60
TaskHours = taskTotalMinutes.ToHoursWithoutRounding(),
UnwellHours = unwellTotalMinutes.ToHoursWithoutRounding()
};
}
}
2 changes: 1 addition & 1 deletion Core/Entities/TrackedEntryBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,6 @@ public int GetDurationInMinutes()

public decimal GetDurationInHours()
{
return (decimal)GetDurationInMinutes() / 60;
return GetDurationInMinutes() / 60m;
}
}
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
# inner-circle-time-api

<!-- auto-generated -->
[![coverage](https://img.shields.io/badge/e2e_coverage-27.97%25-crimson)](https://github.com/TourmalineCore/inner-circle-time-api/actions/workflows/calculate-tests-coverage-on-pull-request.yml)
[![coverage](https://img.shields.io/badge/units_coverage-22.69%25-crimson)](https://github.com/TourmalineCore/inner-circle-time-api/actions/workflows/calculate-tests-coverage-on-pull-request.yml)
[![coverage](https://img.shields.io/badge/integration_coverage-60.48%25-orange)](https://github.com/TourmalineCore/inner-circle-time-api/actions/workflows/calculate-tests-coverage-on-pull-request.yml)
[![coverage](https://img.shields.io/badge/full_coverage-93.86%25-forestgreen)](https://github.com/TourmalineCore/inner-circle-time-api/actions/workflows/calculate-tests-coverage-on-pull-request.yml)
[![coverage](https://img.shields.io/badge/e2e_coverage-27.66%25-crimson)](https://github.com/TourmalineCore/inner-circle-time-api/actions/workflows/calculate-tests-coverage-on-pull-request.yml)
[![coverage](https://img.shields.io/badge/units_coverage-24.71%25-crimson)](https://github.com/TourmalineCore/inner-circle-time-api/actions/workflows/calculate-tests-coverage-on-pull-request.yml)
[![coverage](https://img.shields.io/badge/integration_coverage-59.60%25-crimson)](https://github.com/TourmalineCore/inner-circle-time-api/actions/workflows/calculate-tests-coverage-on-pull-request.yml)
[![coverage](https://img.shields.io/badge/full_coverage-93.95%25-forestgreen)](https://github.com/TourmalineCore/inner-circle-time-api/actions/workflows/calculate-tests-coverage-on-pull-request.yml)
<!-- auto-generated -->

This repo contains Inner Circle Time API.
Expand Down