presence/presence_api/Controllers/AdminPanelController.cs
2024-11-18 15:42:33 +03:00

70 lines
2.1 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using domain.Models;
using domain.UseCase;
using Microsoft.AspNetCore.Mvc;
namespace presence_api.Controllers;
[ApiController]
[Route("api/admin")]
public class AdminPanelController : ControllerBase
{
private readonly GroupUseCase _groupUseCase;
private readonly UserUseCase _userUseCase;
private readonly UseCaseGeneratePresence _presenceUseCase;
public AdminPanelController(GroupUseCase groupUseCase, UserUseCase userUseCase, UseCaseGeneratePresence presenceUseCase)
{
_groupUseCase = groupUseCase;
_userUseCase = userUseCase;
_presenceUseCase = presenceUseCase;
}
[HttpGet("student/{userGuid}")]
public ActionResult GetStudentInfo(Guid userGuid)
{
// Получаем информацию о студенте
var user = _userUseCase.GetUserInfo(userGuid); // Используем UserUseCase для получения данных о студенте
if (user == null)
{
return NotFound("Студент не найден");
}
// Формируем результат
var result = new
{
FIO = user.FIO,
Guid = user.Guid,
GroupName = user.Group?.Name ?? "Не указана",
};
return Ok(result);
}
[HttpGet("groups")]
public ActionResult<List<GroupWithUsersDto>> GetAllGroupsWithUsers()
{
try
{
// Получаем группы с пользователями
var groupsWithUsers = _groupUseCase.GetAllGroupWithStident().Select(group => new GroupWithUsersDto
{
GroupName = group.Name, // Название группы
Students = group.Users.Select(u => u.FIO).ToList() // Список студентов
}).ToList();
return Ok(groupsWithUsers); // Возвращаем результат
}
catch (Exception ex)
{
// Логируем ошибку и возвращаем ошибку
return BadRequest(new { message = ex.Message });
}
}
}