Skip to content

Commit

Permalink
Bug fix
Browse files Browse the repository at this point in the history
  • Loading branch information
dyatlov-a committed Mar 3, 2024
1 parent 2efd43c commit e310558
Show file tree
Hide file tree
Showing 10 changed files with 31 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ public CreateTeamCommandValidator()

RuleFor(e => e.Name)
.NotEmpty()
.MaximumLength(255)
.Must(e => !e.StartsWith("/"))
.WithMessage("Please enter text value.");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
<PackageReference Include="FluentValidation" Version="11.7.1" />
<PackageReference Include="Microsoft.Extensions.Hosting.Abstractions" Version="7.0.0" />
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="7.0.1" />
<PackageReference Include="Npgsql" Version="7.0.6" />
<PackageReference Include="Telegram.Bot" Version="19.0.0" />
</ItemGroup>
<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using MediatR;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using Npgsql;
using Telegram.Bot;
using Telegram.Bot.Types;
using Telegram.Bot.Types.ReplyMarkups;
Expand Down Expand Up @@ -45,6 +46,7 @@ public async Task Handle(ITelegramBotClient client, Update update, Guid botId, C
if (update is null)
throw new ArgumentNullException(nameof(update));

const string duplicateKeyError = "23505";
var bot = await _botRepository.Find(botId, token);
if (bot is null)
throw new TeamAssistantUserException(Messages.Connector_BotNotFound, botId);
Expand All @@ -69,9 +71,17 @@ public async Task Handle(ITelegramBotClient client, Update update, Guid botId, C
userException.MessageId,
messageContext.LanguageId,
userException.Values);

await TrySend(client, messageContext.ChatId, errorMessage, token);
}
catch (PostgresException ex) when (ex.SqlState == duplicateKeyError)
{
await TrySend(
client,
messageContext.ChatId,
"Duplicate key value violates unique constraint.",
token);
}
catch (Exception ex)
{
_logger.LogError(ex, "Unhandled exception");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@
</ItemGroup>
<ItemGroup>
<PackageReference Include="Dapper" Version="2.1.28" />
<PackageReference Include="Npgsql" Version="8.0.1" />
<PackageReference Include="Npgsql" Version="7.0.6" />
</ItemGroup>
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public async Task Upsert(Team team, CancellationToken token)

var upsertTeam = new CommandDefinition(@"
INSERT INTO connector.teams (id, bot_id, chat_id, name, properties)
VALUES (@id, @bot_id, @chat_id, @name, @properties)
VALUES (@id, @bot_id, @chat_id, @name, @properties::jsonb)
ON CONFLICT (id) DO UPDATE SET
bot_id = EXCLUDED.bot_id,
chat_id = EXCLUDED.chat_id,
Expand Down
3 changes: 2 additions & 1 deletion src/Inc.TeamAssistant.Gateway/appsettings.Development.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
},
"ReviewerOptions": {
"BotLink": "https://t.me/inc_teamassistant_test_bot",
"BotName": "inc_teamassistant_test_bot"
"BotName": "inc_teamassistant_test_bot",
"AccessToken": "5950633493:AAFU5Lg_lWCptt8jh05r8SnP5jcLaf8CL84"
}
}
2 changes: 1 addition & 1 deletion src/Inc.TeamAssistant.Gateway/appsettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
}
},
"AllowedHosts": "*",
"AddStoryToAssessmentSessionOptions": {
"AddStoryOptions": {
"LinksPrefix": ["http://", "https://"]
},
"TelegramBotOptions": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ public override void Up()

.WithColumn("name")
.AsString(50).NotNullable()
.Unique("bots__uidx__name")

.WithColumn("token")
.AsString(255).NotNullable();
Expand Down Expand Up @@ -62,6 +63,10 @@ public override void Up()

.WithColumn("properties")
.AsCustom("jsonb").NotNullable();

Execute.Sql(
"CREATE UNIQUE INDEX teams__uidx__bot_id__name ON connector.teams (bot_id, lower(name));",
"Create index by team name");

Create
.Table("teammates")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,13 @@ FROM review.players
.InSchema("review")

.AsInt32().NotNullable().SetExistingRowsTo(1);

Alter
.Column("description")
.OnTable("task_for_reviews")
.InSchema("review")
.AsString(2000)
.NotNullable();
}

public override void Down()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ public MoveToReviewCommandValidator()

RuleFor(e => e.Description)
.NotEmpty()
.MaximumLength(2000)
.Must(e => !e.StartsWith("/"))
.WithMessage("Please enter text value.");
}
Expand Down

0 comments on commit e310558

Please sign in to comment.