Skip to content

Commit b554c36

Browse files
committed
Load working template without Github workflow changes
1 parent 5a967ec commit b554c36

47 files changed

Lines changed: 168 additions & 20833 deletions

Some content is hidden

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

.gitignore

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
## A streamlined .gitignore for modern .NET projects
2+
## including temporary files, build results, and
3+
## files generated by popular .NET tools. If you are
4+
## developing with Visual Studio, the VS .gitignore
5+
## https://github.com/github/gitignore/blob/main/VisualStudio.gitignore
6+
## has more thorough IDE-specific entries.
7+
##
8+
## Get latest from https://github.com/github/gitignore/blob/main/Dotnet.gitignore
9+
10+
# Build results
11+
[Dd]ebug/
12+
[Dd]ebugPublic/
13+
[Rr]elease/
14+
[Rr]eleases/
15+
x64/
16+
x86/
17+
[Ww][Ii][Nn]32/
18+
[Aa][Rr][Mm]/
19+
[Aa][Rr][Mm]64/
20+
bld/
21+
[Bb]in/
22+
[Oo]bj/
23+
[Ll]og/
24+
[Ll]ogs/
25+
26+
# .NET Core
27+
project.lock.json
28+
project.fragment.lock.json
29+
artifacts/
30+
appsettings.json
31+
32+
# ASP.NET Scaffolding
33+
ScaffoldingReadMe.txt
34+
35+
# NuGet Packages
36+
*.nupkg
37+
# NuGet Symbol Packages
38+
*.snupkg
39+
40+
# dotenv environment variables file
41+
.env
42+
43+
# Others
44+
~$*
45+
*~
46+
CodeCoverage/
47+
48+
# MSBuild Binary and Structured Log
49+
*.binlog
50+
51+
# MSTest test Results
52+
[Tt]est[Rr]esult*/
53+
[Bb]uild[Ll]og.*
54+
55+
# NUnit
56+
*.VisualState.xml
57+
TestResult.xml
58+
nunit-*.xml
59+

Data/AppDbContext.cs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
2+
using Microsoft.EntityFrameworkCore;
3+
using TodoApi.Models;
4+
5+
namespace TodoApi.Data;
6+
7+
public class AppDbContext : DbContext
8+
{
9+
public AppDbContext(DbContextOptions<AppDbContext> options) : base(options)
10+
{
11+
}
12+
13+
public DbSet<TodoItem> TodoItems => Set<TodoItem>();
14+
}

Models/TodoItems.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
namespace TodoApi.Models;
2+
3+
public class TodoItem
4+
{
5+
public int Id { get; set; }
6+
public string Title { get; set; } = string.Empty;
7+
public bool IsCompleted { get; set; }
8+
}

Program.cs

Lines changed: 44 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,13 @@
1+
using TodoApi.Models;
2+
using TodoApi.Data;
3+
using Microsoft.EntityFrameworkCore;
4+
using Microsoft.AspNetCore.Mvc;
5+
16
var builder = WebApplication.CreateBuilder(args);
27

8+
builder.Services.AddDbContext<AppDbContext>(options =>
9+
options.UseNpgsql(builder.Configuration.GetConnectionString("DefaultConnection")));
10+
311
// Add services to the container.
412
// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
513
builder.Services.AddEndpointsApiExplorer();
@@ -16,29 +24,43 @@
1624

1725
app.UseHttpsRedirection();
1826

19-
var summaries = new[]
27+
28+
app.MapGet("/api/todos", async ([FromServices] AppDbContext db) =>
29+
await db.TodoItems.AsNoTracking().ToListAsync());
30+
31+
app.MapGet("/api/todos/{id:int}", async (int id, [FromServices] AppDbContext db) =>
32+
await db.TodoItems.FindAsync(id)
33+
is TodoItem todo
34+
? Results.Ok(todo)
35+
: Results.NotFound());
36+
37+
app.MapPost("/api/todos", async (TodoItem todo, [FromServices] AppDbContext db) =>
2038
{
21-
"Freezing", "Bracing", "Chilly", "Cool", "Mild", "Warm", "Balmy", "Hot", "Sweltering", "Scorching"
22-
};
39+
db.TodoItems.Add(todo);
40+
await db.SaveChangesAsync();
41+
return Results.Created($"/api/todos/{todo.Id}", todo);
42+
});
2343

24-
app.MapGet("/weatherforecast", () =>
44+
app.MapPut("/api/todos/{id:int}", async (int id, TodoItem input, [FromServices] AppDbContext db) =>
2545
{
26-
var forecast = Enumerable.Range(1, 5).Select(index =>
27-
new WeatherForecast
28-
(
29-
DateOnly.FromDateTime(DateTime.Now.AddDays(index)),
30-
Random.Shared.Next(-20, 55),
31-
summaries[Random.Shared.Next(summaries.Length)]
32-
))
33-
.ToArray();
34-
return forecast;
35-
})
36-
.WithName("GetWeatherForecast")
37-
.WithOpenApi();
38-
39-
app.Run();
40-
41-
record WeatherForecast(DateOnly Date, int TemperatureC, string? Summary)
46+
var todo = await db.TodoItems.FindAsync(id);
47+
if (todo is null) return Results.NotFound();
48+
49+
todo.Title = input.Title;
50+
todo.IsCompleted = input.IsCompleted;
51+
52+
await db.SaveChangesAsync();
53+
return Results.NoContent();
54+
});
55+
56+
app.MapDelete("/api/todos/{id:int}", async (int id, [FromServices] AppDbContext db) =>
4257
{
43-
public int TemperatureF => 32 + (int)(TemperatureC / 0.5556);
44-
}
58+
var todo = await db.TodoItems.FindAsync(id);
59+
if (todo is null) return Results.NotFound();
60+
61+
db.TodoItems.Remove(todo);
62+
await db.SaveChangesAsync();
63+
return Results.NoContent();
64+
});
65+
66+
app.Run();

README.md

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
> #### This is repository was created for the purpose of saving my thoughts during my study aspnet to understand all underwater rocks and setting up my configuration well. Of course all code i took from the internet and AI
2+
3+
## For the future:
4+
5+
#### ./appsettings.json - must be in Git Secret, it contains a DB login information.
6+
7+
It must contain:
8+
9+
ConnectionStrings:DefaultConnection
10+
Host=127.0.0.1;Port=5432;Database=todo_db;Username=todo_user;Password=...
11+
12+
---
13+
14+
Notes:
15+
16+
1. Setting up:
17+
18+
dotnet-sdk-8.0 aspnet-runtime-8.0, aspnet-targeting-pack-8.0
19+
20+
21+
dotnet tool install --global dotnet-ef
22+
23+
24+
sudo -iu postgres
25+
initdb -D /var/lib/postgres/data
26+
exit
27+
28+
sudo systemctl start postgresql
29+
sudo systemctl enable postgresql
30+
31+
32+
dotnet ef migrations add InitialCreate
33+
34+
1. First run:
35+
36+
dotnet restore
37+
dotnet run

appsettings.json

Lines changed: 0 additions & 9 deletions
This file was deleted.
-64.3 KB
Binary file not shown.
-228 KB
Binary file not shown.
-17 KB
Binary file not shown.
-116 KB
Binary file not shown.

0 commit comments

Comments
 (0)