+ post presence, + get presence
This commit is contained in:
parent
79faa76278
commit
af64fee08f
@ -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; }
|
||||
}
|
||||
}
|
@ -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; }
|
||||
}
|
||||
}
|
@ -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;
|
||||
|
44
presence_api/Controllers/PresenceController.cs
Normal file
44
presence_api/Controllers/PresenceController.cs
Normal 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);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user