using Demo.Domain.Models; using Demo.Domain.UseCase; using Microsoft.AspNetCore.Mvc; namespace presence_api.Controllers; [ApiController] [Route("api/[controller]")] public class PresenceController: ControllerBase{ private readonly PresenceUseCase _presenceUseCase; public PresenceController(PresenceUseCase presenceUseCase) { _presenceUseCase = presenceUseCase; } //get [HttpGet] public ActionResult GetPresence(int groupID, string start = null, string end = null, Guid userGuid = default) { PresenceGet? presences = null; if (start != null && end != null) { DateOnly.TryParse(start, out DateOnly start1); DateOnly.TryParse(end, out DateOnly end1); presences = _presenceUseCase.GetPresencebyAll(groupID, start1, end1, userGuid); } else { presences = _presenceUseCase.GetPresencebyAll(groupID, null, null, userGuid); } return Ok(presences); } //post [HttpPost("generate")] public ActionResult GeneratePresence([FromBody] PresencePost request) { if (request == null){ return BadRequest("buba"); } DateOnly.TryParse(request.date, out DateOnly date); var isGenerated = _presenceUseCase.GeneratePresence(request.firstLesson, request.lastLesson, request.groupID, date); return Ok(isGenerated); } //delete [HttpDelete("gruop")] public ActionResult DeletePresenceByGroup(int groupID) { var isDeleted = _presenceUseCase.DeletePresenceByGroup(groupID); return isDeleted; } [HttpDelete("user")] public ActionResult DeletePresenceByUser(Guid userGuid) { var isDeleted = _presenceUseCase.DeletePresenceByUser(userGuid); return isDeleted; } [HttpDelete("range")] public ActionResult DeletePresenceByRange([FromBody] PresenceDeleteByRange request) { DateOnly.TryParse(request.start, out DateOnly start); DateOnly.TryParse(request.end, out DateOnly end); var isDeleted = _presenceUseCase.DeletePresenceByRange(start, end); return isDeleted; } //update [HttpPatch] public ActionResult UpdatePresence([FromBody] PresenceUpdate request) { DateOnly.TryParse(request.date, out DateOnly date); var isDeleted = _presenceUseCase.IsAttedance(request.firstLesson, request.lastLesson, date, request.UserGuid); return isDeleted; } }