lihao 4 年之前
父節點
當前提交
9c470d533b

+ 0 - 37
gx_api/GxPress/Api/GxPress.Api/AppControllers/AppController.cs

@@ -1,37 +0,0 @@
-using GxPress.Common.Exceptions;
-using GxPress.Result;
-using Microsoft.AspNetCore.Mvc;
-
-namespace GxPress.Api.AppControllers
-{
-
-
-    public class AppController : ControllerBase
-    {
-        public AppResult AppResult { get; set; }
-
-        /// <summary>
-        /// 
-        /// </summary>
-        /// <param name="success"></param>
-        /// <param name="msg"></param>
-        /// <param name="msg1"></param>
-        /// <returns></returns>
-        public JsonResult JsonResult(bool success, string msg, string msg1)
-        {
-            var appJsonData = new AppResult();
-            if (success)
-            {
-                appJsonData.Code = 1;
-                appJsonData.Msg = msg;
-            }
-            else
-            {
-                throw new BusinessException(msg1);
-            }
-
-            var json = new JsonResult(appJsonData);
-            return json;
-        }
-    }
-}

+ 1 - 1
gx_api/GxPress/Api/GxPress.Api/AppControllers/GroupController.cs

@@ -81,7 +81,7 @@ namespace GxPress.Api.AppControllers
         /// <param name="request"></param>
         /// <returns></returns>
         [HttpPost("insert-user")]
-        public async Task<AppResult> AddGroupUser(GroupUserInRequest request)
+        public async Task<AppResult<object>> AddGroupUser(GroupUserInRequest request)
         {
             request.UserId = _loginContext.AccountId;
             return await _groupService.InsertsAsync(request);

+ 2 - 1
gx_api/GxPress/Api/GxPress.Api/AppControllers/TopicController.cs

@@ -7,6 +7,7 @@ using GxPress.Entity.Topic;
 using GxPress.Repository.Interface;
 using GxPress.Repository.Interface.Topic;
 using GxPress.Request.App.Topic;
+using GxPress.Result;
 using GxPress.Result.App.Topic;
 using GxPress.Service.Interface.Middle;
 using GxPress.Service.Interface.Topic;
@@ -52,7 +53,7 @@ namespace GxPress.Api.AppControllers
         /// <param name="request"></param>
         /// <returns></returns>
         [HttpPost("add")]
-        public async Task<bool> Insert(TopicInRequest request)
+        public async Task<AppResultJson<Entity.Topic.Topic>> Insert(TopicInRequest request)
         {
             // request.HtmlContent = StringUtils.RemoveEmoji(request.HtmlContent);
             // request.Content = StringUtils.RemoveEmoji(request.Content);

+ 1 - 1
gx_api/GxPress/Api/GxPress.Api/WebControllers/WebGroupController.cs

@@ -114,7 +114,7 @@ namespace GxPress.Api.WebControllers
         /// <param name="request"></param>
         /// <returns></returns>
         [HttpPost("insert-user")]
-        public async Task<AppResult> AddGroupUser(GroupUserInRequest request)
+        public async Task<AppResult<object>> AddGroupUser(GroupUserInRequest request)
         {
             request.UserId = _loginContext.AccountId;
             return await _groupService.InsertsAsync(request);

+ 2 - 1
gx_api/GxPress/Api/GxPress.Api/WebControllers/WebTopicController.cs

@@ -7,6 +7,7 @@ using GxPress.Entity.Topic;
 using GxPress.Repository.Interface;
 using GxPress.Repository.Interface.Topic;
 using GxPress.Request.App.Topic;
+using GxPress.Result;
 using GxPress.Result.App.Topic;
 using GxPress.Service.Interface.Middle;
 using GxPress.Service.Interface.Topic;
@@ -52,7 +53,7 @@ namespace GxPress.Api.WebControllers
         /// <param name="request"></param>
         /// <returns></returns>
         [HttpPost("add")]
-        public async Task<bool> Insert(TopicInRequest request)
+        public async Task<AppResultJson<Entity.Topic.Topic>> Insert(TopicInRequest request)
         {
             // request.HtmlContent = StringUtils.RemoveEmoji(request.HtmlContent);
             // request.Content = StringUtils.RemoveEmoji(request.Content);

+ 28 - 1
gx_api/GxPress/Model/GxPress.Result/AppResult.cs

@@ -7,7 +7,7 @@ namespace GxPress.Result
     /// <summary>
     /// App返回
     /// </summary>
-    public class AppResult
+    public class AppResult<TItem>
     {
         /// <summary>
         /// 状态码
@@ -22,5 +22,32 @@ namespace GxPress.Result
         /// </summary>
         /// <value></value>
         public bool Success { get; set; }
+        /// <summary>
+        /// 
+        /// </summary>
+        /// <value></value>
+        public IEnumerable<TItem> Data { get; set; }
+    }
+
+    public class AppResultJson<TItem>
+    {
+        /// <summary>
+        /// 状态码
+        /// </summary>
+        public int Code { get; set; }
+        /// <summary>
+        /// 消息
+        /// </summary>
+        public string Msg { get; set; }
+        /// <summary>
+        /// 是否成功
+        /// </summary>
+        /// <value></value>
+        public bool Success { get; set; }
+        /// <summary>
+        /// 
+        /// </summary>
+        /// <value></value>
+        public TItem Data { get; set; }
     }
 }

+ 4 - 3
gx_api/GxPress/Service/GxPress.Service.Implement/Group/GroupService.cs

@@ -140,13 +140,14 @@ namespace GxPress.Service.Implement.Group
         /// </summary>
         /// <param name="request"></param>
         /// <returns></returns>
-        public async Task<AppResult> InsertsAsync(GroupUserInRequest request)
+        public async Task<AppResult<object>> InsertsAsync(GroupUserInRequest request)
         {
-            var result = new AppResult()
+            var result = new AppResult<object>()
             {
                 Code = 200,
                 Success = true,
-                Msg = ""
+                Msg = "",
+                Data=null
             };
             request.UserIds = request.UserIds.Distinct().ToList();
             //获取当前小组

+ 18 - 4
gx_api/GxPress/Service/GxPress.Service.Implement/Topic/TopicService.Add.cs

@@ -18,8 +18,9 @@ namespace GxPress.Service.Implement.Topic
         /// </summary>
         /// <param name="request"></param>
         /// <returns></returns>
-        public async Task<bool> InsertTopicAsync(TopicInRequest request)
+        public async Task<AppResultJson<Entity.Topic.Topic>> InsertTopicAsync(TopicInRequest request)
         {
+            var result = new AppResultJson<Entity.Topic.Topic>();
             if (string.IsNullOrWhiteSpace(request.Title) && string.IsNullOrWhiteSpace(request.HtmlContent))
                 throw new BusinessException("标题和内容必填一项!");
             try
@@ -50,15 +51,28 @@ namespace GxPress.Service.Implement.Topic
                     var topicId = await _topicRepository.InsertAsync(topic);
                     //修改话题访问量
                     await _visitService.AddVisit(request.UserId, GxPress.EnumConst.AllTypeConst.Topic.GetHashCode(), topicId);
+                    result = new AppResultJson<Entity.Topic.Topic>
+                    {
+                        Code = 100,
+                        Msg = "",
+                        Success = false,
+                        Data = await _topicRepository.GetAsync(topicId)
+                    };
                     transactionScope.Complete();
                 }
             }
-            catch (Exception e)
+            catch
             {
-                throw new BusinessException(e.Message);
+                return result = new AppResultJson<Entity.Topic.Topic>
+                {
+                    Code = 100,
+                    Msg = "",
+                    Success = false,
+                    Data = new Entity.Topic.Topic()
+                };
             }
 
-            return true;
+            return result;
         }
     }
 }

