Skip to content

Commit 5cb7a5e

Browse files
committed
init-commit
0 parents  commit 5cb7a5e

23 files changed

+1098
-0
lines changed

.gitignore

+479
Large diffs are not rendered by default.

.vscode/launch.json

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
{
2+
"version": "0.2.0",
3+
"configurations": [
4+
{
5+
// Use IntelliSense to find out which attributes exist for C# debugging
6+
// Use hover for the description of the existing attributes
7+
// For further information visit https://github.com/OmniSharp/omnisharp-vscode/blob/master/debugger-launchjson.md
8+
"name": ".NET Core Launch (web)",
9+
"type": "coreclr",
10+
"request": "launch",
11+
"preLaunchTask": "build",
12+
// If you have changed target frameworks, make sure to update the program path.
13+
"program": "${workspaceFolder}/API/bin/Debug/net7.0/API.dll",
14+
"args": [],
15+
"cwd": "${workspaceFolder}/API",
16+
"stopAtEntry": false,
17+
// Enable launching a web browser when ASP.NET Core starts. For more information: https://aka.ms/VSCode-CS-LaunchJson-WebBrowser
18+
"serverReadyAction": {
19+
"action": "openExternally",
20+
"pattern": "\\bNow listening on:\\s+(https?://\\S+)"
21+
},
22+
"env": {
23+
"ASPNETCORE_ENVIRONMENT": "Development"
24+
},
25+
"sourceFileMap": {
26+
"/Views": "${workspaceFolder}/Views"
27+
}
28+
},
29+
{
30+
"name": ".NET Core Attach",
31+
"type": "coreclr",
32+
"request": "attach"
33+
}
34+
]
35+
}

.vscode/tasks.json

+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
{
2+
"version": "2.0.0",
3+
"tasks": [
4+
{
5+
"label": "build",
6+
"command": "dotnet",
7+
"type": "process",
8+
"args": [
9+
"build",
10+
"${workspaceFolder}/API/API.csproj",
11+
"/property:GenerateFullPaths=true",
12+
"/consoleloggerparameters:NoSummary"
13+
],
14+
"problemMatcher": "$msCompile"
15+
},
16+
{
17+
"label": "publish",
18+
"command": "dotnet",
19+
"type": "process",
20+
"args": [
21+
"publish",
22+
"${workspaceFolder}/API/API.csproj",
23+
"/property:GenerateFullPaths=true",
24+
"/consoleloggerparameters:NoSummary"
25+
],
26+
"problemMatcher": "$msCompile"
27+
},
28+
{
29+
"label": "watch",
30+
"command": "dotnet",
31+
"type": "process",
32+
"args": [
33+
"watch",
34+
"run",
35+
"--project",
36+
"${workspaceFolder}/API/API.csproj"
37+
],
38+
"problemMatcher": "$msCompile"
39+
}
40+
]
41+
}

API/API.csproj

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<Project Sdk="Microsoft.NET.Sdk.Web">
2+
3+
<PropertyGroup>
4+
<TargetFramework>net7.0</TargetFramework>
5+
<Nullable>disable</Nullable>
6+
<ImplicitUsings>enable</ImplicitUsings>
7+
</PropertyGroup>
8+
9+
<ItemGroup>
10+
<PackageReference Include="Microsoft.AspNetCore.OpenApi" Version="7.0.4" />
11+
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="7.0.4">
12+
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
13+
<PrivateAssets>all</PrivateAssets>
14+
</PackageReference>
15+
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.4.0" />
16+
</ItemGroup>
17+
18+
<ItemGroup>
19+
<ProjectReference Include="..\Application\Application.csproj" />
20+
</ItemGroup>
21+
22+
</Project>
+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
using Domain;
2+
using Microsoft.AspNetCore.Mvc;
3+
using Microsoft.EntityFrameworkCore;
4+
using Persistence;
5+
6+
namespace API.Controllers
7+
{
8+
public class ActivitiesController : BaseApiController
9+
{
10+
private readonly DataContext _context;
11+
12+
public ActivitiesController(DataContext context)
13+
{
14+
_context = context;
15+
}
16+
17+
[HttpGet] //api/activities
18+
public async Task<ActionResult<List<Activity>>> GetActivities()
19+
{
20+
return await _context.Activities.ToListAsync();
21+
}
22+
23+
[HttpGet("{id}")] //api/activities/ididid
24+
public async Task<ActionResult<Activity>> GetActivity(Guid id)
25+
{
26+
return await _context.Activities.FindAsync(id);
27+
}
28+
29+
}
30+
}

