-
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 785421e
Showing
19 changed files
with
209 additions
and
12 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
using Inc.TeamAssistant.Primitives.Languages; | ||
|
||
namespace Inc.TeamAssistant.Appraiser.Domain; | ||
|
||
internal static class Messages | ||
{ | ||
public static readonly MessageId Connector_HasNoRights = new(nameof(Connector_HasNoRights)); | ||
} |
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
57 changes: 57 additions & 0 deletions
57
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,57 @@ | ||
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() | ||
.NotNullable() | ||
.SetExistingRowsTo(false); | ||
|
||
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() | ||
{ | ||
Delete | ||
.Column("refused") | ||
.FromTable("entries") | ||
.InSchema("random_coffee"); | ||
|
||
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"); | ||
|
||
Execute.Sql( | ||
""" | ||
DELETE FROM connector.bot_commands | ||
WHERE 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
61 changes: 61 additions & 0 deletions
61
...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,61 @@ | ||
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) | ||
return CommandResult.Empty; | ||
|
||
if (command.MessageContext.Person.Id != existsRandomCoffeeEntry.OwnerId) | ||
throw new TeamAssistantUserException(Messages.Connector_HasNoRights, command.MessageContext.Person.Id); | ||
|
||
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 = 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; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
using Inc.TeamAssistant.Primitives.Languages; | ||
|
||
namespace Inc.TeamAssistant.Reviewer.Domain; | ||
|
||
internal static class Messages | ||
{ | ||
public static readonly MessageId Connector_HasNoRights = new(nameof(Connector_HasNoRights)); | ||
} |