adminController; half presenceConrtoller

This commit is contained in:
Your Name 2024-11-08 16:14:43 +03:00
parent ab663018ab
commit f3b6d3ae0b
50 changed files with 227 additions and 23 deletions

View File

@ -5,6 +5,7 @@ namespace Demo.Data.Repository
public interface IPresenceRepository public interface IPresenceRepository
{ {
List<PresenceLocalEntity> GetAllPresences(); List<PresenceLocalEntity> GetAllPresences();
bool DeletePresence();
void IsAttedance(int firstLesson, int lastLesson, DateOnly date, Guid UserGuid); void IsAttedance(int firstLesson, int lastLesson, DateOnly date, Guid UserGuid);
List<PresenceLocalEntity> GeneratePresence(List<PresenceLocalEntity> presenceLocalEntities); List<PresenceLocalEntity> GeneratePresence(List<PresenceLocalEntity> presenceLocalEntities);
} }

View File

@ -7,6 +7,7 @@ namespace Demo.Data.Repository
List<UserLocalEntity> GetAllUser(); List<UserLocalEntity> GetAllUser();
UserLocalEntity? GetUserByGuid(Guid guid); UserLocalEntity? GetUserByGuid(Guid guid);
List<UserLocalEntity> GetUsersByGroupID(int groupID); List<UserLocalEntity> GetUsersByGroupID(int groupID);
public UserLocalEntity? CreateUser(string FIO, string GroupName);
bool RemoveUserByGuid(Guid guid); bool RemoveUserByGuid(Guid guid);
UserLocalEntity? UpdateUser(UserLocalEntity updatedUser); UserLocalEntity? UpdateUser(UserLocalEntity updatedUser);
} }

View File

