|
1 | | -using S03E05; |
| 1 | +using System.Net.Http.Json; |
| 2 | +using Common.AiDevsApi.Models; |
| 3 | +using S03E05; |
2 | 4 | using S03E05.Models; |
3 | 5 |
|
4 | 6 | var builder = Host.CreateApplicationBuilder(args); |
|
10 | 12 | await using var scope = host.Services.CreateAsyncScope(); |
11 | 13 | var sp = scope.ServiceProvider; |
12 | 14 |
|
| 15 | +var dbUsers = await ListUsers(); |
| 16 | +var dbConnections = await ListConnections(); |
| 17 | + |
| 18 | +Console.WriteLine(JsonSerializer.Serialize(dbUsers)); |
| 19 | +Console.WriteLine(JsonSerializer.Serialize(dbConnections)); |
| 20 | + |
| 21 | + |
13 | 22 | // Add task-specific logic here |
14 | 23 |
|
15 | 24 | // var aiDevsApiService = sp.GetRequiredService<IAiDevsApiService>(); |
|
22 | 31 | // var taskResponseResult = await aiDevsApiService.VerifyTaskAnswerAsync(taskResponse); |
23 | 32 | // Console.WriteLine(JsonSerializer.Serialize(taskResponseResult)); |
24 | 33 |
|
| 34 | +async Task<IReadOnlyList<DbUser>> ListUsers() |
| 35 | +{ |
| 36 | + const string Command = "SELECT * FROM users"; |
| 37 | + var dbResponse = await RunDbCommand(Command); |
| 38 | + |
| 39 | + var parsedResponse = JsonSerializer.Deserialize<DbResponse<DbUser>>(dbResponse) |
| 40 | + ?? throw new InvalidOperationException("Invalid API response"); |
| 41 | + return parsedResponse.Reply; |
| 42 | +} |
| 43 | + |
| 44 | +async Task<IReadOnlyList<DbConnection>> ListConnections() |
| 45 | +{ |
| 46 | + const string Command = "SELECT * FROM connections"; |
| 47 | + var dbResponse = await RunDbCommand(Command); |
| 48 | + |
| 49 | + var parsedResponse = JsonSerializer.Deserialize<DbResponse<DbConnection>>(dbResponse) |
| 50 | + ?? throw new InvalidOperationException("Invalid API response"); |
| 51 | + return parsedResponse.Reply; |
| 52 | +} |
| 53 | + |
25 | 54 | async Task<string> RunDbCommand(string command) |
26 | 55 | { |
27 | 56 | var aiDevsOptions = sp.GetRequiredService<IOptions<AiDevsApiOptions>>().Value; |
28 | | - var taskOptions = sp.GetRequiredService<IOptions<S03E03Options>>().Value; |
| 57 | + var taskOptions = sp.GetRequiredService<IOptions<S03E05Options>>().Value; |
29 | 58 |
|
30 | 59 | var dbRequest = new DatabaseRequest |
31 | 60 | { |
|
0 commit comments