创建签名验证自定义中间件 ,优化代码结构
This commit is contained in:
@@ -10,6 +10,7 @@ using System.Threading.Tasks;
|
||||
using MediatR;
|
||||
using QRCodeService.Application.Queries;
|
||||
using QRCodeService.Application.Commands;
|
||||
using QRCodeService.Infrastructure.Middlewares;
|
||||
|
||||
namespace QRCodeService.Controllers.Api
|
||||
{
|
||||
@@ -19,32 +20,28 @@ namespace QRCodeService.Controllers.Api
|
||||
{
|
||||
readonly IMediator mediator;
|
||||
readonly ILinkQueries linkQueries;
|
||||
readonly IAppQueries appQueries;
|
||||
|
||||
public LinkController(IMediator mediator, ILinkQueries queries, IAppQueries appQueries)
|
||||
public LinkController(IMediator mediator, ILinkQueries queries)
|
||||
{
|
||||
this.mediator = mediator;
|
||||
this.linkQueries = queries;
|
||||
this.appQueries = appQueries;
|
||||
}
|
||||
[Route("{shortCode}")]
|
||||
[HttpGet]
|
||||
public async Task<IActionResult> Get(string shortCode)
|
||||
{
|
||||
var link = await linkQueries.GetLinkAsync(shortCode);
|
||||
if (link == null)
|
||||
{
|
||||
return NotFound();
|
||||
}
|
||||
return Ok(link);
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
public IActionResult Get()
|
||||
{
|
||||
return Ok();
|
||||
}
|
||||
[CheckSign(typeof(CreateLinkModel))]
|
||||
[HttpPost]
|
||||
public async Task<IActionResult> Create(CreateLinkModel input)
|
||||
{
|
||||
var app = await appQueries.GetAppAsync(input.AppId);
|
||||
if (app == null)
|
||||
{
|
||||
return BadRequest();
|
||||
}
|
||||
if (! await input.CheckValidAsync(app.Appkey))
|
||||
{
|
||||
return BadRequest();
|
||||
}
|
||||
var command = new CreateLinkCommand(input.SuffixUrl,1);
|
||||
var link = await mediator.Send(command);
|
||||
if (link==null)
|
||||
|
||||
Reference in New Issue
Block a user