From d1788604b3a0ad805a6a811a778739d0d4fb6f2b Mon Sep 17 00:00:00 2001 From: Harris Zhang Date: Mon, 9 Sep 2024 22:01:21 +0800 Subject: [PATCH 1/2] =?UTF-8?q?api.AppController=20=E7=94=A8=E6=B3=A8?= =?UTF-8?q?=E5=85=A5=E7=9A=84=E6=96=B9=E5=BC=8F=E8=B0=83=E7=94=A8=20Contro?= =?UTF-8?q?ller.AppController?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Controllers/api/AppController.cs | 32 ++++--------------- 1 file changed, 7 insertions(+), 25 deletions(-) diff --git a/src/AgileConfig.Server.Apisite/Controllers/api/AppController.cs b/src/AgileConfig.Server.Apisite/Controllers/api/AppController.cs index 30ec5f6c..0646bd02 100644 --- a/src/AgileConfig.Server.Apisite/Controllers/api/AppController.cs +++ b/src/AgileConfig.Server.Apisite/Controllers/api/AppController.cs @@ -25,17 +25,23 @@ public class AppController : Controller private readonly IPremissionService _premissionService; private readonly IUserService _userService; + private readonly Controllers.AppController ctrl; + public AppController(IAppService appService, IPremissionService premissionService, IUserService userService, IConfigService configService, - ITinyEventBus tinyEventBus) + ITinyEventBus tinyEventBus, + + Controllers.AppController ctrl) { _appService = appService; _premissionService = premissionService; _userService = userService; _configService = configService; _tinyEventBus = tinyEventBus; + + this.ctrl = ctrl; } /// @@ -69,12 +75,6 @@ public async Task>> GetAll() [HttpGet("{id}")] public async Task> GetById(string id) { - var ctrl = new Controllers.AppController( - _appService, - _premissionService, - _userService, - _tinyEventBus - ); var result = (await ctrl.Get(id)) as JsonResult; dynamic obj = result.Value; @@ -121,12 +121,6 @@ public async Task Add([FromBody] ApiAppVM model) }); } - var ctrl = new Controllers.AppController( - _appService, - _premissionService, - _userService, - _tinyEventBus - ); ctrl.ControllerContext.HttpContext = HttpContext; var result = (await ctrl.Add(new AppVM @@ -174,12 +168,6 @@ public async Task Edit(string id, [FromBody] ApiAppVM model) }); } - var ctrl = new Controllers.AppController( - _appService, - _premissionService, - _userService, - _tinyEventBus - ); ctrl.ControllerContext.HttpContext = HttpContext; model.Id = id; @@ -215,12 +203,6 @@ public async Task Edit(string id, [FromBody] ApiAppVM model) [HttpDelete("{id}")] public async Task Delete(string id) { - var ctrl = new Controllers.AppController( - _appService, - _premissionService, - _userService, - _tinyEventBus - ); ctrl.ControllerContext.HttpContext = HttpContext; var result = (await ctrl.Delete(id)) as JsonResult; From be4c8b8b526d11578e555938e04fcf8cd226e719 Mon Sep 17 00:00:00 2001 From: Harris Zhang Date: Mon, 23 Sep 2024 13:34:50 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E7=BB=9F=E4=B8=80=E7=A7=81=E6=9C=89?= =?UTF-8?q?=E5=8F=98=E9=87=8F=E7=9A=84=E5=91=BD=E5=90=8D+=E6=8A=8A?= =?UTF-8?q?=E4=B8=8B=E9=9D=A2=E7=9A=84ConfigController=20=E4=B9=9F?= =?UTF-8?q?=E6=94=B9=E4=B8=80=E4=B8=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Controllers/api/AppController.cs | 47 ++++++++----------- 1 file changed, 19 insertions(+), 28 deletions(-) diff --git a/src/AgileConfig.Server.Apisite/Controllers/api/AppController.cs b/src/AgileConfig.Server.Apisite/Controllers/api/AppController.cs index 0646bd02..fc498ed6 100644 --- a/src/AgileConfig.Server.Apisite/Controllers/api/AppController.cs +++ b/src/AgileConfig.Server.Apisite/Controllers/api/AppController.cs @@ -25,7 +25,8 @@ public class AppController : Controller private readonly IPremissionService _premissionService; private readonly IUserService _userService; - private readonly Controllers.AppController ctrl; + private readonly Controllers.AppController _appController; + private readonly Controllers.ConfigController _configController; public AppController(IAppService appService, IPremissionService premissionService, @@ -33,7 +34,8 @@ public AppController(IAppService appService, IConfigService configService, ITinyEventBus tinyEventBus, - Controllers.AppController ctrl) + Controllers.AppController _appController, + Controllers.ConfigController _configController) { _appService = appService; _premissionService = premissionService; @@ -41,7 +43,8 @@ public AppController(IAppService appService, _configService = configService; _tinyEventBus = tinyEventBus; - this.ctrl = ctrl; + this._appController = _appController; + this._configController = _configController; } /// @@ -75,7 +78,7 @@ public async Task>> GetAll() [HttpGet("{id}")] public async Task> GetById(string id) { - var result = (await ctrl.Get(id)) as JsonResult; + var result = (await _appController.Get(id)) as JsonResult; dynamic obj = result.Value; if (obj.success) @@ -121,9 +124,9 @@ public async Task Add([FromBody] ApiAppVM model) }); } - ctrl.ControllerContext.HttpContext = HttpContext; + _appController.ControllerContext.HttpContext = HttpContext; - var result = (await ctrl.Add(new AppVM + var result = (await _appController.Add(new AppVM { Id = model.Id, Name = model.Name, @@ -168,10 +171,10 @@ public async Task Edit(string id, [FromBody] ApiAppVM model) }); } - ctrl.ControllerContext.HttpContext = HttpContext; + _appController.ControllerContext.HttpContext = HttpContext; model.Id = id; - var result = (await ctrl.Edit(new AppVM + var result = (await _appController.Edit(new AppVM { Id = model.Id, Name = model.Name, @@ -203,9 +206,9 @@ public async Task Edit(string id, [FromBody] ApiAppVM model) [HttpDelete("{id}")] public async Task Delete(string id) { - ctrl.ControllerContext.HttpContext = HttpContext; + _appController.ControllerContext.HttpContext = HttpContext; - var result = (await ctrl.Delete(id)) as JsonResult; + var result = (await _appController.Delete(id)) as JsonResult; dynamic obj = result.Value; if (obj.success == true) @@ -231,15 +234,9 @@ public async Task Delete(string id) [HttpPost("publish")] public async Task Publish(string appId, EnvString env) { - var ctrl = new Controllers.ConfigController( - _configService, - _appService, - _userService, - _tinyEventBus - ); - ctrl.ControllerContext.HttpContext = HttpContext; - - var result = (await ctrl.Publish(new PublishLogVM() + _configController.ControllerContext.HttpContext = HttpContext; + + var result = (await _configController.Publish(new PublishLogVM() { AppId = appId }, env)) as JsonResult; @@ -299,15 +296,9 @@ public async Task>> PublishHistor [HttpPost("rollback")] public async Task Rollback(string historyId, EnvString env) { - var ctrl = new Controllers.ConfigController( - _configService, - _appService, - _userService, - _tinyEventBus - ); - ctrl.ControllerContext.HttpContext = HttpContext; - - var result = (await ctrl.Rollback(historyId, env)) as JsonResult; + _configController.ControllerContext.HttpContext = HttpContext; + + var result = (await _configController.Rollback(historyId, env)) as JsonResult; dynamic obj = result.Value; if (obj.success == true)