@ -26,7 +26,7 @@ public class TacticController(ITacticService service, IContextAccessor accessor)
[FromBody] UpdateNameRequest req )
{
var userId = accessor . CurrentUserId ( HttpContext ) ;
if ( ! await service . IsOwnerOf ( userId , tacticId ) )
if ( ! await service . HasAnyRights ( userId , tacticId ) )
{
return Unauthorized ( ) ;
}
@ -41,7 +41,7 @@ public class TacticController(ITacticService service, IContextAccessor accessor)
public async Task < IActionResult > GetTacticInfo ( int tacticId )
{
var userId = accessor . CurrentUserId ( HttpContext ) ;
if ( ! await service . IsOwnerOf ( userId , tacticId ) )
if ( ! await service . HasAnyRights ( userId , tacticId ) )
{
return Unauthorized ( ) ;
}
@ -57,7 +57,7 @@ public class TacticController(ITacticService service, IContextAccessor accessor)
public async Task < IActionResult > GetTacticStepsRoot ( int tacticId )
{
var userId = accessor . CurrentUserId ( HttpContext ) ;
if ( ! await service . IsOwnerOf ( userId , tacticId ) )
if ( ! await service . HasAnyRights ( userId , tacticId ) )
{
return Unauthorized ( ) ;
}
@ -74,7 +74,7 @@ public class TacticController(ITacticService service, IContextAccessor accessor)
[AllowedValues("PLAIN", "HALF")] string CourtType
) ;
public record CreateNewResponse ( int Id , int RootStepId );
public record CreateNewResponse ( int Id );
[HttpPost("/tactics")]
[Authorize]
@ -88,8 +88,8 @@ public class TacticController(ITacticService service, IContextAccessor accessor)
throw new ArgumentOutOfRangeException ( "for req.CourtType" ) ;
}
var ( id , rootId ) = await service . AddTactic ( userId , req . Name , courtType ) ;
return new CreateNewResponse ( id , rootId );
var id = await service . AddTactic ( userId , req . Name , courtType ) ;
return new CreateNewResponse ( id );
}
public record AddStepRequest ( int ParentId , object Content ) ;
@ -110,7 +110,7 @@ public class TacticController(ITacticService service, IContextAccessor accessor)
{
var userId = accessor . CurrentUserId ( HttpContext ) ;
if ( ! await service . IsOwnerOf ( userId , tacticId ) )
if ( ! await service . HasAnyRights ( userId , tacticId ) )
{
return Unauthorized ( ) ;
}
@ -125,7 +125,7 @@ public class TacticController(ITacticService service, IContextAccessor accessor)
{
var userId = accessor . CurrentUserId ( HttpContext ) ;
if ( ! await service . IsOwnerOf ( userId , tacticId ) )
if ( ! await service . HasAnyRights ( userId , tacticId ) )
{
return Unauthorized ( ) ;
}
@ -142,7 +142,7 @@ public class TacticController(ITacticService service, IContextAccessor accessor)
public async Task < IActionResult > SaveStepContent ( int tacticId , int stepId , [ FromBody ] SaveStepContentRequest req )
{
var userId = accessor . CurrentUserId ( HttpContext ) ;
if ( ! await service . IsOwnerOf ( userId , tacticId ) )
if ( ! await service . HasAnyRights ( userId , tacticId ) )
{
return Unauthorized ( ) ;
}
@ -150,28 +150,4 @@ public class TacticController(ITacticService service, IContextAccessor accessor)
var found = await service . SetTacticStepContent ( tacticId , stepId , JsonSerializer . Serialize ( req . Content ) ) ;
return found ? Ok ( ) : NotFound ( ) ;
}
public record CanEditResponse ( bool CanEdit ) ;
[HttpGet("/tactics/{tacticId:int}/can-edit")]
[Authorize]
public async Task < CanEditResponse > CanEdit ( int tacticId )
{
var userId = accessor . CurrentUserId ( HttpContext ) ;
return new CanEditResponse ( await service . IsOwnerOf ( userId , tacticId ) ) ;
}
[HttpDelete("/tactics/{tacticId:int}")]
[Authorize]
public async Task < IActionResult > RemoveTactic ( int tacticId )
{
var userId = accessor . CurrentUserId ( HttpContext ) ;
if ( ! await service . IsOwnerOf ( userId , tacticId ) )
{
return Unauthorized ( ) ;
}
return await service . RemoveTactic ( tacticId ) ? Ok ( ) : NotFound ( ) ;
}
}