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
privatereadonlyIIdentityService_identitySvc;
2929
privateITableMapper_tableMapper;
3030

31-
publicJsonController(SelectTable_selectTable,DbContext_db,IIdentityServiceidentityService,ITableMappertableMapper)
31+
publicJsonController(IIdentityServiceidentityService,ITableMappertableMapper,DbContext_db)
3232
{
33-
selectTable=_selectTable;
3433
db=_db;
3534
_tableMapper=tableMapper;
3635
_identitySvc=identityService;
36+
selectTable=newSelectTable(_identitySvc,_tableMapper,_db.Db);
3737
}
3838

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

58-
publicActionResultQuery([FromBody]JObjectjobject)
58+
publicasyncTask<ActionResult>Query([FromBody]JObjectjobject)
5959
{
6060
JObjectresultJobj=newSelectTable(_identitySvc,_tableMapper,db.Db).Query(jobject);
6161
returnOk(resultJobj);
@@ -91,8 +91,7 @@ public async Task<ActionResult> QueryByTable([FromRoute]string table)
9191
jobject.Add(table,newJObject());
9292
}
9393

94-
JObjectresultJobj=newSelectTable(_identitySvc,_tableMapper,db.Db).Query(ht);
95-
returnOk(resultJobj);
94+
returnawaitQuery(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
privateIHttpContextAccessor_context;
1616
privateList<Role>roles;
1717

18-
publicIdentityService(IHttpContextAccessorcontext,IOptions<List<Role>>_roles)
18+
publicIdentityService(IHttpContextAccessorcontext,IOptions<List<Role>>_roles)
1919
{
2020
_context=context??thrownewArgumentNullException(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
publicstringGetUserRoleName()
2929
{
3030
return_context.HttpContext.User.FindFirstValue(ClaimTypes.Role);
@@ -50,7 +50,7 @@ public Role GetRole()
5050
{
5151
return(false,$"appsettings.json权限配置不正确!");
5252
}
53-
stringtablerole=role.Select.Table.FirstOrDefault(it =>it.Equals(table,StringComparison.CurrentCultureIgnoreCase));
53+
stringtablerole=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
<divclass="right-bar">
3333
<selectid="rest-url">
34-
<optionvalue="api/json/get">get</option>
35-
<optionvalue="api/json/add">add</option>
36-
<optionvalue="api/json/edit">edit</option>
37-
<optionvalue="api/json/remove">remove</option>
38-
<optionvalue="api/json/org">org</option>
34+
<optionvalue="get">get</option>
35+
<optionvalue="add">add</option>
36+
<optionvalue="edit">edit</option>
37+
<optionvalue="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
stringkey=item.Key.Trim();
202202
varjb=JObject.Parse(item.Value.ToString());
203203
intpage=jb["page"]==null?0:int.Parse(jb["page"].ToString());
204-
intcount=jb["count"]==null?1:int.Parse(jb["count"].ToString());
205-
intquery=jb["query"]==null?2:int.Parse(jb["query"].ToString());
204+
intcount=jb["count"]==null?10:int.Parse(jb["count"].ToString());
205+
intquery=jb["query"]==null?0:int.Parse(jb["query"].ToString());
206206
inttotal=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
varjb=JObject.Parse(item.Value.ToString());
232232
varpage=jb["page"]==null?0:int.Parse(jb["page"].ToString());
233-
varcount=jb["count"]==null?0:int.Parse(jb["count"].ToString());
233+
varcount=jb["count"]==null?10:int.Parse(jb["count"].ToString());
234234
varquery=jb["query"]==null?0:int.Parse(jb["query"].ToString());
235235
jb.Remove("page");jb.Remove("count");jb.Remove("query");
236236
varhtt=newJArray();

0 commit comments

Comments
(0)