-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
50 lines (36 loc) · 1.35 KB
/
Program.cs
File metadata and controls
50 lines (36 loc) · 1.35 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
using DOTNETPokemonAPI.Database;
using DOTNETPokemonAPI.Usecases;
using Microsoft.EntityFrameworkCore;
using Npgsql;
var builder = WebApplication.CreateBuilder(args);
var connectionString = builder.Configuration.GetConnectionString("DefaultConnection");
var dataSourceBuilder = new NpgsqlDataSourceBuilder(connectionString);
dataSourceBuilder.EnableDynamicJson();
var dataSource = dataSourceBuilder.Build();
await using var conn = dataSource.OpenConnection();
Console.WriteLine($"PostgreSQL version: {conn.PostgreSqlVersion}");
builder.Services.AddDbContext<PokemonDb>(options =>
options.UseNpgsql(dataSource));
builder.Services.AddCors(options =>
{
options.AddDefaultPolicy(policy =>
{
policy.AllowAnyOrigin()
.AllowAnyMethod()
.AllowAnyHeader();
});
});
var app = builder.Build();
app.UseCors();
if (app.Environment.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}
app.MapGet("/pokemons", PokemonDbUsecases.GetAllPokemon);
app.MapGet("/trainers", PokemonDbUsecases.GetAllTrainers);
app.MapGet("/trainer/{id}", PokemonDbUsecases.GetTrainerById);
app.MapGet("/trainer/{id}/box", PokemonDbUsecases.GetTrainerBox);
app.MapGet("/trainer/{id}/all", PokemonDbUsecases.GetTrainerAllPokemon);
app.MapGet("/box/{boxId}", BoxDbUsecases.GetBox);
app.MapPut("/box/{boxId}/move", BoxDbUsecases.MovePokemon);
app.Run();