Skip to content

Commit

Permalink
Fix issue
Browse files Browse the repository at this point in the history
  • Loading branch information
agile.zhou committed Sep 28, 2024
1 parent 54e00f7 commit 755229f
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 46 deletions.
25 changes: 16 additions & 9 deletions src/AgileConfig.Server.Apisite/Controllers/AppController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,7 @@ public async Task<IActionResult> All()
[HttpGet]
public async Task<IActionResult> Get(string id)
{
ArgumentNullException.ThrowIfNullOrEmpty(id);
ArgumentException.ThrowIfNullOrEmpty(id);

var app = await _appService.GetAsync(id);
var vm = app.ToAppVM();
Expand All @@ -342,12 +342,19 @@ public async Task<IActionResult> Get(string id)
{
vm.inheritancedApps = (await _appService.GetInheritancedAppsAsync(id)).Select(x => x.Id).ToList();
}
else
{
return NotFound(new
{
success = false,
message = "未找到对应的应用程序。"
});
}

return Json(new
{
success = app != null,
data = vm,
message = app == null ? "未找到对应的应用程序。" : ""
success = true,
data = vm
});
}

Expand All @@ -360,12 +367,12 @@ public async Task<IActionResult> Get(string id)
[HttpPost]
public async Task<IActionResult> DisableOrEanble(string id)
{
ArgumentNullException.ThrowIfNullOrEmpty(id);
ArgumentException.ThrowIfNullOrEmpty(id);

var app = await _appService.GetAsync(id);
if (app == null)
{
return Json(new
return NotFound(new
{
success = false,
message = "未找到对应的应用程序。"
Expand All @@ -392,12 +399,12 @@ public async Task<IActionResult> DisableOrEanble(string id)
[HttpPost]
public async Task<IActionResult> Delete(string id)
{
ArgumentNullException.ThrowIfNullOrEmpty(id);
ArgumentException.ThrowIfNullOrEmpty(id);

var app = await _appService.GetAsync(id);
if (app == null)
{
return Json(new
return NotFound(new
{
success = false,
message = "未找到对应的应用程序。"
Expand Down Expand Up @@ -472,7 +479,7 @@ public async Task<IActionResult> SaveAppAuth([FromBody] AppAuthVM model)
[HttpGet]
public async Task<IActionResult> GetUserAppAuth(string appId)
{
ArgumentNullException.ThrowIfNullOrEmpty(appId);
ArgumentException.ThrowIfNullOrEmpty(appId);

var result = new AppAuthVM
{
Expand Down
70 changes: 41 additions & 29 deletions src/AgileConfig.Server.Apisite/Controllers/api/AppController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
using System.Linq;
using System.Threading.Tasks;
using AgileConfig.Server.Apisite.Models.Mapping;
using Microsoft.AspNetCore.Mvc.Infrastructure;

namespace AgileConfig.Server.Apisite.Controllers.api
{
Expand Down Expand Up @@ -57,19 +58,22 @@ public async Task<ActionResult<IEnumerable<ApiAppVM>>> GetAll()
[HttpGet("{id}")]
public async Task<ActionResult<ApiAppVM>> GetById(string id)
{
var result = (await _appController.Get(id)) as JsonResult;
dynamic obj = result.Value;
var actionResult = await _appController.Get(id);
var status = actionResult as IStatusCodeActionResult;

if (obj.success)
var result = actionResult as JsonResult;
dynamic obj = result?.Value;

if (obj?.success ?? false)
{
AppVM appVM = obj.data;
return Json(appVM.ToApiAppVM());
}

Response.StatusCode = 400;
Response.StatusCode = status.StatusCode.Value;
return Json(new
{
obj.message
obj?.message
});
}

Expand Down Expand Up @@ -98,17 +102,17 @@ public async Task<IActionResult> Add([FromBody] ApiAppVM model)

var result = (await _appController.Add(model.ToAppVM())) as JsonResult;

dynamic obj = result.Value;
dynamic obj = result?.Value;

if (obj.success == true)
if (obj?.success == true)
{
return Created("/api/app/" + obj.data.Id, "");
}

Response.StatusCode = 400;
return Json(new
{
obj.message
obj?.message
});
}

Expand Down Expand Up @@ -137,18 +141,20 @@ public async Task<IActionResult> Edit(string id, [FromBody] ApiAppVM model)
_appController.ControllerContext.HttpContext = HttpContext;

model.Id = id;
var result = (await _appController.Edit(model.ToAppVM())) as JsonResult;
var actionResult = await _appController.Edit(model.ToAppVM());
var status = actionResult as IStatusCodeActionResult;
var result = actionResult as JsonResult;

dynamic obj = result.Value;
if (obj.success == true)
dynamic obj = result?.Value;
if (obj?.success ?? false)
{
return Ok();
}

Response.StatusCode = 400;
Response.StatusCode = status.StatusCode.Value;
return Json(new
{
obj.message
obj?.message
});
}

Expand All @@ -164,18 +170,20 @@ public async Task<IActionResult> Delete(string id)
{
_appController.ControllerContext.HttpContext = HttpContext;

var result = (await _appController.Delete(id)) as JsonResult;
var actionResult = await _appController.Delete(id);
var status = actionResult as IStatusCodeActionResult;
var result = actionResult as JsonResult;

dynamic obj = result.Value;
if (obj.success == true)
dynamic obj = result?.Value;
if (obj?.success ?? false)
{
return NoContent();
}

Response.StatusCode = 400;
Response.StatusCode = status.StatusCode.Value;
return Json(new
{
obj.message
obj?.message
});
}

Expand All @@ -192,21 +200,23 @@ public async Task<IActionResult> Publish(string appId, EnvString env)
{
_configController.ControllerContext.HttpContext = HttpContext;

var result = (await _configController.Publish(new PublishLogVM()
var actionResult = await _configController.Publish(new PublishLogVM()
{
AppId = appId
}, env)) as JsonResult;
}, env);
var status = actionResult as IStatusCodeActionResult;
var result = actionResult as JsonResult;

dynamic obj = result.Value;
if (obj.success == true)
dynamic obj = result?.Value;
if (obj?.success ?? false)
{
return Ok();
}

Response.StatusCode = 400;
Response.StatusCode = status.StatusCode.Value;
return Json(new
{
obj.message
obj?.message
});
}

Expand Down Expand Up @@ -244,18 +254,20 @@ public async Task<IActionResult> Rollback(string historyId, EnvString env)
{
_configController.ControllerContext.HttpContext = HttpContext;

var result = (await _configController.Rollback(historyId, env)) as JsonResult;
var actionResult = await _configController.Rollback(historyId, env);
var status = actionResult as IStatusCodeActionResult;
var result = actionResult as JsonResult;

dynamic obj = result.Value;
if (obj.success == true)
dynamic obj = result?.Value;
if (obj?.success ?? false)
{
return Ok();
}

Response.StatusCode = 400;
Response.StatusCode = status.StatusCode.Value;
return Json(new
{
obj.message
obj?.message
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,8 @@ public static AppVM ToAppVM(this ApiAppVM vm)
Secret = vm.Secret,
AppAdmin = vm.AppAdmin,
Inheritanced = vm.Inheritanced,
Group = vm.Group
Group = vm.Group,
Enabled = vm.Enabled.GetValueOrDefault()
};
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,4 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Text;
using System.Threading.Tasks;
using System.Threading.Tasks;
using AgileConfig.Server.IService;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
Expand Down
2 changes: 1 addition & 1 deletion src/AgileConfig.Server.Apisite/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public void ConfigureServices(IServiceCollection services)
services.AddMemoryCache();

services.AddCors();
services.AddMvc().AddRazorRuntimeCompilation();
services.AddMvc().AddRazorRuntimeCompilation().AddControllersAsServices();

if (Appsettings.IsPreviewMode)
{
Expand Down

0 comments on commit 755229f

Please sign in to comment.