Modification de la localisation des mapper et suppression des dépendances circulaires
continuous-integration/drone/push Build is passing Details

pull/29/head
Clement CHIEU 1 year ago
parent 1fc4affc89
commit 11d970cd88

@ -27,8 +27,9 @@
<ItemGroup> <ItemGroup>
<ProjectReference Include="..\DbContextLib\DbContextLib.csproj" /> <ProjectReference Include="..\DbContextLib\DbContextLib.csproj" />
<ProjectReference Include="..\Dto\Dto.csproj" /> <ProjectReference Include="..\Dto\Dto.csproj" />
<ProjectReference Include="..\ModelToEntities\ModelToEntities.csproj" /> <ProjectReference Include="..\DbDataManager\DbDataManager.csproj" />
<ProjectReference Include="..\Shared\Shared.csproj" /> <ProjectReference Include="..\Shared\Shared.csproj" />
<ProjectReference Include="..\StubbedContextLib\StubbedContextLib.csproj" />
</ItemGroup> </ItemGroup>
</Project> </Project>

@ -1,8 +1,6 @@
using API.Service; using Dto;
using Dto;
using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
using ModelToEntities.Service;
using Shared; using Shared;
namespace API.Controllers namespace API.Controllers

@ -1,12 +1,13 @@
using API; using API;
using API.Service; using API.Service;
using DbContextLib; using DbContextLib;
using DbDataManager.Service;
using Dto; using Dto;
using Entities;
using Microsoft.AspNetCore.Identity; using Microsoft.AspNetCore.Identity;
using Microsoft.AspNetCore.Mvc.Versioning; using Microsoft.AspNetCore.Mvc.Versioning;
using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore;
using Microsoft.OpenApi.Models; using Microsoft.OpenApi.Models;
using ModelToEntities.Service;
using Shared; using Shared;
var builder = WebApplication.CreateBuilder(args); var builder = WebApplication.CreateBuilder(args);
@ -17,9 +18,9 @@ builder.Services.AddControllers();
// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle // Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
builder.Services.AddEndpointsApiExplorer(); builder.Services.AddEndpointsApiExplorer();
builder.Services.AddSwaggerGen(); builder.Services.AddSwaggerGen();
builder.Services.AddScoped<IUserService<UserDTO>, UserDataService>(); builder.Services.AddScoped<IUserService<UserEntity>, UserDataService>();
builder.Services.AddScoped<IUserService<UserDTO>, UserDataServiceApi>(); builder.Services.AddScoped<IUserService<UserDTO>, UserDataServiceApi>();
builder.Services.AddScoped<IInquiryService<InquiryDTO>, InquiryDataService>(); builder.Services.AddScoped<IInquiryService<InquiryEntity>, InquiryDataService>();
builder.Services.AddScoped<IInquiryService<InquiryDTO>, InquiryDataServiceApi>(); builder.Services.AddScoped<IInquiryService<InquiryDTO>, InquiryDataServiceApi>();
builder.Services.AddDbContext<DbContext, UserDbContext>(); builder.Services.AddDbContext<DbContext, UserDbContext>();
builder.Services.AddDbContext<WebAPIDbContext>(options => options.UseInMemoryDatabase("appDb")); builder.Services.AddDbContext<WebAPIDbContext>(options => options.UseInMemoryDatabase("appDb"));

