diff --git a/Verax_API_EF/Verax_API_EF/API/Controllers/ArticleController.cs b/Verax_API_EF/Verax_API_EF/API/Controllers/ArticleController.cs index b5b096c..a7aae26 100644 --- a/Verax_API_EF/Verax_API_EF/API/Controllers/ArticleController.cs +++ b/Verax_API_EF/Verax_API_EF/API/Controllers/ArticleController.cs @@ -43,9 +43,9 @@ namespace API.Controllers [HttpPost("/article")] - public async Task CreateArticle(long id, string title, string description, string author, string date, int lectureTime) + public async Task CreateArticle(Article article) { - return await _articleService.CreateArticle(id, title, description, author, date, lectureTime); + return await _articleService.CreateArticle(article); } [HttpDelete("/article/{id}")] diff --git a/Verax_API_EF/Verax_API_EF/API/Entity_FrameWork.Article.db b/Verax_API_EF/Verax_API_EF/API/Entity_FrameWork.Article.db index d1afbee..9a47220 100644 Binary files a/Verax_API_EF/Verax_API_EF/API/Entity_FrameWork.Article.db and b/Verax_API_EF/Verax_API_EF/API/Entity_FrameWork.Article.db differ diff --git a/Verax_API_EF/Verax_API_EF/Test_Console_EF/Entity_FrameWork.Article.db-shm b/Verax_API_EF/Verax_API_EF/API/Entity_FrameWork.Article.db-shm similarity index 97% rename from Verax_API_EF/Verax_API_EF/Test_Console_EF/Entity_FrameWork.Article.db-shm rename to Verax_API_EF/Verax_API_EF/API/Entity_FrameWork.Article.db-shm index edfc9f0..6776387 100644 Binary files a/Verax_API_EF/Verax_API_EF/Test_Console_EF/Entity_FrameWork.Article.db-shm and b/Verax_API_EF/Verax_API_EF/API/Entity_FrameWork.Article.db-shm differ diff --git a/Verax_API_EF/Verax_API_EF/API/Entity_FrameWork.Article.db-wal b/Verax_API_EF/Verax_API_EF/API/Entity_FrameWork.Article.db-wal new file mode 100644 index 0000000..be3745a Binary files /dev/null and b/Verax_API_EF/Verax_API_EF/API/Entity_FrameWork.Article.db-wal differ diff --git a/Verax_API_EF/Verax_API_EF/API_DbDataManager/DbManagerArticle.cs b/Verax_API_EF/Verax_API_EF/API_DbDataManager/DbManagerArticle.cs index b37ea0f..0c425de 100644 --- a/Verax_API_EF/Verax_API_EF/API_DbDataManager/DbManagerArticle.cs +++ b/Verax_API_EF/Verax_API_EF/API_DbDataManager/DbManagerArticle.cs @@ -76,16 +76,15 @@ public class DbManagerArticle : IArticleService } - public async Task CreateArticle(long id, string title, string description, string author, string date, int lectureTime) + public async Task CreateArticle(Article article) { var entity = new Entities.ArticleEntity() { - Id = id, - Title = title, - Description = description, - Author = author, - DatePublished = date, - LectureTime = lectureTime, + Title = article.Title, + Description = article.Description, + Author = article.Author, + DatePublished = article.DatePublished, + LectureTime = article.LectureTime, }; _context.ArticleSet.Add(entity); await _context.SaveChangesAsync(); diff --git a/Verax_API_EF/Verax_API_EF/API_DbDataManager/DbManagerFormulaire.cs b/Verax_API_EF/Verax_API_EF/API_DbDataManager/DbManagerFormulaire.cs index 2f879cd..4cb5671 100644 --- a/Verax_API_EF/Verax_API_EF/API_DbDataManager/DbManagerFormulaire.cs +++ b/Verax_API_EF/Verax_API_EF/API_DbDataManager/DbManagerFormulaire.cs @@ -33,7 +33,7 @@ public class DbManagerFormulaire : IFormulaireService formulaireList = _context.FormSet.OrderBy(f => f.DatePublication).Select(f => f.ToModel()).ToList(); break; case FormOrderCriteria.ByPseudo: - formulaireList = _context.FormSet.OrderBy(f => f.Pseudo).Select(f => f.ToModel()).ToList(); + formulaireList = _context.FormSet.OrderBy(f => f.UserEntityPseudo).Select(f => f.ToModel()).ToList(); break; default: formulaireList = _context.FormSet.Select(f => f.ToModel()).ToList(); @@ -54,9 +54,10 @@ public class DbManagerFormulaire : IFormulaireService var entity = new FormEntity() { Id = formulaire.Id, - Pseudo = formulaire.Pseudo, + Link = formulaire.Lien, Theme = formulaire.Theme, - DatePublication = formulaire.Date + DatePublication = formulaire.Date, + UserEntityPseudo = formulaire.UserPseudo }; _context.FormSet.Add(entity); @@ -77,9 +78,10 @@ public class DbManagerFormulaire : IFormulaireService { var entity = _context.FormSet.FirstOrDefault(f => f.Id == id); if (entity == null) return false; - entity.Pseudo = formulaire.Pseudo; entity.Theme = formulaire.Theme; entity.DatePublication = formulaire.Date; + entity.Link = formulaire.Lien; + entity.UserEntityPseudo = formulaire.UserPseudo; await _context.SaveChangesAsync(); return true; } diff --git a/Verax_API_EF/Verax_API_EF/API_DbDataManager/Extensions.cs b/Verax_API_EF/Verax_API_EF/API_DbDataManager/Extensions.cs index 511f7da..d35d9b8 100644 --- a/Verax_API_EF/Verax_API_EF/API_DbDataManager/Extensions.cs +++ b/Verax_API_EF/Verax_API_EF/API_DbDataManager/Extensions.cs @@ -26,10 +26,10 @@ public static class Extensions => new User{ Pseudo = user.Pseudo, Mdp = user.Mdp, Prenom = user.Prenom, Nom = user.Nom, Mail = user.Mail, Role = user.Role}; public static FormEntity ToEntity(this Formulaire form) - => new FormEntity{ Id = form.Id, Pseudo = form.Pseudo, Theme = form.Theme, Link = form.Lien}; + => new FormEntity{ Id = form.Id, UserEntityPseudo = form.UserPseudo, Theme = form.Theme, Link = form.Lien}; public static Formulaire ToModel(this FormEntity form) - => new Formulaire{ Id = form.Id, Pseudo = form.Pseudo, Theme = form.Theme, Lien = form.Link}; + => new Formulaire{ Id = form.Id, UserPseudo = form.UserEntityPseudo, Theme = form.Theme, Lien = form.Link}; } \ No newline at end of file diff --git a/Verax_API_EF/Verax_API_EF/API_Mapping/FormulaireMapping.cs b/Verax_API_EF/Verax_API_EF/API_Mapping/FormulaireMapping.cs index eef95ef..8a0e631 100644 --- a/Verax_API_EF/Verax_API_EF/API_Mapping/FormulaireMapping.cs +++ b/Verax_API_EF/Verax_API_EF/API_Mapping/FormulaireMapping.cs @@ -11,7 +11,7 @@ public static class FormulaireMapping Theme = f.Theme, Date = f.Date, Lien = f.Lien, - Pseudo = f.Pseudo + UserPseudo = f.UserPseudo }; public static Formulaire ToModel(this FormulaireDTO f) => new() @@ -20,6 +20,6 @@ public static class FormulaireMapping Theme = f.Theme, Date = f.Date, Lien = f.Lien, - Pseudo = f.Pseudo + UserPseudo = f.UserPseudo }; } \ No newline at end of file diff --git a/Verax_API_EF/Verax_API_EF/API_Model/FormulaireDTO.cs b/Verax_API_EF/Verax_API_EF/API_Model/FormulaireDTO.cs index df256d4..67b5e38 100644 --- a/Verax_API_EF/Verax_API_EF/API_Model/FormulaireDTO.cs +++ b/Verax_API_EF/Verax_API_EF/API_Model/FormulaireDTO.cs @@ -6,7 +6,7 @@ public class FormulaireDTO public string Theme { get; set; } public string Date { get; set; } public string Lien { get; set; } - public string Pseudo { get; set; } + public string UserPseudo { get; set; } } \ No newline at end of file diff --git a/Verax_API_EF/Verax_API_EF/API_Services/IArticleService.cs b/Verax_API_EF/Verax_API_EF/API_Services/IArticleService.cs index 28a2851..c10505b 100644 --- a/Verax_API_EF/Verax_API_EF/API_Services/IArticleService.cs +++ b/Verax_API_EF/Verax_API_EF/API_Services/IArticleService.cs @@ -10,8 +10,7 @@ namespace API_Services Task GetArticleById(int id, int index, int count, ArticleOrderCriteria orderCriterium); - Task CreateArticle(long id, string title, string description, string author, string date, - int lectureTime); + Task CreateArticle(Article article); Task DeleteArticle(long id); diff --git a/Verax_API_EF/Verax_API_EF/DbContextLib/LibraryContext.cs b/Verax_API_EF/Verax_API_EF/DbContextLib/LibraryContext.cs index 774ded2..08e8dba 100644 --- a/Verax_API_EF/Verax_API_EF/DbContextLib/LibraryContext.cs +++ b/Verax_API_EF/Verax_API_EF/DbContextLib/LibraryContext.cs @@ -41,12 +41,12 @@ public class LibraryContext : DbContext modelBuilder.Entity() .HasMany(u => u.Forms) .WithOne(f => f.User) - .HasForeignKey(f => f.UserEntityId); + .HasForeignKey(f => f.UserEntityPseudo); modelBuilder.Entity() .HasOne(f => f.User) .WithMany(u => u.Forms) - .HasForeignKey(f => f.UserEntityId); + .HasForeignKey(f => f.UserEntityPseudo); modelBuilder.Entity().HasData( new ArticleEntity @@ -83,24 +83,24 @@ public class LibraryContext : DbContext modelBuilder.Entity().HasData( new UserEntity { - Id = 1, Nom = "Fages", Prenom = "Tony", Pseudo = "TonyF", Mail = "tony@gmail.com", Mdp = "1234", Role = "Admin" + 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", + 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" + Nom = "M&M's", Prenom = "Red", Pseudo = "RedM", Mail = "M&M#mail.com", Mdp = "1234", Role = "Modérator" }, new UserEntity { - Id = 4, Nom = "Cascarra", Prenom = "Cascarra", Pseudo = "Sha", Mail = "ShaCasca@gmail.com", Mdp = "1234", Role = "Admin" + Nom = "Cascarra", Prenom = "Cascarra", Pseudo = "Sha", Mail = "ShaCasca@gmail.com", Mdp = "1234", Role = "Admin" }, new UserEntity { - Id = 5, Nom = "Sillard", Prenom = "Noa", Pseudo = "NoaSil", Mail = "", Mdp = "1234", Role = "Admin" + Nom = "Sillard", Prenom = "Noa", Pseudo = "NoaSil", Mail = "", Mdp = "1234", Role = "Admin" } ); @@ -108,27 +108,27 @@ public class LibraryContext : DbContext new ArticleUserEntity { ArticleEntityId = 1, - UserEntityId = 1 + UserEntityPseudo = "TonyF" }, new ArticleUserEntity { ArticleEntityId = 2, - UserEntityId = 2 + UserEntityPseudo = "NoaSil" }, new ArticleUserEntity { ArticleEntityId = 3, - UserEntityId = 3 + UserEntityPseudo = "Sha" }, new ArticleUserEntity { ArticleEntityId = 3, - UserEntityId = 1 + UserEntityPseudo = "RedM" }, new ArticleUserEntity { ArticleEntityId = 2, - UserEntityId = 3 + UserEntityPseudo = "TomS" } ); @@ -136,26 +136,23 @@ public class LibraryContext : DbContext new FormEntity { Id = 1, - Pseudo= "Form 1", DatePublication = "Form 1 Description", Link = "hhtp://form1.com", - UserEntityId = 1 + UserEntityPseudo = "Sha" }, new FormEntity { Id = 2, - Pseudo= "Form 2", DatePublication = "Form 2 Description", Link = "hhtp://form2.com", - UserEntityId = 2 + UserEntityPseudo = "Sha" }, new FormEntity { Id = 3, - Pseudo= "Form 3", DatePublication = "Form 3 Description", Link = "hhtp://form3.com", - UserEntityId = 3 + UserEntityPseudo = "Sha" } ); } diff --git a/Verax_API_EF/Verax_API_EF/Entities/ArticleUserEntity.cs b/Verax_API_EF/Verax_API_EF/Entities/ArticleUserEntity.cs index 2faf6b7..74bb542 100644 --- a/Verax_API_EF/Verax_API_EF/Entities/ArticleUserEntity.cs +++ b/Verax_API_EF/Verax_API_EF/Entities/ArticleUserEntity.cs @@ -2,6 +2,6 @@ namespace Entities; public class ArticleUserEntity { - public long UserEntityId { get; set; } + public string UserEntityPseudo { get; set; } public long ArticleEntityId { get; set; } } \ No newline at end of file diff --git a/Verax_API_EF/Verax_API_EF/Entities/FormEntity.cs b/Verax_API_EF/Verax_API_EF/Entities/FormEntity.cs index 75b43e0..8a45973 100644 --- a/Verax_API_EF/Verax_API_EF/Entities/FormEntity.cs +++ b/Verax_API_EF/Verax_API_EF/Entities/FormEntity.cs @@ -6,11 +6,8 @@ public class FormEntity 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; - + public string UserEntityPseudo{ get; set; } + public UserEntity User { get; set; } = null!; } \ No newline at end of file diff --git a/Verax_API_EF/Verax_API_EF/Entities/UserEntity.cs b/Verax_API_EF/Verax_API_EF/Entities/UserEntity.cs index 7d8680a..d7604c0 100644 --- a/Verax_API_EF/Verax_API_EF/Entities/UserEntity.cs +++ b/Verax_API_EF/Verax_API_EF/Entities/UserEntity.cs @@ -1,8 +1,10 @@ +using System.ComponentModel.DataAnnotations; + namespace Entities; public class UserEntity { - public long Id { get; set; } + [Key] public string Pseudo { get; set; } = string.Empty; public string Mdp { get; set; } = string.Empty; diff --git a/Verax_API_EF/Verax_API_EF/Model/Formulaire.cs b/Verax_API_EF/Verax_API_EF/Model/Formulaire.cs index 9b883fb..6dee834 100644 --- a/Verax_API_EF/Verax_API_EF/Model/Formulaire.cs +++ b/Verax_API_EF/Verax_API_EF/Model/Formulaire.cs @@ -6,5 +6,5 @@ public class Formulaire public string Theme { get; set; } public string Date { get; set; } public string Lien { get; set; } - public string Pseudo { get; set; } + public string UserPseudo { get; set; } } \ No newline at end of file diff --git a/Verax_API_EF/Verax_API_EF/StubbedContextLib/Class1.cs b/Verax_API_EF/Verax_API_EF/StubbedContextLib/Class1.cs index b922036..6ef8d5f 100644 --- a/Verax_API_EF/Verax_API_EF/StubbedContextLib/Class1.cs +++ b/Verax_API_EF/Verax_API_EF/StubbedContextLib/Class1.cs @@ -45,16 +45,16 @@ public class StubbedContext : LibraryContext modelBuilder.Entity().HasData( new UserEntity { - Id = 1, Nom = "Fages", Prenom = "Tony", Pseudo = "TonyF", Mail = "tony@gmail.com", Mdp = "1234", Role = "Admin" + 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", + 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" + Nom = "M&M's", Prenom = "Red", Pseudo = "RedM", Mail = "M&M#mail.com", Mdp = "1234", Role = "Modérator" } ); @@ -62,27 +62,27 @@ public class StubbedContext : LibraryContext new ArticleUserEntity { ArticleEntityId = 1, - UserEntityId = 1 + UserEntityPseudo = "Sha" }, new ArticleUserEntity { ArticleEntityId = 2, - UserEntityId = 2 + UserEntityPseudo = "Sha" }, new ArticleUserEntity { ArticleEntityId = 3, - UserEntityId = 3 + UserEntityPseudo = "Sha" }, new ArticleUserEntity { ArticleEntityId = 3, - UserEntityId = 1 + UserEntityPseudo = "Sha" }, new ArticleUserEntity { ArticleEntityId = 2, - UserEntityId = 3 + UserEntityPseudo = "Sha" } ); } diff --git a/Verax_API_EF/Verax_API_EF/Test_Console_EF/Entity_FrameWork.Article.db b/Verax_API_EF/Verax_API_EF/Test_Console_EF/Entity_FrameWork.Article.db index 16746d5..730f5f3 100644 Binary files a/Verax_API_EF/Verax_API_EF/Test_Console_EF/Entity_FrameWork.Article.db and b/Verax_API_EF/Verax_API_EF/Test_Console_EF/Entity_FrameWork.Article.db differ diff --git a/Verax_API_EF/Verax_API_EF/Test_Console_EF/Entity_FrameWork.Article.db-wal b/Verax_API_EF/Verax_API_EF/Test_Console_EF/Entity_FrameWork.Article.db-wal deleted file mode 100644 index e170424..0000000 Binary files a/Verax_API_EF/Verax_API_EF/Test_Console_EF/Entity_FrameWork.Article.db-wal and /dev/null differ diff --git a/Verax_API_EF/Verax_API_EF/Test_Console_EF/Test_Console_Article.cs b/Verax_API_EF/Verax_API_EF/Test_Console_EF/Test_Console_Article.cs index ae275db..df969d9 100644 --- a/Verax_API_EF/Verax_API_EF/Test_Console_EF/Test_Console_Article.cs +++ b/Verax_API_EF/Verax_API_EF/Test_Console_EF/Test_Console_Article.cs @@ -117,7 +117,7 @@ void listForms() var forms = context.FormSet; foreach (var form in forms) { - Console.WriteLine($"{form.Id} - {form.Link} - {form.DatePublication} - {form.Pseudo} - {form.Theme} - {form.UserEntityId}"); + Console.WriteLine($"{form.Id} - {form.Link} - {form.DatePublication} - {form.Theme} - {form.UserEntityPseudo}"); } } } @@ -132,8 +132,7 @@ void addForm() Theme = "Covid", DatePublication = "16-02-2024", Link = "https://www.covid.com", - Pseudo = "Tony Fages", - UserEntityId = 1 + UserEntityPseudo = "Sha" }; context.FormSet.Add(form); context.SaveChanges(); @@ -175,7 +174,7 @@ void listUser() var users = context.UserSet; foreach (var user in users) { - Console.WriteLine($"{user.Id} - {user.Pseudo} - {user.Nom} - {user.Prenom} - {user.Mail} - {user.Role}"); + Console.WriteLine($" {user.Pseudo} - {user.Nom} - {user.Prenom} - {user.Mail} - {user.Role}"); } } } @@ -186,7 +185,7 @@ void addUser() { var user = new UserEntity { - Id = 7, Nom = "Fages", Prenom = "Tony", Pseudo = "TonyF", Mail = "tony@gmail.com", Mdp = "1234", Role = "Admin" + Nom = "Fages", Prenom = "Tony", Pseudo = "TonyF", Mail = "tony@gmail.com", Mdp = "1234", Role = "Admin" }; context.UserSet.Add(user); context.SaveChanges(); @@ -198,7 +197,7 @@ void updateUser() { using (var context = new LibraryContext()) { - var user = context.UserSet.Where(u => u.Id.Equals(7)); + var user = context.UserSet.Where(u => u.Pseudo.Equals("Sha")); foreach (var users in user) { @@ -213,7 +212,7 @@ void deleteUser() { using (var context = new LibraryContext()) { - var user = context.UserSet.Where(u => u.Id.Equals(7)); + var user = context.UserSet.Where(u => u.Pseudo.Equals("Sha")); foreach (var users in user) { @@ -231,7 +230,7 @@ void listArticleUser() var articleUsers = context.ArticleUserSet; foreach (var articleUser in articleUsers) { - Console.WriteLine($"{articleUser.ArticleEntityId} - {articleUser.UserEntityId}"); + Console.WriteLine($"{articleUser.ArticleEntityId} - {articleUser.UserEntityPseudo}"); } } } @@ -243,7 +242,7 @@ void addArticleUser() var articleUser = new ArticleUserEntity { ArticleEntityId = 2, - UserEntityId = 1 + UserEntityPseudo = "Sha" }; context.ArticleUserSet.Add(articleUser); context.SaveChanges(); @@ -255,8 +254,8 @@ void updateArticleUser() { using (var context = new LibraryContext()) { - var articleUser = context.ArticleUserSet.FirstOrDefault(au => au.UserEntityId.Equals(2)); - if (articleUser != null) articleUser.UserEntityId = 3; + var articleUser = context.ArticleUserSet.FirstOrDefault(au => au.UserEntityPseudo.Equals("Sha")); + if (articleUser != null) articleUser.UserEntityPseudo = "Sha"; context.SaveChanges(); } listArticleUser(); @@ -266,7 +265,7 @@ void deleteArticleUser() { using (var context = new LibraryContext()) { - var articleUser = context.ArticleUserSet.Where(au => au.UserEntityId.Equals(1)).Where(u => u.ArticleEntityId.Equals(1)); + var articleUser = context.ArticleUserSet.Where(au => au.UserEntityPseudo.Equals(1)).Where(u => u.ArticleEntityId.Equals(1)); foreach (var articleUsers in articleUser) { @@ -281,10 +280,10 @@ void listFormUser() { using (var context = new LibraryContext()) { - var formUsers = context.FormSet; + var formUsers = context.FormSet.Where(u => u.UserEntityPseudo.Equals(1)); foreach (var formUser in formUsers) { - Console.WriteLine($"{formUser.UserEntityId}"); + Console.WriteLine($"{formUser.UserEntityPseudo} - {formUser.Theme} - {formUser.Link}"); } } } @@ -295,7 +294,7 @@ void addFormUser() { var formUser = new FormEntity { - UserEntityId = 1 + UserEntityPseudo = "Sha", }; context.FormSet.Add(formUser); context.SaveChanges();