Skip to content

Commit 2212822

Browse files
committed
1:增加对所有表“*”的支持
2:添加/{table} 单表查询的接口
1 parent 2e830c4 commit 2212822

File tree

4 files changed

+15
-16
lines changed

4 files changed

+15
-16
lines changed

APIJSON.NET/APIJSON.NET/Controllers/JsonController.cs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,12 @@ public class JsonController : ControllerBase
2828
private readonly IIdentityService _identitySvc;
2929
private ITableMapper _tableMapper;
3030

31-
public JsonController(SelectTable _selectTable, DbContext _db, IIdentityService identityService, ITableMapper tableMapper)
31+
public JsonController(IIdentityService identityService, ITableMapper tableMapper, DbContext _db)
3232
{
33-
selectTable = _selectTable;
3433
db = _db;
3534
_tableMapper = tableMapper;
3635
_identitySvc = identityService;
36+
selectTable = new SelectTable(_identitySvc, _tableMapper, _db.Db);
3737
}
3838

3939
/// <summary>
@@ -55,7 +55,7 @@ public ActionResult Test()
5555
/// <returns></returns>
5656
[HttpPost("/get")]
5757

58-
public ActionResult Query([FromBody] JObject jobject)
58+
public async Task<ActionResult> Query([FromBody] JObject jobject)
5959
{
6060
JObject resultJobj = new SelectTable(_identitySvc, _tableMapper, db.Db).Query(jobject);
6161
return Ok(resultJobj);
@@ -91,8 +91,7 @@ public async Task<ActionResult> QueryByTable([FromRoute]string table)
9191
jobject.Add(table, new JObject());
9292
}
9393

94-
JObject resultJobj = new SelectTable(_identitySvc, _tableMapper, db.Db).Query(ht);
95-
return Ok(resultJobj);
94+
return await Query(ht);
9695
}
9796
/// <summary>
9897
/// 新增

APIJSON.NET/APIJSON.NET/Services/IdentityService.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ public class IdentityService : IIdentityService
1515
private IHttpContextAccessor _context;
1616
private List<Role> roles;
1717

18-
public IdentityService(IHttpContextAccessor context,IOptions<List<Role>> _roles)
18+
public IdentityService(IHttpContextAccessor context, IOptions<List<Role>> _roles)
1919
{
2020
_context = context ?? throw new ArgumentNullException(nameof(context));
2121
roles = _roles.Value;
@@ -24,7 +24,7 @@ public string GetUserIdentity()
2424
{
2525
return _context.HttpContext.User.FindFirstValue(ClaimTypes.NameIdentifier);
2626
}
27-
27+
2828
public string GetUserRoleName()
2929
{
3030
return _context.HttpContext.User.FindFirstValue(ClaimTypes.Role);
@@ -50,7 +50,7 @@ public Role GetRole()
5050
{
5151
return (false, $"appsettings.json权限配置不正确!");
5252
}
53-
string tablerole = role.Select.Table.FirstOrDefault(it => it.Equals(table, StringComparison.CurrentCultureIgnoreCase));
53+
string tablerole = role.Select.Table.FirstOrDefault(it => it == "*" || it.Equals(table, StringComparison.CurrentCultureIgnoreCase));
5454

5555
if (string.IsNullOrEmpty(tablerole))
5656
{

APIJSON.NET/APIJSON.NET/wwwroot/index.html

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,11 @@
3131
<div :class="'side-left side-view-' + baseview">
3232
<div class="right-bar">
3333
<select id="rest-url">
34-
<option value="api/json/get">get</option>
35-
<option value="api/json/add">add</option>
36-
<option value="api/json/edit">edit</option>
37-
<option value="api/json/remove">remove</option>
38-
<option value="api/json/org">org</option>
34+
<option value="get">get</option>
35+
<option value="add">add</option>
36+
<option value="edit">edit</option>
37+
<option value="remove">remove</option>
38+
<!--<option value="org">org</option>-->
3939

4040
</select>
4141
<button @click="hpost()">发送请求</button>

APIJSON.NET/APIJSONCommon/SelectTable.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -201,8 +201,8 @@ private int QuerySingleList(JObject resultObj, KeyValuePair<string, JToken> item
201201
string key = item.Key.Trim();
202202
var jb = JObject.Parse(item.Value.ToString());
203203
int page = jb["page"] == null ? 0 : int.Parse(jb["page"].ToString());
204-
int count = jb["count"] == null ? 1 : int.Parse(jb["count"].ToString());
205-
int query = jb["query"] == null ? 2 : int.Parse(jb["query"].ToString());
204+
int count = jb["count"] == null ? 10 : int.Parse(jb["count"].ToString());
205+
int query = jb["query"] == null ? 0 : int.Parse(jb["query"].ToString());
206206
int total = 0;
207207

208208
jb.Remove("page"); jb.Remove("count"); jb.Remove("query");
@@ -230,7 +230,7 @@ private int QueryMoreList(JObject resultObj, KeyValuePair<string, JToken> item)
230230

231231
var jb = JObject.Parse(item.Value.ToString());
232232
var page = jb["page"] == null ? 0 : int.Parse(jb["page"].ToString());
233-
var count = jb["count"] == null ? 0 : int.Parse(jb["count"].ToString());
233+
var count = jb["count"] == null ? 10 : int.Parse(jb["count"].ToString());
234234
var query = jb["query"] == null ? 0 : int.Parse(jb["query"].ToString());
235235
jb.Remove("page"); jb.Remove("count"); jb.Remove("query");
236236
var htt = new JArray();

0 commit comments

Comments
 (0)