update:优化二维码长度

This commit is contained in:
2021-04-21 17:00:16 +08:00
parent 4cf18f0b83
commit 88ce4f7026
6 changed files with 103 additions and 11 deletions

View File

@@ -3,6 +3,7 @@ using Domain.AggregateModel.LinkAggregate;
using Domain.Exceptions;
using MediatR;
using Microsoft.Extensions.Logging;
using QRCodeService.Services;
using System;
using System.Collections.Generic;
using System.Linq;
@@ -17,10 +18,12 @@ namespace QRCodeService.Application.Commands
readonly ILogger<CreateLinkCommandHandler> logger;
readonly IAppRepository appRepository;
private readonly IShortCodeService shortCodeService;
readonly ILinkRepository linkRepository;
public CreateLinkCommandHandler(ILinkRepository linkRepository, IAppRepository appRepository, ILogger<CreateLinkCommandHandler> logger)
public CreateLinkCommandHandler(IShortCodeService shortCodeService,ILinkRepository linkRepository, IAppRepository appRepository, ILogger<CreateLinkCommandHandler> logger)
{
this.shortCodeService = shortCodeService;
this.linkRepository = linkRepository;
this.appRepository = appRepository;
this.logger = logger;
@@ -33,13 +36,15 @@ namespace QRCodeService.Application.Commands
{
throw new DomainException("app not found");
}
var link = new Link(app.BaseUrl, request.SuffixUrl, request.AppId);
var dbLink = await linkRepository.GetAsync(link.ShortCode);
var fullUrl = new Uri(new Uri(app.BaseUrl), request.SuffixUrl).ToString();
var shortCode = await shortCodeService.GenShortCode(fullUrl);
var dbLink = await linkRepository.GetAsync(shortCode);
if (dbLink != null)
{
logger.LogDebug("use exist link");
return dbLink;
}
var link = new Link(app.BaseUrl, request.SuffixUrl,fullUrl, request.AppId, shortCode);
link = linkRepository.Add(link);
await linkRepository.UnitOfWork.SaveEntitiesAsync();
return link;