-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
3aad282
commit 037b52e
Showing
16 changed files
with
192 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 25 additions & 0 deletions
25
src/Inc.TeamAssistant.Migrations/2024_10_25_0_AddRandomCoffeeRefusedFlag.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
using FluentMigrator; | ||
|
||
namespace Inc.TeamAssistant.Migrations; | ||
|
||
[Migration(2024_10_25_0)] | ||
|
||
public sealed class AddRandomCoffeeRefusedFlag : Migration | ||
{ | ||
public override void Up() | ||
{ | ||
Create | ||
.Column("refused") | ||
.OnTable("entries") | ||
.InSchema("random_coffee") | ||
.AsBoolean().Nullable(); | ||
} | ||
|
||
public override void Down() | ||
{ | ||
Delete | ||
.Column("refused") | ||
.FromTable("entries") | ||
.InSchema("random_coffee"); | ||
} | ||
} |
43 changes: 43 additions & 0 deletions
43
src/Inc.TeamAssistant.Migrations/2024_10_25_1_AddRandomCoffeeRefuseHelpToCommand.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
using FluentMigrator; | ||
|
||
namespace Inc.TeamAssistant.Migrations; | ||
|
||
[Migration(2024_10_25_1)] | ||
|
||
public class AddRandomCoffeeRefuseHelpToCommand : Migration | ||
{ | ||
public override void Up() | ||
{ | ||
Execute.Sql( | ||
""" | ||
INSERT INTO connector.bot_commands(id, value, help_message_id, scopes) | ||
VALUES | ||
('d6097f8b-de33-412c-a064-68069d458776', '/refuse', 'RandomCoffee_RefuseHelp', '[2]'::jsonb) | ||
""", | ||
"Insert new random coffee command"); | ||
Execute.Sql( | ||
""" | ||
INSERT INTO connector.command_packs(feature_id, bot_command_id) | ||
VALUES | ||
('39195e70-b83a-42b3-88e5-dbbf6789a3c8', 'd6097f8b-de33-412c-a064-68069d458776') | ||
""", | ||
"Insert new random coffee command"); | ||
} | ||
|
||
public override void Down() | ||
{ | ||
Execute.Sql( | ||
""" | ||
DELETE FROM connector.bot_commands | ||
WHERE id = 'd6097f8b-de33-412c-a064-68069d458776'; | ||
""", | ||
"Clear new random coffee command"); | ||
Execute.Sql( | ||
""" | ||
DELETE FROM connector.command_packs | ||
WHERE feature_id = '39195e70-b83a-42b3-88e5-dbbf6789a3c8' | ||
AND bot_command_id = 'd6097f8b-de33-412c-a064-68069d458776'; | ||
""", | ||
"Clear new random coffee command"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
59 changes: 59 additions & 0 deletions
59
...RandomCoffee.Application/CommandHandlers/RefuseForCoffee/RefuseForCoffeeCommandHandler.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
using Inc.TeamAssistant.Primitives; | ||
using Inc.TeamAssistant.Primitives.Commands; | ||
using Inc.TeamAssistant.Primitives.Exceptions; | ||
using Inc.TeamAssistant.Primitives.Languages; | ||
using Inc.TeamAssistant.Primitives.Notifications; | ||
using Inc.TeamAssistant.RandomCoffee.Application.Contracts; | ||
using Inc.TeamAssistant.RandomCoffee.Model.Commands.RefuseForCoffee; | ||
using MediatR; | ||
|
||
namespace Inc.TeamAssistant.RandomCoffee.Application.CommandHandlers.RefuseForCoffee; | ||
|
||
public sealed class RefuseForCoffeeCommandHandler : IRequestHandler<RefuseForCoffeeCommand, CommandResult> | ||
{ | ||
private readonly IRandomCoffeeRepository _repository; | ||
private readonly ITeamAccessor _teamAccessor; | ||
private readonly IMessageBuilder _messageBuilder; | ||
|
||
public RefuseForCoffeeCommandHandler( | ||
IRandomCoffeeRepository repository, | ||
ITeamAccessor teamAccessor, | ||
IMessageBuilder messageBuilder) | ||
{ | ||
_repository = repository ?? throw new ArgumentNullException(nameof(repository)); | ||
_teamAccessor = teamAccessor ?? throw new ArgumentNullException(nameof(teamAccessor)); | ||
_messageBuilder = messageBuilder ?? throw new ArgumentNullException(nameof(messageBuilder)); | ||
} | ||
|
||
public async Task<CommandResult> Handle(RefuseForCoffeeCommand command, CancellationToken token) | ||
{ | ||
ArgumentNullException.ThrowIfNull(command); | ||
|
||
var existsRandomCoffeeEntry = await _repository.Find(command.MessageContext.ChatMessage.ChatId, token); | ||
if (existsRandomCoffeeEntry is null || existsRandomCoffeeEntry.Refused is true) | ||
return CommandResult.Empty; | ||
|
||
var owner = await _teamAccessor.FindPerson(existsRandomCoffeeEntry.OwnerId, token); | ||
if (owner is null) | ||
throw new TeamAssistantException($"Owner {existsRandomCoffeeEntry.OwnerId} was not found."); | ||
|
||
existsRandomCoffeeEntry.MoveToRefused(); | ||
|
||
await _repository.Upsert(existsRandomCoffeeEntry, token); | ||
|
||
var languageId = await _teamAccessor.GetClientLanguage(command.MessageContext.Bot.Id, owner.Id, token); | ||
var notification = NotificationMessage | ||
.Create( | ||
existsRandomCoffeeEntry.ChatId, | ||
await _messageBuilder.Build(Messages.RandomCoffee_RefusedForCoffee, languageId)); | ||
var notifications = command.MessageContext.ChatMessage.OnlyChat | ||
? [notification] | ||
: new[] | ||
{ | ||
notification, | ||
NotificationMessage.Delete(command.MessageContext.ChatMessage) | ||
}; | ||
|
||
return CommandResult.Build(notifications); | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
...fee.Application/CommandHandlers/RefuseForCoffee/Services/RefuseForCoffeeCommandCreator.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
using Inc.TeamAssistant.Primitives.Commands; | ||
using Inc.TeamAssistant.RandomCoffee.Model.Commands.RefuseForCoffee; | ||
|
||
namespace Inc.TeamAssistant.RandomCoffee.Application.CommandHandlers.RefuseForCoffee.Services; | ||
|
||
internal sealed class RefuseForCoffeeCommandCreator : ICommandCreator | ||
{ | ||
public string Command => CommandList.RefuseForCoffee; | ||
|
||
public Task<IDialogCommand> Create( | ||
MessageContext messageContext, | ||
CurrentTeamContext teamContext, | ||
CancellationToken token) | ||
{ | ||
ArgumentNullException.ThrowIfNull(messageContext); | ||
ArgumentNullException.ThrowIfNull(teamContext); | ||
|
||
return Task.FromResult<IDialogCommand>(new RefuseForCoffeeCommand(messageContext)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 6 additions & 0 deletions
6
src/Inc.TeamAssistant.RandomCoffee.Model/Commands/RefuseForCoffee/RefuseForCoffeeCommand.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
using Inc.TeamAssistant.Primitives.Commands; | ||
|
||
namespace Inc.TeamAssistant.RandomCoffee.Model.Commands.RefuseForCoffee; | ||
|
||
public sealed record RefuseForCoffeeCommand(MessageContext MessageContext) | ||
: IDialogCommand; |