presence/Presence.API/Controllers/PresenceController.cs

43 lines
1.3 KiB
C#
Raw Normal View History

2024-12-05 07:31:49 +00:00
using domain.UseCase;
using Microsoft.AspNetCore.Mvc;
using Presence.API.Response;
using System;
using System.Linq;
2024-12-04 12:21:15 +00:00
namespace Presence.API.Controllers
{
[ApiController]
[Route("api/[controller]")]
public class PresenceController : ControllerBase
{
2024-12-05 07:31:49 +00:00
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);
}
2024-12-04 12:21:15 +00:00
}
}