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 2df9a5d..d83ebb8 100644 --- a/Verax_API_EF/Verax_API_EF/API/Controllers/ArticleController.cs +++ b/Verax_API_EF/Verax_API_EF/API/Controllers/ArticleController.cs @@ -29,7 +29,7 @@ namespace API.Controllers } [HttpGet("/article/{id}")] - public async Task GetArticleById(int id) + public async Task GetArticleById(int id) { var result = await _articleService.GetArticleById(id); if (result == null) @@ -42,19 +42,19 @@ 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(long id, string title, string description, string author, string date, int lectureTime) { return await _articleService.CreateArticle(id, title, description, author, date, lectureTime); } [HttpDelete("/article/{id}")] - public async Task DeleteArticle(long id) + public async Task DeleteArticle(long id) { return await _articleService.DeleteArticle(id); } [HttpPut("/article/{id}")] - public async Task UpdateArticle(long id, ArticleEntity? a) + public async Task UpdateArticle(long id, Article? a) { return await _articleService.UpdateArticle(id, a); } 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 0e64b42..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/API/Entity_FrameWork.Article.db-shm b/Verax_API_EF/Verax_API_EF/API/Entity_FrameWork.Article.db-shm new file mode 100644 index 0000000..5e1d073 Binary files /dev/null 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..497cd7d 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/Program.cs b/Verax_API_EF/Verax_API_EF/API/Program.cs index 167fa53..9bf4f16 100644 --- a/Verax_API_EF/Verax_API_EF/API/Program.cs +++ b/Verax_API_EF/Verax_API_EF/API/Program.cs @@ -36,11 +36,11 @@ if (app.Environment.IsDevelopment()) app.UseHttpsRedirection(); app.MapControllers(); - +using var scoped = app.Services.CreateScope(); +var libraryContext = scoped.ServiceProvider.GetService(); +//libraryContext.Database.EnsureCreated(); +libraryContext.Database.Migrate(); app.Run(); -using var scoped = app.Services.CreateScope(); -var libraryContext = scoped.ServiceProvider.GetService(); -libraryContext.Database.EnsureCreated(); 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 ee3176c..adf65c2 100644 --- a/Verax_API_EF/Verax_API_EF/API_DbDataManager/DbManagerArticle.cs +++ b/Verax_API_EF/Verax_API_EF/API_DbDataManager/DbManagerArticle.cs @@ -2,7 +2,6 @@ using API_Services; using DbContextLib; using Entities; using Model; -using ArticleEntity = Model.ArticleEntity; namespace DbDataManager; @@ -17,7 +16,7 @@ public class DbManagerArticle : IArticleService } - public async Task CreateArticle(long id, string title, string description, string author, string date, int lectureTime) + public async Task CreateArticle(long id, string title, string description, string author, string date, int lectureTime) { var entity = new Entities.ArticleEntity() { @@ -34,7 +33,7 @@ public class DbManagerArticle : IArticleService return entity.ToModel(); } - public async Task DeleteArticle(long id) + public async Task DeleteArticle(long id) { var entity = _context.ArticleSet.FirstOrDefault(a => a.Id == id); Console.WriteLine(entity); @@ -44,7 +43,7 @@ public class DbManagerArticle : IArticleService return entity.ToModel(); } - public async Task UpdateArticle(long id, ArticleEntity? a) + public async Task UpdateArticle(long id, Article? a) { var entity = _context.ArticleSet.FirstOrDefault(a => a.Id == id); if (entity == null) return false; @@ -57,13 +56,13 @@ public class DbManagerArticle : IArticleService return true; } - public Task GetArticleById(int id) + public Task GetArticleById(int id) { var entity = _context.ArticleSet.FirstOrDefault(a => a.Id == id); return Task.FromResult(entity.ToModel()); } - public async Task> GetAllArticles() + public async Task> GetAllArticles() { return await Task.FromResult(_context.ArticleSet.Select(a => a.ToModel()).AsEnumerable()); } 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 6431bec..511f7da 100644 --- a/Verax_API_EF/Verax_API_EF/API_DbDataManager/Extensions.cs +++ b/Verax_API_EF/Verax_API_EF/API_DbDataManager/Extensions.cs @@ -1,20 +1,19 @@ using Entities; using Model; -using ArticleEntity = Model.ArticleEntity; namespace DbDataManager; public static class Extensions { - public static Entities.ArticleEntity ToEntity(this ArticleEntity articleEntity) + public static Entities.ArticleEntity ToEntity(this Article article) => new Entities.ArticleEntity { - Id = articleEntity.Id, Author = articleEntity.Author, Description = articleEntity.Description, Title = articleEntity.Title, - DatePublished = articleEntity.DatePublished, LectureTime = articleEntity.LectureTime + Id = article.Id, Author = article.Author, Description = article.Description, Title = article.Title, + DatePublished = article.DatePublished, LectureTime = article.LectureTime }; - public static ArticleEntity ToModel(this Entities.ArticleEntity article) - => new ArticleEntity + public static Article ToModel(this Entities.ArticleEntity article) + => new Article { Id = article.Id, Author = article.Author, Description = article.Description, Title = article.Title, DatePublished = article.DatePublished, LectureTime = article.LectureTime diff --git a/Verax_API_EF/Verax_API_EF/API_Mapping/ArticleMapper.cs b/Verax_API_EF/Verax_API_EF/API_Mapping/ArticleMapper.cs index dfaf91c..9767dd8 100644 --- a/Verax_API_EF/Verax_API_EF/API_Mapping/ArticleMapper.cs +++ b/Verax_API_EF/Verax_API_EF/API_Mapping/ArticleMapper.cs @@ -5,7 +5,7 @@ namespace API_Mapping; public static class ArticleMapper { - public static ArticleDTO ToDTO(this ArticleEntity a) => new() + public static ArticleDTO ToDTO(this Article a) => new() { Id = a.Id, Title = a.Title, @@ -15,7 +15,7 @@ public static class ArticleMapper Author = a.Author }; - public static ArticleEntity ToModel(this ArticleDTO a) => new() + public static Article ToModel(this ArticleDTO a) => new() { Id = a.Id, Title = a.Title, 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 3ee9e0f..2bbeac2 100644 --- a/Verax_API_EF/Verax_API_EF/API_Services/IArticleService.cs +++ b/Verax_API_EF/Verax_API_EF/API_Services/IArticleService.cs @@ -4,16 +4,16 @@ namespace API_Services { public interface IArticleService { - Task CreateArticle(long id, string title, string description, string author, string date, + Task CreateArticle(long id, string title, string description, string author, string date, int lectureTime); - Task DeleteArticle(long id); + Task DeleteArticle(long id); - Task UpdateArticle(long id, ArticleEntity? a); + Task UpdateArticle(long id, Article? a); - Task GetArticleById(int id); + Task GetArticleById(int id); - Task> GetAllArticles(); + Task> GetAllArticles(); } } diff --git a/Verax_API_EF/Verax_API_EF/DbContextLib/LibraryContext.cs b/Verax_API_EF/Verax_API_EF/DbContextLib/LibraryContext.cs index 7b63ab6..58c2539 100644 --- a/Verax_API_EF/Verax_API_EF/DbContextLib/LibraryContext.cs +++ b/Verax_API_EF/Verax_API_EF/DbContextLib/LibraryContext.cs @@ -36,6 +36,16 @@ public class LibraryContext : DbContext .WithMany(a => a.Articles) .UsingEntity(); + modelBuilder.Entity() + .HasMany(u => u.Forms) + .WithOne(f => f.User) + .HasForeignKey(f => f.UserEntityId); + + modelBuilder.Entity() + .HasOne(f => f.User) + .WithMany(u => u.Forms) + .HasForeignKey(f => f.UserEntityId); + modelBuilder.Entity().HasData( new ArticleEntity { @@ -111,5 +121,32 @@ public class LibraryContext : DbContext UserEntityId = 3 } ); + + modelBuilder.Entity().HasData( + new FormEntity + { + Id = 1, + Pseudo= "Form 1", + DatePublication = "Form 1 Description", + Link = "hhtp://form1.com", + UserEntityId = 1 + }, + new FormEntity + { + Id = 2, + Pseudo= "Form 2", + DatePublication = "Form 2 Description", + Link = "hhtp://form2.com", + UserEntityId = 2 + }, + new FormEntity + { + Id = 3, + Pseudo= "Form 3", + DatePublication = "Form 3 Description", + Link = "hhtp://form3.com", + UserEntityId = 3 + } + ); } } \ No newline at end of file diff --git a/Verax_API_EF/Verax_API_EF/Model/ArticleEntity.cs b/Verax_API_EF/Verax_API_EF/Model/Article.cs similarity index 92% rename from Verax_API_EF/Verax_API_EF/Model/ArticleEntity.cs rename to Verax_API_EF/Verax_API_EF/Model/Article.cs index 5bedd63..497b56c 100644 --- a/Verax_API_EF/Verax_API_EF/Model/ArticleEntity.cs +++ b/Verax_API_EF/Verax_API_EF/Model/Article.cs @@ -1,6 +1,6 @@ namespace Model; -public class ArticleEntity +public class Article { public long Id { get; set; } public string Title { get; set; } = string.Empty; diff --git a/Verax_API_EF/Verax_API_EF/StubbedContextLib/StubTest.cs b/Verax_API_EF/Verax_API_EF/StubbedContextLib/StubTest.cs index 9648580..6e01d1f 100644 --- a/Verax_API_EF/Verax_API_EF/StubbedContextLib/StubTest.cs +++ b/Verax_API_EF/Verax_API_EF/StubbedContextLib/StubTest.cs @@ -1,18 +1,17 @@ using Entities; using Model; -using ArticleEntity = Model.ArticleEntity; namespace StubbedContextLib; public class StubTest { - private List _article; + private List
_article; - public List StubArticle() + public List
StubArticle() { - _article = new List + _article = new List
{ - new ArticleEntity + new Article { Id = 1, Title = "Test",