91 lines
2.7 KiB
C#
91 lines
2.7 KiB
C#
using Core.Blueprint.Service.External.Clients;
|
|
using Core.Blueprint.Service.External.Clients.BluePrintService;
|
|
using Refit;
|
|
|
|
namespace Core.Blueprint.Service.UseCases.BluePrint
|
|
{
|
|
public interface IBlueprintService
|
|
{
|
|
Task<IEnumerable<MongoBlueprintCollection>> GetBlueprintsAsync();
|
|
Task<MongoBlueprintCollection> GetBlueprintAsync(string id);
|
|
Task<MongoBlueprintCollection> CreateBlueprintAsync(MongoBlueprintCollection blueprint);
|
|
Task UpdateBlueprintAsync(string id, MongoBlueprintCollection blueprint);
|
|
Task DeleteBlueprintAsync(string id);
|
|
|
|
}
|
|
public class BlueprintService: IBlueprintService
|
|
{
|
|
private readonly IBluePrintServiceClient _blueprintApi;
|
|
|
|
public BlueprintService(IBluePrintServiceClient client)
|
|
{
|
|
_blueprintApi = client;
|
|
}
|
|
|
|
public async Task<IEnumerable<MongoBlueprintCollection>> GetBlueprintsAsync()
|
|
{
|
|
try
|
|
{
|
|
return await _blueprintApi.GetBlueprintsAsync();
|
|
}
|
|
catch (ApiException ex)
|
|
{
|
|
Console.WriteLine($"Error fetching blueprints: {ex.Message}");
|
|
throw;
|
|
}
|
|
}
|
|
|
|
public async Task<MongoBlueprintCollection> GetBlueprintAsync(string id)
|
|
{
|
|
try
|
|
{
|
|
return await _blueprintApi.GetBlueprintAsync(id);
|
|
}
|
|
catch (ApiException ex)
|
|
{
|
|
Console.WriteLine($"Error fetching blueprint with ID {id}: {ex.Message}");
|
|
throw;
|
|
}
|
|
}
|
|
|
|
public async Task<MongoBlueprintCollection> CreateBlueprintAsync(MongoBlueprintCollection blueprint)
|
|
{
|
|
try
|
|
{
|
|
return await _blueprintApi.CreateBlueprintAsync(blueprint);
|
|
}
|
|
catch (ApiException ex)
|
|
{
|
|
Console.WriteLine($"Error creating blueprint: {ex.Message}");
|
|
throw;
|
|
}
|
|
}
|
|
|
|
public async Task UpdateBlueprintAsync(string id, MongoBlueprintCollection blueprint)
|
|
{
|
|
try
|
|
{
|
|
await _blueprintApi.UpdateBlueprintAsync(id, blueprint);
|
|
}
|
|
catch (ApiException ex)
|
|
{
|
|
Console.WriteLine($"Error updating blueprint with ID {id}: {ex.Message}");
|
|
throw;
|
|
}
|
|
}
|
|
|
|
public async Task DeleteBlueprintAsync(string id)
|
|
{
|
|
try
|
|
{
|
|
await _blueprintApi.DeleteBlueprintAsync(id);
|
|
}
|
|
catch (ApiException ex)
|
|
{
|
|
Console.WriteLine($"Error deleting blueprint with ID {id}: {ex.Message}");
|
|
throw;
|
|
}
|
|
}
|
|
}
|
|
}
|