using Microsoft.Extensions.Logging;
using System;
using System.Threading.Tasks;
namespace MyAvaloniaApp.Services;
///
/// API 服务实现
///
public class ApiService : IApiService
{
private readonly ILogger? _logger;
public ApiService(ILogger? logger = null)
{
_logger = logger;
_logger?.LogInformation("ApiService 已创建");
}
public async Task GetApiDataAsync(string endpoint)
{
_logger?.LogInformation("调用 API: {Endpoint}", endpoint);
// 模拟 API 调用
await Task.Delay(500);
var result = $"API 响应数据来自 {endpoint} - {DateTime.Now:HH:mm:ss}";
_logger?.LogDebug("API 响应: {Result}", result);
return result;
}
public async Task PostDataAsync(string endpoint, object data)
{
_logger?.LogInformation("POST 数据到 API: {Endpoint}", endpoint);
// 模拟 API 调用
await Task.Delay(300);
_logger?.LogDebug("数据已发送: {Data}", data);
return true;
}
}