add getTeam route
continuous-integration/drone/push Build is passing Details

master
maxime 1 year ago
parent e81b7dd24d
commit cfddcb9f81

@ -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)
{
@ -111,8 +119,6 @@ public class TeamsController(ITeamService service, ITacticService tactics,IConte
default: //unreachable
return Problem();
}
}
[HttpDelete("/team/{teamId:int}/members/{userId:int}")]
@ -160,6 +166,7 @@ public class TeamsController(ITeamService service, ITacticService tactics,IConte
{
return NotFound();
}
if (currentUserId != tactic.OwnerId)
{
return Unauthorized();

@ -52,6 +52,12 @@ public class DbTeamService(AppContext.AppContext context) : ITeamService
return entity.ToModel();
}
public async Task<Team?> GetTeam(int id)
{
var entity = await context.Teams.FirstOrDefaultAsync(t => t.Id == id);
return entity?.ToModel();
}
public async Task RemoveTeams(params int[] teams)
{
await context.Teams

@ -27,6 +27,8 @@ public interface ITeamService
/// </summary>
Task<Team> AddTeam(string name, string picture, string firstColor, string secondColor);
Task<Team?> GetTeam(int id);
/// <summary>
/// Removes one or more teams.
/// </summary>

Loading…
Cancel
Save