@ -1,13 +1,19 @@
using Dto; using Dto;
using Entities;
using Shared; using Shared;
using Shared.Mapper;
namespace API.Service; namespace API.Service;
public class InquiryDataServiceApi(IInquiryService<InquiryDTO> inquiryService) : IInquiryService<InquiryDTO> public class InquiryDataServiceApi(IInquiryService<InquiryEntity> inquiryService) : IInquiryService<InquiryDTO>
{ {
public IEnumerable<InquiryDTO> GetInquiries(int page, int number) => inquiryService.GetInquiries(page, number); public IEnumerable<InquiryDTO> GetInquiries(int page, int number)
{
var inquiries = inquiryService.GetInquiries(page, number);
return inquiries.Select(i => i.FromEntityToDTO()).ToList();
}
public InquiryDTO GetInquiryById(int id) => inquiryService.GetInquiryById(id); public InquiryDTO GetInquiryById(int id) => inquiryService.GetInquiryById(id).FromEntityToDTO();
public InquiryDTO GetInquiryByTitle(string title) => inquiryService.GetInquiryByTitle(title); public InquiryDTO GetInquiryByTitle(string title) => inquiryService.GetInquiryByTitle(title).FromEntityToDTO();
} }

@ -1,20 +1,27 @@
using Dto; using Dto;
using Entities;
using Shared; using Shared;
using Shared.Mapper;
namespace API.Service; namespace API.Service;
public class UserDataServiceApi(IUserService<UserDTO> userService) : IUserService<UserDTO> public class UserDataServiceApi(IUserService<UserEntity> userService) : IUserService<UserDTO>
{ {
public IEnumerable<UserDTO> GetUsers(int page, int number) => userService.GetUsers(page, number); public IEnumerable<UserDTO> GetUsers(int page, int number)
{
var usersEntities = userService.GetUsers(page, number);
return usersEntities.Select(e => e.FromEntityToDTO()).ToList();
}
public UserDTO GetUserById(int id) => userService.GetUserById(id); public UserDTO GetUserById(int id) => userService.GetUserById(id).FromEntityToDTO();
public UserDTO GetUserByUsername(string username) => userService.GetUserByUsername(username); public UserDTO GetUserByUsername(string username) => userService.GetUserByUsername(username).FromEntityToDTO();
public bool DeleteUser(int id) => userService.DeleteUser(id); public bool DeleteUser(int id) => userService.DeleteUser(id);
public UserDTO UpdateUser(int id, UserDTO user) => userService.UpdateUser(id, user); public UserDTO UpdateUser(int id, UserDTO user) =>
userService.UpdateUser(id, user.FromDTOToEntity()).FromEntityToDTO();
public UserDTO CreateUser(string username, string password, string email, bool isAdmin) => public UserDTO CreateUser(string username, string password, string email, bool isAdmin) =>
userService.CreateUser(username, password, email, isAdmin); userService.CreateUser(username, password, email, isAdmin).FromEntityToDTO();
} }

@ -7,7 +7,7 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "API", "API\API.csproj", "{6
EndProject EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Entities", "EntityFramework\Entities.csproj", "{6D079CDA-C000-4833-98A0-D07D153EA264}" Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Entities", "EntityFramework\Entities.csproj", "{6D079CDA-C000-4833-98A0-D07D153EA264}"
EndProject EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ModelToEntities", "ModelToEntities\ModelToEntities.csproj", "{ADCC427D-A3CD-431C-A90B-F9369C4584E8}" Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DbDataManager", "DbDataManager\DbDataManager.csproj", "{ADCC427D-A3CD-431C-A90B-F9369C4584E8}"
EndProject EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TestAPI", "TestAPI\TestAPI.csproj", "{17025B90-8B2A-49E9-97D3-1A84A208DF50}" Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TestAPI", "TestAPI\TestAPI.csproj", "{17025B90-8B2A-49E9-97D3-1A84A208DF50}"
EndProject EndProject

