|
|
|
@ -1,5 +1,6 @@
|
|
|
|
|
using System.ComponentModel.DataAnnotations;
|
|
|
|
|
using API.Context;
|
|
|
|
|
using API.DTO;
|
|
|
|
|
using API.Validation;
|
|
|
|
|
using Microsoft.AspNetCore.Authorization;
|
|
|
|
|
using Microsoft.AspNetCore.Mvc;
|
|
|
|
@ -10,7 +11,12 @@ namespace API.Controllers;
|
|
|
|
|
|
|
|
|
|
[ApiController]
|
|
|
|
|
[Authorize]
|
|
|
|
|
public class TeamsController(ITeamService service, ITacticService tactics, IContextAccessor accessor) : ControllerBase
|
|
|
|
|
public class TeamsController(
|
|
|
|
|
ITeamService service,
|
|
|
|
|
ITacticService tactics,
|
|
|
|
|
IUserService users,
|
|
|
|
|
IContextAccessor accessor
|
|
|
|
|
) : ControllerBase
|
|
|
|
|
{
|
|
|
|
|
public record CreateTeamRequest(
|
|
|
|
|
[Name] string Name,
|
|
|
|
@ -37,6 +43,7 @@ public class TeamsController(ITeamService service, ITacticService tactics, ICont
|
|
|
|
|
return team == null ? NotFound() : Ok(team);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
[HttpGet("/teams/{teamId:int}/members")]
|
|
|
|
|
public async Task<IActionResult> GetMembersOf(int teamId)
|
|
|
|
|
{
|
|
|
|
@ -46,7 +53,16 @@ public class TeamsController(ITeamService service, ITacticService tactics, ICont
|
|
|
|
|
switch (accessibility)
|
|
|
|
|
{
|
|
|
|
|
case ITeamService.TeamAccessibility.Authorized:
|
|
|
|
|
return Ok(await service.GetMembersOf(teamId));
|
|
|
|
|
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);
|
|
|
|
|
case ITeamService.TeamAccessibility.NotFound:
|
|
|
|
|
case ITeamService.TeamAccessibility.Unauthorized:
|
|
|
|
|
return NotFound();
|
|
|
|
|