84 lines
2.4 KiB
C#
84 lines
2.4 KiB
C#
using Apimanager_backend.Config;
|
|
using Apimanager_backend.Data;
|
|
using Apimanager_backend.Dtos;
|
|
using Apimanager_backend.Exceptions;
|
|
using Apimanager_backend.Models;
|
|
using AutoMapper;
|
|
using Microsoft.AspNetCore.Connections.Features;
|
|
using Microsoft.EntityFrameworkCore;
|
|
using System.ComponentModel;
|
|
|
|
namespace Apimanager_backend.Services
|
|
{
|
|
public class UserService : IUserService
|
|
{
|
|
private readonly ApiContext apiContext;
|
|
private readonly IMapper mapper;
|
|
public UserService(ApiContext apiContext,IMapper automapper)
|
|
{
|
|
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);
|
|
//未找到用户
|
|
if (user == null)
|
|
{
|
|
throw new BaseException(2004, "User not found");
|
|
}
|
|
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);
|
|
}
|
|
|
|
public async Task<bool> IsUsernameExist(string username)
|
|
{
|
|
return await apiContext.Users.AnyAsync(x => x.Username == username);
|
|
}
|
|
|
|
public Task ResetPasswordAsync(string email, string token, string newPassword)
|
|
{
|
|
throw new NotImplementedException();
|
|
}
|
|
|
|
public Task SendResetPasswordEmailAsync(string email)
|
|
{
|
|
throw new NotImplementedException();
|
|
}
|
|
|
|
public Task UnbanUserAsync(string username)
|
|
{
|
|
throw new NotImplementedException();
|
|
}
|
|
|
|
public Task<UserInfoDto> UpdateUserAsync(UpdateUserDto user)
|
|
{
|
|
throw new NotImplementedException();
|
|
}
|
|
}
|
|
}
|