@ -29,11 +29,11 @@ namespace DbContextLib
protected override void OnModelCreating(ModelBuilder modelBuilder) protected override void OnModelCreating(ModelBuilder modelBuilder)
{ {
modelBuilder.Entity<UserEntity>().ToTable("user");
modelBuilder.Entity<ContentLessonEntity>().HasKey(c => c.LessonId); modelBuilder.Entity<ContentLessonEntity>().HasKey(c => c.LessonId);
modelBuilder.Entity<ContentLessonEntity>().HasKey(c => c.LessonPartId); modelBuilder.Entity<ContentLessonEntity>().HasKey(c => c.LessonPartId);
modelBuilder.Entity<SuccessEntity>().HasKey(s => s.UserId); modelBuilder.Entity<SuccessEntity>().HasKey(s => s.UserId);
modelBuilder.Entity<SuccessEntity>().HasKey(s => s.InquiryId); modelBuilder.Entity<SuccessEntity>().HasKey(s => s.InquiryId);
modelBuilder.Entity<InquiryEntity>().HasKey(s => s.Id);
base.OnModelCreating(modelBuilder); base.OnModelCreating(modelBuilder);
} }
} }

@ -0,0 +1,38 @@
using Dto;
using Entities;
using ModelToEntities.Business;
namespace Shared.Mapper;
public static class BlackListMapper
{
public static BlackListDTO FromModelToDTO(BlackList model)
{
return new BlackListDTO(model.Email, model.ExpirationDate);
}
public static BlackListDTO FromEntityToDTO(BlackListEntity ent)
{
return new BlackListDTO(ent.Email, ent.ExpirationDate);
}
public static BlackList FromDTOToModel(BlackListDTO dto)
{
return new BlackList(dto.Email, dto.ExpirationDate);
}
public static BlackList FromEntityToModel(BlackListEntity ent)
{
return new BlackList(ent.Email, ent.ExpirationDate);
}
public static BlackListEntity FromDTOToEntity(BlackListDTO dto)
{
return new BlackListEntity(dto.Email, dto.ExpirationDate);
}
public static BlackListEntity FromModelToEntity(BlackList model)
{
return new BlackListEntity(model.Email, model.ExpirationDate);
}
}

@ -0,0 +1,34 @@
using Dto;
using Entities;
using ModelToEntities.Business;
namespace Shared.Mapper;
public static class ContentLessonMapper
{
public static ContentLesson FromDTOToModel(this ContentLessonDTO dto)
{
return new ContentLesson(dto.LessonId, dto.LessonPartId);
}
public static ContentLesson FromEntityToModel(this ContentLessonEntity ent)
{
return new ContentLesson(ent.LessonId, ent.LessonPartId);
}
public static ContentLessonDTO FromModelToDTO(this ContentLesson les)
{
return new ContentLessonDTO(les.LessonId, les.LessonPartId);
}
public static ContentLessonDTO FromEntityToDTO(this ContentLessonEntity ent)
{
return new ContentLessonDTO(ent.LessonId, ent.LessonPartId);
}
public static ContentLessonEntity FromModelToEntity(this ContentLesson les)
{
return new ContentLessonEntity(les.LessonId, new LessonEntity(les.LessonId), les.LessonPartId,
new ParagraphEntity(les.LessonPartId));
}
}

@ -0,0 +1,44 @@
using Dto;
using Entities;
using ModelToEntities.Business;
namespace Shared.Mapper;
public static class InquiryMapper
{
public static Inquiry FromDTOToModel(this InquiryDTO InqDto)
{
return new Inquiry(InqDto.Id, InqDto.Title, InqDto.Description, InqDto.IsUser, InqDto.Database,
InqDto.InquiryTable);
}
public static Inquiry FromEntityToModel(this InquiryEntity InqEntity)
{
return new Inquiry(InqEntity.Id, InqEntity.Title, InqEntity.Description, InqEntity.IsUser,
InqEntity.Database.OwnerId, InqEntity.InquiryTable.OwnerId);
}
public static InquiryEntity FromModelToEntity(this Inquiry Inq)
{
return new InquiryEntity(Inq.Id, Inq.Title, Inq.Description, Inq.IsUser, new InquiryTableEntity(Inq.Database),
new SolutionEntity(Inq.InquiryTable));
}
public static InquiryEntity FromDTOToEntity(this InquiryDTO InqDto)
{
return new InquiryEntity(InqDto.Id, InqDto.Title, InqDto.Description, InqDto.IsUser,
new InquiryTableEntity(InqDto.Database), new SolutionEntity(InqDto.InquiryTable));
}
public static InquiryDTO FromModelToDTO(this Inquiry Inq)
{
return new InquiryDTO(Inq.Id, Inq.Title, Inq.Description, Inq.IsUser, Inq.Database, Inq.InquiryTable);
}
public static InquiryDTO FromEntityToDTO(this InquiryEntity InqEntity)
{
return new InquiryDTO(InqEntity.Id, InqEntity.Title, InqEntity.Description, InqEntity.IsUser,
InqEntity.Database.OwnerId, InqEntity.InquiryTable.OwnerId);
}
}

