From 64fa663501f03eb085af7810c0f34dda1f6d97f7 Mon Sep 17 00:00:00 2001 From: BuzzLeclair Date: Sat, 1 Mar 2025 12:45:48 +0100 Subject: [PATCH 1/2] =?UTF-8?q?Ajout=20des=20entit=C3=A9s=20du=20PgContext?= =?UTF-8?q?=20directemen=20g=C3=A9n=C3=A9r=C3=A9=20via=20EfCore?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .idea/.idea.ldap-cesi/.idea/dataSources.xml | 18 +++ ldap-cesi/Configurations/Conf.cs | 19 +++ ldap-cesi/Context/PgContext.cs | 135 ++++++++++++++++++++ ldap-cesi/Entities/Role.cs | 13 ++ ldap-cesi/Entities/Salarie.cs | 27 ++++ ldap-cesi/Entities/Service.cs | 13 ++ ldap-cesi/Entities/Site.cs | 13 ++ ldap-cesi/Entities/Utilisateur.cs | 19 +++ ldap-cesi/Program.cs | 29 +---- ldap-cesi/ldap-cesi.csproj | 17 +++ 10 files changed, 277 insertions(+), 26 deletions(-) create mode 100644 .idea/.idea.ldap-cesi/.idea/dataSources.xml create mode 100644 ldap-cesi/Configurations/Conf.cs create mode 100644 ldap-cesi/Context/PgContext.cs create mode 100644 ldap-cesi/Entities/Role.cs create mode 100644 ldap-cesi/Entities/Salarie.cs create mode 100644 ldap-cesi/Entities/Service.cs create mode 100644 ldap-cesi/Entities/Site.cs create mode 100644 ldap-cesi/Entities/Utilisateur.cs diff --git a/.idea/.idea.ldap-cesi/.idea/dataSources.xml b/.idea/.idea.ldap-cesi/.idea/dataSources.xml new file mode 100644 index 0000000..62b6f3e --- /dev/null +++ b/.idea/.idea.ldap-cesi/.idea/dataSources.xml @@ -0,0 +1,18 @@ + + + + + postgresql + true + org.postgresql.Driver + jdbc:postgresql://192.168.1.196:5432/ldap + + + + + + + $ProjectFileDir$ + + + \ No newline at end of file diff --git a/ldap-cesi/Configurations/Conf.cs b/ldap-cesi/Configurations/Conf.cs new file mode 100644 index 0000000..d1dbb77 --- /dev/null +++ b/ldap-cesi/Configurations/Conf.cs @@ -0,0 +1,19 @@ +using ldap_cesi.Context; +using ldap_cesi.Entities; +using Microsoft.EntityFrameworkCore; + +namespace ldap_cesi.Configurations; + +public static class Conf +{ + public static void BuildConf(this WebApplicationBuilder builder) + { + builder.AddEFCoreConfiguration(); + } + + public static void AddEFCoreConfiguration(this WebApplicationBuilder builder) + { + string connectionString = builder.Configuration.GetConnectionString("DefaultConnection"); + builder.Services.AddDbContext(options => options.UseNpgsql(connectionString)); + } +} \ No newline at end of file diff --git a/ldap-cesi/Context/PgContext.cs b/ldap-cesi/Context/PgContext.cs new file mode 100644 index 0000000..778e575 --- /dev/null +++ b/ldap-cesi/Context/PgContext.cs @@ -0,0 +1,135 @@ +using System; +using System.Collections.Generic; +using ldap_cesi.Entities; +using Microsoft.EntityFrameworkCore; + +namespace ldap_cesi.Context; + +public partial class PgContext : DbContext +{ + public PgContext() + { + } + + public PgContext(DbContextOptions options) + : base(options) + { + } + + public virtual DbSet Roles { get; set; } + + public virtual DbSet Salaries { get; set; } + + public virtual DbSet Services { get; set; } + + public virtual DbSet Sites { get; set; } + + public virtual DbSet Utilisateurs { get; set; } + + protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) +#warning To protect potentially sensitive information in your connection string, you should move it out of source code. You can avoid scaffolding the connection string by using the Name= syntax to read it from configuration - see https://go.microsoft.com/fwlink/?linkid=2131148. For more guidance on storing connection strings, see https://go.microsoft.com/fwlink/?LinkId=723263. + => optionsBuilder.UseNpgsql("Host=192.168.1.196;Database=ldap;Username=postgres;Password=pimer0-buzz"); + + protected override void OnModelCreating(ModelBuilder modelBuilder) + { + modelBuilder.Entity(entity => + { + entity.HasKey(e => e.Id).HasName("role_pk"); + + entity.ToTable("role"); + + entity.Property(e => e.Id).HasColumnName("id"); + entity.Property(e => e.Nom) + .HasMaxLength(50) + .HasColumnName("nom"); + }); + + modelBuilder.Entity(entity => + { + entity.HasKey(e => e.Id).HasName("salarie_pk"); + + entity.ToTable("salarie"); + + entity.Property(e => e.Id).HasColumnName("id"); + entity.Property(e => e.Email) + .HasMaxLength(50) + .HasColumnName("email"); + entity.Property(e => e.IdService).HasColumnName("id_service"); + entity.Property(e => e.IdSite).HasColumnName("id_site"); + entity.Property(e => e.Nom) + .HasMaxLength(50) + .HasColumnName("nom"); + entity.Property(e => e.Prenom) + .HasMaxLength(50) + .HasColumnName("prenom"); + entity.Property(e => e.TelephoneFixe) + .HasMaxLength(50) + .HasColumnName("telephone_fixe"); + entity.Property(e => e.TelephonePortable) + .HasMaxLength(50) + .HasColumnName("telephone_portable"); + + entity.HasOne(d => d.IdServiceNavigation).WithMany(p => p.Salaries) + .HasForeignKey(d => d.IdService) + .OnDelete(DeleteBehavior.ClientSetNull) + .HasConstraintName("salarie_service0_fk"); + + entity.HasOne(d => d.IdSiteNavigation).WithMany(p => p.Salaries) + .HasForeignKey(d => d.IdSite) + .OnDelete(DeleteBehavior.ClientSetNull) + .HasConstraintName("salarie_site_fk"); + }); + + modelBuilder.Entity(entity => + { + entity.HasKey(e => e.Id).HasName("service_pk"); + + entity.ToTable("service"); + + entity.Property(e => e.Id).HasColumnName("id"); + entity.Property(e => e.Nom) + .HasMaxLength(50) + .HasColumnName("nom"); + }); + + modelBuilder.Entity(entity => + { + entity.HasKey(e => e.Id).HasName("site_pk"); + + entity.ToTable("site"); + + entity.Property(e => e.Id).HasColumnName("id"); + entity.Property(e => e.Ville) + .HasMaxLength(150) + .HasColumnName("ville"); + }); + + modelBuilder.Entity(entity => + { + entity.HasKey(e => e.Id).HasName("utilisateur_pk"); + + entity.ToTable("utilisateur"); + + entity.Property(e => e.Id).HasColumnName("id"); + entity.Property(e => e.IdRole).HasColumnName("id_role"); + entity.Property(e => e.MotDePasse) + .HasMaxLength(50) + .HasColumnName("mot_de_passe"); + entity.Property(e => e.Nom) + .HasMaxLength(50) + .HasColumnName("nom"); + entity.Property(e => e.Prenom) + .HasMaxLength(50) + .HasColumnName("prenom"); + + entity.HasOne(d => d.IdRoleNavigation).WithMany(p => p.Utilisateurs) + .HasForeignKey(d => d.IdRole) + .OnDelete(DeleteBehavior.ClientSetNull) + .HasConstraintName("utilisateur_role_fk"); + }); + + OnModelCreatingPartial(modelBuilder); + } + + partial void OnModelCreatingPartial(ModelBuilder modelBuilder); +} diff --git a/ldap-cesi/Entities/Role.cs b/ldap-cesi/Entities/Role.cs new file mode 100644 index 0000000..bd74754 --- /dev/null +++ b/ldap-cesi/Entities/Role.cs @@ -0,0 +1,13 @@ +using System; +using System.Collections.Generic; + +namespace ldap_cesi.Entities; + +public partial class Role +{ + public int Id { get; set; } + + public string Nom { get; set; } = null!; + + public virtual ICollection Utilisateurs { get; set; } = new List(); +} diff --git a/ldap-cesi/Entities/Salarie.cs b/ldap-cesi/Entities/Salarie.cs new file mode 100644 index 0000000..9ccc76a --- /dev/null +++ b/ldap-cesi/Entities/Salarie.cs @@ -0,0 +1,27 @@ +using System; +using System.Collections.Generic; + +namespace ldap_cesi.Entities; + +public partial class Salarie +{ + public int Id { get; set; } + + public string Nom { get; set; } = null!; + + public string Prenom { get; set; } = null!; + + public string TelephoneFixe { get; set; } = null!; + + public string TelephonePortable { get; set; } = null!; + + public string Email { get; set; } = null!; + + public int IdSite { get; set; } + + public int IdService { get; set; } + + public virtual Service IdServiceNavigation { get; set; } = null!; + + public virtual Site IdSiteNavigation { get; set; } = null!; +} diff --git a/ldap-cesi/Entities/Service.cs b/ldap-cesi/Entities/Service.cs new file mode 100644 index 0000000..912f597 --- /dev/null +++ b/ldap-cesi/Entities/Service.cs @@ -0,0 +1,13 @@ +using System; +using System.Collections.Generic; + +namespace ldap_cesi.Entities; + +public partial class Service +{ + public int Id { get; set; } + + public string Nom { get; set; } = null!; + + public virtual ICollection Salaries { get; set; } = new List(); +} diff --git a/ldap-cesi/Entities/Site.cs b/ldap-cesi/Entities/Site.cs new file mode 100644 index 0000000..40c7f26 --- /dev/null +++ b/ldap-cesi/Entities/Site.cs @@ -0,0 +1,13 @@ +using System; +using System.Collections.Generic; + +namespace ldap_cesi.Entities; + +public partial class Site +{ + public int Id { get; set; } + + public string? Ville { get; set; } + + public virtual ICollection Salaries { get; set; } = new List(); +} diff --git a/ldap-cesi/Entities/Utilisateur.cs b/ldap-cesi/Entities/Utilisateur.cs new file mode 100644 index 0000000..8f2223b --- /dev/null +++ b/ldap-cesi/Entities/Utilisateur.cs @@ -0,0 +1,19 @@ +using System; +using System.Collections.Generic; + +namespace ldap_cesi.Entities; + +public partial class Utilisateur +{ + public int Id { get; set; } + + public string? Nom { get; set; } + + public string? Prenom { get; set; } + + public string? MotDePasse { get; set; } + + public int IdRole { get; set; } + + public virtual Role IdRoleNavigation { get; set; } = null!; +} diff --git a/ldap-cesi/Program.cs b/ldap-cesi/Program.cs index d5e0ef3..5881c4b 100644 --- a/ldap-cesi/Program.cs +++ b/ldap-cesi/Program.cs @@ -1,7 +1,8 @@ +using ldap_cesi.Configurations; + var builder = WebApplication.CreateBuilder(args); -// Add services to the container. -// Learn more about configuring OpenAPI at https://aka.ms/aspnet/openapi +builder.BuildConf(); builder.Services.AddOpenApi(); var app = builder.Build(); @@ -14,28 +15,4 @@ if (app.Environment.IsDevelopment()) app.UseHttpsRedirection(); -var summaries = new[] -{ - "Freezing", "Bracing", "Chilly", "Cool", "Mild", "Warm", "Balmy", "Hot", "Sweltering", "Scorching" -}; - -app.MapGet("/weatherforecast", () => - { - var forecast = Enumerable.Range(1, 5).Select(index => - new WeatherForecast - ( - DateOnly.FromDateTime(DateTime.Now.AddDays(index)), - Random.Shared.Next(-20, 55), - summaries[Random.Shared.Next(summaries.Length)] - )) - .ToArray(); - return forecast; - }) - .WithName("GetWeatherForecast"); - app.Run(); - -record WeatherForecast(DateOnly Date, int TemperatureC, string? Summary) -{ - public int TemperatureF => 32 + (int)(TemperatureC / 0.5556); -} \ No newline at end of file diff --git a/ldap-cesi/ldap-cesi.csproj b/ldap-cesi/ldap-cesi.csproj index ab3c826..e7d67ee 100644 --- a/ldap-cesi/ldap-cesi.csproj +++ b/ldap-cesi/ldap-cesi.csproj @@ -8,7 +8,24 @@ + + + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + + + + + + From 66a00c60145c388107a6dee3ae304db9b2e184de Mon Sep 17 00:00:00 2001 From: BuzzLeclair Date: Sat, 1 Mar 2025 12:49:59 +0100 Subject: [PATCH 2/2] =?UTF-8?q?Ajout=20des=20r=C3=A9pertoires=20n=C3=A9ces?= =?UTF-8?q?saires=20au=20clean=20design=20pattern?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ldap-cesi/ldap-cesi.csproj | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/ldap-cesi/ldap-cesi.csproj b/ldap-cesi/ldap-cesi.csproj index e7d67ee..b240452 100644 --- a/ldap-cesi/ldap-cesi.csproj +++ b/ldap-cesi/ldap-cesi.csproj @@ -25,7 +25,11 @@ + + + +