|
|
|
@ -1,7 +1,6 @@
|
|
|
|
|
using System.ComponentModel.DataAnnotations;
|
|
|
|
|
using API.Context;
|
|
|
|
|
using API.Validation;
|
|
|
|
|
using AppContext.Entities;
|
|
|
|
|
using Microsoft.AspNetCore.Authorization;
|
|
|
|
|
using Microsoft.AspNetCore.Mvc;
|
|
|
|
|
using Model;
|
|
|
|
@ -11,13 +10,15 @@ namespace API.Controllers;
|
|
|
|
|
|
|
|
|
|
[ApiController]
|
|
|
|
|
[Authorize]
|
|
|
|
|
public class TeamsController(ITeamService service, ITacticService tactics,IContextAccessor accessor) : ControllerBase
|
|
|
|
|
public class TeamsController(ITeamService service, ITacticService tactics, IContextAccessor accessor) : ControllerBase
|
|
|
|
|
{
|
|
|
|
|
public record CreateTeamRequest(
|
|
|
|
|
[Name] string Name,
|
|
|
|
|
[Url] string Picture,
|
|
|
|
|
[RegularExpression("^#[0-9A-Fa-f]{6}$")] string FirstColor,
|
|
|
|
|
[RegularExpression("^#[0-9A-Fa-f]{6}$")] string SecondColor
|
|
|
|
|
[RegularExpression("^#[0-9A-Fa-f]{6}$")]
|
|
|
|
|
string FirstColor,
|
|
|
|
|
[RegularExpression("^#[0-9A-Fa-f]{6}$")]
|
|
|
|
|
string SecondColor
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
[HttpPost("/teams")]
|
|
|
|
@ -29,6 +30,13 @@ public class TeamsController(ITeamService service, ITacticService tactics,IConte
|
|
|
|
|
return Ok(team);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[HttpGet("/teams/{id:int}")]
|
|
|
|
|
public async Task<IActionResult> GetTeam(int id)
|
|
|
|
|
{
|
|
|
|
|
var team = await service.GetTeam(id);
|
|
|
|
|
return team == null ? NotFound() : Ok(team);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[HttpGet("/teams/{teamId:int}/members")]
|
|
|
|
|
public async Task<IActionResult> GetMembersOf(int teamId)
|
|
|
|
|
{
|
|
|
|
@ -59,7 +67,7 @@ public class TeamsController(ITeamService service, ITacticService tactics,IConte
|
|
|
|
|
{
|
|
|
|
|
throw new Exception($"Unable to convert string input '{req.Role}' to a role enum variant.");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var accessibility =
|
|
|
|
|
await service.EnsureAccessibility(accessor.CurrentUserId(HttpContext), teamId, MemberRole.Coach);
|
|
|
|
|
|
|
|
|
@ -111,8 +119,6 @@ public class TeamsController(ITeamService service, ITacticService tactics,IConte
|
|
|
|
|
default: //unreachable
|
|
|
|
|
return Problem();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[HttpDelete("/team/{teamId:int}/members/{userId:int}")]
|
|
|
|
@ -135,12 +141,12 @@ public class TeamsController(ITeamService service, ITacticService tactics,IConte
|
|
|
|
|
return Problem();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public record ShareTacticToTeamRequest(
|
|
|
|
|
int TacticId,
|
|
|
|
|
int TeamId
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
[HttpPost("/team/share-tactic")]
|
|
|
|
|
public async Task<IActionResult> ShareTactic([FromBody] ShareTacticToTeamRequest sharedTactic)
|
|
|
|
|
{
|
|
|
|
@ -149,7 +155,7 @@ public class TeamsController(ITeamService service, ITacticService tactics,IConte
|
|
|
|
|
|
|
|
|
|
return success ? Ok() : BadRequest();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
[HttpDelete("/tactics/shared/{tacticId:int}/team/{teamId:int}")]
|
|
|
|
|
public async Task<IActionResult> UnshareTactic(int tacticId, int teamId)
|
|
|
|
|
{
|
|
|
|
@ -160,6 +166,7 @@ public class TeamsController(ITeamService service, ITacticService tactics,IConte
|
|
|
|
|
{
|
|
|
|
|
return NotFound();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (currentUserId != tactic.OwnerId)
|
|
|
|
|
{
|
|
|
|
|
return Unauthorized();
|
|
|
|
@ -168,12 +175,12 @@ public class TeamsController(ITeamService service, ITacticService tactics,IConte
|
|
|
|
|
var success = await tactics.UnshareTactic(tacticId, null, teamId);
|
|
|
|
|
return success ? Ok() : NotFound();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
[HttpGet("/tactics/shared/team/{teamId:int}")]
|
|
|
|
|
public async Task<IActionResult> GetSharedTacticsToTeam(int teamId)
|
|
|
|
|
{
|
|
|
|
|
var currentUserId = accessor.CurrentUserId(HttpContext);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (!await service.IsUserInTeam(currentUserId, teamId))
|
|
|
|
|
{
|
|
|
|
|
return Unauthorized();
|
|
|
|
|