Merge branch 'dev_add_auth_1029' of http://192.168.5.200:8081/ql/apismnagaer_backend into dev_add_auth_1029
This commit is contained in:
@@ -0,0 +1,40 @@
|
||||
using Apimanager_backend.Dtos;
|
||||
|
||||
namespace Apimanager_backend.Services
|
||||
{
|
||||
public interface IAdminService
|
||||
{
|
||||
/// <summary>
|
||||
/// 禁用用户,使其无法登录。
|
||||
/// </summary>
|
||||
/// <param name="userId">要禁用的用户ID</param>
|
||||
/// <returns>异步操作</returns>
|
||||
Task BanUserAsync(int userId);
|
||||
/// <summary>
|
||||
/// 取消禁用用户,恢复登录权限。
|
||||
/// </summary>
|
||||
/// <param name="userId">要取消禁用的用户ID</param>
|
||||
/// <returns>异步操作</returns>
|
||||
Task UnbanUserAsync(int userId);
|
||||
/// <summary>
|
||||
/// 获取分页的用户列表。
|
||||
/// </summary>
|
||||
/// <param name="page">要获取的页码,从1开始</param>
|
||||
/// <param name="pageSize">每页的用户数量</param>
|
||||
/// <param name="desc">是否按降序排序</param>
|
||||
/// <returns>包含用户信息的 <see cref="List{UserInfoDto}"/></returns>
|
||||
Task<List<UserInfoDto>> GetUsersAsync(int page, int pageSize, bool desc);
|
||||
/// <summary>
|
||||
/// 创建新用户。
|
||||
/// </summary>
|
||||
/// <param name="user">包含新用户信息的 <see cref="CreateUserDto"/></param>
|
||||
/// <returns>创建成功的用户信息 <see cref="UserInfoDto"/></returns>
|
||||
Task<UserInfoDto> CreateUserAsync(CreateUserDto user);
|
||||
/// <summary>
|
||||
/// 删除指定的用户。
|
||||
/// </summary>
|
||||
/// <param name="userId">用户ID</param>
|
||||
/// <returns>异步操作</returns>
|
||||
Task DeleteUserAsync(int userId);
|
||||
}
|
||||
}
|
||||
@@ -35,43 +35,6 @@ namespace Apimanager_backend.Services
|
||||
/// <param name="user">包含更新信息的 <see cref="UpdateUserDto"/></param>
|
||||
/// <returns>更新后的 <see cref="UserInfoDto"/></returns>
|
||||
Task<UserInfoDto> UpdateUserAsync(UpdateUserDto user);
|
||||
|
||||
/// <summary>
|
||||
/// 删除指定的用户。
|
||||
/// </summary>
|
||||
/// <param name="username">要删除的用户名</param>
|
||||
/// <returns>异步操作</returns>
|
||||
Task DeleteUserAsync(string username);
|
||||
|
||||
/// <summary>
|
||||
/// 创建新用户。
|
||||
/// </summary>
|
||||
/// <param name="user">包含新用户信息的 <see cref="CreateUserDto"/></param>
|
||||
/// <returns>创建成功的用户信息 <see cref="UserInfoDto"/></returns>
|
||||
Task<UserInfoDto> CreateUserAsync(CreateUserDto user);
|
||||
|
||||
/// <summary>
|
||||
/// 禁用用户,使其无法登录。
|
||||
/// </summary>
|
||||
/// <param name="username">要禁用的用户名</param>
|
||||
/// <returns>异步操作</returns>
|
||||
Task BanUserAsync(string username);
|
||||
|
||||
/// <summary>
|
||||
/// 取消禁用用户,恢复登录权限。
|
||||
/// </summary>
|
||||
/// <param name="username">要取消禁用的用户名</param>
|
||||
/// <returns>异步操作</returns>
|
||||
Task UnbanUserAsync(string username);
|
||||
|
||||
/// <summary>
|
||||
/// 获取分页的用户列表。
|
||||
/// </summary>
|
||||
/// <param name="page">要获取的页码,从1开始</param>
|
||||
/// <param name="pageSize">每页的用户数量</param>
|
||||
/// <param name="desc">是否按降序排序</param>
|
||||
/// <returns>包含用户信息的 <see cref="List{UserInfoDto}"/></returns>
|
||||
Task<List<UserInfoDto>> GetUsersAsync(int page, int pageSize, bool desc);
|
||||
/// <summary>
|
||||
/// 检测用户名是否被使用
|
||||
/// </summary>
|
||||
|
||||
@@ -19,21 +19,6 @@ namespace Apimanager_backend.Services
|
||||
this.apiContext = apiContext;
|
||||
this.mapper = automapper;
|
||||
}
|
||||
public Task BanUserAsync(string username)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public Task<UserInfoDto> CreateUserAsync(CreateUserDto user)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public Task DeleteUserAsync(string username)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public async Task<UserInfoDto> GetUserAsync(int userId)
|
||||
{
|
||||
User? user = await apiContext.Users.SingleOrDefaultAsync(x => x.Id == userId);
|
||||
@@ -45,11 +30,6 @@ namespace Apimanager_backend.Services
|
||||
return mapper.Map<UserInfoDto>(user);
|
||||
}
|
||||
|
||||
public Task<List<UserInfoDto>> GetUsersAsync(int page, int pageSize, bool desc)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public async Task<bool> IsEmailExist(string email)
|
||||
{
|
||||
return await apiContext.Users.AnyAsync(x => x.Email == email);
|
||||
@@ -70,14 +50,19 @@ namespace Apimanager_backend.Services
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public Task UnbanUserAsync(string username)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public Task<UserInfoDto> UpdateUserAsync(UpdateUserDto user)
|
||||
public async Task<UserInfoDto> UpdateUserAsync(UpdateUserDto dto)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
var user = await apiContext.Users.FirstOrDefaultAsync(x => x.Id == dto.userId);
|
||||
if (user == null)
|
||||
{
|
||||
throw new BaseException(2004, "用户不存在");
|
||||
}
|
||||
user.PassHash = dto.password == null ? user.PassHash : dto.password;
|
||||
|
||||
apiContext.Users.Update(user);
|
||||
await apiContext.SaveChangesAsync();
|
||||
return mapper.Map<UserInfoDto>(user);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user