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; } [HttpGet] public ActionResult> GetPresence([FromQuery] int GroupId, [FromQuery] string StartData, [FromQuery] string EndData, [FromQuery] int UserId) { DateOnly startData; DateOnly endData; bool isParsed = DateOnly.TryParse(StartData, out startData); bool isParse = DateOnly.TryParse(EndData, out endData); if (!isParsed) { return BadRequest("Неверный формат даты начала."); } if (!isParse) { return BadRequest("Неверный формат даты конца."); } return Ok(_presenceUseCase.GetPresence(GroupId, startData, endData, UserId)); } [HttpPost("~/AddPresence")] public ActionResult> PostPresence([FromQuery] int GroupId, [FromQuery] string StartData, [FromQuery] string EndData, [FromQuery] int UserId) { return Ok(_presenceUseCase.AddPresenceByDate(StartData, EndData, GroupId)); } [HttpDelete("~/DeleteByGroup")] public ActionResult> DeletePresenceByGroup([FromQuery] int GroupId) { return Ok(_presenceUseCase.DeletePresenceByGroup(GroupId)); } [HttpDelete("~/DeleteByUser")] public ActionResult> DeletePresenceByUser([FromQuery] int UserId) { return Ok(_presenceUseCase.DeletePresenceByUser(UserId)); } [HttpDelete("~/DeleteByDate")] public ActionResult> DeletePresenceByDate([FromQuery] string StartData, [FromQuery] string EndData) { DateOnly startData; DateOnly endData; bool isParsed = DateOnly.TryParse(StartData, out startData); bool isParse = DateOnly.TryParse(EndData, out endData); if (!isParsed) { return BadRequest("Неверный формат даты начала."); } if (!isParse) { return BadRequest("Неверный формат даты конца."); } return Ok(_presenceUseCase.DeletePresenceByDate(startData, endData)); } [HttpPost("~/IsAttendence")] public ActionResult UpdateAttendance([FromQuery] int FirstClass, [FromQuery] int LastClass, [FromQuery] string Data, [FromQuery] int UserId) { DateOnly data; bool isParsed = DateOnly.TryParse(Data, out data); if (!isParsed) { return BadRequest("Неверный формат даты."); } return Ok(_presenceUseCase.UncheckAttendence(FirstClass, LastClass, data, UserId)); } }