@ -0,0 +1,38 @@
using Dto;
using Entities;
using ModelToEntities.Business;
namespace Shared.Mapper;
public static class InquiryTableMapper
{
public static InquiryTable FromDTOToModel(this InquiryTableDTO InqTDto)
{
return new InquiryTable(InqTDto.OwnerId, InqTDto.ConnectionInfo, InqTDto.DatabaseName);
}
public static InquiryTable FromEntityToModel(this InquiryTableEntity InqTEntity)
{
return new InquiryTable(InqTEntity.OwnerId, InqTEntity.ConnectionInfo, InqTEntity.DatabaseName);
}
public static InquiryTableDTO FromModelToDTO(this InquiryTable InqT)
{
return new InquiryTableDTO(InqT.OwnerId, InqT.DatabaseName, InqT.ConnectionInfo);
}
public static InquiryTableDTO FromEntityToDTO(this InquiryTableEntity InqTEntity)
{
return new InquiryTableDTO(InqTEntity.OwnerId, InqTEntity.DatabaseName, InqTEntity.ConnectionInfo);
}
public static InquiryTableEntity FromModelToEntity(this InquiryTable InqT)
{
return new InquiryTableEntity(InqT.OwnerId, InqT.DatabaseName, InqT.ConnectionInfo);
}
public static InquiryTableEntity FromDTOToEntity(this InquiryTableDTO dto)
{
return new InquiryTableEntity(dto.OwnerId, dto.DatabaseName, dto.ConnectionInfo);
}
}

@ -0,0 +1,38 @@
using Dto;
using Entities;
using ModelToEntities.Business;
namespace Shared.Mapper;
public static class LessonMapper
{
public static LessonDTO FromModelToDTO(Lesson model)
{
return new LessonDTO(model.Id, model.Title, model.LastPublisher, model.LastEdit);
}
public static LessonDTO FromEntityToDTO(LessonEntity model)
{
return new LessonDTO(model.Id, model.Title, model.LastPublisher, model.LastEdit);
}
public static LessonEntity FromModelToEntity(Lesson model)
{
return new LessonEntity(model.Id, model.Title, model.LastPublisher, model.LastEdit);
}
public static LessonEntity FromDTOToEntity(LessonDTO dto)
{
return new LessonEntity(dto.Id, dto.Title, dto.LastPublisher, dto.LastEdit);
}
public static Lesson FromDTOToModel(LessonDTO dto)
{
return new Lesson(dto.Id, dto.Title, dto.LastPublisher, dto.LastEdit);
}
public static Lesson FromEntityToModel(LessonEntity entity)
{
return new Lesson(entity.Id, entity.Title, entity.LastPublisher, entity.LastEdit);
}
}

