From 62957eb56fd3e37d57482881cf717b2247f7451f Mon Sep 17 00:00:00 2001 From: Damien NORTIER Date: Thu, 22 Feb 2024 16:01:36 +0100 Subject: [PATCH] =?UTF-8?q?feat=20:=20cr=C3=A9ation=20d'une=20question=20e?= =?UTF-8?q?ntity?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- WebApi/Entities/QuestionEntity.cs | 21 +++++ .../AnswerExtensionMethods.cs | 94 +++++++++++++++++++ .../ExtensionsClassLibrairie.csproj | 15 +++ 3 files changed, 130 insertions(+) create mode 100644 WebApi/Entities/QuestionEntity.cs create mode 100644 WebApi/ExtensionsClassLibrairie/AnswerExtensionMethods.cs create mode 100644 WebApi/ExtensionsClassLibrairie/ExtensionsClassLibrairie.csproj diff --git a/WebApi/Entities/QuestionEntity.cs b/WebApi/Entities/QuestionEntity.cs new file mode 100644 index 0000000..38605d0 --- /dev/null +++ b/WebApi/Entities/QuestionEntity.cs @@ -0,0 +1,21 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel.DataAnnotations.Schema; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Entities +{ + public class QuestionEntity + { + public int Id { get; set; } + public string Content { get; set; } + public int difficuty { get; set; } + public int NbFalls { get; set; } + public int IdChapter { get; set; } + + [ForeignKey(nameof(AnswerEntity))] + public int IdAnswerGood { get; set; } + } +} diff --git a/WebApi/ExtensionsClassLibrairie/AnswerExtensionMethods.cs b/WebApi/ExtensionsClassLibrairie/AnswerExtensionMethods.cs new file mode 100644 index 0000000..ce9a13c --- /dev/null +++ b/WebApi/ExtensionsClassLibrairie/AnswerExtensionMethods.cs @@ -0,0 +1,94 @@ +using DTOs; +using Entities; +using Model; + +namespace ExtensionsClassLibrairie +{ + public static class AnswerExtensionMethods + { + + /// + /// convet a dto answer into a model answer + /// + /// the dto answer to convert + /// the model answer that correspond + public static Answer ToModel(this AnswerDto a) + { + return new Answer(a.Content, a.Id); + } + + /// + /// convet an entity answer into a model answer + /// + /// the entity answer to convert + /// the model answer that correspond + public static Answer ToModel(this AnswerEntity a) + { + return new Answer(a.Content, a.Id); + } + + /// + /// convet a model answer into an entity answer + /// + /// the model answer to convert + /// the entity answer that correspond + public static AnswerEntity ToEntity(this Answer a) + { + return new AnswerEntity + { + Id = a.Id, + Content = a.Content + }; + } + + /// + /// convet a dto answer into an entity answer + /// + /// the dto answer to convert + /// the entity answer that correspond + public static AnswerEntity ToEntity(this AnswerDto a) + { + return new AnswerEntity + { + Id = a.Id, + Content = a.Content + }; + } + + /// + /// convet a model answer into a dto answer + /// + /// the model answer to convert + /// the dto answer that correspond + public static AnswerDto ToDto(this Answer a) + { + return new AnswerDto(a.Content, a.Id); + } + + /// + /// convet an entity answer into a dto answer + /// + /// the entity answer to convert + /// the dto answer that correspond + public static AnswerDto ToDto(this AnswerEntity a) + { + return new AnswerDto(a.Content, a.Id); + } + + /// + /// equality protocole + /// + /// an object + /// + /// true if the object is an AnswerEntity + /// and the two contents are equals + /// (we don't care about the id because + /// he's set by the database + /// + public static bool Equals(this AnswerEntity a, object? obj) + { + return obj != null && obj is AnswerEntity other + && other.Content == a.Content; + } + } +} diff --git a/WebApi/ExtensionsClassLibrairie/ExtensionsClassLibrairie.csproj b/WebApi/ExtensionsClassLibrairie/ExtensionsClassLibrairie.csproj new file mode 100644 index 0000000..0c6b8fd --- /dev/null +++ b/WebApi/ExtensionsClassLibrairie/ExtensionsClassLibrairie.csproj @@ -0,0 +1,15 @@ + + + + net8.0 + enable + enable + + + + + + + + +