2024-12-19 17:36:57 +00:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
using domain.Models.ResponseModels;
|
|
|
|
|
using Microsoft.AspNetCore.Mvc;
|
|
|
|
|
using presence.domain.Models;
|
|
|
|
|
using presence.domain.UseCase;
|
|
|
|
|
|
|
|
|
|
namespace presence_api.Controllers.PresenceController;
|
|
|
|
|
|
|
|
|
|
[ApiController]
|
|
|
|
|
[Route("api/[controller]")]
|
|
|
|
|
public class PresenceController : ControllerBase
|
|
|
|
|
{
|
|
|
|
|
private readonly PresenceUseCase _presenceUseCase;
|
|
|
|
|
|
|
|
|
|
public PresenceController(PresenceUseCase presenceUseCase)
|
|
|
|
|
{
|
|
|
|
|
_presenceUseCase = presenceUseCase;
|
|
|
|
|
}
|
|
|
|
|
|
2024-12-23 09:12:26 +00:00
|
|
|
|
[HttpPost("~/IsAttendence")] //Добавление информации о посещаемости
|
|
|
|
|
public ActionResult<PresenceResponse> UpdateAttendance([FromQuery] int FirstClass,
|
|
|
|
|
[FromQuery] int LastClass, [FromQuery] string Data,
|
|
|
|
|
[FromQuery] int UserId)
|
2024-12-19 17:36:57 +00:00
|
|
|
|
{
|
2024-12-23 09:12:26 +00:00
|
|
|
|
DateOnly data;
|
|
|
|
|
bool isParsed = DateOnly.TryParse(Data, out data);
|
2024-12-19 17:36:57 +00:00
|
|
|
|
if (!isParsed)
|
|
|
|
|
{
|
2024-12-23 09:12:26 +00:00
|
|
|
|
return BadRequest("Неверный формат");
|
2024-12-19 17:36:57 +00:00
|
|
|
|
}
|
2024-12-23 09:12:26 +00:00
|
|
|
|
return Ok(_presenceUseCase.UncheckAttendence(FirstClass, LastClass, data, UserId));
|
2024-12-19 17:36:57 +00:00
|
|
|
|
}
|
|
|
|
|
|
2024-12-23 09:12:26 +00:00
|
|
|
|
[HttpPost("~/AddPresence")] //Добавление записи о присутствии
|
2024-12-19 17:36:57 +00:00
|
|
|
|
public ActionResult<IEnumerable<Presence>> PostPresence([FromQuery] int GroupId,
|
|
|
|
|
[FromQuery] string StartData, [FromQuery] string EndData, [FromQuery] int UserId)
|
|
|
|
|
{
|
|
|
|
|
return Ok(_presenceUseCase.AddPresenceByDate(StartData, EndData, GroupId));
|
|
|
|
|
}
|
|
|
|
|
|
2024-12-23 09:12:26 +00:00
|
|
|
|
[HttpGet] //Получение информации о присутствии
|
|
|
|
|
public ActionResult<IEnumerable<Presence>> GetPresence(
|
|
|
|
|
[FromQuery] int groupId,
|
|
|
|
|
[FromQuery] string startDataString,
|
|
|
|
|
[FromQuery] string endDataString,
|
|
|
|
|
[FromQuery] int userId)
|
2024-12-19 17:36:57 +00:00
|
|
|
|
{
|
2024-12-23 09:12:26 +00:00
|
|
|
|
// Объявление переменных для хранения преобразованных дат
|
|
|
|
|
DateOnly startData;
|
|
|
|
|
DateOnly endData;
|
|
|
|
|
|
|
|
|
|
// Попытка преобразования строковых дат в DateOnly
|
|
|
|
|
bool isStartParsed = DateOnly.TryParse(startDataString, out startData);
|
|
|
|
|
bool isEndParsed = DateOnly.TryParse(endDataString, out endData);
|
|
|
|
|
|
|
|
|
|
// Проверка на корректность формата даты начала
|
|
|
|
|
if (!isStartParsed)
|
|
|
|
|
{
|
|
|
|
|
return BadRequest("Неверный формат даты начала");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Проверка на корректность формата даты конца
|
|
|
|
|
if (!isEndParsed)
|
|
|
|
|
{
|
|
|
|
|
return BadRequest("Неверный формат даты конца");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Возвращает список присутствия
|
|
|
|
|
var presenceList = _presenceUseCase.GetPresence(groupId, startData, endData, userId);
|
|
|
|
|
return Ok(presenceList);
|
2024-12-19 17:36:57 +00:00
|
|
|
|
}
|
|
|
|
|
|
2024-12-23 09:12:26 +00:00
|
|
|
|
[HttpDelete("~/DeleteByUser")] //Удаление записи о присутствии по пользователю
|
2024-12-19 17:36:57 +00:00
|
|
|
|
public ActionResult<IEnumerable<PresenceResponse>> DeletePresenceByUser([FromQuery] int UserId)
|
|
|
|
|
{
|
|
|
|
|
return Ok(_presenceUseCase.DeletePresenceByUser(UserId));
|
|
|
|
|
}
|
|
|
|
|
|
2024-12-23 09:12:26 +00:00
|
|
|
|
[HttpDelete("~/DeleteByGroup")]//Удаление записи о присутствии по группе
|
|
|
|
|
public ActionResult<IEnumerable<PresenceResponse>> DeletePresenceByGroup([FromQuery] int GroupId)
|
|
|
|
|
{
|
|
|
|
|
return Ok(_presenceUseCase.DeletePresenceByGroup(GroupId));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[HttpDelete("~/DeleteByDate")] //Удаление записей о присутствии по дате
|
|
|
|
|
public ActionResult<IEnumerable<PresenceResponse>> DeletePresenceByDate(
|
|
|
|
|
[FromQuery] string StartData,
|
|
|
|
|
[FromQuery] string EndData)
|
2024-12-19 17:36:57 +00:00
|
|
|
|
{
|
|
|
|
|
DateOnly startData;
|
|
|
|
|
DateOnly endData;
|
2024-12-23 09:12:26 +00:00
|
|
|
|
|
|
|
|
|
// Попытка преобразования строковых дат в DateOnly
|
2024-12-19 17:36:57 +00:00
|
|
|
|
bool isParsed = DateOnly.TryParse(StartData, out startData);
|
|
|
|
|
bool isParse = DateOnly.TryParse(EndData, out endData);
|
2024-12-23 09:12:26 +00:00
|
|
|
|
|
|
|
|
|
// Проверка на корректность формата даты начала
|
2024-12-19 17:36:57 +00:00
|
|
|
|
if (!isParsed)
|
|
|
|
|
{
|
|
|
|
|
return BadRequest("Неверный формат даты начала.");
|
|
|
|
|
}
|
2024-12-23 09:12:26 +00:00
|
|
|
|
// Проверка на корректность формата даты конца
|
2024-12-19 17:36:57 +00:00
|
|
|
|
if (!isParse)
|
|
|
|
|
{
|
|
|
|
|
return BadRequest("Неверный формат даты конца.");
|
|
|
|
|
}
|
2024-12-23 09:12:26 +00:00
|
|
|
|
|
|
|
|
|
// Возвращает результат удаления
|
2024-12-19 17:36:57 +00:00
|
|
|
|
return Ok(_presenceUseCase.DeletePresenceByDate(startData, endData));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|