init project
This commit is contained in:
34
QRCodeService/Controllers/GoController.cs
Normal file
34
QRCodeService/Controllers/GoController.cs
Normal file
@@ -0,0 +1,34 @@
|
||||
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}")]
|
||||
[ApiController]
|
||||
public class GoController: ControllerBase
|
||||
{
|
||||
readonly ILinkRepository LinkRepository;
|
||||
public GoController(ILinkRepository linkRepository)
|
||||
{
|
||||
LinkRepository = linkRepository;
|
||||
}
|
||||
[HttpGet]
|
||||
public async Task<IActionResult> Get(string shortcode)
|
||||
{
|
||||
var link = await LinkRepository.GetAsync(shortcode);
|
||||
if (link == null)
|
||||
{
|
||||
return NotFound();
|
||||
}
|
||||
return Redirect(link.FullUrl);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user