Skip to content

Commit

Permalink
Single url added to story
Browse files Browse the repository at this point in the history
  • Loading branch information
Space-tourist committed Dec 2, 2024
1 parent 9e1f459 commit 0c75151
Show file tree
Hide file tree
Showing 21 changed files with 103 additions and 73 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using MediatR;
using Inc.TeamAssistant.Appraiser.Application.Services;
using Inc.TeamAssistant.Appraiser.Domain;
using Inc.TeamAssistant.Primitives;
using Inc.TeamAssistant.Primitives.Commands;
using Inc.TeamAssistant.Primitives.Exceptions;

Expand All @@ -28,6 +29,20 @@ public AddStoryCommandHandler(
public async Task<CommandResult> Handle(AddStoryCommand command, CancellationToken token)
{
ArgumentNullException.ThrowIfNull(command);

var separator = ' ';
var storyItems = command.Text.Split(separator);
var url = string.Empty;
var text = new List<string>();

foreach (var storyItem in storyItems)
{
if (GlobalSettings.LinksPrefix.Any(l => storyItem.StartsWith(l, StringComparison.InvariantCultureIgnoreCase)))
url = string.IsNullOrWhiteSpace(url) ? storyItem.ToLowerInvariant()
: throw new TeamAssistantUserException(Messages.Appraiser_MultipleLinkError);
else
text.Add(storyItem);
}

var targetTeam = command.MessageContext.FindTeam(command.TeamId);
if (targetTeam is null)
Expand All @@ -41,10 +56,10 @@ public async Task<CommandResult> Handle(AddStoryCommand command, CancellationTok
targetTeam.ChatId,
command.MessageContext.Person.Id,
command.MessageContext.LanguageId,
command.Title);
string.Join(separator, text));

foreach (var link in command.Links)
story.AddLink(link);
if (!string.IsNullOrWhiteSpace(url))
story.AddLink(url);

foreach (var teammate in command.Teammates)
story.AddStoryForEstimate(new StoryForEstimate(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,27 +24,14 @@ public async Task<IDialogCommand> Create(
{
ArgumentNullException.ThrowIfNull(messageContext);
ArgumentNullException.ThrowIfNull(teamContext);

var separator = ' ';

var teammates = await _teamAccessor.GetTeammates(teamContext.TeamId, DateTimeOffset.UtcNow, token);
var storyItems = messageContext.Text.Split(separator);
var links = new List<string>();
var text = new List<string>();

foreach (var storyItem in storyItems)
{
if (GlobalSettings.LinksPrefix.Any(l => storyItem.StartsWith(l, StringComparison.InvariantCultureIgnoreCase)))
links.Add(storyItem.ToLowerInvariant());
else
text.Add(storyItem);
}

return new AddStoryCommand(
messageContext,
teamContext.TeamId,
teamContext.Properties.GetStoryType(),
string.Join(separator, text),
links,
messageContext.Text,
teammates);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,11 @@ public AddStoryCommandValidator()
RuleFor(e => e.StoryType)
.NotEmpty();

RuleFor(e => e.Title)
RuleFor(e => e.Text)
.NotEmpty()
.Must(e => !e.StartsWith("/"))
.WithMessage("'{PropertyName}' please enter text value.");

RuleForEach(e => e.Links)
.NotEmpty();

RuleFor(e => e.Teammates)
.NotEmpty();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,12 @@ public static StoryDto Convert(Story story)
return new(
story.Id,
story.Title,
story.Links.ToArray(),
items,
story.EstimateEnded,
story.CalculateMean().DisplayValue,
story.CalculateMedian().DisplayValue,
story.AcceptedValue.DisplayValue,
story.RoundsCount);
story.RoundsCount,
story.Url);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ public static SummaryByStory ConvertTo(Story story)
story.ExternalId,
story.Title,
story.StoryType.ToString(),
story.Links.ToArray(),
story.EstimateEnded,
story.CalculateMean().DisplayValue,
story.CalculateMedian().DisplayValue,
Expand All @@ -44,6 +43,7 @@ public static SummaryByStory ConvertTo(Story story)
assessments,
story.Accepted,
assessmentsToAccept,
story.RoundsCount);
story.RoundsCount,
story.Url);
}
}
1 change: 1 addition & 0 deletions src/Inc.TeamAssistant.Appraiser.Application/Messages.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,5 @@ internal static class Messages
public static readonly MessageId Connector_TeamNotFound = new(nameof(Connector_TeamNotFound));
public static readonly MessageId Appraiser_MissingTaskForEvaluate = new(nameof(Appraiser_MissingTaskForEvaluate));
public static readonly MessageId Appraiser_NumberOfRounds = new(nameof(Appraiser_NumberOfRounds));
public static readonly MessageId Appraiser_MultipleLinkError = new(nameof(Appraiser_MultipleLinkError));
}
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,11 @@ private async Task AddBody(StringBuilder builder, SummaryByStory summary)
summary.LanguageId);

