|
|
@ -1,7 +1,6 @@
|
|
|
|
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;
|
|
|
@ -11,13 +10,15 @@ namespace API.Controllers;
|
|
|
|
|
|
|
|
|
|
|
|
[ApiController]
|
|
|
|
[ApiController]
|
|
|
|
[Authorize]
|
|
|
|
[Authorize]
|
|
|
|
public class TeamsController(ITeamService service, ITacticService tactics,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,
|
|
|
|
[Url] string Picture,
|
|
|
|
[Url] string Picture,
|
|
|
|
[RegularExpression("^#[0-9A-Fa-f]{6}$")] string FirstColor,
|
|
|
|
[RegularExpression("^#[0-9A-Fa-f]{6}$")]
|
|
|
|
[RegularExpression("^#[0-9A-Fa-f]{6}$")] string SecondColor
|
|
|
|
string FirstColor,
|
|
|
|
|
|
|
|
[RegularExpression("^#[0-9A-Fa-f]{6}$")]
|
|
|
|
|
|
|
|
string SecondColor
|
|
|
|
);
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
[HttpPost("/teams")]
|
|
|
|
[HttpPost("/teams")]
|
|
|
@ -29,6 +30,13 @@ public class TeamsController(ITeamService service, ITacticService tactics,IConte
|
|
|
|
return Ok(team);
|
|
|
|
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")]
|
|
|
|
[HttpGet("/teams/{teamId:int}/members")]
|
|
|
|
public async Task<IActionResult> GetMembersOf(int teamId)
|
|
|
|
public async Task<IActionResult> GetMembersOf(int teamId)
|
|
|
|
{
|
|
|
|
{
|
|
|
@ -111,8 +119,6 @@ public class TeamsController(ITeamService service, ITacticService tactics,IConte
|
|
|
|
default: //unreachable
|
|
|
|
default: //unreachable
|
|
|
|
return Problem();
|
|
|
|
return Problem();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
[HttpDelete("/team/{teamId:int}/members/{userId:int}")]
|
|
|
|
[HttpDelete("/team/{teamId:int}/members/{userId:int}")]
|
|
|
@ -160,6 +166,7 @@ public class TeamsController(ITeamService service, ITacticService tactics,IConte
|
|
|
|
{
|
|
|
|
{
|
|
|
|
return NotFound();
|
|
|
|
return NotFound();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (currentUserId != tactic.OwnerId)
|
|
|
|
if (currentUserId != tactic.OwnerId)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
return Unauthorized();
|
|
|
|
return Unauthorized();
|
|
|
|