diff --git a/API_SQLuedo/API/Controllers/LessonsController.cs b/API_SQLuedo/API/Controllers/LessonsController.cs index 57404aa..c02cc6b 100644 --- a/API_SQLuedo/API/Controllers/LessonsController.cs +++ b/API_SQLuedo/API/Controllers/LessonsController.cs @@ -1,4 +1,5 @@ -using Microsoft.AspNetCore.Authorization; +using System.Net; +using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; using Dto; using Model.OrderCriteria; @@ -94,18 +95,33 @@ namespace API.Controllers [HttpPost] [ProducesResponseType(typeof(LessonDto), 201)] [ProducesResponseType(typeof(string), 400)] + [ProducesResponseType(typeof(string), 500)] public IActionResult CreateLesson([FromBody] LessonDto dto) { if (dto.Title == null || dto.LastPublisher == null) { return BadRequest(); } - - _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), - _lessonDataService.CreateLesson(dto.Title, dto.LastPublisher, dto.LastEdit)); + try + { + var createdLesson = _lessonDataService.CreateLesson(dto.Id, dto.Title, dto.LastPublisher, dto.LastEdit ?? DateOnly.FromDateTime(DateTime.Now)); + if (createdLesson != null) + { + _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}")] @@ -126,7 +142,6 @@ namespace API.Controllers id); return BadRequest(); } - if (LessonDto != null) { _logger.LogInformation("[INFORMATION] La mise à jour de la leçon avec l'id {id} a été effectuée", id); diff --git a/API_SQLuedo/API/Controllers/ParagraphsController.cs b/API_SQLuedo/API/Controllers/ParagraphsController.cs index 9d2557f..a8fa71a 100644 --- a/API_SQLuedo/API/Controllers/ParagraphsController.cs +++ b/API_SQLuedo/API/Controllers/ParagraphsController.cs @@ -97,7 +97,7 @@ namespace API.Controllers [ProducesResponseType(typeof(string), 400)] 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) { 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}", dto.Title, dto.Content, dto.Info, dto.Query, dto.Comment); 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)); } diff --git a/API_SQLuedo/API/Controllers/SuccessesController.cs b/API_SQLuedo/API/Controllers/SuccessesController.cs index adafc33..60433c1 100644 --- a/API_SQLuedo/API/Controllers/SuccessesController.cs +++ b/API_SQLuedo/API/Controllers/SuccessesController.cs @@ -38,11 +38,11 @@ namespace API.Controllers var nbUser = _successDataService.GetSuccesses(page, number, orderCriteria).ToList().Count; if (nbUser == 0) { - _logger.LogError("[ERREUR] Aucun utilisateur trouvé."); + _logger.LogError("[ERREUR] Aucun Succès trouvé."); 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)); } diff --git a/API_SQLuedo/API/Program.cs b/API_SQLuedo/API/Program.cs index 8f6c77d..529a451 100644 --- a/API_SQLuedo/API/Program.cs +++ b/API_SQLuedo/API/Program.cs @@ -37,6 +37,7 @@ builder.Services.AddScoped, LessonDataServiceApi>(); builder.Services.AddDbContext(); builder.Services.AddDbContext(options => options.UseInMemoryDatabase("appDb")); builder.Services.AddIdentityApiEndpoints().AddEntityFrameworkStores(); + builder.Services.AddAuthorization(); builder.Services.AddApiVersioning(o => { @@ -81,6 +82,36 @@ builder.Services.AddSwaggerGen(option => 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>(); + + 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>(); + logger.LogError(ex, "Une erreur s'est produite lors de la création de l'utilisateur."); + } +} + // Configure the HTTP request pipeline. if (app.Environment.IsDevelopment()) { diff --git a/API_SQLuedo/API/Service/LessonDataServiceAPI.cs b/API_SQLuedo/API/Service/LessonDataServiceAPI.cs index a93726b..17fd31b 100644 --- a/API_SQLuedo/API/Service/LessonDataServiceAPI.cs +++ b/API_SQLuedo/API/Service/LessonDataServiceAPI.cs @@ -26,6 +26,6 @@ public class LessonDataServiceApi(ILessonService lessonService) : public LessonDto UpdateLesson(int id, LessonEntity lesson) => lessonService.UpdateLesson(id, lesson).FromEntityToDto(); - public LessonDto CreateLesson(string title, string lastPublisher, DateOnly lastEdit) => - lessonService.CreateLesson(title, lastPublisher, lastEdit).FromEntityToDto(); + public LessonDto CreateLesson(int id, string title, string lastPublisher, DateOnly lastEdit) => + lessonService.CreateLesson(id, title, lastPublisher, lastEdit).FromEntityToDto(); } \ No newline at end of file diff --git a/API_SQLuedo/API/Service/ParagraphDataServiceAPI.cs b/API_SQLuedo/API/Service/ParagraphDataServiceAPI.cs index e8dd3ff..3b0cb16 100644 --- a/API_SQLuedo/API/Service/ParagraphDataServiceAPI.cs +++ b/API_SQLuedo/API/Service/ParagraphDataServiceAPI.cs @@ -25,7 +25,6 @@ public class ParagraphDataServiceApi(IParagraphService paragrap public ParagraphDto UpdateParagraph(int id, ParagraphDto paragraph) => paragraphService.UpdateParagraph(id, paragraph.FromDtoToEntity()).FromEntityToDto(); - public ParagraphDto CreateParagraph(string title, string content, string info, string query, string comment, - int lessonId) => - paragraphService.CreateParagraph(title, content, info, query, comment, lessonId).FromEntityToDto(); + public ParagraphDto CreateParagraph(string contentTitle, string contentContent,string title, string content, string info, string query, string comment, + int lessonId) => paragraphService.CreateParagraph(contentTitle, contentContent, title, content, info, query, comment, lessonId).FromEntityToDto(); } \ No newline at end of file diff --git a/API_SQLuedo/DbDataManager/Service/InquiryDataService.cs b/API_SQLuedo/DbDataManager/Service/InquiryDataService.cs index b3b263a..0d69699 100644 --- a/API_SQLuedo/DbDataManager/Service/InquiryDataService.cs +++ b/API_SQLuedo/DbDataManager/Service/InquiryDataService.cs @@ -18,6 +18,14 @@ public class InquiryDataService : IInquiryService public IEnumerable GetInquiries(int page, int number, InquiryOrderCriteria orderCriteria) { + if (page <= 0) + { + page = 1; + } + if (number <= 0) + { + number = 10; + } IQueryable query = DbContext.Inquiries.Skip((page - 1) * number).Take(number); switch (orderCriteria) { diff --git a/API_SQLuedo/DbDataManager/Service/LessonDataService.cs b/API_SQLuedo/DbDataManager/Service/LessonDataService.cs index 7c15987..bb7ced6 100644 --- a/API_SQLuedo/DbDataManager/Service/LessonDataService.cs +++ b/API_SQLuedo/DbDataManager/Service/LessonDataService.cs @@ -1,5 +1,6 @@ using DbContextLib; using Entities; +using Microsoft.AspNetCore.Mvc.ModelBinding; using Microsoft.EntityFrameworkCore; using Model.OrderCriteria; using Shared; @@ -18,6 +19,14 @@ public class LessonDataService : ILessonService public IEnumerable GetLessons(int page, int number, LessonOrderCriteria orderCriteria) { + if (page <= 0) + { + page = 1; + } + if (number <= 0) + { + number = 10; + } IQueryable query = DbContext.Lessons.Skip((page - 1) * number).Take(number); switch (orderCriteria) { @@ -64,45 +73,64 @@ public class LessonDataService : ILessonService public bool DeleteLesson(int id) { - var lessonEntity = DbContext.Lessons.FirstOrDefault(l => l.Id == id); - if (lessonEntity == null) + using (UserDbContext context = new UserDbContext(new DbContextOptions())) { - return false; - } + var lessonEntity = context.Lessons.FirstOrDefault(l => l.Id == id); + if (lessonEntity == null) + { + return false; + } - DbContext.Lessons.Remove(lessonEntity); - DbContext.SaveChangesAsync(); - return true; + context.Lessons.Remove(lessonEntity); + context.SaveChangesAsync(); + return true; + } } public LessonEntity UpdateLesson(int id, LessonEntity lesson) { - var updatingLesson = DbContext.Lessons.FirstOrDefault(l => l.Id == id); - if (updatingLesson == null) + using (UserDbContext context = new UserDbContext(new DbContextOptions())) { - 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() - .Where(p => p.CanWrite && p.Name != nameof(LessonEntity.Id))) - { - pptt.SetValue(updatingLesson, pptt.GetValue(lesson)); - } + foreach (var pptt in typeof(LessonEntity).GetProperties() + .Where(p => p.CanWrite && p.Name != nameof(LessonEntity.Id))) + { + pptt.SetValue(updatingLesson, pptt.GetValue(lesson)); + } - DbContext.SaveChangesAsync(); - return updatingLesson; + context.SaveChangesAsync(); + return updatingLesson; + } } - - public LessonEntity CreateLesson(string title, string lastPublisher, DateOnly lastEdit) + public LessonEntity CreateLesson(int id, string title, string lastPublisher, DateOnly lastEdit) { - var newLessonEntity = new LessonEntity() + using (UserDbContext context = new UserDbContext(new DbContextOptions())) { - Title = title, - LastPublisher = lastPublisher, - LastEdit = lastEdit, - }; - DbContext.Lessons.Add(newLessonEntity); - DbContext.SaveChangesAsync(); - return newLessonEntity; + DateTime date = DateTime.Now; + var newLessonEntity = new LessonEntity() + { + Title = title, + LastPublisher = lastPublisher, + LastEdit = lastEdit, + }; + 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; + } } } \ No newline at end of file diff --git a/API_SQLuedo/DbDataManager/Service/ParagraphDataService.cs b/API_SQLuedo/DbDataManager/Service/ParagraphDataService.cs index ddf2d34..5486813 100644 --- a/API_SQLuedo/DbDataManager/Service/ParagraphDataService.cs +++ b/API_SQLuedo/DbDataManager/Service/ParagraphDataService.cs @@ -18,6 +18,14 @@ public class ParagraphDataService : IParagraphService public IEnumerable GetParagraphs(int page, int number, ParagraphOrderCriteria orderCriteria) { + if (page <= 0) + { + page = 1; + } + if (number <= 0) + { + number = 10; + } IQueryable query = DbContext.Paragraphs.Skip((page - 1) * number).Take(number); switch (orderCriteria) { @@ -94,16 +102,25 @@ public class ParagraphDataService : IParagraphService { 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(); 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) { var newParagraphEntity = new ParagraphEntity() { + ContentContent = contentContent, + ContentTitle = contentTitle, Title = title, Content = content, Info = info, diff --git a/API_SQLuedo/DbDataManager/Service/SuccessDataService.cs b/API_SQLuedo/DbDataManager/Service/SuccessDataService.cs index 0654a2e..64e66b4 100644 --- a/API_SQLuedo/DbDataManager/Service/SuccessDataService.cs +++ b/API_SQLuedo/DbDataManager/Service/SuccessDataService.cs @@ -18,6 +18,14 @@ public class SuccessDataService : ISuccessService public IEnumerable GetSuccesses(int page, int number, SuccessOrderCriteria orderCriteria) { + if (page <= 0) + { + page = 1; + } + if (number <= 0) + { + number = 10; + } IQueryable query = DbContext.Successes.Skip((page - 1) * number).Take(number); switch (orderCriteria) { diff --git a/API_SQLuedo/DbDataManager/Service/UserDataService.cs b/API_SQLuedo/DbDataManager/Service/UserDataService.cs index 0162348..ebb3ba5 100644 --- a/API_SQLuedo/DbDataManager/Service/UserDataService.cs +++ b/API_SQLuedo/DbDataManager/Service/UserDataService.cs @@ -39,6 +39,14 @@ public class UserDataService : IUserService public IEnumerable GetUsers(int page, int number, UserOrderCriteria orderCriteria) { + if (page <= 0) + { + page = 1; + } + if (number <= 0) + { + number = 10; + } IQueryable query = DbContext.Users.Skip((page - 1) * number).Take(number); switch (orderCriteria) { diff --git a/API_SQLuedo/Dto/ContentLessonDTO.cs b/API_SQLuedo/Dto/ContentLessonDTO.cs index 98a9faf..d9bcb41 100644 --- a/API_SQLuedo/Dto/ContentLessonDTO.cs +++ b/API_SQLuedo/Dto/ContentLessonDTO.cs @@ -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; } + [DataMember(Name = "contentContent")] public string ContentContent { get; set; } + [DataMember(Name = "contentTitle")] public string ContentTitle { get; set; } + [DataMember(Name = "lessonId")] 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; ContentContent = contentContent; @@ -22,7 +30,7 @@ public abstract class ContentLessonDto LessonId = lessonId; } - protected ContentLessonDto() + public ContentLessonDto() { } } \ No newline at end of file diff --git a/API_SQLuedo/Dto/Dto.csproj b/API_SQLuedo/Dto/Dto.csproj index 3a63532..5040c07 100644 --- a/API_SQLuedo/Dto/Dto.csproj +++ b/API_SQLuedo/Dto/Dto.csproj @@ -6,4 +6,10 @@ enable + + + ..\..\..\..\..\.nuget\packages\newtonsoft.json\13.0.1\lib\netstandard2.0\Newtonsoft.Json.dll + + + diff --git a/API_SQLuedo/Dto/InquiryDTO.cs b/API_SQLuedo/Dto/InquiryDTO.cs index 4601252..6c4234d 100644 --- a/API_SQLuedo/Dto/InquiryDTO.cs +++ b/API_SQLuedo/Dto/InquiryDTO.cs @@ -1,13 +1,20 @@ -namespace Dto; +using System.Runtime.Serialization; +namespace Dto; + +[DataContract] public class InquiryDto : IEquatable { - public int Id { get; } + [DataMember] + public int Id { get; set; } + [DataMember] public string Title { get; set; } + [DataMember] public string Description { get; set; } + [DataMember] public bool IsUser { get; set; } public InquiryDto() diff --git a/API_SQLuedo/Dto/LessonDTO.cs b/API_SQLuedo/Dto/LessonDTO.cs index f95aa86..948455c 100644 --- a/API_SQLuedo/Dto/LessonDTO.cs +++ b/API_SQLuedo/Dto/LessonDTO.cs @@ -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 { - public int Id { get; } - public string Title { get; set; } - public string LastPublisher { get; set; } - public DateOnly LastEdit { get; set; } + [DataMember] + public int Id { get; set; } + [DataMember] + public string? Title { get; set; } + [DataMember] + public string? LastPublisher { get; set; } + [DataMember] + public DateOnly? LastEdit { get; set; } + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] public ICollection Content { get; set; } = new List(); public LessonDto() { } - public LessonDto(int id, string title, string lastPublisher, DateOnly lastEdit) { Id = id; @@ -19,7 +27,15 @@ public class LessonDto : IEquatable LastPublisher = lastPublisher; LastEdit = lastEdit; } - + + public LessonDto(int id, string title, string lastPublisher, DateOnly? lastEdit, ICollection content) + { + Id = id; + Title = title; + LastPublisher = lastPublisher; + LastEdit = lastEdit; + Content = content; + } public LessonDto(string title, string lastPublisher, DateOnly lastEdit) { Title = title; diff --git a/API_SQLuedo/Dto/ParagraphDTO.cs b/API_SQLuedo/Dto/ParagraphDTO.cs index 75ac6d8..4e15e3e 100644 --- a/API_SQLuedo/Dto/ParagraphDTO.cs +++ b/API_SQLuedo/Dto/ParagraphDTO.cs @@ -1,13 +1,31 @@ -namespace Dto; +using System.Runtime.Serialization; +namespace Dto; + +[DataContract] public class ParagraphDto : ContentLessonDto, IEquatable { + [DataMember(Name = "title")] public string Title { get; set; } + [DataMember(Name = "content")] public string Content { get; set; } + [DataMember(Name = "info")] public string Info { get; set; } + [DataMember(Name = "query")] public string Query { get; set; } + [DataMember(Name = "comment")] 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) : base(content, title, lessonId) diff --git a/API_SQLuedo/Shared/ILessonService.cs b/API_SQLuedo/Shared/ILessonService.cs index 92f2683..51836e0 100644 --- a/API_SQLuedo/Shared/ILessonService.cs +++ b/API_SQLuedo/Shared/ILessonService.cs @@ -9,5 +9,5 @@ public interface ILessonService public TLesson GetLessonByTitle(string title); public bool DeleteLesson(int id); 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); } \ No newline at end of file diff --git a/API_SQLuedo/Shared/IParagraphService.cs b/API_SQLuedo/Shared/IParagraphService.cs index aa2fe7a..34a249b 100644 --- a/API_SQLuedo/Shared/IParagraphService.cs +++ b/API_SQLuedo/Shared/IParagraphService.cs @@ -10,7 +10,7 @@ namespace Shared public bool DeleteParagraph(int id); 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); } } \ No newline at end of file diff --git a/API_SQLuedo/Shared/Mapper/ContentLessonMapper.cs b/API_SQLuedo/Shared/Mapper/ContentLessonMapper.cs new file mode 100644 index 0000000..91164e3 --- /dev/null +++ b/API_SQLuedo/Shared/Mapper/ContentLessonMapper.cs @@ -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); + } +} \ No newline at end of file diff --git a/API_SQLuedo/Shared/Mapper/LessonMapper.cs b/API_SQLuedo/Shared/Mapper/LessonMapper.cs index 2154023..b630b6e 100644 --- a/API_SQLuedo/Shared/Mapper/LessonMapper.cs +++ b/API_SQLuedo/Shared/Mapper/LessonMapper.cs @@ -10,8 +10,13 @@ public static class LessonMapper { return new LessonDto(model.Id, model.Title, model.LastPublisher, model.LastEdit); } - + 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); } @@ -26,21 +31,22 @@ public static class LessonMapper LastEdit = model.LastEdit }; } - public static LessonEntity FromDtoToEntity(this LessonDto dto) { + DateTime date = DateTime.Now; return new LessonEntity { Id = dto.Id, Title = dto.Title, LastPublisher = dto.LastPublisher, - LastEdit = dto.LastEdit + LastEdit = dto.LastEdit ?? new DateOnly(date.Year,date.Month,date.Day) }; } - + 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) diff --git a/API_SQLuedo/Shared/Mapper/ParagraphMapper.cs b/API_SQLuedo/Shared/Mapper/ParagraphMapper.cs index 69f5be8..d26464d 100644 --- a/API_SQLuedo/Shared/Mapper/ParagraphMapper.cs +++ b/API_SQLuedo/Shared/Mapper/ParagraphMapper.cs @@ -35,6 +35,8 @@ public static class ParagraphMapper Id = dto.Id, ContentTitle = dto.ContentTitle, ContentContent = dto.ContentContent, + Title = dto.Title, + Content = dto.Content, Info = dto.Info, Query = dto.Query, Comment = dto.Comment, diff --git a/API_SQLuedo/TestAPI/LessonUnitTest.cs b/API_SQLuedo/TestAPI/LessonUnitTest.cs index bdf7c7e..186dc09 100644 --- a/API_SQLuedo/TestAPI/LessonUnitTest.cs +++ b/API_SQLuedo/TestAPI/LessonUnitTest.cs @@ -179,7 +179,7 @@ public class LessonUnitTest [Fact] 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))); var lessonsController = new LessonsController(_lessonService.Object, new NullLogger()); @@ -200,7 +200,7 @@ public class LessonUnitTest [Fact] 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))); var lessonsController = new LessonsController(_lessonService.Object, new NullLogger()); diff --git a/API_SQLuedo/TestAPI/ParagraphsUnitTest.cs b/API_SQLuedo/TestAPI/ParagraphsUnitTest.cs index a7b5438..87da631 100644 --- a/API_SQLuedo/TestAPI/ParagraphsUnitTest.cs +++ b/API_SQLuedo/TestAPI/ParagraphsUnitTest.cs @@ -193,21 +193,22 @@ public class ParagraphsUnitTest [Fact] 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)) - .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)); var paragraphsController = new ParagraphsController(_paragraphService.Object, new NullLogger()); - 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)); if (paragraphsResult is CreatedResult createdObjectResult) { ParagraphDto valeur = createdObjectResult.Value as ParagraphDto; - 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("Les infos", valeur.Info); Assert.Equal("La requête requêtante", valeur.Query); @@ -219,8 +220,8 @@ public class ParagraphsUnitTest [Fact] public void CreateParagraphFail() { - _paragraphService.Setup(x => x.CreateParagraph("Le nouveau titre", "Le nouveau content", "Les infos", - "La requête requêtante", "Commentaires", 2)) + _paragraphService.Setup(x => x.CreateParagraph("Le nouveau titre", "Le nouveau content", "Title","Les infos", + "La requête requêtante", "Commentaires", "Comment", 2)) .Returns(new ParagraphDto("Le nouveau titre", "Le nouveau content", "Les infos", "La requête requêtante", "Commentaires", 2)); var paragraphsController =