58 lines
1.6 KiB
C#
58 lines
1.6 KiB
C#
using Domain.AggregateModel.AppAggregate;
|
|
using Domain.AggregateModel.LinkAggregate;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
using QRCodeService.Models;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using MediatR;
|
|
using QRCodeService.Application.Queries;
|
|
using QRCodeService.Application.Commands;
|
|
|
|
namespace QRCodeService.Controllers.Api
|
|
{
|
|
[Route("api/v1/[controller]")]
|
|
[ApiController]
|
|
public class LinkController:ControllerBase
|
|
{
|
|
readonly IMediator mediator;
|
|
readonly ILinkQueries linkQueries;
|
|
readonly IAppQueries appQueries;
|
|
|
|
public LinkController(IMediator mediator, ILinkQueries queries, IAppQueries appQueries)
|
|
{
|
|
this.mediator = mediator;
|
|
this.linkQueries = queries;
|
|
this.appQueries = appQueries;
|
|
}
|
|
|
|
[HttpGet]
|
|
public IActionResult Get()
|
|
{
|
|
return Ok();
|
|
}
|
|
[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)
|
|
{
|
|
return BadRequest();
|
|
}
|
|
return Ok(link.ShortCode);
|
|
}
|
|
}
|
|
}
|