48 lines
1.8 KiB
C#
48 lines
1.8 KiB
C#
using JSMR.Application.Tags.Queries.Search;
|
|
using JSMR.Application.VoiceWorks.Queries.Search;
|
|
using JSMR.UI.Blazor;
|
|
using Microsoft.AspNetCore.Components.Web;
|
|
using Microsoft.AspNetCore.Components.WebAssembly.Hosting;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
using MudBlazor.Services;
|
|
using System.Net.Http.Json;
|
|
|
|
var builder = WebAssemblyHostBuilder.CreateDefault(args);
|
|
builder.RootComponents.Add<App>("#app");
|
|
builder.RootComponents.Add<HeadOutlet>("head::after");
|
|
|
|
var apiBase = builder.Configuration["ApiBaseUrl"] ?? builder.HostEnvironment.BaseAddress;
|
|
apiBase = "https://localhost:7277";
|
|
|
|
Console.WriteLine(apiBase);
|
|
|
|
builder.Services.AddScoped(sp => new HttpClient { BaseAddress = new Uri(apiBase) });
|
|
builder.Services.AddMudServices();
|
|
|
|
builder.Services.AddScoped<VoiceWorksClient>();
|
|
|
|
await builder.Build().RunAsync();
|
|
|
|
public class VoiceWorksClient(HttpClient http)
|
|
{
|
|
public async Task<SearchVoiceWorksResponse?> SearchAsync(SearchVoiceWorksRequest request, CancellationToken ct = default)
|
|
{
|
|
using var resp = await http.PostAsJsonAsync("/api/voiceworks/search", request, ct);
|
|
return await resp.Content.ReadFromJsonAsync<SearchVoiceWorksResponse>(cancellationToken: ct);
|
|
}
|
|
|
|
public async Task<SearchTagsResponse?> SearchAsync(SearchTagsRequest request, CancellationToken ct = default)
|
|
{
|
|
using var resp = await http.PostAsJsonAsync("/api/tags/search", request, ct);
|
|
return await resp.Content.ReadFromJsonAsync<SearchTagsResponse>(cancellationToken: ct);
|
|
}
|
|
}
|
|
|
|
public record VoiceWorkDto(string ProductId, string ProductName);
|
|
|
|
// Tiny helper result type
|
|
public readonly record struct Result<T>(bool Ok, T? Value, string? Error)
|
|
{
|
|
public static Result<T> Success(T v) => new(true, v, null);
|
|
public static Result<T> Failure(string e) => new(false, default, e);
|
|
} |