-
-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathGetWeatherForecast.cs
More file actions
48 lines (41 loc) · 900 Bytes
/
GetWeatherForecast.cs
File metadata and controls
48 lines (41 loc) · 900 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
using Immediate.Handlers.Shared;
namespace Normal;
[Handler]
public static partial class GetWeatherForecast
{
private static readonly string[] Summaries =
[
"Freezing",
"Bracing",
"Chilly",
"Cool",
"Mild",
"Warm",
"Balmy",
"Hot",
"Sweltering",
"Scorching",
];
public sealed record Query;
public sealed record Response(DateOnly Date, int TemperatureC, string? Summary)
{
public int TemperatureF => 32 + (int)(TemperatureC / 0.5556);
}
private static ValueTask<IEnumerable<Response>> HandleAsync(
Query _,
CancellationToken token
)
{
token.ThrowIfCancellationRequested();
var forecast = Enumerable.Range(1, 5)
.Select(index =>
new Response
(
DateOnly.FromDateTime(DateTime.Now.AddDays(index)),
Random.Shared.Next(-20, 55),
Summaries[Random.Shared.Next(Summaries.Length)]
)
);
return ValueTask.FromResult(forecast);
}
}