50 lines
1.4 KiB
C#
50 lines
1.4 KiB
C#
using domain.Request;
|
|
using domain.UseCase;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
using Presence.API.Response;
|
|
|
|
namespace Presence.API.Controllers
|
|
{
|
|
[ApiController]
|
|
[Route("api/[controller]")]
|
|
public class GroupController : ControllerBase
|
|
{
|
|
private readonly IGroupUseCase _groupService;
|
|
|
|
public GroupController(IGroupUseCase groupService)
|
|
{
|
|
_groupService = groupService;
|
|
}
|
|
|
|
[HttpGet("/group")]
|
|
public ActionResult<GroupResponse> GetAllGroups()
|
|
{
|
|
var result = _groupService
|
|
.GetGroupsWithStudents()
|
|
.Select(group => new GroupResponse
|
|
{
|
|
Id = group.Id,
|
|
Name = group.Name,
|
|
Users = group.Users?.Select(
|
|
user => new UserResponse
|
|
{
|
|
Id = user.Id,
|
|
LastName = user.LastName,
|
|
FirstName = user.FirstName,
|
|
Patronymic = user.Patronymic
|
|
}).ToList()
|
|
}).ToList();
|
|
return Ok(result);
|
|
}
|
|
|
|
[HttpDelete("/group/{id}")]
|
|
public IActionResult DeleteGroup(int id)
|
|
{
|
|
RemoveGroupRequest removeGroupRequest = new() { GroupId = id };
|
|
_groupService.RemoveGroup(removeGroupRequest);
|
|
return NoContent();
|
|
}
|
|
|
|
}
|
|
}
|