2
0
Files
Simon Dellenbach cf91281a51 Initial exercise setup.
Additions

* Instructions for manually starting the database.
* Each phase now has a success criteria with how to verify.
* Troubleshooting section for working with the Docker DB container.
* All phases of the exercise are described in README.md (with as little advanced hints as possible).
* DFD to illustrate phase 1
* Debugging starts the database container and applies schema migrations (no setup required).
* Launch settings for VS Code, VS 2022 and Rider (IntelliJ IDEA).
* Swagger UI is available at <http://localhost:8080/swagger/index.html> for testing.
2025-07-24 17:10:10 +02:00

47 lines
1.6 KiB
C#

using System;
using System.Net.Http;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Http;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Polly.Simmy;
using service;
var builder = WebApplication.CreateBuilder(args);
// Add services to the container.
var services = builder.Services;
services.AddRequestTimeouts();
// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
services.AddEndpointsApiExplorer();
services.AddSwaggerGen();
services.AddDbContext<AppDbContext>(optionsBuilder =>
{
// Configure the database connection string.
var connectionString = builder.Configuration.GetValue<string>("PostgresConnection");
Console.WriteLine($"Connecting to PostgreSQL database with connection string: {connectionString}");
optionsBuilder.UseNpgsql(connectionString);
});
var httpClientBuilder = services.AddHttpClient<JsonPlaceholderClient>();
var app = builder.Build();
app.UseSwagger();
app.UseSwaggerUI(); // Swagger UI is available at http://localhost:8080/swagger/index.html
app.UseRequestTimeouts();
app.MapGet("/posts/{id}", async (AppDbContext dbContext, JsonPlaceholderClient client, int id) =>
{
// TODO: (Phase 1) Implement the logic to retrieve a post by ID and store it in the database.
// Consider some minimal error handling in case the post is not found (e.g. Id > 100).
return Results.Ok();
})
.WithRequestTimeout(TimeSpan.FromSeconds(29))
.WithName("GetPostById")
.WithOpenApi();
app.Run();