2024-11-25 04:33:26 +00:00
|
|
|
|
using Microsoft.AspNetCore.Mvc;
|
|
|
|
|
using Demo.Data.RemoteData.RemoteDataBase.DAO;
|
|
|
|
|
using Demo.Domain.UseCase;
|
|
|
|
|
using Demo.Domain.Models;
|
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
|
|
|
|
|
namespace Demo.API.Controllers
|
|
|
|
|
{
|
|
|
|
|
[ApiController]
|
|
|
|
|
[Route("api/[controller]")]
|
|
|
|
|
public class PresenceController : ControllerBase
|
|
|
|
|
{
|
|
|
|
|
private readonly UseCasePresence _presenceUseCase;
|
2024-12-02 10:24:02 +00:00
|
|
|
|
private readonly UserUseCase _userUseCase;
|
|
|
|
|
private readonly GroupUseCase _groupUseCase;
|
2024-11-25 04:33:26 +00:00
|
|
|
|
|
2024-12-02 10:24:02 +00:00
|
|
|
|
public PresenceController(UseCasePresence presenceUseCase, UserUseCase userUseCase, GroupUseCase groupUseCase)
|
2024-11-25 04:33:26 +00:00
|
|
|
|
{
|
|
|
|
|
_presenceUseCase = presenceUseCase;
|
2024-12-02 10:24:02 +00:00
|
|
|
|
_userUseCase = userUseCase;
|
|
|
|
|
_groupUseCase = groupUseCase;
|
2024-11-25 04:33:26 +00:00
|
|
|
|
}
|
|
|
|
|
|
2024-12-02 10:24:02 +00:00
|
|
|
|
[HttpGet("getPresence")]
|
|
|
|
|
public IActionResult GetPresence([FromQuery] DateTime? startDate, [FromQuery] DateTime? endDate, [FromQuery] int? groupId, [FromQuery] Guid? userId)
|
2024-11-25 04:33:26 +00:00
|
|
|
|
{
|
2024-12-02 10:24:02 +00:00
|
|
|
|
var presence = _presenceUseCase.PresenceRepository.GetAllPresence();
|
|
|
|
|
|
|
|
|
|
if (startDate.HasValue)
|
|
|
|
|
{
|
|
|
|
|
presence = presence.Where(p => p.Date >= startDate.Value);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (endDate.HasValue)
|
|
|
|
|
{
|
|
|
|
|
presence = presence.Where(p => p.Date <= endDate.Value);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (groupId.HasValue)
|
|
|
|
|
{
|
|
|
|
|
presence = presence.Where(p => _userUseCase.GetAllUsers().Any(u => u.Id == p.UserId && u.GroupID == groupId.Value));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (userId.HasValue)
|
|
|
|
|
{
|
|
|
|
|
presence = presence.Where(p => p.UserId == userId.Value);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var result = new List<PresenceInfo>();
|
|
|
|
|
foreach (var p in presence)
|
|
|
|
|
{
|
|
|
|
|
var user = _userUseCase.GetUserById(p.UserId);
|
|
|
|
|
var group = _groupUseCase.GetAllGroups().FirstOrDefault(g => g.Id == user.GroupID);
|
|
|
|
|
result.Add(new PresenceInfo
|
|
|
|
|
{
|
|
|
|
|
GroupName = group?.Name,
|
|
|
|
|
FIO = user.FIO,
|
|
|
|
|
LessonNumber = p.LessonNumber,
|
|
|
|
|
Date = p.Date,
|
|
|
|
|
IsAttendance = p.IsAttendance
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return Ok(result);
|
2024-11-25 04:33:26 +00:00
|
|
|
|
}
|
|
|
|
|
|
2024-12-02 10:24:02 +00:00
|
|
|
|
[HttpPost("fillPresence")]
|
|
|
|
|
public IActionResult FillPresence([FromBody] List<Demo.Domain.Models.Presence> presenceList)
|
2024-11-25 04:33:26 +00:00
|
|
|
|
{
|
2024-12-02 10:24:02 +00:00
|
|
|
|
foreach (var presence in presenceList)
|
2024-11-25 04:33:26 +00:00
|
|
|
|
{
|
2024-12-02 10:24:02 +00:00
|
|
|
|
_presenceUseCase.PresenceRepository.AddPresence(presence);
|
|
|
|
|
}
|
2024-11-25 04:33:26 +00:00
|
|
|
|
return Ok();
|
|
|
|
|
}
|
|
|
|
|
|
2024-12-02 10:24:02 +00:00
|
|
|
|
[HttpDelete("clearPresence")]
|
|
|
|
|
public IActionResult ClearPresence([FromQuery] int? groupId, [FromQuery] Guid? userId, [FromQuery] DateTime? startDate, [FromQuery] DateTime? endDate)
|
2024-11-25 04:33:26 +00:00
|
|
|
|
{
|
2024-12-02 10:24:02 +00:00
|
|
|
|
var presence = _presenceUseCase.PresenceRepository.GetAllPresence();
|
|
|
|
|
|
|
|
|
|
if (groupId.HasValue)
|
|
|
|
|
{
|
|
|
|
|
presence = presence.Where(p => _userUseCase.GetAllUsers().Any(u => u.Id == p.UserId && u.GroupID == groupId.Value));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (userId.HasValue)
|
|
|
|
|
{
|
|
|
|
|
presence = presence.Where(p => p.UserId == userId.Value);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (startDate.HasValue)
|
|
|
|
|
{
|
|
|
|
|
presence = presence.Where(p => p.Date >= startDate.Value);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (endDate.HasValue)
|
|
|
|
|
{
|
|
|
|
|
presence = presence.Where(p => p.Date <= endDate.Value);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
foreach (var p in presence)
|
|
|
|
|
{
|
|
|
|
|
_presenceUseCase.PresenceRepository.DeletePresence(p.Id);
|
|
|
|
|
}
|
|
|
|
|
|
2024-11-25 04:33:26 +00:00
|
|
|
|
return Ok();
|
|
|
|
|
}
|
|
|
|
|
|
2024-12-02 10:24:02 +00:00
|
|
|
|
[HttpPut("updatePresence")]
|
|
|
|
|
public IActionResult UpdatePresence([FromQuery] Guid userId, [FromQuery] int lessonNumber, [FromQuery] DateTime date)
|
2024-11-25 04:33:26 +00:00
|
|
|
|
{
|
2024-12-02 10:24:02 +00:00
|
|
|
|
_presenceUseCase.MarkUserAsAbsent(userId, lessonNumber, date);
|
2024-11-25 04:33:26 +00:00
|
|
|
|
return Ok();
|
|
|
|
|
}
|
|
|
|
|
}
|
2024-12-02 10:24:02 +00:00
|
|
|
|
|
|
|
|
|
public class PresenceInfo
|
|
|
|
|
{
|
|
|
|
|
public string GroupName { get; set; }
|
|
|
|
|
public string FIO { get; set; }
|
|
|
|
|
public int LessonNumber { get; set; }
|
|
|
|
|
public DateTime Date { get; set; }
|
|
|
|
|
public bool IsAttendance { get; set; }
|
|
|
|
|
}
|
2024-11-25 04:33:26 +00:00
|
|
|
|
}
|