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

master
maxime 1 year ago
parent b3ba44f127
commit eb1053ca52

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

@ -27,7 +27,7 @@ public class DbTacticService(AppContext.AppContext context) : ITacticService
return tacticEntity.OwnerId == userId; 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 var tacticEntity = new TacticEntity
{ {
@ -49,7 +49,7 @@ public class DbTacticService(AppContext.AppContext context) : ITacticService
await context.SaveChangesAsync(); await context.SaveChangesAsync();
return tacticEntity.Id; return (tacticEntity.Id, stepEntity.Id);
} }
public async Task<bool> UpdateName(int tacticId, string name) 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="name">The name of the tactic.</param>
/// <param name="courtType">The type of court.</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> /// <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> /// <summary>
/// Updates the name of the specified tactic. /// Updates the name of the specified tactic.

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

Loading…
Cancel
Save