presence_sample_v2/domain/Service/GroupService.cs

83 lines
2.7 KiB
C#
Raw Normal View History

2024-11-22 12:18:04 +00:00
using data.DAO;
using data.Repository;
using domain.Entity;
using domain.Request;
using domain.UseCase;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace domain.Service
{
public class GroupService : IGroupUseCase
{
private readonly IGroupRepository _groupRepository;
public GroupService(IGroupRepository groupRepository)
{
_groupRepository = groupRepository;
}
public void AddGroup(AddGroupRequest addGroupRequest)
{
_groupRepository.addGroup(new GroupDAO { Name = addGroupRequest.Name });
}
public void AddGroupWithSutdents(AddGroupWithStudentsRequest addGroupWithStudents)
{
GroupDAO groupDAO = new GroupDAO { Name = addGroupWithStudents.addGroupRequest.Name };
List<UserDAO> users = addGroupWithStudents
.AddStudentRequests
.Select(it => new UserDAO { Name = it.StudentName })
.ToList();
_groupRepository.addGroupWithStudents(groupDAO, users);
}
public IEnumerable<GroupEntity> GetGroupsWithStudents()
{
return _groupRepository.getAllGroup().Select(
group => new GroupEntity
{
Id = group.Id,
Name = group.Name,
Users = group.Users.Select(
user => new UserEntity
{
Guid = user.Guid,
Name = user.Name,
Group = new GroupEntity
{
Id = group.Id,
Name = group.Name,
}
}).ToList()
}).ToList();
}
2024-11-25 10:47:17 +00:00
public async Task<IEnumerable<GroupEntity>> GetGroupsWithStudentsAsync()
{
var result = await _groupRepository.getAllGroupAsync();
return result.Select(
group => new GroupEntity
{
Id = group.Id,
Name = group.Name,
Users = group.Users.Select(
user => new UserEntity
{
Guid = user.Guid,
Name = user.Name,
Group = new GroupEntity
{
Id = group.Id,
Name = group.Name,
}
}).ToList()
}).ToList();
}
2024-11-22 12:18:04 +00:00
}
}