2
0
Files
dotnet-interview-exercise/service/Program.cs
Simon Dellenbach f1c0021ad3 Use a local SQLite3 backend instead of PostgreSQL Docker container.
* The provided SQLite3 database contains the required schemas, but no data and can be reset to if required.
* Remove all references to PostgreSQL in documentation and configuration.
* Replace native sqlite3 command with a console app to remove dependency on SQLite3 installation.
2026-02-17 16:25:49 +01:00

46 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 =>
{
var connectionString = builder.Configuration.GetValue<string>("SqliteConnection");
Console.WriteLine($"Setting up SQLite database with {connectionString}");
optionsBuilder.UseSqlite(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();