diff --git a/Verax_API_EF/Verax_API_EF/API/Controllers/ArticleUserController.cs b/Verax_API_EF/Verax_API_EF/API/Controllers/ArticleUserController.cs index d8baa78..e02ba64 100644 --- a/Verax_API_EF/Verax_API_EF/API/Controllers/ArticleUserController.cs +++ b/Verax_API_EF/Verax_API_EF/API/Controllers/ArticleUserController.cs @@ -1,3 +1,4 @@ +using API_Mapping; using API_Services; using Entities; using Microsoft.AspNetCore.Mvc; @@ -24,7 +25,7 @@ public class ArticleUserController : ControllerBase _logger.LogInformation("Executing {Action} - with parameters: {Parameters}",nameof(GetAllArticleUsers), ""); try { - var result = await _us.GetAllArticleUsers(); + var result = (await _us.GetAllArticleUsers()).Select(u => u.ToDTO()); if (result == null) { return NoContent(); 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 9a47220..3cd9f2f 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/API/Entity_FrameWork.Article.db-shm b/Verax_API_EF/Verax_API_EF/API/Entity_FrameWork.Article.db-shm deleted file mode 100644 index 6776387..0000000 Binary files a/Verax_API_EF/Verax_API_EF/API/Entity_FrameWork.Article.db-shm and /dev/null 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 deleted file mode 100644 index 99a315d..0000000 Binary files a/Verax_API_EF/Verax_API_EF/API/Entity_FrameWork.Article.db-wal and /dev/null differ diff --git a/Verax_API_EF/Verax_API_EF/API/Program.cs b/Verax_API_EF/Verax_API_EF/API/Program.cs index b1ae889..f57c6e0 100644 --- a/Verax_API_EF/Verax_API_EF/API/Program.cs +++ b/Verax_API_EF/Verax_API_EF/API/Program.cs @@ -39,8 +39,8 @@ app.MapControllers(); using var scoped = app.Services.CreateScope(); var libraryContext = scoped.ServiceProvider.GetService(); -libraryContext.Database.EnsureCreated(); -//libraryContext.Database.Migrate(); +//libraryContext.Database.EnsureCreated(); +libraryContext.Database.Migrate(); app.Run(); diff --git a/Verax_API_EF/Verax_API_EF/API/log.txt b/Verax_API_EF/Verax_API_EF/API/log.txt new file mode 100644 index 0000000..e69de29 diff --git a/Verax_API_EF/Verax_API_EF/API_DbDataManager/DbManagerArticleUser.cs b/Verax_API_EF/Verax_API_EF/API_DbDataManager/DbManagerArticleUser.cs index cad3888..d923855 100644 --- a/Verax_API_EF/Verax_API_EF/API_DbDataManager/DbManagerArticleUser.cs +++ b/Verax_API_EF/Verax_API_EF/API_DbDataManager/DbManagerArticleUser.cs @@ -1,6 +1,7 @@ using API_Services; using DbContextLib; using Entities; +using Microsoft.Extensions.Logging; using Model; namespace DbDataManager; @@ -14,11 +15,17 @@ public class DbManagerArticleUser : IArticleUserService _context = context; } - public async Task> GetAllArticleUsers() + public async Task> GetAllArticleUsers() { var entities = _context.ArticleUserSet.ToList(); - if (entities == null) return await Task.FromResult>(null); - return await Task.FromResult(entities.AsEnumerable()); + List users = new List(); + foreach( var articleUser in entities) + { + var user = _context.UserSet.FirstOrDefault(u => u.Pseudo.Equals(articleUser.UserEntityPseudo)); + if (user != null) users.Add(user); + } + if (users == null) return await Task.FromResult>(null); + return await Task.FromResult(users.Select(u => u.ToModel()).AsEnumerable()); } public async Task GetArticleUser(string pseudo) diff --git a/Verax_API_EF/Verax_API_EF/API_Services/IArticleUserService.cs b/Verax_API_EF/Verax_API_EF/API_Services/IArticleUserService.cs index 3a07594..1d4118f 100644 --- a/Verax_API_EF/Verax_API_EF/API_Services/IArticleUserService.cs +++ b/Verax_API_EF/Verax_API_EF/API_Services/IArticleUserService.cs @@ -1,10 +1,11 @@ using Entities; +using Model; namespace API_Services; public interface IArticleUserService { - Task> GetAllArticleUsers(); + Task> GetAllArticleUsers(); Task GetArticleUser(string pseudo); Task CreateArticleUser(ArticleUserEntity articleUser); diff --git a/Verax_API_EF/Verax_API_EF/DbContextLib/Class1.cs b/Verax_API_EF/Verax_API_EF/DbContextLib/Class1.cs new file mode 100644 index 0000000..6ef8d5f --- /dev/null +++ b/Verax_API_EF/Verax_API_EF/DbContextLib/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 + { + Nom = "Fages", Prenom = "Tony", Pseudo = "TonyF", Mail = "tony@gmail.com", Mdp = "1234", Role = "Admin" + }, + new UserEntity + { + Nom = "Smith", Prenom = "Tom", Pseudo = "TomS", Mail = "tom@mail.com", Mdp = "1234", + Role = "User" + }, + new UserEntity + { + 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, + UserEntityPseudo = "Sha" + }, + new ArticleUserEntity + { + ArticleEntityId = 2, + UserEntityPseudo = "Sha" + }, + new ArticleUserEntity + { + ArticleEntityId = 3, + UserEntityPseudo = "Sha" + }, + new ArticleUserEntity + { + ArticleEntityId = 3, + UserEntityPseudo = "Sha" + }, + new ArticleUserEntity + { + ArticleEntityId = 2, + UserEntityPseudo = "Sha" + } + ); + } +} \ No newline at end of file diff --git a/Verax_API_EF/Verax_API_EF/DbContextLib/LibraryContext.cs b/Verax_API_EF/Verax_API_EF/DbContextLib/LibraryContext.cs index 08e8dba..8923007 100644 --- a/Verax_API_EF/Verax_API_EF/DbContextLib/LibraryContext.cs +++ b/Verax_API_EF/Verax_API_EF/DbContextLib/LibraryContext.cs @@ -1,10 +1,13 @@ using Entities; using Microsoft.EntityFrameworkCore; +using Microsoft.Extensions.Logging; namespace DbContextLib; public class LibraryContext : DbContext { + + private static readonly StreamWriter LogFile = new StreamWriter("log.txt"); public LibraryContext() : base() { } @@ -23,6 +26,7 @@ public class LibraryContext : DbContext protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) { + optionsBuilder.LogTo( l => LogFile.WriteLine(l), LogLevel.Error).EnableDetailedErrors().EnableDetailedErrors(); if (!optionsBuilder.IsConfigured) { optionsBuilder.UseSqlite($"Data Source=Entity_FrameWork.Article.db"); @@ -48,6 +52,7 @@ public class LibraryContext : DbContext .WithMany(u => u.Forms) .HasForeignKey(f => f.UserEntityPseudo); + /* modelBuilder.Entity().HasData( new ArticleEntity { @@ -155,5 +160,6 @@ public class LibraryContext : DbContext UserEntityPseudo = "Sha" } ); + */ } } \ No newline at end of file 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 deleted file mode 100644 index 730f5f3..0000000 Binary files a/Verax_API_EF/Verax_API_EF/Test_Console_EF/Entity_FrameWork.Article.db and /dev/null differ diff --git a/Verax_API_EF/Verax_API_EF/TestsUnitaires/TestsArticleEntity.cs b/Verax_API_EF/Verax_API_EF/TestsUnitaires/TestsArticleEntity.cs index fce41a3..01cfb24 100644 --- a/Verax_API_EF/Verax_API_EF/TestsUnitaires/TestsArticleEntity.cs +++ b/Verax_API_EF/Verax_API_EF/TestsUnitaires/TestsArticleEntity.cs @@ -21,13 +21,13 @@ public class ArticleDB_Tests using (var context = new LibraryContext(options)) { context.Database.EnsureCreated(); - ArticleEntity a1 = 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" }; - ArticleEntity a2 = 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" }; - ArticleEntity a3 = 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" }; + ArticleEntity a1 = new ArticleEntity { 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" }; + ArticleEntity a2 = new ArticleEntity { 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" }; + ArticleEntity a3 = new ArticleEntity { 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" }; - context.Add(a1); - context.Add(a2); - context.Add(a3); + context.ArticleSet.Add(a1); + context.ArticleSet.Add(a2); + context.ArticleSet.Add(a3); context.SaveChanges(); @@ -52,9 +52,9 @@ public class ArticleDB_Tests ArticleEntity a1 = 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" }; ArticleEntity a2 = 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" }; ArticleEntity a3 = 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" }; - context.Add(a1); - context.Add(a2); - context.Add(a3); + context.ArticleSet.Add(a1); + context.ArticleSet.Add(a2); + context.ArticleSet.Add(a3); context.SaveChanges(); diff --git a/Verax_API_EF/Verax_API_EF/Verax_API_EF/.idea/.idea.Verax_API_EF.dir/.idea/.gitignore b/Verax_API_EF/Verax_API_EF/Verax_API_EF/.idea/.idea.Verax_API_EF.dir/.idea/.gitignore new file mode 100644 index 0000000..477ae27 --- /dev/null +++ b/Verax_API_EF/Verax_API_EF/Verax_API_EF/.idea/.idea.Verax_API_EF.dir/.idea/.gitignore @@ -0,0 +1,15 @@ +# Default ignored files +/shelf/ +/workspace.xml +# Rider ignored files +/modules.xml +/projectSettingsUpdater.xml +/.idea.Verax_API_EF.iml +/contentModel.xml +# Editor-based HTTP Client requests +/httpRequests/ +# Datasource local storage ignored files +/dataSources/ +/dataSources.local.xml +# GitHub Copilot persisted chat sessions +/copilot/chatSessions diff --git a/Verax_API_EF/Verax_API_EF/Verax_API_EF/.idea/.idea.Verax_API_EF.dir/.idea/indexLayout.xml b/Verax_API_EF/Verax_API_EF/Verax_API_EF/.idea/.idea.Verax_API_EF.dir/.idea/indexLayout.xml new file mode 100644 index 0000000..7b08163 --- /dev/null +++ b/Verax_API_EF/Verax_API_EF/Verax_API_EF/.idea/.idea.Verax_API_EF.dir/.idea/indexLayout.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/Verax_API_EF/Verax_API_EF/Verax_API_EF/.idea/.idea.Verax_API_EF.dir/.idea/vcs.xml b/Verax_API_EF/Verax_API_EF/Verax_API_EF/.idea/.idea.Verax_API_EF.dir/.idea/vcs.xml new file mode 100644 index 0000000..b2bdec2 --- /dev/null +++ b/Verax_API_EF/Verax_API_EF/Verax_API_EF/.idea/.idea.Verax_API_EF.dir/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file