update:重复创建也返回成功
创建时可直接返回二维码
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
using Domain.AggregateModel.LinkAggregate;
|
||||
using Domain.Exceptions;
|
||||
using MediatR;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
@@ -13,16 +14,19 @@ namespace QRCodeService.Application.Commands
|
||||
{
|
||||
public class CreateLinkCommandHandler : IRequestHandler<CreateLinkCommand, Link>
|
||||
{
|
||||
|
||||
readonly ILogger<CreateLinkCommandHandler> logger;
|
||||
readonly IAppRepository appRepository;
|
||||
readonly ILinkRepository linkRepository;
|
||||
|
||||
public CreateLinkCommandHandler(ILinkRepository linkRepository, IAppRepository appRepository)
|
||||
public CreateLinkCommandHandler(ILinkRepository linkRepository, IAppRepository appRepository, ILogger<CreateLinkCommandHandler> logger)
|
||||
{
|
||||
this.linkRepository = linkRepository;
|
||||
this.appRepository = appRepository;
|
||||
this.logger = logger;
|
||||
}
|
||||
|
||||
async Task<Link> IRequestHandler<CreateLinkCommand, Link>.Handle(CreateLinkCommand request, CancellationToken cancellationToken)
|
||||
async Task<Link> IRequestHandler<CreateLinkCommand, Link>.Handle(CreateLinkCommand request, CancellationToken cancellationToken)
|
||||
{
|
||||
var app = await appRepository.GetAsync(request.AppId);
|
||||
if (app == null)
|
||||
@@ -33,7 +37,8 @@ namespace QRCodeService.Application.Commands
|
||||
var dbLink = await linkRepository.GetAsync(link.ShortCode);
|
||||
if (dbLink != null)
|
||||
{
|
||||
throw new DomainException("url has been registed");
|
||||
logger.LogDebug("use exist link");
|
||||
return dbLink;
|
||||
}
|
||||
link = linkRepository.Add(link);
|
||||
await linkRepository.UnitOfWork.SaveEntitiesAsync();
|
||||
|
||||
Reference in New Issue
Block a user