parent
8b22c4ae0c
commit
5eaa35ba8f
@ -0,0 +1,67 @@
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Model;
|
||||
using Services;
|
||||
|
||||
namespace API.Controllers;
|
||||
|
||||
[ApiController]
|
||||
public class TeamsController(ITeamService service) : ControllerBase
|
||||
{
|
||||
public record CountTeamsResponse(int Value);
|
||||
|
||||
|
||||
[HttpGet("/admin/teams/count")]
|
||||
public async Task<CountTeamsResponse> CountTeams()
|
||||
{
|
||||
return new CountTeamsResponse(await service.CountTeams());
|
||||
}
|
||||
|
||||
// [HttpGet("/admin/users/count")]
|
||||
// public async Task<CountUsersResponse> CountUsers()
|
||||
// {
|
||||
// return new CountUsersResponse(await service.UsersCount());
|
||||
// }
|
||||
|
||||
[HttpGet("/admin/teams")]
|
||||
public async Task<IEnumerable<Team>> ListTeams(
|
||||
[Range(0, int.MaxValue, ErrorMessage = "Only positive number allowed")]
|
||||
int start,
|
||||
[Range(0, int.MaxValue, ErrorMessage = "Only positive number allowed")]
|
||||
int n
|
||||
)
|
||||
{
|
||||
var result = await service.ListTeams();
|
||||
|
||||
return result.Skip(start).Take(n);
|
||||
}
|
||||
|
||||
public record AddTeamRequest(string Name, string Picture, string FirstColor, string SecondColor);
|
||||
|
||||
[HttpPost("/admin/teams")]
|
||||
public async Task<IActionResult> AddTeam([FromBody] AddTeamRequest req)
|
||||
{
|
||||
var team = await service.AddTeam(req.Name, req.Picture, req.FirstColor, req.SecondColor);
|
||||
|
||||
return Ok(team);
|
||||
}
|
||||
|
||||
public record UpdateTeamRequest(int Id, string Name, string Picture, string MainColor, string SecondaryColor);
|
||||
|
||||
[HttpPut("/admin/teams/{teamId:int}")]
|
||||
public async Task<IActionResult> UpdateTeam([FromBody] UpdateTeamRequest req)
|
||||
{
|
||||
await service.UpdateTeam(new Team(req.Id, req.Name, req.Picture, req.MainColor, req.SecondaryColor));
|
||||
|
||||
return Ok();
|
||||
}
|
||||
|
||||
public record DeleteTeamsRequest(int[] Teams);
|
||||
|
||||
[HttpPost("/admin/teams/remove-all")]
|
||||
public async Task<IActionResult> DeleteTeams([FromBody] DeleteTeamsRequest req)
|
||||
{
|
||||
await service.RemoveTeams(req.Teams);
|
||||
return Ok();
|
||||
}
|
||||
}
|
Loading…
Reference in new issue