Skip to content

Commit 3cabaa9

Browse files
authored
Merge pull request #20 from GGrouppFoundation/feature/get-timesheet-set
Feature/get timesheet set
2 parents e3fb1bd + a1e58a2 commit 3cabaa9

14 files changed

+509
-9
lines changed

src/Application/Application.csproj

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<Project Sdk="Microsoft.NET.Sdk.Web">
1+
<Project Sdk="Microsoft.NET.Sdk.Web">
22

33
<PropertyGroup>
44
<TargetFramework>net6.0</TargetFramework>
@@ -8,7 +8,7 @@
88
<InvariantGlobalization>false</InvariantGlobalization>
99
<RootNamespace>GGroupp.Internal.Timesheet</RootNamespace>
1010
<AssemblyName>GGroupp.Internal.Timesheet.Bot.Application</AssemblyName>
11-
<Version>1.3.2</Version>
11+
<Version>1.4.0</Version>
1212
</PropertyGroup>
1313

1414
<PropertyGroup Condition=" '$(RunConfiguration)' == 'Application' " />
@@ -19,18 +19,19 @@
1919
<PackageReference Include="GGroupp.Infra.Bot.Builder.Command.Stop" Version="1.1.1" />
2020
<PackageReference Include="GGroupp.Infra.Bot.Builder.Integration.AspNet.Core" Version="1.4.0" />
2121
<PackageReference Include="GGroupp.Infra.Bot.Builder.Integration.CosmosDb" Version="1.0.0" />
22-
<PackageReference Include="GGroupp.Infra.Bot.Builder.TurnContext.Extensions" Version="1.0.2" />
23-
<PackageReference Include="GGroupp.Infra.Dataverse.Api" Version="2.7.3" />
22+
<PackageReference Include="GGroupp.Infra.Dataverse.Api" Version="2.7.4" />
2423
<PackageReference Include="GGroupp.Infra.Http.SocketsHandlerProvider" Version="2.2.0" />
2524
<PackageReference Include="GGroupp.Internal.Timesheet.FavoriteProjectSet.Get.Api" Version="1.4.2" />
2625
<PackageReference Include="GGroupp.Internal.Timesheet.ProjectSet.Search.Api" Version="1.4.4" />
2726
<PackageReference Include="GGroupp.Internal.Timesheet.Timesheet.Create.Api" Version="1.4.3" />
27+
<PackageReference Include="GGroupp.Internal.Timesheet.TimesheetSet.Get.Api" Version="1.0.5" />
2828
<PackageReference Include="GGroupp.Platform.Azure.AzureUser.Get.Api" Version="1.2.0" />
2929
<PackageReference Include="GGroupp.Platform.Dataverse.DataverseUser.Get.Api" Version="1.1.0" />
3030
</ItemGroup>
3131

3232
<ItemGroup>
3333
<ProjectReference Include="..\Timesheet.Create\Timesheet.Create.csproj" />
34+
<ProjectReference Include="..\DateTimesheet.Get\DateTimesheet.Get.csproj" />
3435
</ItemGroup>
3536

36-
</Project>
37+
</Project>
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
using System;
2+
using GGroupp.Infra.Bot.Builder;
3+
4+
namespace GGroupp.Internal.Timesheet;
5+
6+
using ITimesheetSetGetFunc = IAsyncValueFunc<TimesheetSetGetIn, Result<TimesheetSetGetOut, Failure<TimesheetSetGetFailureCode>>>;
7+
8+
partial class GTimesheetBotBuilder
9+
{
10+
internal static IBotBuilder UseGDateTimesheetGet(this IBotBuilder botBuilder, string commandName)
11+
=>
12+
botBuilder.UseDateTimesheetGet(commandName, GetTimesheetSetApi);
13+
14+
private static ITimesheetSetGetFunc GetTimesheetSetApi(IBotContext botContext)
15+
=>
16+
CreateStandardHttpHandlerDependency("TimesheetSetGetApi")
17+
.UseDataverseImpersonation(botContext)
18+
.CreateDataverseApiClient()
19+
.UseTimesheetSetGetApi()
20+
.Resolve(botContext.ServiceProvider);
21+
}

