diff --git a/Verax_API_EF/Verax_API_EF/API/API.csproj b/Verax_API_EF/Verax_API_EF/API/API.csproj index e993a90..1a9894b 100644 --- a/Verax_API_EF/Verax_API_EF/API/API.csproj +++ b/Verax_API_EF/Verax_API_EF/API/API.csproj @@ -21,6 +21,7 @@ all runtime; build; native; contentfiles; analyzers; buildtransitive + 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 a7aae26..940469f 100644 --- a/Verax_API_EF/Verax_API_EF/API/Controllers/ArticleController.cs +++ b/Verax_API_EF/Verax_API_EF/API/Controllers/ArticleController.cs @@ -12,52 +12,114 @@ namespace API.Controllers { private readonly IArticleService _articleService; + private readonly ILogger _logger; - public ArticleController(IArticleService articleService) + public ArticleController(IArticleService articleService, ILogger logger) { - _articleService = articleService; + this._articleService = articleService; + this._logger = logger; } [HttpGet] public async Task GetAllArticles([FromQuery] int index = 0, [FromQuery] int count = 10, [FromQuery] ArticleOrderCriteria orderCriterium = ArticleOrderCriteria.None) { - var result = (await _articleService.GetAllArticles(index, count, orderCriterium)).Select(a => a.ToDTO()); - if (result == null) + _logger.LogInformation("Executing {Action} - with parameters: {Parameters}",nameof(GetAllArticles), index, count, orderCriterium); + try { - return NotFound(); + var result = (await _articleService.GetAllArticles(index, count, orderCriterium)).Select(a => a.ToDTO()); + if (result == null) + { + return NotFound(); + } + return Ok(result); + } + catch (Exception error) + { + _logger.LogError(error.Message); + return BadRequest(error.Message); } - return Ok(result); } [HttpGet("/article/{id}")] - public async Task GetArticleById(int id, [FromQuery] int index = 0, [FromQuery] int count = 10, [FromQuery] ArticleOrderCriteria orderCriterium = ArticleOrderCriteria.None) + public async Task GetArticleById(int id) { - var result = await _articleService.GetArticleById(id, index, count, orderCriterium); - if (result == null) + _logger.LogInformation("Executing {Action} - with parameters: {Parameters}",nameof(GetArticleById), id); + try + { + var result = (await _articleService.GetArticleById(id)).ToDTO(); + if (result == null) + { + return NotFound($"Article ID {id} not found"); + } + return Ok(result); + } + catch (Exception error) { - return null; + _logger.LogError(error.Message); + return BadRequest(error.Message); } - return result; } [HttpPost("/article")] - public async Task CreateArticle(Article article) + public async Task CreateArticle(Article article) { - return await _articleService.CreateArticle(article); + _logger.LogInformation("Executing {Action} - with parameters: {Parameters}",nameof(CreateArticle), article); + try + { + var result = (await _articleService.CreateArticle(article)).ToDTO(); + if (result == null) + { + return BadRequest($"Article not created"); + } + return Ok(result); + } + catch (Exception error) + { + _logger.LogError(error.Message); + return BadRequest(error.Message); + } } [HttpDelete("/article/{id}")] - public async Task DeleteArticle(long id) + public async Task DeleteArticle(long id) { - return await _articleService.DeleteArticle(id); + _logger.LogInformation("Executing {Action} - with parameters: {Parameters}",nameof(DeleteArticle), id); + try + { + var result = await _articleService.DeleteArticle(id); + if (result == null) + { + return NotFound($"Article ID {id} not found"); + } + return Ok(result.ToDTO()); + } + catch (Exception error) + { + _logger.LogError(error.Message); + return BadRequest(error.Message); + } } [HttpPut("/article/{id}")] - public async Task UpdateArticle(long id, Article? a) + public async Task UpdateArticle(long id, Article? a) { - return await _articleService.UpdateArticle(id, a); + _logger.LogInformation("Executing {Action} - with parameters: {Parameters}",nameof(UpdateArticle), id, a); + try + { + var result = await _articleService.UpdateArticle(id, a); + if (result == false) + { + return NotFound($"Article ID {id} not found"); + } + return Ok(result); + } + catch (Exception error) + { + _logger.LogError(error.Message); + return BadRequest(error.Message); + } } diff --git a/Verax_API_EF/Verax_API_EF/API/Controllers/ArticleUserController.cs b/Verax_API_EF/Verax_API_EF/API/Controllers/ArticleUserController.cs new file mode 100644 index 0000000..d8baa78 --- /dev/null +++ b/Verax_API_EF/Verax_API_EF/API/Controllers/ArticleUserController.cs @@ -0,0 +1,121 @@ +using API_Services; +using Entities; +using Microsoft.AspNetCore.Mvc; + +namespace API.Controllers; + +[Route("api/[controller]")] +[ApiController] +public class ArticleUserController : ControllerBase +{ + + private readonly IArticleUserService _us; + private readonly ILogger _logger; + public ArticleUserController(IArticleUserService us, ILogger logger) + { + this._us = us; + this._logger = logger; + } + + + [HttpGet("/articleUsers")] + public async Task GetAllArticleUsers() + { + _logger.LogInformation("Executing {Action} - with parameters: {Parameters}",nameof(GetAllArticleUsers), ""); + try + { + var result = await _us.GetAllArticleUsers(); + if (result == null) + { + return NoContent(); + } + return Ok(result); + } + catch (Exception error) + { + _logger.LogError(error.Message); + return BadRequest(error.Message); + } + } + + [HttpGet("/user/{pseudo}/article")] + public async Task GetArticleUser(string pseudo) + { + _logger.LogInformation("Executing {Action} - with parameters: {Parameters}",nameof(GetArticleUser), pseudo); + try + { + var result = await _us.GetArticleUser(pseudo); + if (result == null) + { + return NoContent(); + } + return Ok(result); + } + catch (Exception error) + { + _logger.LogError(error.Message); + return BadRequest(error.Message); + } + } + + [HttpPost("/user/{pseudo}/article")] + public async Task CreateArticleUser(ArticleUserEntity articleUser) + { + _logger.LogInformation("Executing {Action} - with parameters: {Parameters}",nameof(CreateArticleUser), articleUser); + try + { + var result = await _us.CreateArticleUser(articleUser); + if (result == null) + { + return BadRequest($"ArticleUser {articleUser.UserEntityPseudo} already exists"); + } + return Ok(result); + } + catch (Exception error) + { + _logger.LogError(error.Message); + return BadRequest(error.Message); + } + } + + [HttpDelete("/user/{pseudo}/article")] + public async Task DeleteArticleUser(string pseudo) + { + _logger.LogInformation("Executing {Action} - with parameters: {Parameters}",nameof(DeleteArticleUser), pseudo); + try + { + var result = await _us.DeleteArticleUser(pseudo); + if (!result) + { + return BadRequest($"ArticleUser {pseudo} does not exist"); + } + return Ok(result); + } + catch (Exception error) + { + _logger.LogError(error.Message); + return BadRequest(error.Message); + } + } + + [HttpPut("/user/{pseudo}/article")] + public async Task UpdateArticleUser(ArticleUserEntity articleUser) + { + _logger.LogInformation("Executing {Action} - with parameters: {Parameters}",nameof(UpdateArticleUser), articleUser); + try + { + var result = await _us.UpdateArticleUser(articleUser); + if (!result) + { + return BadRequest($"ArticleUser {articleUser.UserEntityPseudo} does not exist"); + } + return Ok(result); + } + catch (Exception error) + { + _logger.LogError(error.Message); + return BadRequest(error.Message); + } + } + +} \ No newline at end of file diff --git a/Verax_API_EF/Verax_API_EF/API/Controllers/FormulaireController.cs b/Verax_API_EF/Verax_API_EF/API/Controllers/FormulaireController.cs index 72c54b5..1e793a9 100644 --- a/Verax_API_EF/Verax_API_EF/API/Controllers/FormulaireController.cs +++ b/Verax_API_EF/Verax_API_EF/API/Controllers/FormulaireController.cs @@ -13,50 +13,116 @@ namespace API.Controllers public class FormulaireController : ControllerBase { private readonly IFormulaireService _form; + private readonly ILogger _logger; - public FormulaireController(IFormulaireService iform) + public FormulaireController(IFormulaireService iform, ILogger logger) { this._form = iform; + this._logger = logger; } - [HttpGet("/forms")] + [HttpGet("/formulaires")] public async Task GetAllForm([FromQuery] int index = 0, [FromQuery] int count = 10, [FromQuery] FormOrderCriteria orderCriteria = FormOrderCriteria.None) { - var result = (await _form.GetAllForm(index, count, orderCriteria)).Select(f => f.ToDTO()); - if (result == null) + _logger.LogInformation("Executing {Action} - with parameters: {Parameters}",nameof(GetAllForm), index, count, orderCriteria); + try { - return NotFound(); + var result = (await _form.GetAllForm(index, count, orderCriteria)).Select(f => f.ToDTO()); + if (result == null) + { + return NotFound($"No form found"); + } + return Ok(result); } - return Ok(result); + catch (Exception error) + { + _logger.LogError(error.Message); + return BadRequest(error.Message); + } + } - [HttpGet("{id}")] + [HttpGet("/formulaire/{id}")] public async Task GetById(long id) { - var result = (await _form.GetById(id)).ToDTO(); - if (result == null) + _logger.LogInformation("Executing {Action} - with parameters: {Parameters}",nameof(GetById), id); + try { - return NotFound(); + var result = (await _form.GetById(id)).ToDTO(); + if (result == null) + { + return NotFound($"form ID {id} not found"); + } + return Ok(result); } - return Ok(result); + catch (Exception error) + { + _logger.LogError(error.Message); + return BadRequest(error.Message); + } + + } - [HttpPost] - public async Task CreateForm(Formulaire formulaire) + [HttpPost ("/formulaire")] + public async Task CreateForm(Formulaire formulaire) { - return await _form.CreateForm(formulaire); + _logger.LogInformation("Executing {Action} - with parameters: {Parameters}",nameof(CreateForm), formulaire); + try + { + var result = (await _form.CreateForm(formulaire)).ToDTO(); + if (result == null) + { + return BadRequest($"Form Id {formulaire.Id} already exists"); + } + return Ok(result); + } + catch (Exception error) + { + _logger.LogError(error.Message); + return BadRequest(error.Message); + } } - [HttpDelete("{id}")] - public async Task DeleteForm(long id) + [HttpDelete("/formulaire/{id}")] + public async Task DeleteForm(long id) { - return await _form.DeleteForm(id); + _logger.LogInformation("Executing {Action} - with parameters: {Parameters}",nameof(DeleteForm), id); + try + { + var result = await _form.DeleteForm(id); + if (result == false) + { + return NotFound($"Form Id {id} not found"); + } + return Ok(result); + } + catch (Exception error) + { + _logger.LogError(error.Message); + return BadRequest(error.Message); + } } - [HttpPut("{id}")] - public async Task UpdateForm(long id, Formulaire formulaire) + [HttpPut("/formulaire/{id}")] + public async Task UpdateForm(long id, Formulaire formulaire) { - return await _form.UpdateForm(id, formulaire); + _logger.LogInformation("Executing {Action} - with parameters: {Parameters}",nameof(UpdateForm), formulaire); + + try + { + var result = await _form.UpdateForm(id, formulaire); + if (result == false) + { + return NotFound($"form Id {id} not found"); + } + return Ok(result); + } + catch (Exception error) + { + _logger.LogError(error.Message); + return BadRequest(error.Message); + } } } } \ No newline at end of file diff --git a/Verax_API_EF/Verax_API_EF/API/Controllers/UserController.cs b/Verax_API_EF/Verax_API_EF/API/Controllers/UserController.cs index c7ed3c2..b874e9e 100644 --- a/Verax_API_EF/Verax_API_EF/API/Controllers/UserController.cs +++ b/Verax_API_EF/Verax_API_EF/API/Controllers/UserController.cs @@ -3,6 +3,7 @@ using Microsoft.AspNetCore.Mvc; using API_Services; using Model; using API_Mapping; +using Entities; namespace API.Controllers @@ -12,53 +13,117 @@ namespace API.Controllers public class UserController : ControllerBase { private readonly IUserService _us; - - public UserController(IUserService us) + private readonly ILogger _logger; + public UserController(IUserService us, ILogger logger) { this._us = us; + this._logger = logger; } [HttpGet("/users")] public async Task GetAll([FromQuery] int index = 0, [FromQuery] int count = 10, [FromQuery] UserOrderCriteria orderCriteria = UserOrderCriteria.None) { - var result = (await _us.GetAll(index, count, orderCriteria)).Select(u => u.ToDTO()); - if (result == null) + _logger.LogInformation("Executing {Action} - with parameters: {Parameters}",nameof(GetAll), index, count, orderCriteria); + try + { + var result = (await _us.GetAll(index, count, orderCriteria)).Select(u => u.ToDTO()); + if (result == null) + { + return NotFound($"No user found with the given parameters"); + } + return Ok(result); + } + catch (Exception error) { - return NotFound(); + _logger.LogError(error.Message); + return BadRequest(error.Message); } - return Ok(result); } [HttpGet("/user/{pseudo}")] public async Task GetByPseudo(string pseudo) { - var result = (await _us.GetByPseudo(pseudo)).ToDTO(); - if (result == null) + _logger.LogInformation("Executing {Action} - with parameters: {Parameters}",nameof(GetByPseudo), pseudo); + try + { + var result = (await _us.GetByPseudo(pseudo)).ToDTO(); + if (result == null) + { + return NotFound($"Psuedo {pseudo} not found"); + } + return Ok(result); + } + catch (Exception error) { - return NotFound(); + _logger.LogError(error.Message); + return BadRequest(error.Message); } - return Ok(result); + } [HttpPost("/user")] - public async Task Create(User user) + public async Task Create(User user) { - return await _us.Create(user); + _logger.LogInformation("Executing {Action} - with parameters: {Parameters}",nameof(Create), user); + try + { + var result = await _us.Create(user); + if (result == false) + { + return BadRequest($"User {user.Pseudo} already exists"); + } + return Ok(result); + } + catch (Exception error) + { + _logger.LogError(error.Message); + return BadRequest(error.Message); + } + } [HttpPut("/user/{pseudo}")] - public async Task Update(User user, string pseudo) + public async Task Update(User user, string pseudo) { - return await _us.Update(user,pseudo); + _logger.LogInformation("Executing {Action} - with parameters: {Parameters}",nameof(Update), user, pseudo); + try + { + var result = await _us.Update(user,pseudo); + if (result == false) + { + return NotFound(); + } + return Ok(result); + } + catch (Exception error) + { + _logger.LogError(error.Message); + return BadRequest(error.Message); + } + } [HttpDelete("/user/{pseudo}")] - public async Task Delete(string pseudo) + public async Task Delete(string pseudo) { - return await _us.Delete(pseudo); + _logger.LogInformation("Executing {Action} - with parameters: {Parameters}",nameof(Delete), pseudo); + try + { + var result = await _us.Delete(pseudo); + if (result == false) + { + return NotFound(); + } + return Ok(result); + } + catch (Exception error) + { + _logger.LogError(error.Message); + return BadRequest(error.Message); + } } - + 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 index be3745a..99a315d 100644 Binary files a/Verax_API_EF/Verax_API_EF/API/Entity_FrameWork.Article.db-wal 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 7ee0854..b1ae889 100644 --- a/Verax_API_EF/Verax_API_EF/API/Program.cs +++ b/Verax_API_EF/Verax_API_EF/API/Program.cs @@ -23,6 +23,7 @@ builder.Services.AddDbContext(options => builder.Services.AddScoped(); builder.Services.AddScoped(); builder.Services.AddScoped(); +builder.Services.AddScoped(); var app = builder.Build(); 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 0c425de..81405d9 100644 --- a/Verax_API_EF/Verax_API_EF/API_DbDataManager/DbManagerArticle.cs +++ b/Verax_API_EF/Verax_API_EF/API_DbDataManager/DbManagerArticle.cs @@ -45,34 +45,11 @@ public class DbManagerArticle : IArticleService return await Task.FromResult(articles.AsEnumerable()); } - public Task GetArticleById(int id, int index, int count, ArticleOrderCriteria orderCriterium) + public Task GetArticleById(int id) { - List
articles = new List
(); - switch (orderCriterium) - { - case ArticleOrderCriteria.None: - articles = _context.ArticleSet.Where(a => a.Id == id).Select(a => a.ToModel()).ToList(); - break; - case ArticleOrderCriteria.ByLectureTime: - articles = _context.ArticleSet.Where(a => a.Id == id).OrderBy(a => a.LectureTime).Select(a => a.ToModel()).ToList(); - break; - case ArticleOrderCriteria.ByTitle: - articles = _context.ArticleSet.Where(a => a.Id == id).OrderBy(a => a.Title).Select(a => a.ToModel()).ToList(); - break; - case ArticleOrderCriteria.ByAuthor: - articles = _context.ArticleSet.Where(a => a.Id == id).OrderBy(a => a.Author).Select(a => a.ToModel()).ToList(); - break; - case ArticleOrderCriteria.ByDatePublished: - articles = _context.ArticleSet.Where(a => a.Id == id).OrderBy(a => a.DatePublished).Select(a => a.ToModel()).ToList(); - break; - case ArticleOrderCriteria.ByDescription: - articles = _context.ArticleSet.Where(a => a.Id == id).OrderBy(a => a.Description).Select(a => a.ToModel()).ToList(); - break; - default: - articles = _context.ArticleSet.Where(a => a.Id == id).Select(a => a.ToModel()).ToList(); - break; - } - return Task.FromResult(articles.FirstOrDefault()); + var entity = _context.ArticleSet.FirstOrDefault(a => a.Id == id); + if (entity == null) return Task.FromResult(null); + return Task.FromResult(entity.ToModel()); } @@ -80,6 +57,7 @@ public class DbManagerArticle : IArticleService { var entity = new Entities.ArticleEntity() { + Id = article.Id, Title = article.Title, Description = article.Description, Author = article.Author, diff --git a/Verax_API_EF/Verax_API_EF/API_DbDataManager/DbManagerArticleUser.cs b/Verax_API_EF/Verax_API_EF/API_DbDataManager/DbManagerArticleUser.cs new file mode 100644 index 0000000..cad3888 --- /dev/null +++ b/Verax_API_EF/Verax_API_EF/API_DbDataManager/DbManagerArticleUser.cs @@ -0,0 +1,67 @@ +using API_Services; +using DbContextLib; +using Entities; +using Model; + +namespace DbDataManager; + +public class DbManagerArticleUser : IArticleUserService +{ + private readonly LibraryContext _context; + + public DbManagerArticleUser(LibraryContext context) + { + _context = context; + } + + public async Task> GetAllArticleUsers() + { + var entities = _context.ArticleUserSet.ToList(); + if (entities == null) return await Task.FromResult>(null); + return await Task.FromResult(entities.AsEnumerable()); + } + + public async Task GetArticleUser(string pseudo) + { + var entity = _context.ArticleUserSet.FirstOrDefault(a => a.UserEntityPseudo.Equals(pseudo)); + if (entity == null) return await Task.FromResult(null); + return await Task.FromResult(entity); + } + + + public async Task CreateArticleUser(ArticleUserEntity articleUser) + { + var result = await GetArticleUser(articleUser.UserEntityPseudo); + if (result != null) return await Task.FromResult(null); + var entity = new ArticleUserEntity() + { + ArticleEntityId = articleUser.ArticleEntityId, + UserEntityPseudo = articleUser.UserEntityPseudo + }; + if (entity == null) return await Task.FromResult(null); + _context.ArticleUserSet.Add(entity); + await _context.SaveChangesAsync(); + return await Task.FromResult(entity); + } + + public async Task DeleteArticleUser(string pseudo) + { + var entity = _context.ArticleUserSet.FirstOrDefault(a => a.UserEntityPseudo.Equals(pseudo)); + if (entity == null) return await Task.FromResult(false); + _context.ArticleUserSet.Remove(entity); + await _context.SaveChangesAsync(); + return await Task.FromResult(true); + } + + public async Task UpdateArticleUser(ArticleUserEntity articleUser) + { + var entity = _context.ArticleUserSet.FirstOrDefault(a => a.UserEntityPseudo.Equals(articleUser.UserEntityPseudo)); + if (entity == null) return await Task.FromResult(false); + entity.ArticleEntityId = articleUser.ArticleEntityId; + entity.UserEntityPseudo = articleUser.UserEntityPseudo; + await _context.SaveChangesAsync(); + return await Task.FromResult(true); + } + + +} \ No newline at end of file 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 4cb5671..d84f9ba 100644 --- a/Verax_API_EF/Verax_API_EF/API_DbDataManager/DbManagerFormulaire.cs +++ b/Verax_API_EF/Verax_API_EF/API_DbDataManager/DbManagerFormulaire.cs @@ -21,22 +21,22 @@ public class DbManagerFormulaire : IFormulaireService switch (orderCriteria) { case FormOrderCriteria.None: - formulaireList = _context.FormSet.Select(f => f.ToModel()).ToList(); + formulaireList = _context.FormSet.Skip(index * count).Select(f => f.ToModel()).ToList(); break; case FormOrderCriteria.ByTheme: - formulaireList = _context.FormSet.OrderBy(f => f.Theme).Select(f => f.ToModel()).ToList(); + formulaireList = _context.FormSet.Skip(index * count).OrderBy(f => f.Theme).Select(f => f.ToModel()).ToList(); break; case FormOrderCriteria.ByLien: - formulaireList = _context.FormSet.OrderBy(f => f.Link).Select(f => f.ToModel()).ToList(); + formulaireList = _context.FormSet.Skip(index * count).OrderBy(f => f.Link).Select(f => f.ToModel()).ToList(); break; case FormOrderCriteria.ByDate: - formulaireList = _context.FormSet.OrderBy(f => f.DatePublication).Select(f => f.ToModel()).ToList(); + formulaireList = _context.FormSet.Skip(index * count).OrderBy(f => f.DatePublication).Select(f => f.ToModel()).ToList(); break; case FormOrderCriteria.ByPseudo: - formulaireList = _context.FormSet.OrderBy(f => f.UserEntityPseudo).Select(f => f.ToModel()).ToList(); + formulaireList = _context.FormSet.Skip(index * count).OrderBy(f => f.UserEntityPseudo).Select(f => f.ToModel()).ToList(); break; default: - formulaireList = _context.FormSet.Select(f => f.ToModel()).ToList(); + formulaireList = _context.FormSet.Skip(index * count).Select(f => f.ToModel()).ToList(); break; } return await Task.FromResult(formulaireList.AsEnumerable()); diff --git a/Verax_API_EF/Verax_API_EF/API_DbDataManager/DbManagerUser.cs b/Verax_API_EF/Verax_API_EF/API_DbDataManager/DbManagerUser.cs index be61dd4..b3928ae 100644 --- a/Verax_API_EF/Verax_API_EF/API_DbDataManager/DbManagerUser.cs +++ b/Verax_API_EF/Verax_API_EF/API_DbDataManager/DbManagerUser.cs @@ -15,6 +15,35 @@ public class DbManagerUser: IUserService _context = context; } + public async Task> GetAll(int index, int count, UserOrderCriteria orderCriteria) + { + List users = new List(); + switch(orderCriteria) + { + case UserOrderCriteria.None: + users = _context.UserSet.Skip(index * count).Select(u => u.ToModel()).ToList(); + break; + case UserOrderCriteria.ByFirstName: + users = _context.UserSet.Skip(index * count).OrderBy(u => u.Prenom).Select(u => u.ToModel()).ToList(); + break; + case UserOrderCriteria.ByLastName: + users = _context.UserSet.Skip(index * count).OrderBy(u => u.Nom).Select(u => u.ToModel()).ToList(); + break; + default: + users = _context.UserSet.Skip(index * count).Select(u => u.ToModel()).ToList(); + break; + + } + return await Task.FromResult(users.AsEnumerable()); + + } + + public async Task GetByPseudo(string pseudo) + { + var entity = _context.UserSet.FirstOrDefault(u => u.Pseudo == pseudo); + return await Task.FromResult(entity.ToModel()); + } + public async Task Create(User user) { var entity = new UserEntity() @@ -51,35 +80,10 @@ public class DbManagerUser: IUserService _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(int index, int count, UserOrderCriteria orderCriteria) - { - List users = new List(); - switch(orderCriteria) - { - case UserOrderCriteria.None: - users = _context.UserSet.Select(u => u.ToModel()).ToList(); - break; - case UserOrderCriteria.ByFirstName: - users = _context.UserSet.OrderBy(u => u.Prenom).Select(u => u.ToModel()).ToList(); - break; - case UserOrderCriteria.ByLastName: - users = _context.UserSet.OrderBy(u => u.Nom).Select(u => u.ToModel()).ToList(); - break; - default: - users = _context.UserSet.Select(u => u.ToModel()).ToList(); - break; - - } - return await Task.FromResult(users.AsEnumerable()); - } + + + + + } \ No newline at end of file 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 9767dd8..3c9e57f 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 Article a) => new() + public static ArticleDTO ToDTO(this Article? a) => new() { Id = a.Id, Title = a.Title, diff --git a/Verax_API_EF/Verax_API_EF/API_Services/API_Services.csproj b/Verax_API_EF/Verax_API_EF/API_Services/API_Services.csproj index b0ff0a6..4fe8b1d 100644 --- a/Verax_API_EF/Verax_API_EF/API_Services/API_Services.csproj +++ b/Verax_API_EF/Verax_API_EF/API_Services/API_Services.csproj @@ -7,6 +7,7 @@ + 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 c10505b..712ab2e 100644 --- a/Verax_API_EF/Verax_API_EF/API_Services/IArticleService.cs +++ b/Verax_API_EF/Verax_API_EF/API_Services/IArticleService.cs @@ -7,7 +7,7 @@ namespace API_Services Task> GetAllArticles(int index, int count, ArticleOrderCriteria orderCriterium); - Task GetArticleById(int id, int index, int count, ArticleOrderCriteria orderCriterium); + Task GetArticleById(int id); Task CreateArticle(Article article); diff --git a/Verax_API_EF/Verax_API_EF/API_Services/IArticleUserService.cs b/Verax_API_EF/Verax_API_EF/API_Services/IArticleUserService.cs new file mode 100644 index 0000000..3a07594 --- /dev/null +++ b/Verax_API_EF/Verax_API_EF/API_Services/IArticleUserService.cs @@ -0,0 +1,15 @@ +using Entities; + +namespace API_Services; + +public interface IArticleUserService +{ + Task> GetAllArticleUsers(); + Task GetArticleUser(string pseudo); + + Task CreateArticleUser(ArticleUserEntity articleUser); + + Task DeleteArticleUser(string pseudo); + + Task UpdateArticleUser(ArticleUserEntity articleUser); +} \ No newline at end of file diff --git a/Verax_API_EF/Verax_API_EF/API_Services/IUserService.cs b/Verax_API_EF/Verax_API_EF/API_Services/IUserService.cs index 1e447d3..771947f 100644 --- a/Verax_API_EF/Verax_API_EF/API_Services/IUserService.cs +++ b/Verax_API_EF/Verax_API_EF/API_Services/IUserService.cs @@ -1,18 +1,20 @@ -using Model; +using Entities; +using Model; namespace API_Services { public interface IUserService { + + Task> GetAll(int index, int count, UserOrderCriteria orderCriteria); + Task GetByPseudo(string pseudo); Task Create(User user); Task Update(User user, string pseudo); Task Delete(string pseudo); + - Task GetByPseudo(string pseudo); - - Task> GetAll(int index, int count, UserOrderCriteria orderCriteria); diff --git a/Verax_API_EF/Verax_API_EF/Entities/ArticleEntity.cs b/Verax_API_EF/Verax_API_EF/Entities/ArticleEntity.cs index f82543e..86e4c01 100644 --- a/Verax_API_EF/Verax_API_EF/Entities/ArticleEntity.cs +++ b/Verax_API_EF/Verax_API_EF/Entities/ArticleEntity.cs @@ -1,7 +1,10 @@ +using System.ComponentModel.DataAnnotations; + namespace Entities; public class ArticleEntity { + [Key] public long Id { get; set; } public string Title { get; set; } = string.Empty; public string Description { get; set; } = string.Empty; diff --git a/Verax_API_EF/Verax_API_EF/Entities/FormEntity.cs b/Verax_API_EF/Verax_API_EF/Entities/FormEntity.cs index 8a45973..6f5788a 100644 --- a/Verax_API_EF/Verax_API_EF/Entities/FormEntity.cs +++ b/Verax_API_EF/Verax_API_EF/Entities/FormEntity.cs @@ -1,7 +1,10 @@ +using System.ComponentModel.DataAnnotations; + namespace Entities; public class FormEntity { + [Key] public long Id { get; set; } public string Theme { get; set; } = string.Empty; public string DatePublication { get; set; } = string.Empty; diff --git a/Verax_API_EF/Verax_API_EF/Model/Article.cs b/Verax_API_EF/Verax_API_EF/Model/Article.cs index 497b56c..222e3a2 100644 --- a/Verax_API_EF/Verax_API_EF/Model/Article.cs +++ b/Verax_API_EF/Verax_API_EF/Model/Article.cs @@ -2,7 +2,7 @@ namespace Model; public class Article { - public long Id { get; set; } + public long Id; public string Title { get; set; } = string.Empty; public string Description { get; set; } = string.Empty; public string DatePublished { get; set; } = string.Empty;