+ post presence, + get presence

This commit is contained in:
1billy17 2024-11-11 10:01:04 +03:00
parent 79faa76278
commit af64fee08f
4 changed files with 92 additions and 0 deletions

View File

@ -16,4 +16,17 @@ namespace Demo.Domain.Models
public required int groupID {get; set; }
public required DateOnly date {get; set; }
}
public class PresenceGetRequest
{
public int groupID { get; set; }
public DateOnly startDate { get; set; }
public DateOnly endDate { get; set; }
}
public class PresenceResponce
{
public string GroupName { get; set; }
public List<UserPresenceInfo> Users { get; set; }
}
}

View File

@ -46,4 +46,12 @@ namespace Demo.Domain.Models
{
public List<Guid> UsersGuid { get; set; }
}
public class UserPresenceInfo
{
public string FIO { get; set; }
public int LessonNumber { get; set; }
public DateOnly Date { get; set; }
public bool IsAttendance { get; set; }
}
}

View File

@ -130,6 +130,33 @@ namespace Demo.Domain.UseCase
return presenceByGroup;
}
public PresenceResponce GetPresenceByDataRangeAndGroup(int groupID, DateOnly? startDate, DateOnly? endDate) {
var group = _repositoryGroupImpl.GetAllGroup().FirstOrDefault(g => g.ID == groupID);
var usersByGroup = _repositoryUserImpl.GetAllUser()
.Where(user => user.GroupID == groupID).ToList();
var presences = _repositoryPresenceImpl.GetAllPresences()
.Where(presence =>
usersByGroup.Any(user => user.Guid == presence.UserGuid) &&
presence.Date >= startDate && presence.Date <= endDate)
.ToList();
var userPresenceInfos = presences.Select(presence => new UserPresenceInfo
{
FIO = usersByGroup.First(user => user.Guid == presence.UserGuid).FIO,
LessonNumber = presence.LessonNumber,
Date = presence.Date,
IsAttendance = presence.IsAttedance
}).ToList();
return new PresenceResponce
{
GroupName = group.Name,
Users = userPresenceInfos
};
}
public bool IsAttedance(int firstLesson, int lastLesson, DateOnly date, Guid UserGuid){
_repositoryPresenceImpl.IsAttedance(firstLesson, lastLesson, date, UserGuid);
return true;

View File

@ -0,0 +1,44 @@
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);
}
}