builder.AppendLine(storyHeader);

builder.AppendLine(summary.StoryTitle);
if (summary.StoryLinks.Any())
foreach (var link in summary.StoryLinks)
builder.AppendLine(link);

if (!string.IsNullOrWhiteSpace(summary.Url))
builder.AppendLine(summary.Url);
}

private async Task AddEstimateSummary(StringBuilder builder, SummaryByStory summary)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ public static async Task<IReadOnlyCollection<Story>> Get(
s.language_id AS languageid,
s.title AS title,
s.external_id AS externalid,
s.links AS links,
s.total_value AS totalvalue,
s.rounds_count AS roundscount
s.rounds_count AS roundscount,
s.url AS url
FROM appraiser.stories AS s
WHERE s.id = ANY(@story_ids);
Expand Down
4 changes: 2 additions & 2 deletions src/Inc.TeamAssistant.Appraiser.DataAccess/StoryReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@ public async Task<IReadOnlyCollection<Story>> GetStories(
s.language_id AS languageid,
s.title AS title,
s.external_id AS externalid,
s.links AS links,
s.total_value AS totalvalue,
s.rounds_count AS roundscount
s.rounds_count AS roundscount,
s.url AS url
FROM appraiser.stories AS s
WHERE s.team_id = @team_id AND s.created <= @before AND (@from is null OR s.created >= @from);",
new
Expand Down
12 changes: 7 additions & 5 deletions src/Inc.TeamAssistant.Appraiser.DataAccess/StoryRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,10 @@ public async Task Upsert(Story story, CancellationToken token)
var upsertStory = new CommandDefinition(@"
INSERT INTO appraiser.stories (
id, bot_id, story_type, created, team_id, chat_id, moderator_id, language_id, title,
external_id, links, total_value, rounds_count)
external_id, links, total_value, rounds_count, url)
VALUES (
@id, @bot_id, @story_type, @created, @team_id, @chat_id, @moderator_id, @language_id, @title,
@external_id, @links::jsonb, @total_value, @rounds_count)
@external_id, @links::jsonb, @total_value, @rounds_count, @url)
ON CONFLICT (id) DO UPDATE SET
bot_id = EXCLUDED.bot_id,
story_type = EXCLUDED.story_type,
Expand All @@ -63,7 +63,8 @@ ON CONFLICT (id) DO UPDATE SET
external_id = EXCLUDED.external_id,
links = EXCLUDED.links,
total_value = EXCLUDED.total_value,
rounds_count = EXCLUDED.rounds_count;",
rounds_count = EXCLUDED.rounds_count,
url = EXCLUDED.url;",
new
{
id = story.Id,
Expand All @@ -76,9 +77,10 @@ ON CONFLICT (id) DO UPDATE SET
language_id = story.LanguageId.Value,
title = story.Title,
external_id = story.ExternalId,
links = JsonSerializer.Serialize(story.Links),
links = JsonSerializer.Serialize(Array.Empty<string>()),
total_value = story.TotalValue,
rounds_count = story.RoundsCount
rounds_count = story.RoundsCount,
url = story.Url
},
flags: CommandFlags.None,
cancellationToken: token);
Expand Down
8 changes: 2 additions & 6 deletions src/Inc.TeamAssistant.Appraiser.Domain/Story.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,16 @@ public sealed class Story
public bool Accepted => TotalValue.HasValue;
public int? TotalValue { get; private set; }
public int RoundsCount { get; private set; }
public string? Url { get; private set; }

private readonly List<StoryForEstimate> _storyForEstimates;
public IReadOnlyCollection<StoryForEstimate> StoryForEstimates => _storyForEstimates;

public ICollection<string> Links { get; private set; }

private IEstimationStrategy EstimationStrategy => EstimationStrategyFactory.Create(StoryType);

private Story()
{
_storyForEstimates = new();
Links = new List<string>();
}

