Skip to content

Commit

Permalink
Merge pull request #188 from harris2012/patch-1
Browse files Browse the repository at this point in the history
api.AppController 用注入的方式调用 Controller.AppController
  • Loading branch information
kklldog authored Sep 24, 2024
2 parents b1589fa + be4c8b8 commit 5792cad
Showing 1 changed file with 23 additions and 50 deletions.
73 changes: 23 additions & 50 deletions src/AgileConfig.Server.Apisite/Controllers/api/AppController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,17 +25,26 @@ public class AppController : Controller
private readonly IPremissionService _premissionService;
private readonly IUserService _userService;

private readonly Controllers.AppController _appController;
private readonly Controllers.ConfigController _configController;

public AppController(IAppService appService,
IPremissionService premissionService,
IUserService userService,
IConfigService configService,
ITinyEventBus tinyEventBus)
ITinyEventBus tinyEventBus,

Controllers.AppController _appController,
Controllers.ConfigController _configController)
{
_appService = appService;
_premissionService = premissionService;
_userService = userService;
_configService = configService;
_tinyEventBus = tinyEventBus;

this._appController = _appController;
this._configController = _configController;
}

/// <summary>
Expand Down Expand Up @@ -69,13 +78,7 @@ public async Task<ActionResult<IEnumerable<ApiAppVM>>> GetAll()
[HttpGet("{id}")]
public async Task<ActionResult<ApiAppVM>> GetById(string id)
{
var ctrl = new Controllers.AppController(
_appService,
_premissionService,
_userService,
_tinyEventBus
);
var result = (await ctrl.Get(id)) as JsonResult;
var result = (await _appController.Get(id)) as JsonResult;
dynamic obj = result.Value;

if (obj.success)
Expand Down Expand Up @@ -121,15 +124,9 @@ public async Task<IActionResult> Add([FromBody] ApiAppVM model)
});
}

var ctrl = new Controllers.AppController(
_appService,
_premissionService,
_userService,
_tinyEventBus
);
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,
Expand Down Expand Up @@ -174,16 +171,10 @@ public async Task<IActionResult> Edit(string id, [FromBody] ApiAppVM model)
});
}

var ctrl = new Controllers.AppController(
_appService,
_premissionService,
_userService,
_tinyEventBus
);
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,
Expand Down Expand Up @@ -215,15 +206,9 @@ public async Task<IActionResult> Edit(string id, [FromBody] ApiAppVM model)
[HttpDelete("{id}")]
public async Task<IActionResult> Delete(string id)
{
var ctrl = new Controllers.AppController(
_appService,
_premissionService,
_userService,
_tinyEventBus
);
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)
Expand All @@ -249,15 +234,9 @@ public async Task<IActionResult> Delete(string id)
[HttpPost("publish")]
public async Task<IActionResult> 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;
Expand Down Expand Up @@ -317,15 +296,9 @@ public async Task<ActionResult<IEnumerable<ApiPublishTimelineVM>>> PublishHistor
[HttpPost("rollback")]
public async Task<IActionResult> 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)
Expand Down

0 comments on commit 5792cad

Please sign in to comment.