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 0238168
Show file tree
Hide file tree
Showing 25 changed files with 60 additions and 52 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,9 @@ private GetStoryDetailsResult Get(Story story)

return new(
story.Title,
story.Links.ToArray(),
code,
StorySelected: story != Story.Empty,
new StoryDetails(story.Title, story.Links.ToArray()),
items,
story.GetTotal().ToDisplayValue(estimateEnded, story.StoryType));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@

namespace Inc.TeamAssistant.Appraiser.Model;

public interface IAssessmentSessionsService
public interface IAppraiserService
{
Task<ServiceResult<GetStoryDetailsResult?>> GetStoryDetails(
Guid assessmentSessionId,
Guid teamId,
CancellationToken cancellationToken = default);

Task<ServiceResult<GetLinkForConnectResult>> GetLinkForConnect(CancellationToken cancellationToken = default);
Expand Down
2 changes: 1 addition & 1 deletion src/Inc.TeamAssistant.Appraiser.Model/IEventsProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@ namespace Inc.TeamAssistant.Appraiser.Model;

public interface IEventsProvider : IAsyncDisposable
{
Task OnStoryChanged(Guid assessmentSessionId, Func<Task> changed);
Task OnStoryChanged(Guid teamId, Func<Task> changed);
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
namespace Inc.TeamAssistant.Appraiser.Model.Queries.GetStoryDetails;

public sealed record GetStoryDetailsResult(
string AssessmentSessionTitle,
string Title,
IReadOnlyCollection<string> Links,
string CodeForConnect,
bool StorySelected,
StoryDetails Story,
IReadOnlyCollection<StoryForEstimateDto> StoryForEstimates,
string Total);

This file was deleted.

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
8 changes: 0 additions & 8 deletions src/Inc.TeamAssistant.Gateway/CommandList.cs

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,18 @@ namespace Inc.TeamAssistant.Gateway.Controllers;

[ApiController]
[Route("sessions")]
public sealed class AssessmentSessionsController : ControllerBase
public sealed class SessionsController : ControllerBase
{
private readonly IAssessmentSessionsService _service;
private readonly IAppraiserService _service;

public AssessmentSessionsController(IAssessmentSessionsService service)
public SessionsController(IAppraiserService service)
{
_service = service ?? throw new ArgumentNullException(nameof(service));
}

[HttpGet("story/{assessmentSessionId}")]
public async Task<IActionResult> GetStoryDetails(Guid assessmentSessionId, CancellationToken cancellationToken)
=> Ok(await _service.GetStoryDetails(assessmentSessionId, cancellationToken));
[HttpGet("story/{teamId}")]
public async Task<IActionResult> GetStoryDetails(Guid teamId, CancellationToken cancellationToken)
=> Ok(await _service.GetStoryDetails(teamId, cancellationToken));

[HttpGet("link-for-connect")]
public async Task<IActionResult> LinkForConnect(CancellationToken cancellationToken)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,21 @@

namespace Inc.TeamAssistant.Gateway.Services;

internal sealed class AssessmentSessionsService : IAssessmentSessionsService
internal sealed class AppraiserService : IAppraiserService
{
private readonly IMediator _mediator;

public AssessmentSessionsService(IMediator mediator)
public AppraiserService(IMediator mediator)
=> _mediator = mediator ?? throw new ArgumentNullException(nameof(mediator));

public async Task<ServiceResult<GetStoryDetailsResult?>> GetStoryDetails(
Guid assessmentSessionId,
Guid teamId,
CancellationToken cancellationToken)
{
try
{
var result = await _mediator.Send(
new GetStoryDetailsQuery(assessmentSessionId),
new GetStoryDetailsQuery(teamId),
cancellationToken);

return result is null
Expand Down
2 changes: 1 addition & 1 deletion src/Inc.TeamAssistant.Gateway/Services/EventsProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ namespace Inc.TeamAssistant.Gateway.Services;

internal sealed class EventsProvider : IEventsProvider
{
public Task OnStoryChanged(Guid assessmentSessionId, Func<Task> changed) => Task.CompletedTask;
public Task OnStoryChanged(Guid teamId, Func<Task> changed) => Task.CompletedTask;

public ValueTask DisposeAsync() => ValueTask.CompletedTask;
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public static IServiceCollection AddServices(
options.CacheAbsoluteExpiration));

services
.AddScoped<IAssessmentSessionsService, AssessmentSessionsService>()
.AddScoped<IAppraiserService, AppraiserService>()
.AddSingleton<IEventsProvider, EventsProvider>()
.AddScoped<ICookieService, CookieService>()
.AddScoped<IMessagesSender, MessagesSender>()
Expand Down
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
2 changes: 1 addition & 1 deletion src/Inc.TeamAssistant.WebUI/Components/About.razor
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
@using Inc.TeamAssistant.Appraiser.Model.Common
@using Inc.TeamAssistant.WebUI.Components.Annotations

@inject IAssessmentSessionsService Service
@inject IAppraiserService Service
@inject LanguageManager LanguageManager

<div class="about__body">
Expand Down
12 changes: 5 additions & 7 deletions src/Inc.TeamAssistant.WebUI/Pages/AssessmentSession.razor
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
@using Inc.TeamAssistant.Appraiser.Model.Common
@using Inc.TeamAssistant.WebUI.Pages.Annotations

@inject IAssessmentSessionsService Service
@inject IAppraiserService Service
@inject IEventsProvider EventsProvider
@inject LanguageManager LanguageManager

Expand All @@ -18,16 +18,14 @@
@if (_model is { State: ServiceResultState.Success, Result: not null })
{
<div class="assessment-session__details">
<span class="assessment-session__subtitle">@_model.Result.AssessmentSessionTitle</span>

@if (_model.Result.StorySelected)
{
<h1 class="assessment-session__title">@_annotation.GetTitle(_model.Result.Story.Title)</h1>
<h1 class="assessment-session__title">@_annotation.GetTitle(_model.Result.Title)</h1>

if (_model.Result.Story.Links.Any())
if (_model.Result.Links.Any())
{
<ul class="assessment-session__items">
@foreach (var link in _model.Result.Story.Links)
@foreach (var link in _model.Result.Links)
{
<li class="assessment-session__item">
<a class="assessment-session__link" href="@link" target="_blank">@link</a>
Expand Down Expand Up @@ -89,7 +87,7 @@
private AssessmentSessionAnnotation _annotation = AssessmentSessionAnnotation.Empty;

private MarkupString PageTitle => _model is { State: ServiceResultState.Success, Result: not null }
? (MarkupString)_model.Result.AssessmentSessionTitle
? (MarkupString)_model.Result.Title
: _annotation.AssessmentSessionCard;

private MarkupString StateMessage => _model.State switch
Expand Down
4 changes: 0 additions & 4 deletions src/Inc.TeamAssistant.WebUI/Pages/AssessmentSession.razor.css
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,6 @@
margin: 0 0 .75rem 0;
letter-spacing: .0625rem;
}
.assessment-session__subtitle {
margin: 0 0 .75rem 0;
display: block;
}
.assessment-session__text {
line-height: 1.6rem;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,23 +7,23 @@

namespace Inc.TeamAssistant.WebUI.Services;

internal sealed class AssessmentSessionsClient : IAssessmentSessionsService
internal sealed class AppraiserClient : IAppraiserService
{
private readonly HttpClient _client;

public AssessmentSessionsClient(HttpClient client)
public AppraiserClient(HttpClient client)
{
_client = client ?? throw new ArgumentNullException(nameof(client));
}

public async Task<ServiceResult<GetStoryDetailsResult?>> GetStoryDetails(
Guid assessmentSessionId,
Guid teamId,
CancellationToken cancellationToken)
{
try
{
var result = await _client.GetFromJsonAsync<ServiceResult<GetStoryDetailsResult?>>(
$"sessions/story/{assessmentSessionId}",
$"sessions/story/{teamId}",
cancellationToken);

if (result is null)
Expand Down
4 changes: 2 additions & 2 deletions src/Inc.TeamAssistant.WebUI/Services/EventsProviderClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,15 @@ public EventsProviderClient(NavigationManager navigationManager)
.Build();
}

public async Task OnStoryChanged(Guid assessmentSessionId, Func<Task> changed)
public async Task OnStoryChanged(Guid teamId, Func<Task> changed)
{
if (changed is null)
throw new ArgumentNullException(nameof(changed));

_hubConnection.On("StoryChanged", changed);

await _hubConnection.StartAsync();
await _hubConnection.InvokeAsync("JoinToGroup", assessmentSessionId);
await _hubConnection.InvokeAsync("JoinToGroup", teamId);
}

public ValueTask DisposeAsync() => _hubConnection.DisposeAsync();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ internal static IServiceCollection AddServices(this IServiceCollection services)
services
.AddBlazoredLocalStorage()

.AddScoped<IAssessmentSessionsService, AssessmentSessionsClient>()
.AddScoped<IAppraiserService, AppraiserClient>()
.AddScoped<IClientInfoService, ClientInfoClient>()
.AddSingleton<IEventsProvider, EventsProviderClient>()
.AddSingleton<ICookieService, CookieServiceClient>()
Expand Down

0 comments on commit 0238168

Please sign in to comment.