public Story(
Expand Down Expand Up @@ -78,9 +76,7 @@ public void AddStoryForEstimate(StoryForEstimate storyForEstimate)

public void AddLink(string link)
{
ArgumentException.ThrowIfNullOrWhiteSpace(link);

Links.Add(link);
Url = link;
}

public void Reset(long participantId, bool hasManagerAccess)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ public sealed record AddStoryCommand(
MessageContext MessageContext,
Guid TeamId,
string StoryType,
string Title,
IReadOnlyCollection<string> Links,
string Text,
IReadOnlyCollection<Person> Teammates)
: IEndDialogCommand;
4 changes: 2 additions & 2 deletions src/Inc.TeamAssistant.Appraiser.Model/Common/StoryDto.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ namespace Inc.TeamAssistant.Appraiser.Model.Common;
public sealed record StoryDto(
Guid Id,
string Title,
IReadOnlyCollection<string> Links,
IReadOnlyCollection<StoryForEstimateDto> StoryForEstimates,
bool EstimateEnded,
string Mean,
string Median,
string AcceptedValue,
int RoundsCount);
int RoundsCount,
string? Url);
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ public sealed record SummaryByStory(
int? StoryExternalId,
string StoryTitle,
string StoryType,
IReadOnlyCollection<string> StoryLinks,
bool EstimateEnded,
string Mean,
string Median,
Expand All @@ -19,4 +18,5 @@ public sealed record SummaryByStory(
IReadOnlyCollection<EstimateDto> Assessments,
bool Accepted,
IReadOnlyCollection<EstimateDto> AssessmentsToAccept,
int RoundsCount);
int RoundsCount,
string? Url);
Original file line number Diff line number Diff line change
Expand Up @@ -41,15 +41,14 @@ public async Task StartEstimate(StartEstimateRequest request, CancellationToken
var title = string.IsNullOrWhiteSpace(request.IssueKey)
? request.Subject
: $"[{request.IssueKey}] {request.Subject}";
var links = string.IsNullOrWhiteSpace(request.IssueUrl)
? Array.Empty<string>()
: [request.IssueUrl];
var url = string.IsNullOrWhiteSpace(request.IssueUrl)
? string.Empty
: request.IssueUrl;
var command = new AddStoryCommand(
messageContext,
context.TeamId,
context.TeamProperties.GetStoryType(),
title,
links,
$"{title} {url}",
teammates);

await _commandExecutor.Execute(command, token);
Expand Down
1 change: 1 addition & 0 deletions src/Inc.TeamAssistant.Gateway/wwwroot/langs/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
"Appraiser_PowerOfTwo_32SP": "32",
"Appraiser_PowerOfTwo_64SP": "64",
"Appraiser_NumberOfRounds": "Number of evaluation rounds",
"Appraiser_MultipleLinkError": "Please attach only one link",

"CheckIn_GetStarted": "To get started, please add the bot to your chat room",
"CheckIn_ConnectLinkText": "Use {0} to see our locations",
Expand Down
1 change: 1 addition & 0 deletions src/Inc.TeamAssistant.Gateway/wwwroot/langs/ru.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
"Appraiser_PowerOfTwo_32SP": "32",
"Appraiser_PowerOfTwo_64SP": "64",
"Appraiser_NumberOfRounds": "Количество раундов оценки",
"Appraiser_MultipleLinkError": "Пожалуйста, укажите только одну ссылку",

"CheckIn_GetStarted": "Добавьте бота в чат для начала работы",
"CheckIn_ConnectLinkText": "Перейдите по ссылке {0} чтобы увидеть наши локации",
Expand Down
33 changes: 33 additions & 0 deletions src/Inc.TeamAssistant.Migrations/2024_11_25_0_AddUrl.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
using FluentMigrator;

namespace Inc.TeamAssistant.Migrations;

[Migration(2024_11_25_0)]

public sealed class AddUrl : Migration
{
public override void Up()
{
Create
.Column("url")
.OnTable("stories")
.InSchema("appraiser")
.AsString()
.Nullable();

Execute.Sql(
"""
UPDATE appraiser.stories
SET url = links->>0;
""",
"Add single url to story");
}

public override void Down()
{
Delete
.Column("url")
.FromTable("stories")
.InSchema("appraiser");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,6 @@
new StoryDto(
Id: Guid.NewGuid(),
Title: "Create order from user card",
Links: ["https://amazon.com", "https://ozon.ru"],
StoryForEstimates: [
new StoryForEstimateDto(
ParticipantId: 0,
Expand All @@ -104,7 +103,8 @@
Mean: "9.6",
Median: "8",
AcceptedValue: string.Empty,
RoundsCount: 1));
RoundsCount: 1,
Url: "https://amazon.com"));

private void OnViewChanged(AssessmentType view)
{
Expand Down
Loading

0 comments on commit 0c75151

Please sign in to comment.