presence_sample_v2/Presence.Api/Controllers/GroupController.cs
2024-11-25 13:47:17 +03:00

38 lines
1.1 KiB
C#

using domain.Service;
using domain.UseCase;
using Microsoft.AspNetCore.Mvc;
using Presence.Api.Response;
namespace Presence.Api.Controllers
{
[ApiController]
[Route("api/[contrtoller]")]
public class GroupController: ControllerBase
{
private readonly IGroupUseCase _groupService;
public GroupController(IGroupUseCase groupService) {
_groupService = groupService;
}
[HttpGet("/group")]
public async Task<ActionResult<GroupResponse>> GetAllGroups() {
var result = await _groupService
.GetGroupsWithStudentsAsync();
var response = result
.Select(group => new GroupResponse {
Id = group.Id,
Name = group.Name,
Users = group.Users?.Select(
user => new UserResponse {
Guid = user.Guid,
Name = user.Name,
}).ToList()
}).ToList();
return Ok(result);
}
}
}