Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

api.AppController 用注入的方式调用 Controller.AppController #188

Merged
merged 2 commits into from
Sep 24, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading