presence/Presence.API/Controllers/PresenceController.cs
2024-12-05 10:31:49 +03:00

43 lines
1.3 KiB
C#

using domain.UseCase;
using Microsoft.AspNetCore.Mvc;
using Presence.API.Response;
using System;
using System.Linq;
namespace Presence.API.Controllers
{
[ApiController]
[Route("api/[controller]")]
public class PresenceController : ControllerBase
{
private readonly IPresenceUseCase _presenceUseCase;
public PresenceController(IPresenceUseCase presenceUseCase)
{
_presenceUseCase = presenceUseCase;
}
[HttpGet("/presence/{groupId}")]
public ActionResult<PresenceResponse> GetPresence(
int groupId,
[FromQuery] int? subject,
[FromQuery] DateTime? date,
[FromQuery] int? student)
{
var presences = _presenceUseCase.GetPresence(groupId, subject, date, student)
.Select(p => new PresenceResponse
{
Id = p.Id,
StudentId = p.StudentId,
StudentName = $"{p.Student.LastName} {p.Student.FirstName} {p.Student.Patronymic}",
SubjectId = p.SubjectId,
SubjectName = p.Subject.Name,
Date = p.Date
})
.ToList();
return Ok(presences);
}
}
}