35 lines
887 B
C#
35 lines
887 B
C#
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);
|
|
}
|
|
}
|
|
}
|