API/Controllers/BaseApiController.cs

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
using Microsoft.AspNetCore.Mvc;
2+
3+
namespace API.Controllers
4+
{
5+
[ApiController]
6+
[Route("api/[controller]")]
7+
public class BaseApiController : ControllerBase
8+
{
9+
10+
}
11+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
using Microsoft.AspNetCore.Mvc;
2+
3+
namespace API.Controllers;
4+
5+
[ApiController]
6+
[Route("[controller]")]
7+
public class WeatherForecastController : ControllerBase
8+
{
9+
private static readonly string[] Summaries = new[]
10+
{
11+
"Freezing", "Bracing", "Chilly", "Cool", "Mild", "Warm", "Balmy", "Hot", "Sweltering", "Scorching"
12+
};
13+
14+
private readonly ILogger<WeatherForecastController> _logger;
15+
16+
public WeatherForecastController(ILogger<WeatherForecastController> logger)
17+
{
18+
_logger = logger;
19+
}
20+
21+
[HttpGet(Name = "GetWeatherForecast")]
22+
public IEnumerable<WeatherForecast> Get()
23+
{
24+
return Enumerable.Range(1, 5).Select(index => new WeatherForecast
25+
{
26+
Date = DateOnly.FromDateTime(DateTime.Now.AddDays(index)),
27+
TemperatureC = Random.Shared.Next(-20, 55),
28+
Summary = Summaries[Random.Shared.Next(Summaries.Length)]
29+
})
30+
.ToArray();
31+
}
32+
}

API/Program.cs

+46
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
using Microsoft.EntityFrameworkCore;
2+
using Persistence;
3+
4+
var builder = WebApplication.CreateBuilder(args);
5+
6+
// Add services to the container.
7+
8+
builder.Services.AddControllers();
9+
// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
10+
builder.Services.AddEndpointsApiExplorer();
11+
builder.Services.AddSwaggerGen();
12+
builder.Services.AddDbContext<DataContext>(opt => {
13+
opt.UseSqlite(builder.Configuration.GetConnectionString("DafaultConnection"));
14+
});
15+
16+
var app = builder.Build();
17+
18+
// Configure the HTTP request pipeline.
19+
if (app.Environment.IsDevelopment())
20+
{
21+
app.UseSwagger();
22+
app.UseSwaggerUI();
23+
}
24+
25+
app.UseHttpsRedirection();
26+
27+
app.UseAuthorization();
28+
29+
app.MapControllers();
30+
31+
using var scope = app.Services.CreateScope();
32+
var services = scope.ServiceProvider;
33+
34+
try
35+
{
36+
var context = services.GetRequiredService<DataContext>();
37+
await context.Database.MigrateAsync();
38+
await Seed.SeedData(context);
39+
}
40+
catch (Exception ex)
41+
{
42+
var logger = services.GetRequiredService<ILogger<Program>>();
43+
logger.LogError(ex, "An error occured during migration");
44+
}
45+
46+
app.Run();

API/Properties/launchSettings.json

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
"$schema": "https://json.schemastore.org/launchsettings.json",
3+
"profiles": {
4+
"http": {
5+
"commandName": "Project",
6+
"dotnetRunMessages": true,
7+
"launchBrowser": false,
8+
"applicationUrl": "http://localhost:5000",
9+
"environmentVariables": {
10+
"ASPNETCORE_ENVIRONMENT": "Development"
11+
}
12+
}
13+
}
14+
}

API/WeatherForecast.cs

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
namespace API;
2+
3+
public class WeatherForecast
4+
{
5+
public DateOnly Date { get; set; }
6+
7+
public int TemperatureC { get; set; }
8+
9+
public int TemperatureF => 32 + (int)(TemperatureC / 0.5556);
10+
11+
public string Summary { get; set; }
12+
}

API/appsettings.Development.json

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"Logging": {
3+
"LogLevel": {
4+
"Default": "Information",
5+
"Microsoft.AspNetCore": "Information"
6+
}
7+
},
8+
"ConnectionStrings": {
9+
"DafaultConnection": "Data Source=reactivities.db"
10+
}
11+
}

API/reactivities.db

20 KB
Binary file not shown.

Application/Application.csproj

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<ItemGroup>
4+
<ProjectReference Include="..\Domain\Domain.csproj" />
5+
<ProjectReference Include="..\Persistence\Persistence.csproj" />
6+
</ItemGroup>
7+
8+
<PropertyGroup>
9+
<TargetFramework>net7.0</TargetFramework>
10+
<ImplicitUsings>enable</ImplicitUsings>
11+
<Nullable>disable</Nullable>
12+
</PropertyGroup>
13+
14+
</Project>

Application/Class1.cs

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
namespace Application;
2+
public class Class1
3+
{
4+
5+
}

Domain/Activity.cs

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
namespace Domain
2+
{
3+
public class Activity
4+
{
5+
public Guid Id { get; set; }
6+
public string Title { get; set; }
7+
public DateTime Date { get; set; }
8+
public string Description { get; set; }
9+
public string Category { get; set; }
10+
public string City { get; set; }
11+
public string Venue { get; set; }
12+
}
13+
}

Domain/Domain.csproj

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<TargetFramework>net7.0</TargetFramework>
5+
<ImplicitUsings>enable</ImplicitUsings>
6+
<Nullable>disable</Nullable>
7+
</PropertyGroup>
8+
9+
</Project>

Persistence/DataContext.cs

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
using Domain;
2+
using Microsoft.EntityFrameworkCore;
3+
4+
namespace Persistence
5+
{
6+
public class DataContext : DbContext
7+
{
8+
public DataContext(DbContextOptions options) : base(options)
9+
{
10+
}
11+
12+
public DbSet<Activity> Activities { get; set; }
13+
}
14+
}

Persistence/Migrations/20230320131035_InitialCreate.Designer.cs

+54
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)