🚧 Modification des services
continuous-integration/drone/push Build is failing Details

pull/29/head
Clement CHIEU 1 year ago
parent 5c133445a5
commit ffcf615bfc

@ -25,7 +25,10 @@
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Services\Services.csproj" />
<ProjectReference Include="..\DbContextLib\DbContextLib.csproj" />
<ProjectReference Include="..\Dto\Dto.csproj" />
<ProjectReference Include="..\ModelToEntities\ModelToEntities.csproj" />
<ProjectReference Include="..\Shared\Shared.csproj" />
</ItemGroup>
</Project>

@ -1,34 +1,34 @@
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Services;
using Shared;
namespace API.Controllers
{
[Route("api/[controller]")]
[Authorize]
[ApiController]
public class InquiriesController : Controller
public class InquiriesController : ControllerBase
{
private IDataService _inquiryDataService;
private IUserService<> _inquiryUserService;
private readonly ILogger<UserController> _logger;
public InquiriesController(IDataService inquiryDataService)
public InquiriesController(IUserService<> inquiryUserService)
{
_inquiryDataService = inquiryDataService;
_inquiryUserService = inquiryUserService;
}
[HttpGet("inquiries/{page}/{number}")]
public IActionResult GetInquiries(int page, int number)
{
var nbInquiry = _inquiryDataService.GetInquiries(page, number).Count();
var nbInquiry = _inquiryUserService.GetInquiries(page, number).Count();
if (nbInquiry == 0)
{
_logger.LogError("[ERREUR] Aucune enquête trouvé.");
return StatusCode(204);
}
_logger.LogInformation("[INFORMATION] {nb} Enquête(s) trouvée(s)", nbInquiry);
return Ok(_inquiryDataService.GetInquiries(page, number));
return Ok(_inquiryUserService.GetInquiries(page, number));
}
[HttpGet("inquiry/id/{id}")]
@ -37,7 +37,7 @@ namespace API.Controllers
try
{
_logger.LogInformation("[INFORMATION] Enquête avec l'id {id} a été trouvé.", id);
return Ok(_inquiryDataService.GetInquiryById(id));
return Ok(_inquiryUserService.GetInquiryById(id));
}
catch (ArgumentException)
{
@ -52,7 +52,7 @@ namespace API.Controllers
try
{
_logger.LogInformation("[INFORMATION] Enquête avec le titre {title} a été trouvé.", title);
return Ok(_inquiryDataService.GetInquiryByTitle(title));
return Ok(_inquiryUserService.GetInquiryByTitle(title));
}
catch (ArgumentException)
{

@ -1,7 +1,6 @@
using Dto;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Services;
using Shared;
namespace API.Controllers
{
@ -9,29 +8,33 @@ namespace API.Controllers
[Authorize]
[ApiVersion("1.0")]
[ApiController]
public class UserController : Controller
public class UserController : ControllerBase
{
private IDataService _userDataService;
private IUserService<> _userUserService;
private readonly ILogger<UserController> _logger;
public UserController(IDataService userDataService, ILogger<UserController> logger)
public UserController(IUserService<> userUserService, ILogger<UserController> logger)
{
_userDataService = userDataService;
_userUserService = userUserService;
_logger = logger;
}
[HttpGet("users/{page}/{number}")]
public IActionResult GetUsers(int page, int number)
{
var nbUser = _userDataService.GetUsers(page, number).Count();
var getUsers = new InClassName(page, number);
_userUserService.GetUsers(getUsers);
var nbUser = getUsers.ReturnValue.Count();
if(nbUser == 0)
{
_logger.LogError("[ERREUR] Aucun utilisateur trouvé.");
return StatusCode(204);
}
_logger.LogInformation("[INFORMATION] {nb} Utilisateur(s) trouvé(s)", nbUser);
return Ok(_userDataService.GetUsers(page, number));
var value = new InClassName(page, number);
_userUserService.GetUsers(value);
return Ok(value.ReturnValue);
}
[HttpGet("user/id/{id}")]
@ -40,7 +43,7 @@ namespace API.Controllers
try
{
_logger.LogInformation("[INFORMATION] Utilisateur avec l'id {id} a été trouvé.", id);
return Ok(_userDataService.GetUserById(id));
return Ok(_userUserService.GetUserById(id));
} catch (ArgumentException)
{
_logger.LogError("[ERREUR] Aucun utilisateur trouvé avec l'id {id}.", id);
@ -54,7 +57,7 @@ namespace API.Controllers
try
{
_logger.LogInformation("[INFORMATION] Utilisateur avec l'username {username} a été trouvé.", username);
return Ok(_userDataService.GetUserByUsername(username));
return Ok(_userUserService.GetUserByUsername(username));
}catch (ArgumentException)
{
_logger.LogError("[ERREUR] Aucun utilisateur trouvé avec l'username {username}.", username);
@ -66,11 +69,11 @@ namespace API.Controllers
[HttpDelete]
public IActionResult DeleteUser(int id)
{
var success = _userDataService.DeleteUser(id);
var success = _userUserService.DeleteUser(id);
if(success)
{
_logger.LogInformation("[INFORMATION] L'utilisateur avec l'id {id} a été supprimé.", id);
return Ok(_userDataService.DeleteUser(id));
return Ok(_userUserService.DeleteUser(id));
} else
{
_logger.LogError("[ERREUR] Aucun utilisateur trouvé avec l'id {id}.", id);
@ -88,7 +91,7 @@ namespace API.Controllers
}
// return Ok(_userDataService.CreateUser(username, password, email, isAdmin));
_logger.LogInformation("[INFORMATION] Un utilisateur a été créé : username - {username}, password - {password}, email - {email}, isAdmin - {isAdmin}", dto.Username, dto.Password, dto.Email, dto.IsAdmin);
return Created(nameof(GetUsers), _userDataService.CreateUser(dto.Username, dto.Password, dto.Email, dto.IsAdmin));
return Created(nameof(GetUsers), _userUserService.CreateUser(dto.Username, dto.Password, dto.Email, dto.IsAdmin));
}
[HttpPut]
@ -107,7 +110,7 @@ namespace API.Controllers
if(userDTO != null)
{
_logger.LogInformation("[INFORMATION] La mise à jour de l'utilsiateur avec l'id {id} a été effectuée", id);
return Ok(_userDataService.UpdateUser(id, userDTO));
return Ok(_userUserService.UpdateUser(id, userDTO));
}
_logger.LogError("[ERREUR] Aucun utilisateur trouvé avec l'id {id}.", id);
return NotFound();

@ -1,10 +1,13 @@
using API;
using DbContextLib;
using Dto;
using Microsoft.AspNetCore.Identity;
using Microsoft.AspNetCore.Mvc.Versioning;
using Microsoft.EntityFrameworkCore;
using Microsoft.OpenApi.Models;
using Services;
using ModelToEntities.Business;
using ModelToEntities.Service;
using Shared;
var builder = WebApplication.CreateBuilder(args);
@ -14,7 +17,8 @@ builder.Services.AddControllers();
// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
builder.Services.AddEndpointsApiExplorer();
builder.Services.AddSwaggerGen();
builder.Services.AddScoped<IDataService, UserDataService>();
builder.Services.AddScoped<IUserService<UserDTO>, UserDataService>();
builder.Services.AddScoped<IInquiryService<Inquiry>, InquiryDataService>();
builder.Services.AddDbContext<DbContext, UserDbContext>();
builder.Services.AddDbContext<WebAPIDbContext>(options => options.UseInMemoryDatabase("appDb"));
builder.Services.AddIdentityApiEndpoints<IdentityUser>().AddEntityFrameworkStores<WebAPIDbContext>();

@ -15,8 +15,6 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TestEF", "TestEF\TestEF.csp
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DbContextLib", "DbContextLib\DbContextLib.csproj", "{BDCB3BFD-B744-4BC0-BCFC-78E08600203A}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Services", "Services\Services.csproj", "{9BD3DCBA-AFD8-47FA-B07C-613B53E63968}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TestConsoleAPI", "TestConsoleAPI\TestConsoleAPI.csproj", "{46376AEF-4093-4AE9-AD2F-F51B541F9C6A}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "StubbedContextLib", "StubbedContextLib\StubbedContextLib.csproj", "{B64941C9-0550-4C47-89B6-396F6DB0486D}"
@ -25,6 +23,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Dto", "Dto\Dto.csproj", "{9
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Model", "Model\Model.csproj", "{EDDA59D4-BD38-46BF-8292-26A47187B76F}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Shared", "Shared\Shared.csproj", "{9DC1D2DF-AC2B-4CF5-BB30-2FB6533BFF76}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
@ -55,10 +55,6 @@ Global
{BDCB3BFD-B744-4BC0-BCFC-78E08600203A}.Debug|Any CPU.Build.0 = Debug|Any CPU
{BDCB3BFD-B744-4BC0-BCFC-78E08600203A}.Release|Any CPU.ActiveCfg = Release|Any CPU
{BDCB3BFD-B744-4BC0-BCFC-78E08600203A}.Release|Any CPU.Build.0 = Release|Any CPU
{9BD3DCBA-AFD8-47FA-B07C-613B53E63968}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{9BD3DCBA-AFD8-47FA-B07C-613B53E63968}.Debug|Any CPU.Build.0 = Debug|Any CPU
{9BD3DCBA-AFD8-47FA-B07C-613B53E63968}.Release|Any CPU.ActiveCfg = Release|Any CPU
{9BD3DCBA-AFD8-47FA-B07C-613B53E63968}.Release|Any CPU.Build.0 = Release|Any CPU
{46376AEF-4093-4AE9-AD2F-F51B541F9C6A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{46376AEF-4093-4AE9-AD2F-F51B541F9C6A}.Debug|Any CPU.Build.0 = Debug|Any CPU
{46376AEF-4093-4AE9-AD2F-F51B541F9C6A}.Release|Any CPU.ActiveCfg = Release|Any CPU
@ -75,6 +71,10 @@ Global
{EDDA59D4-BD38-46BF-8292-26A47187B76F}.Debug|Any CPU.Build.0 = Debug|Any CPU
{EDDA59D4-BD38-46BF-8292-26A47187B76F}.Release|Any CPU.ActiveCfg = Release|Any CPU
{EDDA59D4-BD38-46BF-8292-26A47187B76F}.Release|Any CPU.Build.0 = Release|Any CPU
{9DC1D2DF-AC2B-4CF5-BB30-2FB6533BFF76}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{9DC1D2DF-AC2B-4CF5-BB30-2FB6533BFF76}.Debug|Any CPU.Build.0 = Debug|Any CPU
{9DC1D2DF-AC2B-4CF5-BB30-2FB6533BFF76}.Release|Any CPU.ActiveCfg = Release|Any CPU
{9DC1D2DF-AC2B-4CF5-BB30-2FB6533BFF76}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE

@ -2,7 +2,7 @@
using Entities;
using ModelToEntities.Business;
namespace ModelToEntities
namespace ModelToEntities.Service
{
public static class UserMapper
{

@ -24,6 +24,7 @@
<ProjectReference Include="..\Dto\Dto.csproj" />
<ProjectReference Include="..\EntityFramework\Entities.csproj" />
<ProjectReference Include="..\Model\Model.csproj" />
<ProjectReference Include="..\Shared\Shared.csproj" />
</ItemGroup>
</Project>

@ -0,0 +1,22 @@
using ModelToEntities.Business;
using Shared;
namespace ModelToEntities.Service;
public class InquiryDataService : IInquiryService<Inquiry>
{
public IEnumerable<Inquiry> GetInquiries(int page, int number)
{
throw new NotImplementedException();
}
public Inquiry GetInquiryById(int id)
{
throw new NotImplementedException();
}
public Inquiry GetInquiryByTitle(string title)
{
throw new NotImplementedException();
}
}

@ -1,11 +1,11 @@
using DbContextLib;
using Dto;
using Dto;
using Microsoft.EntityFrameworkCore;
using ModelToEntities;
using ModelToEntities.Business;
using Shared;
namespace Services
namespace ModelToEntities.Service
{
public class UserDataService : IDataService
public class UserDataService : IUserService<UserDTO>
{
private UserDbContext DbContext { get; set; }
public UserDataService(UserDbContext context)
@ -71,7 +71,7 @@ namespace Services
public UserDTO CreateUser(string username, string password, string email, bool isAdmin)
{
var newUserEntity = new UserDTO
var newUserEntity = new User
{
Username = username,
Password = password,
@ -82,20 +82,5 @@ namespace Services
DbContext.SaveChangesAsync();
return newUserEntity;
}
public IEnumerable<InquiryDTO> GetInquiries(int page, int number)
{
throw new NotImplementedException();
}
public InquiryDTO GetInquiryById(int id)
{
throw new NotImplementedException();
}
public InquiryDTO GetInquiryByTitle(string title)
{
throw new NotImplementedException();
}
}
}

@ -1,18 +0,0 @@
using Dto;
using ModelToEntities.Business;
namespace Services
{
public interface IDataService
{
public IEnumerable<UserDTO> GetUsers(int page, int number);
public UserDTO GetUserById(int id);
public UserDTO GetUserByUsername(string username);
public bool DeleteUser(int id);
public UserDTO UpdateUser(int id, UserDTO user);
public UserDTO CreateUser(string username, string password, string email, bool isAdmin);
public IEnumerable<InquiryDTO> GetInquiries(int page, int number);
public InquiryDTO GetInquiryById(int id);
public InquiryDTO GetInquiryByTitle(string title);
}
}

@ -1,28 +0,0 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="8.0.2" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="8.0.2">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="8.0.2">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="8.0.0" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\DbContextLib\DbContextLib.csproj" />
<ProjectReference Include="..\EntityFramework\Entities.csproj" />
<ProjectReference Include="..\ModelToEntities\ModelToEntities.csproj" />
</ItemGroup>
</Project>

@ -0,0 +1,8 @@
namespace Shared;
public interface IInquiryService<TInquiry>
{
public IEnumerable<TInquiry> GetInquiries(int page, int number);
public TInquiry GetInquiryById(int id);
public TInquiry GetInquiryByTitle(string title);
}

@ -0,0 +1,12 @@
namespace Shared
{
public interface IUserService<TUser>
{
public IEnumerable<TUser> GetUsers(int page, int number);
public TUser GetUserById(int id);
public TUser GetUserByUsername(string username);
public bool DeleteUser(int id);
public TUser UpdateUser(int id, TUser user);
public TUser CreateUser(string username, string password, string email, bool isAdmin);
}
}

@ -0,0 +1,9 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
</Project>

@ -8,7 +8,7 @@ using Microsoft.Data.Sqlite;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options;
using Services;
using ModelToEntities.Service;
var connection = new SqliteConnection("DataSource=:memory:");
connection.Open();

@ -15,7 +15,6 @@
<ProjectReference Include="..\API\API.csproj" />
<ProjectReference Include="..\DbContextLib\DbContextLib.csproj" />
<ProjectReference Include="..\ModelToEntities\ModelToEntities.csproj" />
<ProjectReference Include="..\Services\Services.csproj" />
</ItemGroup>
</Project>

Loading…
Cancel
Save