try to implement unit of <ork
continuous-integration/drone/push Build is passing Details

pagination
Tony Fages 1 year ago
parent 43c30f5277
commit 0ccaeaeda0

@ -11,12 +11,13 @@ namespace API.Controllers
public class ArticleController : ControllerBase
{
private readonly IArticleService _articleService;
//private readonly IArticleService _articleService;
private readonly IDataManager _dataManager;
private readonly ILogger<ArticleController> _logger;
public ArticleController(IArticleService articleService, ILogger<ArticleController> logger)
public ArticleController(IDataManager dataManager, ILogger<ArticleController> logger)
{
this._articleService = articleService;
this._dataManager = dataManager;
this._logger = logger;
}
@ -26,7 +27,7 @@ namespace API.Controllers
_logger.LogInformation("Executing {Action} - with parameters: {Parameters}",nameof(GetAllArticles), index, count, orderCriterium);
try
{
var result = (await _articleService.GetAllArticles(index, count, orderCriterium)).Select(a => a.ToDTO());
var result = (await _dataManager.ArticleService.GetAllArticles(index, count, orderCriterium)).Select(a => a.ToDTO());
if (result == null)
{
return NotFound();
@ -46,7 +47,7 @@ namespace API.Controllers
_logger.LogInformation("Executing {Action} - with parameters: {Parameters}",nameof(GetArticleById), id);
try
{
var result = (await _articleService.GetArticleById(id)).ToDTO();
var result = (await _dataManager.ArticleService.GetArticleById(id)).ToDTO();
if (result == null)
{
return NotFound($"Article ID {id} not found");
@ -68,7 +69,7 @@ namespace API.Controllers
_logger.LogInformation("Executing {Action} - with parameters: {Parameters}",nameof(CreateArticle), article);
try
{
var result = (await _articleService.CreateArticle(article)).ToDTO();
var result = (await _dataManager.ArticleService.CreateArticle(article)).ToDTO();
if (result == null)
{
return BadRequest($"Article not created");
@ -88,7 +89,7 @@ namespace API.Controllers
_logger.LogInformation("Executing {Action} - with parameters: {Parameters}",nameof(DeleteArticle), id);
try
{
var result = await _articleService.DeleteArticle(id);
var result = await _dataManager.ArticleService.DeleteArticle(id);
if (result == null)
{
return NotFound($"Article ID {id} not found");
@ -108,7 +109,7 @@ namespace API.Controllers
_logger.LogInformation("Executing {Action} - with parameters: {Parameters}",nameof(UpdateArticle), id, a);
try
{
var result = await _articleService.UpdateArticle(id, a);
var result = await _dataManager.ArticleService.UpdateArticle(id, a);
if (result == false)
{
return NotFound($"Article ID {id} not found");

@ -12,12 +12,13 @@ namespace API.Controllers
[ApiController]
public class FormulaireController : ControllerBase
{
private readonly IFormulaireService _form;
//private readonly IFormulaireService _form;
private readonly IDataManager _dataManager;
private readonly ILogger<FormulaireController> _logger;
public FormulaireController(IFormulaireService iform, ILogger<FormulaireController> logger)
public FormulaireController(IDataManager dataManager, ILogger<FormulaireController> logger)
{
this._form = iform;
this._dataManager = dataManager;
this._logger = logger;
}
@ -27,7 +28,7 @@ namespace API.Controllers
_logger.LogInformation("Executing {Action} - with parameters: {Parameters}",nameof(GetAllForm), index, count, orderCriteria);
try
{
var result = (await _form.GetAllForm(index, count, orderCriteria)).Select(f => f.ToDTO());
var result = (await _dataManager.FormulaireService.GetAllForm(index, count, orderCriteria)).Select(f => f.ToDTO());
if (result == null)
{
return NotFound($"No form found");
@ -48,7 +49,7 @@ namespace API.Controllers
_logger.LogInformation("Executing {Action} - with parameters: {Parameters}",nameof(GetById), id);
try
{
var result = (await _form.GetById(id)).ToDTO();
var result = (await _dataManager.FormulaireService.GetById(id)).ToDTO();
if (result == null)
{
return NotFound($"form ID {id} not found");
@ -70,7 +71,7 @@ namespace API.Controllers
_logger.LogInformation("Executing {Action} - with parameters: {Parameters}",nameof(CreateForm), formulaire);
try
{
var result = (await _form.CreateForm(formulaire)).ToDTO();
var result = (await _dataManager.FormulaireService.CreateForm(formulaire)).ToDTO();
if (result == null)
{
return BadRequest($"Form Id {formulaire.Id} already exists");
@ -90,7 +91,7 @@ namespace API.Controllers
_logger.LogInformation("Executing {Action} - with parameters: {Parameters}",nameof(DeleteForm), id);
try
{
var result = await _form.DeleteForm(id);
var result = await _dataManager.FormulaireService.DeleteForm(id);
if (result == false)
{
return NotFound($"Form Id {id} not found");
@ -111,7 +112,7 @@ namespace API.Controllers
try
{
var result = await _form.UpdateForm(id, formulaire);
var result = await _dataManager.FormulaireService.UpdateForm(id, formulaire);
if (result == false)
{
return NotFound($"form Id {id} not found");

@ -12,12 +12,13 @@ namespace API.Controllers
[ApiController]
public class UserController : ControllerBase
{
private readonly IUserService _us;
//private readonly IUserService _us;
private readonly IDataManager _dataManager;
private readonly ILogger<UserController> _logger;
public UserController(IUserService us, ILogger<UserController> logger)
public UserController(IDataManager dataManager, ILogger<UserController> logger)
{
this._us = us;
this._logger = logger;
this._dataManager = dataManager;
}
[HttpGet("/users")]
@ -26,7 +27,7 @@ namespace API.Controllers
_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());
var result = (await _dataManager.UserService.GetAll(index, count, orderCriteria)).Select(u => u.ToDTO());
if (result == null)
{
return NotFound($"No user found with the given parameters");
@ -46,7 +47,7 @@ namespace API.Controllers
_logger.LogInformation("Executing {Action} - with parameters: {Parameters}",nameof(GetByPseudo), pseudo);
try
{
var result = (await _us.GetByPseudo(pseudo)).ToDTO();
var result = (await _dataManager.UserService.GetByPseudo(pseudo)).ToDTO();
if (result == null)
{
return NotFound($"Psuedo {pseudo} not found");
@ -67,7 +68,7 @@ namespace API.Controllers
_logger.LogInformation("Executing {Action} - with parameters: {Parameters}",nameof(Create), user);
try
{
var result = await _us.Create(user);
var result = await _dataManager.UserService.Create(user);
if (result == false)
{
return BadRequest($"User {user.Pseudo} already exists");
@ -89,7 +90,7 @@ namespace API.Controllers
_logger.LogInformation("Executing {Action} - with parameters: {Parameters}",nameof(Update), user, pseudo);
try
{
var result = await _us.Update(user,pseudo);
var result = await _dataManager.UserService.Update(user,pseudo);
if (result == false)
{
return NotFound();
@ -110,7 +111,7 @@ namespace API.Controllers
_logger.LogInformation("Executing {Action} - with parameters: {Parameters}",nameof(Delete), pseudo);
try
{
var result = await _us.Delete(pseudo);
var result = await _dataManager.UserService.Delete(pseudo);
if (result == false)
{
return NotFound();
@ -130,7 +131,7 @@ namespace API.Controllers
_logger.LogInformation("Executing {Action} - with parameters: {Parameters}",nameof(GetAllArticleUsers), "");
try
{
var result = (await _us.GetAllArticleUsers()).Select(u => u.ToDTO());
var result = (await _dataManager.UserService.GetAllArticleUsers()).Select(u => u.ToDTO());
if (result == null)
{
return NoContent();
@ -150,7 +151,7 @@ namespace API.Controllers
_logger.LogInformation("Executing {Action} - with parameters: {Parameters}",nameof(GetArticleUser), pseudo);
try
{
var result = (await _us.GetArticleUser(pseudo)).Select(a => a.ToDTO());
var result = (await _dataManager.UserService.GetArticleUser(pseudo)).Select(a => a.ToDTO());
if (result == null)
{
return NoContent();
@ -171,7 +172,7 @@ namespace API.Controllers
try
{
Console.WriteLine(articleUser);
var result = await _us.CreateArticleUser(articleUser);
var result = await _dataManager.UserService.CreateArticleUser(articleUser);
if (result == null)
{
return BadRequest($"ArticleUser {articleUser.UserEntityPseudo} already exists");
@ -191,7 +192,7 @@ namespace API.Controllers
_logger.LogInformation("Executing {Action} - with parameters: {Parameters}",nameof(DeleteArticleUser), pseudo);
try
{
var result = await _us.DeleteArticleUser(pseudo);
var result = await _dataManager.UserService.DeleteArticleUser(pseudo);
if (!result)
{
return BadRequest($"ArticleUser {pseudo} does not exist");
@ -211,7 +212,7 @@ namespace API.Controllers
_logger.LogInformation("Executing {Action} - with parameters: {Parameters}",nameof(UpdateArticleUser), articleUser);
try
{
var result = await _us.UpdateArticleUser(articleUser);
var result = await _dataManager.UserService.UpdateArticleUser(articleUser);
if (!result)
{
return BadRequest($"ArticleUser {articleUser.UserEntityPseudo} does not exist");

@ -2,6 +2,7 @@ using API_Services;
using DbContextLib;
using DbDataManager;
using Microsoft.EntityFrameworkCore;
using Model;
using StubbedContextLib;
var builder = WebApplication.CreateBuilder(args);
@ -20,9 +21,9 @@ builder.Services.AddDbContext<LibraryContext>(options =>
options.UseSqlite("Data Source=Entity_FrameWork.Article.db");
});
builder.Services.AddScoped<IArticleService, DbManagerArticle>();
builder.Services.AddScoped<IUserService, DbManagerUser>();
builder.Services.AddScoped<IFormulaireService, DbManagerFormulaire>();
builder.Services.AddScoped<IDataManager, DbManager>();
var app = builder.Build();

@ -3,8 +3,11 @@ using API_Services;
public interface IDataManager
{
IArticleService ArticleService { get; }
IUserService UserService { get; }
IFormulaireService FormulaireService { get; }
}
}

Loading…
Cancel
Save