mirror of
https://github.com/temporal-community/temporal-ai-agent.git
synced 2026-03-17 06:58:09 +01:00
tcloud compatibility, dotnet bug fixes
This commit is contained in:
@@ -1,20 +1,28 @@
|
||||
using System.Net.Http.Json;
|
||||
using System.Text.Json;
|
||||
using Temporalio.Activities;
|
||||
using TrainSearchWorker.Models;
|
||||
using TrainSearchWorker.Converters;
|
||||
|
||||
namespace TrainSearchWorker.Activities;
|
||||
|
||||
public class TrainActivities
|
||||
{
|
||||
private readonly HttpClient _client;
|
||||
private readonly JsonSerializerOptions _jsonOptions;
|
||||
|
||||
public TrainActivities(IHttpClientFactory clientFactory)
|
||||
{
|
||||
_client = clientFactory.CreateClient("TrainApi");
|
||||
_jsonOptions = new JsonSerializerOptions
|
||||
{
|
||||
PropertyNameCaseInsensitive = true
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
[Activity]
|
||||
public async Task<List<Journey>> SearchTrains(SearchTrainsRequest request)
|
||||
public async Task<JourneyResponse> SearchTrains(SearchTrainsRequest request)
|
||||
{
|
||||
var response = await _client.GetAsync(
|
||||
$"api/search?from={Uri.EscapeDataString(request.From)}" +
|
||||
@@ -24,17 +32,28 @@ public class TrainActivities
|
||||
|
||||
response.EnsureSuccessStatusCode();
|
||||
|
||||
return await response.Content.ReadFromJsonAsync<List<Journey>>()
|
||||
?? throw new InvalidOperationException("Received null response from API");
|
||||
// Deserialize into JourneyResponse rather than List<Journey>
|
||||
var journeyResponse = await response.Content.ReadFromJsonAsync<JourneyResponse>(_jsonOptions)
|
||||
?? throw new InvalidOperationException("Received null response from API");
|
||||
|
||||
return journeyResponse;
|
||||
}
|
||||
|
||||
[Activity]
|
||||
public async Task<List<Journey>> BookTrains(BookTrainsRequest request)
|
||||
public async Task<BookTrainsResponse> BookTrains(BookTrainsRequest request)
|
||||
{
|
||||
var response = await _client.PostAsJsonAsync("api/book", request);
|
||||
// Build the URL using the train IDs from the request
|
||||
var url = $"api/book/{Uri.EscapeDataString(request.TrainIds)}";
|
||||
|
||||
// POST with no JSON body, matching the Python version
|
||||
var response = await _client.PostAsync(url, null);
|
||||
response.EnsureSuccessStatusCode();
|
||||
|
||||
return await response.Content.ReadFromJsonAsync<List<Journey>>()
|
||||
?? throw new InvalidOperationException("Received null response from API");
|
||||
// Deserialize into a BookTrainsResponse (a single object)
|
||||
var bookingResponse = await response.Content.ReadFromJsonAsync<BookTrainsResponse>(_jsonOptions)
|
||||
?? throw new InvalidOperationException("Received null response from API");
|
||||
|
||||
return bookingResponse;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user