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> GetUserInfoAsync(Guid userId) { var user = await repository.FindByIdAsync(userId); if (user is null) { return Result.Fail(ResultCode.USER_NOT_FOUND); } return Result.Success(mapper.Map(user)); } public async Task> GetUserInfoByUnameAsync(string username) { var user = await repository.FindByUserNameAsync(username); if (user is null) { return Result.Fail(ResultCode.USER_NOT_FOUND); } return Result.Success(mapper.Map(user)); } public async Task> UpdateAsync(UserUpdateCommand command) { var user = await repository.FindByIdAsync(command.UserId); if (user is null) { return Result.Fail(ResultCode.USER_NOT_FOUND); } user.Update(command.NickName, command.Region, command.Avatar, command.Description); return Result.Success(mapper.Map(user)); } public async Task>> GetUsersByIdsAsync(IEnumerable ids) { var specification = new UserResponseFindSpecification(ids, mapper); var users = await repository.GetUsersAsync(specification); return Result>.Success([.. users]); } } }