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

master
Maxime BATISTA 8 months ago
parent e81b7dd24d
commit cfddcb9f81

@ -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();

@ -52,6 +52,12 @@ public class DbTeamService(AppContext.AppContext context) : ITeamService
return entity.ToModel(); 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) public async Task RemoveTeams(params int[] teams)
{ {
await context.Teams await context.Teams

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

Loading…
Cancel
Save