Skip to content

Commit

Permalink
Add autotag delete support
Browse files Browse the repository at this point in the history
  • Loading branch information
sei-bstein committed Sep 19, 2024
1 parent ccb2649 commit d1aa29d
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,5 @@ await _testContext.WithDataState(state =>
// }
// .ToJsonBody())
// .DeserializeResponseAs<Ticket>();

// TODO: test support for FromForm
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using Gameboard.Api.Data;
using Gameboard.Api.Structure.MediatR;
using Gameboard.Api.Structure.MediatR.Validators;
using MediatR;
using Microsoft.EntityFrameworkCore;

namespace Gameboard.Api.Features.Support;

public sealed record DeleteSupportSettingsAutoTagCommand(string Id) : IRequest;

internal sealed class DeleteSupportSettingsAutoTagHandler(
IStore store,
EntityExistsValidator<SupportSettingsAutoTag> tagExists,
IValidatorService validatorService) : IRequestHandler<DeleteSupportSettingsAutoTagCommand>
{
private readonly IStore _store = store;
private readonly EntityExistsValidator<SupportSettingsAutoTag> _tagExists = tagExists;
private readonly IValidatorService _validatorService = validatorService;

public async Task Handle(DeleteSupportSettingsAutoTagCommand request, CancellationToken cancellationToken)
{
await _validatorService
.Auth(c => c.RequirePermissions(Users.PermissionKey.Support_EditSettings))
.AddValidator(_tagExists.UseValue(request.Id))
.Validate(cancellationToken);

await _store
.WithNoTracking<SupportSettingsAutoTag>()
.Where(t => t.Id == request.Id)
.ExecuteDeleteAsync(cancellationToken);
}
}
4 changes: 4 additions & 0 deletions src/Gameboard.Api/Features/Support/SupportController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ public Task<SupportSettingsViewModel> GetSupportSettingsGreeting()
public Task<SupportSettingsViewModel> UpdateSupportSettings([FromBody] SupportSettingsViewModel settings)
=> _mediator.Send(new UpdateSupportSettingsCommand(settings));

[HttpDelete("settings/autotag/{id}")]
public Task DeleteAutoTag([FromRoute] string id)
=> _mediator.Send(new DeleteSupportSettingsAutoTagCommand(id));

[HttpGet("settings/autotags")]
public Task<IEnumerable<SupportSettingsAutoTagViewModel>> GetAutoTags()
=> _mediator.Send(new GetSupportSettingsAutoTagsQuery());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ await _validatorService
.RequirePermissions(PermissionKey.Teams_Enroll)
.Unless(() => _store.AnyAsync<Data.Player>(p => p.UserId == _actingUserService.Get().Id && p.Id == request.PlayerId, cancellationToken))
)
.AddValidator(_playerExists.WithIdValue(request.PlayerId))
.AddValidator(_playerExists.UseValue(request.PlayerId))
.AddValidator(async (req, ctx) =>
{
var teamPlayers = await _store
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ public class EntityExistsValidator<TEntity>(IStore store) : IGameboardValidator
public string IdValue { get; private set; }
private readonly IStore _store = store;

public EntityExistsValidator<TEntity> WithIdValue(string idValue)
public EntityExistsValidator<TEntity> UseValue(string idValue)
{
IdValue = idValue;
return this;
Expand Down

0 comments on commit d1aa29d

Please sign in to comment.