1
0
Fork 0
mirror of https://github.com/docker/awesome-compose.git synced 2025-04-29 07:38:02 +02:00

Added backend

Signed-off-by: GitHub <noreply@github.com>
This commit is contained in:
Esteban Solano Granados 2022-06-11 01:26:09 +00:00 committed by GitHub
parent c4c4136352
commit 718df2a62d
8 changed files with 473 additions and 22 deletions

View file

@ -0,0 +1,33 @@
using System;
using System.Linq;
using System.Threading.Tasks;
using MongoDB.Bson;
using MongoDB.Bson.Serialization.Attributes;
using MongoDB.Driver;
using Models;
var builder = WebApplication.CreateBuilder(args);
string connectionString = File.ReadAllText("/run/secrets/db-connection");
builder.Services.AddTransient<MongoClient>((_provider) => new MongoClient(connectionString));
var app = builder.Build();
app.MapGet("/api", async (MongoClient connection) => {
try
{
var client = new MongoClient(connectionString);
var database = client.GetDatabase("BackendMongoDb");
var collection = database.GetCollection<ToDo>("ToDos");
var results = await collection.Find(_ => true).ToListAsync().ConfigureAwait(false);
return Results.Ok(results);
}
catch (Exception ex)
{
return Results.Problem(detail: ex.ToString());
}
});
app.Run();