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
1 change: 1 addition & 0 deletions Api/Features/Tracking/TrackingControllerTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ public async Task CreateTaskEntryAsync_ShouldThrowValidationErrorIfAtLeastOneOfR
TaskId = "#2231",
ProjectId = 1,
Description = "Task description",
TimeZoneId = "Asia/Yekaterinburg"
};

var response = await HttpClient.PostAsJsonAsync("/api/time/tracking/task-entries", createTaskEntryRequest);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ protected override async Task<long> MakeChangesToEntryAsync(CreateTaskEntryReque
ProjectId = createTaskEntryRequest.ProjectId,
TaskId = createTaskEntryRequest.TaskId,
Description = createTaskEntryRequest.Description,
TimeZoneId = createTaskEntryRequest.TimeZoneId
};

await _context
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ public async Task CreateTaskEntryAsync_ShouldThrowInvalidTimeRangeExceptionIfSta
TaskId = "#2231",
ProjectId = 1,
Description = "Task description",
TimeZoneId = "Asia/Yekaterinburg"
};

var exception = await Assert.ThrowsAsync<InvalidTimeRangeException>(
Expand Down Expand Up @@ -65,6 +66,7 @@ public async Task CreateTaskEntryAsync_ShouldThrowConflictingTimeRangeExceptionI
TaskId = "#2232",
ProjectId = 1,
Description = "Task description",
TimeZoneId = "Asia/Yekaterinburg"
};

var exception = await Assert.ThrowsAsync<ConflictingTimeRangeException>(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,7 @@ public class CreateTaskEntryRequest

[Required]
public required string Description { get; set; }

[Required]
public required string TimeZoneId { get; set; }
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ protected override async Task<long> MakeChangesToEntryAsync(CreateUnwellEntryReq
EmployeeId = _claimsProvider.EmployeeId,
StartTime = createUnwellEntryRequest.StartTime,
EndTime = createUnwellEntryRequest.EndTime,
TimeZoneId = createUnwellEntryRequest.TimeZoneId
};

await _context
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,7 @@ public class CreateUnwellEntryRequest

[Required]
public required DateTime EndTime { get; set; }

[Required]
public required string TimeZoneId { get; set; }
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ DateOnly endDate
Title = x.Title,
ProjectId = x.ProjectId,
TaskId = x.TaskId,
Description = x.Description
Description = x.Description,
})
.ToList();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ await _context
.SetProperty(x => x.TaskId, updateTaskEntryRequest.TaskId)
.SetProperty(x => x.ProjectId, updateTaskEntryRequest.ProjectId)
.SetProperty(x => x.Description, updateTaskEntryRequest.Description)
.SetProperty(x => x.TimeZoneId, updateTaskEntryRequest.TimeZoneId)
);

return updateTaskEntryRequest.Id;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ public async Task UpdateTaskEntryAsync_ShouldThrowInvalidTimeRangeExceptionIfSta
TaskId = "#22",
ProjectId = 2,
Description = "Task description",
TimeZoneId = "Asia/Yekaterinburg"
};

var exception = await Assert.ThrowsAsync<InvalidTimeRangeException>(
Expand Down Expand Up @@ -89,6 +90,7 @@ public async Task UpdateTaskEntryAsync_ShouldThrowConflictingTimeRangeExceptionI
TaskId = "#2232",
ProjectId = 1,
Description = "Task description",
TimeZoneId = "Asia/Yekaterinburg"
};

var exception = await Assert.ThrowsAsync<ConflictingTimeRangeException>(
Expand Down Expand Up @@ -129,6 +131,7 @@ public async Task UpdateTaskEntryAsync_ShouldNotUpdateDeletedTaskEntry()
TaskId = "#2232",
ProjectId = 1,
Description = "Task description",
TimeZoneId = "Asia/Yekaterinburg"
};

await updateTaskEntryCommand.ExecuteAsync(updateTaskEntryRequest);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,7 @@ public class UpdateTaskEntryRequest

[Required]
public required string Description { get; set; }

[Required]
public required string TimeZoneId { get; set; }
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ await _context
.ExecuteUpdateAsync(setters => setters
.SetProperty(x => x.StartTime, updateUnwellEntryRequest.StartTime)
.SetProperty(x => x.EndTime, updateUnwellEntryRequest.EndTime)
.SetProperty(x => x.TimeZoneId, updateUnwellEntryRequest.TimeZoneId)
);

return updateUnwellEntryRequest.Id;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,7 @@ public class UpdateUnwellEntryRequest

[Required]
public required DateTime EndTime { get; set; }

[Required]
public required string TimeZoneId { get; set; }
}
18 changes: 18 additions & 0 deletions Application/Mappings/TrackedEntryBaseMapping.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,23 @@ public void Configure(EntityTypeBuilder<TrackedEntryBase> builder)
.ToTable(x => x.HasCheckConstraint(
"ck_entries_end_time_is_greater_than_start_time",
"\"end_time\" > \"start_time\""));

builder
.Property(x => x.StartTimeUtc)
.HasComputedColumnSql(
"start_time AT TIME ZONE time_zone_id",
stored: true
)
.HasColumnType("timestamptz")
.ValueGeneratedOnAddOrUpdate();

builder
.Property(x => x.EndTimeUtc)
.HasComputedColumnSql(
"end_time AT TIME ZONE time_zone_id",
stored: true
)
.HasColumnType("timestamptz")
.ValueGeneratedOnAddOrUpdate();
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
using System;
using Microsoft.EntityFrameworkCore.Migrations;

#nullable disable

namespace Application.Migrations
{
/// <inheritdoc />
public partial class AddStartTimeUtcAndEndTimeUtcAndMakeTimeZoneIdRequired : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.AlterColumn<string>(
name: "time_zone_id",
table: "tracked_entries",
type: "text",
nullable: false,
defaultValue: "",
oldClrType: typeof(string),
oldType: "text",
oldNullable: true);

migrationBuilder.AddColumn<DateTime>(
name: "end_time_utc",
table: "tracked_entries",
type: "timestamptz",
nullable: false,
computedColumnSql: "end_time AT TIME ZONE time_zone_id",
stored: true);

migrationBuilder.AddColumn<DateTime>(
name: "start_time_utc",
table: "tracked_entries",
type: "timestamptz",
nullable: false,
computedColumnSql: "start_time AT TIME ZONE time_zone_id",
stored: true);
}

/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropColumn(
name: "end_time_utc",
table: "tracked_entries");

migrationBuilder.DropColumn(
name: "start_time_utc",
table: "tracked_entries");

migrationBuilder.AlterColumn<string>(
name: "time_zone_id",
table: "tracked_entries",
type: "text",
nullable: true,
oldClrType: typeof(string),
oldType: "text");
}
}
}
Loading