semesterWork/Presence.Api/Controllers/GroupController.cs

46 lines
1.3 KiB
C#

using domain.Service;
using domain.UseCase;
using domain.Request;
using domain.Service;
using Microsoft.AspNetCore.Mvc;
using Presence.Api.Response;
namespace Presence.Api.Controllers
{
[ApiController]
[Route("[controller]/api")]
public class GroupController: ControllerBase
{
private readonly IGroupUseCase _groupService;
public GroupController(IGroupUseCase groupService)
{
_groupService = groupService;
}
[HttpGet("/group")]
public async Task<ActionResult<GroupResponse>> GetAllGroups()
{
var result = _groupService
.GetGroupsWithStudents();
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(new GroupResponse());
}
[HttpPost("/admin/{groupId}/students")]
public void AddGroup(int groupId, [FromBody] AddGroupRequest addGroupRequest)
{
Console.WriteLine(groupId);
_groupService.AddGroup(addGroupRequest);
}
}
}