Browse Source

测试api分组

lcl 10 months ago
parent
commit
5c02a18e16

+ 9 - 9
Controllers/ApiGroupController.cs

@@ -41,9 +41,9 @@ namespace Controllers
         /// <returns>api接口分组列表</returns>
         [HttpGet]
         [Route("/v1/api/ApiGroup/list")]
-        public IActionResult List([FromQuery] ApiGroupListDto parm)
+        public IActionResult List([FromQuery] PagerInfo page, [FromQuery] ApiGroupListDto parm)
         {
-            var response = _ApiGroupService.List(parm);
+            var response = _ApiGroupService.List(page, parm);
             return SUCCESS(response);
         }
 
@@ -59,7 +59,7 @@ namespace Controllers
         [Route("/v1/api/ApiGroup/query")]
         public IActionResult Query([FromQuery] ApiGroupQueryDto parm)
         {
-            var response = _ApiGroupService.GetFirst(x => x.Id == parm.Id).Adapt<ApiGroupQueryVo>();
+            var response = _ApiGroupService.GetFirst(x => x.id == parm.id).Adapt<ApiGroupQueryVo>();
             return SUCCESS(response);
         }
 
@@ -77,7 +77,7 @@ namespace Controllers
         {
             var modal = parm.Adapt<ApiGroup>().ToCreate(HttpContext);
             var response = _ApiGroupService.Add(modal);
-            return ToResponse(response);
+            return SUCCESS(response);
         }
 
 
@@ -94,7 +94,7 @@ namespace Controllers
         {
             var modal = parm.Adapt<ApiGroup>().ToUpdate(HttpContext);
             var response = _ApiGroupService.Update(modal, true);
-            return ToResponse(response);
+            return SUCCESS(response);
         }
 
 
@@ -106,11 +106,11 @@ namespace Controllers
         /// <param name="Id">ID</param>
         /// <returns>api接口分组删除</returns>
         [HttpDelete]
-        [Route("/v1/api/ApiGroup/delete/{Id}")]
-        public IActionResult Delete(int Id)
+        [Route("/v1/api/ApiGroup/delete/{id}")]
+        public IActionResult Delete(int id)
         {
-            var response = _ApiGroupService.Delete(Id);
-            return ToResponse(response);
+            var response = _ApiGroupService.Delete(id);
+            return SUCCESS(response);
         }
 
 

+ 1 - 1
Controllers/Base/BaseController.cs

@@ -138,7 +138,7 @@ namespace Controllers
                 DateFormatString = timeFormatStr
             };
 
-            return JsonConvert.SerializeObject(apiResult, Formatting.Indented, serializerSettings);
+            return JsonConvert.SerializeObject(apiResult, Formatting.None, serializerSettings);
         }
         #endregion
 

+ 14 - 6
Filters/AuthorizationFilter.cs

@@ -36,18 +36,26 @@ namespace Filters
                 content = content.Substring(content.IndexOf("=") + 1);
                 content = HttpUtility.UrlDecode(content);
                 content = Decrypt(content);
-                Dictionary<string, string> dic = Newtonsoft.Json.JsonConvert.DeserializeObject<Dictionary<string, string>>(content);
-                string queryString = "";
-                foreach(string key in dic.Keys)
+                if(!string.IsNullOrEmpty(content))
                 {
-                    queryString += key + "=" + dic[key] + "&";
+                    Dictionary<string, string> dic = Newtonsoft.Json.JsonConvert.DeserializeObject<Dictionary<string, string>>(content);
+                    string queryString = "";
+                    foreach(string key in dic.Keys)
+                    {
+                        queryString += key + "=" + dic[key] + "&";
+                    }
+                    request.QueryString = new QueryString("?" + queryString.TrimEnd('&'));
                 }
-                request.QueryString = new QueryString("?" + queryString.TrimEnd('&'));
             }
             else if(context.HttpContext.Request.Method.ToLower() == "delete")
             {
                 string path = request.Path.Value;
-                path = path.Substring(0, path.LastIndexOf("/") + 1) + Decrypt(path.Substring(path.LastIndexOf("/") + 1));
+                string value = path.Substring(path.LastIndexOf("/") + 1);
+                path = path.Substring(0, path.LastIndexOf("/") + 1);
+                value = Decrypt(value);
+                path += value;
+                request.Path = new PathString(path);
+                request.RouteValues["Id"] = value;
             }
             else
             {

+ 9 - 5
Filters/GlobalActionMonitor.cs

@@ -49,13 +49,18 @@ namespace Middleware
                     content = "{" + jsonString.TrimEnd(',') + "}";
                 }
             }
