更新仓储层上下文对象与接口命名规范

This commit is contained in:
chenchun
2022-04-12 18:09:13 +08:00
parent e7a27cc474
commit 796bba1abe
9 changed files with 57 additions and 7 deletions

Binary file not shown.

View File

@@ -6,11 +6,11 @@
<members> <members>
<member name="T:Yi.Framework.ApiMicroservice.Controllers.BaseCrudController`1"> <member name="T:Yi.Framework.ApiMicroservice.Controllers.BaseCrudController`1">
<summary> <summary>
6666 Json To Sql 类比模式,通用模型
</summary> </summary>
<typeparam name="T"></typeparam> <typeparam name="T"></typeparam>
</member> </member>
<member name="M:Yi.Framework.ApiMicroservice.Controllers.BaseCrudController`1.Get(System.Int64)"> <member name="M:Yi.Framework.ApiMicroservice.Controllers.BaseCrudController`1.GetById(System.Int64)">
<summary> <summary>
主键查询 主键查询
</summary> </summary>
@@ -23,7 +23,7 @@
</summary> </summary>
<returns></returns> <returns></returns>
</member> </member>
<member name="M:Yi.Framework.ApiMicroservice.Controllers.BaseCrudController`1.Page(Yi.Framework.Model.Query.QueryPageCondition)"> <member name="M:Yi.Framework.ApiMicroservice.Controllers.BaseCrudController`1.PageList(Yi.Framework.Model.Query.QueryPageCondition)">
<summary> <summary>
条件分页查询 条件分页查询
</summary> </summary>
@@ -51,6 +51,12 @@
<param name="ids"></param> <param name="ids"></param>
<returns></returns> <returns></returns>
</member> </member>
<member name="M:Yi.Framework.ApiMicroservice.Controllers.TestController.DbTest">
<summary>
仓储上下文对象测试
</summary>
<returns></returns>
</member>
<member name="M:Yi.Framework.ApiMicroservice.Controllers.TestController.LocalTest"> <member name="M:Yi.Framework.ApiMicroservice.Controllers.TestController.LocalTest">
<summary> <summary>
国际化测试 国际化测试

View File

