add root step id in the response of a create tactic request
continuous-integration/drone/push Build is passing Details

master
Maxime BATISTA 8 months ago
parent b3ba44f127
commit eb1053ca52

@ -74,7 +74,7 @@ public class TacticController(ITacticService service, IContextAccessor accessor)
[AllowedValues("PLAIN", "HALF")] string CourtType
);
public record CreateNewResponse(int Id);
public record CreateNewResponse(int Id, int RootStepId);
[HttpPost("/tactics")]
[Authorize]
@ -88,8 +88,8 @@ public class TacticController(ITacticService service, IContextAccessor accessor)
throw new ArgumentOutOfRangeException("for req.CourtType");
}
var id = await service.AddTactic(userId, req.Name, courtType);
return new CreateNewResponse(id);
var (id, rootId) = await service.AddTactic(userId, req.Name, courtType);
return new CreateNewResponse(id, rootId);
}
public record AddStepRequest(int ParentId, object Content);

@ -27,7 +27,7 @@ public class DbTacticService(AppContext.AppContext context) : ITacticService
return tacticEntity.OwnerId == userId;
}
public async Task<int> AddTactic(int userId, string name, CourtType courtType)
public async Task<(int, int)> AddTactic(int userId, string name, CourtType courtType)
{
var tacticEntity = new TacticEntity
{
@ -49,7 +49,7 @@ public class DbTacticService(AppContext.AppContext context) : ITacticService
await context.SaveChangesAsync();
return tacticEntity.Id;
return (tacticEntity.Id, stepEntity.Id);
}
public async Task<bool> UpdateName(int tacticId, string name)

@ -29,7 +29,7 @@ public interface ITacticService
/// <param name="name">The name of the tactic.</param>
/// <param name="courtType">The type of court.</param>
/// <returns>A task that represents the asynchronous operation. The task result contains the ID of the newly added tactic.</returns>
Task<int> AddTactic(int userId, string name, CourtType courtType);
Task<(int, int)> AddTactic(int userId, string name, CourtType courtType);
/// <summary>
/// Updates the name of the specified tactic.

@ -71,7 +71,7 @@ public class TacticsControllerTest
{
var (controller, context) = GetController(1);
var result = await controller.CreateNew(new("Test Tactic", "pLaIn"));
result.Should().BeEquivalentTo(new TacticController.CreateNewResponse(2));
result.Should().BeEquivalentTo(new TacticController.CreateNewResponse(2, 2));
var tactic = await context.Tactics.FirstOrDefaultAsync(e => e.Id == 2);
tactic.Should().NotBeNull();
tactic!.Name.Should().BeEquivalentTo("Test Tactic");

Loading…
Cancel
Save