Skip to content

Commit

Permalink
Fixed autotagging bug and minor cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
sei-bstein committed Jan 15, 2025
1 parent 0064bd6 commit 3ceba4e
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 45 deletions.
2 changes: 1 addition & 1 deletion src/Gameboard.Api/Data/Entities/Ticket.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ public class Ticket : IEntity
public User Creator { get; set; }
public Challenge Challenge { get; set; }
public Player Player { get; set; }

// Activity is a thread of comments and activity like status or assignee changes
public ICollection<TicketActivity> Activity { get; set; } = [];
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
using Gameboard.Api.Services;
using MediatR;
using Microsoft.EntityFrameworkCore;
using ServiceStack;

namespace Gameboard.Api.Features.Admin;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ public async Task<Challenge> Create(NewChallenge model, string actorId, string g
}
finally
{
entry.Specs = entry.Specs.Where(s => s.SpecId != model.SpecId).ToList();
entry.Specs = [.. entry.Specs.Where(s => s.SpecId != model.SpecId)];
}
}

Expand Down
79 changes: 42 additions & 37 deletions src/Gameboard.Api/Features/Support/AutoTagService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
using System.Threading;
using System.Threading.Tasks;
using Gameboard.Api.Data;
using Gameboard.Api.Features.Teams;
using Microsoft.EntityFrameworkCore;

namespace Gameboard.Api.Features.Support;
Expand All @@ -20,56 +19,62 @@ internal sealed class AutoTagService(IStore store) : IAutoTagService

public async Task<IEnumerable<string>> GetAutoTags(Data.Ticket ticket, CancellationToken cancellationToken)
{
if (ticket.ChallengeId.IsEmpty() && ticket.TeamId.IsEmpty())
return [];
var retVal = new List<string>();

var teamSponsorIds = Array.Empty<string>();

if (ticket.TeamId.IsEmpty())
if (!ticket.TeamId.IsNotEmpty())
{
teamSponsorIds = await _store
.WithNoTracking<Data.Player>()
.Where(p => p.TeamId == ticket.TeamId)
.Select(p => p.SponsorId)
.Distinct()
.ToArrayAsync(cancellationToken);

retVal.AddRange
(
await _store
.WithNoTracking<SupportSettingsAutoTag>()
.Where(t => t.ConditionType == SupportSettingsAutoTagConditionType.SponsorId && teamSponsorIds.Contains(t.ConditionValue))
.Select(t => t.Tag)
.ToArrayAsync(cancellationToken)
);
}

var challengeData = await _store
.WithNoTracking<Data.Challenge>()
.Where(c => c.Id == ticket.ChallengeId)
.Select(c => new
{
c.PlayerMode,
c.SpecId,
c.GameId
})
.SingleAsync(cancellationToken);
if (ticket.ChallengeId.IsNotEmpty())
{
var challengeData = await _store
.WithNoTracking<Data.Challenge>()
.Where(c => c.Id == ticket.ChallengeId)
.Select(c => new
{
c.GameId

Check failure on line 51 in src/Gameboard.Api/Features/Support/AutoTagService.cs

View workflow job for this annotation

GitHub Actions / test

Syntax error, ',' expected

Check failure on line 51 in src/Gameboard.Api/Features/Support/AutoTagService.cs

View workflow job for this annotation

GitHub Actions / test

Syntax error, ',' expected
c.PlayerMode,
c.SpecId,
})
.SingleOrDefaultAsync(cancellationToken);

var playerModeValue = (int)challengeData.PlayerMode;
var playerModeValue = (int)challengeData.PlayerMode;

var autoTagConfig = await _store
.WithNoTracking<SupportSettingsAutoTag>()
.Where(t => t.IsEnabled)
.Where
(
t =>
(t.ConditionType == SupportSettingsAutoTagConditionType.ChallengeSpecId && t.ConditionValue == challengeData.SpecId) ||
(t.ConditionType == SupportSettingsAutoTagConditionType.GameId && t.ConditionValue == challengeData.GameId) ||
(t.ConditionType == SupportSettingsAutoTagConditionType.PlayerMode && t.ConditionValue == playerModeValue.ToString()) ||
(t.ConditionType == SupportSettingsAutoTagConditionType.SponsorId && teamSponsorIds.Contains(t.ConditionValue))
)
.Select(t => new
if (challengeData is not null)
{
t.ConditionType,
t.ConditionValue,
t.Tag
})
.ToArrayAsync(cancellationToken);

var autoTags = await _store.WithNoTracking<SupportSettingsAutoTag>().ToArrayAsync();

return [.. autoTagConfig.Select(c => c.Tag).OrderBy(t => t)];
retVal.AddRange
(
await _store
.WithNoTracking<SupportSettingsAutoTag>()
.Where
(
c =>
(c.ConditionType == SupportSettingsAutoTagConditionType.GameId && c.ConditionValue == challengeData.GameId) ||
(c.ConditionType == SupportSettingsAutoTagConditionType.ChallengeSpecId && c.ConditionValue == challengeData.SpecId) ||
(c.ConditionType == SupportSettingsAutoTagConditionType.PlayerMode && c.ConditionValue == challengeData.PlayerMode.ToString())
)
.Select(c => c.Tag)
.ToArrayAsync(cancellationToken)
);
}
}

