pr1/presence/presence_api/Controllers/AdminController.cs

64 lines
2.2 KiB
C#
Raw Normal View History

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