using Demo.Domain.Models; using Demo.Domain.UseCase; using Microsoft.AspNetCore.Mvc; using Npgsql.TypeMapping; namespace presence_api.Controllers; [ApiController] [Route("api/[controller]")] public class PresenceController: ControllerBase{ private readonly PresenceUseCase _presenceUseCase; public PresenceController(PresenceUseCase presenceUseCase){ _presenceUseCase = presenceUseCase; } [HttpPost] public ActionResult GeneratePresence(int firstLesson, int lastLesson, int groupID, string date) { if (!DateOnly.TryParse(date, out var parseDate)) { return BadRequest("Invalid date format"); } var isGenerate = _presenceUseCase.GeneratePresence(firstLesson, lastLesson, groupID, parseDate); return Ok(true); } [HttpGet] public ActionResult GetPresence(int groupID, string startDate, string endDate) { if (!DateOnly.TryParse(startDate, out var parsedStartDate) || !DateOnly.TryParse(endDate, out var parsedEndDate)) { return BadRequest("Invalid date format"); } var presence = _presenceUseCase.GetPresenceByDataRangeAndGroup(groupID, parsedStartDate, parsedEndDate); return Ok(presence); } }