+            else if(context.HttpContext.Request.Method.ToLower() == "delete")
+            {
+                string path = context.HttpContext.Request.Path.Value;
+                content = path.Substring(path.LastIndexOf("/") + 1);
+            }
             else
             {
                 content = context.HttpContext.GetBody();
             }
             if(!string.IsNullOrEmpty(content))
             {                
-                if(content.Contains("{") && content.Contains("}"))
+                if(content.Contains("{") && content.Contains("}") && content != "{}")
                 {
                     Dictionary<string, object> dictionary = Newtonsoft.Json.JsonConvert.DeserializeObject<Dictionary<string, object>>(content);
                     if(context.ActionDescriptor.Parameters.Count > 0)
@@ -75,8 +80,7 @@ namespace Middleware
                                 {
                                     foreach (string key in dictionary.Keys)
                                     {
-                                        string field = key.Substring(0, 1).ToUpper() + key.Substring(1);
-                                        if (propertyInfos[i].Name == field)
+                                        if (propertyInfos[i].Name == key)
                                         {
                                             object value = dictionary[key];
                                             if (propertyInfos[i].GetMethod.ReturnParameter.ParameterType.Name == "Int32")
@@ -105,11 +109,11 @@ namespace Middleware
                     string ParamName = context.ActionDescriptor.Parameters[0].Name;
                     if(context.ActionArguments.ContainsKey(ParamName))
                     {
-                        context.ActionArguments[ParamName] = content;
+                        context.ActionArguments[ParamName] = Convert.ToInt32(content);
                     }
                     else
                     {
-                        context.ActionArguments.Add(ParamName, content);
+                        context.ActionArguments.Add(ParamName, Convert.ToInt32(content));
                     }
                 }
             }

+ 11 - 11
Model/Database/ApiGroup.cs

@@ -11,70 +11,70 @@ namespace Model
         /// 名称
         /// </summary>
         [SugarColumn(ColumnDescription = "名称", Length = 50, ColumnName = "group_name")]
-        public string GroupName { get; set; }
+        public string groupName { get; set; }
 
 
         /// <summary>
         /// 说明
         /// </summary>
         [SugarColumn(ColumnDescription = "说明", Length = 200, ColumnName = "group_remark")]
-        public string GroupRemark { get; set; }
+        public string groupRemark { get; set; }
 
 
         /// <summary>
         /// 版本号
         /// </summary>
         [SugarColumn(ColumnDescription = "版本号", Length = 20, ColumnName = "group_version")]
-        public string GroupVersion { get; set; }
+        public string groupVersion { get; set; }
 
 
         /// <summary>
         /// ID
         /// </summary>
-        [SugarColumn(ColumnDescription = "ID", ColumnName = "id")]
-        public int Id { get; set; }
+        [SugarColumn(ColumnDescription = "ID", IsPrimaryKey = true, IsIdentity = true, ColumnName = "id")]
+        public int id { get; set; }
 
 
         /// <summary>
         /// 状态
         /// </summary>
         [SugarColumn(ColumnDescription = "状态", ColumnName = "status")]
-        public int Status { get; set; }
+        public int status { get; set; }
 
 
         /// <summary>
         /// 排序
         /// </summary>
         [SugarColumn(ColumnDescription = "排序", ColumnName = "sort")]
-        public int Sort { get; set; }
+        public int sort { get; set; }
 
 
         /// <summary>
         /// 版本号
         /// </summary>
         [SugarColumn(ColumnDescription = "版本号", ColumnName = "version")]
-        public int Version { get; set; }
+        public int version { get; set; }
 
 
         /// <summary>
         /// 创建时间
         /// </summary>
         [SugarColumn(ColumnDescription = "创建时间", ColumnName = "create_date")]
-        public DateTime? CreateDate { get; set; }
+        public DateTime? createDate { get; set; }
 
 
         /// <summary>
         /// 更新时间
         /// </summary>
         [SugarColumn(ColumnDescription = "更新时间", ColumnName = "update_date")]
-        public DateTime? UpdateDate { get; set; }
+        public DateTime? updateDate { get; set; }
 
 
         /// <summary>
         /// 类型
         /// </summary>
         [SugarColumn(ColumnDescription = "类型", ColumnName = "group_kind")]
-        public int GroupKind { get; set; }
+        public int groupKind { get; set; }
 
 
 

+ 3 - 4
Model/Dto/ApiGroupAddDto.cs

@@ -12,21 +12,20 @@ namespace Dto
         /// <summary>
         /// 名称
         /// </summary>
-        [Required(ErrorMessage = "名称不能为空")]
-        public string GroupName { get; set; }
+        public string? groupName { get; set; }
 
 
         /// <summary>
         /// 说明
         /// </summary>
-        public string GroupRemark { get; set; }
+        public string? groupRemark { get; set; }
 
 
         /// <summary>
         /// 版本号
         /// </summary>
         [Required(ErrorMessage = "版本号不能为空")]
-        public string GroupVersion { get; set; }
+        public string? groupVersion { get; set; }
 
 
 

+ 1 - 2
Model/Dto/ApiGroupListDto.cs

@@ -12,8 +12,7 @@ namespace Dto
         /// <summary>
         /// 名称
         /// </summary>
-        [Required(ErrorMessage = "名称不能为空")]
-        public string GroupName { get; set; }
+        public string? groupName { get; set; }
 
 
 

+ 1 - 1
Model/Dto/ApiGroupQueryDto.cs

@@ -12,7 +12,7 @@ namespace Dto
         /// <summary>
         /// ID
         /// </summary>
-        public int Id { get; set; }
+        public int id { get; set; }
 
 
 

+ 4 - 5
Model/Dto/ApiGroupUpdateDto.cs

@@ -12,27 +12,26 @@ namespace Dto
         /// <summary>
         /// 名称
         /// </summary>
-        [Required(ErrorMessage = "名称不能为空")]
-        public string GroupName { get; set; }
+        public string? groupName { get; set; }
 
 
         /// <summary>
         /// 说明
         /// </summary>
-        public string GroupRemark { get; set; }
+        public string? groupRemark { get; set; }
 
 
         /// <summary>
         /// 版本号
         /// </summary>
         [Required(ErrorMessage = "版本号不能为空")]
-        public string GroupVersion { get; set; }
+        public string? groupVersion { get; set; }
 
 
         /// <summary>
         /// ID
         /// </summary>
-        public int Id { get; set; }
+        public int id { get; set; }
 
 
 

+ 1 - 1
Model/Vo/ApiGroupAddVo.cs

@@ -10,7 +10,7 @@ namespace Vo
         /// <summary>
         /// ID
         /// </summary>
-        public int Id { get; set; }
+        public int id { get; set; }
 
 
 

+ 3 - 3
Model/Vo/ApiGroupListVo.cs

@@ -10,19 +10,19 @@ namespace Vo
         /// <summary>
         /// 名称
         /// </summary>
-        public string GroupName { get; set; }
+        public string groupName { get; set; }
 
 
         /// <summary>
         /// 版本号
         /// </summary>
-        public string GroupVersion { get; set; }
+        public string groupVersion { get; set; }
 
 
         /// <summary>
         /// ID
         /// </summary>
-        public int Id { get; set; }
+        public int id { get; set; }
 
 
 

+ 3 - 2
Model/Vo/ApiGroupQueryVo.cs

@@ -10,14 +10,15 @@ namespace Vo
         /// <summary>
         /// 名称
         /// </summary>
-        public string GroupName { get; set; }
+        public string groupName { get; set; }
 
 
         /// <summary>
         /// 版本号
         /// </summary>
-        public string GroupVersion { get; set; }
+        public string groupVersion { get; set; }
 
+        public int id { get; set; }
 
 
     }

+ 12 - 3
Services/ApiGroupService.cs

@@ -20,14 +20,15 @@ namespace Services
         /// </summary>
         /// <param name="parm">请求参数</param>
         /// <returns>api接口分组列表</returns>
-        public PagedInfo<ApiGroupListVo> List([FromQuery] ApiGroupListDto parm)
+        public PagedInfo<ApiGroupListVo> List([FromQuery] PagerInfo page, [FromQuery] ApiGroupListDto parm)
         {
             //开始拼装查询条件
             var predicate = Expressionable.Create<ApiGroup>();
-            predicate = predicate.AndIF(!string.IsNullOrEmpty(parm.GroupName), m => m.GroupName.Contains(parm.GroupName));
+            predicate = predicate.AndIF(!string.IsNullOrEmpty(parm.groupName), m => m.groupName.Contains(parm.groupName));
             var response = Queryable()
                 .Where(predicate.ToExpression())
-                .ToPage<ApiGroup, ApiGroupListVo>(new PagerInfo());
+                .OrderByDescending(m => m.id)
+                .ToPage<ApiGroup, ApiGroupListVo>(page);
             return response;
         }
 
@@ -35,5 +36,13 @@ namespace Services
 
 
 
+
+
+
+
+
+
+
+
     }
 }

+ 9 - 1
Services/IService/IApiGroupService.cs

@@ -13,7 +13,15 @@ namespace Services
         /// </summary>
         /// <param name="parm">请求参数</param>
         /// <returns>api接口分组列表</returns>
-        PagedInfo<ApiGroupListVo> List([FromQuery] ApiGroupListDto parm);
+        PagedInfo<ApiGroupListVo> List([FromQuery] PagerInfo page, [FromQuery] ApiGroupListDto parm);
+
+
+
+
+
+
+
+