@ -0,0 +1,40 @@
using Dto;
using Entities;
using ModelToEntities.Business;
namespace Shared.Mapper;
public static class NotepadMapper
{
public static Notepad FromDTOToModel(this NotepadDTO dto)
{
return new Notepad(dto.Id, dto.UserId, dto.InquiryId, dto.Notes);
}
public static Notepad FromEntityToModel(this NotepadEntity ent)
{
return new Notepad(ent.Id, ent.UserId, ent.InquiryId, ent.Notes);
}
public static NotepadDTO FromModelToDTO(this Notepad not)
{
return new NotepadDTO(not.Id, not.UserId, not.InquiryId, not.Notes);
}
public static NotepadDTO FromEntityToDTO(this NotepadEntity ent)
{
return new NotepadDTO(ent.Id, ent.UserId, ent.InquiryId, ent.Notes);
}
public static NotepadEntity FromDTOToEntity(this NotepadDTO dto)
{
return new NotepadEntity(dto.Id, new UserEntity(dto.UserId), dto.UserId, new InquiryEntity(dto.InquiryId),
dto.Notes);
}
public static NotepadEntity FromModelToEntity(this Notepad not)
{
return new NotepadEntity(not.Id, new UserEntity(not.UserId), not.UserId, new InquiryEntity(not.InquiryId),
not.Notes);
}
}

@ -0,0 +1,38 @@
using Dto;
using Entities;
using ModelToEntities.Business;
namespace Shared.Mapper;
public static class ParagraphMapper
{
public static Paragraph FromDTOToModel(ParagraphDTO dto)
{
return new Paragraph(dto.Id, dto.Title, dto.Content, dto.Info, dto.Query, dto.Comment);
}
public static Paragraph FromEntityToModel(ParagraphEntity model)
{
return new Paragraph(model.Id, model.Title, model.Content, model.Info, model.Query, model.Comment);
}
public static ParagraphDTO FromEntityToDTO(ParagraphEntity model)
{
return new ParagraphDTO(model.Id, model.Title, model.Content, model.Info, model.Query, model.Comment);
}
public static ParagraphDTO FromModelToDTO(Paragraph model)
{
return new ParagraphDTO(model.Id, model.Title, model.Content, model.Info, model.Query, model.Comment);
}
public static ParagraphEntity FromDTOToEntity(ParagraphDTO dto)
{
return new ParagraphEntity(dto.Id, dto.Title, dto.Content, dto.Info, dto.Query, dto.Comment);
}
public static Paragraph FromModelToEntity(Paragraph model)
{
return new Paragraph(model.Id, model.Title, model.Content, model.Info, model.Query, model.Comment);
}
}

@ -0,0 +1,44 @@
using Dto;
using Entities;
using ModelToEntities.Business;
namespace Shared.Mapper;
public static class SolutionMapper
{
public static Solution FromDTOToModel(this SolutionDTO dto)
{
return new Solution(dto.OwnerId, dto.MurdererFirstName, dto.MurdererLastName, dto.MurderPlace, dto.MurderWeapon,
dto.Explanation);
}
public static Solution FromEntityToModel(this SolutionEntity entity)
{
return new Solution(entity.OwnerId, entity.MurdererFirstName, entity.MurdererLastName, entity.MurderPlace,
entity.MurderWeapon, entity.Explanation);
}
public static SolutionDTO FromModelToDTO(this Solution model)
{
return new SolutionDTO(model.OwnerId, model.MurdererFirstName, model.MurdererLastName, model.MurderPlace,
model.MurderWeapon, model.Explanation);
}
public static SolutionDTO FromEntityToDTO(this SolutionEntity entity)
{
return new SolutionDTO(entity.OwnerId, entity.MurdererFirstName, entity.MurdererLastName, entity.MurderPlace,
entity.MurderWeapon, entity.Explanation);
}
public static SolutionEntity FromModelToEntity(this Solution model)
{
return new SolutionEntity(model.OwnerId, new InquiryEntity(model.OwnerId), model.MurdererFirstName,
model.MurdererLastName, model.MurderPlace, model.MurderWeapon, model.Explanation);
}
public static SolutionEntity FromDTOToEntity(this SolutionDTO dto)
{
return new SolutionEntity(dto.OwnerId, new InquiryEntity(dto.OwnerId), dto.MurdererFirstName,
dto.MurdererLastName, dto.MurderPlace, dto.MurderWeapon, dto.Explanation);
}
}

