Réglage de tous les problèmes conus pour les paragraphes + merge de la branche debugLesson
continuous-integration/drone/push Build is passing Details

pull/45/head
Johnny RATTON 1 year ago
commit 69d344e947

@ -1,4 +1,5 @@
using Microsoft.AspNetCore.Authorization; using System.Net;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
using Dto; using Dto;
using Model.OrderCriteria; using Model.OrderCriteria;
@ -94,18 +95,33 @@ namespace API.Controllers
[HttpPost] [HttpPost]
[ProducesResponseType(typeof(LessonDto), 201)] [ProducesResponseType(typeof(LessonDto), 201)]
[ProducesResponseType(typeof(string), 400)] [ProducesResponseType(typeof(string), 400)]
[ProducesResponseType(typeof(string), 500)]
public IActionResult CreateLesson([FromBody] LessonDto dto) public IActionResult CreateLesson([FromBody] LessonDto dto)
{ {
if (dto.Title == null || dto.LastPublisher == null) if (dto.Title == null || dto.LastPublisher == null)
{ {
return BadRequest(); return BadRequest();
} }
try
_logger.LogInformation( {
"[INFORMATION] Une leçon a été créé : title - {title}, lastPublisher - {publisher}, lastEdit - {lastEdit}", var createdLesson = _lessonDataService.CreateLesson(dto.Id, dto.Title, dto.LastPublisher, dto.LastEdit ?? DateOnly.FromDateTime(DateTime.Now));
dto.Title, dto.LastPublisher, dto.LastEdit); if (createdLesson != null)
return Created(nameof(GetLessons), {
_lessonDataService.CreateLesson(dto.Title, dto.LastPublisher, dto.LastEdit)); _logger.LogInformation(
"[INFORMATION] Une leçon a été créé : title - {title}, lastPublisher - {publisher}, lastEdit - {lastEdit}",
dto.Title, dto.LastPublisher, dto.LastEdit);
return Created(nameof(GetLessons), createdLesson);
}
else
{
return StatusCode(500);
}
}
catch (ArgumentException e)
{
_logger.LogError("[ERREUR] " + e.Message);
return Created();
}
} }
[HttpPut("lesson/{id:int}")] [HttpPut("lesson/{id:int}")]
@ -126,7 +142,6 @@ namespace API.Controllers
id); id);
return BadRequest(); return BadRequest();
} }
if (LessonDto != null) if (LessonDto != null)
{ {
_logger.LogInformation("[INFORMATION] La mise à jour de la leçon avec l'id {id} a été effectuée", id); _logger.LogInformation("[INFORMATION] La mise à jour de la leçon avec l'id {id} a été effectuée", id);

@ -97,7 +97,7 @@ namespace API.Controllers
[ProducesResponseType(typeof(string), 400)] [ProducesResponseType(typeof(string), 400)]
public IActionResult CreateParagraph([FromBody] ParagraphDto dto) public IActionResult CreateParagraph([FromBody] ParagraphDto dto)
{ {
if (dto.Title == null || dto.Content == null || dto.Info == null || dto.Query == null || if (dto.ContentTitle == null || dto.ContentContent == null || dto.Title == null || dto.Content == null || dto.Info == null || dto.Query == null ||
dto.Comment == null) dto.Comment == null)
{ {
return BadRequest(); return BadRequest();
@ -107,7 +107,7 @@ namespace API.Controllers
"[INFORMATION] Un paragraphe a été créé : title - {title}, content - {content}, info - {info}, query - {query}, comment - {comment}", "[INFORMATION] Un paragraphe a été créé : title - {title}, content - {content}, info - {info}, query - {query}, comment - {comment}",
dto.Title, dto.Content, dto.Info, dto.Query, dto.Comment); dto.Title, dto.Content, dto.Info, dto.Query, dto.Comment);
return Created(nameof(GetParagraphs), return Created(nameof(GetParagraphs),
_paragraphDataService.CreateParagraph(dto.Title, dto.Content, dto.Info, dto.Query, dto.Comment, _paragraphDataService.CreateParagraph(dto.ContentTitle, dto.ContentContent,dto.Title, dto.Content, dto.Info, dto.Query, dto.Comment,
dto.LessonId)); dto.LessonId));
} }

@ -38,11 +38,11 @@ namespace API.Controllers
var nbUser = _successDataService.GetSuccesses(page, number, orderCriteria).ToList().Count; var nbUser = _successDataService.GetSuccesses(page, number, orderCriteria).ToList().Count;
if (nbUser == 0) if (nbUser == 0)
{ {
_logger.LogError("[ERREUR] Aucun utilisateur trouvé."); _logger.LogError("[ERREUR] Aucun Succès trouvé.");
return StatusCode(204); return StatusCode(204);
} }
_logger.LogInformation("[INFORMATION] {nb} Utilisateur(s) trouvé(s)", nbUser); _logger.LogInformation("[INFORMATION] {nb} Succès(s) trouvé(s)", nbUser);
return Ok(_successDataService.GetSuccesses(page, number, orderCriteria)); return Ok(_successDataService.GetSuccesses(page, number, orderCriteria));
} }

