diff --git a/Verax_API_EF/.idea/.idea.Verax_API_EF/.idea/.gitignore b/Verax_API_EF/.idea/.idea.Verax_API_EF/.idea/.gitignore new file mode 100644 index 0000000..16e553f --- /dev/null +++ b/Verax_API_EF/.idea/.idea.Verax_API_EF/.idea/.gitignore @@ -0,0 +1,13 @@ +# Default ignored files +/shelf/ +/workspace.xml +# Rider ignored files +/.idea.Verax_API_EF.iml +/contentModel.xml +/projectSettingsUpdater.xml +/modules.xml +# Editor-based HTTP Client requests +/httpRequests/ +# Datasource local storage ignored files +/dataSources/ +/dataSources.local.xml diff --git a/Verax_API_EF/.idea/.idea.Verax_API_EF/.idea/indexLayout.xml b/Verax_API_EF/.idea/.idea.Verax_API_EF/.idea/indexLayout.xml new file mode 100644 index 0000000..7b08163 --- /dev/null +++ b/Verax_API_EF/.idea/.idea.Verax_API_EF/.idea/indexLayout.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/Verax_API_EF/API_DbDataManager/API_DbDataManager.csproj b/Verax_API_EF/API_DbDataManager/API_DbDataManager.csproj new file mode 100644 index 0000000..b2f1743 --- /dev/null +++ b/Verax_API_EF/API_DbDataManager/API_DbDataManager.csproj @@ -0,0 +1,15 @@ + + + + net8.0 + enable + enable + DbDataManager + + + + + + + + diff --git a/Verax_API_EF/API_DbDataManager/Class1.cs b/Verax_API_EF/API_DbDataManager/Class1.cs new file mode 100644 index 0000000..628fa69 --- /dev/null +++ b/Verax_API_EF/API_DbDataManager/Class1.cs @@ -0,0 +1,94 @@ +using API_Services; +using DbContextLib; +using Web_API.Mapper; +using Web_API.Model; + +namespace DbDataManager; + +public class DbDataManager : IArticleService, IFormulaireService, IUserService +{ + + private readonly LibraryContext _context; + private Mapper map = new Mapper(); + public DbDataManager(LibraryContext context) + { + _context = context; + } + + public Task CreateArticle(ArticleDTO a) + { + throw new NotImplementedException(); + } + + public Task DeleteArticle(long id) + { + throw new NotImplementedException(); + } + + public Task UpdateArticle(long id, ArticleDTO a) + { + throw new NotImplementedException(); + } + + public Task GetArticleById(int id) + { + var article = _context.ArticleSet.Find(id); + return Task.FromResult(map.ArtEntityToDTO(article)); + } + + public Task> GetAllArticles() + { + var articles = _context.ArticleSet.ToList(); + return Task.FromResult(map.ArtEntityToDTO(articles)); + } + + public Task> GetAllForm() + { + throw new NotImplementedException(); + } + + public Task GetById(long id) + { + throw new NotImplementedException(); + } + + public Task CreateForm(Formulaire formulaire) + { + throw new NotImplementedException(); + } + + public Task DeleteForm(long id) + { + throw new NotImplementedException(); + } + + public Task UpdateForm(long id, Formulaire formulaire) + { + throw new NotImplementedException(); + } + + public Task Create(User user) + { + throw new NotImplementedException(); + } + + public Task Update(User user) + { + throw new NotImplementedException(); + } + + public Task Delete(string pseudo) + { + throw new NotImplementedException(); + } + + public Task GetByPseudo(string pseudo) + { + throw new NotImplementedException(); + } + + public Task> GetAll() + { + throw new NotImplementedException(); + } +} \ No newline at end of file diff --git a/Verax_API_EF/API_Mapping/API_Mapping.csproj b/Verax_API_EF/API_Mapping/API_Mapping.csproj new file mode 100644 index 0000000..e7b7c68 --- /dev/null +++ b/Verax_API_EF/API_Mapping/API_Mapping.csproj @@ -0,0 +1,14 @@ + + + + net8.0 + enable + enable + + + + + + + + diff --git a/Verax_API_EF/API_Mapping/ArticleMapper.cs b/Verax_API_EF/API_Mapping/ArticleMapper.cs new file mode 100644 index 0000000..9767dd8 --- /dev/null +++ b/Verax_API_EF/API_Mapping/ArticleMapper.cs @@ -0,0 +1,27 @@ +using Model; +using Web_API.Model; + +namespace API_Mapping; + +public static class ArticleMapper +{ + public static ArticleDTO ToDTO(this Article a) => new() + { + Id = a.Id, + Title = a.Title, + Description = a.Description, + DatePublished = a.DatePublished, + LectureTime = a.LectureTime, + Author = a.Author + }; + + public static Article ToModel(this ArticleDTO a) => new() + { + Id = a.Id, + Title = a.Title, + Description = a.Description, + DatePublished = a.DatePublished, + LectureTime = a.LectureTime, + Author = a.Author + }; +} \ No newline at end of file diff --git a/Verax_API_EF/API_Mapping/FormulaireMapping.cs b/Verax_API_EF/API_Mapping/FormulaireMapping.cs new file mode 100644 index 0000000..eef95ef --- /dev/null +++ b/Verax_API_EF/API_Mapping/FormulaireMapping.cs @@ -0,0 +1,25 @@ +using Model; +using Web_API.Model; + +namespace API_Mapping; + +public static class FormulaireMapping +{ + public static FormulaireDTO ToDTO(this Formulaire f) => new() + { + Id = f.Id, + Theme = f.Theme, + Date = f.Date, + Lien = f.Lien, + Pseudo = f.Pseudo + }; + + public static Formulaire ToModel(this FormulaireDTO f) => new() + { + Id = f.Id, + Theme = f.Theme, + Date = f.Date, + Lien = f.Lien, + Pseudo = f.Pseudo + }; +} \ No newline at end of file diff --git a/Verax_API_EF/API_Mapping/UserMapping.cs b/Verax_API_EF/API_Mapping/UserMapping.cs new file mode 100644 index 0000000..ef5cd9c --- /dev/null +++ b/Verax_API_EF/API_Mapping/UserMapping.cs @@ -0,0 +1,27 @@ +using Model; +using Web_API.Model; + +namespace API_Mapping; + +public static class UserMapping +{ + public static UserDTO ToDTO(this User u) => new() + { + Pseudo = u.Pseudo, + Mdp = u.Mdp, + Nom = u.Nom, + Prenom = u.Prenom, + Mail = u.Mail, + Role = u.Role + }; + + public static User ToModel(this UserDTO u) => new() + { + Pseudo = u.Pseudo, + Mdp = u.Mdp, + Nom = u.Nom, + Prenom = u.Prenom, + Mail = u.Mail, + Role = u.Role + }; +} \ No newline at end of file diff --git a/Verax_API_EF/API_Model/API_Model.csproj b/Verax_API_EF/API_Model/API_Model.csproj new file mode 100644 index 0000000..3a63532 --- /dev/null +++ b/Verax_API_EF/API_Model/API_Model.csproj @@ -0,0 +1,9 @@ + + + + net8.0 + enable + enable + + + diff --git a/Verax_API_EF/API_Model/ArticleDTO.cs b/Verax_API_EF/API_Model/ArticleDTO.cs new file mode 100644 index 0000000..b5d2129 --- /dev/null +++ b/Verax_API_EF/API_Model/ArticleDTO.cs @@ -0,0 +1,12 @@ +namespace Web_API.Model; + +public class ArticleDTO +{ + public long Id { get; set; } + public string Title { get; set; } = string.Empty; + public string Description { get; set; } = string.Empty; + public string DatePublished { get; set; } = string.Empty; + public int LectureTime { get; set; } + public string Author { get; set; } = string.Empty; + +} \ No newline at end of file diff --git a/Verax_API_EF/API_Model/FormulaireDTO.cs b/Verax_API_EF/API_Model/FormulaireDTO.cs new file mode 100644 index 0000000..53d1457 --- /dev/null +++ b/Verax_API_EF/API_Model/FormulaireDTO.cs @@ -0,0 +1,12 @@ +namespace Web_API.Model; + +public class FormulaireDTO +{ + public long Id; + public string Theme { get; set; } + public DateTime Date { get; set; } + public string Lien { get; set; } + public string Pseudo { get; set; } + + +} \ No newline at end of file diff --git a/Verax_API_EF/API_Model/UserDTO.cs b/Verax_API_EF/API_Model/UserDTO.cs new file mode 100644 index 0000000..9292c2d --- /dev/null +++ b/Verax_API_EF/API_Model/UserDTO.cs @@ -0,0 +1,11 @@ +namespace Web_API.Model; + +public class UserDTO +{ + public string Pseudo { get; set; } + public string Mdp { get; set; } + public string Nom { get; set; } + public string Prenom { get; set; } + public string Mail { get; set; } + public string Role { get; set; } +} \ No newline at end of file diff --git a/Verax_API_EF/API_Services/API_Services.csproj b/Verax_API_EF/API_Services/API_Services.csproj new file mode 100644 index 0000000..cd25ca9 --- /dev/null +++ b/Verax_API_EF/API_Services/API_Services.csproj @@ -0,0 +1,13 @@ + + + + net8.0 + enable + enable + + + + + + + diff --git a/Verax_API_EF/API_Services/IArticleService.cs b/Verax_API_EF/API_Services/IArticleService.cs new file mode 100644 index 0000000..46766f9 --- /dev/null +++ b/Verax_API_EF/API_Services/IArticleService.cs @@ -0,0 +1,19 @@ +using Entities; +using Web_API.Model; + +namespace API_Services +{ + public interface IArticleService + { + Task CreateArticle(ArticleDTO a); + + Task DeleteArticle(long id); + + Task UpdateArticle(long id, ArticleDTO a); + + Task GetArticleById(int id); + + Task> GetAllArticles(); + + } +} diff --git a/Verax_API_EF/API_Services/IFormulaireService.cs b/Verax_API_EF/API_Services/IFormulaireService.cs new file mode 100644 index 0000000..49c0ade --- /dev/null +++ b/Verax_API_EF/API_Services/IFormulaireService.cs @@ -0,0 +1,18 @@ +using Web_API.Model; + +namespace API_Services; + +public interface IFormulaireService +{ + + Task> GetAllForm(); + + Task GetById(long id); + + + Task CreateForm(Formulaire formulaire); + + Task DeleteForm(long id); + + Task UpdateForm(long id, Formulaire formulaire); +} \ No newline at end of file diff --git a/Verax_API_EF/API_Services/IUserService.cs b/Verax_API_EF/API_Services/IUserService.cs new file mode 100644 index 0000000..51b1d6f --- /dev/null +++ b/Verax_API_EF/API_Services/IUserService.cs @@ -0,0 +1,20 @@ +using Web_API.Model; + +namespace API_Services +{ + public interface IUserService + { + Task Create(User user); + Task Update(User user); + + Task Delete(string pseudo); + + + Task GetByPseudo(string pseudo); + + Task> GetAll(); + + + + } +} diff --git a/Verax_API_EF/DbContextLib/DbContextLib.csproj b/Verax_API_EF/DbContextLib/DbContextLib.csproj new file mode 100644 index 0000000..ad20d53 --- /dev/null +++ b/Verax_API_EF/DbContextLib/DbContextLib.csproj @@ -0,0 +1,23 @@ + + + + net8.0 + enable + enable + + + + + + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + + + + + + + diff --git a/Verax_API_EF/DbContextLib/LibraryContext.cs b/Verax_API_EF/DbContextLib/LibraryContext.cs new file mode 100644 index 0000000..fe2cbf4 --- /dev/null +++ b/Verax_API_EF/DbContextLib/LibraryContext.cs @@ -0,0 +1,36 @@ +using Entities; +using Microsoft.EntityFrameworkCore; + +namespace DbContextLib; + +public class LibraryContext : DbContext +{ + public LibraryContext() + : base() + { } + + public LibraryContext(DbContextOptions options) + : base(options) + { } + + public DbSet ArticleSet { get; set; } + public DbSet UserSet { get; set; } + + protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) + { + if (!optionsBuilder.IsConfigured) + { + optionsBuilder.UseSqlite($"Data Source=Entity_FrameWork.Article.db"); + } + } + + protected override void OnModelCreating(ModelBuilder modelBuilder) + { + base.OnModelCreating(modelBuilder); + + modelBuilder.Entity() + .HasMany(a => a.Users) + .WithMany(a => a.Articles) + .UsingEntity(); + } +} \ No newline at end of file diff --git a/Verax_API_EF/Entities/ArticleEntity.cs b/Verax_API_EF/Entities/ArticleEntity.cs new file mode 100644 index 0000000..f82543e --- /dev/null +++ b/Verax_API_EF/Entities/ArticleEntity.cs @@ -0,0 +1,14 @@ +namespace Entities; + +public class ArticleEntity +{ + public long Id { get; set; } + public string Title { get; set; } = string.Empty; + public string Description { get; set; } = string.Empty; + public string DatePublished { get; set; } = string.Empty; + public int LectureTime { get; set; } + public string Author { get; set; } = string.Empty; + + public ICollection Users { get; } = new List(); + +} \ No newline at end of file diff --git a/Verax_API_EF/Entities/ArticleUserEntity.cs b/Verax_API_EF/Entities/ArticleUserEntity.cs new file mode 100644 index 0000000..2faf6b7 --- /dev/null +++ b/Verax_API_EF/Entities/ArticleUserEntity.cs @@ -0,0 +1,7 @@ +namespace Entities; + +public class ArticleUserEntity +{ + public long UserEntityId { get; set; } + public long ArticleEntityId { get; set; } +} \ No newline at end of file diff --git a/Verax_API_EF/Entities/Entities.csproj b/Verax_API_EF/Entities/Entities.csproj new file mode 100644 index 0000000..e547c5d --- /dev/null +++ b/Verax_API_EF/Entities/Entities.csproj @@ -0,0 +1,19 @@ + + + + net8.0 + enable + enable + + + + + + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + + + diff --git a/Verax_API_EF/Entities/FormEntity.cs b/Verax_API_EF/Entities/FormEntity.cs new file mode 100644 index 0000000..75b43e0 --- /dev/null +++ b/Verax_API_EF/Entities/FormEntity.cs @@ -0,0 +1,16 @@ +namespace Entities; + +public class FormEntity +{ + public long Id { get; set; } + public string Theme { get; set; } = string.Empty; + public string DatePublication { get; set; } = string.Empty; + public string Link { get; set; } = string.Empty; + public string Pseudo { get; set; } = string.Empty; + + + public long UserEntityId { get; set; } + public UserEntity User { get; set; } = null; + + +} \ No newline at end of file diff --git a/Verax_API_EF/Entities/UserEntity.cs b/Verax_API_EF/Entities/UserEntity.cs new file mode 100644 index 0000000..7d8680a --- /dev/null +++ b/Verax_API_EF/Entities/UserEntity.cs @@ -0,0 +1,21 @@ +namespace Entities; + +public class UserEntity +{ + public long Id { get; set; } + public string Pseudo { get; set; } = string.Empty; + + public string Mdp { get; set; } = string.Empty; + + public string Nom { get; set; } = string.Empty; + + public string Prenom { get; set; } = string.Empty; + + public string Mail { get; set; } = string.Empty; + + public string Role { get; set; } = string.Empty; + + public ICollection Articles { get; set; } = new List(); + + public ICollection Forms { get; set; } = new List(); +} \ No newline at end of file diff --git a/Verax_API_EF/Model/Article.cs b/Verax_API_EF/Model/Article.cs new file mode 100644 index 0000000..497b56c --- /dev/null +++ b/Verax_API_EF/Model/Article.cs @@ -0,0 +1,11 @@ +namespace Model; + +public class Article +{ + public long Id { get; set; } + public string Title { get; set; } = string.Empty; + public string Description { get; set; } = string.Empty; + public string DatePublished { get; set; } = string.Empty; + public int LectureTime { get; set; } + public string Author { get; set; } = string.Empty; +} \ No newline at end of file diff --git a/Verax_API_EF/Model/Formulaire.cs b/Verax_API_EF/Model/Formulaire.cs new file mode 100644 index 0000000..2363c4d --- /dev/null +++ b/Verax_API_EF/Model/Formulaire.cs @@ -0,0 +1,10 @@ +namespace Model; + +public class Formulaire +{ + public long Id; + public string Theme { get; set; } + public DateTime Date { get; set; } + public string Lien { get; set; } + public string Pseudo { get; set; } +} \ No newline at end of file diff --git a/Verax_API_EF/Model/Model.csproj b/Verax_API_EF/Model/Model.csproj new file mode 100644 index 0000000..3a63532 --- /dev/null +++ b/Verax_API_EF/Model/Model.csproj @@ -0,0 +1,9 @@ + + + + net8.0 + enable + enable + + + diff --git a/Verax_API_EF/Model/User.cs b/Verax_API_EF/Model/User.cs new file mode 100644 index 0000000..f6b4be0 --- /dev/null +++ b/Verax_API_EF/Model/User.cs @@ -0,0 +1,11 @@ +namespace Model; + +public class User +{ + public string Pseudo { get; set; } + public string Mdp { get; set; } + public string Nom { get; set; } + public string Prenom { get; set; } + public string Mail { get; set; } + public string Role { get; set; } +} \ No newline at end of file diff --git a/Verax_API_EF/StubbedContextLib/Class1.cs b/Verax_API_EF/StubbedContextLib/Class1.cs new file mode 100644 index 0000000..b922036 --- /dev/null +++ b/Verax_API_EF/StubbedContextLib/Class1.cs @@ -0,0 +1,89 @@ +using DbContextLib; +using Entities; +using Microsoft.EntityFrameworkCore; + +namespace StubbedContextLib; + +public class StubbedContext : LibraryContext +{ + protected override void OnModelCreating(ModelBuilder modelBuilder) + { + base.OnModelCreating(modelBuilder); + + modelBuilder.Entity().HasData( + new ArticleEntity + { + Id = 1, + Title = "Breaking News Elisabeth 2 Died", + Description = "The queen of England died today at the age of 95", + DatePublished = "2022-02-06", + LectureTime = 2, + Author = "Tom Smith" + + }, + new ArticleEntity + { + Id = 2, + Title = "The new iPhone 15", + Description = "The new iPhone 15 is out and it's the best phone ever", + DatePublished = "2022-02-06", + LectureTime = 3, + Author = "Tom Smith" + + }, + new ArticleEntity + { + Id = 3, + Title = "M&M's new recipe", + Description = "M&M's new recipe is out and it's the best chocolate ever", + DatePublished = "2022-02-06", + LectureTime = 1, + Author = "M&M's Red" + } + ); + + modelBuilder.Entity().HasData( + new UserEntity + { + Id = 1, Nom = "Fages", Prenom = "Tony", Pseudo = "TonyF", Mail = "tony@gmail.com", Mdp = "1234", Role = "Admin" + }, + new UserEntity + { + Id = 2, Nom = "Smith", Prenom = "Tom", Pseudo = "TomS", Mail = "tom@mail.com", Mdp = "1234", + Role = "User" + }, + new UserEntity + { + Id = 3, Nom = "M&M's", Prenom = "Red", Pseudo = "RedM", Mail = "M&M#mail.com", Mdp = "1234", Role = "Modérator" + } + ); + + modelBuilder.Entity().HasData( + new ArticleUserEntity + { + ArticleEntityId = 1, + UserEntityId = 1 + }, + new ArticleUserEntity + { + ArticleEntityId = 2, + UserEntityId = 2 + }, + new ArticleUserEntity + { + ArticleEntityId = 3, + UserEntityId = 3 + }, + new ArticleUserEntity + { + ArticleEntityId = 3, + UserEntityId = 1 + }, + new ArticleUserEntity + { + ArticleEntityId = 2, + UserEntityId = 3 + } + ); + } +} \ No newline at end of file diff --git a/Verax_API_EF/StubbedContextLib/Migrations/20240305073325_mrg1.Designer.cs b/Verax_API_EF/StubbedContextLib/Migrations/20240305073325_mrg1.Designer.cs new file mode 100644 index 0000000..c8caf18 --- /dev/null +++ b/Verax_API_EF/StubbedContextLib/Migrations/20240305073325_mrg1.Designer.cs @@ -0,0 +1,255 @@ +// +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; +using StubbedContextLib; + +#nullable disable + +namespace StubbedContextLib.Migrations +{ + [DbContext(typeof(StubbedContext))] + [Migration("20240305073325_mrg1")] + partial class mrg1 + { + /// + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder.HasAnnotation("ProductVersion", "8.0.2"); + + modelBuilder.Entity("Entities.ArticleEntity", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("INTEGER"); + + b.Property("Author") + .IsRequired() + .HasColumnType("TEXT"); + + b.Property("DatePublished") + .IsRequired() + .HasColumnType("TEXT"); + + b.Property("Description") + .IsRequired() + .HasColumnType("TEXT"); + + b.Property("LectureTime") + .HasColumnType("INTEGER"); + + b.Property("Title") + .IsRequired() + .HasColumnType("TEXT"); + + b.HasKey("Id"); + + b.ToTable("ArticleSet"); + + b.HasData( + new + { + Id = 1L, + Author = "Tom Smith", + DatePublished = "2022-02-06", + Description = "The queen of England died today at the age of 95", + LectureTime = 2, + Title = "Breaking News Elisabeth 2 Died" + }, + new + { + Id = 2L, + Author = "Tom Smith", + DatePublished = "2022-02-06", + Description = "The new iPhone 15 is out and it's the best phone ever", + LectureTime = 3, + Title = "The new iPhone 15" + }, + new + { + Id = 3L, + Author = "M&M's Red", + DatePublished = "2022-02-06", + Description = "M&M's new recipe is out and it's the best chocolate ever", + LectureTime = 1, + Title = "M&M's new recipe" + }); + }); + + modelBuilder.Entity("Entities.ArticleUserEntity", b => + { + b.Property("ArticleEntityId") + .HasColumnType("INTEGER"); + + b.Property("UserEntityId") + .HasColumnType("INTEGER"); + + b.HasKey("ArticleEntityId", "UserEntityId"); + + b.HasIndex("UserEntityId"); + + b.ToTable("ArticleUserEntity"); + + b.HasData( + new + { + ArticleEntityId = 1L, + UserEntityId = 1L + }, + new + { + ArticleEntityId = 2L, + UserEntityId = 2L + }, + new + { + ArticleEntityId = 3L, + UserEntityId = 3L + }, + new + { + ArticleEntityId = 3L, + UserEntityId = 1L + }, + new + { + ArticleEntityId = 2L, + UserEntityId = 3L + }); + }); + + modelBuilder.Entity("Entities.FormEntity", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("INTEGER"); + + b.Property("DatePublication") + .IsRequired() + .HasColumnType("TEXT"); + + b.Property("Link") + .IsRequired() + .HasColumnType("TEXT"); + + b.Property("Pseudo") + .IsRequired() + .HasColumnType("TEXT"); + + b.Property("Theme") + .IsRequired() + .HasColumnType("TEXT"); + + b.Property("UserEntityId") + .HasColumnType("INTEGER"); + + b.HasKey("Id"); + + b.HasIndex("UserEntityId"); + + b.ToTable("FormEntity"); + }); + + modelBuilder.Entity("Entities.UserEntity", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("INTEGER"); + + b.Property("Mail") + .IsRequired() + .HasColumnType("TEXT"); + + b.Property("Mdp") + .IsRequired() + .HasColumnType("TEXT"); + + b.Property("Nom") + .IsRequired() + .HasColumnType("TEXT"); + + b.Property("Prenom") + .IsRequired() + .HasColumnType("TEXT"); + + b.Property("Pseudo") + .IsRequired() + .HasColumnType("TEXT"); + + b.Property("Role") + .IsRequired() + .HasColumnType("TEXT"); + + b.HasKey("Id"); + + b.ToTable("UserSet"); + + b.HasData( + new + { + Id = 1L, + Mail = "tony@gmail.com", + Mdp = "1234", + Nom = "Fages", + Prenom = "Tony", + Pseudo = "TonyF", + Role = "Admin" + }, + new + { + Id = 2L, + Mail = "tom@mail.com", + Mdp = "1234", + Nom = "Smith", + Prenom = "Tom", + Pseudo = "TomS", + Role = "User" + }, + new + { + Id = 3L, + Mail = "M&M#mail.com", + Mdp = "1234", + Nom = "M&M's", + Prenom = "Red", + Pseudo = "RedM", + Role = "Modérator" + }); + }); + + modelBuilder.Entity("Entities.ArticleUserEntity", b => + { + b.HasOne("Entities.ArticleEntity", null) + .WithMany() + .HasForeignKey("ArticleEntityId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("Entities.UserEntity", null) + .WithMany() + .HasForeignKey("UserEntityId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("Entities.FormEntity", b => + { + b.HasOne("Entities.UserEntity", "User") + .WithMany("Forms") + .HasForeignKey("UserEntityId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("User"); + }); + + modelBuilder.Entity("Entities.UserEntity", b => + { + b.Navigation("Forms"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/Verax_API_EF/StubbedContextLib/Migrations/20240305073325_mrg1.cs b/Verax_API_EF/StubbedContextLib/Migrations/20240305073325_mrg1.cs new file mode 100644 index 0000000..7cfb904 --- /dev/null +++ b/Verax_API_EF/StubbedContextLib/Migrations/20240305073325_mrg1.cs @@ -0,0 +1,156 @@ +using Microsoft.EntityFrameworkCore.Migrations; + +#nullable disable + +#pragma warning disable CA1814 // Prefer jagged arrays over multidimensional + +namespace StubbedContextLib.Migrations +{ + /// + public partial class mrg1 : Migration + { + /// + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.CreateTable( + name: "ArticleSet", + columns: table => new + { + Id = table.Column(type: "INTEGER", nullable: false) + .Annotation("Sqlite:Autoincrement", true), + Title = table.Column(type: "TEXT", nullable: false), + Description = table.Column(type: "TEXT", nullable: false), + DatePublished = table.Column(type: "TEXT", nullable: false), + LectureTime = table.Column(type: "INTEGER", nullable: false), + Author = table.Column(type: "TEXT", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_ArticleSet", x => x.Id); + }); + + migrationBuilder.CreateTable( + name: "UserSet", + columns: table => new + { + Id = table.Column(type: "INTEGER", nullable: false) + .Annotation("Sqlite:Autoincrement", true), + Pseudo = table.Column(type: "TEXT", nullable: false), + Mdp = table.Column(type: "TEXT", nullable: false), + Nom = table.Column(type: "TEXT", nullable: false), + Prenom = table.Column(type: "TEXT", nullable: false), + Mail = table.Column(type: "TEXT", nullable: false), + Role = table.Column(type: "TEXT", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_UserSet", x => x.Id); + }); + + migrationBuilder.CreateTable( + name: "ArticleUserEntity", + columns: table => new + { + UserEntityId = table.Column(type: "INTEGER", nullable: false), + ArticleEntityId = table.Column(type: "INTEGER", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_ArticleUserEntity", x => new { x.ArticleEntityId, x.UserEntityId }); + table.ForeignKey( + name: "FK_ArticleUserEntity_ArticleSet_ArticleEntityId", + column: x => x.ArticleEntityId, + principalTable: "ArticleSet", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + table.ForeignKey( + name: "FK_ArticleUserEntity_UserSet_UserEntityId", + column: x => x.UserEntityId, + principalTable: "UserSet", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateTable( + name: "FormEntity", + columns: table => new + { + Id = table.Column(type: "INTEGER", nullable: false) + .Annotation("Sqlite:Autoincrement", true), + Theme = table.Column(type: "TEXT", nullable: false), + DatePublication = table.Column(type: "TEXT", nullable: false), + Link = table.Column(type: "TEXT", nullable: false), + Pseudo = table.Column(type: "TEXT", nullable: false), + UserEntityId = table.Column(type: "INTEGER", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_FormEntity", x => x.Id); + table.ForeignKey( + name: "FK_FormEntity_UserSet_UserEntityId", + column: x => x.UserEntityId, + principalTable: "UserSet", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.InsertData( + table: "ArticleSet", + columns: new[] { "Id", "Author", "DatePublished", "Description", "LectureTime", "Title" }, + values: new object[,] + { + { 1L, "Tom Smith", "2022-02-06", "The queen of England died today at the age of 95", 2, "Breaking News Elisabeth 2 Died" }, + { 2L, "Tom Smith", "2022-02-06", "The new iPhone 15 is out and it's the best phone ever", 3, "The new iPhone 15" }, + { 3L, "M&M's Red", "2022-02-06", "M&M's new recipe is out and it's the best chocolate ever", 1, "M&M's new recipe" } + }); + + migrationBuilder.InsertData( + table: "UserSet", + columns: new[] { "Id", "Mail", "Mdp", "Nom", "Prenom", "Pseudo", "Role" }, + values: new object[,] + { + { 1L, "tony@gmail.com", "1234", "Fages", "Tony", "TonyF", "Admin" }, + { 2L, "tom@mail.com", "1234", "Smith", "Tom", "TomS", "User" }, + { 3L, "M&M#mail.com", "1234", "M&M's", "Red", "RedM", "Modérator" } + }); + + migrationBuilder.InsertData( + table: "ArticleUserEntity", + columns: new[] { "ArticleEntityId", "UserEntityId" }, + values: new object[,] + { + { 1L, 1L }, + { 2L, 2L }, + { 2L, 3L }, + { 3L, 1L }, + { 3L, 3L } + }); + + migrationBuilder.CreateIndex( + name: "IX_ArticleUserEntity_UserEntityId", + table: "ArticleUserEntity", + column: "UserEntityId"); + + migrationBuilder.CreateIndex( + name: "IX_FormEntity_UserEntityId", + table: "FormEntity", + column: "UserEntityId"); + } + + /// + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropTable( + name: "ArticleUserEntity"); + + migrationBuilder.DropTable( + name: "FormEntity"); + + migrationBuilder.DropTable( + name: "ArticleSet"); + + migrationBuilder.DropTable( + name: "UserSet"); + } + } +} diff --git a/Verax_API_EF/StubbedContextLib/Migrations/StubbedContextModelSnapshot.cs b/Verax_API_EF/StubbedContextLib/Migrations/StubbedContextModelSnapshot.cs new file mode 100644 index 0000000..46de8e6 --- /dev/null +++ b/Verax_API_EF/StubbedContextLib/Migrations/StubbedContextModelSnapshot.cs @@ -0,0 +1,252 @@ +// +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; +using StubbedContextLib; + +#nullable disable + +namespace StubbedContextLib.Migrations +{ + [DbContext(typeof(StubbedContext))] + partial class StubbedContextModelSnapshot : ModelSnapshot + { + protected override void BuildModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder.HasAnnotation("ProductVersion", "8.0.2"); + + modelBuilder.Entity("Entities.ArticleEntity", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("INTEGER"); + + b.Property("Author") + .IsRequired() + .HasColumnType("TEXT"); + + b.Property("DatePublished") + .IsRequired() + .HasColumnType("TEXT"); + + b.Property("Description") + .IsRequired() + .HasColumnType("TEXT"); + + b.Property("LectureTime") + .HasColumnType("INTEGER"); + + b.Property("Title") + .IsRequired() + .HasColumnType("TEXT"); + + b.HasKey("Id"); + + b.ToTable("ArticleSet"); + + b.HasData( + new + { + Id = 1L, + Author = "Tom Smith", + DatePublished = "2022-02-06", + Description = "The queen of England died today at the age of 95", + LectureTime = 2, + Title = "Breaking News Elisabeth 2 Died" + }, + new + { + Id = 2L, + Author = "Tom Smith", + DatePublished = "2022-02-06", + Description = "The new iPhone 15 is out and it's the best phone ever", + LectureTime = 3, + Title = "The new iPhone 15" + }, + new + { + Id = 3L, + Author = "M&M's Red", + DatePublished = "2022-02-06", + Description = "M&M's new recipe is out and it's the best chocolate ever", + LectureTime = 1, + Title = "M&M's new recipe" + }); + }); + + modelBuilder.Entity("Entities.ArticleUserEntity", b => + { + b.Property("ArticleEntityId") + .HasColumnType("INTEGER"); + + b.Property("UserEntityId") + .HasColumnType("INTEGER"); + + b.HasKey("ArticleEntityId", "UserEntityId"); + + b.HasIndex("UserEntityId"); + + b.ToTable("ArticleUserEntity"); + + b.HasData( + new + { + ArticleEntityId = 1L, + UserEntityId = 1L + }, + new + { + ArticleEntityId = 2L, + UserEntityId = 2L + }, + new + { + ArticleEntityId = 3L, + UserEntityId = 3L + }, + new + { + ArticleEntityId = 3L, + UserEntityId = 1L + }, + new + { + ArticleEntityId = 2L, + UserEntityId = 3L + }); + }); + + modelBuilder.Entity("Entities.FormEntity", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("INTEGER"); + + b.Property("DatePublication") + .IsRequired() + .HasColumnType("TEXT"); + + b.Property("Link") + .IsRequired() + .HasColumnType("TEXT"); + + b.Property("Pseudo") + .IsRequired() + .HasColumnType("TEXT"); + + b.Property("Theme") + .IsRequired() + .HasColumnType("TEXT"); + + b.Property("UserEntityId") + .HasColumnType("INTEGER"); + + b.HasKey("Id"); + + b.HasIndex("UserEntityId"); + + b.ToTable("FormEntity"); + }); + + modelBuilder.Entity("Entities.UserEntity", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("INTEGER"); + + b.Property("Mail") + .IsRequired() + .HasColumnType("TEXT"); + + b.Property("Mdp") + .IsRequired() + .HasColumnType("TEXT"); + + b.Property("Nom") + .IsRequired() + .HasColumnType("TEXT"); + + b.Property("Prenom") + .IsRequired() + .HasColumnType("TEXT"); + + b.Property("Pseudo") + .IsRequired() + .HasColumnType("TEXT"); + + b.Property("Role") + .IsRequired() + .HasColumnType("TEXT"); + + b.HasKey("Id"); + + b.ToTable("UserSet"); + + b.HasData( + new + { + Id = 1L, + Mail = "tony@gmail.com", + Mdp = "1234", + Nom = "Fages", + Prenom = "Tony", + Pseudo = "TonyF", + Role = "Admin" + }, + new + { + Id = 2L, + Mail = "tom@mail.com", + Mdp = "1234", + Nom = "Smith", + Prenom = "Tom", + Pseudo = "TomS", + Role = "User" + }, + new + { + Id = 3L, + Mail = "M&M#mail.com", + Mdp = "1234", + Nom = "M&M's", + Prenom = "Red", + Pseudo = "RedM", + Role = "Modérator" + }); + }); + + modelBuilder.Entity("Entities.ArticleUserEntity", b => + { + b.HasOne("Entities.ArticleEntity", null) + .WithMany() + .HasForeignKey("ArticleEntityId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("Entities.UserEntity", null) + .WithMany() + .HasForeignKey("UserEntityId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("Entities.FormEntity", b => + { + b.HasOne("Entities.UserEntity", "User") + .WithMany("Forms") + .HasForeignKey("UserEntityId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("User"); + }); + + modelBuilder.Entity("Entities.UserEntity", b => + { + b.Navigation("Forms"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/Verax_API_EF/StubbedContextLib/StubbedContextLib.csproj b/Verax_API_EF/StubbedContextLib/StubbedContextLib.csproj new file mode 100644 index 0000000..c39101a --- /dev/null +++ b/Verax_API_EF/StubbedContextLib/StubbedContextLib.csproj @@ -0,0 +1,23 @@ + + + + net8.0 + enable + enable + + + + + + + + + + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + + + diff --git a/Verax_API_EF/Test_Console_EF/Entity_FrameWork.Article.db b/Verax_API_EF/Test_Console_EF/Entity_FrameWork.Article.db new file mode 100644 index 0000000..a650ca1 Binary files /dev/null and b/Verax_API_EF/Test_Console_EF/Entity_FrameWork.Article.db differ diff --git a/Verax_API_EF/Test_Console_EF/Program.cs b/Verax_API_EF/Test_Console_EF/Program.cs new file mode 100644 index 0000000..5077f83 --- /dev/null +++ b/Verax_API_EF/Test_Console_EF/Program.cs @@ -0,0 +1,83 @@ +// See https://aka.ms/new-console-template for more information + +using DbContextLib; +using Entities; + +addArticle(); +listArticle(); + +// Allows to list all the articles from the db +void listArticle() +{ + using (var context = new LibraryContext()) + { + var articles = context.ArticleSet; + foreach (var article in articles) + { + Console.WriteLine($"{article.Author} - {article.Title} - {article.Description} - {article.DatePublished} - {article.LectureTime}"); + } + } +} + + +// Allows to list all the articles from the db by author +void listArticleByAuthor() +{ + using (var context = new LibraryContext()) + { + var articles = context.ArticleSet.Where(a => a.Author.Equals("Tony Fages")); + foreach (var article in articles) + { + Console.WriteLine($"{article.Author} - {article.Title} - {article.Description} - {article.DatePublished} - {article.LectureTime}"); + } + } +} + +// Allows to add an article to the db +void addArticle() +{ + using (var context = new LibraryContext()) + { + var article = new ArticleEntity + { + Title = "Louis is not sick anymore", + Description = "Louis is not sick anymore, he is now healthy and happy", + DatePublished = "16-02-2024", + LectureTime = 1, + Author = "Tony Fages" + }; + context.ArticleSet.Add(article); + context.SaveChanges(); + } +} + + +// Allows to modify an article from the db +void modifyArticle() +{ + using (var context = new LibraryContext()) + { + var article = context.ArticleSet.Where(a => a.Author.Equals("Tom Smith")); + + foreach (var articles in article) + { + articles.Title = "Demain des l'aube"; + context.SaveChanges(); + } + } +} + +// Allows to delete an article from the db +void deleteArticle() +{ + using (var context = new LibraryContext()) + { + var article = context.ArticleSet.Where(a => a.Author.Equals("M&M's Red")); + + foreach (var articles in article) + { + context.ArticleSet.Remove(articles); + context.SaveChanges(); + } + } +} \ No newline at end of file diff --git a/Verax_API_EF/Test_Console_EF/Test_Console_EF.csproj b/Verax_API_EF/Test_Console_EF/Test_Console_EF.csproj new file mode 100644 index 0000000..bd068dc --- /dev/null +++ b/Verax_API_EF/Test_Console_EF/Test_Console_EF.csproj @@ -0,0 +1,26 @@ + + + + Exe + net8.0 + enable + enable + $(MSBuildProjectDirectory) + + + + + + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + + + + + + + + diff --git a/Verax_API_EF/TestsUnitaires/Properties/AssemblyInfo.cs b/Verax_API_EF/TestsUnitaires/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..c3f33a7 --- /dev/null +++ b/Verax_API_EF/TestsUnitaires/Properties/AssemblyInfo.cs @@ -0,0 +1,35 @@ +using System.Reflection; +using System.Runtime.InteropServices; + +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +[assembly: AssemblyTitle("TestsUnitaires")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("TestsUnitaires")] +[assembly: AssemblyCopyright("Copyright © 2024")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// Setting ComVisible to false makes the types in this assembly not visible +// to COM components. If you need to access a type in this assembly from +// COM, set the ComVisible attribute to true on that type. +[assembly: ComVisible(false)] + +// The following GUID is for the ID of the typelib if this project is exposed to COM +[assembly: Guid("FF8AFA55-12FE-4856-A0A1-21344D366E12")] + +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +// You can specify all the values or you can default the Build and Revision Numbers +// by using the '*' as shown below: +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] \ No newline at end of file diff --git a/Verax_API_EF/TestsUnitaires/Tests.cs b/Verax_API_EF/TestsUnitaires/Tests.cs new file mode 100644 index 0000000..f0b4fcb --- /dev/null +++ b/Verax_API_EF/TestsUnitaires/Tests.cs @@ -0,0 +1,14 @@ +using System; +using Xunit; + +namespace TestsUnitaires +{ + public class Tests + { + [Fact] + public void Test1() + { + Assert.True(true); + } + } +} \ No newline at end of file diff --git a/Verax_API_EF/TestsUnitaires/TestsUnitaires.csproj b/Verax_API_EF/TestsUnitaires/TestsUnitaires.csproj new file mode 100644 index 0000000..6242cf4 --- /dev/null +++ b/Verax_API_EF/TestsUnitaires/TestsUnitaires.csproj @@ -0,0 +1,66 @@ + + + + + Debug + AnyCPU + {FF8AFA55-12FE-4856-A0A1-21344D366E12} + {FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} + Library + Properties + TestsUnitaires + TestsUnitaires + v4.8 + 512 + + + AnyCPU + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + AnyCPU + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + + + + + ..\packages\xunit.abstractions.2.0.0\lib\net35\xunit.abstractions.dll + + + ..\packages\xunit.assert.2.1.0\lib\dotnet\xunit.assert.dll + + + ..\packages\xunit.extensibility.core.2.1.0\lib\dotnet\xunit.core.dll + + + ..\packages\xunit.extensibility.execution.2.1.0\lib\net45\xunit.execution.desktop.dll + + + + + + + + + diff --git a/Verax_API_EF/TestsUnitaires/packages.config b/Verax_API_EF/TestsUnitaires/packages.config new file mode 100644 index 0000000..69a4ec4 --- /dev/null +++ b/Verax_API_EF/TestsUnitaires/packages.config @@ -0,0 +1,9 @@ + + + + + + + + + \ No newline at end of file diff --git a/Verax_API_EF/Verax_API_EF.sln b/Verax_API_EF/Verax_API_EF.sln new file mode 100644 index 0000000..c282d92 --- /dev/null +++ b/Verax_API_EF/Verax_API_EF.sln @@ -0,0 +1,70 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Test_Console_EF", "Test_Console_EF\Test_Console_EF.csproj", "{E27E2617-28A1-4675-B12B-89430582C05E}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Entities", "Entities\Entities.csproj", "{40BD34D7-3F07-410A-BC04-2A5B09E758C0}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DbContextLib", "DbContextLib\DbContextLib.csproj", "{F94BEE1F-302F-4654-8D85-AD41E0BACD03}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "StubbedContextLib", "StubbedContextLib\StubbedContextLib.csproj", "{F1B4BCE5-8DE7-4EFB-8BC1-D7E04EA75302}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Web_API", "Web_API\Web_API.csproj", "{852E0658-1A97-482A-84F3-0EF08E34D7B1}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "API_DbDataManager", "API_DbDataManager\API_DbDataManager.csproj", "{FBA0CF18-7488-4088-A7C5-5D2071D19CCB}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "API_Services", "API_Services\API_Services.csproj", "{4FB7D286-B583-44BC-BB79-4AE3058AFEDE}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "API_Model", "API_Model\API_Model.csproj", "{F09B566E-8D25-4D70-B9F0-99E6969D4D1F}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "API_Mapping", "API_Mapping\API_Mapping.csproj", "{BECFAD2C-E442-4300-8121-5AE6610B92DF}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Model", "Model\Model.csproj", "{96FDB5DE-6707-4856-94CD-EFAF0C7CEB4B}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {E27E2617-28A1-4675-B12B-89430582C05E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {E27E2617-28A1-4675-B12B-89430582C05E}.Debug|Any CPU.Build.0 = Debug|Any CPU + {E27E2617-28A1-4675-B12B-89430582C05E}.Release|Any CPU.ActiveCfg = Release|Any CPU + {E27E2617-28A1-4675-B12B-89430582C05E}.Release|Any CPU.Build.0 = Release|Any CPU + {40BD34D7-3F07-410A-BC04-2A5B09E758C0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {40BD34D7-3F07-410A-BC04-2A5B09E758C0}.Debug|Any CPU.Build.0 = Debug|Any CPU + {40BD34D7-3F07-410A-BC04-2A5B09E758C0}.Release|Any CPU.ActiveCfg = Release|Any CPU + {40BD34D7-3F07-410A-BC04-2A5B09E758C0}.Release|Any CPU.Build.0 = Release|Any CPU + {F94BEE1F-302F-4654-8D85-AD41E0BACD03}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {F94BEE1F-302F-4654-8D85-AD41E0BACD03}.Debug|Any CPU.Build.0 = Debug|Any CPU + {F94BEE1F-302F-4654-8D85-AD41E0BACD03}.Release|Any CPU.ActiveCfg = Release|Any CPU + {F94BEE1F-302F-4654-8D85-AD41E0BACD03}.Release|Any CPU.Build.0 = Release|Any CPU + {F1B4BCE5-8DE7-4EFB-8BC1-D7E04EA75302}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {F1B4BCE5-8DE7-4EFB-8BC1-D7E04EA75302}.Debug|Any CPU.Build.0 = Debug|Any CPU + {F1B4BCE5-8DE7-4EFB-8BC1-D7E04EA75302}.Release|Any CPU.ActiveCfg = Release|Any CPU + {F1B4BCE5-8DE7-4EFB-8BC1-D7E04EA75302}.Release|Any CPU.Build.0 = Release|Any CPU + {852E0658-1A97-482A-84F3-0EF08E34D7B1}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {852E0658-1A97-482A-84F3-0EF08E34D7B1}.Debug|Any CPU.Build.0 = Debug|Any CPU + {852E0658-1A97-482A-84F3-0EF08E34D7B1}.Release|Any CPU.ActiveCfg = Release|Any CPU + {852E0658-1A97-482A-84F3-0EF08E34D7B1}.Release|Any CPU.Build.0 = Release|Any CPU + {FBA0CF18-7488-4088-A7C5-5D2071D19CCB}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {FBA0CF18-7488-4088-A7C5-5D2071D19CCB}.Debug|Any CPU.Build.0 = Debug|Any CPU + {FBA0CF18-7488-4088-A7C5-5D2071D19CCB}.Release|Any CPU.ActiveCfg = Release|Any CPU + {FBA0CF18-7488-4088-A7C5-5D2071D19CCB}.Release|Any CPU.Build.0 = Release|Any CPU + {4FB7D286-B583-44BC-BB79-4AE3058AFEDE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {4FB7D286-B583-44BC-BB79-4AE3058AFEDE}.Debug|Any CPU.Build.0 = Debug|Any CPU + {4FB7D286-B583-44BC-BB79-4AE3058AFEDE}.Release|Any CPU.ActiveCfg = Release|Any CPU + {4FB7D286-B583-44BC-BB79-4AE3058AFEDE}.Release|Any CPU.Build.0 = Release|Any CPU + {F09B566E-8D25-4D70-B9F0-99E6969D4D1F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {F09B566E-8D25-4D70-B9F0-99E6969D4D1F}.Debug|Any CPU.Build.0 = Debug|Any CPU + {F09B566E-8D25-4D70-B9F0-99E6969D4D1F}.Release|Any CPU.ActiveCfg = Release|Any CPU + {F09B566E-8D25-4D70-B9F0-99E6969D4D1F}.Release|Any CPU.Build.0 = Release|Any CPU + {BECFAD2C-E442-4300-8121-5AE6610B92DF}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {BECFAD2C-E442-4300-8121-5AE6610B92DF}.Debug|Any CPU.Build.0 = Debug|Any CPU + {BECFAD2C-E442-4300-8121-5AE6610B92DF}.Release|Any CPU.ActiveCfg = Release|Any CPU + {BECFAD2C-E442-4300-8121-5AE6610B92DF}.Release|Any CPU.Build.0 = Release|Any CPU + {96FDB5DE-6707-4856-94CD-EFAF0C7CEB4B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {96FDB5DE-6707-4856-94CD-EFAF0C7CEB4B}.Debug|Any CPU.Build.0 = Debug|Any CPU + {96FDB5DE-6707-4856-94CD-EFAF0C7CEB4B}.Release|Any CPU.ActiveCfg = Release|Any CPU + {96FDB5DE-6707-4856-94CD-EFAF0C7CEB4B}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection +EndGlobal diff --git a/Verax_API_EF/Verax_API_EF/Program.cs b/Verax_API_EF/Verax_API_EF/Program.cs new file mode 100644 index 0000000..c4035ea --- /dev/null +++ b/Verax_API_EF/Verax_API_EF/Program.cs @@ -0,0 +1,3 @@ + // See https://aka.ms/new-console-template for more information + +Console.WriteLine("Hello, World!"); \ No newline at end of file diff --git a/Verax_API_EF/Verax_API_EF/Verax_API_EF.csproj b/Verax_API_EF/Verax_API_EF/Verax_API_EF.csproj new file mode 100644 index 0000000..6f2eba9 --- /dev/null +++ b/Verax_API_EF/Verax_API_EF/Verax_API_EF.csproj @@ -0,0 +1,20 @@ + + + + Exe + net8.0 + enable + enable + + + + + + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + + + diff --git a/Verax_API_EF/Web_API/Controllers/ArticleController.cs b/Verax_API_EF/Web_API/Controllers/ArticleController.cs new file mode 100644 index 0000000..39f9429 --- /dev/null +++ b/Verax_API_EF/Web_API/Controllers/ArticleController.cs @@ -0,0 +1,68 @@ +using Microsoft.AspNetCore.Http; +using Microsoft.AspNetCore.Mvc; +using Web_API.Model; +using API_Services; + +namespace Web_API.Controllers +{ + [Route("api/[controller]")] + [ApiController] + public class ArticleController : ControllerBase + { + private readonly IArticleService _as; + private Mapper.Mapper map = new Mapper.Mapper(); + + public ArticleController(IArticleService articleService) + { + this._as = articleService; + } + + [HttpGet("Articles")] + + public async Task GetAllArticle() + { + return Ok(await _as.GetAllArticles()); + + } + + [HttpGet("{id}")] + public async Task GetArticle(int id) + { + var article = await _as.GetById(id); + if (article == null) + { + return NotFound(); + } + return Ok(article); + } + + [HttpPost] + public async Task> PostArticle(ArticleDTO article) + { + var newArticle = await _as.Create(article); + if (newArticle == null) return BadRequest(); + var newArticleEnt = map.ArtDTOToEntity(article); + return CreatedAtAction(nameof(GetArticle), new { id = newArticle.Id}, newArticleEnt); + } + + [HttpPut("{id}")] + public async Task> PutArticle(long id , [FromBody]ArticleDTO article) + { + var check = await _as.Update(id,article); + if (!check) return NotFound(); + var articleEnt = map.ArtDTOToEntity(article); + return articleEnt; + } + + [HttpDelete("{id}")] + public async Task> DeleteArticle(long id) + { + var articleDeleted = await _as.Delete(id); + if (articleDeleted == null)return NotFound(); + articleDeleted = map.ArtEntityToDTO(articleDeleted); + return Ok(articleDeleted); + + } + + } +} diff --git a/Verax_API_EF/Web_API/Controllers/FormulaireController.cs b/Verax_API_EF/Web_API/Controllers/FormulaireController.cs new file mode 100644 index 0000000..841e0c3 --- /dev/null +++ b/Verax_API_EF/Web_API/Controllers/FormulaireController.cs @@ -0,0 +1,27 @@ +using Microsoft.AspNetCore.Mvc; +using Web_API.Model; +using API_Services; + +namespace Web_API.Controllers +{ + [Route("api/[controller]")] + [ApiController] + public class FormulaireController : ControllerBase + { + private readonly IFormulaireService _form; + private Mapper.Mapper map = new Mapper.Mapper(); + + public FormulaireController(IFormulaireService iform) + { + this._form = iform; + } + + [HttpGet] + public async Task> GetAllForm() + { + var AllForms = await _form.GetAllForm(); + return AllForms; + } + + } +} diff --git a/Verax_API_EF/Web_API/Controllers/UserController.cs b/Verax_API_EF/Web_API/Controllers/UserController.cs new file mode 100644 index 0000000..620c960 --- /dev/null +++ b/Verax_API_EF/Web_API/Controllers/UserController.cs @@ -0,0 +1,76 @@ +using Microsoft.AspNetCore.Http; +using Microsoft.AspNetCore.Mvc; +using Web_API.Model; +using API_Services; + + +namespace Web_API.Controllers +{ + [Route("api/[controller]")] + [ApiController] + public class UserController : ControllerBase + { + private readonly ILogger? logger; + + private readonly IUserService _us; + + public UserController(IUserService us) + { + this._us = us; + } + + [HttpGet] + public async Task GetAll() + { + return Ok(await _us.GetAll()); + + } + + // GET : users/id + [HttpGet("{pseudo}", Name = "GetUserByPseudo")] + public async Task GetUser(string pseudo) + { + var user = _us.GetByPseudo(pseudo); + if (user == null) + { + return NotFound(); + } + return Ok(user); + } + + [HttpPost] + public async Task> PostUser(User user) + { + var check = await _us.Create(user); + if (!check) + { + return BadRequest(); + } + return CreatedAtAction(nameof(GetUser), new { Pseudo = user.Pseudo}, user); + } + + [HttpDelete] + public async Task DeleteUser(string pseudo) + { + var check = await _us.Delete(pseudo); + if (!check) + { + return NotFound(); + } + return Ok(pseudo); + } + + [HttpPut] + + public async Task UpdateUser(User user) + { + var check = await _us.Update(user); + if (!check) + { + return NotFound(); + } + return Ok(user); + } + + } +} diff --git a/Verax_API_EF/Web_API/Mapper/Mapper.cs b/Verax_API_EF/Web_API/Mapper/Mapper.cs new file mode 100644 index 0000000..ef89862 --- /dev/null +++ b/Verax_API_EF/Web_API/Mapper/Mapper.cs @@ -0,0 +1,82 @@ +using Entities; +using Web_API.Model; + +namespace Web_API.Mapper; + +public class Mapper +{ + public ArticleDTO ArtEntityToDTO(ArticleEntity a) + { + return new ArticleDTO + { + Id = a.Id, + Author = a.Author, + Title = a.Title, + Description = a.Description, + LectureTime = a.LectureTime, + DatePublished = a.DatePublished + }; + } + + + public ArticleEntity ArtDTOToEntity(ArticleDTO a) + { + return new ArticleEntity() + { + Id = a.Id, + Author = a.Author, + Title = a.Title, + Description = a.Description, + LectureTime = a.LectureTime, + DatePublished = a.DatePublished + }; + } + + public FormulaireDTO FormEntityToDTO(FormEntity f) + { + return new FormulaireDTO + { + Theme = f.Theme, + Date = f.DatePublication, + Lien = f.Lien, + Pseudo = f.Pseudo + }; + } + + public Formulaire FormDTOToEntity(FormulaireDTO f) + { + return new Formulaire + { + Theme = f.Theme, + Date = f.Date, + Lien = f.Lien, + Pseudo = f.Pseudo + }; + } + + public UserDTO UserEntityToDTO(User u) + { + return new UserDTO + { + Pseudo = u.Pseudo, + Mail = u.Mail, + Prenom = u.Prenom, + Nom = u.Nom, + Role = u.Role, + Mdp = u.Mdp + }; + } + + public User UserDTOToEntity(UserDTO u) + { + return new User + { + Pseudo = u.Pseudo, + Mail = u.Mail, + Prenom = u.Prenom, + Nom = u.Nom, + Role = u.Role, + Mdp = u.Mdp + }; + } +} \ No newline at end of file diff --git a/Verax_API_EF/Web_API/Program.cs b/Verax_API_EF/Web_API/Program.cs new file mode 100644 index 0000000..161f695 --- /dev/null +++ b/Verax_API_EF/Web_API/Program.cs @@ -0,0 +1,44 @@ +var builder = WebApplication.CreateBuilder(args); + +// Add services to the container. +// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle +builder.Services.AddEndpointsApiExplorer(); +builder.Services.AddSwaggerGen(); + +var app = builder.Build(); + +// Configure the HTTP request pipeline. +if (app.Environment.IsDevelopment()) +{ + app.UseSwagger(); + app.UseSwaggerUI(); +} + +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") + .WithOpenApi(); + +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/Verax_API_EF/Web_API/Properties/launchSettings.json b/Verax_API_EF/Web_API/Properties/launchSettings.json new file mode 100644 index 0000000..37623b3 --- /dev/null +++ b/Verax_API_EF/Web_API/Properties/launchSettings.json @@ -0,0 +1,41 @@ +{ + "$schema": "http://json.schemastore.org/launchsettings.json", + "iisSettings": { + "windowsAuthentication": false, + "anonymousAuthentication": true, + "iisExpress": { + "applicationUrl": "http://localhost:48061", + "sslPort": 44331 + } + }, + "profiles": { + "http": { + "commandName": "Project", + "dotnetRunMessages": true, + "launchBrowser": true, + "launchUrl": "swagger", + "applicationUrl": "http://localhost:5139", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + } + }, + "https": { + "commandName": "Project", + "dotnetRunMessages": true, + "launchBrowser": true, + "launchUrl": "swagger", + "applicationUrl": "https://localhost:7143;http://localhost:5139", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + } + }, + "IIS Express": { + "commandName": "IISExpress", + "launchBrowser": true, + "launchUrl": "swagger", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + } + } + } +} diff --git a/Verax_API_EF/Web_API/Web_API.csproj b/Verax_API_EF/Web_API/Web_API.csproj new file mode 100644 index 0000000..6441ade --- /dev/null +++ b/Verax_API_EF/Web_API/Web_API.csproj @@ -0,0 +1,21 @@ + + + + net8.0 + enable + enable + + + + + + + + + + + + + + + diff --git a/Verax_API_EF/Web_API/Web_API.http b/Verax_API_EF/Web_API/Web_API.http new file mode 100644 index 0000000..6015298 --- /dev/null +++ b/Verax_API_EF/Web_API/Web_API.http @@ -0,0 +1,6 @@ +@Web_API_HostAddress = http://localhost:5139 + +GET {{Web_API_HostAddress}}/weatherforecast/ +Accept: application/json + +### diff --git a/Verax_API_EF/Web_API/appsettings.Development.json b/Verax_API_EF/Web_API/appsettings.Development.json new file mode 100644 index 0000000..0c208ae --- /dev/null +++ b/Verax_API_EF/Web_API/appsettings.Development.json @@ -0,0 +1,8 @@ +{ + "Logging": { + "LogLevel": { + "Default": "Information", + "Microsoft.AspNetCore": "Warning" + } + } +} diff --git a/Verax_API_EF/Web_API/appsettings.json b/Verax_API_EF/Web_API/appsettings.json new file mode 100644 index 0000000..10f68b8 --- /dev/null +++ b/Verax_API_EF/Web_API/appsettings.json @@ -0,0 +1,9 @@ +{ + "Logging": { + "LogLevel": { + "Default": "Information", + "Microsoft.AspNetCore": "Warning" + } + }, + "AllowedHosts": "*" +}