@ -0,0 +1,40 @@
using Dto;
using Entities;
using ModelToEntities.Business;
namespace Shared.Mapper;
public static class SuccessMapper
{
public static Success FromDTOToModel(this SuccessDTO dto)
{
return new Success(dto.UserId, dto.InquiryId, dto.IsFinished);
}
public static Success FromEntityToModel(this SuccessEntity ent)
{
return new Success(ent.UserId, ent.InquiryId, ent.IsFinished);
}
public static SuccessDTO FromModelToDTO(this Success suc)
{
return new SuccessDTO(suc.UserId, suc.InquiryId, suc.IsFinished);
}
public static SuccessDTO FromEntityToDTO(this SuccessEntity ent)
{
return new SuccessDTO(ent.UserId, ent.InquiryId, ent.IsFinished);
}
public static SuccessEntity FromDTOToEntity(this SuccessDTO dto)
{
return new SuccessEntity(dto.UserId, new UserEntity(dto.UserId), dto.InquiryId,
new InquiryEntity(dto.InquiryId), dto.IsFinished);
}
public static SuccessEntity FromModelToEntity(this Success suc)
{
return new SuccessEntity(suc.UserId, new UserEntity(suc.UserId), suc.InquiryId,
new InquiryEntity(suc.InquiryId), suc.IsFinished);
}
}

@ -0,0 +1,38 @@
using Dto;
using Entities;
using ModelToEntities.Business;
namespace Shared.Mapper;
public static class UserMapper
{
public static User FromDTOToModel(this UserDTO dto)
{
return new User(dto.Id, dto.Username, dto.Password, dto.Email, dto.IsAdmin);
}
public static UserEntity FromDTOToEntity(this UserDTO dto)
{
return new UserEntity(dto.Id, dto.Username, dto.Password, dto.Email, dto.IsAdmin);
}
public static User FromEntityToModel(this UserEntity entity)
{
return new User(entity.Id, entity.Username, entity.Password, entity.Email, entity.IsAdmin);
}
public static UserDTO FromEntityToDTO(this UserEntity entity)
{
return new UserDTO(entity.Id, entity.Username, entity.Password, entity.Email, entity.IsAdmin);
}
public static UserDTO FromModelToDTO(this User user)
{
return new UserDTO(user.Id, user.Username, user.Password, user.Email, user.IsAdmin);
}
public static UserEntity FromModelToEntity(this User user)
{
return new UserEntity(user.Id, user.Username, user.Password, user.Email, user.IsAdmin);
}
}

@ -6,4 +6,10 @@
<Nullable>enable</Nullable> <Nullable>enable</Nullable>
</PropertyGroup> </PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\Dto\Dto.csproj" />
<ProjectReference Include="..\EntityFramework\Entities.csproj" />
<ProjectReference Include="..\Model\Model.csproj" />
</ItemGroup>
</Project> </Project>

@ -10,4 +10,11 @@
<ProjectReference Include="..\DbContextLib\DbContextLib.csproj" /> <ProjectReference Include="..\DbContextLib\DbContextLib.csproj" />
</ItemGroup> </ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="8.0.2">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
</ItemGroup>
</Project> </Project>

@ -3,13 +3,12 @@
using API.Controllers; using API.Controllers;
using API.Service; using API.Service;
using DbContextLib; using DbContextLib;
using DbDataManager.Service;
using Dto; using Dto;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
using Microsoft.Data.Sqlite; using Microsoft.Data.Sqlite;
using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options;
using ModelToEntities.Service;
var connection = new SqliteConnection("DataSource=:memory:"); var connection = new SqliteConnection("DataSource=:memory:");
connection.Open(); connection.Open();

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

Loading…
Cancel
Save