Ai
1 Star 0 Fork 10

SyncGithub/OAuthApp

forked from uncle wang/OAuthApp 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
ApiCodeGeneratorsController.cs 2.41 KB
一键复制 编辑 原始数据 按行查看 历史
uncle wang 提交于 2022-06-14 17:44 +08:00 . 1,添加了服务器在线编辑功能
using System.Linq;
using Microsoft.AspNetCore.Mvc;
using OAuthApp.Data;
using Swashbuckle.AspNetCore.Annotations;
using OAuthApp.Filters;
using OAuthApp.Services;
namespace OAuthApp.Apis
{
[SwaggerTag("API CodeGen")]
[ServiceFilter(typeof(ApiRequestLoggingAttribute))]
public class ApiCodeGeneratorsController : BaseController
{
private readonly ApiDbContext _context;
public ApiCodeGeneratorsController(ApiDbContext context)
{
_context = context;
}
[HttpGet]
[SwaggerOperation(OperationId = "ApiCodeGens")]
[EncryptResultFilter]
public IActionResult List(long apiId, int skip, int take)
{
var q = _context.ApiCodeGenerators.Where(x => x.ApiID == apiId).AsQueryable();
var total = q.Count();
var data = q.Skip(skip).Take(take).OrderByDescending(x => x.ID).ToList();
return OK(new
{
total,
data
});
}
[HttpGet("{id}")]
[SwaggerOperation(OperationId = "ApiCodeGen")]
[EncryptResultFilter]
public IActionResult Get(long id)
{
var result = _context.ApiCodeGenerators
.FirstOrDefault(x => x.ID == id);
if (result == null)
{
return NotFound();
}
return OK(result);
}
[HttpPost]
[SwaggerOperation(OperationId = "ApiCodeGenPost")]
public IActionResult Post(ApiCodeGenerator apiCodeGenerator)
{
if(_context.ApiCodeGenerators.Any(x=>x.ApiID==apiCodeGenerator.ApiID
&&x.CodeGeneratorID==apiCodeGenerator.CodeGeneratorID))
{
return Error("请勿重复添加");
}
_context.ApiCodeGenerators.Add(apiCodeGenerator);
_context.SaveChanges();
return OK(new { id = apiCodeGenerator.ID });
}
[HttpDelete("{id}")]
[SwaggerOperation(OperationId = "ApiCodeGenDelete")]
public IActionResult Delete(long id)
{
var result = _context.ApiCodeGenerators
.FirstOrDefault(x => x.ID == id);
if (result == null)
{
return NotFound();
}
_context.ApiCodeGenerators.Remove(result);
_context.SaveChanges();
return OK(true);
}
}
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
C#
1
https://gitee.com/sync-github/OAuthApp.git
git@gitee.com:sync-github/OAuthApp.git
sync-github
OAuthApp
OAuthApp
master

搜索帮助