Interfaces user, group

This commit is contained in:
1billy17 2024-10-21 12:07:49 +03:00
parent 7603d4fbad
commit be284427eb
5 changed files with 50 additions and 5 deletions

View File

@ -8,7 +8,7 @@ using System.Threading.Tasks;
namespace Demo.Data.Repository namespace Demo.Data.Repository
{ {
public class GroupRepositoryImpl public class GroupRepositoryImpl:IGroupRepository
{ {
public GroupRepositoryImpl() { public GroupRepositoryImpl() {
@ -17,6 +17,11 @@ namespace Demo.Data.Repository
public List<GroupLocalEntity> GetAllGroups public List<GroupLocalEntity> GetAllGroups
{ get; set; } { get; set; }
public List<GroupLocalEntity> GetAllGroup()
{
return GetAllGroups;
}
public GroupLocalEntity? UpdateGroupName(GroupLocalEntity groupUpdateLocalEntity) { public GroupLocalEntity? UpdateGroupName(GroupLocalEntity groupUpdateLocalEntity) {
int index = GetAllGroups.FindIndex(x => x.Id == groupUpdateLocalEntity.Id); int index = GetAllGroups.FindIndex(x => x.Id == groupUpdateLocalEntity.Id);
@ -32,5 +37,22 @@ namespace Demo.Data.Repository
GetAllGroups.Add(groupCreateLocalEntity); GetAllGroups.Add(groupCreateLocalEntity);
return groupCreateLocalEntity; return groupCreateLocalEntity;
} }
public bool RemoveGroupById(int groupID)
{
GroupLocalEntity? groupLocal = GetAllGroups
.Where(x => x.Id == groupID).FirstOrDefault();
if (groupLocal == null) return false;
return GetAllGroups.Remove(groupLocal);
}
public GroupLocalEntity? GetGroupById(int groupID) {
GroupLocalEntity? groupLocal = GetAllGroups
.Where(x => x.Id == groupID).FirstOrDefault();
if (groupLocal == null) return null;
return groupLocal;
}
} }
} }

View File

@ -0,0 +1,18 @@
using Demo.domain.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Demo.Data.Repository
{
public interface IGroupRepository
{
List<GroupLocalEntity> GetAllGroup();
bool RemoveGroupById(int groupID);
GroupLocalEntity? UpdateGroupName(GroupLocalEntity updatedGroup);
GroupLocalEntity? GetGroupById(int groupID);
GroupLocalEntity? CreateGroup(GroupLocalEntity newGroup);
}
}

View File

View File

@ -8,7 +8,7 @@ using System.Threading.Tasks;
namespace Demo.Data.Repository namespace Demo.Data.Repository
{ {
public class UserRepositoryImpl public class UserRepositoryImpl:IUserRepository
{ {
public UserRepositoryImpl() { public UserRepositoryImpl() {
@ -17,6 +17,11 @@ namespace Demo.Data.Repository
public List<UserLocalEntity> GetAllUsers public List<UserLocalEntity> GetAllUsers
{ get; set; } { get; set; }
public List<UserLocalEntity> GetAllUser()
{
return GetAllUsers;
}
public bool RemoveUserByGuid(Guid userGuid) public bool RemoveUserByGuid(Guid userGuid)
{ {
UserLocalEntity? userLocal = GetAllUsers UserLocalEntity? userLocal = GetAllUsers

View File

@ -10,8 +10,8 @@ namespace Demo.Domain.UseCase
{ {
public class UserUseCase public class UserUseCase
{ {
private UserRepositoryImpl _repositoryUserImpl; private readonly UserRepositoryImpl _repositoryUserImpl;
private GroupRepositoryImpl _repositoryGroupImpl; private readonly GroupRepositoryImpl _repositoryGroupImpl;
public UserUseCase(UserRepositoryImpl repositoryImpl, GroupRepositoryImpl repositoryGroupImpl) public UserUseCase(UserRepositoryImpl repositoryImpl, GroupRepositoryImpl repositoryGroupImpl)
{ {
@ -19,7 +19,7 @@ namespace Demo.Domain.UseCase
_repositoryGroupImpl = repositoryGroupImpl; _repositoryGroupImpl = repositoryGroupImpl;
} }
public List<Group> GetAllGroups() => _repositoryGroupImpl.GetAllGroups private List<Group> GetAllGroups() => _repositoryGroupImpl.GetAllGroups
.Select(it => new Group { Id = it.Id, Name = it.Name}).ToList(); .Select(it => new Group { Id = it.Id, Name = it.Name}).ToList();
public List<User> GetAllUsers() => _repositoryUserImpl.GetAllUsers public List<User> GetAllUsers() => _repositoryUserImpl.GetAllUsers
.Join(_repositoryGroupImpl.GetAllGroups, .Join(_repositoryGroupImpl.GetAllGroups,