Skip to content

Commit 1e09f88

Browse files
committed
refactor: return TotalHoursPlayed as double in GetTestersUseCase
Simplifies backend logic by returning TotalHoursPlayed in decimal hours instead of a formatted string. Delegates the display formatting to the client, avoiding rounding issues and making the API more flexible.
1 parent 10d02ed commit 1e09f88

2 files changed

Lines changed: 5 additions & 6 deletions

File tree

src/UseCases/Testers/GetAll.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ public class GetTestersResponse
99
{
1010
public required string Name { get; init; }
1111
public required string AccessKey { get; init; }
12-
public required string TotalPlaytime { get; init; }
12+
public required double TotalHoursPlayed { get; init; }
1313
public required string CreatedAt { get; init; }
1414
}
1515

@@ -23,7 +23,7 @@ public async Task<ListedResult<GetTestersResponse>> ExecuteAsync()
2323
{
2424
Name = t.Name,
2525
AccessKey = t.AccessKey,
26-
TotalPlaytime = TimeSpan.FromHours(t.TotalHoursPlayed).ToString(@"hh\:mm\:ss"),
26+
TotalHoursPlayed = t.TotalHoursPlayed,
2727
CreatedAt = t.CreatedAt.ToString("yyyy-MM-dd HH:mm:ss")
2828
})
2929
.ToListAsync();

tests/UseCases/Testers/GetAll.cs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ public async Task Get_WhenTestersExist_ShouldReturnAllTesters()
3636
}
3737

3838
[Test]
39-
public async Task Get_WhenTesterHasPlaytime_ShouldReturnFormattedPlaytime()
39+
public async Task Get_WhenTesterHasPlaytime_ShouldReturnTotalHoursPlayed()
4040
{
4141
// Arrange
4242
var client = CreateHttpClientWithApiKey();
@@ -45,11 +45,10 @@ public async Task Get_WhenTesterHasPlaytime_ShouldReturnFormattedPlaytime()
4545
var createdBody = await createResponse.Content.ReadFromJsonAsync<Result<CreateTesterResponse>>();
4646
var accessKey = createdBody.Data.AccessKey;
4747

48-
// Update playtime (for example 2.75 hours = 02:45:00)
4948
var playtimeRequest = new UpdatePlaytimeRequest(HoursPlayed: 2.75);
5049
var requestUri = $"/api/testers/{accessKey}/playtime";
5150
var playtimeResponse = await client.PatchAsJsonAsync(requestUri, playtimeRequest);
52-
var expectedPlaytime = "02:45:00";
51+
double expectedTotalHours = 2.75f;
5352

5453
// Act
5554
var response = await client.GetAsync("/api/testers");
@@ -62,7 +61,7 @@ public async Task Get_WhenTesterHasPlaytime_ShouldReturnFormattedPlaytime()
6261
body.IsSuccess.Should().BeTrue();
6362

6463
var tester = body.Data.FirstOrDefault(t => t.Name == "Carlos");
65-
tester.TotalPlaytime.Should().Be(expectedPlaytime);
64+
tester.TotalHoursPlayed.Should().Be(expectedTotalHours);
6665
}
6766

6867
[Test]

0 commit comments

Comments
 (0)