46 lines
1.6 KiB
C#
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. when testing with an Id > 100).
|
|
return Results.Ok();
|
|
})
|
|
.WithRequestTimeout(TimeSpan.FromSeconds(29))
|
|
.WithName("GetPostById")
|
|
.WithOpenApi();
|
|
|
|
app.Run();
|