Skip to content

Commit 8cb0104

Browse files
authored
Implement deadlines (#60)
* Implement deadlines * Fix build
1 parent 6b31271 commit 8cb0104

File tree

9 files changed

+108
-12
lines changed

9 files changed

+108
-12
lines changed

build/Build.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
using Nuke.Common.CI;
33
using Nuke.Common.CI.AppVeyor;
44
using Nuke.Common.ProjectModel;
5+
using Nuke.Common.Tooling;
56
using Nuke.Common.Tools.DotNet;
6-
using Nuke.Common.Tools.Git;
77
using Nuke.Common.Tools.SonarScanner;
88

99
using static Nuke.Common.Tools.DotNet.DotNetTasks;

build/_build.csproj

+2-2
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@
1212
</PropertyGroup>
1313

1414
<ItemGroup>
15-
<PackageReference Include="Nuke.Common" Version="8.1.2" />
16-
<PackageDownload Include="dotnet-sonarscanner" Version="[9.0.1]" />
15+
<PackageReference Include="Nuke.Common" Version="9.0.4" />
16+
<PackageDownload Include="dotnet-sonarscanner" Version="[9.0.2]" />
1717
</ItemGroup>
1818

1919
</Project>

src/Todoist.Net.Tests/Services/ItemsServiceTests.cs

+19
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,25 @@ public async Task CreateNewItem_DueDateIsLocal_DueDateNotChanged()
240240
}
241241
}
242242

243+
[Fact]
244+
[Trait(Constants.TraitName, Constants.IntegrationFreeTraitValue)]
245+
public async Task CreateNewItem_DeadlineIsLocal_DeadlaneNotChanged()
246+
{
247+
var client = TodoistClientFactory.Create(_outputHelper);
248+
249+
var item = new AddItem("New task") { Deadline = new Deadline(DateTime.Now.AddYears(1).Date) };
250+
var taskId = await client.Items.AddAsync(item);
251+
try
252+
{
253+
var itemInfo = await client.Items.GetAsync(taskId);
254+
255+
Assert.Equal(item.Deadline.Date, itemInfo.Item.Deadline.Date);
256+
}
257+
finally
258+
{
259+
await client.Items.DeleteAsync(item.Id);
260+
}
261+
}
243262

244263
[Fact]
245264
[Trait(Constants.TraitName, Constants.IntegrationPremiumTraitValue)]

src/Todoist.Net.Tests/Services/ProjectsServiceTests.cs

+10-1
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,16 @@ public async Task CreateUpdateOrderMoveAndDelete_Success()
7676
}
7777
finally
7878
{
79-
await client.Projects.DeleteAsync(project.Id);
79+
try
80+
{
81+
await client.Projects.DeleteAsync(project.Id);
82+
}
83+
// Parent project removes child projects too
84+
// So the project may be deleted already
85+
catch
86+
{
87+
// ignored
88+
}
8089
}
8190
}
8291

src/Todoist.Net.Tests/Todoist.Net.Tests.csproj

+3-3
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@
66
</PropertyGroup>
77

88
<ItemGroup>
9-
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.11.1" />
10-
<PackageReference Include="xunit" Version="2.9.2" />
11-
<PackageReference Include="xunit.runner.visualstudio" Version="2.8.2">
9+
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.12.0" />
10+
<PackageReference Include="xunit" Version="2.9.3" />
11+
<PackageReference Include="xunit.runner.visualstudio" Version="3.0.1">
1212
<PrivateAssets>all</PrivateAssets>
1313
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
1414
</PackageReference>

src/Todoist.Net/Models/BaseItem.cs

+7
Original file line numberDiff line numberDiff line change
@@ -93,5 +93,12 @@ private protected BaseItem()
9393
/// <value>The responsible uid.</value>
9494
[JsonPropertyName("responsible_uid")]
9595
public string ResponsibleUid { get; set; }
96+
97+
/// <summary>
98+
/// Gets or sets the deadline for the task.
99+
/// </summary>
100+
/// <value>The deadline.</value>
101+
[JsonPropertyName("deadline")]
102+
public Deadline Deadline { get; set; }
96103
}
97104
}

src/Todoist.Net/Models/Deadline.cs

+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
using System;
2+
using System.Text.Json.Serialization;
3+
4+
using Todoist.Net.Serialization.Converters;
5+
6+
namespace Todoist.Net.Models
7+
{
8+
/// <summary>
9+
/// Represents a deadline for a task.
10+
/// </summary>
11+
public class Deadline
12+
{
13+
[JsonConstructor]
14+
internal Deadline()
15+
{
16+
17+
}
18+
19+
/// <summary>
20+
/// Initializes a new instance of the <see cref="Deadline"/> class with the specified date.
21+
/// </summary>
22+
/// <param name="date">The date of the deadline.</param>
23+
public Deadline(DateTime date)
24+
{
25+
Date = date;
26+
}
27+
28+
/// <summary>
29+
/// Gets the date of the deadline.
30+
/// </summary>
31+
[JsonPropertyName("date")]
32+
[JsonConverter(typeof(DateOnlyConverter))]
33+
public DateTime Date { get; internal set; }
34+
35+
[JsonInclude]
36+
[JsonPropertyName("lang")]
37+
internal string Lang { get; } = "en";
38+
}
39+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
using System;
2+
using System.Globalization;
3+
using System.Text.Json;
4+
using System.Text.Json.Serialization;
5+
6+
namespace Todoist.Net.Serialization.Converters
7+
{
8+
internal sealed class DateOnlyConverter : JsonConverter<DateTime>
9+
{
10+
private const string CustomDateFormat = "yyyy-MM-dd";
11+
12+
public override DateTime Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
13+
{
14+
return DateTime.Parse(reader.GetString(), CultureInfo.InvariantCulture, DateTimeStyles.None);
15+
}
16+
17+
public override void Write(Utf8JsonWriter writer, DateTime value, JsonSerializerOptions options)
18+
{
19+
writer.WriteStringValue(value.ToString(CustomDateFormat));
20+
}
21+
}
22+
}

src/Todoist.Net/Todoist.Net.csproj

+5-5
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
<PropertyGroup>
44
<Description>A Todoist API client for .NET</Description>
5-
<VersionPrefix>8.0.0</VersionPrefix>
5+
<VersionPrefix>8.1.0</VersionPrefix>
66
<Authors>Oleg Shevchenko, Ahmed Zaki</Authors>
77
<TargetFrameworks>netstandard2.0;net462</TargetFrameworks>
88
<GenerateDocumentationFile>true</GenerateDocumentationFile>
@@ -29,10 +29,6 @@
2929
<PackageReference Include="System.Text.Json" Version="8.0.5" />
3030
</ItemGroup>
3131

32-
<ItemGroup Condition=" '$(TargetFramework)' == 'netstandard2.0' ">
33-
<PackageReference Include="Microsoft.Extensions.Http" Version="6.0.0"/>
34-
</ItemGroup>
35-
3632
<ItemGroup Condition=" '$(TargetFramework)' == 'net462' ">
3733
<Reference Include="System.Net.Http" />
3834
</ItemGroup>
@@ -48,4 +44,8 @@
4844
<None Include="../../README.md" Pack="true" PackagePath="\" />
4945
</ItemGroup>
5046

47+
<ItemGroup Condition="'$(TargetFramework)' == 'netstandard2.0'">
48+
<PackageReference Include="Microsoft.Extensions.Http" Version="6.0.1" />
49+
</ItemGroup>
50+
5151
</Project>

0 commit comments

Comments
 (0)