wip for todoist -> habitica syncing process
This commit is contained in:
@@ -313,6 +313,10 @@
|
||||
<None Include="packages.config" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\Habitica.Todoist.Integration.Data\Habitica.Todoist.Integration.Data.csproj">
|
||||
<Project>{08055C1C-7581-4E74-97BB-C5D56E0CA3D8}</Project>
|
||||
<Name>Habitica.Todoist.Integration.Data</Name>
|
||||
</ProjectReference>
|
||||
<ProjectReference Include="..\Habitica.Todoist.Integration.Model\Habitica.Todoist.Integration.Model.csproj">
|
||||
<Project>{1EDCF34E-E1B1-4F82-AEC7-90C35A267967}</Project>
|
||||
<Name>Habitica.Todoist.Integration.Model</Name>
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using Habitica.Todoist.Integration.Model.Habitica;
|
||||
using Habitica.Todoist.Integration.Data;
|
||||
using Habitica.Todoist.Integration.Model.Habitica;
|
||||
using Habitica.Todoist.Integration.Model.Habitica.Enums;
|
||||
using Habitica.Todoist.Integration.Model.Storage;
|
||||
using Habitica.Todoist.Integration.Model.Todoist;
|
||||
@@ -40,7 +41,7 @@ namespace Habitica.Todoist.Integration.Console
|
||||
.OrderByDescending(x => x.Timestamp).First().RowKey; } catch { }
|
||||
|
||||
// get all changed items from todoist
|
||||
var response = todoistClient.GetChangedItems(syncToken).ConfigureAwait(false).GetAwaiter().GetResult();
|
||||
var response = todoistClient.GetItemChanges(syncToken).ConfigureAwait(false).GetAwaiter().GetResult();
|
||||
var changedItems = response.Items;
|
||||
|
||||
/* TESTING */
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>netstandard2.0</TargetFramework>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.Azure.Cosmos.Table" Version="1.0.6" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
@@ -1,12 +1,11 @@
|
||||
using Habitica.Todoist.Integration.Model.Storage;
|
||||
using Microsoft.Azure.Cosmos.Table;
|
||||
using Microsoft.Azure.Cosmos.Table;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Habitica.Todoist.Integration.Services
|
||||
namespace Habitica.Todoist.Integration.Data
|
||||
{
|
||||
public class TableStorageClient
|
||||
{
|
||||
@@ -7,6 +7,7 @@
|
||||
<PackageReference Include="Microsoft.NET.Sdk.Functions" Version="3.0.1" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\Habitica.Todoist.Integration.Data\Habitica.Todoist.Integration.Data.csproj" />
|
||||
<ProjectReference Include="..\Habitica.Todoist.Integration.Model\Habitica.Todoist.Integration.Model.csproj" />
|
||||
<ProjectReference Include="..\Habitica.Todoist.Integration.Services\Habitica.Todoist.Integration.Services.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
@@ -2,6 +2,7 @@ using System;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Habitica.Todoist.Integration.Data;
|
||||
using Habitica.Todoist.Integration.Model.Habitica.Enums;
|
||||
using Habitica.Todoist.Integration.Model.Storage;
|
||||
using Habitica.Todoist.Integration.Model.Todoist;
|
||||
@@ -14,7 +15,7 @@ using HabiticaTask = Habitica.Todoist.Integration.Model.Habitica.Task;
|
||||
|
||||
namespace Habitica.Todoist.Integration.Function.Sync
|
||||
{
|
||||
public static class SyncFunction
|
||||
public static class ScheduledSyncFunction
|
||||
{
|
||||
private static IConfiguration configuration { get; set; }
|
||||
private static string habiticaUserId => configuration["habiticaUserId"];
|
||||
@@ -24,8 +25,8 @@ namespace Habitica.Todoist.Integration.Function.Sync
|
||||
private static string giosUserId => "0b6ec4eb-8878-4b9e-8585-7673764a6541";
|
||||
|
||||
[Singleton]
|
||||
[FunctionName("SyncFunction")]
|
||||
public static async Task Run([TimerTrigger("0 */2 * * * *")]TimerInfo myTimer, ILogger log)
|
||||
[FunctionName("ScheduledSyncFunction")]
|
||||
public static async Task Run([TimerTrigger("0 */30 * * * *")]TimerInfo myTimer, ILogger log)
|
||||
{
|
||||
BuildConfig();
|
||||
|
||||
@@ -47,7 +48,7 @@ namespace Habitica.Todoist.Integration.Function.Sync
|
||||
catch { }
|
||||
|
||||
// get all changed items from todoist
|
||||
var response = await todoistClient.GetChangedItems(syncToken);
|
||||
var response = await todoistClient.GetItemChanges(syncToken);
|
||||
var changedItems = response.Items;
|
||||
|
||||
// filter out items by actions
|
||||
@@ -5,11 +5,11 @@
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.Azure.Cosmos.Table" Version="1.0.6" />
|
||||
<PackageReference Include="Newtonsoft.Json" Version="12.0.3" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\Habitica.Todoist.Integration.Data\Habitica.Todoist.Integration.Data.csproj" />
|
||||
<ProjectReference Include="..\Habitica.Todoist.Integration.Model\Habitica.Todoist.Integration.Model.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
|
||||
41
Habitica.Todoist.Integration.Services/TodoistExtensions.cs
Normal file
41
Habitica.Todoist.Integration.Services/TodoistExtensions.cs
Normal file
@@ -0,0 +1,41 @@
|
||||
using Habitica.Todoist.Integration.Data;
|
||||
using Habitica.Todoist.Integration.Model.Storage;
|
||||
using Habitica.Todoist.Integration.Model.Todoist;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
namespace Habitica.Todoist.Integration.Services
|
||||
{
|
||||
public static class TodoistExtensions
|
||||
{
|
||||
public static IEnumerable<Item> WhereAdded(this List<Item> items, TableStorageClient storageClient, string userId)
|
||||
{
|
||||
return items
|
||||
.Where(x => !storageClient
|
||||
.Exists<TodoHabitLink>(userId, x.Id) && x.Is_deleted == 0);
|
||||
}
|
||||
|
||||
public static IEnumerable<Item> WhereUpdated(this List<Item> items, TableStorageClient storageClient, string userId)
|
||||
{
|
||||
return items
|
||||
.Where(x => storageClient
|
||||
.Exists<TodoHabitLink>(userId, x.Id) && x.Is_deleted == 0 && x.Date_completed == null);
|
||||
}
|
||||
|
||||
public static IEnumerable<Item> WhereCompleted(this List<Item> items, TableStorageClient storageClient, string userId)
|
||||
{
|
||||
return items
|
||||
.Where(x => storageClient
|
||||
.Exists<TodoHabitLink>(userId, x.Id) && x.Is_deleted == 0 && x.Date_completed != null);
|
||||
}
|
||||
|
||||
public static IEnumerable<Item> WhereDeleted(this List<Item> items, TableStorageClient storageClient, string userId)
|
||||
{
|
||||
return items
|
||||
.Where(x => storageClient
|
||||
.Exists<TodoHabitLink>(userId, x.Id) && x.Is_deleted == 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,55 @@
|
||||
using Habitica.Todoist.Integration.Data;
|
||||
using Habitica.Todoist.Integration.Model.Storage;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using System.Linq;
|
||||
using Habitica.Todoist.Integration.Model.Todoist;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Habitica.Todoist.Integration.Services
|
||||
{
|
||||
public class TodoistIntegrationService
|
||||
{
|
||||
private TodoistServiceClient todoistClient { get; set; }
|
||||
private TableStorageClient storageClient { get; set; }
|
||||
|
||||
private string userId { get; set; }
|
||||
private string latestSyncToken { get; set; } = string.Empty;
|
||||
|
||||
public TodoistIntegrationService(TodoistServiceClient todoistClient,
|
||||
TableStorageClient storageClient,
|
||||
string userId)
|
||||
{
|
||||
this.todoistClient = todoistClient;
|
||||
this.storageClient = storageClient;
|
||||
this.userId = userId;
|
||||
}
|
||||
|
||||
public async Task<List<Item>> ReadItemChanges()
|
||||
{
|
||||
var response = await todoistClient.GetItemChanges(ReadLatestSyncToken());
|
||||
return response.Items;
|
||||
}
|
||||
|
||||
public async Task CommitRead()
|
||||
{
|
||||
await storageClient.InsertOrUpdate(new TodoistSync(userId, latestSyncToken));
|
||||
}
|
||||
|
||||
private string ReadLatestSyncToken()
|
||||
{
|
||||
try
|
||||
{
|
||||
latestSyncToken = storageClient.Query<TodoistSync>()
|
||||
.Where(x => x.PartitionKey == userId)
|
||||
.ToList()
|
||||
.OrderByDescending(x => x.Timestamp)
|
||||
.First().RowKey;
|
||||
}
|
||||
catch { }
|
||||
|
||||
return latestSyncToken;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -19,7 +19,7 @@ namespace Habitica.Todoist.Integration.Services
|
||||
this.apiKey = apiKey;
|
||||
}
|
||||
|
||||
public async Task<SyncResponse> GetChangedItems(string syncToken = null)
|
||||
public async Task<SyncResponse> GetItemChanges(string syncToken = null)
|
||||
{
|
||||
if (string.IsNullOrEmpty(syncToken))
|
||||
syncToken = "*";
|
||||
|
||||
@@ -18,7 +18,9 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Habitica.Todoist.Integratio
|
||||
EndProject
|
||||
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Functions", "Functions", "{2DEF5574-4626-414C-9CF2-1FD6F3815B16}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Habitica.Todoist.Integration.Function.Sync", "Habitica.Todoist.Integration.Function.Sync\Habitica.Todoist.Integration.Function.Sync.csproj", "{9C825688-20BC-4580-8126-1E7320A8CC4D}"
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Habitica.Todoist.Integration.Function.Sync", "Habitica.Todoist.Integration.Function.Sync\Habitica.Todoist.Integration.Function.Sync.csproj", "{9C825688-20BC-4580-8126-1E7320A8CC4D}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Habitica.Todoist.Integration.Data", "Habitica.Todoist.Integration.Data\Habitica.Todoist.Integration.Data.csproj", "{08055C1C-7581-4E74-97BB-C5D56E0CA3D8}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
@@ -42,6 +44,10 @@ Global
|
||||
{9C825688-20BC-4580-8126-1E7320A8CC4D}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{9C825688-20BC-4580-8126-1E7320A8CC4D}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{9C825688-20BC-4580-8126-1E7320A8CC4D}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{08055C1C-7581-4E74-97BB-C5D56E0CA3D8}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{08055C1C-7581-4E74-97BB-C5D56E0CA3D8}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{08055C1C-7581-4E74-97BB-C5D56E0CA3D8}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{08055C1C-7581-4E74-97BB-C5D56E0CA3D8}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
|
||||
Reference in New Issue
Block a user