diff --git a/console_ui/Program.cs b/console_ui/Program.cs index b6e25ab..9eed8e6 100644 --- a/console_ui/Program.cs +++ b/console_ui/Program.cs @@ -18,6 +18,8 @@ IServiceCollection services = new ServiceCollection(); .AddSingleton() .AddSingleton() .AddSingleton() + .AddSingleton() + .AddSingleton() .AddSingleton() .AddSingleton(); diff --git a/presence_api/Controllers/AdminController.cs b/presence_api/Controllers/AdminController.cs index cf442aa..102a14d 100644 --- a/presence_api/Controllers/AdminController.cs +++ b/presence_api/Controllers/AdminController.cs @@ -25,7 +25,7 @@ public class AdminController: ControllerBase{ { if (request == null || string.IsNullOrEmpty(request.GroupName)) { - _logger.LogWarning("Invalid request"); + _logger.LogWarning("CreateGroup: Invalid request"); return BadRequest("Invalid request"); } @@ -43,12 +43,12 @@ public class AdminController: ControllerBase{ [HttpDelete("user")] public ActionResult DeleteUser(Guid userGuid){ if (userGuid == Guid.Empty){ - _logger.LogWarning("Invalid request"); + _logger.LogWarning("DeleteUser: userGuid empty"); return BadRequest("Invalid request"); } bool isDeleted = _userUseCase.RemoveUserByGuid(userGuid); if (isDeleted == false){ - _logger.LogWarning("User not found"); + _logger.LogWarning("DeleteUser: User not found"); return NotFound("User not found"); } return Ok(true); @@ -57,7 +57,7 @@ public class AdminController: ControllerBase{ [HttpDelete("users")] public ActionResult DeleteUsers([FromBody] DeleteUsersRequest request){ if (request == null){ - _logger.LogWarning("Invalid request"); + _logger.LogWarning("DeleteUsers null request"); return BadRequest("Invalid request"); } foreach (Guid userGuid in request.UsersGuid) diff --git a/presence_api/Controllers/PresenceController.cs b/presence_api/Controllers/PresenceController.cs index 4cba947..87405b4 100644 --- a/presence_api/Controllers/PresenceController.cs +++ b/presence_api/Controllers/PresenceController.cs @@ -23,7 +23,7 @@ public class PresenceController: ControllerBase{ if (!DateOnly.TryParse(date, out var parseDate)) { - _logger.LogWarning("Invalid date format"); + _logger.LogWarning("GeneratePresence: Invalid date format"); return BadRequest("Invalid date format"); } @@ -50,13 +50,13 @@ public class PresenceController: ControllerBase{ public ActionResult DeletePresenceByUserGuid(Guid userGuid) { if (userGuid == Guid.Empty){ - _logger.LogWarning("Invalid Guid"); + _logger.LogWarning("DeletePresenceByUserGuid: userGuid empty"); return BadRequest("Invalid request"); } var isDeleted = _presenceUseCase.DeletePresenceByUser(userGuid); if (isDeleted == false){ - _logger.LogWarning("User not found"); + _logger.LogWarning("DeletePresenceByUserGuid: User not found"); return NotFound("User not found"); } return Ok(true); @@ -67,7 +67,7 @@ public class PresenceController: ControllerBase{ { var isDeleted = _presenceUseCase.DeletePresenceByGroup(groupID); if (isDeleted == false){ - _logger.LogWarning("Group not found"); + _logger.LogWarning("DeletePresenceByGroup: Group not found"); return NotFound("Group not found"); } return Ok(true); @@ -79,13 +79,13 @@ public class PresenceController: ControllerBase{ if (!DateOnly.TryParse(startDate, out var parsedStartDate) || !DateOnly.TryParse(endDate, out var parsedEndDate)) { - _logger.LogWarning("Invalid date format"); + _logger.LogWarning("DeletePresenceByDateRange: Invalid date format"); return BadRequest("Invalid date format"); } var isDeleted = _presenceUseCase.DeletePresenceByDateRange(parsedStartDate, parsedEndDate); if (isDeleted == false){ - _logger.LogWarning("Presence not found"); + _logger.LogWarning("DeletePresenceByDateRange: Presence not found"); return NotFound("Presence not found"); } @@ -97,13 +97,13 @@ public class PresenceController: ControllerBase{ { if (!DateOnly.TryParse(date, out var parseDate)) { - _logger.LogWarning("Invalid date format"); + _logger.LogWarning("UpdatePresence: Invalid date format"); return BadRequest("Invalid date format"); } var isUpdated = _presenceUseCase.IsAttedance(firstLesson, lastLesson, parseDate, UserGuid); if (isUpdated == false){ - _logger.LogWarning("Presence not found"); + _logger.LogWarning("UpdatePresence: Presence not found"); return NotFound("Presence not found"); } diff --git a/presence_api/Program.cs b/presence_api/Program.cs index c2f44fb..d352d9c 100644 --- a/presence_api/Program.cs +++ b/presence_api/Program.cs @@ -8,7 +8,9 @@ builder.Services.AddDbContext(); builder.Services.AddEndpointsApiExplorer(); builder.Services.AddSwaggerGen(); -builder.Services.ConfigurateGroup(); +builder.Services.AddGroupServices(); +builder.Services.AddUserServices(); +builder.Services.AddPresenceServices(); var app = builder.Build(); diff --git a/presence_api/ServiceExtensions/ServiceExtensions.cs b/presence_api/ServiceExtensions/ServiceExtensions.cs index 4d5b6b1..0bd6ad2 100644 --- a/presence_api/ServiceExtensions/ServiceExtensions.cs +++ b/presence_api/ServiceExtensions/ServiceExtensions.cs @@ -3,13 +3,21 @@ using Demo.Domain.UseCase; public static class ServiceExtencions { - public static void ConfigurateGroup(this IServiceCollection services) + public static void AddGroupServices(this IServiceCollection services) { services.AddScoped() - .AddScoped() - .AddScoped() - .AddScoped() - .AddScoped() + .AddScoped(); + } + + public static void AddUserServices(this IServiceCollection services) + { + services.AddScoped() + .AddScoped(); + } + + public static void AddPresenceServices(this IServiceCollection services) + { + services.AddScoped() .AddScoped(); } } \ No newline at end of file diff --git a/ui/GroupConsole.cs b/ui/GroupConsole.cs new file mode 100644 index 0000000..8e7ca89 --- /dev/null +++ b/ui/GroupConsole.cs @@ -0,0 +1,88 @@ +using System.ComponentModel.DataAnnotations; +using System.Text; +using Demo.Domain.Models; +using Demo.Domain.UseCase; + +namespace Demo.UI +{ + public class GroupConsoleUI + { + IGroupUseCase _groupUseCase; + IUserUseCase _userUseCase; + IPresenceUseCase _presenceUseCase; + public GroupConsoleUI(IGroupUseCase groupUseCase, IUserUseCase userUseCase, IPresenceUseCase presenceUseCase){ + _groupUseCase = groupUseCase; + _userUseCase = userUseCase; + _presenceUseCase = presenceUseCase; + } + + public void DisplayAllGroups(){ + StringBuilder userOutput = new StringBuilder(); + foreach (var group in _groupUseCase.GetAllGroups()) + { + userOutput.AppendLine($"{group.ID}\t{group.Name}"); + } + Console.WriteLine(userOutput); + } + + public void DisplayGroupByID(int ID){ + StringBuilder userOutput = new StringBuilder(); + var group = _groupUseCase.GetGroupById(ID); + { + userOutput.AppendLine($"{group.ID}\t{group.Name}"); + } + Console.WriteLine(userOutput); + } + + public void CreateNewGroup(string Name){ + string output = _groupUseCase.CreateGroup(Name) ? "Группа создана" : "Группа не создана"; + Console.WriteLine(output); + } + + public void UpdateGroupName(Group group) + { + try + { + Group output = _groupUseCase.UpdateGroup(group); + StringBuilder groupOutput = new StringBuilder(); + groupOutput.AppendLine($"Обновленная группа: {output.ID}\t{output.Name}"); + Console.WriteLine(groupOutput); + } + catch (Exception ex) + { + Console.WriteLine($"Ошибка при обновлении группы: {ex.Message}"); + } + } + + public void RemoveGroupByID(int ID){ + string output = _groupUseCase.RemoveGroupByID(ID) ? "Группа удалена" : "Группа не удалена"; + Console.WriteLine(output); + } + + public void DisplayAllBoutGroup(int groupID){ + var users = _userUseCase.GetUsersByGroupID(groupID); + Console.WriteLine($"Группа: {groupID}\tКоличество учеников: {users.Count}"); + + var presencesByGroup = _presenceUseCase.GetPresenceByGroup(groupID); + var presenceFalseByGroup = _presenceUseCase.GetFalsePresenceByGroup(groupID); + var precentePresenceGroup = 100 - Math.Round((double)presenceFalseByGroup.Count / presencesByGroup.Count * 100); + Console.WriteLine($"Количество занятий: {presencesByGroup.Count}\tОбщий процент посещаемости: {precentePresenceGroup}"); + + foreach(var user in _userUseCase.GetUsersByGroupID(groupID)){ + var countPresences = _presenceUseCase.GetPresenceByUser(user.Guid); + var countFalsePresences = _presenceUseCase.GetFalsePresenceByUser(user.Guid); + var precentePresenceUser = 100 - Math.Round((double)countFalsePresences.Count / countPresences.Count * 100); + if (precentePresenceUser < 40) + { + Console.ForegroundColor = ConsoleColor.Red; + Console.WriteLine($"FIO: {user.FIO}\tКоличество посещённых занятий: {countPresences.Count - countFalsePresences.Count}\tКоличество пропущенных занятий: {countFalsePresences.Count}\tПроцент посещаемости: {precentePresenceUser}"); + Console.ResetColor(); + } + else + { + Console.WriteLine($"FIO: {user.FIO}\tКоличество посещённых занятий: {countPresences.Count - countFalsePresences.Count}\tКоличество пропущенных занятий: {countFalsePresences.Count}\tПроцент посещаемости: {precentePresenceUser}"); + } + } + } + } +} \ No newline at end of file diff --git a/ui/PresenceConsole.cs b/ui/PresenceConsole.cs new file mode 100644 index 0000000..66c524a --- /dev/null +++ b/ui/PresenceConsole.cs @@ -0,0 +1,45 @@ +using System.ComponentModel.DataAnnotations; +using System.Text; +using Demo.Domain.Models; +using Demo.Domain.UseCase; + +namespace Demo.UI +{ + public class PresenceConsoleUI{ + IPresenceUseCase _presenceUseCase; + public PresenceConsoleUI (IPresenceUseCase presenceUseCase){ + _presenceUseCase = presenceUseCase; + } + + public void DisplayPresenceByGroup(int groupID){ + StringBuilder stringBuilder = new StringBuilder(); + foreach(Presence presence in _presenceUseCase.GetPresenceByGroup(groupID)){ + stringBuilder.AppendLine($"{presence.User.FIO}, {presence.User.Group.Name}, {presence.IsAttedance}, {presence.Date}, {presence.LessonNumber}"); + } + Console.WriteLine(stringBuilder); + } + + public void DisplayPresenceByGroupByTime(int groupID, DateOnly date){ + StringBuilder stringBuilder = new StringBuilder(); + foreach(Presence presence in _presenceUseCase.GetPresenceByGroupByTime(groupID, date)){ + stringBuilder.AppendLine($"{presence.User.FIO}, {presence.User.Group.Name}, {presence.IsAttedance}, {presence.Date}, {presence.LessonNumber}"); + } + Console.WriteLine(stringBuilder); + } + + public void GeneratePresence(int firstLesson, int lastLesson, int groupID, DateOnly date){ + string output = _presenceUseCase.GeneratePresence(firstLesson, lastLesson, groupID, date) ? "Сгенерированно" : "Не сгенерированно"; + Console.WriteLine(output); + } + + public void GeneratePresenceWeek(int firstLesson, int lastLesson, int groupID, DateOnly date){ + string output = _presenceUseCase.GeneratePresenceWeek(firstLesson, lastLesson, groupID, date) ? "Сгенерированно" : "Не сгенерированно"; + Console.WriteLine(output); + } + + public void IsAttedance(int firstLesson, int lastLesson, DateOnly date, Guid UserGuid){ + string output = _presenceUseCase.IsAttedance(firstLesson, lastLesson, date, UserGuid) ? "Обновлено" : "Не обновлено"; + Console.WriteLine(output); + } + } +} \ No newline at end of file diff --git a/ui/UserConsole.cs b/ui/UserConsole.cs index 0fac04f..5d89fb0 100644 --- a/ui/UserConsole.cs +++ b/ui/UserConsole.cs @@ -50,123 +50,4 @@ namespace Demo.UI Console.WriteLine(userOutput); } } - - public class GroupConsoleUI - { - IGroupUseCase _groupUseCase; - IUserUseCase _userUseCase; - IPresenceUseCase _presenceUseCase; - public GroupConsoleUI(IGroupUseCase groupUseCase, IUserUseCase userUseCase, IPresenceUseCase presenceUseCase){ - _groupUseCase = groupUseCase; - _userUseCase = userUseCase; - _presenceUseCase = presenceUseCase; - } - - public void DisplayAllGroups(){ - StringBuilder userOutput = new StringBuilder(); - foreach (var group in _groupUseCase.GetAllGroups()) - { - userOutput.AppendLine($"{group.ID}\t{group.Name}"); - } - Console.WriteLine(userOutput); - } - - public void DisplayGroupByID(int ID){ - StringBuilder userOutput = new StringBuilder(); - var group = _groupUseCase.GetGroupById(ID); - { - userOutput.AppendLine($"{group.ID}\t{group.Name}"); - } - Console.WriteLine(userOutput); - } - - public void CreateNewGroup(string Name){ - string output = _groupUseCase.CreateGroup(Name) ? "Группа создана" : "Группа не создана"; - Console.WriteLine(output); - } - - public void UpdateGroupName(Group group) - { - try - { - Group output = _groupUseCase.UpdateGroup(group); - StringBuilder groupOutput = new StringBuilder(); - groupOutput.AppendLine($"Обновленная группа: {output.ID}\t{output.Name}"); - Console.WriteLine(groupOutput); - } - catch (Exception ex) - { - Console.WriteLine($"Ошибка при обновлении группы: {ex.Message}"); - } - } - - public void RemoveGroupByID(int ID){ - string output = _groupUseCase.RemoveGroupByID(ID) ? "Группа удалена" : "Группа не удалена"; - Console.WriteLine(output); - } - - public void DisplayAllBoutGroup(int groupID){ - var users = _userUseCase.GetUsersByGroupID(groupID); - Console.WriteLine($"Группа: {groupID}\tКоличество учеников: {users.Count}"); - - var presencesByGroup = _presenceUseCase.GetPresenceByGroup(groupID); - var presenceFalseByGroup = _presenceUseCase.GetFalsePresenceByGroup(groupID); - var precentePresenceGroup = 100 - Math.Round((double)presenceFalseByGroup.Count / presencesByGroup.Count * 100); - Console.WriteLine($"Количество занятий: {presencesByGroup.Count}\tОбщий процент посещаемости: {precentePresenceGroup}"); - - foreach(var user in _userUseCase.GetUsersByGroupID(groupID)){ - var countPresences = _presenceUseCase.GetPresenceByUser(user.Guid); - var countFalsePresences = _presenceUseCase.GetFalsePresenceByUser(user.Guid); - var precentePresenceUser = 100 - Math.Round((double)countFalsePresences.Count / countPresences.Count * 100); - if (precentePresenceUser < 40) - { - Console.ForegroundColor = ConsoleColor.Red; - Console.WriteLine($"FIO: {user.FIO}\tКоличество посещённых занятий: {countPresences.Count - countFalsePresences.Count}\tКоличество пропущенных занятий: {countFalsePresences.Count}\tПроцент посещаемости: {precentePresenceUser}"); - Console.ResetColor(); - } - else - { - Console.WriteLine($"FIO: {user.FIO}\tКоличество посещённых занятий: {countPresences.Count - countFalsePresences.Count}\tКоличество пропущенных занятий: {countFalsePresences.Count}\tПроцент посещаемости: {precentePresenceUser}"); - } - } - } - } - - public class PresenceConsoleUI{ - IPresenceUseCase _presenceUseCase; - public PresenceConsoleUI (IPresenceUseCase presenceUseCase){ - _presenceUseCase = presenceUseCase; - } - - public void DisplayPresenceByGroup(int groupID){ - StringBuilder stringBuilder = new StringBuilder(); - foreach(Presence presence in _presenceUseCase.GetPresenceByGroup(groupID)){ - stringBuilder.AppendLine($"{presence.User.FIO}, {presence.User.Group.Name}, {presence.IsAttedance}, {presence.Date}, {presence.LessonNumber}"); - } - Console.WriteLine(stringBuilder); - } - - public void DisplayPresenceByGroupByTime(int groupID, DateOnly date){ - StringBuilder stringBuilder = new StringBuilder(); - foreach(Presence presence in _presenceUseCase.GetPresenceByGroupByTime(groupID, date)){ - stringBuilder.AppendLine($"{presence.User.FIO}, {presence.User.Group.Name}, {presence.IsAttedance}, {presence.Date}, {presence.LessonNumber}"); - } - Console.WriteLine(stringBuilder); - } - - public void GeneratePresence(int firstLesson, int lastLesson, int groupID, DateOnly date){ - string output = _presenceUseCase.GeneratePresence(firstLesson, lastLesson, groupID, date) ? "Сгенерированно" : "Не сгенерированно"; - Console.WriteLine(output); - } - - public void GeneratePresenceWeek(int firstLesson, int lastLesson, int groupID, DateOnly date){ - string output = _presenceUseCase.GeneratePresenceWeek(firstLesson, lastLesson, groupID, date) ? "Сгенерированно" : "Не сгенерированно"; - Console.WriteLine(output); - } - - public void IsAttedance(int firstLesson, int lastLesson, DateOnly date, Guid UserGuid){ - string output = _presenceUseCase.IsAttedance(firstLesson, lastLesson, date, UserGuid) ? "Обновлено" : "Не обновлено"; - Console.WriteLine(output); - } - } } \ No newline at end of file