fix: align backend APIs and upload flow
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
using AutoMapper;
|
||||
using AutoMapper;
|
||||
using GroupService.Domain;
|
||||
using GroupService.Domain.IReposities;
|
||||
using GroupService.WebApi.Application.Dtos;
|
||||
@@ -13,24 +13,28 @@ namespace GroupService.WebApi.Application.GroupMember
|
||||
private readonly IGroupReposity groupReposity;
|
||||
private readonly GroupMemberDomainService service;
|
||||
private readonly IIdentityIntegrationService idService;
|
||||
private IMapper mapper;
|
||||
private IMapper mapper; private readonly IM.InitCommon.Management.RuntimePolicy runtime;
|
||||
|
||||
public GroupMemberService(IGroupMemberReposity reposity, IGroupReposity groupReposity, GroupMemberDomainService service, IIdentityIntegrationService idService, IMapper mapper)
|
||||
public GroupMemberService(IGroupMemberReposity reposity, IGroupReposity groupReposity, GroupMemberDomainService service, IIdentityIntegrationService idService, IMapper mapper, IM.InitCommon.Management.RuntimePolicy runtime)
|
||||
{
|
||||
this.reposity = reposity;
|
||||
this.groupReposity = groupReposity;
|
||||
this.service = service;
|
||||
this.idService = idService;
|
||||
this.mapper = mapper;
|
||||
this.mapper = mapper; this.runtime = runtime;
|
||||
}
|
||||
|
||||
public async Task<Result<List<GroupMemberResponse>>> GetByGroupIdAsync(Guid groupId)
|
||||
public async Task<Result<List<GroupMemberResponse>>> GetByGroupIdAsync(Guid groupId, Guid userId)
|
||||
{
|
||||
var group = await groupReposity.FindByIdAsync(groupId);
|
||||
if (group is null)
|
||||
{
|
||||
return Result<List<GroupMemberResponse>>.Fail(ResultCode.GROUP_NOT_FOUND);
|
||||
}
|
||||
if (!await reposity.CheckMemberExistAsync(groupId, userId))
|
||||
{
|
||||
return Result<List<GroupMemberResponse>>.Fail(ResultCode.PERMISSION_DENIED);
|
||||
}
|
||||
var members = await reposity.FindByGroupIdAsync(groupId);
|
||||
|
||||
return Result<List<GroupMemberResponse>>.Success(mapper.Map<List<GroupMemberResponse>>(members.ToList()));
|
||||
@@ -45,6 +49,9 @@ namespace GroupService.WebApi.Application.GroupMember
|
||||
return Result<GroupMemberResponse>.Fail(ResultCode.GROUP_NOT_FOUND);
|
||||
}
|
||||
|
||||
if (group.Status != Domain.Enums.GroupState.Normal) throw new IM.DomainCommons.DomainException("群组已被封禁,不能加入");
|
||||
var limit = runtime.Current.GroupMemberLimit;
|
||||
if (limit > 0 && (await reposity.FindByGroupIdAsync(groupId)).Count() >= limit) throw new IM.DomainCommons.DomainException("群成员数量已达到平台上限");
|
||||
var userRes = await idService.FindUserByIdAsync(userId);
|
||||
if (!userRes.Succeeded)
|
||||
{
|
||||
@@ -64,7 +71,7 @@ namespace GroupService.WebApi.Application.GroupMember
|
||||
|
||||
public async Task<Result<bool>> CheckMemberAsync(Guid groupId, Guid userId)
|
||||
{
|
||||
var exist = await reposity.CheckMemberExistAsync(groupId, userId);
|
||||
var group = await groupReposity.FindByIdAsync(groupId); var exist = group?.Status == Domain.Enums.GroupState.Normal && await reposity.CheckMemberExistAsync(groupId, userId);
|
||||
|
||||
return Result.Success(exist);
|
||||
}
|
||||
@@ -78,14 +85,32 @@ namespace GroupService.WebApi.Application.GroupMember
|
||||
}
|
||||
|
||||
var operatorMember = await reposity.FindOneByGroupIdAndUserIdAsync(member.GroupId, operatorId);
|
||||
if (operatorMember is null || operatorMember.Role == Domain.Enums.GroupMemberRole.Normal)
|
||||
if (operatorMember is null || operatorMember.Id == member.Id ||
|
||||
member.Role == Domain.Enums.GroupMemberRole.Master ||
|
||||
operatorMember.Role <= member.Role)
|
||||
{
|
||||
return Result.Fail(ResultCode.PERMISSION_DENIED);
|
||||
}
|
||||
|
||||
member.SoftDelete();
|
||||
member.Leave();
|
||||
|
||||
return Result.Success();
|
||||
}
|
||||
|
||||
public async Task<Result<object>> LeaveAsync(Guid groupId, Guid userId)
|
||||
{
|
||||
var member = await reposity.FindOneByGroupIdAndUserIdAsync(groupId, userId);
|
||||
if (member is null)
|
||||
{
|
||||
return Result.Fail(ResultCode.GROUP_MEMBER_NOT_FOUNT);
|
||||
}
|
||||
if (member.Role == Domain.Enums.GroupMemberRole.Master)
|
||||
{
|
||||
return Result.Fail<object>(ResultCode.PERMISSION_DENIED, "群主不能直接退群,请使用解散群接口");
|
||||
}
|
||||
|
||||
member.Leave();
|
||||
return Result.Success();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user