|
|
@ -1,6 +1,7 @@
|
|
|
|
using System.ComponentModel.DataAnnotations;
|
|
|
|
using System.ComponentModel.DataAnnotations;
|
|
|
|
using API.Context;
|
|
|
|
using API.Context;
|
|
|
|
using API.Validation;
|
|
|
|
using API.Validation;
|
|
|
|
|
|
|
|
using AppContext.Entities;
|
|
|
|
using Microsoft.AspNetCore.Authorization;
|
|
|
|
using Microsoft.AspNetCore.Authorization;
|
|
|
|
using Microsoft.AspNetCore.Mvc;
|
|
|
|
using Microsoft.AspNetCore.Mvc;
|
|
|
|
using Model;
|
|
|
|
using Model;
|
|
|
@ -10,7 +11,7 @@ namespace API.Controllers;
|
|
|
|
|
|
|
|
|
|
|
|
[ApiController]
|
|
|
|
[ApiController]
|
|
|
|
[Authorize]
|
|
|
|
[Authorize]
|
|
|
|
public class TeamsController(ITeamService service, IContextAccessor accessor) : ControllerBase
|
|
|
|
public class TeamsController(ITeamService service, ITacticService tactics,IContextAccessor accessor) : ControllerBase
|
|
|
|
{
|
|
|
|
{
|
|
|
|
public record CreateTeamRequest(
|
|
|
|
public record CreateTeamRequest(
|
|
|
|
[Name] string Name,
|
|
|
|
[Name] string Name,
|
|
|
@ -74,4 +75,34 @@ public class TeamsController(ITeamService service, IContextAccessor accessor) :
|
|
|
|
var removed = await service.RemoveMember(teamId, userId);
|
|
|
|
var removed = await service.RemoveMember(teamId, userId);
|
|
|
|
return removed ? Ok() : NotFound();
|
|
|
|
return removed ? Ok() : NotFound();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public record ShareTacticToTeamRequest(
|
|
|
|
|
|
|
|
int TacticId,
|
|
|
|
|
|
|
|
int TeamId
|
|
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
[HttpPost("/team/share-tactic")]
|
|
|
|
|
|
|
|
[Authorize]
|
|
|
|
|
|
|
|
public async Task<IActionResult> ShareTactic([FromBody] ShareTacticToTeamRequest sharedTactic)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
var userId = accessor.CurrentUserId(HttpContext);
|
|
|
|
|
|
|
|
var success = await tactics.ShareTactic(sharedTactic.TacticId, null, sharedTactic.TeamId);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return success ? Ok() : BadRequest();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
[HttpGet("/tactics/shared/team/{teamId:int}")]
|
|
|
|
|
|
|
|
[Authorize]
|
|
|
|
|
|
|
|
public async Task<IActionResult> GetSharedTacticsToTeam(int teamId)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
var currentUserId = accessor.CurrentUserId(HttpContext);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (!await service.IsUserInTeam(currentUserId, teamId))
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
return Unauthorized();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var sharedTactics = await service.GetSharedTacticsToTeam(teamId);
|
|
|
|
|
|
|
|
return sharedTactics != null ? Ok(sharedTactics) : NotFound();
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|