src/Application/Program.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,5 +28,6 @@ private static IBotBuilder ConfigureGTimesheetBot(IBotBuilder bot)
2828
.UseGTimesheetBotStop("stop")
2929
.UseGTimesheetAuthorization()
3030
.UseGTimesheetBotInfo("info")
31-
.UseGTimesheetCreate("newtimesheet");
31+
.UseGTimesheetCreate("newtimesheet")
32+
.UseGDateTimesheetGet("datetimesheet");
3233
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<TargetFramework>net6.0</TargetFramework>
5+
<ImplicitUsings>disable</ImplicitUsings>
6+
<Nullable>enable</Nullable>
7+
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
8+
<InvariantGlobalization>false</InvariantGlobalization>
9+
<RootNamespace>GGroupp.Internal.Timesheet</RootNamespace>
10+
<AssemblyName>GGroupp.Internal.Timesheet.Flow.DateTimesheet.Get</AssemblyName>
11+
</PropertyGroup>
12+
13+
<ItemGroup>
14+
<PackageReference Include="EarlyFuncPack.Core.AsyncPipeline" Version="0.1.0" />
15+
<PackageReference Include="GGroupp.Infra.Bot.Builder.ChatFlow.Step.Date" Version="2.0.0" />
16+
<PackageReference Include="GGroupp.Infra.Bot.Builder.TurnContext.Extensions" Version="1.1.0" />
17+
<PackageReference Include="GGroupp.Internal.Timesheet.TimesheetSet.Get.InOut" Version="1.0.1" />
18+
<PackageReference Include="PrimeFuncPack.Core.Failure" Version="2.0.0" />
19+
<PackageReference Include="PrimeFuncPack.Primitives.Pipeline" Version="2.0.1" />
20+
</ItemGroup>
21+
22+
</Project>
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
using System;
2+
using System.Threading;
3+
using System.Threading.Tasks;
4+
using GGroupp.Infra.Bot.Builder;
5+
6+
namespace GGroupp.Internal.Timesheet;
7+
8+
using ITimesheetSetGetFunc = IAsyncValueFunc<TimesheetSetGetIn, Result<TimesheetSetGetOut, Failure<TimesheetSetGetFailureCode>>>;
9+
10+
public static class DateTimesheetGetBotBuilder
11+
{
12+
public static IBotBuilder UseDateTimesheetGet(
13+
this IBotBuilder botBuilder, string commandName, Func<IBotContext, ITimesheetSetGetFunc> timesheetSetGetFuncResolver)
14+
{
15+
_ = botBuilder ?? throw new ArgumentNullException(nameof(botBuilder));
16+
_ = timesheetSetGetFuncResolver ?? throw new ArgumentNullException(nameof(timesheetSetGetFuncResolver));
17+
18+
return botBuilder.Use(InnerInvokeAsync);
19+
20+
ValueTask<Unit> InnerInvokeAsync(IBotContext botContext, CancellationToken cancellationToken)
21+
=>
22+
botContext.InnerDateTimesheetGetAsync(
23+
commandName ?? string.Empty,
24+
botContext.BotUserProvider,
25+
timesheetSetGetFuncResolver.Invoke(botContext),
26+
cancellationToken);
27+
}
28+
29+
private static ValueTask<Unit> InnerDateTimesheetGetAsync(
30+
this IBotContext botContext,
31+
string commandName,
32+
IBotUserProvider botUserProvider,
33+
ITimesheetSetGetFunc timesheetSetGetFuncResolver,
34+
CancellationToken cancellationToken)
35+
=>
36+
AsyncPipeline.Pipe(
37+
commandName, cancellationToken)
38+
.PipeValue(
39+
botContext.InternalRecoginzeOrFailureAsync)
40+
.MapSuccessValue(
41+
(flow, token) => flow.GetTimesheet(botUserProvider, timesheetSetGetFuncResolver).CompleteValueAsync(token))
42+
.FoldValue(
43+
(_, token) => botContext.BotFlow.EndAsync(token),
44+
(_, token) => botContext.BotFlow.NextAsync(token));
45+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
using System;
2+
using GGroupp.Infra.Bot.Builder;
3+
4+
namespace GGroupp.Internal.Timesheet;
5+
6+
using ITimesheetSetGetFunc = IAsyncValueFunc<TimesheetSetGetIn, Result<TimesheetSetGetOut, Failure<TimesheetSetGetFailureCode>>>;
7+
8+
partial class TimesheetSetGetChatFlow
9+
{
10+
internal static ChatFlow<Unit> GetTimesheet(
11+
this ChatFlow chatFlow,
12+
IBotUserProvider botUserProvider,
13+
ITimesheetSetGetFunc timesheetSetGetFunc)
14+
=>
15+
chatFlow.Start(
16+
static () => new DateTimesheetFlowState())
17+
.GetDate()
18+
.GetTimesheet(
19+
botUserProvider,
20+
timesheetSetGetFunc);
21+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
using System;
2+
using System.Threading;
3+
using System.Threading.Tasks;
4+
using GGroupp.Infra.Bot.Builder;
5+
6+
namespace GGroupp.Internal.Timesheet;
7+
8+
partial class TimesheetSetGetChatFlow
9+
{
10+
internal static async ValueTask<Result<ChatFlow, Unit>> InternalRecoginzeOrFailureAsync(
11+
this IBotContext context, string commandName, CancellationToken cancellationToken)
12+
{
13+
var turnContext = context.TurnContext;
14+
if (turnContext.IsNotMessageType())
15+
{
16+
return default;
17+
}
18+
19+
var chatFlow = context.CreateChatFlow("TimesheetSetGet");
20+
if (await chatFlow.IsStartedAsync(cancellationToken).ConfigureAwait(false))
21+
{
22+
return chatFlow;
23+
}
24+
25+
return turnContext.RecognizeCommandOrAbsent(commandName).Fold(_ => chatFlow, Result.Absent<ChatFlow>);
26+
}
27+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
namespace GGroupp.Internal.Timesheet;
2+
3+
internal static partial class TimesheetSetGetChatFlow
4+
{
5+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Globalization;
4+
using Newtonsoft.Json;
5+
6+
namespace GGroupp.Internal.Timesheet;
7+
8+
internal sealed record class DateTimesheetFlowState
9+
{
10+
[JsonIgnore]
11+
public DateOnly Date { get; init; }
12+
13+
[JsonProperty("dateText")]
14+
public string DateText
15+
{
16+
get => Date.ToString("yyyy-MM-dd", CultureInfo.InvariantCulture);
17+
private init => Date = DateOnly.Parse(value, CultureInfo.InvariantCulture);
18+
}
19+
20+
[JsonProperty("timesheets")]
21+
public IReadOnlyCollection<TimesheetJson>? Timesheets { get; init; }
22+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
using Newtonsoft.Json;
2+
3+
namespace GGroupp.Internal.Timesheet;
4+
5+
internal sealed record class TimesheetJson
6+
{
7+
[JsonProperty("duration")]
8+
public decimal Duration { get; init; }
9+
10+
[JsonProperty("projectName")]
11+
public string? ProjectName { get; init; }
12+
13+
[JsonProperty("description")]
14+
public string? Description { get; init; }
15+
}

0 commit comments

Comments
 (0)