更新框架,增加云库搜索模块
This commit is contained in:
1 parent
8526e5e0d2
commit
f2caec6083
192 files changed
+3626
-804
No files matched your search
@@ -0,0 +1,17 @@
|
||||
namespace StoreHub.Services.Dtos;
|
||||
|
||||
/// <summary>
|
||||
/// 用户信息 DTO(对外暴露的用户数据,不包含密码等敏感字段)。
|
||||
/// </summary>
|
||||
public class UserDto
|
||||
{
|
||||
/// <summary>用户ID</summary>
|
||||
public int Id { get; set; }
|
||||
|
||||
/// <summary>登录账户</summary>
|
||||
public string UserName { get; set; } = string.Empty;
|
||||
|
||||
/// <summary>用户昵称</summary>
|
||||
public string NickName { get; set; } = string.Empty;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,19 @@
|
||||
using Riok.Mapperly.Abstractions;
|
||||
using Store.Framework.Models;
|
||||
using StoreHub.Services.Dtos;
|
||||
|
||||
namespace StoreHub.Services.Mappers;
|
||||
|
||||
/// <summary>
|
||||
/// User 实体 → UserDto 映射(Riok.Mapperly 源码生成)。
|
||||
/// UserDto 只暴露部分字段,因此仅要求目标成员都被映射(忽略源端未映射警告)。
|
||||
/// </summary>
|
||||
[Mapper(RequiredMappingStrategy = RequiredMappingStrategy.Target)]
|
||||
public static partial class UserMapper
|
||||
{
|
||||
/// <summary>
|
||||
/// 将用户实体映射为用户 DTO。
|
||||
/// </summary>
|
||||
public static partial UserDto ToDto(User user);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<FrameworkReference Include="Microsoft.AspNetCore.App" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\StoreHub.Framework\Store.Framework.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
@@ -0,0 +1,64 @@
|
||||
using FreeSql;
|
||||
using MAX.Core.Cryptography;
|
||||
using MAX.Core.DependencyInjection;
|
||||
using Store.Framework.Models;
|
||||
using Store.Framework.Repositorys;
|
||||
using StoreHub.Services.Dtos;
|
||||
using StoreHub.Services.Mappers;
|
||||
|
||||
namespace StoreHub.Services;
|
||||
|
||||
/// <summary>
|
||||
/// 用户业务服务:登录校验、用户查询等用例。
|
||||
/// </summary>
|
||||
public interface IUserService
|
||||
{
|
||||
/// <summary>
|
||||
/// 校验用户名/密码,成功返回用户 DTO,失败返回 null。
|
||||
/// </summary>
|
||||
Task<UserDto?> LoginAsync(string userName, string password);
|
||||
|
||||
/// <summary>
|
||||
/// 根据用户ID获取用户 DTO,不存在返回 null。
|
||||
/// </summary>
|
||||
Task<UserDto?> GetByIdAsync(int id);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 用户业务服务实现(<see cref="IScopedDependency"/>,由 AddStoreHub 自动注册)。
|
||||
/// </summary>
|
||||
public class UserService : IUserService, IScopedDependency
|
||||
{
|
||||
private readonly IUserRepository _userRepository;
|
||||
|
||||
public UserService(IUserRepository userRepository)
|
||||
{
|
||||
_userRepository = userRepository;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public async Task<UserDto?> LoginAsync(string userName, string password)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(userName) || string.IsNullOrWhiteSpace(password))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
var sql = _userRepository.Where(u => u.UserName == userName).ToSql();
|
||||
User? user = await _userRepository.Where(u => u.UserName == userName).FirstAsync();
|
||||
string pwd = MD5Helper.Md5_32(password);
|
||||
if (user is null || !string.Equals(user.Password, pwd, StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
return UserMapper.ToDto(user);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public async Task<UserDto?> GetByIdAsync(int id)
|
||||
{
|
||||
User? user = await _userRepository.Where(u => u.Id == id).FirstAsync();
|
||||
return user is null ? null : UserMapper.ToDto(user);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user