@ -37,6 +37,7 @@ builder.Services.AddScoped<ILessonService<LessonDto>, LessonDataServiceApi>();
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"));
builder.Services.AddIdentityApiEndpoints<IdentityUser>().AddEntityFrameworkStores<WebAPIDbContext>(); builder.Services.AddIdentityApiEndpoints<IdentityUser>().AddEntityFrameworkStores<WebAPIDbContext>();
builder.Services.AddAuthorization(); builder.Services.AddAuthorization();
builder.Services.AddApiVersioning(o => builder.Services.AddApiVersioning(o =>
{ {
@ -81,6 +82,36 @@ builder.Services.AddSwaggerGen(option =>
var app = builder.Build(); var app = builder.Build();
// Création de l'utilisateur admin pour la base de données Identity
using (var scope = app.Services.CreateScope())
{
var services = scope.ServiceProvider;
var userManager = services.GetRequiredService<UserManager<IdentityUser>>();
try
{
var user = new IdentityUser { UserName = "admin@example.com", Email = "admin@example.com" };
var result = await userManager.CreateAsync(user, "Mdp_1234");
if (result.Succeeded)
{
Console.WriteLine("Utilisateur admin créé avec succès.");
}
else
{
foreach (var error in result.Errors)
{
Console.WriteLine($"Erreur lors de la création de l'utilisateur : {error.Description}");
}
}
}
catch (Exception ex)
{
var logger = services.GetRequiredService<ILogger<Program>>();
logger.LogError(ex, "Une erreur s'est produite lors de la création de l'utilisateur.");
}
}
// Configure the HTTP request pipeline. // Configure the HTTP request pipeline.
if (app.Environment.IsDevelopment()) if (app.Environment.IsDevelopment())
{ {

@ -26,6 +26,6 @@ public class LessonDataServiceApi(ILessonService<LessonEntity> lessonService) :
public LessonDto UpdateLesson(int id, LessonEntity lesson) => public LessonDto UpdateLesson(int id, LessonEntity lesson) =>
lessonService.UpdateLesson(id, lesson).FromEntityToDto(); lessonService.UpdateLesson(id, lesson).FromEntityToDto();
public LessonDto CreateLesson(string title, string lastPublisher, DateOnly lastEdit) => public LessonDto CreateLesson(int id, string title, string lastPublisher, DateOnly lastEdit) =>
lessonService.CreateLesson(title, lastPublisher, lastEdit).FromEntityToDto(); lessonService.CreateLesson(id, title, lastPublisher, lastEdit).FromEntityToDto();
} }

@ -25,7 +25,6 @@ public class ParagraphDataServiceApi(IParagraphService<ParagraphEntity> paragrap
public ParagraphDto UpdateParagraph(int id, ParagraphDto paragraph) => public ParagraphDto UpdateParagraph(int id, ParagraphDto paragraph) =>
paragraphService.UpdateParagraph(id, paragraph.FromDtoToEntity()).FromEntityToDto(); paragraphService.UpdateParagraph(id, paragraph.FromDtoToEntity()).FromEntityToDto();
public ParagraphDto CreateParagraph(string title, string content, string info, string query, string comment, public ParagraphDto CreateParagraph(string contentTitle, string contentContent,string title, string content, string info, string query, string comment,
int lessonId) => int lessonId) => paragraphService.CreateParagraph(contentTitle, contentContent, title, content, info, query, comment, lessonId).FromEntityToDto();
paragraphService.CreateParagraph(title, content, info, query, comment, lessonId).FromEntityToDto();
} }

@ -18,6 +18,14 @@ public class InquiryDataService : IInquiryService<InquiryEntity>
public IEnumerable<InquiryEntity> GetInquiries(int page, int number, InquiryOrderCriteria orderCriteria) public IEnumerable<InquiryEntity> GetInquiries(int page, int number, InquiryOrderCriteria orderCriteria)
{ {
if (page <= 0)
{
page = 1;
}
if (number <= 0)
{
number = 10;
}
IQueryable<InquiryEntity> query = DbContext.Inquiries.Skip((page - 1) * number).Take(number); IQueryable<InquiryEntity> query = DbContext.Inquiries.Skip((page - 1) * number).Take(number);
switch (orderCriteria) switch (orderCriteria)
{ {

@ -1,5 +1,6 @@
using DbContextLib; using DbContextLib;
using Entities; using Entities;
using Microsoft.AspNetCore.Mvc.ModelBinding;
using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore;
using Model.OrderCriteria; using Model.OrderCriteria;
using Shared; using Shared;
@ -18,6 +19,14 @@ public class LessonDataService : ILessonService<LessonEntity>
public IEnumerable<LessonEntity> GetLessons(int page, int number, LessonOrderCriteria orderCriteria) public IEnumerable<LessonEntity> GetLessons(int page, int number, LessonOrderCriteria orderCriteria)
{ {
if (page <= 0)
{
page = 1;
}
if (number <= 0)
{
number = 10;
}
IQueryable<LessonEntity> query = DbContext.Lessons.Skip((page - 1) * number).Take(number); IQueryable<LessonEntity> query = DbContext.Lessons.Skip((page - 1) * number).Take(number);
switch (orderCriteria) switch (orderCriteria)
{ {
@ -64,45 +73,64 @@ public class LessonDataService : ILessonService<LessonEntity>
public bool DeleteLesson(int id) public bool DeleteLesson(int id)
{ {
var lessonEntity = DbContext.Lessons.FirstOrDefault(l => l.Id == id); using (UserDbContext context = new UserDbContext(new DbContextOptions<UserDbContext>()))
if (lessonEntity == null)
{ {
return false; var lessonEntity = context.Lessons.FirstOrDefault(l => l.Id == id);
} if (lessonEntity == null)
{
return false;
}
DbContext.Lessons.Remove(lessonEntity); context.Lessons.Remove(lessonEntity);
DbContext.SaveChangesAsync(); context.SaveChangesAsync();
return true; return true;
}
} }
public LessonEntity UpdateLesson(int id, LessonEntity lesson) public LessonEntity UpdateLesson(int id, LessonEntity lesson)
{ {
var updatingLesson = DbContext.Lessons.FirstOrDefault(l => l.Id == id); using (UserDbContext context = new UserDbContext(new DbContextOptions<UserDbContext>()))
if (updatingLesson == null)
{ {
throw new ArgumentException("Impossible de trouver la leçon", nameof(id)); var updatingLesson = context.Lessons.FirstOrDefault(l => l.Id == id);
} if (updatingLesson == null)
{
throw new ArgumentException("Impossible de trouver la leçon", nameof(id));
}
foreach (var pptt in typeof(LessonEntity).GetProperties() foreach (var pptt in typeof(LessonEntity).GetProperties()
.Where(p => p.CanWrite && p.Name != nameof(LessonEntity.Id))) .Where(p => p.CanWrite && p.Name != nameof(LessonEntity.Id)))
{ {
pptt.SetValue(updatingLesson, pptt.GetValue(lesson)); pptt.SetValue(updatingLesson, pptt.GetValue(lesson));
} }
DbContext.SaveChangesAsync(); context.SaveChangesAsync();
return updatingLesson; return updatingLesson;
}
} }
public LessonEntity CreateLesson(int id, string title, string lastPublisher, DateOnly lastEdit)
public LessonEntity CreateLesson(string title, string lastPublisher, DateOnly lastEdit)
{ {
var newLessonEntity = new LessonEntity() using (UserDbContext context = new UserDbContext(new DbContextOptions<UserDbContext>()))
{ {
Title = title, DateTime date = DateTime.Now;
LastPublisher = lastPublisher, var newLessonEntity = new LessonEntity()
LastEdit = lastEdit, {
}; Title = title,
DbContext.Lessons.Add(newLessonEntity); LastPublisher = lastPublisher,
DbContext.SaveChangesAsync(); LastEdit = lastEdit,
return newLessonEntity; };
var lesson = context.Lessons.FirstOrDefault(l => l.Id == id);
if (lesson == null && id > 0)
{
newLessonEntity.Id = id;
context.Lessons.Add(newLessonEntity);
context.SaveChangesAsync();
throw new ArgumentException(
$"Erreur, l'ID {id} est déjà utilisé pour une autre leçon, un id par a été attribué.");
}
context.Lessons.Add(newLessonEntity);
context.SaveChangesAsync();
return newLessonEntity;
}
} }
} }

@ -18,6 +18,14 @@ public class ParagraphDataService : IParagraphService<ParagraphEntity>
public IEnumerable<ParagraphEntity> GetParagraphs(int page, int number, ParagraphOrderCriteria orderCriteria) public IEnumerable<ParagraphEntity> GetParagraphs(int page, int number, ParagraphOrderCriteria orderCriteria)
{ {
if (page <= 0)
{
page = 1;
}
if (number <= 0)
{
number = 10;
}
IQueryable<ParagraphEntity> query = DbContext.Paragraphs.Skip((page - 1) * number).Take(number); IQueryable<ParagraphEntity> query = DbContext.Paragraphs.Skip((page - 1) * number).Take(number);
switch (orderCriteria) switch (orderCriteria)
{ {
@ -94,16 +102,25 @@ public class ParagraphDataService : IParagraphService<ParagraphEntity>
{ {
pptt.SetValue(updatingParagraph, pptt.GetValue(paragraph)); pptt.SetValue(updatingParagraph, pptt.GetValue(paragraph));
} }
/*updatingParagraph.ContentTitle = paragraph.ContentTitle;
updatingParagraph.ContentContent = paragraph.ContentContent;
updatingParagraph.Title = paragraph.Title;
updatingParagraph.Content = paragraph.Content;
updatingParagraph.Info = paragraph.Info;
updatingParagraph.Query = paragraph.Query;
updatingParagraph.Comment = paragraph.Comment;
updatingParagraph.LessonId = paragraph.LessonId;*/
DbContext.SaveChangesAsync(); DbContext.SaveChangesAsync();
return updatingParagraph; return updatingParagraph;
} }
public ParagraphEntity CreateParagraph(string title, string content, string info, string query, string comment, public ParagraphEntity CreateParagraph(string contentTitle, string contentContent, string title, string content, string info, string query, string comment,
int lessonId) int lessonId)
{ {
var newParagraphEntity = new ParagraphEntity() var newParagraphEntity = new ParagraphEntity()
{ {
ContentContent = contentContent,
ContentTitle = contentTitle,
Title = title, Title = title,
Content = content, Content = content,
Info = info, Info = info,

@ -18,6 +18,14 @@ public class SuccessDataService : ISuccessService<SuccessEntity>
public IEnumerable<SuccessEntity> GetSuccesses(int page, int number, SuccessOrderCriteria orderCriteria) public IEnumerable<SuccessEntity> GetSuccesses(int page, int number, SuccessOrderCriteria orderCriteria)
{ {
if (page <= 0)
{
page = 1;
}
if (number <= 0)
{
number = 10;
}
IQueryable<SuccessEntity> query = DbContext.Successes.Skip((page - 1) * number).Take(number); IQueryable<SuccessEntity> query = DbContext.Successes.Skip((page - 1) * number).Take(number);
switch (orderCriteria) switch (orderCriteria)
{ {

@ -39,6 +39,14 @@ public class UserDataService : IUserService<UserEntity>
public IEnumerable<UserEntity> GetUsers(int page, int number, UserOrderCriteria orderCriteria) public IEnumerable<UserEntity> GetUsers(int page, int number, UserOrderCriteria orderCriteria)
{ {
if (page <= 0)
{
page = 1;
}
if (number <= 0)
{
number = 10;
}
IQueryable<UserEntity> query = DbContext.Users.Skip((page - 1) * number).Take(number); IQueryable<UserEntity> query = DbContext.Users.Skip((page - 1) * number).Take(number);
switch (orderCriteria) switch (orderCriteria)
{ {

@ -1,13 +1,21 @@
namespace Dto; using System.Runtime.Serialization;
using System.Text.Json.Serialization;
public abstract class ContentLessonDto namespace Dto;
[DataContract]
public class ContentLessonDto
{ {
[DataMember(Name = "id")]
public int Id { get; set; } public int Id { get; set; }
[DataMember(Name = "contentContent")]
public string ContentContent { get; set; } public string ContentContent { get; set; }
[DataMember(Name = "contentTitle")]
public string ContentTitle { get; set; } public string ContentTitle { get; set; }
[DataMember(Name = "lessonId")]
public int LessonId { get; set; } public int LessonId { get; set; }
protected ContentLessonDto(int id, string contentContent, string contentTitle, int lessonId) public ContentLessonDto(int id, string contentContent, string contentTitle, int lessonId)
{ {
Id = id; Id = id;
ContentContent = contentContent; ContentContent = contentContent;
@ -22,7 +30,7 @@ public abstract class ContentLessonDto
LessonId = lessonId; LessonId = lessonId;
} }
protected ContentLessonDto() public ContentLessonDto()
{ {
} }
} }

@ -6,4 +6,10 @@
<Nullable>enable</Nullable> <Nullable>enable</Nullable>
</PropertyGroup> </PropertyGroup>
<ItemGroup>
<Reference Include="Newtonsoft.Json">
<HintPath>..\..\..\..\..\.nuget\packages\newtonsoft.json\13.0.1\lib\netstandard2.0\Newtonsoft.Json.dll</HintPath>
</Reference>
</ItemGroup>
</Project> </Project>

@ -1,13 +1,20 @@
namespace Dto; using System.Runtime.Serialization;
namespace Dto;
[DataContract]
public class InquiryDto : IEquatable<InquiryDto> public class InquiryDto : IEquatable<InquiryDto>
{ {
public int Id { get; } [DataMember]
public int Id { get; set; }
[DataMember]
public string Title { get; set; } public string Title { get; set; }
[DataMember]
public string Description { get; set; } public string Description { get; set; }
[DataMember]
public bool IsUser { get; set; } public bool IsUser { get; set; }
public InquiryDto() public InquiryDto()

@ -1,17 +1,25 @@
namespace Dto; using System.Net;
using System.Runtime.Serialization;
using System.Text.Json.Serialization;
namespace Dto;
[DataContract]
public class LessonDto : IEquatable<LessonDto> public class LessonDto : IEquatable<LessonDto>
{ {
public int Id { get; } [DataMember]
public string Title { get; set; } public int Id { get; set; }
public string LastPublisher { get; set; } [DataMember]
public DateOnly LastEdit { get; set; } public string? Title { get; set; }
[DataMember]
public string? LastPublisher { get; set; }
[DataMember]
public DateOnly? LastEdit { get; set; }
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
public ICollection<ContentLessonDto> Content { get; set; } = new List<ContentLessonDto>(); public ICollection<ContentLessonDto> Content { get; set; } = new List<ContentLessonDto>();
public LessonDto() public LessonDto()
{ {
} }
public LessonDto(int id, string title, string lastPublisher, DateOnly lastEdit) public LessonDto(int id, string title, string lastPublisher, DateOnly lastEdit)
{ {
Id = id; Id = id;
@ -20,6 +28,14 @@ public class LessonDto : IEquatable<LessonDto>
LastEdit = lastEdit; LastEdit = lastEdit;
} }
public LessonDto(int id, string title, string lastPublisher, DateOnly? lastEdit, ICollection<ContentLessonDto> content)
{
Id = id;
Title = title;
LastPublisher = lastPublisher;
LastEdit = lastEdit;
Content = content;
}
public LessonDto(string title, string lastPublisher, DateOnly lastEdit) public LessonDto(string title, string lastPublisher, DateOnly lastEdit)
{ {
Title = title; Title = title;

@ -1,13 +1,31 @@
namespace Dto; using System.Runtime.Serialization;
namespace Dto;
[DataContract]
public class ParagraphDto : ContentLessonDto, IEquatable<ParagraphDto> public class ParagraphDto : ContentLessonDto, IEquatable<ParagraphDto>
{ {
[DataMember(Name = "title")]
public string Title { get; set; } public string Title { get; set; }
[DataMember(Name = "content")]
public string Content { get; set; } public string Content { get; set; }
[DataMember(Name = "info")]
public string Info { get; set; } public string Info { get; set; }
[DataMember(Name = "query")]
public string Query { get; set; } public string Query { get; set; }
[DataMember(Name = "comment")]
public string Comment { get; set; } public string Comment { get; set; }
public ParagraphDto(string contentTitle, string contentContent, string title, string content, string info, string query, string comment, int lessonId) :
base(contentContent,
contentTitle, lessonId)
{
Title = title;
Content = content;
Info = info;
Query = query;
Comment = comment;
}
public ParagraphDto(string title, string content, string info, string query, string comment, int lessonId) : public ParagraphDto(string title, string content, string info, string query, string comment, int lessonId) :
base(content, base(content,
title, lessonId) title, lessonId)

@ -9,5 +9,5 @@ public interface ILessonService<TLesson>
public TLesson GetLessonByTitle(string title); public TLesson GetLessonByTitle(string title);
public bool DeleteLesson(int id); public bool DeleteLesson(int id);
public TLesson UpdateLesson(int id, TLesson lesson); public TLesson UpdateLesson(int id, TLesson lesson);
public TLesson CreateLesson(string title, string lastPublisher, DateOnly lastEdit); public TLesson CreateLesson(int id, string title, string lastPublisher, DateOnly lastEdit);
} }

@ -10,7 +10,7 @@ namespace Shared
public bool DeleteParagraph(int id); public bool DeleteParagraph(int id);
public TParagraph UpdateParagraph(int id, TParagraph paragraph); public TParagraph UpdateParagraph(int id, TParagraph paragraph);
public TParagraph CreateParagraph(string title, string content, string info, string query, string comment, public TParagraph CreateParagraph(string contentTitle, string contentContent, string title, string content, string info, string query, string comment,
int lessonId); int lessonId);
} }
} }

@ -0,0 +1,13 @@
using Dto;
using Entities;
using Model;
namespace Shared.Mapper;
public static class ContentLessonMapper
{
public static ContentLessonDto FromEntityToDto(this ContentLessonEntity entity)
{
return new ContentLessonDto(entity.Id, entity.ContentContent, entity.ContentTitle, entity.LessonId);
}
}

@ -12,6 +12,11 @@ public static class LessonMapper
} }
public static LessonDto FromEntityToDto(this LessonEntity model) public static LessonDto FromEntityToDto(this LessonEntity model)
{
return new LessonDto(model.Id, model.Title, model.LastPublisher, model.LastEdit, model.Content.Select(c => c.FromEntityToDto()).ToList());
}
public static LessonDto FromEntityToDTOPost(this LessonEntity model)
{ {
return new LessonDto(model.Id, model.Title, model.LastPublisher, model.LastEdit); return new LessonDto(model.Id, model.Title, model.LastPublisher, model.LastEdit);
} }
@ -26,21 +31,22 @@ public static class LessonMapper
LastEdit = model.LastEdit LastEdit = model.LastEdit
}; };
} }
public static LessonEntity FromDtoToEntity(this LessonDto dto) public static LessonEntity FromDtoToEntity(this LessonDto dto)
{ {
DateTime date = DateTime.Now;
return new LessonEntity return new LessonEntity
{ {
Id = dto.Id, Id = dto.Id,
Title = dto.Title, Title = dto.Title,
LastPublisher = dto.LastPublisher, LastPublisher = dto.LastPublisher,
LastEdit = dto.LastEdit LastEdit = dto.LastEdit ?? new DateOnly(date.Year,date.Month,date.Day)
}; };
} }
public static Lesson FromDtoToModel(this LessonDto dto) public static Lesson FromDtoToModel(this LessonDto dto)
{ {
return new Lesson(dto.Id, dto.Title, dto.LastPublisher, dto.LastEdit); DateTime date = DateTime.Now;
return new Lesson(dto.Id, dto.Title, dto.LastPublisher, dto.LastEdit ?? new DateOnly(date.Year,date.Month,date.Day));
} }
public static Lesson FromEntityToModel(this LessonEntity entity) public static Lesson FromEntityToModel(this LessonEntity entity)

@ -35,6 +35,8 @@ public static class ParagraphMapper
Id = dto.Id, Id = dto.Id,
ContentTitle = dto.ContentTitle, ContentTitle = dto.ContentTitle,
ContentContent = dto.ContentContent, ContentContent = dto.ContentContent,
Title = dto.Title,
Content = dto.Content,
Info = dto.Info, Info = dto.Info,
Query = dto.Query, Query = dto.Query,
Comment = dto.Comment, Comment = dto.Comment,

@ -179,7 +179,7 @@ public class LessonUnitTest
[Fact] [Fact]
public void CreateLessonSuccess() public void CreateLessonSuccess()
{ {
_lessonService.Setup(x => x.CreateLesson("Le nouveau titre", "Le nouvel éditeur", new DateOnly(2024, 03, 16))) _lessonService.Setup(x => x.CreateLesson(96,"Le nouveau titre", "Le nouvel éditeur", new DateOnly(2024, 03, 16)))
.Returns(new LessonDto("Le nouveau titre", "Le nouvel éditeur", new DateOnly(2024, 03, 16))); .Returns(new LessonDto("Le nouveau titre", "Le nouvel éditeur", new DateOnly(2024, 03, 16)));
var lessonsController = new LessonsController(_lessonService.Object, new NullLogger<LessonsController>()); var lessonsController = new LessonsController(_lessonService.Object, new NullLogger<LessonsController>());
@ -200,7 +200,7 @@ public class LessonUnitTest
[Fact] [Fact]
public void CreateLessonFail() public void CreateLessonFail()
{ {
_lessonService.Setup(x => x.CreateLesson("Le nouveau titre", "Le nouvel éditeur", new DateOnly(2024, 03, 16))) _lessonService.Setup(x => x.CreateLesson(42,"Le nouveau titre", "Le nouvel éditeur", new DateOnly(2024, 03, 16)))
.Returns(new LessonDto("Le nouveau titre", "Le nouvel éditeur", new DateOnly(2024, 03, 16))); .Returns(new LessonDto("Le nouveau titre", "Le nouvel éditeur", new DateOnly(2024, 03, 16)));
var lessonsController = new LessonsController(_lessonService.Object, new NullLogger<LessonsController>()); var lessonsController = new LessonsController(_lessonService.Object, new NullLogger<LessonsController>());

@ -193,21 +193,22 @@ public class ParagraphsUnitTest
[Fact] [Fact]
public void CreateParagraphSuccess() public void CreateParagraphSuccess()
{ {
_paragraphService.Setup(x => x.CreateParagraph("Le nouveau titre", "Le nouveau content", "Les infos", _paragraphService.Setup(x => x.CreateParagraph("Le nouveau titre", "Le nouveau content", "Title","Le nouveau content","Les infos",
"La requête requêtante", "Commentaires", 2)) "La requête requêtante", "Commentaires", 2))
.Returns(new ParagraphDto("Le nouveau titre", "Le nouveau content", "Les infos", "La requête requêtante", .Returns(new ParagraphDto("Le nouveau titre", "Le nouveau content","Title", "Le nouveau content", "Les infos", "La requête requêtante",
"Commentaires", 2)); "Commentaires", 2));
var paragraphsController = var paragraphsController =
new ParagraphsController(_paragraphService.Object, new NullLogger<ParagraphsController>()); new ParagraphsController(_paragraphService.Object, new NullLogger<ParagraphsController>());
var paragraphsResult = paragraphsController.CreateParagraph(new ParagraphDto("Le nouveau titre", var paragraphsResult = paragraphsController.CreateParagraph(new ParagraphDto("Le nouveau titre", "Le nouveau content","Title",
"Le nouveau content", "Les infos", "La requête requêtante", "Commentaires", 2)); "Le nouveau content", "Les infos", "La requête requêtante", "Commentaires", 2));
if (paragraphsResult is CreatedResult createdObjectResult) if (paragraphsResult is CreatedResult createdObjectResult)
{ {
ParagraphDto valeur = createdObjectResult.Value as ParagraphDto; ParagraphDto valeur = createdObjectResult.Value as ParagraphDto;
Assert.NotNull(valeur); Assert.NotNull(valeur);
Assert.Equal("Le nouveau titre", valeur.Title); Assert.Equal("Title", valeur.Title);
Assert.Equal("Le nouveau titre", valeur.ContentTitle);
Assert.Equal("Le nouveau content", valeur.ContentContent);
Assert.Equal("Le nouveau content", valeur.Content); Assert.Equal("Le nouveau content", valeur.Content);
Assert.Equal("Les infos", valeur.Info); Assert.Equal("Les infos", valeur.Info);
Assert.Equal("La requête requêtante", valeur.Query); Assert.Equal("La requête requêtante", valeur.Query);
@ -219,8 +220,8 @@ public class ParagraphsUnitTest
[Fact] [Fact]
public void CreateParagraphFail() public void CreateParagraphFail()
{ {
_paragraphService.Setup(x => x.CreateParagraph("Le nouveau titre", "Le nouveau content", "Les infos", _paragraphService.Setup(x => x.CreateParagraph("Le nouveau titre", "Le nouveau content", "Title","Les infos",
"La requête requêtante", "Commentaires", 2)) "La requête requêtante", "Commentaires", "Comment", 2))
.Returns(new ParagraphDto("Le nouveau titre", "Le nouveau content", "Les infos", "La requête requêtante", .Returns(new ParagraphDto("Le nouveau titre", "Le nouveau content", "Les infos", "La requête requêtante",
"Commentaires", 2)); "Commentaires", 2));
var paragraphsController = var paragraphsController =

Loading…
Cancel
Save