Skip to content

Commit

Permalink
Remove commands: join, show users
Browse files Browse the repository at this point in the history
  • Loading branch information
dyatlov-a committed Nov 13, 2023
1 parent 72d7663 commit ac86561
Show file tree
Hide file tree
Showing 24 changed files with 104 additions and 397 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,28 +6,24 @@
using Inc.TeamAssistant.Appraiser.Application.Extensions;
using Inc.TeamAssistant.Appraiser.Application.Services;
using Inc.TeamAssistant.Appraiser.Model.Common;
using Inc.TeamAssistant.DialogContinuations;

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

internal sealed class ConnectToAssessmentSessionCommandHandler
: IRequestHandler<ConnectToAssessmentSessionCommand, CommandResult>
{
private readonly IAssessmentSessionRepository _repository;
private readonly IDialogContinuation<ContinuationState> _dialogContinuation;
private readonly IMessagesSender _messagesSender;
private readonly IMessageBuilder _messageBuilder;
private readonly SummaryByStoryBuilder _summaryByStoryBuilder;

public ConnectToAssessmentSessionCommandHandler(
IAssessmentSessionRepository repository,
IDialogContinuation<ContinuationState> dialogContinuation,
IMessagesSender messagesSender,
IMessageBuilder messageBuilder,
SummaryByStoryBuilder summaryByStoryBuilder)
{
_repository = repository ?? throw new ArgumentNullException(nameof(repository));
_dialogContinuation = dialogContinuation ?? throw new ArgumentNullException(nameof(dialogContinuation));
_messagesSender = messagesSender ?? throw new ArgumentNullException(nameof(messagesSender));
_messageBuilder = messageBuilder ?? throw new ArgumentNullException(nameof(messageBuilder));
_summaryByStoryBuilder = summaryByStoryBuilder ?? throw new ArgumentNullException(nameof(summaryByStoryBuilder));
Expand Down Expand Up @@ -65,7 +61,6 @@ public async Task<CommandResult> Handle(
.EnsureForAppraiser(command.AppraiserName);

assessmentSession.Connect(command.AppraiserId, command.AppraiserName);
_dialogContinuation.End(command.AppraiserId.Value, ContinuationState.EnterSessionId);

var notifications = new List<NotificationMessage>(3);
var connectedSuccessMessage = await _messageBuilder.Build(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
using Inc.TeamAssistant.Appraiser.Application.Contracts;
using Inc.TeamAssistant.Appraiser.Model.Commands.ConnectToAssessmentSession;
using Inc.TeamAssistant.Appraiser.Model.Commands.CreateAssessmentSession;
using Inc.TeamAssistant.Appraiser.Model.Commands.JoinToAssessmentSession;
using Inc.TeamAssistant.Appraiser.Model.Common;
using Inc.TeamAssistant.Appraiser.Primitives;

Expand Down Expand Up @@ -41,14 +40,12 @@ private async Task HasAssessmentSessionId(
{
if (context == null)
throw new ArgumentNullException(nameof(context));

var joinToSessionCommand = _commandProvider.GetCommand(typeof(JoinToAssessmentSessionCommand));

var createAssessmentCommand = _commandProvider.GetCommand(typeof(CreateAssessmentSessionCommand));
if (assessmentSessionId is null || assessmentSessionId.Value == Guid.Empty)
context.AddFailure(await _messageBuilder.Build(
Messages.Error_StarterMessage,
context.InstanceToValidate.LanguageId,
joinToSessionCommand,
createAssessmentCommand));
}
}

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,20 @@
using Inc.TeamAssistant.Appraiser.Model.Commands.CreateAssessmentSession;
using Inc.TeamAssistant.Appraiser.Model.Commands.ExitFromAssessmentSession;
using Inc.TeamAssistant.Appraiser.Model.Commands.FinishAssessmentSession;
using Inc.TeamAssistant.Appraiser.Model.Commands.JoinToAssessmentSession;
using Inc.TeamAssistant.Appraiser.Model.Commands.ReVoteEstimate;
using Inc.TeamAssistant.Appraiser.Model.Commands.ShowHelp;
using Inc.TeamAssistant.Appraiser.Model.Common;
using Inc.TeamAssistant.Appraiser.Model.Queries.ShowHelp;
using Inc.TeamAssistant.Appraiser.Model.Queries.ShowParticipants;
using MediatR;

namespace Inc.TeamAssistant.Appraiser.Application.QueryHandlers.ShowHelp;
namespace Inc.TeamAssistant.Appraiser.Application.CommandHandlers.ShowHelp;

internal sealed class ShowHelpQueryHandler : IRequestHandler<ShowHelpQuery, CommandResult>
internal sealed class ShowHelpCommandHandler : IRequestHandler<ShowHelpCommand, CommandResult>
{
private readonly ICommandProvider _commandProvider;
private readonly IMessageBuilder _messageBuilder;
private readonly IEnumerable<LanguageContext> _languagesInfo;

public ShowHelpQueryHandler(
public ShowHelpCommandHandler(
ICommandProvider commandProvider,
IMessageBuilder messageBuilder,
IEnumerable<LanguageContext> languagesInfo)
Expand All @@ -31,17 +29,17 @@ public ShowHelpQueryHandler(
_languagesInfo = languagesInfo ?? throw new ArgumentNullException(nameof(languagesInfo));
}

public async Task<CommandResult> Handle(ShowHelpQuery query, CancellationToken cancellationToken)
public async Task<CommandResult> Handle(ShowHelpCommand command, CancellationToken cancellationToken)
{
if (query == null)
throw new ArgumentNullException(nameof(query));
if (command == null)
throw new ArgumentNullException(nameof(command));

var commandsHelp = new List<string>();

var createAssessmentSessionCommand = _commandProvider.GetCommand(typeof(CreateAssessmentSessionCommand));
commandsHelp.Add(await _messageBuilder.Build(
Messages.CreateAssessmentSessionHelp,
query.LanguageId,
command.LanguageId,
createAssessmentSessionCommand));

foreach (var languageInfo in _languagesInfo)
Expand All @@ -52,58 +50,46 @@ public async Task<CommandResult> Handle(ShowHelpQuery query, CancellationToken c

commandsHelp.Add(await _messageBuilder.Build(
Messages.ChangeLanguageHelp,
query.LanguageId,
command.LanguageId,
changeLanguageCommand,
languageInfo.LanguageId.Value));
}

var addStoryToAssessmentSessionCommand = _commandProvider.GetCommand(typeof(AddStoryToAssessmentSessionCommand));
commandsHelp.Add(await _messageBuilder.Build(
Messages.AddStoryToAssessmentSessionHelp,
query.LanguageId,
command.LanguageId,
addStoryToAssessmentSessionCommand));

var reVoteEstimateCommand = _commandProvider.GetCommand(typeof(ReVoteEstimateCommand));
commandsHelp.Add(await _messageBuilder.Build(
Messages.ReVoteEstimateHelp,
query.LanguageId,
command.LanguageId,
reVoteEstimateCommand));

var acceptEstimateCommand = _commandProvider.GetCommand(typeof(AcceptEstimateCommand));
commandsHelp.Add(await _messageBuilder.Build(
Messages.AcceptEstimateHelp,
query.LanguageId,
command.LanguageId,
acceptEstimateCommand));

var finishAssessmentSessionCommand = _commandProvider.GetCommand(typeof(FinishAssessmentSessionCommand));
commandsHelp.Add(await _messageBuilder.Build(
Messages.FinishAssessmentSessionHelp,
query.LanguageId,
command.LanguageId,
finishAssessmentSessionCommand));

var showParticipantsQuery = _commandProvider.GetCommand(typeof(ShowParticipantsQuery));
commandsHelp.Add(await _messageBuilder.Build(
Messages.ShowParticipantsHelp,
query.LanguageId,
showParticipantsQuery));

var joinToAssessmentSessionCommand = _commandProvider.GetCommand(typeof(JoinToAssessmentSessionCommand));
commandsHelp.Add(await _messageBuilder.Build(
Messages.JoinToAssessmentSessionHelp,
query.LanguageId,
joinToAssessmentSessionCommand));

var exitFromAssessmentSessionCommand = _commandProvider.GetCommand(typeof(ExitFromAssessmentSessionCommand));
commandsHelp.Add(await _messageBuilder.Build(
Messages.ExitFromAssessmentSessionHelp,
query.LanguageId,
command.LanguageId,
exitFromAssessmentSessionCommand));

var messageBuilder = new StringBuilder();

foreach (var commandHelp in commandsHelp)
messageBuilder.AppendLine(commandHelp);

return CommandResult.Build(NotificationMessage.Create(query.TargetChatId, messageBuilder.ToString()));
return CommandResult.Build(NotificationMessage.Create(command.TargetChatId, messageBuilder.ToString()));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
using FluentValidation;
using Inc.TeamAssistant.Appraiser.Model.Commands.ShowHelp;
using Inc.TeamAssistant.Appraiser.Model.Common;

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

internal sealed class ShowHelpCommandValidator : AbstractValidator<ShowHelpCommand>
{
public ShowHelpCommandValidator(IValidator<IWithLanguage> languageValidator)
{
if (languageValidator == null)
throw new ArgumentNullException(nameof(languageValidator));

RuleFor(e => e).SetValidator(languageValidator);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,5 @@ public enum ContinuationState
{
None = 0,
EnterTitle = 1,
EnterStory = 2,
EnterSessionId = 3
EnterStory = 2
}
4 changes: 0 additions & 4 deletions src/Inc.TeamAssistant.Appraiser.Application/Messages.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,11 @@ internal static class Messages

public static readonly MessageId ExitFromAssessmentSessionHelp = new(nameof(ExitFromAssessmentSessionHelp));
public static readonly MessageId CreateAssessmentSessionHelp = new(nameof(CreateAssessmentSessionHelp));
public static readonly MessageId ShowParticipantsHelp = new(nameof(ShowParticipantsHelp));
public static readonly MessageId AddStoryToAssessmentSessionHelp = new(nameof(AddStoryToAssessmentSessionHelp));
public static readonly MessageId ChangeLanguageHelp = new(nameof(ChangeLanguageHelp));
public static readonly MessageId AcceptEstimateHelp = new(nameof(AcceptEstimateHelp));
public static readonly MessageId ReVoteEstimateHelp = new(nameof(ReVoteEstimateHelp));
public static readonly MessageId FinishAssessmentSessionHelp = new(nameof(FinishAssessmentSessionHelp));
public static readonly MessageId JoinToAssessmentSessionHelp = new(nameof(JoinToAssessmentSessionHelp));

public static readonly MessageId EnterSessionName = new(nameof(EnterSessionName));
public static readonly MessageId CreateAssessmentSessionFailed = new(nameof(CreateAssessmentSessionFailed));
Expand All @@ -38,6 +36,4 @@ internal static class Messages
public static readonly MessageId EndEstimate = new(nameof(EndEstimate));
public static readonly MessageId NeedEstimate = new(nameof(NeedEstimate));
public static readonly MessageId TotalEstimate = new(nameof(TotalEstimate));
public static readonly MessageId AppraiserList = new(nameof(AppraiserList));
public static readonly MessageId EnterSessionId = new(nameof(EnterSessionId));
}

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
using Inc.TeamAssistant.Primitives;
using MediatR;

namespace Inc.TeamAssistant.Appraiser.Model.Queries.ShowHelp;
namespace Inc.TeamAssistant.Appraiser.Model.Commands.ShowHelp;

public sealed record ShowHelpQuery(long TargetChatId, LanguageId LanguageId)
public sealed record ShowHelpCommand(long TargetChatId, LanguageId LanguageId)
: IRequest<CommandResult>, IWithLanguage;

This file was deleted.

Loading

0 comments on commit ac86561

Please sign in to comment.