38 lines
1.2 KiB
C#
38 lines
1.2 KiB
C#
using Common;
|
|||
|
|
using CommonInfrastructure;
|
||
|
|
using Domain.Admin.Admin;
|
||
|
|
using Microsoft.AspNetCore.Mvc;
|
||
|
|
using MongoRepository;
|
||
|
|
|
||
|
|
namespace UserApi.Dict
|
||
|
|
{
|
||
|
|
[ApiController, Route("api/[controller]")]
|
||
|
|
public class DictController : BaseController
|
||
|
|
{
|
||
|
|
private readonly IMongoBaseRepository<SystemDic> _dicRepo;
|
||
|
|
|
||
|
|
public DictController(IMongoBaseRepository<SystemDic> dicRepo)
|
||
|
|
{
|
||
|
|
_dicRepo = dicRepo;
|
||
|
|
}
|
||
|
|
|
||
|
|
[HttpGet("GetByCode")]
|
||
|
|
public async Task<BaseResponse<SystemDic>> GetByCode(string code)
|
||
|
|
{
|
||
|
|
var dic = await _dicRepo.FindOneAsync(c => c.IsDelete == false && c.Code == code);
|
||
|
|
return this.ToResult(dic);
|
||
|
|
}
|
||
|
|
|
||
|
|
[HttpGet("GetListByCode")]
|
||
|
|
public async Task<BaseResponse<List<SystemDic>>> GetListByCode(string code)
|
||
|
|
{
|
||
|
|
var all = await _dicRepo.FilterByAsync(c => c.IsDelete == false);
|
||
|
|
var parent = all.FirstOrDefault(c => c.Code == code);
|
||
|
|
if (parent == null)
|
||
|
|
return this.ToResult(new List<SystemDic>());
|
||
|
|
var children = all.Where(c => c.ParentId == parent.Id).OrderBy(c => c.Order).ToList();
|
||
|
|
return this.ToResult(children);
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|