@@ -11,7 +11,7 @@ using Yi.Framework.WebCore.AttributeExtend;
namespace Yi.Framework.ApiMicroservice.Controllers namespace Yi.Framework.ApiMicroservice.Controllers
{ {
/// <summary> /// <summary>
/// 6666 /// Json To Sql 类比模式,通用模型
/// </summary> /// </summary>
/// <typeparam name="T"></typeparam> /// <typeparam name="T"></typeparam>
[ApiController] [ApiController]
@@ -35,7 +35,7 @@ namespace Yi.Framework.ApiMicroservice.Controllers
/// <returns></returns> /// <returns></returns>
[Permission($"{nameof(T)}:get:one")] [Permission($"{nameof(T)}:get:one")]
[HttpGet] [HttpGet]
public async Task<Result> Get(long id) public async Task<Result> GetById(long id)
{ {
return Result.Success().SetData(await _repository.GetByIdAsync(id)); return Result.Success().SetData(await _repository.GetByIdAsync(id));
} }
@@ -58,7 +58,7 @@ namespace Yi.Framework.ApiMicroservice.Controllers
/// <returns></returns> /// <returns></returns>
[Permission($"{nameof(T)}:get:page")] [Permission($"{nameof(T)}:get:page")]
[HttpPost] [HttpPost]
public async Task<Result> Page(QueryPageCondition queryCondition) public async Task<Result> PageList(QueryPageCondition queryCondition)
{ {
return Result.Success().SetData(await _repository.CommonPageAsync(queryCondition)); return Result.Success().SetData(await _repository.CommonPageAsync(queryCondition));
} }

View File

@@ -22,10 +22,24 @@ namespace Yi.Framework.ApiMicroservice.Controllers
public class TestController : ControllerBase public class TestController : ControllerBase
{ {
private IStringLocalizer<LocalLanguage> _local; private IStringLocalizer<LocalLanguage> _local;
private IUserService _iUserService;
public TestController(ILogger<UserEntity> logger, IUserService iUserService, IStringLocalizer<LocalLanguage> local) public TestController(ILogger<UserEntity> logger, IUserService iUserService, IStringLocalizer<LocalLanguage> local)
{ {
_local = local; _local = local;
_iUserService = iUserService;
} }
/// <summary>
/// 仓储上下文对象测试
/// </summary>
/// <returns></returns>
[HttpGet]
/// 特点:仓储代理上下文对象,用起来就是爽
public async Task<Result> DbTest()
{
return Result.Success().SetData(await _iUserService.DbTest());
}
/// <summary> /// <summary>
/// 国际化测试 /// 国际化测试
/// </summary> /// </summary>

View File

@@ -19,8 +19,10 @@ namespace Yi.Framework.ApiMicroservice.Controllers
[Route("api/[controller]/[action]")] [Route("api/[controller]/[action]")]
public class UserController : BaseCrudController<UserEntity> public class UserController : BaseCrudController<UserEntity>
{ {
private IUserService _iUserService;
public UserController(ILogger<UserEntity> logger, IUserService iUserService) : base(logger, iUserService) public UserController(ILogger<UserEntity> logger, IUserService iUserService) : base(logger, iUserService)
{ {
_iUserService = iUserService;
} }
} }
} }

View File

@@ -1,4 +1,5 @@
using System; using System;
using System.Collections.Generic;
using System.Threading.Tasks; using System.Threading.Tasks;
using Yi.Framework.Model.Models; using Yi.Framework.Model.Models;
using Yi.Framework.Repository; using Yi.Framework.Repository;
@@ -7,7 +8,27 @@ namespace Yi.Framework.Interface
{ {
public partial interface IUserService public partial interface IUserService
{ {
/// <summary>
/// 测试仓储的上下文对象
/// </summary>
/// <returns></returns>
public Task<List<UserEntity>> DbTest();
/// <summary>
/// 登录方法
/// </summary>
/// <param name="userName"></param>
/// <param name="password"></param>
/// <param name="userAction"></param>
/// <returns></returns>
public Task<bool> Login(string userName, string password, Action<UserEntity> userAction = null); public Task<bool> Login(string userName, string password, Action<UserEntity> userAction = null);
/// <summary>
/// 注册方法
/// </summary>
/// <param name="userEntity"></param>
/// <param name="userAction"></param>
/// <returns></returns>
public Task<bool> Register(UserEntity userEntity, Action<UserEntity> userAction = null); public Task<bool> Register(UserEntity userEntity, Action<UserEntity> userAction = null);
} }
} }

View File

@@ -13,6 +13,7 @@ namespace Yi.Framework.Repository
{ {
public interface IRepository<T> : ISimpleClient<T> where T : BaseModelEntity,new() public interface IRepository<T> : ISimpleClient<T> where T : BaseModelEntity,new()
{ {
public ISqlSugarClient _Db { get; set; }
public Task<T> InsertReturnEntityAsync(T entity); public Task<T> InsertReturnEntityAsync(T entity);
public Task<List<S>> StoreAsync<S>(string storeName, object para); public Task<List<S>> StoreAsync<S>(string storeName, object para);
public Task<PageModel<List<T>>> CommonPageAsync(QueryPageCondition pars); public Task<PageModel<List<T>>> CommonPageAsync(QueryPageCondition pars);

View File

@@ -14,13 +14,14 @@ namespace Yi.Framework.Repository
/// <typeparam name="T"></typeparam> /// <typeparam name="T"></typeparam>
public class Repository<T> : DataContext<T>, IRepository<T> where T : BaseModelEntity,new() public class Repository<T> : DataContext<T>, IRepository<T> where T : BaseModelEntity,new()
{ {
public ISqlSugarClient _Db { get; set; }
/// <summary> /// <summary>
/// 构造函数 /// 构造函数
/// </summary> /// </summary>
/// <param name="context"></param> /// <param name="context"></param>
public Repository(ISqlSugarClient context) : base(context)//注意这里要有默认值等于null public Repository(ISqlSugarClient context) : base(context)//注意这里要有默认值等于null
{ {
_Db = context;
} }

View File

@@ -1,5 +1,6 @@
using SqlSugar; using SqlSugar;
using System; using System;
using System.Collections.Generic;
using System.Threading; using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
using Yi.Framework.Interface; using Yi.Framework.Interface;
@@ -10,6 +11,10 @@ namespace Yi.Framework.Service
{ {
public partial class UserService public partial class UserService
{ {
public async Task<List<UserEntity>> DbTest()
{
return await _repository._Db.Queryable<UserEntity>().ToListAsync();
}
public async Task<bool> Exist(Guid id, Action<UserEntity> userAction = null) public async Task<bool> Exist(Guid id, Action<UserEntity> userAction = null)
{ {
var user = await _repository.GetByIdAsync(id); var user = await _repository.GetByIdAsync(id);