添加项目文件。
This commit is contained in:
@@ -0,0 +1,35 @@
|
||||
using AutoMapper;
|
||||
using IdentityService.WebApi.Applications.Dtos.Common;
|
||||
using IM.Commons;
|
||||
using System.Linq.Expressions;
|
||||
|
||||
namespace IdentityService.WebApi.Applications.User
|
||||
{
|
||||
public class UserResponseFindSpecification : ISpecification<Domain.Entities.User, UserResponse>
|
||||
{
|
||||
private readonly IEnumerable<Guid> Ids;
|
||||
public UserResponseFindSpecification(IEnumerable<Guid> ids, IMapper mapper)
|
||||
{
|
||||
Ids = ids;
|
||||
Criteria = u => Ids.Contains(u.Id);
|
||||
Select = u => new UserResponse
|
||||
{
|
||||
Avatar = u.Avatar,
|
||||
CreationTime = u.CreationTime,
|
||||
Deletion = u.Deletion,
|
||||
Description = u.Description,
|
||||
Email = u.Email,
|
||||
Id = u.Id,
|
||||
Phone = u.PhoneNumber,
|
||||
Region = u.Region,
|
||||
UserName = u.UserName
|
||||
};
|
||||
}
|
||||
|
||||
public Expression<Func<Domain.Entities.User, bool>> Criteria { get; }
|
||||
|
||||
public List<Expression<Func<Domain.Entities.User, object>>> Includes { get; }
|
||||
|
||||
public Expression<Func<Domain.Entities.User, UserResponse>> Select { get; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
using AutoMapper;
|
||||
using IdentityService.Domain;
|
||||
using IdentityService.Infrastructure;
|
||||
using IdentityService.WebApi.Applications.Dtos.Common;
|
||||
using IM.Commons;
|
||||
|
||||
namespace IdentityService.WebApi.Applications.User
|
||||
{
|
||||
public class UserService
|
||||
{
|
||||
private readonly IIdRepository repository;
|
||||
private readonly IMapper mapper;
|
||||
private readonly UserDbContext userDb;
|
||||
|
||||
public UserService(IIdRepository repository, IMapper mapper,
|
||||
UserDbContext userDbContext
|
||||
)
|
||||
{
|
||||
this.repository = repository;
|
||||
this.mapper = mapper;
|
||||
userDb = userDbContext;
|
||||
}
|
||||
|
||||
public async Task<Result<UserResponse?>> GetUserInfoAsync(Guid userId)
|
||||
{
|
||||
var user = await repository.FindByIdAsync(userId);
|
||||
if (user is null)
|
||||
{
|
||||
return Result<UserResponse?>.Fail(ResultCode.USER_NOT_FOUND);
|
||||
}
|
||||
|
||||
return Result<UserResponse?>.Success(mapper.Map<UserResponse>(user));
|
||||
}
|
||||
|
||||
public async Task<Result<UserResponse>> UpdateAsync(UserUpdateCommand command)
|
||||
{
|
||||
var user = await repository.FindByIdAsync(command.UserId);
|
||||
if (user is null)
|
||||
{
|
||||
return Result<UserResponse>.Fail(ResultCode.USER_NOT_FOUND);
|
||||
}
|
||||
user.Update(command.NickName, command.Region, command.Avatar, command.Description);
|
||||
|
||||
return Result<UserResponse>.Success(mapper.Map<UserResponse>(user));
|
||||
}
|
||||
|
||||
public async Task<Result<List<UserResponse>>> GetUsersByIdsAsync(IEnumerable<Guid> ids)
|
||||
{
|
||||
var specification = new UserResponseFindSpecification(ids, mapper);
|
||||
var users = await repository.GetUsersAsync(specification);
|
||||
return Result<List<UserResponse>>.Success([.. users]);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
namespace IdentityService.WebApi.Applications.User
|
||||
{
|
||||
public class UserUpdateCommand
|
||||
{
|
||||
public Guid UserId { get; private set; }
|
||||
public string? NickName { get; private set; }
|
||||
public string? Region { get; private set; }
|
||||
public string? Avatar { get; private set; }
|
||||
public string? Description { get; private set; }
|
||||
|
||||
public UserUpdateCommand(Guid userId, string? nickName, string? region, string? avatar, string? description)
|
||||
{
|
||||
UserId = userId;
|
||||
NickName = nickName;
|
||||
Region = region;
|
||||
Avatar = avatar;
|
||||
Description = description;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user