presence_new/presence_api/Controllers/AdminController/AdminController.cs
2024-11-19 15:41:31 +03:00

70 lines
2.1 KiB
C#

using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using domain.Models.ResponseModels;
using domain.UseCase;
using Microsoft.AspNetCore.Mvc;
using presence.domain.Models;
using presence.domain.UseCase;
namespace presence_api.Controllers.UserController;
[ApiController]
[Route("api/[admin]")]
public class AdminController: ControllerBase
{
private readonly AdminUseCase _adminUseCase;
public AdminController(AdminUseCase adminUseCase)
{
_adminUseCase = adminUseCase;
}
[HttpPost("~/AddStudents")]
public ActionResult<String> AddStudents([FromQuery] string GroupName, [FromQuery] List<string> students)
{
return _adminUseCase.AddStudents(GroupName, students) ? "Данные группы и студентов добавлены": "Данные не добавлены";
}
[HttpDelete("~/DeleteUserFromGroup")]
public ActionResult<string> DeleteUserFromGroup([FromQuery] int userId, [FromQuery] int groupId)
{
return _adminUseCase.DeleteUserFromGroup(userId, groupId) ? "Юзер удален": "Юзер не удален";
}
[HttpDelete("~/DeleteGroup")]
public ActionResult<String> DeleteGroup([FromQuery] int groupId)
{
return _adminUseCase.DeleteGroup(groupId) ? "Группа удалена" : "Группа не удалена";
}
// [HttpDelete("~/ClearPresence")]
// public ActionResult ClearPresence()
// {
// }
[HttpGet("~/GetAllGroupsWithStudents")]
public ActionResult<IEnumerable<GroupResponse>> GetAllGroupsWithStudents()
{
return Ok(_adminUseCase.GetAllGroupsWithStudents());
}
[HttpGet("~/GetStudentInfo")]
public ActionResult<UserResponse?> GetStudentInfo([FromQuery] int userId)
{
if (userId <= 0)
{
return BadRequest("Некорректный идентификатор пользователя.");
}
var studentInfo = _adminUseCase.GetStudentInfo(userId);
if (studentInfo == null)
{
return NotFound("Студент не найден.");
}
return Ok(studentInfo);
}
}