Skip to content

Commit d7e78b9

Browse files
committed
Merge branch 'topic/story-35050-aspire-logging-metalama'
2 parents 924da71 + 7775410 commit d7e78b9

54 files changed

Lines changed: 1797 additions & 0 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

src/aspire/logging-metalama/TodoList/.idea/.idea.TodoList/.idea/.gitignore

Lines changed: 13 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/aspire/logging-metalama/TodoList/.idea/.idea.TodoList/.idea/encodings.xml

Lines changed: 4 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/aspire/logging-metalama/TodoList/.idea/.idea.TodoList/.idea/indexLayout.xml

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/aspire/logging-metalama/TodoList/.idea/.idea.TodoList/.idea/vcs.xml

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/aspire/logging-metalama/TodoList/TodoList.Api/Migrations/20240718092245_Initial.Designer.cs

Lines changed: 42 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
using Microsoft.EntityFrameworkCore.Migrations;
2+
3+
#nullable disable
4+
5+
namespace TodoList.Api.Migrations
6+
{
7+
/// <inheritdoc />
8+
public partial class Initial : Migration
9+
{
10+
/// <inheritdoc />
11+
protected override void Up(MigrationBuilder migrationBuilder)
12+
{
13+
migrationBuilder.CreateTable(
14+
name: "Todos",
15+
columns: table => new
16+
{
17+
Id = table.Column<int>(type: "INTEGER", nullable: false)
18+
.Annotation("Sqlite:Autoincrement", true),
19+
IsCompleted = table.Column<bool>(type: "INTEGER", nullable: false),
20+
Title = table.Column<string>(type: "TEXT", nullable: false)
21+
},
22+
constraints: table =>
23+
{
24+
table.PrimaryKey("PK_Todos", x => x.Id);
25+
});
26+
}
27+
28+
/// <inheritdoc />
29+
protected override void Down(MigrationBuilder migrationBuilder)
30+
{
31+
migrationBuilder.DropTable(
32+
name: "Todos");
33+
}
34+
}
35+
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
// <auto-generated />
2+
using Microsoft.EntityFrameworkCore;
3+
using Microsoft.EntityFrameworkCore.Infrastructure;
4+
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
5+
using TodoList.ApiService.Model;
6+
7+
#nullable disable
8+
9+
namespace TodoList.Api.Migrations
10+
{
11+
[DbContext(typeof(ApplicationDbContext))]
12+
partial class ApplicationDbContextModelSnapshot : ModelSnapshot
13+
{
14+
protected override void BuildModel(ModelBuilder modelBuilder)
15+
{
16+
#pragma warning disable 612, 618
17+
modelBuilder.HasAnnotation("ProductVersion", "8.0.7");
18+
19+
modelBuilder.Entity("Todo", b =>
20+
{
21+
b.Property<int>("Id")
22+
.ValueGeneratedOnAdd()
23+
.HasColumnType("INTEGER");
24+
25+
b.Property<bool>("IsCompleted")
26+
.HasColumnType("INTEGER");
27+
28+
b.Property<string>("Title")
29+
.IsRequired()
30+
.HasColumnType("TEXT");
31+
32+
b.HasKey("Id");
33+
34+
b.ToTable("Todos");
35+
});
36+
#pragma warning restore 612, 618
37+
}
38+
}
39+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// Copyright (c) SharpCrafters s.r.o. See the LICENSE.md file in the root directory of this repository root for details.
2+
3+
using Microsoft.EntityFrameworkCore;
4+
5+
namespace TodoList.ApiService.Model;
6+
7+
public class ApplicationDbContext : DbContext
8+
{
9+
public ApplicationDbContext( DbContextOptions<ApplicationDbContext> options )
10+
: base( options ) { }
11+
12+
public DbSet<Todo> Todos { get; set; } = null!;
13+
}
Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
// Copyright (c) SharpCrafters s.r.o. See the LICENSE.md file in the root directory of this repository root for details.
2+
3+
using Microsoft.Data.Sqlite;
4+
using Microsoft.EntityFrameworkCore;
5+
using TodoList.ApiService.Model;
6+
using TodoList.ApiService.Services;
7+
8+
var builder = WebApplication.CreateBuilder( args );
9+
10+
// Add service defaults & Aspire components.
11+
builder.AddServiceDefaults();
12+
13+
// Add services to the container.
14+
15+
// Keep the database connection open for the lifetime of the application, so the in-memory database is not lost after each operation.
16+
// https://github.com/dotnet/efcore/issues/9842#issuecomment-1634427346
17+
using var dbConnection = new SqliteConnection( "Data Source=:memory:" );
18+
await dbConnection.OpenAsync();
19+
builder.Services.AddDbContext<ApplicationDbContext>( dbOptions => dbOptions.UseSqlite( dbConnection ) );
20+
21+
builder.Services.AddScoped<TodoService>();
22+
23+
var app = builder.Build();
24+
25+
using ( var scope = app.Services.CreateScope() )
26+
{
27+
var db = scope.ServiceProvider.GetRequiredService<ApplicationDbContext>().Database;
28+
db.EnsureCreated();
29+
}
30+
31+
app.MapDefaultEndpoints();
32+
33+
// Configure the HTTP request pipeline.
34+
app.UseHttpsRedirection();
35+
36+
// Ensure the schema is created.
37+
using ( var scope = app.Services.CreateScope() )
38+
{
39+
var db = scope.ServiceProvider.GetRequiredService<ApplicationDbContext>();
40+
await db.Database.EnsureCreatedAsync();
41+
}
42+
43+
app.MapGet(
44+
"/todo",
45+
( TodoService todos, CancellationToken cancellationToken )
46+
=> todos.GetTodosAsync( cancellationToken ) );
47+
48+
app.MapGet(
49+
"/todo/{id}",
50+
( TodoService todos, int id, CancellationToken cancellationToken )
51+
=> todos.GetTodoAsync( id, cancellationToken ) );
52+
53+
app.MapPost(
54+
"/todo",
55+
async ( TodoService todos, Todo todo, CancellationToken cancellationToken ) =>
56+
{
57+
var newTodo = await todos.AddTodoAsync( todo, cancellationToken );
58+
59+
return Results.Created( $"/todo/{newTodo.Id}", newTodo );
60+
} );
61+
62+
app.MapPut(
63+
"/todo/{id}",
64+
async ( TodoService todos, int id, Todo todo, CancellationToken cancellationToken ) =>
65+
{
66+
if ( id != todo.Id )
67+
{
68+
return Results.BadRequest( "The ID in the URL does not match the ID in the request body." );
69+
}
70+
71+
if ( await todos.UpdateTodoAsync( todo, cancellationToken ) )
72+
{
73+
return Results.NoContent();
74+
}
75+
else
76+
{
77+
return Results.NotFound();
78+
}
79+
} );
80+
81+
app.MapDelete(
82+
"/todo/{id}",
83+
async ( TodoService todos, int id, CancellationToken cancellationToken ) =>
84+
{
85+
if ( await todos.DeleteTodoAsync( id, cancellationToken ) )
86+
{
87+
return Results.NoContent();
88+
}
89+
else
90+
{
91+
return Results.NotFound();
92+
}
93+
} );
94+
95+
app.Run();
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
{
2+
"$schema": "http://json.schemastore.org/launchsettings.json",
3+
"iisSettings": {
4+
"windowsAuthentication": false,
5+
"anonymousAuthentication": true,
6+
"iisExpress": {
7+
"applicationUrl": "http://localhost:2741",
8+
"sslPort": 44375
9+
}
10+
},
11+
"profiles": {
12+
"http": {
13+
"commandName": "Project",
14+
"dotnetRunMessages": true,
15+
"launchBrowser": true,
16+
"launchUrl": "weatherforecast",
17+
"applicationUrl": "http://localhost:5251",
18+
"environmentVariables": {
19+
"ASPNETCORE_ENVIRONMENT": "Development"
20+
}
21+
},
22+
"https": {
23+
"commandName": "Project",
24+
"dotnetRunMessages": true,
25+
"launchBrowser": true,
26+
"launchUrl": "weatherforecast",
27+
"applicationUrl": "https://localhost:7212;http://localhost:5251",
28+
"environmentVariables": {
29+
"ASPNETCORE_ENVIRONMENT": "Development"
30+
}
31+
},
32+
"IIS Express": {
33+
"commandName": "IISExpress",
34+
"launchBrowser": true,
35+
"launchUrl": "weatherforecast",
36+
"environmentVariables": {
37+
"ASPNETCORE_ENVIRONMENT": "Development"
38+
}
39+
}
40+
}
41+
}

0 commit comments

Comments
 (0)