+ 1 - 1
gx_api/GxPress/Service/GxPress.Service.Interface/Group/IGroupService.cs

@@ -16,7 +16,7 @@ namespace GxPress.Service.Interface.Group
         Task<GroupDetailResult> InsertGroup(GroupInRequest request);
         Task<PagedList<GroupUserFindResult>> FindGroupByGroupFolderIdAsync(GroupSearchRequest request);
 
-        Task<AppResult> InsertsAsync(GroupUserInRequest request);
+        Task<AppResult<Object>> InsertsAsync(GroupUserInRequest request);
 
         /// <summary>
         /// 小组添加用户

+ 2 - 1
gx_api/GxPress/Service/GxPress.Service.Interface/Topic/ITopicService.cs

@@ -4,6 +4,7 @@ using System.Text;
 using System.Threading.Tasks;
 using GxPress.Common.Page;
 using GxPress.Request.App.Topic;
+using GxPress.Result;
 using GxPress.Result.App.Topic;
 
 namespace GxPress.Service.Interface.Topic
@@ -40,7 +41,7 @@ namespace GxPress.Service.Interface.Topic
         /// </summary>
         /// <param name="request"></param>
         /// <returns></returns>
-        Task<bool> InsertTopicAsync(TopicInRequest request);
+        Task<AppResultJson<Entity.Topic.Topic>> InsertTopicAsync(TopicInRequest request);
 
         /// <summary>
         /// 删除话题