@ -19,6 +19,13 @@ namespace Demo.Data.Repository
return _remoteDatabaseContext.PresenceDaos.Select(x => new PresenceLocalEntity{UserGuid = x.UserGuid, Date = x.Date, LessonNumber = x.LessonNumber, IsAttedance = x.IsAttedance}).ToList(); return _remoteDatabaseContext.PresenceDaos.Select(x => new PresenceLocalEntity{UserGuid = x.UserGuid, Date = x.Date, LessonNumber = x.LessonNumber, IsAttedance = x.IsAttedance}).ToList();
} }
public bool DeletePresence(){
var allRecords = _remoteDatabaseContext.PresenceDaos.ToList();
_remoteDatabaseContext.PresenceDaos.RemoveRange(allRecords);
_remoteDatabaseContext.SaveChanges();
return true;
}
public List<PresenceLocalEntity> GeneratePresence(List<PresenceLocalEntity> presenceLocalEntities) public List<PresenceLocalEntity> GeneratePresence(List<PresenceLocalEntity> presenceLocalEntities)
{ {
var presences = presenceLocalEntities.Select(x => new PresenceDAO var presences = presenceLocalEntities.Select(x => new PresenceDAO

View File

@ -1,6 +1,7 @@
using Demo.Domain.Models; using Demo.Domain.Models;
using Demo.Data.LocalData; using Demo.Data.LocalData;
using Demo.Data.RemoteData.RemoteDataBase; using Demo.Data.RemoteData.RemoteDataBase;
using Demo.Data.RemoteData.RemoteDataBase.DAO;
namespace Demo.Data.Repository namespace Demo.Data.Repository
{ {
@ -38,6 +39,14 @@ namespace Demo.Data.Repository
.ToList(); .ToList();
} }
public UserLocalEntity? CreateUser(string FIO, string GroupName){
var groupDAO = _remoteDatabaseContext.Groups.FirstOrDefault(x => x.Name == GroupName);
UserDAO userDAO = new UserDAO{FIO = FIO, Guid = Guid.NewGuid(), GroupID = groupDAO.ID};
var result = _remoteDatabaseContext.Users.Add(userDAO);
_remoteDatabaseContext.SaveChanges();
return new UserLocalEntity{FIO = FIO, Guid = Guid.NewGuid(), GroupID = groupDAO.ID};
}
public bool RemoveUserByGuid(Guid guid){ public bool RemoveUserByGuid(Guid guid){
var userDAO = _remoteDatabaseContext.Users.FirstOrDefault(x => x.Guid == guid); var userDAO = _remoteDatabaseContext.Users.FirstOrDefault(x => x.Guid == guid);
_remoteDatabaseContext.Users.Remove(userDAO); _remoteDatabaseContext.Users.Remove(userDAO);

Binary file not shown.

Binary file not shown.

View File

@ -13,10 +13,10 @@ using System.Reflection;
[assembly: System.Reflection.AssemblyCompanyAttribute("data")] [assembly: System.Reflection.AssemblyCompanyAttribute("data")]
[assembly: System.Reflection.AssemblyConfigurationAttribute("Debug")] [assembly: System.Reflection.AssemblyConfigurationAttribute("Debug")]
[assembly: System.Reflection.AssemblyFileVersionAttribute("1.0.0.0")] [assembly: System.Reflection.AssemblyFileVersionAttribute("1.0.0.0")]
[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+9a1a4a676f43477d6c758020bf8a6f3c550c7d1f")] [assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+ab663018abacf01e070b5ad828bf9b4512e0c4d7")]
[assembly: System.Reflection.AssemblyProductAttribute("data")] [assembly: System.Reflection.AssemblyProductAttribute("data")]
[assembly: System.Reflection.AssemblyTitleAttribute("data")] [assembly: System.Reflection.AssemblyTitleAttribute("data")]
[assembly: System.Reflection.AssemblyVersionAttribute("1.0.0.0")] [assembly: System.Reflection.AssemblyVersionAttribute("1.0.0.0")]
// Создано классом WriteCodeFragment MSBuild. // Generated by the MSBuild WriteCodeFragment class.

View File

@ -1 +1 @@
5ba87ffa7bb75ecaaebd58cb228572decf22f2fcbdf786cdba357d38098903ad cd43bf0997982c5c306bd1cf1db3c12e77ec46315653277fe2d342bd04c4db32

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -10,4 +10,21 @@ namespace Demo.Domain.Models
return new Group{ID = Convert.ToInt32(words[0]), Name = words[1]}; return new Group{ID = Convert.ToInt32(words[0]), Name = words[1]};
} }
} }
public class GroupCon{
public required int ID{get; set; }
public required string Name{get; set; }
public List<User> Users { get; set; } = new List<User>();
}
public class GroupWithUsers
{
public required string GroupName { get; set; }
public List<UserRequest> Users { get; set; }
}
public class DeleteGroupsRequest
{
public List<int> GroupIDs { get; set; }
}
} }

View File

@ -8,4 +8,12 @@ namespace Demo.Domain.Models
public required int LessonNumber { get; set; } public required int LessonNumber { get; set; }
} }
public class PresencePost
{
public required int firstLesson {get; set; }
public required int lastLesson {get; set; }
public required int groupID {get; set; }
public required DateOnly date {get; set; }
}
} }

View File

@ -35,4 +35,15 @@ namespace Demo.Domain.Models
} }
} }
} }
public class UserRequest
{
public required string FIO{get; set; }
public required Group Group{get; set; }
}
public class DeleteUsersRequest
{
public List<Guid> UsersGuid { get; set; }
}
} }

View File

