添加命令数据验证和其他杂项修改
This commit is contained in:
25
QRCodeService/Controllers/Api/AppController.cs
Normal file
25
QRCodeService/Controllers/Api/AppController.cs
Normal file
@@ -0,0 +1,25 @@
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace QRCodeService.Controllers.Api
|
||||
{
|
||||
[Route("api/v1/[controller]")]
|
||||
[ApiController]
|
||||
public class AppController:ControllerBase
|
||||
{
|
||||
[HttpGet]
|
||||
public IActionResult Get()
|
||||
{
|
||||
return Ok();
|
||||
}
|
||||
[HttpPost]
|
||||
public IActionResult Create(object input)
|
||||
{
|
||||
return Ok();
|
||||
}
|
||||
}
|
||||
}
|
||||
46
QRCodeService/Controllers/Api/LinkController.cs
Normal file
46
QRCodeService/Controllers/Api/LinkController.cs
Normal file
@@ -0,0 +1,46 @@
|
||||
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 queries;
|
||||
|
||||
public LinkController(IMediator mediator, ILinkQueries queries)
|
||||
{
|
||||
this.mediator = mediator;
|
||||
this.queries = queries;
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
public IActionResult Get()
|
||||
{
|
||||
return Ok();
|
||||
}
|
||||
[HttpPost]
|
||||
public async Task<IActionResult> Create(CreateLinkModel input)
|
||||
{
|
||||
var command = new CreateLinkCommand(input.SuffixUrl,1);
|
||||
var link = await mediator.Send(command);
|
||||
if (link==null)
|
||||
{
|
||||
return BadRequest();
|
||||
}
|
||||
return Ok(link.ShortCode);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,15 +0,0 @@
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace QRCodeService.Controllers
|
||||
{
|
||||
[Route("api/v1/[controller]")]
|
||||
public class AppController:ControllerBase
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1,58 +0,0 @@
|
||||
using Domain.AggregateModel.LinkAggregate;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using QRCodeService.Models;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Security.Cryptography;
|
||||
using Domain.AggregateModel.AppAggregate;
|
||||
using Base62;
|
||||
using QRCodeService.Extensions;
|
||||
|
||||
namespace QRCodeService.Controllers
|
||||
{
|
||||
/// <summary>
|
||||
/// 生成二维码图片
|
||||
/// </summary>
|
||||
[Route("api/[controller]")]
|
||||
[ApiController]
|
||||
public class GenController:ControllerBase
|
||||
{
|
||||
readonly ILinkRepository linkRepository;
|
||||
readonly IAppRepository appRepository;
|
||||
|
||||
public GenController(ILinkRepository linkRepository, IAppRepository appRepository)
|
||||
{
|
||||
this.linkRepository = linkRepository;
|
||||
this.appRepository = appRepository;
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
public async Task<IActionResult> CreateLink(GenInputModel model)
|
||||
{
|
||||
|
||||
var app = await appRepository.GetAsync(model.AppId);
|
||||
if (app == null)
|
||||
{
|
||||
return BadRequest();
|
||||
}
|
||||
using(var md5 = MD5.Create())
|
||||
{
|
||||
var result = md5.ComputeHash(Encoding.UTF8.GetBytes($"{model.AppId}{model.SuffixUrl}{model.Time}{app.AppKey}"));
|
||||
var sign = BitConverter.ToString(result);
|
||||
if (sign != model.Sign)
|
||||
{
|
||||
return BadRequest();
|
||||
}
|
||||
}
|
||||
var shortCode = $"{model.SuffixUrl}".ToMD5().ToBase62();
|
||||
var link = new Link(app.BaseUrl, model.SuffixUrl,1);
|
||||
linkRepository.Add(link);
|
||||
await linkRepository.UnitOfWork.SaveEntitiesAsync();
|
||||
return Ok(link.ShortCode);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,30 +0,0 @@
|
||||
using Domain.AggregateModel.LinkAggregate;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace QRCodeService.Controllers
|
||||
{
|
||||
/// <summary>
|
||||
/// 跳转url请求的地址
|
||||
/// </summary>
|
||||
[Route("{shortCode}")]
|
||||
public class GoController: Controller
|
||||
{
|
||||
//readonly ILinkRepository LinkRepository;
|
||||
//public GoController(ILinkRepository linkRepository)
|
||||
//{
|
||||
// LinkRepository = linkRepository;
|
||||
//}
|
||||
[HttpGet]
|
||||
public async Task<IActionResult> Index(string shortcode)
|
||||
{
|
||||
var a = new { Url = "asdasd" };
|
||||
//var link = await LinkRepository.GetAsync(shortcode);
|
||||
return View(a);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -14,6 +14,7 @@ namespace QRCodeService.Controllers
|
||||
public class ImageController : ControllerBase
|
||||
{
|
||||
[Route("{shortCode}")]
|
||||
[HttpGet]
|
||||
public IActionResult Get(string shortCode)
|
||||
{
|
||||
var qrCodeGenerator = new QRCodeGenerator();
|
||||
|
||||
@@ -10,6 +10,7 @@ using Microsoft.Extensions.Logging;
|
||||
namespace QRCodeService.Controllers
|
||||
{
|
||||
[Route("[controller]/[action]")]
|
||||
[ApiController]
|
||||
public class PlaygroundController:ControllerBase
|
||||
{
|
||||
private readonly ILogger<PlaygroundController> logger;
|
||||
@@ -18,7 +19,7 @@ namespace QRCodeService.Controllers
|
||||
{
|
||||
this.logger = logger;
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
public IActionResult GenShortCode(string url)
|
||||
{
|
||||
logger.LogInformation("duduledule");
|
||||
|
||||
27
QRCodeService/Controllers/RedirectController.cs
Normal file
27
QRCodeService/Controllers/RedirectController.cs
Normal file
@@ -0,0 +1,27 @@
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using QRCodeService.Application.Queries;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace QRCodeService.Controllers
|
||||
{
|
||||
[Route("{shortCode}")]
|
||||
public class RedirectController:Controller
|
||||
{
|
||||
private readonly ILinkQueries queries;
|
||||
|
||||
public RedirectController(ILinkQueries queries)
|
||||
{
|
||||
this.queries = queries;
|
||||
}
|
||||
[HttpGet]
|
||||
public async Task<IActionResult> Index(string shortCode)
|
||||
{
|
||||
var link = await queries.GetLinkAsync(shortCode);
|
||||
return View(link);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user