feat: Add ClearCart command and response, implement CancelOrder command with validation, and enhance DeliveryStatus and User models
This commit is contained in:
@@ -0,0 +1,104 @@
|
||||
using CMSMicroservice.Application.DayaLoanCQ.Services;
|
||||
using CMSMicroservice.Domain.Enums;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Net.Http;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace CMSMicroservice.Infrastructure.Services;
|
||||
|
||||
/// <summary>
|
||||
/// Mock Implementation برای شبیهسازی Daya API
|
||||
/// این کلاس فقط برای تست و توسعه است و باید با Implementation واقعی جایگزین شود
|
||||
/// </summary>
|
||||
public class MockDayaLoanApiService : IDayaLoanApiService
|
||||
{
|
||||
private readonly ILogger<MockDayaLoanApiService> _logger;
|
||||
|
||||
public MockDayaLoanApiService(ILogger<MockDayaLoanApiService> logger)
|
||||
{
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
public async Task<List<DayaLoanStatusResult>> CheckLoanStatusAsync(
|
||||
List<string> nationalCodes,
|
||||
CancellationToken cancellationToken = default)
|
||||
{
|
||||
_logger.LogWarning("⚠️ Using MOCK Daya API Service - Replace with real implementation!");
|
||||
|
||||
// شبیهسازی تاخیر شبکه
|
||||
await Task.Delay(100, cancellationToken);
|
||||
|
||||
var results = new List<DayaLoanStatusResult>();
|
||||
|
||||
foreach (var nationalCode in nationalCodes)
|
||||
{
|
||||
// شبیهسازی: کدملیهایی که با 1 شروع میشوند وام گرفتهاند
|
||||
if (nationalCode.StartsWith("1"))
|
||||
{
|
||||
results.Add(new DayaLoanStatusResult
|
||||
{
|
||||
NationalCode = nationalCode,
|
||||
Status = DayaLoanStatus.PendingReceive,
|
||||
ContractNumber = $"MOCK-DAYA-{nationalCode}-{DateTime.Now.Ticks}"
|
||||
});
|
||||
}
|
||||
// شبیهسازی: کدملیهایی که با 2 شروع میشوند رد شدهاند
|
||||
else if (nationalCode.StartsWith("2"))
|
||||
{
|
||||
results.Add(new DayaLoanStatusResult
|
||||
{
|
||||
NationalCode = nationalCode,
|
||||
Status = DayaLoanStatus.Rejected,
|
||||
ContractNumber = null
|
||||
});
|
||||
}
|
||||
// بقیه: هنوز بررسی نشدهاند
|
||||
else
|
||||
{
|
||||
results.Add(new DayaLoanStatusResult
|
||||
{
|
||||
NationalCode = nationalCode,
|
||||
Status = DayaLoanStatus.PendingReceive,
|
||||
ContractNumber = null // هنوز قرارداد صادر نشده
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
_logger.LogInformation("Mock Daya API returned {Count} results", results.Count);
|
||||
return results;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Real Implementation برای API واقعی دایا
|
||||
/// TODO: این کلاس باید پیادهسازی شود زمانی که API دایا آماده شد
|
||||
/// </summary>
|
||||
public class DayaLoanApiService : IDayaLoanApiService
|
||||
{
|
||||
private readonly HttpClient _httpClient;
|
||||
private readonly ILogger<DayaLoanApiService> _logger;
|
||||
|
||||
public DayaLoanApiService(HttpClient httpClient, ILogger<DayaLoanApiService> logger)
|
||||
{
|
||||
_httpClient = httpClient;
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
public async Task<List<DayaLoanStatusResult>> CheckLoanStatusAsync(
|
||||
List<string> nationalCodes,
|
||||
CancellationToken cancellationToken = default)
|
||||
{
|
||||
// TODO: پیادهسازی واقعی API دایا
|
||||
// مثال:
|
||||
// var request = new DayaApiRequest { NationalCodes = nationalCodes };
|
||||
// var response = await _httpClient.PostAsJsonAsync("/api/loan/check", request, cancellationToken);
|
||||
// response.EnsureSuccessStatusCode();
|
||||
// var result = await response.Content.ReadFromJsonAsync<DayaApiResponse>(cancellationToken);
|
||||
// return MapToResults(result);
|
||||
|
||||
throw new NotImplementedException("Real Daya API is not implemented yet. Use MockDayaLoanApiService for testing.");
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user