From 7afe33c430c920c4bed24279235e30d89de6438b Mon Sep 17 00:00:00 2001 From: tonyfages Date: Thu, 7 Mar 2024 18:59:23 +0100 Subject: [PATCH] =?UTF-8?q?COntrolleur=20+=20DBManager=20+=20Ca=20marche?= =?UTF-8?q?=20pas=20lol=20=20=F0=9F=9A=A7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../.idea/.idea.Verax_API_EF/.idea/.gitignore | 2 + .../.idea/.idea.Verax_API_EF/.idea/vcs.xml | 6 ++ Verax_API_EF/API/API.csproj | 23 +++++ Verax_API_EF/API/API.http | 6 ++ .../API/Controllers/ArticleController.cs | 64 ++++++++++++ .../API/Controllers/FormulaireController.cs | 51 ++++++++++ .../API/Controllers/UserController.cs | 51 ++++++++++ Verax_API_EF/API/Program.cs | 35 +++++++ .../Properties/launchSettings.json | 8 +- .../appsettings.Development.json | 0 .../{Web_API => API}/appsettings.json | 0 .../API_DbDataManager.csproj | 2 +- Verax_API_EF/API_DbDataManager/Class1.cs | 94 ------------------ .../API_DbDataManager/DbManagerArticle.cs | 66 ++++++++++++ .../API_DbDataManager/DbManagerFormulaire.cs | 56 +++++++++++ .../API_DbDataManager/DbManagerUser.cs | 59 +++++++++++ Verax_API_EF/API_DbDataManager/Extensions.cs | 35 +++++++ Verax_API_EF/API_Model/FormulaireDTO.cs | 2 +- Verax_API_EF/API_Services/API_Services.csproj | 2 +- Verax_API_EF/API_Services/IArticleService.cs | 14 +-- .../API_Services/IFormulaireService.cs | 8 +- Verax_API_EF/API_Services/IUserService.cs | 6 +- Verax_API_EF/DbContextLib/LibraryContext.cs | 3 + Verax_API_EF/Model/Formulaire.cs | 2 +- .../Entity_FrameWork.Article.db | Bin 45056 -> 45056 bytes Verax_API_EF/Verax_API_EF.sln | 12 +-- .../Web_API/Controllers/ArticleController.cs | 68 ------------- .../Controllers/FormulaireController.cs | 27 ----- .../Web_API/Controllers/UserController.cs | 76 -------------- Verax_API_EF/Web_API/Mapper/Mapper.cs | 82 --------------- Verax_API_EF/Web_API/Program.cs | 44 -------- Verax_API_EF/Web_API/Web_API.csproj | 21 ---- Verax_API_EF/Web_API/Web_API.http | 6 -- 33 files changed, 485 insertions(+), 446 deletions(-) create mode 100644 Verax_API_EF/.idea/.idea.Verax_API_EF/.idea/vcs.xml create mode 100644 Verax_API_EF/API/API.csproj create mode 100644 Verax_API_EF/API/API.http create mode 100644 Verax_API_EF/API/Controllers/ArticleController.cs create mode 100644 Verax_API_EF/API/Controllers/FormulaireController.cs create mode 100644 Verax_API_EF/API/Controllers/UserController.cs create mode 100644 Verax_API_EF/API/Program.cs rename Verax_API_EF/{Web_API => API}/Properties/launchSettings.json (82%) rename Verax_API_EF/{Web_API => API}/appsettings.Development.json (100%) rename Verax_API_EF/{Web_API => API}/appsettings.json (100%) delete mode 100644 Verax_API_EF/API_DbDataManager/Class1.cs create mode 100644 Verax_API_EF/API_DbDataManager/DbManagerArticle.cs create mode 100644 Verax_API_EF/API_DbDataManager/DbManagerFormulaire.cs create mode 100644 Verax_API_EF/API_DbDataManager/DbManagerUser.cs create mode 100644 Verax_API_EF/API_DbDataManager/Extensions.cs delete mode 100644 Verax_API_EF/Web_API/Controllers/ArticleController.cs delete mode 100644 Verax_API_EF/Web_API/Controllers/FormulaireController.cs delete mode 100644 Verax_API_EF/Web_API/Controllers/UserController.cs delete mode 100644 Verax_API_EF/Web_API/Mapper/Mapper.cs delete mode 100644 Verax_API_EF/Web_API/Program.cs delete mode 100644 Verax_API_EF/Web_API/Web_API.csproj delete mode 100644 Verax_API_EF/Web_API/Web_API.http diff --git a/Verax_API_EF/.idea/.idea.Verax_API_EF/.idea/.gitignore b/Verax_API_EF/.idea/.idea.Verax_API_EF/.idea/.gitignore index 16e553f..9a114e8 100644 --- a/Verax_API_EF/.idea/.idea.Verax_API_EF/.idea/.gitignore +++ b/Verax_API_EF/.idea/.idea.Verax_API_EF/.idea/.gitignore @@ -11,3 +11,5 @@ # Datasource local storage ignored files /dataSources/ /dataSources.local.xml +# GitHub Copilot persisted chat sessions +/copilot/chatSessions diff --git a/Verax_API_EF/.idea/.idea.Verax_API_EF/.idea/vcs.xml b/Verax_API_EF/.idea/.idea.Verax_API_EF/.idea/vcs.xml new file mode 100644 index 0000000..6c0b863 --- /dev/null +++ b/Verax_API_EF/.idea/.idea.Verax_API_EF/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/Verax_API_EF/API/API.csproj b/Verax_API_EF/API/API.csproj new file mode 100644 index 0000000..8e60ffc --- /dev/null +++ b/Verax_API_EF/API/API.csproj @@ -0,0 +1,23 @@ + + + + net8.0 + enable + enable + true + + + + + + + + + + + + + + + + diff --git a/Verax_API_EF/API/API.http b/Verax_API_EF/API/API.http new file mode 100644 index 0000000..4bb3497 --- /dev/null +++ b/Verax_API_EF/API/API.http @@ -0,0 +1,6 @@ +@API_HostAddress = http://localhost:5052 + +GET {{API_HostAddress}}/weatherforecast/ +Accept: application/json + +### diff --git a/Verax_API_EF/API/Controllers/ArticleController.cs b/Verax_API_EF/API/Controllers/ArticleController.cs new file mode 100644 index 0000000..fb64675 --- /dev/null +++ b/Verax_API_EF/API/Controllers/ArticleController.cs @@ -0,0 +1,64 @@ +using API_Services; +using Microsoft.AspNetCore.Mvc; +using Model; + + +namespace API.Controllers +{ + [Route("api/[controller]")] + [ApiController] + public class ArticleController : ControllerBase + { + + private readonly IArticleService _articleService; + + public ArticleController(IArticleService articleService) + { + _articleService = articleService; + } + + [HttpGet("/articles")] + public async Task GetAllArticles() + { + var result = await _articleService.GetAllArticles(); + if (result == null) + { + return NotFound(); + } + return Ok(result); + } + + [HttpGet("/article/{id}")] + public async Task GetArticleById(int id) + { + var result = await _articleService.GetArticleById(id); + if (result == null) + { + return null; + } + return result; + } + + + + [HttpPost("/article")] + 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) + { + return await _articleService.DeleteArticle(id); + } + + [HttpPut("/article/{id}")] + public async Task UpdateArticle(long id, Article? a) + { + return await _articleService.UpdateArticle(id, a); + } + + + } +} diff --git a/Verax_API_EF/API/Controllers/FormulaireController.cs b/Verax_API_EF/API/Controllers/FormulaireController.cs new file mode 100644 index 0000000..653ec45 --- /dev/null +++ b/Verax_API_EF/API/Controllers/FormulaireController.cs @@ -0,0 +1,51 @@ +using Microsoft.AspNetCore.Mvc; +using API_Services; +using Model; +using System; +using System.Collections.Generic; +using System.Threading.Tasks; + +namespace API.Controllers +{ + [Route("api/[controller]")] + [ApiController] + public class FormulaireController : ControllerBase + { + private readonly IFormulaireService _form; + + public FormulaireController(IFormulaireService iform) + { + this._form = iform; + } + + [HttpGet("/forms/{id}")] + public Task> GetAllForm() + { + throw new NotImplementedException(); + } + + [HttpGet("{id}")] + public Task GetById(long id) + { + throw new NotImplementedException(); + } + + [HttpPost] + public Task CreateForm(Formulaire formulaire) + { + throw new NotImplementedException(); + } + + [HttpDelete("{id}")] + public Task DeleteForm(long id) + { + throw new NotImplementedException(); + } + + [HttpPut("{id}")] + public Task UpdateForm(long id, Formulaire formulaire) + { + throw new NotImplementedException(); + } + } +} \ No newline at end of file diff --git a/Verax_API_EF/API/Controllers/UserController.cs b/Verax_API_EF/API/Controllers/UserController.cs new file mode 100644 index 0000000..6a90231 --- /dev/null +++ b/Verax_API_EF/API/Controllers/UserController.cs @@ -0,0 +1,51 @@ +using Microsoft.AspNetCore.Http; +using Microsoft.AspNetCore.Mvc; +using API_Services; +using Model; + + +namespace API.Controllers +{ + [Route("api/[controller]")] + [ApiController] + public class UserController : ControllerBase + { + private readonly IUserService _us; + + public UserController(IUserService us) + { + this._us = us; + } + + [HttpPost("/user")] + public Task Create(User user) + { + throw new NotImplementedException(); + } + + + [HttpPut("/user/{pseudo}")] + public Task Update(User user) + { + throw new NotImplementedException(); + } + + [HttpDelete("/user/{pseudo}")] + public Task Delete(string pseudo) + { + throw new NotImplementedException(); + } + + [HttpGet("/user/{pseudo}")] + public Task GetByPseudo(string pseudo) + { + throw new NotImplementedException(); + } + + [HttpGet("/users")] + public Task> GetAll() + { + throw new NotImplementedException(); + } + } +} diff --git a/Verax_API_EF/API/Program.cs b/Verax_API_EF/API/Program.cs new file mode 100644 index 0000000..d07947c --- /dev/null +++ b/Verax_API_EF/API/Program.cs @@ -0,0 +1,35 @@ +using API_Services; +using DbContextLib; +using DbDataManager; +using Microsoft.EntityFrameworkCore; + +var builder = WebApplication.CreateBuilder(args); + + + +// Add services to the container. +// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle +builder.Services.AddControllers(); + +builder.Services.AddEndpointsApiExplorer(); +builder.Services.AddSwaggerGen(); + + +builder.Services.AddDbContext(); +builder.Services.AddScoped(); + +var app = builder.Build(); + +// Configure the HTTP request pipeline. +if (app.Environment.IsDevelopment()) +{ + app.UseSwagger(); + app.UseSwaggerUI(); +} + +app.UseHttpsRedirection(); + + + + +app.Run(); diff --git a/Verax_API_EF/Web_API/Properties/launchSettings.json b/Verax_API_EF/API/Properties/launchSettings.json similarity index 82% rename from Verax_API_EF/Web_API/Properties/launchSettings.json rename to Verax_API_EF/API/Properties/launchSettings.json index 37623b3..b8f34d4 100644 --- a/Verax_API_EF/Web_API/Properties/launchSettings.json +++ b/Verax_API_EF/API/Properties/launchSettings.json @@ -4,8 +4,8 @@ "windowsAuthentication": false, "anonymousAuthentication": true, "iisExpress": { - "applicationUrl": "http://localhost:48061", - "sslPort": 44331 + "applicationUrl": "http://localhost:16122", + "sslPort": 44361 } }, "profiles": { @@ -14,7 +14,7 @@ "dotnetRunMessages": true, "launchBrowser": true, "launchUrl": "swagger", - "applicationUrl": "http://localhost:5139", + "applicationUrl": "http://localhost:5052", "environmentVariables": { "ASPNETCORE_ENVIRONMENT": "Development" } @@ -24,7 +24,7 @@ "dotnetRunMessages": true, "launchBrowser": true, "launchUrl": "swagger", - "applicationUrl": "https://localhost:7143;http://localhost:5139", + "applicationUrl": "https://localhost:7159;http://localhost:5052", "environmentVariables": { "ASPNETCORE_ENVIRONMENT": "Development" } diff --git a/Verax_API_EF/Web_API/appsettings.Development.json b/Verax_API_EF/API/appsettings.Development.json similarity index 100% rename from Verax_API_EF/Web_API/appsettings.Development.json rename to Verax_API_EF/API/appsettings.Development.json diff --git a/Verax_API_EF/Web_API/appsettings.json b/Verax_API_EF/API/appsettings.json similarity index 100% rename from Verax_API_EF/Web_API/appsettings.json rename to Verax_API_EF/API/appsettings.json diff --git a/Verax_API_EF/API_DbDataManager/API_DbDataManager.csproj b/Verax_API_EF/API_DbDataManager/API_DbDataManager.csproj index b2f1743..098d5a6 100644 --- a/Verax_API_EF/API_DbDataManager/API_DbDataManager.csproj +++ b/Verax_API_EF/API_DbDataManager/API_DbDataManager.csproj @@ -9,7 +9,7 @@ - + diff --git a/Verax_API_EF/API_DbDataManager/Class1.cs b/Verax_API_EF/API_DbDataManager/Class1.cs deleted file mode 100644 index 628fa69..0000000 --- a/Verax_API_EF/API_DbDataManager/Class1.cs +++ /dev/null @@ -1,94 +0,0 @@ -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_DbDataManager/DbManagerArticle.cs b/Verax_API_EF/API_DbDataManager/DbManagerArticle.cs new file mode 100644 index 0000000..9d0d2fa --- /dev/null +++ b/Verax_API_EF/API_DbDataManager/DbManagerArticle.cs @@ -0,0 +1,66 @@ +using API_Services; +using DbContextLib; +using Entities; +using Model; + +namespace DbDataManager; + +public class DbManagerArticle : IArticleService +{ + private readonly LibraryContext _context; + + public DbManagerArticle(LibraryContext context) + { + _context = context; + } + + public async Task CreateArticle(long id, string title, string description, string author, string date, int lectureTime) + { + var entity = new ArticleEntity() + { + Id = id, + Title = title, + Description = description, + Author = author, + DatePublished = date, + LectureTime = lectureTime, + }; + _context.ArticleSet.Add(entity); + await _context.SaveChangesAsync(); + + return entity.ToModel(); + } + + public async Task DeleteArticle(long id) + { + var entity = _context.ArticleSet.FirstOrDefault(a => a.Id == id); + if (entity == null) return null; + _context.ArticleSet.Remove(entity); + await _context.SaveChangesAsync(); + return entity.ToModel(); + } + + public async Task UpdateArticle(long id, Article? a) + { + var entity = _context.ArticleSet.FirstOrDefault(a => a.Id == id); + if (entity == null) return false; + entity.Title = a.Title; + entity.Description = a.Description; + entity.Author = a.Author; + entity.DatePublished = a.DatePublished; + entity.LectureTime = a.LectureTime; + await _context.SaveChangesAsync(); + return true; + } + + public Task GetArticleById(int id) + { + var entity = _context.ArticleSet.FirstOrDefault(a => a.Id == id); + return Task.FromResult(entity.ToModel()); + } + + public async Task> GetAllArticles() + { + return await Task.FromResult(_context.ArticleSet.Select(a => a.ToModel()).AsEnumerable()); + } +} \ No newline at end of file diff --git a/Verax_API_EF/API_DbDataManager/DbManagerFormulaire.cs b/Verax_API_EF/API_DbDataManager/DbManagerFormulaire.cs new file mode 100644 index 0000000..52ca273 --- /dev/null +++ b/Verax_API_EF/API_DbDataManager/DbManagerFormulaire.cs @@ -0,0 +1,56 @@ +using API_Services; +using DbContextLib; +using Entities; +using Model; + +namespace DbDataManager; + +public class DbManagerFormulaire(LibraryContext _context) : IFormulaireService +{ + public async Task> GetAllForm() + { + return await Task.FromResult(_context.FormSet.Select(f => f.ToModel()).AsEnumerable()); + } + + public async Task GetById(long id) + { + var entity = _context.FormSet.FirstOrDefault(f => f.Id == id); + if (entity != null) return await Task.FromResult(entity.ToModel()); + return null; + } + + public async Task CreateForm(Formulaire formulaire) + { + var entity = new FormEntity() + { + Id = formulaire.Id, + Pseudo = formulaire.Pseudo, + Theme = formulaire.Theme, + DatePublication = formulaire.Date + }; + + _context.FormSet.Add(entity); + await _context.SaveChangesAsync(); + return entity.ToModel(); + } + + public async Task DeleteForm(long id) + { + var entity = _context.FormSet.FirstOrDefault(f => f.Id == id); + if (entity == null) return false; + _context.FormSet.Remove(entity); + await _context.SaveChangesAsync(); + return true; + } + + public async Task UpdateForm(long id, Formulaire formulaire) + { + 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; + await _context.SaveChangesAsync(); + return true; + } +} \ No newline at end of file diff --git a/Verax_API_EF/API_DbDataManager/DbManagerUser.cs b/Verax_API_EF/API_DbDataManager/DbManagerUser.cs new file mode 100644 index 0000000..b35bde6 --- /dev/null +++ b/Verax_API_EF/API_DbDataManager/DbManagerUser.cs @@ -0,0 +1,59 @@ +using API_Services; +using DbContextLib; +using Entities; +using Model; + +namespace DbDataManager; + +public class DbManagerUser(LibraryContext _context): IUserService +{ + public async Task Create(User user) + { + var entity = new UserEntity() + { + Pseudo = user.Pseudo, + Prenom = user.Prenom, + Nom = user.Nom, + Mdp = user.Mdp, + Mail = user.Mail, + Role = user.Role + }; + _context.UserSet.Add(entity); + await _context.SaveChangesAsync(); + return true; + } + + public async Task Update(User user) + { + var entity = _context.UserSet.FirstOrDefault(u => u.Pseudo == user.Pseudo); + if (entity == null) return false; + entity.Mdp = user.Mdp; + entity.Mail = user.Mail; + entity.Role = user.Role; + entity.Prenom = user.Prenom; + entity.Nom = user.Nom; + await _context.SaveChangesAsync(); + return true; + } + + public async Task Delete(string pseudo) + { + var entity = _context.UserSet.FirstOrDefault(u => u.Pseudo == pseudo); + if (entity == null) return await Task.FromResult(false); + _context.UserSet.Remove(entity); + await _context.SaveChangesAsync(); + return await Task.FromResult(true); + + } + + public async Task GetByPseudo(string pseudo) + { + var entity = _context.UserSet.FirstOrDefault(u => u.Pseudo == pseudo); + return await Task.FromResult(entity.ToModel()); + } + + public async Task> GetAll() + { + return await Task.FromResult(_context.UserSet.Select(u => u.ToModel()).AsEnumerable()); + } +} \ No newline at end of file diff --git a/Verax_API_EF/API_DbDataManager/Extensions.cs b/Verax_API_EF/API_DbDataManager/Extensions.cs new file mode 100644 index 0000000..2e9335e --- /dev/null +++ b/Verax_API_EF/API_DbDataManager/Extensions.cs @@ -0,0 +1,35 @@ +using Entities; +using Model; + +namespace DbDataManager; + +public static class Extensions +{ + public static ArticleEntity ToEntity(this Article article) + => new ArticleEntity + { + Id = article.Id, Author = article.Author, Description = article.Description, Title = article.Title, + DatePublished = article.DatePublished, LectureTime = article.LectureTime + }; + + public static Article ToModel(this ArticleEntity article) + => new Article + { + Id = article.Id, Author = article.Author, Description = article.Description, Title = article.Title, + DatePublished = article.DatePublished, LectureTime = article.LectureTime + }; + + public static UserEntity ToEntity(this User user) + => new UserEntity{ Pseudo = user.Pseudo, Mdp = user.Mdp, Prenom = user.Prenom, Nom = user.Nom, Mail = user.Mail, Role = user.Role}; + + public static User ToModel(this UserEntity user) + => 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}; + + public static Formulaire ToModel(this FormEntity form) + => new Formulaire{ Id = form.Id, Pseudo = form.Pseudo, Theme = form.Theme, Lien = form.Link}; + + +} \ No newline at end of file diff --git a/Verax_API_EF/API_Model/FormulaireDTO.cs b/Verax_API_EF/API_Model/FormulaireDTO.cs index 53d1457..df256d4 100644 --- a/Verax_API_EF/API_Model/FormulaireDTO.cs +++ b/Verax_API_EF/API_Model/FormulaireDTO.cs @@ -4,7 +4,7 @@ public class FormulaireDTO { public long Id; public string Theme { get; set; } - public DateTime Date { get; set; } + public string Date { get; set; } public string Lien { get; set; } public string Pseudo { get; set; } diff --git a/Verax_API_EF/API_Services/API_Services.csproj b/Verax_API_EF/API_Services/API_Services.csproj index cd25ca9..b0ff0a6 100644 --- a/Verax_API_EF/API_Services/API_Services.csproj +++ b/Verax_API_EF/API_Services/API_Services.csproj @@ -7,7 +7,7 @@ - + diff --git a/Verax_API_EF/API_Services/IArticleService.cs b/Verax_API_EF/API_Services/IArticleService.cs index 46766f9..2bbeac2 100644 --- a/Verax_API_EF/API_Services/IArticleService.cs +++ b/Verax_API_EF/API_Services/IArticleService.cs @@ -1,19 +1,19 @@ -using Entities; -using Web_API.Model; +using Model; namespace API_Services { public interface IArticleService { - Task CreateArticle(ArticleDTO a); + 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, ArticleDTO 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/API_Services/IFormulaireService.cs b/Verax_API_EF/API_Services/IFormulaireService.cs index 49c0ade..e3159c0 100644 --- a/Verax_API_EF/API_Services/IFormulaireService.cs +++ b/Verax_API_EF/API_Services/IFormulaireService.cs @@ -1,16 +1,16 @@ -using Web_API.Model; +using Model; namespace API_Services; public interface IFormulaireService { - Task> GetAllForm(); + Task> GetAllForm(); - Task GetById(long id); + Task GetById(long id); - Task CreateForm(Formulaire formulaire); + Task CreateForm(Formulaire formulaire); Task DeleteForm(long id); diff --git a/Verax_API_EF/API_Services/IUserService.cs b/Verax_API_EF/API_Services/IUserService.cs index 51b1d6f..480cb43 100644 --- a/Verax_API_EF/API_Services/IUserService.cs +++ b/Verax_API_EF/API_Services/IUserService.cs @@ -1,4 +1,4 @@ -using Web_API.Model; +using Model; namespace API_Services { @@ -10,9 +10,9 @@ namespace API_Services Task Delete(string pseudo); - Task GetByPseudo(string pseudo); + Task GetByPseudo(string pseudo); - Task> GetAll(); + Task> GetAll(); diff --git a/Verax_API_EF/DbContextLib/LibraryContext.cs b/Verax_API_EF/DbContextLib/LibraryContext.cs index fe2cbf4..146b845 100644 --- a/Verax_API_EF/DbContextLib/LibraryContext.cs +++ b/Verax_API_EF/DbContextLib/LibraryContext.cs @@ -13,8 +13,11 @@ public class LibraryContext : DbContext : base(options) { } + + public DbSet ArticleSet { get; set; } public DbSet UserSet { get; set; } + public DbSet FormSet { get; set; } protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) { diff --git a/Verax_API_EF/Model/Formulaire.cs b/Verax_API_EF/Model/Formulaire.cs index 2363c4d..9b883fb 100644 --- a/Verax_API_EF/Model/Formulaire.cs +++ b/Verax_API_EF/Model/Formulaire.cs @@ -4,7 +4,7 @@ public class Formulaire { public long Id; public string Theme { get; set; } - public DateTime Date { get; set; } + public string 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/Test_Console_EF/Entity_FrameWork.Article.db b/Verax_API_EF/Test_Console_EF/Entity_FrameWork.Article.db index a650ca1be57db6c63741a7245aabd81416301ae7..18350873d4552aa83d40d78e16e90841abc2ca4d 100644 GIT binary patch delta 46 zcmZp8z|`=7X# 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 deleted file mode 100644 index 841e0c3..0000000 --- a/Verax_API_EF/Web_API/Controllers/FormulaireController.cs +++ /dev/null @@ -1,27 +0,0 @@ -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 deleted file mode 100644 index 620c960..0000000 --- a/Verax_API_EF/Web_API/Controllers/UserController.cs +++ /dev/null @@ -1,76 +0,0 @@ -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 deleted file mode 100644 index ef89862..0000000 --- a/Verax_API_EF/Web_API/Mapper/Mapper.cs +++ /dev/null @@ -1,82 +0,0 @@ -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 deleted file mode 100644 index 161f695..0000000 --- a/Verax_API_EF/Web_API/Program.cs +++ /dev/null @@ -1,44 +0,0 @@ -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/Web_API.csproj b/Verax_API_EF/Web_API/Web_API.csproj deleted file mode 100644 index 6441ade..0000000 --- a/Verax_API_EF/Web_API/Web_API.csproj +++ /dev/null @@ -1,21 +0,0 @@ - - - - net8.0 - enable - enable - - - - - - - - - - - - - - - diff --git a/Verax_API_EF/Web_API/Web_API.http b/Verax_API_EF/Web_API/Web_API.http deleted file mode 100644 index 6015298..0000000 --- a/Verax_API_EF/Web_API/Web_API.http +++ /dev/null @@ -1,6 +0,0 @@ -@Web_API_HostAddress = http://localhost:5139 - -GET {{Web_API_HostAddress}}/weatherforecast/ -Accept: application/json - -###