Updated delete logic for voice works.
This commit is contained in:
@@ -7,6 +7,7 @@ using JSMR.Application.Tags.Queries.Search;
|
||||
using JSMR.Application.VoiceWorks.Commands.Delete;
|
||||
using JSMR.Application.VoiceWorks.Commands.SetFavorite;
|
||||
using JSMR.Application.VoiceWorks.Queries.Search;
|
||||
using JSMR.UI.Blazor.Exceptions;
|
||||
using System.Net.Http.Json;
|
||||
using System.Text.Json;
|
||||
using System.Text.Json.Serialization;
|
||||
@@ -23,6 +24,18 @@ public class VoiceWorksClient(HttpClient http)
|
||||
}
|
||||
};
|
||||
|
||||
private static async Task<T?> ReadJsonOrThrowAsync<T>(HttpResponseMessage response, CancellationToken cancellationToken)
|
||||
{
|
||||
if (!response.IsSuccessStatusCode)
|
||||
{
|
||||
string body = await response.Content.ReadAsStringAsync(cancellationToken);
|
||||
|
||||
throw new ApiException(response.StatusCode, $"Request failed: {(int)response.StatusCode}", body);
|
||||
}
|
||||
|
||||
return await response.Content.ReadFromJsonAsync<T>(JsonOptions, cancellationToken: cancellationToken);
|
||||
}
|
||||
|
||||
public async Task<SearchVoiceWorksResponse?> SearchAsync(SearchVoiceWorksRequest request, CancellationToken ct = default)
|
||||
{
|
||||
using var resp = await http.PostAsJsonAsync("/api/voiceworks/search", request, ct);
|
||||
@@ -56,7 +69,8 @@ public class VoiceWorksClient(HttpClient http)
|
||||
public async Task<DeleteVoiceWorkResponse?> DeleteVoiceWorkAsync(DeleteVoiceWorkRequest request, CancellationToken ct = default)
|
||||
{
|
||||
using var resp = await http.PostAsJsonAsync("/api/voicework/delete", request, ct);
|
||||
return await resp.Content.ReadFromJsonAsync<DeleteVoiceWorkResponse>(JsonOptions, cancellationToken: ct);
|
||||
//return await resp.Content.ReadFromJsonAsync<DeleteVoiceWorkResponse>(JsonOptions, cancellationToken: ct);
|
||||
return await ReadJsonOrThrowAsync<DeleteVoiceWorkResponse>(resp, ct);
|
||||
}
|
||||
|
||||
public async Task<UpdateTagStatusResponse?> UpdateTagStatusAsync(UpdateTagStatusRequest request, CancellationToken ct = default)
|
||||
|
||||
Reference in New Issue
Block a user