diff --git a/client/MAVN.Service.SmartVouchers.Client/Models/Responses/ReserveVoucherResponse.cs b/client/MAVN.Service.SmartVouchers.Client/Models/Responses/ReserveVoucherResponse.cs
index 32f9bbe..45bac19 100644
--- a/client/MAVN.Service.SmartVouchers.Client/Models/Responses/ReserveVoucherResponse.cs
+++ b/client/MAVN.Service.SmartVouchers.Client/Models/Responses/ReserveVoucherResponse.cs
@@ -14,5 +14,8 @@ public class ReserveVoucherResponse
/// Payment url
public string PaymentUrl { get; set; }
+
+ /// Short code of already reserved voucher
+ public string AlreadyReservedVoucherShortCode { get; set; }
}
}
diff --git a/src/MAVN.Service.SmartVouchers.Domain/Models/VoucherReservationResult.cs b/src/MAVN.Service.SmartVouchers.Domain/Models/VoucherReservationResult.cs
index 412e11f..bf5c395 100644
--- a/src/MAVN.Service.SmartVouchers.Domain/Models/VoucherReservationResult.cs
+++ b/src/MAVN.Service.SmartVouchers.Domain/Models/VoucherReservationResult.cs
@@ -7,5 +7,7 @@ public class VoucherReservationResult
public ProcessingVoucherError ErrorCode { get; set; }
public string PaymentUrl { get; set; }
+
+ public string AlreadyReservedVoucherShortCode { get; set; }
}
}
diff --git a/src/MAVN.Service.SmartVouchers.Domain/Repositories/IVouchersRepository.cs b/src/MAVN.Service.SmartVouchers.Domain/Repositories/IVouchersRepository.cs
index dfa7235..b93a558 100644
--- a/src/MAVN.Service.SmartVouchers.Domain/Repositories/IVouchersRepository.cs
+++ b/src/MAVN.Service.SmartVouchers.Domain/Repositories/IVouchersRepository.cs
@@ -25,7 +25,7 @@ Task GetByOwnerIdAsync(
Task> GetByCampaignIdAndStatusAsync(Guid campaignId, VoucherStatus status);
Task> GetReservedVouchersBeforeDateAsync(DateTime reservationTimeoutDate);
Task SetVouchersFromCampaignsAsExpired(Guid[] campaignsIds);
- Task AnyReservedVouchersAsync(Guid customerId);
+ Task GetReservedVoucherForCustomerAsync(Guid customerId);
Task GetReservedVouchersCountForCampaign(Guid campaignId);
}
}
diff --git a/src/MAVN.Service.SmartVouchers.DomainServices/VouchersService.cs b/src/MAVN.Service.SmartVouchers.DomainServices/VouchersService.cs
index d65f42e..4ffcf94 100644
--- a/src/MAVN.Service.SmartVouchers.DomainServices/VouchersService.cs
+++ b/src/MAVN.Service.SmartVouchers.DomainServices/VouchersService.cs
@@ -122,9 +122,13 @@ public async Task ReserveVoucherAsync(Guid voucherCamp
continue;
}
- var hasAnyReservedVouchers = await _vouchersRepository.AnyReservedVouchersAsync(ownerId);
- if (hasAnyReservedVouchers)
- return new VoucherReservationResult { ErrorCode = ProcessingVoucherError.CustomerHaveAnotherReservedVoucher };
+ var alreadyReservedVoucher = await _vouchersRepository.GetReservedVoucherForCustomerAsync(ownerId);
+ if (alreadyReservedVoucher != null)
+ return new VoucherReservationResult
+ {
+ ErrorCode = ProcessingVoucherError.CustomerHaveAnotherReservedVoucher,
+ AlreadyReservedVoucherShortCode = alreadyReservedVoucher.ShortCode
+ };
var vouchers = await _vouchersRepository.GetByCampaignIdAndStatusAsync(voucherCampaignId, VoucherStatus.InStock);
Voucher voucher = null;
diff --git a/src/MAVN.Service.SmartVouchers.MsSqlRepositories/Repositories/VouchersRepository.cs b/src/MAVN.Service.SmartVouchers.MsSqlRepositories/Repositories/VouchersRepository.cs
index 9c66380..953510f 100644
--- a/src/MAVN.Service.SmartVouchers.MsSqlRepositories/Repositories/VouchersRepository.cs
+++ b/src/MAVN.Service.SmartVouchers.MsSqlRepositories/Repositories/VouchersRepository.cs
@@ -220,14 +220,14 @@ public async Task SetVouchersFromCampaignsAsExpired(Guid[] campaignsIds)
}
}
- public async Task AnyReservedVouchersAsync(Guid customerId)
+ public async Task GetReservedVoucherForCustomerAsync(Guid customerId)
{
using (var context = _contextFactory.CreateDataContext())
{
- var result = await context.Vouchers
- .AnyAsync(x => x.OwnerId == customerId && x.Status == VoucherStatus.Reserved);
+ var entity = await context.Vouchers
+ .FirstOrDefaultAsync(x => x.OwnerId == customerId && x.Status == VoucherStatus.Reserved);
- return result;
+ return _mapper.Map(entity);
}
}