Skip to content

Commit

Permalink
Impl connector
Browse files Browse the repository at this point in the history
  • Loading branch information
dyatlov-a committed Jan 7, 2024
1 parent 608185d commit c82a4f9
Show file tree
Hide file tree
Showing 86 changed files with 1,612 additions and 58 deletions.
31 changes: 31 additions & 0 deletions Inc.TeamAssistant.sln
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,16 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Inc.TeamAssistant.Reviewer.
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Inc.TeamAssistant.Reviewer.Model", "src\Inc.TeamAssistant.Reviewer.Model\Inc.TeamAssistant.Reviewer.Model.csproj", "{CC45D751-DEF6-47A9-BBB3-9F46AA1F2A18}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "telegram_connector", "telegram_connector", "{533DB9B2-8423-4379-9B57-AE87EC9091D0}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Inc.TeamAssistant.Connector.Application", "src\Inc.TeamAssistant.Connector.Application\Inc.TeamAssistant.Connector.Application.csproj", "{6D88ACED-9750-402F-AFDF-61A5E8478961}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Inc.TeamAssistant.Connector.Domain", "src\Inc.TeamAssistant.Connector.Domain\Inc.TeamAssistant.Connector.Domain.csproj", "{27B45834-FCB5-46FE-999A-A6B12F69ACF2}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Inc.TeamAssistant.Connector.DataAccess", "src\Inc.TeamAssistant.Connector.DataAccess\Inc.TeamAssistant.Connector.DataAccess.csproj", "{1960CAA3-ACB5-4299-8B65-F764BDFF32FC}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Inc.TeamAssistant.Connector.Model", "src\Inc.TeamAssistant.Connector.Model\Inc.TeamAssistant.Connector.Model.csproj", "{066637C7-22D8-4F1F-A2F2-ADDDC363D011}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -184,6 +194,22 @@ Global
{CC45D751-DEF6-47A9-BBB3-9F46AA1F2A18}.Debug|Any CPU.Build.0 = Debug|Any CPU
{CC45D751-DEF6-47A9-BBB3-9F46AA1F2A18}.Release|Any CPU.ActiveCfg = Release|Any CPU
{CC45D751-DEF6-47A9-BBB3-9F46AA1F2A18}.Release|Any CPU.Build.0 = Release|Any CPU
{6D88ACED-9750-402F-AFDF-61A5E8478961}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{6D88ACED-9750-402F-AFDF-61A5E8478961}.Debug|Any CPU.Build.0 = Debug|Any CPU
{6D88ACED-9750-402F-AFDF-61A5E8478961}.Release|Any CPU.ActiveCfg = Release|Any CPU
{6D88ACED-9750-402F-AFDF-61A5E8478961}.Release|Any CPU.Build.0 = Release|Any CPU
{27B45834-FCB5-46FE-999A-A6B12F69ACF2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{27B45834-FCB5-46FE-999A-A6B12F69ACF2}.Debug|Any CPU.Build.0 = Debug|Any CPU
{27B45834-FCB5-46FE-999A-A6B12F69ACF2}.Release|Any CPU.ActiveCfg = Release|Any CPU
{27B45834-FCB5-46FE-999A-A6B12F69ACF2}.Release|Any CPU.Build.0 = Release|Any CPU
{1960CAA3-ACB5-4299-8B65-F764BDFF32FC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{1960CAA3-ACB5-4299-8B65-F764BDFF32FC}.Debug|Any CPU.Build.0 = Debug|Any CPU
{1960CAA3-ACB5-4299-8B65-F764BDFF32FC}.Release|Any CPU.ActiveCfg = Release|Any CPU
{1960CAA3-ACB5-4299-8B65-F764BDFF32FC}.Release|Any CPU.Build.0 = Release|Any CPU
{066637C7-22D8-4F1F-A2F2-ADDDC363D011}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{066637C7-22D8-4F1F-A2F2-ADDDC363D011}.Debug|Any CPU.Build.0 = Debug|Any CPU
{066637C7-22D8-4F1F-A2F2-ADDDC363D011}.Release|Any CPU.ActiveCfg = Release|Any CPU
{066637C7-22D8-4F1F-A2F2-ADDDC363D011}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(NestedProjects) = preSolution
{B8F7A67F-CFA3-4CF2-BACB-B14C282BF202} = {1943C11E-7A4A-4300-BDC1-DA333BD3EBED}
Expand Down Expand Up @@ -218,5 +244,10 @@ Global
{529CC802-3552-4381-8D22-872890CC6A9E} = {70E979AF-B6E2-4044-9161-91FA02A2644F}
{0BCBE76B-F740-44AE-8D47-5DD735EA6F3D} = {70E979AF-B6E2-4044-9161-91FA02A2644F}
{CC45D751-DEF6-47A9-BBB3-9F46AA1F2A18} = {70E979AF-B6E2-4044-9161-91FA02A2644F}
{533DB9B2-8423-4379-9B57-AE87EC9091D0} = {73CA6C4E-FE60-4BEF-9902-FFA9241616F9}
{6D88ACED-9750-402F-AFDF-61A5E8478961} = {533DB9B2-8423-4379-9B57-AE87EC9091D0}
{27B45834-FCB5-46FE-999A-A6B12F69ACF2} = {533DB9B2-8423-4379-9B57-AE87EC9091D0}
{1960CAA3-ACB5-4299-8B65-F764BDFF32FC} = {533DB9B2-8423-4379-9B57-AE87EC9091D0}
{066637C7-22D8-4F1F-A2F2-ADDDC363D011} = {533DB9B2-8423-4379-9B57-AE87EC9091D0}
EndGlobalSection
EndGlobal
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
using MediatR;
using Inc.TeamAssistant.Appraiser.Application.Extensions;
using Inc.TeamAssistant.Appraiser.Application.Services;
using Inc.TeamAssistant.Appraiser.Model.Common;
using Inc.TeamAssistant.Primitives;

namespace Inc.TeamAssistant.Appraiser.Application.CommandHandlers.AcceptEstimate;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
using Inc.TeamAssistant.Appraiser.Model.Commands.ActivateAssessment;
using MediatR;
using Inc.TeamAssistant.Appraiser.Application.Extensions;
using Inc.TeamAssistant.Appraiser.Model.Common;
using Inc.TeamAssistant.DialogContinuations;
using Inc.TeamAssistant.Primitives;

namespace Inc.TeamAssistant.Appraiser.Application.CommandHandlers.ActivateAssessment;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
using Inc.TeamAssistant.Appraiser.Model.Commands.AddStoryForEstimate;
using MediatR;
using Inc.TeamAssistant.Appraiser.Application.Extensions;
using Inc.TeamAssistant.Appraiser.Model.Common;
using Inc.TeamAssistant.Primitives;

namespace Inc.TeamAssistant.Appraiser.Application.CommandHandlers.AddStoryForEstimate;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
using MediatR;
using Inc.TeamAssistant.Appraiser.Application.Extensions;
using Inc.TeamAssistant.Appraiser.Application.Services;
using Inc.TeamAssistant.Appraiser.Model.Common;
using Inc.TeamAssistant.DialogContinuations;
using Inc.TeamAssistant.Primitives;

namespace Inc.TeamAssistant.Appraiser.Application.CommandHandlers.AddStoryToAssessmentSession;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using Inc.TeamAssistant.Appraiser.Application.Contracts;
using Inc.TeamAssistant.Appraiser.Model.Commands.AddStoryToAssessmentSession;
using Inc.TeamAssistant.Appraiser.Model.Common;
using Inc.TeamAssistant.Primitives;

namespace Inc.TeamAssistant.Appraiser.Application.CommandHandlers.AddStoryToAssessmentSession.Validators;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
using Inc.TeamAssistant.Appraiser.Model.Commands.ChangeLanguage;
using MediatR;
using Inc.TeamAssistant.Appraiser.Application.Extensions;
using Inc.TeamAssistant.Appraiser.Model.Common;
using Inc.TeamAssistant.Primitives;

namespace Inc.TeamAssistant.Appraiser.Application.CommandHandlers.ChangeLanguage;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
using MediatR;
using Inc.TeamAssistant.Appraiser.Application.Extensions;
using Inc.TeamAssistant.Appraiser.Application.Services;
using Inc.TeamAssistant.Appraiser.Model.Common;
using Inc.TeamAssistant.Primitives;

namespace Inc.TeamAssistant.Appraiser.Application.CommandHandlers.ConnectToAssessmentSession;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using Inc.TeamAssistant.Appraiser.Model.Commands.ConnectToAssessmentSession;
using Inc.TeamAssistant.Appraiser.Model.Commands.CreateAssessmentSession;
using Inc.TeamAssistant.Appraiser.Model.Common;
using Inc.TeamAssistant.Primitives;

namespace Inc.TeamAssistant.Appraiser.Application.CommandHandlers.ConnectToAssessmentSession.Validators;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
using Inc.TeamAssistant.Appraiser.Application.Contracts;
using Inc.TeamAssistant.Appraiser.Domain;
using Inc.TeamAssistant.Appraiser.Model.Commands.CreateAssessmentSession;
using Inc.TeamAssistant.Appraiser.Model.Common;
using Inc.TeamAssistant.DialogContinuations;
using Inc.TeamAssistant.Primitives;
using MediatR;

namespace Inc.TeamAssistant.Appraiser.Application.CommandHandlers.CreateAssessmentSession;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
using MediatR;
using Inc.TeamAssistant.Appraiser.Application.Extensions;
using Inc.TeamAssistant.Appraiser.Application.Services;
using Inc.TeamAssistant.Appraiser.Model.Common;
using Inc.TeamAssistant.Primitives;

namespace Inc.TeamAssistant.Appraiser.Application.CommandHandlers.ExitFromAssessmentSession;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
using Inc.TeamAssistant.Appraiser.Model.Commands.FinishAssessmentSession;
using MediatR;
using Inc.TeamAssistant.Appraiser.Application.Extensions;
using Inc.TeamAssistant.Appraiser.Model.Common;
using Inc.TeamAssistant.Primitives;

namespace Inc.TeamAssistant.Appraiser.Application.CommandHandlers.FinishAssessmentSession;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
using MediatR;
using Inc.TeamAssistant.Appraiser.Application.Extensions;
using Inc.TeamAssistant.Appraiser.Application.Services;
using Inc.TeamAssistant.Appraiser.Model.Common;
using Inc.TeamAssistant.Primitives;

namespace Inc.TeamAssistant.Appraiser.Application.CommandHandlers.ReVoteEstimate;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
using Inc.TeamAssistant.Appraiser.Application.Extensions;
using Inc.TeamAssistant.Appraiser.Application.Services;
using Inc.TeamAssistant.Appraiser.Domain;
using Inc.TeamAssistant.Appraiser.Model.Common;
using Inc.TeamAssistant.Primitives;

namespace Inc.TeamAssistant.Appraiser.Application.CommandHandlers.SetEstimateForStory;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
using Inc.TeamAssistant.Appraiser.Model.Commands.FinishAssessmentSession;
using Inc.TeamAssistant.Appraiser.Model.Commands.ReVoteEstimate;
using Inc.TeamAssistant.Appraiser.Model.Commands.ShowHelp;
using Inc.TeamAssistant.Appraiser.Model.Common;
using Inc.TeamAssistant.Primitives;
using MediatR;

namespace Inc.TeamAssistant.Appraiser.Application.CommandHandlers.ShowHelp;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
using Inc.TeamAssistant.Appraiser.Model.Commands.StartStorySelection;
using MediatR;
using Inc.TeamAssistant.Appraiser.Application.Extensions;
using Inc.TeamAssistant.Appraiser.Model.Common;
using Inc.TeamAssistant.DialogContinuations;
using Inc.TeamAssistant.Primitives;

namespace Inc.TeamAssistant.Appraiser.Application.CommandHandlers.StartStorySelection;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ namespace Inc.TeamAssistant.Appraiser.Application;

public static class ServiceCollectionExtensions
{
public static IServiceCollection AddApplication(this IServiceCollection services, IConfiguration configuration)
public static IServiceCollection AddAppraiserApplication(
this IServiceCollection services,
IConfiguration configuration)
{
if (services is null)
throw new ArgumentNullException(nameof(services));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using Inc.TeamAssistant.Appraiser.Domain;
using Inc.TeamAssistant.Appraiser.Model.Commands.AddStoryForEstimate;
using Inc.TeamAssistant.Appraiser.Model.Common;
using Inc.TeamAssistant.Primitives;
using MediatR;

namespace Inc.TeamAssistant.Appraiser.Application.Services;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Inc.TeamAssistant.Appraiser.Model.Common;
using Inc.TeamAssistant.Primitives;
using MediatR;

namespace Inc.TeamAssistant.Appraiser.Model.Commands.AcceptEstimate;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Inc.TeamAssistant.Appraiser.Model.Common;
using Inc.TeamAssistant.Primitives;
using MediatR;

namespace Inc.TeamAssistant.Appraiser.Model.Commands.ActivateAssessment;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Inc.TeamAssistant.Appraiser.Model.Common;
using Inc.TeamAssistant.Primitives;
using MediatR;

namespace Inc.TeamAssistant.Appraiser.Model.Commands.AddStoryForEstimate;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Inc.TeamAssistant.Appraiser.Model.Common;
using Inc.TeamAssistant.Primitives;
using MediatR;

namespace Inc.TeamAssistant.Appraiser.Model.Commands.ExitFromAssessmentSession;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Inc.TeamAssistant.Appraiser.Model.Common;
using Inc.TeamAssistant.Primitives;
using MediatR;

namespace Inc.TeamAssistant.Appraiser.Model.Commands.FinishAssessmentSession;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Inc.TeamAssistant.Appraiser.Model.Common;
using Inc.TeamAssistant.Primitives;
using MediatR;

namespace Inc.TeamAssistant.Appraiser.Model.Commands.ReVoteEstimate;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Inc.TeamAssistant.Appraiser.Model.Common;
using Inc.TeamAssistant.Primitives;
using MediatR;

namespace Inc.TeamAssistant.Appraiser.Model.Commands.SetEstimateForStory;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Inc.TeamAssistant.Appraiser.Model.Common;
using Inc.TeamAssistant.Primitives;
using MediatR;

namespace Inc.TeamAssistant.Appraiser.Model.Commands.StartStorySelection;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
<Project Sdk="Microsoft.NET.Sdk">
<ItemGroup>
<PackageReference Include="MediatR" Version="12.1.1" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Inc.TeamAssistant.Primitives\Inc.TeamAssistant.Primitives.csproj" />
</ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
<Project Sdk="Microsoft.NET.Sdk">
<ItemGroup>
<PackageReference Include="MediatR" Version="12.1.1" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Inc.TeamAssistant.Appraiser.Model\Inc.TeamAssistant.Appraiser.Model.csproj" />
</ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
using Inc.TeamAssistant.Connector.Domain;
using Inc.TeamAssistant.Connector.Model.Commands.Begin;
using Inc.TeamAssistant.DialogContinuations;
using Inc.TeamAssistant.DialogContinuations.Model;
using Inc.TeamAssistant.Primitives;
using MediatR;

namespace Inc.TeamAssistant.Connector.Application.CommandHandlers.Begin;

internal sealed class BeginCommandHandler : IRequestHandler<BeginCommand, CommandResult>
{
private readonly IDialogContinuation<BotCommandStage> _dialogContinuation;

public BeginCommandHandler(IDialogContinuation<BotCommandStage> dialogContinuation)
{
_dialogContinuation = dialogContinuation ?? throw new ArgumentNullException(nameof(dialogContinuation));
}

public async Task<CommandResult> Handle(BeginCommand command, CancellationToken token)
{
if (command is null)
throw new ArgumentNullException(nameof(command));

var nextStage = Enum.Parse<BotCommandStage>(command.NextStage);

var dialogState = _dialogContinuation.TryBegin(command.MessageContext.PersonId, nextStage);

if (dialogState is null)
throw new ApplicationException("Can not start command dialog.");

dialogState.AddItem(command.Command);

if (command.MessageContext.Shared)
dialogState.TryAttachMessage(new ChatMessage(
command.MessageContext.ChatId,
command.MessageContext.MessageId));

return CommandResult.Build(command.Notification);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
using Inc.TeamAssistant.Connector.Application.Contracts;
using Inc.TeamAssistant.Connector.Domain;
using Inc.TeamAssistant.Connector.Model.Commands.CreateTeam;
using Inc.TeamAssistant.DialogContinuations;
using Inc.TeamAssistant.Primitives;
using MediatR;

namespace Inc.TeamAssistant.Connector.Application.CommandHandlers.CreateTeam;

internal sealed class CreateTeamCommandHandler : IRequestHandler<CreateTeamCommand, CommandResult>
{
private readonly ITeamRepository _teamRepository;
private readonly IDialogContinuation<BotCommandStage> _dialogContinuation;

public CreateTeamCommandHandler(
ITeamRepository teamRepository,
IDialogContinuation<BotCommandStage> dialogContinuation)
{
_teamRepository = teamRepository ?? throw new ArgumentNullException(nameof(teamRepository));
_dialogContinuation = dialogContinuation ?? throw new ArgumentNullException(nameof(dialogContinuation));
}

public async Task<CommandResult> Handle(CreateTeamCommand command, CancellationToken token)
{
if (command is null)
throw new ArgumentNullException(nameof(command));

var team = new Team(
command.MessageContext.BotId,
command.MessageContext.ChatId,
command.Name);

await _teamRepository.Upsert(team, token);

_dialogContinuation.End(command.MessageContext.PersonId, BotCommandStage.EnterText);

return CommandResult.Build(NotificationMessage.Create(
command.MessageContext.ChatId,
$"https://t.me/{command.BotName}?start={team.Id:N}"));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
using Inc.TeamAssistant.Connector.Domain;
using Inc.TeamAssistant.Connector.Model.Commands.End;
using Inc.TeamAssistant.DialogContinuations;
using Inc.TeamAssistant.DialogContinuations.Model;
using Inc.TeamAssistant.Primitives;
using MediatR;

namespace Inc.TeamAssistant.Connector.Application.CommandHandlers.End;

internal sealed class EndCommandHandler : IRequestHandler<EndCommand, CommandResult>
{
private readonly IDialogContinuation<BotCommandStage> _dialogContinuation;

public EndCommandHandler(IDialogContinuation<BotCommandStage> dialogContinuation)
{
_dialogContinuation = dialogContinuation ?? throw new ArgumentNullException(nameof(dialogContinuation));
}

public Task<CommandResult> Handle(EndCommand command, CancellationToken token)
{
if (command is null)
throw new ArgumentNullException(nameof(command));

var currentStage = Enum.Parse<BotCommandStage>(command.CurrentStage);

var dialogState = _dialogContinuation.End(command.MessageContext.PersonId, currentStage);

if (command.MessageContext.Shared)
dialogState.TryAttachMessage(new ChatMessage(
command.MessageContext.ChatId,
command.MessageContext.MessageId));

// TODO: remove messages

return Task.FromResult(CommandResult.Empty);
}
}
Loading

0 comments on commit c82a4f9

Please sign in to comment.