|
|
|
@ -1,7 +1,7 @@
|
|
|
|
|
using System.ComponentModel.DataAnnotations;
|
|
|
|
|
using API.Context;
|
|
|
|
|
using API.DTO;
|
|
|
|
|
using API.Validation;
|
|
|
|
|
using AppContext.Entities;
|
|
|
|
|
using Microsoft.AspNetCore.Authorization;
|
|
|
|
|
using Microsoft.AspNetCore.Mvc;
|
|
|
|
|
using Model;
|
|
|
|
@ -11,20 +11,13 @@ namespace API.Controllers;
|
|
|
|
|
|
|
|
|
|
[ApiController]
|
|
|
|
|
[Authorize]
|
|
|
|
|
public class TeamsController(
|
|
|
|
|
ITeamService service,
|
|
|
|
|
ITacticService tactics,
|
|
|
|
|
IUserService users,
|
|
|
|
|
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-F]{6}$")] string FirstColor,
|
|
|
|
|
[RegularExpression("^#[0-9A-F]{6}$")] string SecondColor
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
[HttpPost("/teams")]
|
|
|
|
@ -36,14 +29,6 @@ public class TeamsController(
|
|
|
|
|
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)
|
|
|
|
|
{
|
|
|
|
@ -53,16 +38,7 @@ public class TeamsController(
|
|
|
|
|
switch (accessibility)
|
|
|
|
|
{
|
|
|
|
|
case ITeamService.TeamAccessibility.Authorized:
|
|
|
|
|
var members = (await service.GetMembersOf(teamId)).ToList();
|
|
|
|
|
|
|
|
|
|
var membersDto = new List<MemberDto>();
|
|
|
|
|
|
|
|
|
|
foreach (var m in members)
|
|
|
|
|
{
|
|
|
|
|
membersDto.Add(new MemberDto((await users.GetUser(m.UserId))!, m.Role));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return Ok(membersDto);
|
|
|
|
|
return Ok(await service.GetMembersOf(teamId));
|
|
|
|
|
case ITeamService.TeamAccessibility.NotFound:
|
|
|
|
|
case ITeamService.TeamAccessibility.Unauthorized:
|
|
|
|
|
return NotFound();
|
|
|
|
@ -135,6 +111,8 @@ public class TeamsController(
|
|
|
|
|
default: //unreachable
|
|
|
|
|
return Problem();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[HttpDelete("/team/{teamId:int}/members/{userId:int}")]
|
|
|
|
@ -182,7 +160,6 @@ public class TeamsController(
|
|
|
|
|
{
|
|
|
|
|
return NotFound();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (currentUserId != tactic.OwnerId)
|
|
|
|
|
{
|
|
|
|
|
return Unauthorized();
|
|
|
|
|