Add entity framework (#11)

Co-authored-by: Maxime Adler <madler@sqli.com>
Reviewed-on: #11
This commit was merged in pull request #11.
This commit is contained in:
2025-04-09 23:12:48 +02:00
parent 3d5056ce91
commit 3537465588
22 changed files with 1617 additions and 38 deletions

View File

@@ -1,7 +1,7 @@
name: Game Ideas build for PR
on:
pull_request:
types: [ opened, edited, closed, reopened, synchronize ]
types: [ opened, edited, reopened, synchronize ]
branches:
- 'feature/**'
- main

2
.gitignore vendored
View File

@@ -437,3 +437,5 @@ FodyWeavers.xsd
.ionide
# End of https://www.toptal.com/developers/gitignore/api/visualstudiocode
.env

View File

@@ -8,7 +8,7 @@ Store your favorite games, intelligent game add, store game files and data, mana
## Services
| project | Port | Technos | Base de données |
| Project | Port | Technos | Base de données |
| ------------- | --------- | --------------- | --------------- |
| WebApp | 5172,7060 | C# (Blazor) | |
| API | 8000 | C# (ASP.NET) | PostgreSQL |
@@ -29,6 +29,15 @@ Store your favorite games, intelligent game add, store game files and data, mana
└── GameIdeas.Shared
```
## Environment variables
| Name | Value type |
| --- | --- |
| DB_HOST | Address IP or hostname of the database |
| DB_USERNAME | Username for the database |
| DB_PASSWORD | Plain password for the database |
| DB_DATABASE | Name of the database |
<!-- ## Installation
### Docker Compose

View File

@@ -29,15 +29,20 @@ builder.Services.AddSingleton<Translations>();
var app = builder.Build();
var client = app.Services.GetService<IHttpClientFactory>()?.CreateClient("GameIdeas.WebAPI") ??
throw new Exception("Http client not found");
var response = await client.GetAsync("api/Translations");
var dictionary = await response.Content.ReadFromJsonAsync<Dictionary<string, string>>();
if (dictionary != null)
{
app.Services.GetService<TranslationService>()!.Initialize(dictionary);
ResourcesKey.Initialize(app.Services.GetService<Translations>()!);
}
await FetchTranslation(app);
await app.RunAsync();
static async Task FetchTranslation(WebAssemblyHost app)
{
var client = app.Services.GetService<IHttpClientFactory>()?.CreateClient("GameIdeas.WebAPI") ??
throw new Exception("Http client not found");
var response = await client.GetAsync("api/Translations");
var dictionary = await response.Content.ReadFromJsonAsync<Dictionary<string, string>>();
if (dictionary != null)
{
app.Services.GetService<TranslationService>()!.Initialize(dictionary);
ResourcesKey.Initialize(app.Services.GetService<Translations>()!);
}
}

View File

@@ -0,0 +1,14 @@
namespace GameIdeas.Shared.Model;
public partial class Developer
{
public Developer()
{
GameDevelopers = new HashSet<GameDeveloper>();
}
public int Id { get; set; }
public string Name { get; set; } = null!;
public virtual ICollection<GameDeveloper> GameDevelopers { get; set; }
}

View File

@@ -0,0 +1,34 @@
namespace GameIdeas.Shared.Model;
public partial class Game
{
public Game()
{
GamePlatforms = new HashSet<GamePlatform>();
GameProperties = new HashSet<GameProperty>();
GameTags = new HashSet<GameTag>();
GamePublishers = new HashSet<GamePublisher>();
GameDevelopers = new HashSet<GameDeveloper>();
}
public int Id { get; set; }
public string Title { get; set; } = null!;
public DateTime? ReleaseDate { get; set; }
public DateTime CreationDate { get; set; }
public int CreationUserId { get; set; }
public DateTime? ModificationDate { get; set; }
public int? ModificationUserId { get; set; }
public double? StorageSpace { get; set; }
public string? Description { get; set; }
public int Interest { get; set; }
public virtual User CreationUser { get; set; } = null!;
public virtual User? ModificationUser { get; set; }
public virtual ICollection<GamePlatform> GamePlatforms { get; set; }
public virtual ICollection<GameProperty> GameProperties { get; set; }
public virtual ICollection<GameTag> GameTags { get; set; }
public virtual ICollection<GamePublisher> GamePublishers { get; set; }
public virtual ICollection<GameDeveloper> GameDevelopers { get; set; }
}

View File

@@ -0,0 +1,10 @@
namespace GameIdeas.Shared.Model;
public partial class GameDeveloper
{
public int GameId { get; set; }
public int DeveloperId { get; set; }
public virtual Game Game { get; set; } = null!;
public virtual Developer Developer { get; set; } = null!;
}

View File

@@ -0,0 +1,11 @@
namespace GameIdeas.Shared.Model;
public partial class GamePlatform
{
public int GameId { get; set; }
public int PlatformId { get; set; }
public string? Url { get; set; }
public virtual Game Game { get; set; } = null!;
public virtual Platform Platform { get; set; } = null!;
}

View File

@@ -0,0 +1,10 @@
namespace GameIdeas.Shared.Model;
public partial class GameProperty
{
public int GameId { get; set; }
public int PropertyId { get; set; }
public virtual Game Game { get; set; } = null!;
public virtual Property Property { get; set; } = null!;
}

View File

@@ -0,0 +1,10 @@
namespace GameIdeas.Shared.Model;
public partial class GamePublisher
{
public int GameId { get; set; }
public int PublisherId { get; set; }
public virtual Game Game { get; set; } = null!;
public virtual Publisher Publisher { get; set; } = null!;
}

View File

@@ -0,0 +1,10 @@
namespace GameIdeas.Shared.Model;
public partial class GameTag
{
public int GameId { get; set; }
public int TagId { get; set; }
public virtual Game Game { get; set; } = null!;
public virtual Tag Tag { get; set; } = null!;
}

View File

@@ -0,0 +1,15 @@
namespace GameIdeas.Shared.Model;
public partial class Platform
{
public Platform()
{
GamePlatforms = new HashSet<GamePlatform>();
}
public int Id { get; set; }
public string Libelle { get; set; } = null!;
public virtual ICollection<GamePlatform> GamePlatforms { get; set; }
}

View File

@@ -0,0 +1,15 @@
namespace GameIdeas.Shared.Model;
public partial class Property
{
public Property()
{
GameProperties = new HashSet<GameProperty>();
}
public int Id { get; set; }
public string Label { get; set; } = null!;
public virtual ICollection<GameProperty> GameProperties { get; set; }
}

View File

@@ -0,0 +1,14 @@
namespace GameIdeas.Shared.Model;
public partial class Publisher
{
public Publisher()
{
GamePublishers = new HashSet<GamePublisher>();
}
public int Id { get; set; }
public string Name { get; set; } = null!;
public virtual ICollection<GamePublisher> GamePublishers { get; set; }
}

View File

@@ -0,0 +1,14 @@
namespace GameIdeas.Shared.Model;
public partial class Tag
{
public Tag()
{
GameTags = new HashSet<GameTag>();
}
public int Id { get; set; }
public string Label { get; set; } = null!;
public virtual ICollection<GameTag> GameTags { get; set; }
}

View File

@@ -0,0 +1,18 @@
namespace GameIdeas.Shared.Model;
public partial class User
{
public User()
{
CreationGames = new HashSet<Game>();
ModificationGames = new HashSet<Game>();
}
public int Id { get; set; }
public string Username { get; set; } = null!;
public string Password { get; set; } = null!;
public int Role { get; set; }
public virtual ICollection<Game> CreationGames { get; set; }
public virtual ICollection<Game> ModificationGames { get; set; }
}

View File

@@ -0,0 +1,158 @@
using GameIdeas.Shared.Model;
using Microsoft.EntityFrameworkCore;
namespace GameIdeas.WebAPI.Context;
public class GameIdeasContext : DbContext
{
public GameIdeasContext(DbContextOptions<GameIdeasContext> option)
: base(option)
{ }
public virtual DbSet<User> Users { get; set; } = null!;
public virtual DbSet<Developer> Developers { get; set; } = null!;
public virtual DbSet<Platform> Platforms { get; set; } = null!;
public virtual DbSet<Property> Properties { get; set; } = null!;
public virtual DbSet<Publisher> Publishers { get; set; } = null!;
public virtual DbSet<Tag> Tags { get; set; } = null!;
public virtual DbSet<Game> Games { get; set; } = null!;
public virtual DbSet<GameDeveloper> GameDevelopers { get; set; } = null!;
public virtual DbSet<GamePlatform> GamePlatforms { get; set; } = null!;
public virtual DbSet<GameProperty> GameProperties { get; set; } = null!;
public virtual DbSet<GamePublisher> GamePublishers { get; set; } = null!;
public virtual DbSet<GameTag> GameTags { get; set; } = null!;
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
modelBuilder.Entity<User>(entity => {
entity.ToTable("User");
entity.Property(e => e.Id)
.UseIdentityByDefaultColumn()
.HasIdentityOptions(startValue: 100000);
});
modelBuilder.Entity<Developer>(entity => entity.ToTable("Developer"));
modelBuilder.Entity<Platform>(entity => entity.ToTable("Platform"));
modelBuilder.Entity<Property>(entity => entity.ToTable("Property"));
modelBuilder.Entity<Publisher>(entity => entity.ToTable("Publisher"));
modelBuilder.Entity<Tag>(entity => entity.ToTable("Tag"));
modelBuilder.Entity<Game>(entity =>
{
entity.ToTable("Game");
entity.HasIndex(e => e.CreationUserId);
entity.HasIndex(e => e.ModificationUserId);
entity.Property(e => e.CreationDate)
.HasDefaultValueSql("now()");
entity.Property(e => e.Id)
.UseIdentityByDefaultColumn()
.HasIdentityOptions(startValue: 100000);
entity.HasOne(d => d.CreationUser)
.WithMany(p => p.CreationGames)
.HasForeignKey(d => d.CreationUserId)
.OnDelete(DeleteBehavior.ClientSetNull);
entity.HasOne(d => d.ModificationUser)
.WithMany(p => p.ModificationGames)
.HasForeignKey(d => d.ModificationUserId)
.OnDelete(DeleteBehavior.ClientSetNull);
});
modelBuilder.Entity<GameDeveloper>(entity =>
{
entity.ToTable("GameDeveloper");
entity.HasKey(e => new { e.GameId, e.DeveloperId });
entity.HasOne(d => d.Game)
.WithMany(p => p.GameDevelopers)
.HasForeignKey(d => d.GameId)
.OnDelete(DeleteBehavior.Cascade);
entity.HasOne(d => d.Developer)
.WithMany(p => p.GameDevelopers)
.HasForeignKey(d => d.DeveloperId)
.OnDelete(DeleteBehavior.Cascade);
});
modelBuilder.Entity<GamePlatform>(entity =>
{
entity.ToTable("GamePlatform");
entity.HasKey(e => new { e.GameId, e.PlatformId });
entity.HasOne(d => d.Game)
.WithMany(p => p.GamePlatforms)
.HasForeignKey(d => d.GameId)
.OnDelete(DeleteBehavior.Cascade);
entity.HasOne(d => d.Platform)
.WithMany(p => p.GamePlatforms)
.HasForeignKey(d => d.PlatformId)
.OnDelete(DeleteBehavior.Cascade);
});
modelBuilder.Entity<GameProperty>(entity =>
{
entity.ToTable("GameProperty");
entity.HasKey(e => new { e.GameId, e.PropertyId });
entity.HasOne(d => d.Game)
.WithMany(p => p.GameProperties)
.HasForeignKey(d => d.GameId)
.OnDelete(DeleteBehavior.Cascade);
entity.HasOne(d => d.Property)
.WithMany(p => p.GameProperties)
.HasForeignKey(d => d.PropertyId)
.OnDelete(DeleteBehavior.Cascade);
});
modelBuilder.Entity<GamePublisher>(entity =>
{
entity.ToTable("GamePublisher");
entity.HasKey(e => new { e.GameId, e.PublisherId });
entity.HasOne(d => d.Game)
.WithMany(p => p.GamePublishers)
.HasForeignKey(d => d.GameId)
.OnDelete(DeleteBehavior.Cascade);
entity.HasOne(d => d.Publisher)
.WithMany(p => p.GamePublishers)
.HasForeignKey(d => d.PublisherId)
.OnDelete(DeleteBehavior.Cascade);
});
modelBuilder.Entity<GameTag>(entity =>
{
entity.ToTable("GameTag");
entity.HasKey(e => new { e.GameId, e.TagId });
entity.HasOne(d => d.Game)
.WithMany(p => p.GameTags)
.HasForeignKey(d => d.GameId)
.OnDelete(DeleteBehavior.Cascade);
entity.HasOne(d => d.Tag)
.WithMany(p => p.GameTags)
.HasForeignKey(d => d.TagId)
.OnDelete(DeleteBehavior.Cascade);
});
base.OnModelCreating(modelBuilder);
}
}

View File

@@ -1,4 +1,4 @@
<Project Sdk="Microsoft.NET.Sdk.Web">
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>net9.0</TargetFramework>
@@ -12,10 +12,17 @@
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.OpenApi" Version="9.0.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="9.0.4" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="9.0.4">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="9.0.4" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\GameIdeas.Resources\GameIdeas.Resources.csproj" />
<ProjectReference Include="..\..\GameIdeas.Shared\GameIdeas.Shared.csproj" />
</ItemGroup>
</Project>

View File

@@ -0,0 +1,422 @@
// <auto-generated />
using System;
using GameIdeas.WebAPI.Context;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Migrations;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
#nullable disable
namespace GameIdeas.WebAPI.Migrations
{
[DbContext(typeof(GameIdeasContext))]
[Migration("20250409210640_InitialCreate")]
partial class InitialCreate
{
/// <inheritdoc />
protected override void BuildTargetModel(ModelBuilder modelBuilder)
{
#pragma warning disable 612, 618
modelBuilder
.HasAnnotation("ProductVersion", "9.0.4")
.HasAnnotation("Relational:MaxIdentifierLength", 63);
NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder);
modelBuilder.Entity("GameIdeas.Shared.Model.Developer", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("integer");
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
b.Property<string>("Name")
.IsRequired()
.HasColumnType("text");
b.HasKey("Id");
b.ToTable("Developer", (string)null);
});
modelBuilder.Entity("GameIdeas.Shared.Model.Game", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("integer");
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
NpgsqlPropertyBuilderExtensions.HasIdentityOptions(b.Property<int>("Id"), 100000L, null, null, null, null, null);
b.Property<DateTime>("CreationDate")
.ValueGeneratedOnAdd()
.HasColumnType("timestamp with time zone")
.HasDefaultValueSql("now()");
b.Property<int>("CreationUserId")
.HasColumnType("integer");
b.Property<string>("Description")
.HasColumnType("text");
b.Property<int>("Interest")
.HasColumnType("integer");
b.Property<DateTime?>("ModificationDate")
.HasColumnType("timestamp with time zone");
b.Property<int?>("ModificationUserId")
.HasColumnType("integer");
b.Property<DateTime?>("ReleaseDate")
.HasColumnType("timestamp with time zone");
b.Property<double?>("StorageSpace")
.HasColumnType("double precision");
b.Property<string>("Title")
.IsRequired()
.HasColumnType("text");
b.HasKey("Id");
b.HasIndex("CreationUserId");
b.HasIndex("ModificationUserId");
b.ToTable("Game", (string)null);
});
modelBuilder.Entity("GameIdeas.Shared.Model.GameDeveloper", b =>
{
b.Property<int>("GameId")
.HasColumnType("integer");
b.Property<int>("DeveloperId")
.HasColumnType("integer");
b.HasKey("GameId", "DeveloperId");
b.HasIndex("DeveloperId");
b.ToTable("GameDeveloper", (string)null);
});
modelBuilder.Entity("GameIdeas.Shared.Model.GamePlatform", b =>
{
b.Property<int>("GameId")
.HasColumnType("integer");
b.Property<int>("PlatformId")
.HasColumnType("integer");
b.Property<string>("Url")
.HasColumnType("text");
b.HasKey("GameId", "PlatformId");
b.HasIndex("PlatformId");
b.ToTable("GamePlatform", (string)null);
});
modelBuilder.Entity("GameIdeas.Shared.Model.GameProperty", b =>
{
b.Property<int>("GameId")
.HasColumnType("integer");
b.Property<int>("PropertyId")
.HasColumnType("integer");
b.HasKey("GameId", "PropertyId");
b.HasIndex("PropertyId");
b.ToTable("GameProperty", (string)null);
});
modelBuilder.Entity("GameIdeas.Shared.Model.GamePublisher", b =>
{
b.Property<int>("GameId")
.HasColumnType("integer");
b.Property<int>("PublisherId")
.HasColumnType("integer");
b.HasKey("GameId", "PublisherId");
b.HasIndex("PublisherId");
b.ToTable("GamePublisher", (string)null);
});
modelBuilder.Entity("GameIdeas.Shared.Model.GameTag", b =>
{
b.Property<int>("GameId")
.HasColumnType("integer");
b.Property<int>("TagId")
.HasColumnType("integer");
b.HasKey("GameId", "TagId");
b.HasIndex("TagId");
b.ToTable("GameTag", (string)null);
});
modelBuilder.Entity("GameIdeas.Shared.Model.Platform", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("integer");
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
b.Property<string>("Libelle")
.IsRequired()
.HasColumnType("text");
b.HasKey("Id");
b.ToTable("Platform", (string)null);
});
modelBuilder.Entity("GameIdeas.Shared.Model.Property", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("integer");
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
b.Property<string>("Label")
.IsRequired()
.HasColumnType("text");
b.HasKey("Id");
b.ToTable("Property", (string)null);
});
modelBuilder.Entity("GameIdeas.Shared.Model.Publisher", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("integer");
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
b.Property<string>("Name")
.IsRequired()
.HasColumnType("text");
b.HasKey("Id");
b.ToTable("Publisher", (string)null);
});
modelBuilder.Entity("GameIdeas.Shared.Model.Tag", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("integer");
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
b.Property<string>("Label")
.IsRequired()
.HasColumnType("text");
b.HasKey("Id");
b.ToTable("Tag", (string)null);
});
modelBuilder.Entity("GameIdeas.Shared.Model.User", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("integer");
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
NpgsqlPropertyBuilderExtensions.HasIdentityOptions(b.Property<int>("Id"), 100000L, null, null, null, null, null);
b.Property<string>("Password")
.IsRequired()
.HasColumnType("text");
b.Property<int>("Role")
.HasColumnType("integer");
b.Property<string>("Username")
.IsRequired()
.HasColumnType("text");
b.HasKey("Id");
b.ToTable("User", (string)null);
});
modelBuilder.Entity("GameIdeas.Shared.Model.Game", b =>
{
b.HasOne("GameIdeas.Shared.Model.User", "CreationUser")
.WithMany("CreationGames")
.HasForeignKey("CreationUserId")
.IsRequired();
b.HasOne("GameIdeas.Shared.Model.User", "ModificationUser")
.WithMany("ModificationGames")
.HasForeignKey("ModificationUserId");
b.Navigation("CreationUser");
b.Navigation("ModificationUser");
});
modelBuilder.Entity("GameIdeas.Shared.Model.GameDeveloper", b =>
{
b.HasOne("GameIdeas.Shared.Model.Developer", "Developer")
.WithMany("GameDevelopers")
.HasForeignKey("DeveloperId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("GameIdeas.Shared.Model.Game", "Game")
.WithMany("GameDevelopers")
.HasForeignKey("GameId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Developer");
b.Navigation("Game");
});
modelBuilder.Entity("GameIdeas.Shared.Model.GamePlatform", b =>
{
b.HasOne("GameIdeas.Shared.Model.Game", "Game")
.WithMany("GamePlatforms")
.HasForeignKey("GameId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("GameIdeas.Shared.Model.Platform", "Platform")
.WithMany("GamePlatforms")
.HasForeignKey("PlatformId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Game");
b.Navigation("Platform");
});
modelBuilder.Entity("GameIdeas.Shared.Model.GameProperty", b =>
{
b.HasOne("GameIdeas.Shared.Model.Game", "Game")
.WithMany("GameProperties")
.HasForeignKey("GameId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("GameIdeas.Shared.Model.Property", "Property")
.WithMany("GameProperties")
.HasForeignKey("PropertyId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Game");
b.Navigation("Property");
});
modelBuilder.Entity("GameIdeas.Shared.Model.GamePublisher", b =>
{
b.HasOne("GameIdeas.Shared.Model.Game", "Game")
.WithMany("GamePublishers")
.HasForeignKey("GameId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("GameIdeas.Shared.Model.Publisher", "Publisher")
.WithMany("GamePublishers")
.HasForeignKey("PublisherId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Game");
b.Navigation("Publisher");
});
modelBuilder.Entity("GameIdeas.Shared.Model.GameTag", b =>
{
b.HasOne("GameIdeas.Shared.Model.Game", "Game")
.WithMany("GameTags")
.HasForeignKey("GameId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("GameIdeas.Shared.Model.Tag", "Tag")
.WithMany("GameTags")
.HasForeignKey("TagId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Game");
b.Navigation("Tag");
});
modelBuilder.Entity("GameIdeas.Shared.Model.Developer", b =>
{
b.Navigation("GameDevelopers");
});
modelBuilder.Entity("GameIdeas.Shared.Model.Game", b =>
{
b.Navigation("GameDevelopers");
b.Navigation("GamePlatforms");
b.Navigation("GameProperties");
b.Navigation("GamePublishers");
b.Navigation("GameTags");
});
modelBuilder.Entity("GameIdeas.Shared.Model.Platform", b =>
{
b.Navigation("GamePlatforms");
});
modelBuilder.Entity("GameIdeas.Shared.Model.Property", b =>
{
b.Navigation("GameProperties");
});
modelBuilder.Entity("GameIdeas.Shared.Model.Publisher", b =>
{
b.Navigation("GamePublishers");
});
modelBuilder.Entity("GameIdeas.Shared.Model.Tag", b =>
{
b.Navigation("GameTags");
});
modelBuilder.Entity("GameIdeas.Shared.Model.User", b =>
{
b.Navigation("CreationGames");
b.Navigation("ModificationGames");
});
#pragma warning restore 612, 618
}
}
}

View File

@@ -0,0 +1,325 @@
using System;
using Microsoft.EntityFrameworkCore.Migrations;
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
#nullable disable
namespace GameIdeas.WebAPI.Migrations
{
/// <inheritdoc />
public partial class InitialCreate : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.CreateTable(
name: "Developer",
columns: table => new
{
Id = table.Column<int>(type: "integer", nullable: false)
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
Name = table.Column<string>(type: "text", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_Developer", x => x.Id);
});
migrationBuilder.CreateTable(
name: "Platform",
columns: table => new
{
Id = table.Column<int>(type: "integer", nullable: false)
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
Libelle = table.Column<string>(type: "text", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_Platform", x => x.Id);
});
migrationBuilder.CreateTable(
name: "Property",
columns: table => new
{
Id = table.Column<int>(type: "integer", nullable: false)
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
Label = table.Column<string>(type: "text", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_Property", x => x.Id);
});
migrationBuilder.CreateTable(
name: "Publisher",
columns: table => new
{
Id = table.Column<int>(type: "integer", nullable: false)
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
Name = table.Column<string>(type: "text", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_Publisher", x => x.Id);
});
migrationBuilder.CreateTable(
name: "Tag",
columns: table => new
{
Id = table.Column<int>(type: "integer", nullable: false)
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
Label = table.Column<string>(type: "text", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_Tag", x => x.Id);
});
migrationBuilder.CreateTable(
name: "User",
columns: table => new
{
Id = table.Column<int>(type: "integer", nullable: false)
.Annotation("Npgsql:IdentitySequenceOptions", "'100000', '1', '', '', 'False', '1'")
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
Username = table.Column<string>(type: "text", nullable: false),
Password = table.Column<string>(type: "text", nullable: false),
Role = table.Column<int>(type: "integer", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_User", x => x.Id);
});
migrationBuilder.CreateTable(
name: "Game",
columns: table => new
{
Id = table.Column<int>(type: "integer", nullable: false)
.Annotation("Npgsql:IdentitySequenceOptions", "'100000', '1', '', '', 'False', '1'")
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
Title = table.Column<string>(type: "text", nullable: false),
ReleaseDate = table.Column<DateTime>(type: "timestamp with time zone", nullable: true),
CreationDate = table.Column<DateTime>(type: "timestamp with time zone", nullable: false, defaultValueSql: "now()"),
CreationUserId = table.Column<int>(type: "integer", nullable: false),
ModificationDate = table.Column<DateTime>(type: "timestamp with time zone", nullable: true),
ModificationUserId = table.Column<int>(type: "integer", nullable: true),
StorageSpace = table.Column<double>(type: "double precision", nullable: true),
Description = table.Column<string>(type: "text", nullable: true),
Interest = table.Column<int>(type: "integer", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_Game", x => x.Id);
table.ForeignKey(
name: "FK_Game_User_CreationUserId",
column: x => x.CreationUserId,
principalTable: "User",
principalColumn: "Id");
table.ForeignKey(
name: "FK_Game_User_ModificationUserId",
column: x => x.ModificationUserId,
principalTable: "User",
principalColumn: "Id");
});
migrationBuilder.CreateTable(
name: "GameDeveloper",
columns: table => new
{
GameId = table.Column<int>(type: "integer", nullable: false),
DeveloperId = table.Column<int>(type: "integer", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_GameDeveloper", x => new { x.GameId, x.DeveloperId });
table.ForeignKey(
name: "FK_GameDeveloper_Developer_DeveloperId",
column: x => x.DeveloperId,
principalTable: "Developer",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
table.ForeignKey(
name: "FK_GameDeveloper_Game_GameId",
column: x => x.GameId,
principalTable: "Game",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateTable(
name: "GamePlatform",
columns: table => new
{
GameId = table.Column<int>(type: "integer", nullable: false),
PlatformId = table.Column<int>(type: "integer", nullable: false),
Url = table.Column<string>(type: "text", nullable: true)
},
constraints: table =>
{
table.PrimaryKey("PK_GamePlatform", x => new { x.GameId, x.PlatformId });
table.ForeignKey(
name: "FK_GamePlatform_Game_GameId",
column: x => x.GameId,
principalTable: "Game",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
table.ForeignKey(
name: "FK_GamePlatform_Platform_PlatformId",
column: x => x.PlatformId,
principalTable: "Platform",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateTable(
name: "GameProperty",
columns: table => new
{
GameId = table.Column<int>(type: "integer", nullable: false),
PropertyId = table.Column<int>(type: "integer", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_GameProperty", x => new { x.GameId, x.PropertyId });
table.ForeignKey(
name: "FK_GameProperty_Game_GameId",
column: x => x.GameId,
principalTable: "Game",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
table.ForeignKey(
name: "FK_GameProperty_Property_PropertyId",
column: x => x.PropertyId,
principalTable: "Property",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateTable(
name: "GamePublisher",
columns: table => new
{
GameId = table.Column<int>(type: "integer", nullable: false),
PublisherId = table.Column<int>(type: "integer", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_GamePublisher", x => new { x.GameId, x.PublisherId });
table.ForeignKey(
name: "FK_GamePublisher_Game_GameId",
column: x => x.GameId,
principalTable: "Game",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
table.ForeignKey(
name: "FK_GamePublisher_Publisher_PublisherId",
column: x => x.PublisherId,
principalTable: "Publisher",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateTable(
name: "GameTag",
columns: table => new
{
GameId = table.Column<int>(type: "integer", nullable: false),
TagId = table.Column<int>(type: "integer", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_GameTag", x => new { x.GameId, x.TagId });
table.ForeignKey(
name: "FK_GameTag_Game_GameId",
column: x => x.GameId,
principalTable: "Game",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
table.ForeignKey(
name: "FK_GameTag_Tag_TagId",
column: x => x.TagId,
principalTable: "Tag",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateIndex(
name: "IX_Game_CreationUserId",
table: "Game",
column: "CreationUserId");
migrationBuilder.CreateIndex(
name: "IX_Game_ModificationUserId",
table: "Game",
column: "ModificationUserId");
migrationBuilder.CreateIndex(
name: "IX_GameDeveloper_DeveloperId",
table: "GameDeveloper",
column: "DeveloperId");
migrationBuilder.CreateIndex(
name: "IX_GamePlatform_PlatformId",
table: "GamePlatform",
column: "PlatformId");
migrationBuilder.CreateIndex(
name: "IX_GameProperty_PropertyId",
table: "GameProperty",
column: "PropertyId");
migrationBuilder.CreateIndex(
name: "IX_GamePublisher_PublisherId",
table: "GamePublisher",
column: "PublisherId");
migrationBuilder.CreateIndex(
name: "IX_GameTag_TagId",
table: "GameTag",
column: "TagId");
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropTable(
name: "GameDeveloper");
migrationBuilder.DropTable(
name: "GamePlatform");
migrationBuilder.DropTable(
name: "GameProperty");
migrationBuilder.DropTable(
name: "GamePublisher");
migrationBuilder.DropTable(
name: "GameTag");
migrationBuilder.DropTable(
name: "Developer");
migrationBuilder.DropTable(
name: "Platform");
migrationBuilder.DropTable(
name: "Property");
migrationBuilder.DropTable(
name: "Publisher");
migrationBuilder.DropTable(
name: "Game");
migrationBuilder.DropTable(
name: "Tag");
migrationBuilder.DropTable(
name: "User");
}
}
}

View File

@@ -0,0 +1,419 @@
// <auto-generated />
using System;
using GameIdeas.WebAPI.Context;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
#nullable disable
namespace GameIdeas.WebAPI.Migrations
{
[DbContext(typeof(GameIdeasContext))]
partial class GameIdeasContextModelSnapshot : ModelSnapshot
{
protected override void BuildModel(ModelBuilder modelBuilder)
{
#pragma warning disable 612, 618
modelBuilder
.HasAnnotation("ProductVersion", "9.0.4")
.HasAnnotation("Relational:MaxIdentifierLength", 63);
NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder);
modelBuilder.Entity("GameIdeas.Shared.Model.Developer", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("integer");
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
b.Property<string>("Name")
.IsRequired()
.HasColumnType("text");
b.HasKey("Id");
b.ToTable("Developer", (string)null);
});
modelBuilder.Entity("GameIdeas.Shared.Model.Game", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("integer");
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
NpgsqlPropertyBuilderExtensions.HasIdentityOptions(b.Property<int>("Id"), 100000L, null, null, null, null, null);
b.Property<DateTime>("CreationDate")
.ValueGeneratedOnAdd()
.HasColumnType("timestamp with time zone")
.HasDefaultValueSql("now()");
b.Property<int>("CreationUserId")
.HasColumnType("integer");
b.Property<string>("Description")
.HasColumnType("text");
b.Property<int>("Interest")
.HasColumnType("integer");
b.Property<DateTime?>("ModificationDate")
.HasColumnType("timestamp with time zone");
b.Property<int?>("ModificationUserId")
.HasColumnType("integer");
b.Property<DateTime?>("ReleaseDate")
.HasColumnType("timestamp with time zone");
b.Property<double?>("StorageSpace")
.HasColumnType("double precision");
b.Property<string>("Title")
.IsRequired()
.HasColumnType("text");
b.HasKey("Id");
b.HasIndex("CreationUserId");
b.HasIndex("ModificationUserId");
b.ToTable("Game", (string)null);
});
modelBuilder.Entity("GameIdeas.Shared.Model.GameDeveloper", b =>
{
b.Property<int>("GameId")
.HasColumnType("integer");
b.Property<int>("DeveloperId")
.HasColumnType("integer");
b.HasKey("GameId", "DeveloperId");
b.HasIndex("DeveloperId");
b.ToTable("GameDeveloper", (string)null);
});
modelBuilder.Entity("GameIdeas.Shared.Model.GamePlatform", b =>
{
b.Property<int>("GameId")
.HasColumnType("integer");
b.Property<int>("PlatformId")
.HasColumnType("integer");
b.Property<string>("Url")
.HasColumnType("text");
b.HasKey("GameId", "PlatformId");
b.HasIndex("PlatformId");
b.ToTable("GamePlatform", (string)null);
});
modelBuilder.Entity("GameIdeas.Shared.Model.GameProperty", b =>
{
b.Property<int>("GameId")
.HasColumnType("integer");
b.Property<int>("PropertyId")
.HasColumnType("integer");
b.HasKey("GameId", "PropertyId");
b.HasIndex("PropertyId");
b.ToTable("GameProperty", (string)null);
});
modelBuilder.Entity("GameIdeas.Shared.Model.GamePublisher", b =>
{
b.Property<int>("GameId")
.HasColumnType("integer");
b.Property<int>("PublisherId")
.HasColumnType("integer");
b.HasKey("GameId", "PublisherId");
b.HasIndex("PublisherId");
b.ToTable("GamePublisher", (string)null);
});
modelBuilder.Entity("GameIdeas.Shared.Model.GameTag", b =>
{
b.Property<int>("GameId")
.HasColumnType("integer");
b.Property<int>("TagId")
.HasColumnType("integer");
b.HasKey("GameId", "TagId");
b.HasIndex("TagId");
b.ToTable("GameTag", (string)null);
});
modelBuilder.Entity("GameIdeas.Shared.Model.Platform", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("integer");
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
b.Property<string>("Libelle")
.IsRequired()
.HasColumnType("text");
b.HasKey("Id");
b.ToTable("Platform", (string)null);
});
modelBuilder.Entity("GameIdeas.Shared.Model.Property", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("integer");
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
b.Property<string>("Label")
.IsRequired()
.HasColumnType("text");
b.HasKey("Id");
b.ToTable("Property", (string)null);
});
modelBuilder.Entity("GameIdeas.Shared.Model.Publisher", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("integer");
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
b.Property<string>("Name")
.IsRequired()
.HasColumnType("text");
b.HasKey("Id");
b.ToTable("Publisher", (string)null);
});
modelBuilder.Entity("GameIdeas.Shared.Model.Tag", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("integer");
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
b.Property<string>("Label")
.IsRequired()
.HasColumnType("text");
b.HasKey("Id");
b.ToTable("Tag", (string)null);
});
modelBuilder.Entity("GameIdeas.Shared.Model.User", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("integer");
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
NpgsqlPropertyBuilderExtensions.HasIdentityOptions(b.Property<int>("Id"), 100000L, null, null, null, null, null);
b.Property<string>("Password")
.IsRequired()
.HasColumnType("text");
b.Property<int>("Role")
.HasColumnType("integer");
b.Property<string>("Username")
.IsRequired()
.HasColumnType("text");
b.HasKey("Id");
b.ToTable("User", (string)null);
});
modelBuilder.Entity("GameIdeas.Shared.Model.Game", b =>
{
b.HasOne("GameIdeas.Shared.Model.User", "CreationUser")
.WithMany("CreationGames")
.HasForeignKey("CreationUserId")
.IsRequired();
b.HasOne("GameIdeas.Shared.Model.User", "ModificationUser")
.WithMany("ModificationGames")
.HasForeignKey("ModificationUserId");
b.Navigation("CreationUser");
b.Navigation("ModificationUser");
});
modelBuilder.Entity("GameIdeas.Shared.Model.GameDeveloper", b =>
{
b.HasOne("GameIdeas.Shared.Model.Developer", "Developer")
.WithMany("GameDevelopers")
.HasForeignKey("DeveloperId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("GameIdeas.Shared.Model.Game", "Game")
.WithMany("GameDevelopers")
.HasForeignKey("GameId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Developer");
b.Navigation("Game");
});
modelBuilder.Entity("GameIdeas.Shared.Model.GamePlatform", b =>
{
b.HasOne("GameIdeas.Shared.Model.Game", "Game")
.WithMany("GamePlatforms")
.HasForeignKey("GameId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("GameIdeas.Shared.Model.Platform", "Platform")
.WithMany("GamePlatforms")
.HasForeignKey("PlatformId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Game");
b.Navigation("Platform");
});
modelBuilder.Entity("GameIdeas.Shared.Model.GameProperty", b =>
{
b.HasOne("GameIdeas.Shared.Model.Game", "Game")
.WithMany("GameProperties")
.HasForeignKey("GameId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("GameIdeas.Shared.Model.Property", "Property")
.WithMany("GameProperties")
.HasForeignKey("PropertyId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Game");
b.Navigation("Property");
});
modelBuilder.Entity("GameIdeas.Shared.Model.GamePublisher", b =>
{
b.HasOne("GameIdeas.Shared.Model.Game", "Game")
.WithMany("GamePublishers")
.HasForeignKey("GameId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("GameIdeas.Shared.Model.Publisher", "Publisher")
.WithMany("GamePublishers")
.HasForeignKey("PublisherId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Game");
b.Navigation("Publisher");
});
modelBuilder.Entity("GameIdeas.Shared.Model.GameTag", b =>
{
b.HasOne("GameIdeas.Shared.Model.Game", "Game")
.WithMany("GameTags")
.HasForeignKey("GameId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("GameIdeas.Shared.Model.Tag", "Tag")
.WithMany("GameTags")
.HasForeignKey("TagId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Game");
b.Navigation("Tag");
});
modelBuilder.Entity("GameIdeas.Shared.Model.Developer", b =>
{
b.Navigation("GameDevelopers");
});
modelBuilder.Entity("GameIdeas.Shared.Model.Game", b =>
{
b.Navigation("GameDevelopers");
b.Navigation("GamePlatforms");
b.Navigation("GameProperties");
b.Navigation("GamePublishers");
b.Navigation("GameTags");
});
modelBuilder.Entity("GameIdeas.Shared.Model.Platform", b =>
{
b.Navigation("GamePlatforms");
});
modelBuilder.Entity("GameIdeas.Shared.Model.Property", b =>
{
b.Navigation("GameProperties");
});
modelBuilder.Entity("GameIdeas.Shared.Model.Publisher", b =>
{
b.Navigation("GamePublishers");
});
modelBuilder.Entity("GameIdeas.Shared.Model.Tag", b =>
{
b.Navigation("GameTags");
});
modelBuilder.Entity("GameIdeas.Shared.Model.User", b =>
{
b.Navigation("CreationGames");
b.Navigation("ModificationGames");
});
#pragma warning restore 612, 618
}
}
}

View File

@@ -1,47 +1,104 @@
using GameIdeas.Resources;
using System.Resources;
using GameIdeas.WebAPI.Context;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.DependencyInjection;
using System.Data;
using System.Data.Common;
var builder = WebApplication.CreateBuilder(args);
var services = builder.Services;
#if DEBUG
Load("../../../../.env");
#else
Load(".env");
#endif
Action<DbContextOptionsBuilder> dbContextOptions = options =>
{
options.UseNpgsql(
GetConnectionString(),
npgOption =>
{
npgOption.CommandTimeout(60);
npgOption.MigrationsAssembly("GameIdeas.WebAPI");
})
.LogTo(Console.WriteLine);
};
// Add services to the container.
services.AddDbContext<GameIdeasContext>(dbContextOptions);
builder.Services.AddControllers();
services.AddSingleton<TranslationService>();
services.AddSingleton<Translations>();
services.AddControllers();
// Learn more about configuring OpenAPI at https://aka.ms/aspnet/openapi
builder.Services.AddOpenApi();
services.AddOpenApi();
builder.Services.AddCors(option => option.AddDefaultPolicy(policy =>
policy.WithOrigins("http://localhost:5172")
services.AddCors(option => option.AddDefaultPolicy(policy =>
policy.WithOrigins("http://localhost:5172", "http://localhost:7060")
.AllowAnyHeader()
.WithMethods("GET", "POST")));
builder.Services.AddSingleton<TranslationService>();
builder.Services.AddSingleton<Translations>();
.WithMethods("GET", "POST", "PUT", "DELETE")));
var app = builder.Build();
await LoadTranslations();
// Configure the HTTP request pipeline.
if (app.Environment.IsDevelopment())
{
app.MapOpenApi();
}
var filesDirectory = Path.Combine(Directory.GetCurrentDirectory(), "Files");
var translationFiles = Directory.GetFiles(filesDirectory, "*.json");
var dictionary = new Dictionary<string, string>();
foreach (var file in translationFiles)
{
var name = file.Split('.');
var culture = name[^2];
var content = await File.ReadAllTextAsync(file);
dictionary.Add(culture, content);
}
app.Services.GetRequiredService<TranslationService>().Initialize(dictionary);
ResourcesKey.Initialize(app.Services.GetRequiredService<Translations>());
app.UseCors();
app.UseAuthorization();
app.MapControllers();
app.Run();
async Task LoadTranslations()
{
var filesDirectory = Path.Combine(Directory.GetCurrentDirectory(), "Files");
var translationFiles = Directory.GetFiles(filesDirectory, "*.json");
var dictionary = new Dictionary<string, string>();
foreach (var file in translationFiles)
{
var name = file.Split('.');
var culture = name[^2];
var content = await File.ReadAllTextAsync(file);
dictionary.Add(culture, content);
}
app.Services.GetRequiredService<TranslationService>().Initialize(dictionary);
ResourcesKey.Initialize(app.Services.GetRequiredService<Translations>());
}
string GetConnectionString()
{
var host = Environment.GetEnvironmentVariable("DB_HOST");
var login = Environment.GetEnvironmentVariable("DB_USERNAME");
var pass = Environment.GetEnvironmentVariable("DB_PASSWORD");
var database = Environment.GetEnvironmentVariable("DB_DATABASE");
return $"Host={host};Username={login};Password={pass};Database={database}";
}
static void Load(string filePath)
{
if (!File.Exists(filePath))
return;
foreach (var line in File.ReadAllLines(filePath))
{
var parts = line.Split(
'=',
StringSplitOptions.RemoveEmptyEntries);
if (parts.Length != 2)
continue;
Environment.SetEnvironmentVariable(parts[0], parts[1]);
}
}