2024-11-15 09:22:30 +00:00
|
|
|
|
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;
|
2024-11-20 09:15:21 +00:00
|
|
|
|
private readonly UseCaseAPI _useCaseAPI;
|
2024-11-15 09:22:30 +00:00
|
|
|
|
|
2024-11-20 09:15:21 +00:00
|
|
|
|
public AdminPanelController(GroupUseCase groupUseCase, UserUseCase userUseCase, UseCaseGeneratePresence presenceUseCase, UseCaseAPI useCaseAPI)
|
2024-11-15 09:22:30 +00:00
|
|
|
|
{
|
|
|
|
|
_groupUseCase = groupUseCase;
|
|
|
|
|
_userUseCase = userUseCase;
|
|
|
|
|
_presenceUseCase = presenceUseCase;
|
2024-11-20 09:15:21 +00:00
|
|
|
|
_useCaseAPI = useCaseAPI;
|
2024-11-15 09:22:30 +00:00
|
|
|
|
}
|
|
|
|
|
|
2024-11-18 12:42:33 +00:00
|
|
|
|
[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")]
|
2024-11-20 09:15:21 +00:00
|
|
|
|
public ActionResult<List<GroupWithStudentsDto>> GetAllGroupsWithUsers()
|
2024-11-18 12:42:33 +00:00
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
// Получаем группы с пользователями
|
2024-11-20 09:15:21 +00:00
|
|
|
|
var groupsWithUsers = _groupUseCase.GetAllGroupWithStident().Select(group => new GroupWithStudentsDto
|
2024-11-18 12:42:33 +00:00
|
|
|
|
{
|
|
|
|
|
GroupName = group.Name, // Название группы
|
|
|
|
|
Students = group.Users.Select(u => u.FIO).ToList() // Список студентов
|
|
|
|
|
}).ToList();
|
|
|
|
|
|
|
|
|
|
return Ok(groupsWithUsers); // Возвращаем результат
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
// Логируем ошибку и возвращаем ошибку
|
|
|
|
|
return BadRequest(new { message = ex.Message });
|
|
|
|
|
}
|
|
|
|
|
}
|
2024-11-15 09:22:30 +00:00
|
|
|
|
|
2024-11-20 09:15:21 +00:00
|
|
|
|
[HttpDelete("presence/clear")]
|
|
|
|
|
public ActionResult ClearPresence()
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
_presenceUseCase.ClearAllPresence();
|
|
|
|
|
return Ok(new { message = "Все записи присутствия успешно удалены." });
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
return BadRequest(new { message = ex.Message });
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[HttpDelete("groups/{groupId}")]
|
|
|
|
|
public ActionResult RemoveGroupById(int groupId)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
_groupUseCase.RemoveGroupById(groupId);
|
|
|
|
|
return Ok(new { message = "Группа успешно удалена." });
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
return BadRequest(new { message = ex.Message });
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[HttpDelete("users/{userGuid}")]
|
|
|
|
|
public ActionResult RemoveUserByGuid(Guid userGuid)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
_userUseCase.RemoveUserByGuid(userGuid);
|
|
|
|
|
return Ok(new { message = "Пользователь удален." });
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
return BadRequest (new { message = ex.Message });
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[HttpPost("groups/add")]
|
|
|
|
|
public IActionResult AddGroupWithStudents([FromBody] GroupWithStudentsDto groupDto)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
_useCaseAPI.AddGroupWithStudents(groupDto);
|
|
|
|
|
return Ok(new { message = "Группа успешно добавлена." });
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
return BadRequest(new { message = ex.Message });
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-11-15 09:22:30 +00:00
|
|
|
|
}
|