feat: token 下拉列表支持可选是否包含默认项
为 GetSelectListAsync 接口新增 includeDefault 查询参数,允许调用方控制是否返回“默认”选项,默认保持原有行为。
This commit is contained in:
@@ -26,6 +26,7 @@ public class TokenService : ApplicationService
|
|||||||
private readonly ISqlSugarRepository<TokenAggregateRoot> _tokenRepository;
|
private readonly ISqlSugarRepository<TokenAggregateRoot> _tokenRepository;
|
||||||
private readonly ISqlSugarRepository<UsageStatisticsAggregateRoot> _usageStatisticsRepository;
|
private readonly ISqlSugarRepository<UsageStatisticsAggregateRoot> _usageStatisticsRepository;
|
||||||
private readonly ModelManager _modelManager;
|
private readonly ModelManager _modelManager;
|
||||||
|
|
||||||
public TokenService(
|
public TokenService(
|
||||||
ISqlSugarRepository<TokenAggregateRoot> tokenRepository,
|
ISqlSugarRepository<TokenAggregateRoot> tokenRepository,
|
||||||
ISqlSugarRepository<UsageStatisticsAggregateRoot> usageStatisticsRepository,
|
ISqlSugarRepository<UsageStatisticsAggregateRoot> usageStatisticsRepository,
|
||||||
@@ -90,7 +91,7 @@ public class TokenService : ApplicationService
|
|||||||
}
|
}
|
||||||
|
|
||||||
[HttpGet("token/select-list")]
|
[HttpGet("token/select-list")]
|
||||||
public async Task<List<TokenSelectListOutputDto>> GetSelectListAsync()
|
public async Task<List<TokenSelectListOutputDto>> GetSelectListAsync([FromQuery] bool? includeDefault = true)
|
||||||
{
|
{
|
||||||
var userId = CurrentUser.GetId();
|
var userId = CurrentUser.GetId();
|
||||||
var tokens = await _tokenRepository._DbQueryable
|
var tokens = await _tokenRepository._DbQueryable
|
||||||
@@ -104,12 +105,16 @@ public class TokenService : ApplicationService
|
|||||||
IsDisabled = x.IsDisabled
|
IsDisabled = x.IsDisabled
|
||||||
}).ToListAsync();
|
}).ToListAsync();
|
||||||
|
|
||||||
tokens.Insert(0,new TokenSelectListOutputDto
|
if (includeDefault == true)
|
||||||
|
{
|
||||||
|
tokens.Insert(0, new TokenSelectListOutputDto
|
||||||
{
|
{
|
||||||
TokenId = Guid.Empty,
|
TokenId = Guid.Empty,
|
||||||
Name = "默认",
|
Name = "默认",
|
||||||
IsDisabled = false
|
IsDisabled = false
|
||||||
});
|
});
|
||||||
|
}
|
||||||
|
|
||||||
return tokens;
|
return tokens;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user