presence/presence_api/Controllers/PresenceController.cs

44 lines
1.3 KiB
C#
Raw Normal View History

2024-11-11 07:01:04 +00:00
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<bool> 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<PresenceResponce> 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);
}
}