添加项目文件。
This commit is contained in:
@@ -0,0 +1,14 @@
|
||||
namespace GroupService.WebApi.Application.Group
|
||||
{
|
||||
public class GroupCreateCommand
|
||||
{
|
||||
public Guid GroupMasterId { get; private set; }
|
||||
public string? Name { get; private set; } = "新建群聊";
|
||||
|
||||
public GroupCreateCommand(Guid groupMasterId, string? name)
|
||||
{
|
||||
GroupMasterId = groupMasterId;
|
||||
Name = name;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
using AutoMapper;
|
||||
using GroupService.WebApi.Application.Dtos;
|
||||
|
||||
namespace GroupService.WebApi.Application.Group
|
||||
{
|
||||
public class GroupMapperConfig : Profile
|
||||
{
|
||||
public GroupMapperConfig()
|
||||
{
|
||||
CreateMap<Domain.Entities.Group, GroupResponse>()
|
||||
.ForMember(dest => dest.Created, opt => opt.MapFrom(src => src.CreationTime))
|
||||
.ForMember(dest => dest.Updated, opt => opt.MapFrom(src => src.ModificationTime))
|
||||
;
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
using AutoMapper;
|
||||
using GroupService.Domain.IReposities;
|
||||
using GroupService.WebApi.Application.Dtos;
|
||||
using IM.Commons;
|
||||
|
||||
namespace GroupService.WebApi.Application.Group
|
||||
{
|
||||
public class GroupService
|
||||
{
|
||||
private readonly IGroupReposity reposity;
|
||||
private readonly IMapper mapper;
|
||||
|
||||
public GroupService(IGroupReposity reposity, IMapper mapper)
|
||||
{
|
||||
this.reposity = reposity;
|
||||
this.mapper = mapper;
|
||||
}
|
||||
|
||||
public async Task<Result<GroupResponse>> CreateAsync(GroupCreateCommand command)
|
||||
{
|
||||
var group = new Domain.Entities.Group(command.GroupMasterId, command.Name);
|
||||
reposity.Create(group);
|
||||
return Result<GroupResponse>.Success(mapper.Map<GroupResponse>(group));
|
||||
}
|
||||
|
||||
public async Task<Result<List<GroupResponse>>> GetAllAsync(Guid userId)
|
||||
{
|
||||
var groups = await reposity.FindByMasterIdAsync(userId);
|
||||
return Result<List<GroupResponse>>.Success(mapper.Map<List<GroupResponse>>(groups));
|
||||
}
|
||||
|
||||
public async Task<Result<GroupResponse>> GetByIdAsync(Guid groupId)
|
||||
{
|
||||
var group = await reposity.FindByIdAsync(groupId);
|
||||
if (group is null)
|
||||
{
|
||||
return Result<GroupResponse>.Fail(ResultCode.GROUP_NOT_FOUND);
|
||||
}
|
||||
|
||||
return Result<GroupResponse>.Success(mapper.Map<GroupResponse>(group));
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user