@ -23,6 +23,21 @@ namespace Demo.Domain.UseCase
return new Group{ID = groupID, Name = groupLocalEntity.Name}; return new Group{ID = groupID, Name = groupLocalEntity.Name};
} }
public List<GroupCon> GetAllGroupsWithUsers(){
var groups = _repositoryGroupImpl.GetAllGroup().Select(it => new GroupCon { ID = it.ID, Name = it.Name }).ToList();
var users = _repositoryUserImpl.GetAllUser().Select(it => new User{FIO = it.FIO, Guid = it.Guid, Group = new Group{ID = it.GroupID, Name = _repositoryGroupImpl.GetGroupById(it.GroupID).Name}}).ToList();
foreach (var group in groups)
{
foreach (var user in users)
{
if (user.Group.ID == group.ID){
group.Users.Add(user);
}
}
}
return groups;
}
public bool CreateGroup(string Name){ public bool CreateGroup(string Name){
_repositoryGroupImpl.CreateGroup(Name); _repositoryGroupImpl.CreateGroup(Name);
return true; return true;

View File

@ -5,6 +5,7 @@ namespace Demo.Domain.UseCase
public interface IGroupUseCase public interface IGroupUseCase
{ {
List<Group> GetAllGroups(); List<Group> GetAllGroups();
List<GroupCon> GetAllGroupsWithUsers();
bool RemoveGroupByID(int groupID); bool RemoveGroupByID(int groupID);
Group UpdateGroup(Group group); Group UpdateGroup(Group group);
Group GetGroupById(int groupID); Group GetGroupById(int groupID);

View File

@ -9,6 +9,7 @@ namespace Demo.Domain.UseCase
List<Presence> GetPresenceByUser(Guid userGuid); List<Presence> GetPresenceByUser(Guid userGuid);
List<Presence> GetFalsePresenceByUser(Guid userGuid); List<Presence> GetFalsePresenceByUser(Guid userGuid);
List<Presence> GetFalsePresenceByGroup(int groupID); List<Presence> GetFalsePresenceByGroup(int groupID);
bool DeletePresence();
bool IsAttedance(int firstLesson, int lastLesson, DateOnly date, Guid UserGuid); bool IsAttedance(int firstLesson, int lastLesson, DateOnly date, Guid UserGuid);
bool GeneratePresence(int firstLesson, int lastLesson, int groupID, DateOnly date); bool GeneratePresence(int firstLesson, int lastLesson, int groupID, DateOnly date);
bool GeneratePresenceWeek(int firstLesson, int lastLesson, int groupID, DateOnly date); bool GeneratePresenceWeek(int firstLesson, int lastLesson, int groupID, DateOnly date);

View File

@ -5,6 +5,7 @@ namespace Demo.Domain.UseCase
public interface IUserUseCase public interface IUserUseCase
{ {
List<User> GetAllUsers(); List<User> GetAllUsers();
bool CreateUser(User user);
bool RemoveUserByGuid(Guid userGuid); bool RemoveUserByGuid(Guid userGuid);
User UpdateUser(User user); User UpdateUser(User user);
User GetUserByGuid(Guid userGuid); User GetUserByGuid(Guid userGuid);

View File

@ -130,6 +130,10 @@ namespace Demo.Domain.UseCase
return presenceByGroup; return presenceByGroup;
} }
public bool DeletePresence(){
return _repositoryPresenceImpl.DeletePresence();
}
public bool IsAttedance(int firstLesson, int lastLesson, DateOnly date, Guid UserGuid){ public bool IsAttedance(int firstLesson, int lastLesson, DateOnly date, Guid UserGuid){
_repositoryPresenceImpl.IsAttedance(firstLesson, lastLesson, date, UserGuid); _repositoryPresenceImpl.IsAttedance(firstLesson, lastLesson, date, UserGuid);
return true; return true;

View File

@ -61,6 +61,11 @@ namespace Demo.Domain.UseCase
return users; return users;
} }
public bool CreateUser(User user){
_repositoryUserImpl.CreateUser(user.FIO, user.Group.Name);
return true;
}
public bool RemoveUserByGuid(Guid userGuid) { public bool RemoveUserByGuid(Guid userGuid) {
return _repositoryUserImpl.RemoveUserByGuid(userGuid); return _repositoryUserImpl.RemoveUserByGuid(userGuid);
} }

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -13,7 +13,7 @@ using System.Reflection;
[assembly: System.Reflection.AssemblyCompanyAttribute("domain")] [assembly: System.Reflection.AssemblyCompanyAttribute("domain")]
[assembly: System.Reflection.AssemblyConfigurationAttribute("Debug")] [assembly: System.Reflection.AssemblyConfigurationAttribute("Debug")]
[assembly: System.Reflection.AssemblyFileVersionAttribute("1.0.0.0")] [assembly: System.Reflection.AssemblyFileVersionAttribute("1.0.0.0")]
[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+9a1a4a676f43477d6c758020bf8a6f3c550c7d1f")] [assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+ab663018abacf01e070b5ad828bf9b4512e0c4d7")]
[assembly: System.Reflection.AssemblyProductAttribute("domain")] [assembly: System.Reflection.AssemblyProductAttribute("domain")]
[assembly: System.Reflection.AssemblyTitleAttribute("domain")] [assembly: System.Reflection.AssemblyTitleAttribute("domain")]
[assembly: System.Reflection.AssemblyVersionAttribute("1.0.0.0")] [assembly: System.Reflection.AssemblyVersionAttribute("1.0.0.0")]

View File

@ -1 +1 @@
ea5525c196e6a42ab8fb1a310ecfb776da42845ff47bc24abc92536ef0465e16 53e90c69f33df0bd1e7077d29424b1847917acfabb5c61f6d56d7e56ca00c889

Binary file not shown.

Binary file not shown.

View File

@ -1,16 +1,113 @@
using Demo.Domain.Models;
using Demo.Domain.UseCase;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
using Npgsql.TypeMapping;
namespace presence_api.Controllers; namespace presence_api.Controllers;
[ApiController] [ApiController]
[Route("api/[controller]")] [Route("api/[controller]")]
public class AdminController: ControllerBase{ public class AdminController: ControllerBase{
private readonly GroupUseCase _groupUseCase;
private readonly UserUseCase _userUseCase;
private readonly PresenceUseCase _presenceUseCase;
public AdminController(GroupUseCase groupUseCase, UserUseCase userUseCase, PresenceUseCase presenceUseCase){
_groupUseCase = groupUseCase;
_userUseCase = userUseCase;
_presenceUseCase = presenceUseCase;
}
//post //post
[HttpPost]
public ActionResult<bool> CreateGroup([FromBody] GroupWithUsers request)
{
if (request == null || string.IsNullOrEmpty(request.GroupName))
{
return BadRequest("Invalid request");
}
bool isCreated = _groupUseCase.CreateGroup(request.GroupName);
foreach(var user in request.Users){
var usert = new User{FIO = user.FIO, Guid = Guid.NewGuid(), Group = user.Group};
_userUseCase.CreateUser(usert);
}
return Ok(isCreated);
}
//delete //delete
[HttpDelete("user")]
public ActionResult<bool> DeleteUser(Guid userGuid){
if (userGuid == Guid.Empty){
return BadRequest("Invalid request");
}
bool isDeleted = _userUseCase.RemoveUserByGuid(userGuid);
if (isDeleted == false){
return NotFound("User not found");
}
return Ok(true);
}
[HttpDelete("users")]
public ActionResult<bool> DeleteUsers([FromBody] DeleteUsersRequest request){
if (request == null){
return BadRequest("Invalid request");
}
foreach (Guid userGuid in request.UsersGuid)
{
bool isDeleted = _userUseCase.RemoveUserByGuid(userGuid);
if (isDeleted == false){
return NotFound("User not found");
}
}
return Ok(true);
}
[HttpDelete("group")]
public ActionResult<bool> DeleteGroup(int GroupID){
bool isDeleted = _groupUseCase.RemoveGroupByID(GroupID);
if (isDeleted == false){
return NotFound("Group not found");
}
return Ok(true);
}
[HttpDelete("groups")]
public ActionResult<bool> DeleteGroups([FromBody] DeleteGroupsRequest request){
if (request == null){
return BadRequest("Invalid request");
}
foreach (int GroupID in request.GroupIDs)
{
bool isDeleted = _groupUseCase.RemoveGroupByID(GroupID);
if (isDeleted == false){
return NotFound("Group not found");
}
}
return Ok(true);
}
[HttpDelete("presence")]
public ActionResult<bool> DeletePresence(){
return Ok(_presenceUseCase.DeletePresence());
}
//get //get
[HttpGet]
public ActionResult<IEnumerable<GroupCon>> getGroupsWithUsers()
{
return Ok(_groupUseCase.GetAllGroupsWithUsers());
}
[HttpGet("user/{userGuid}")]
public ActionResult<User> GetUserByGuid(Guid userGuid)
{
var user = _userUseCase.GetUserByGuid(userGuid);
if (user != null){
return Ok(user);
} else{
return NotFound("User not found");
}
}
} }

View File

@ -0,0 +1,34 @@
using Demo.Domain.Models;
using Demo.Domain.UseCase;
using Microsoft.AspNetCore.Mvc;
namespace presence_api.Controllers;
[ApiController]
[Route("api/[controller]")]
public class PresenceController: ControllerBase{
private readonly PresenceUseCase _presenceUseCase;
public PresenceController(PresenceUseCase presenceUseCase)
{
_presenceUseCase = presenceUseCase;
}
//get
//post
[HttpPost("generate")]
public ActionResult<bool> GeneratePresence([FromBody] PresencePost request)
{
if (request == null){
return BadRequest("buba");
}
var isGenerated = _presenceUseCase.GeneratePresence(request.firstLesson, request.lastLesson, request.groupID, request.date);
return Ok(isGenerated);
}
//delete
//update
}

View File

@ -1,14 +1,3 @@
// using Demo.Data.Repository;
// using Demo.Domain.UseCase;
// public static class ServiceExtencions{
// public static void ConfigurateGroup(this IServiceCollection services)
// {
// services.AddScoped<IGroupRepository, SQLGroupRepositoryImpl>()
// .AddScoped<GroupUseCase>();
// }
// }
using Demo.Data.Repository; using Demo.Data.Repository;
using Demo.Domain.UseCase; using Demo.Domain.UseCase;
@ -18,6 +7,9 @@ public static class ServiceExtencions
{ {
services.AddScoped<IGroupRepository, SQLGroupRepositoryImpl>() services.AddScoped<IGroupRepository, SQLGroupRepositoryImpl>()
.AddScoped<IUserRepository, SQLUserRepositoryImpl>() .AddScoped<IUserRepository, SQLUserRepositoryImpl>()
.AddScoped<GroupUseCase>(); .AddScoped<IPresenceRepository, SQLPresenceRepositoryImpl>()
.AddScoped<GroupUseCase>()
.AddScoped<UserUseCase>()
.AddScoped<PresenceUseCase>();
} }
} }

View File

@ -13,7 +13,7 @@ using System.Reflection;
[assembly: System.Reflection.AssemblyCompanyAttribute("presence_api")] [assembly: System.Reflection.AssemblyCompanyAttribute("presence_api")]
[assembly: System.Reflection.AssemblyConfigurationAttribute("Debug")] [assembly: System.Reflection.AssemblyConfigurationAttribute("Debug")]
[assembly: System.Reflection.AssemblyFileVersionAttribute("1.0.0.0")] [assembly: System.Reflection.AssemblyFileVersionAttribute("1.0.0.0")]
[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+9a1a4a676f43477d6c758020bf8a6f3c550c7d1f")] [assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+ab663018abacf01e070b5ad828bf9b4512e0c4d7")]
[assembly: System.Reflection.AssemblyProductAttribute("presence_api")] [assembly: System.Reflection.AssemblyProductAttribute("presence_api")]
[assembly: System.Reflection.AssemblyTitleAttribute("presence_api")] [assembly: System.Reflection.AssemblyTitleAttribute("presence_api")]
[assembly: System.Reflection.AssemblyVersionAttribute("1.0.0.0")] [assembly: System.Reflection.AssemblyVersionAttribute("1.0.0.0")]

View File

@ -1 +1 @@
10827b4c81f3bbe2ddad3a0cffacb58a86473e79298f58d43c550df7310e052e e4838467133c57bdd2c94f8db0c1fd2159f424bc63563685da366c57ec64e107

View File

@ -1 +1 @@
7fd8191932eb3651c4c77b0c932930207f4dca09c1cb88c8509828f17de96157 ea8075ffbb357bda1813b80b328a20c60762bee510180efc2da28da284041540