return [.. retVal.Distinct().OrderBy(t => t)];
}
}
11 changes: 6 additions & 5 deletions src/Gameboard.Api/Features/Ticket/TicketService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ ITeamService teamService
private readonly ISupportHubBus _supportHubBus = supportHubBus;
private readonly ITeamService _teamService = teamService;

internal static char LABELS_DELIMITER = ' ';
internal static char TAGS_DELIMITER = ' ';

public string GetFullKey(int key)
=> $"{(Options.KeyPrefix.IsEmpty() ? "GB" : Options.KeyPrefix)}-{key}";
Expand Down Expand Up @@ -191,14 +191,15 @@ public async Task<Ticket> Update(ChangedTicket model, string actorId, bool sudo)
}

if (statusChanged && entity.Status == "Closed")
{
updateClosesTicket = true;
}

updatedBySupport = true;
}
else // regular participant can only edit a few fields
{
Mapper.Map(Mapper.Map<SelfChangedTicket>(model), entity);

updatedByUser = true;
}

Expand Down Expand Up @@ -452,7 +453,7 @@ internal IEnumerable<string> TransformTicketLabels(string labels)
if (labels.IsEmpty())
return [];

return labels.Split(LABELS_DELIMITER, StringSplitOptions.RemoveEmptyEntries | StringSplitOptions.TrimEntries);
return labels.Split(TAGS_DELIMITER, StringSplitOptions.RemoveEmptyEntries | StringSplitOptions.TrimEntries);
}

private async Task UpdatedSessionContext(Data.Ticket entity)
Expand Down Expand Up @@ -486,7 +487,7 @@ private async Task UpdatedSessionContext(Data.Ticket entity)

// add conditional auto-tags
var autoTags = await _autoTagService.GetAutoTags(entity, CancellationToken.None);
var finalTags = new List<string>(entity.Label?.Split(LABELS_DELIMITER, StringSplitOptions.RemoveEmptyEntries | StringSplitOptions.TrimEntries) ?? []);
var finalTags = new List<string>(entity.Label?.Split(TAGS_DELIMITER, StringSplitOptions.RemoveEmptyEntries | StringSplitOptions.TrimEntries) ?? []);

foreach (var autoTag in autoTags)
{
Expand All @@ -496,7 +497,7 @@ private async Task UpdatedSessionContext(Data.Ticket entity)
}
}

entity.Label = string.Join(LABELS_DELIMITER, finalTags);
entity.Label = string.Join(TAGS_DELIMITER, finalTags);

if (entity.TeamId.IsEmpty())
{
Expand Down

0 comments on commit 3ceba4e

Please sign in to comment.