From 4d2047b03ad40335ac09e9900b86d858c6a42dce Mon Sep 17 00:00:00 2001 From: Kevin MONDEJAR Date: Thu, 6 Mar 2025 15:58:28 +0100 Subject: [PATCH 01/65] =?UTF-8?q?Pr=C3=A9paration=20des=20projet=20+=20Int?= =?UTF-8?q?erface=20Service?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- WF_EF_Api/.dockerignore | 30 ++++++ WF_EF_Api/ConsoleTest/ConsoleTest.csproj | 10 ++ WF_EF_Api/ConsoleTest/Program.cs | 1 + WF_EF_Api/Contextlib/Contextlib.csproj | 9 ++ WF_EF_Api/Entity/Entity.csproj | 9 ++ WF_EF_Api/Model/Entities.csproj | 9 ++ WF_EF_Api/Model2entities/Class1.cs | 7 ++ .../Model2entities/Model2Entities.csproj | 9 ++ WF_EF_Api/Shared/ICharacterService.cs | 39 ++++++++ WF_EF_Api/Shared/IComentaryService.cs | 54 +++++++++++ WF_EF_Api/Shared/IFavoriteService.cs | 28 ++++++ WF_EF_Api/Shared/IImagesService.cs | 39 ++++++++ WF_EF_Api/Shared/IQuestionService.cs | 59 ++++++++++++ WF_EF_Api/Shared/IQuizService.cs | 41 ++++++++ WF_EF_Api/Shared/IQuoteService.cs | 96 +++++++++++++++++++ WF_EF_Api/Shared/ISourceService.cs | 47 +++++++++ WF_EF_Api/Shared/IUserService.cs | 67 +++++++++++++ WF_EF_Api/Shared/PaginationResult.cs | 33 +++++++ WF_EF_Api/Shared/Shared.csproj | 9 ++ .../StubbedContextLib.csproj | 9 ++ .../TestModel2Entities.csproj | 9 ++ WF_EF_Api/WF_EF_Api.sln | 79 +++++++++++++++ .../Controllers/WeatherForecastController.cs | 33 +++++++ WF_EF_Api/WfApi/Dockerfile | 25 +++++ WF_EF_Api/WfApi/Program.cs | 25 +++++ .../WfApi/Properties/launchSettings.json | 52 ++++++++++ WF_EF_Api/WfApi/WeatherForecast.cs | 13 +++ WF_EF_Api/WfApi/WfApi.csproj | 16 ++++ WF_EF_Api/WfApi/WfApi.http | 6 ++ WF_EF_Api/WfApi/appsettings.Development.json | 8 ++ WF_EF_Api/WfApi/appsettings.json | 9 ++ WF_EF_Api/XUnitTest/UnitTest1.cs | 11 +++ WF_EF_Api/XUnitTest/XUnitTest.csproj | 23 +++++ 33 files changed, 914 insertions(+) create mode 100644 WF_EF_Api/.dockerignore create mode 100644 WF_EF_Api/ConsoleTest/ConsoleTest.csproj create mode 100644 WF_EF_Api/ConsoleTest/Program.cs create mode 100644 WF_EF_Api/Contextlib/Contextlib.csproj create mode 100644 WF_EF_Api/Entity/Entity.csproj create mode 100644 WF_EF_Api/Model/Entities.csproj create mode 100644 WF_EF_Api/Model2entities/Class1.cs create mode 100644 WF_EF_Api/Model2entities/Model2Entities.csproj create mode 100644 WF_EF_Api/Shared/ICharacterService.cs create mode 100644 WF_EF_Api/Shared/IComentaryService.cs create mode 100644 WF_EF_Api/Shared/IFavoriteService.cs create mode 100644 WF_EF_Api/Shared/IImagesService.cs create mode 100644 WF_EF_Api/Shared/IQuestionService.cs create mode 100644 WF_EF_Api/Shared/IQuizService.cs create mode 100644 WF_EF_Api/Shared/IQuoteService.cs create mode 100644 WF_EF_Api/Shared/ISourceService.cs create mode 100644 WF_EF_Api/Shared/IUserService.cs create mode 100644 WF_EF_Api/Shared/PaginationResult.cs create mode 100644 WF_EF_Api/Shared/Shared.csproj create mode 100644 WF_EF_Api/StubbedContextLib/StubbedContextLib.csproj create mode 100644 WF_EF_Api/TestModel2Entities/TestModel2Entities.csproj create mode 100644 WF_EF_Api/WF_EF_Api.sln create mode 100644 WF_EF_Api/WfApi/Controllers/WeatherForecastController.cs create mode 100644 WF_EF_Api/WfApi/Dockerfile create mode 100644 WF_EF_Api/WfApi/Program.cs create mode 100644 WF_EF_Api/WfApi/Properties/launchSettings.json create mode 100644 WF_EF_Api/WfApi/WeatherForecast.cs create mode 100644 WF_EF_Api/WfApi/WfApi.csproj create mode 100644 WF_EF_Api/WfApi/WfApi.http create mode 100644 WF_EF_Api/WfApi/appsettings.Development.json create mode 100644 WF_EF_Api/WfApi/appsettings.json create mode 100644 WF_EF_Api/XUnitTest/UnitTest1.cs create mode 100644 WF_EF_Api/XUnitTest/XUnitTest.csproj diff --git a/WF_EF_Api/.dockerignore b/WF_EF_Api/.dockerignore new file mode 100644 index 0000000..4d72b4f --- /dev/null +++ b/WF_EF_Api/.dockerignore @@ -0,0 +1,30 @@ +**/.classpath +**/.dockerignore +**/.env +**/.git +**/.gitignore +**/.project +**/.settings +**/.toolstarget +**/.vs +**/.vscode +**/*.*proj.user +**/*.dbmdl +**/*.jfm +**/azds.yaml +**/bin +**/charts +**/docker-compose* +**/Dockerfile* +**/node_modules +**/npm-debug.log +**/obj +**/secrets.dev.yaml +**/values.dev.yaml +LICENSE +README.md +!**/.gitignore +!.git/HEAD +!.git/config +!.git/packed-refs +!.git/refs/heads/** \ No newline at end of file diff --git a/WF_EF_Api/ConsoleTest/ConsoleTest.csproj b/WF_EF_Api/ConsoleTest/ConsoleTest.csproj new file mode 100644 index 0000000..206b89a --- /dev/null +++ b/WF_EF_Api/ConsoleTest/ConsoleTest.csproj @@ -0,0 +1,10 @@ + + + + Exe + net8.0 + enable + enable + + + diff --git a/WF_EF_Api/ConsoleTest/Program.cs b/WF_EF_Api/ConsoleTest/Program.cs new file mode 100644 index 0000000..af0744a --- /dev/null +++ b/WF_EF_Api/ConsoleTest/Program.cs @@ -0,0 +1 @@ + diff --git a/WF_EF_Api/Contextlib/Contextlib.csproj b/WF_EF_Api/Contextlib/Contextlib.csproj new file mode 100644 index 0000000..bb23fb7 --- /dev/null +++ b/WF_EF_Api/Contextlib/Contextlib.csproj @@ -0,0 +1,9 @@ + + + + net8.0 + enable + enable + + + diff --git a/WF_EF_Api/Entity/Entity.csproj b/WF_EF_Api/Entity/Entity.csproj new file mode 100644 index 0000000..bb23fb7 --- /dev/null +++ b/WF_EF_Api/Entity/Entity.csproj @@ -0,0 +1,9 @@ + + + + net8.0 + enable + enable + + + diff --git a/WF_EF_Api/Model/Entities.csproj b/WF_EF_Api/Model/Entities.csproj new file mode 100644 index 0000000..bb23fb7 --- /dev/null +++ b/WF_EF_Api/Model/Entities.csproj @@ -0,0 +1,9 @@ + + + + net8.0 + enable + enable + + + diff --git a/WF_EF_Api/Model2entities/Class1.cs b/WF_EF_Api/Model2entities/Class1.cs new file mode 100644 index 0000000..7214afa --- /dev/null +++ b/WF_EF_Api/Model2entities/Class1.cs @@ -0,0 +1,7 @@ +namespace Model2entities +{ + public class Class1 + { + + } +} diff --git a/WF_EF_Api/Model2entities/Model2Entities.csproj b/WF_EF_Api/Model2entities/Model2Entities.csproj new file mode 100644 index 0000000..bb23fb7 --- /dev/null +++ b/WF_EF_Api/Model2entities/Model2Entities.csproj @@ -0,0 +1,9 @@ + + + + net8.0 + enable + enable + + + diff --git a/WF_EF_Api/Shared/ICharacterService.cs b/WF_EF_Api/Shared/ICharacterService.cs new file mode 100644 index 0000000..a1c1a57 --- /dev/null +++ b/WF_EF_Api/Shared/ICharacterService.cs @@ -0,0 +1,39 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Shared +{ + public interface ICharacterService + { + // Retrieves a character by its unique identifier (id). + // 'id' is the unique identifier of the character. + Task GetCharById(int id); + + // Retrieves a character by its name. + // 'name' is the name of the character to be retrieved. + Task GetCharByName(string name); + + // Retrieves all characters, with pagination support. + // This returns a list of all characters in the system. + Task> GetAll(); + + // Adds a new character to the system. + // 'character' is the character object that will be added to the system. + Task AddCharacter(TChar character); + + // Updates an existing character identified by its unique identifier ('id'). + // 'id' is the unique identifier of the character to be updated + // 'character' contains the updated character data. + Task UpdateCharacter(int id, TChar character); + + // Removes a character from the system based on its unique identifier ('id'). + // 'id' is the unique identifier of the character to be removed. + Task RemoveCharacter(int id); + + // Retrieves the unique identifier of the last added character. + Task GetLastCharId(); + } +} diff --git a/WF_EF_Api/Shared/IComentaryService.cs b/WF_EF_Api/Shared/IComentaryService.cs new file mode 100644 index 0000000..2cf4fe1 --- /dev/null +++ b/WF_EF_Api/Shared/IComentaryService.cs @@ -0,0 +1,54 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Shared +{ + public interface ICommentService + { + // Retrieves a comment by its unique identifier (id). + // 'id' is the unique identifier of the comment. + Task GetCommentById(int id); + + // Retrieves comments related to a specific quote, with pagination. + // 'quoteId' is the unique identifier of the quote. + // 'index' is the page number (for pagination). + // 'pageSize' is the number of comments per page. + Task> GetCommentByQuote(int quoteId, int index, int pageSize); + + // Retrieves all comments, with pagination support. + // This returns a list of all comments. + Task> GetAllComment(); + + // Retrieves comments made by a specific user, with pagination. + // 'userId' is the unique identifier of the user. + // 'index' is the page number (for pagination). + // 'pageSize' is the number of comments per page. + Task> GetCommentByUser(int userId, int index, int pageSize); + + // Adds a new commenT. + // 'comment' is the comment object that will be added. + Task AddComment(TComment comment); + + // Updates an existing comment identified by 'id'. + // 'id' is the unique identifier of the comment, and 'comment' contains the updated comment data. + Task UpdateComment(int id, TComment comment); + + // Removes a comment based on its unique identifier ('id'). + // 'id' is the unique identifier of the comment to be removed. + Task RemoveComment(int id); + + // Deletes all comments related to a specific quote. + // 'quoteId' is the unique identifier of the quote for which comments will be deleted. + Task DeleteCommentForQuote(int quoteId); + + // Deletes all comments made by a specific user. + // 'userId' is the unique identifier of the user whose comments will be deleted. + Task DeleteCommentForuser(int userId); + + // Retrieves the last comment ID. + Task LastCommentId(); + } +} diff --git a/WF_EF_Api/Shared/IFavoriteService.cs b/WF_EF_Api/Shared/IFavoriteService.cs new file mode 100644 index 0000000..53ca0a7 --- /dev/null +++ b/WF_EF_Api/Shared/IFavoriteService.cs @@ -0,0 +1,28 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Shared +{ + public interface IFavoriteService + { + // Adds a quote to a user's list of favorites. + // 'quoteid' is the unique identifier of the quote to be added to favorites. + // 'userId' is the unique identifier of the user who is adding the quote to their favorites. + Task AddFavorite(int quoteid, int userId); + + // Removes a quote from a user's list of favorites. + // 'quoteid' is the unique identifier of the quote to be removed from favorites. + // 'userId' is the unique identifier of the user who is removing the quote from their favorites. + Task RemoveFavorite(int quoteid, int userId); + + // Removes all favorite quotes for a specific user. + // 'userId' is the unique identifier of the user whose favorites will be removed. + Task RemoveAllFavoriteForUser(int userId); + + // Removes a specific quote from the favorite lists of all users. + // 'quoteId' is the unique identifier of the quote to be removed from all users' favorites. + Task RemoveAllFavoriteForQuote(int quoteId); + } diff --git a/WF_EF_Api/Shared/IImagesService.cs b/WF_EF_Api/Shared/IImagesService.cs new file mode 100644 index 0000000..e2d0465 --- /dev/null +++ b/WF_EF_Api/Shared/IImagesService.cs @@ -0,0 +1,39 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Shared +{ + public interface IImagesService + { + // Retrieves an image by its unique identifier (id). + // 'id' is the unique identifier of the image. + Task GetImageById(string id); + + // Retrieves all images, with pagination support. + // This returns a list of all images in the system. + Task> GetAllImage(); + + // Retrieves a subset of images based on the provided index and page size. + // 'index' is the starting point for pagination (page number). + // 'pageSize' is the number of images per page. + Task> GetSomeImage(int index, int pageSize); + + // Adds a new image to the system. + // 'image' is the image object that will be added to the system. + Task AddImage(TImage image); + + // Updates an existing image identified by its unique identifier ('id'). + // 'id' is the unique identifier of the image to be updated, and 'image' contains the updated image data. + Task UpdateImage(int id, TImage image); + + // Removes an image from the system based on its unique identifier ('id'). + // 'id' is the unique identifier of the image to be removed from the system. + Task RemoveImage(int id); + + // Retrieves the last Image ID. + Task GetLastImageId(); + } +} diff --git a/WF_EF_Api/Shared/IQuestionService.cs b/WF_EF_Api/Shared/IQuestionService.cs new file mode 100644 index 0000000..73b8f0d --- /dev/null +++ b/WF_EF_Api/Shared/IQuestionService.cs @@ -0,0 +1,59 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Shared +{ + public interface IQuestionService + { + // Retrieves all questions, with pagination support. + // This returns a list of all questions in the system. + Task> GetAllQuestion(); + + // Retrieves a subset of questions based on the provided index and page size. + // 'index' is the starting point for pagination (page number). + // 'pageSize' is the number of questions per page. + Task> GetSomeQuestion(int index, int pageSize); + + // Retrieves questions that are marked as invalid, with pagination support. + // 'index' is the starting page (page number) + // 'pageSize' is the number of questions per page. + Task> GetInvalidQuestion(int index, int pageSize); + + // Retrieves a specific question by its unique identifier (id). + // 'id' is the unique identifier of the question. + Task GetQuestionById(int id); + + // Retrieves a random question from the system. + Task GetRandomQuestion(); + + // Adds a new question to the system. + // 'question' is the question object that will be added. + Task AddQuestion(TQuestion question); + + // Updates an existing question identified by 'id'. + // 'id' is the unique identifier of the question + // 'question' contains the new question data. + Task UpdateQuestion(int id, TQuestion question); + + // Removes a question from the system based on its unique identifier ('id'). + // 'id' is the unique identifier of the question to be removed. + Task RemoveQuestion(int id); + + // Retrieves the total count of questions in the system. + Task CountQuestions(); + + // Validates or invalidates a question based on its unique identifier ('id'). + // 'id' is the unique identifier of the question + // 'isvalid' is a boolean indicating whether the question is valid. + Task ValidateQuestion(int id, bool isvalid); + + // Retrieves a random question from a quote to a character. + Task GetRandomQuestionQuoteToCharacter(); + + // Retrieves a random question from a quote to a source. + Task GetRandomQuestionQuoteToSource(); + } +} diff --git a/WF_EF_Api/Shared/IQuizService.cs b/WF_EF_Api/Shared/IQuizService.cs new file mode 100644 index 0000000..e0735b2 --- /dev/null +++ b/WF_EF_Api/Shared/IQuizService.cs @@ -0,0 +1,41 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Shared +{ + public interface IQuizService + { + // Retrieves a specific quiz by its unique identifier (id). + // 'id' is the unique identifier of the quiz to be retrieved. + Task GetQuizById(int id); + + // Retrieves all quizzes, with pagination support. + // This returns a list of all quizzes in the system. + Task> GetAllQuiz(); + + // Retrieves a subset of quizzes based on the provided index and page size. + // 'index' is the starting point for pagination (page number). + // 'pageSize' is the number of quizzes per page. + Task> GetSomeQuiz(int index, int pageSize); + + // Adds a new quiz to the system. + // 'quiz' is the quiz object that will be added to the system. + Task AddQuiz(TQuiz quiz); + + // Updates an existing quiz identified by its unique identifier ('quizId'). + // 'quizId' is the unique identifier of the quiz to be updated + // 'quiz' contains the updated quiz data. + Task UpdateQiz(int quizId, TQuiz quiz); + + // Removes a quiz from the system based on its unique identifier ('quizId'). + // 'quizId' is the unique identifier of the quiz to be removed from the system. + Task RemoveQuiz(int quizId); + + // Retrieves the number of questions in a specific quiz identified by its unique identifier ('quizId'). + // 'quizId' is the unique identifier of the quiz for which the number of questions is requested. + Task GetNbQuestionQuiz(int quizId); + } +} diff --git a/WF_EF_Api/Shared/IQuoteService.cs b/WF_EF_Api/Shared/IQuoteService.cs new file mode 100644 index 0000000..5a4e5e9 --- /dev/null +++ b/WF_EF_Api/Shared/IQuoteService.cs @@ -0,0 +1,96 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Shared +{ + public interface IQuoteService + { + // Retrieves the daily quote in a specified language. + // 'lang' is a language code. + Task GetDayliQuote(int lang); + + // Retrieves a specific quote by its unique identifier (id). + Task GetQuoteById(int id); + + // Retrieves all available quotes in the system, without any filters. + Task> GetAllQuote(); + + // Retrieves a page of some availble quote based on the index (pagination) + // 'index' is the starting point for pagination + // 'pageSize' determines the number of quotes per page + Task> GetSomeQuote(int index, int pageSize); + + // Retrieves all available quotes but filtered by language. + // 'lang' is a language code used to filter the quotes in the chosen language. + Task> GetAllQuoteLang(int lang); + + // Retrieves a page of quote suggestions based on the index (pagination) and language. + // 'index' is the starting point for pagination + // 'pageSize' determines the number of quotes per page + // 'lang' specifies the language for the suggestions. + Task> GetSuggestions(int index, int pageSize, int lang); + + // Retrieves the favorite quotes of a specific user. + // 'index' is the starting point for pagination + // 'pageSize' determines the number of quotes per page + // 'UserId' is the identifier of the user to fetch their favorite quotes. + Task> GetFavorites(int index, int pageSize, int UserId); + + // Retrieves a page of valid quotes with pagination. + // 'index' is the current page + // 'pageSize' is the number of quotes per page. + Task> GetValidQuote(int index, int pageSize); + + // Retrieves a page of invalid quotes with pagination. + // 'index' is the current page + // 'pageSize' is the number of quotes per page. + Task> GetInvalidQuote(int index, int pageSize); + + + // Searches for quotes based on content (text of the quote), with pagination and filtering by language. + // 'content' is the text of the quote + // 'index' is the current page + // 'pageSize' is the number of results per page + // 'lang' is the language code to filter the results. + Task> SearchByContent(string content, int index, int pageSize, int lang); + + // Searches for quotes by their source, with pagination and filtering by language. + // 'source' is the source of the quote + // 'index' is the current page + // 'pageSize' is the number of results per page + // 'lang' is the language code to filter the results. + Task> SearchBySource(string source, int index, int pageSize, int lang); + + // Searches for quotes related to a specific character, with pagination and filtering by language. + // 'character' refers to a name or role in the content + // 'index' is the current page + // 'pageSize' is the number of results per page, + // 'lang' is the language code to filter the results. + Task> SearchByCharacter(string character, int index, int pageSize, int lang); + + // Adds a new quote. + // 'quote' is the quote object that will be added. + Task AddQuote(TQuote quote); + + // Updates an existing quote identified by 'quoteId' with new details. + // 'quoteId' is the ID of the quote to be updated + // 'quote' contains the new data. + Task UpdateQuote(int quoteId, TQuote quote); + + // Removes a quote based on its unique identifier ('quoteId'). + Task RemoveQuote(int quoteId); + + // Returns the total number of quotes available. + Task CountQuotes(); + + // Retrieves the last ID. + Task GetLastQuoteId(); + + // Validates or invalidates a quote based on the 'quoteId' and a boolean value ('isValidate'). + // If 'isValidate' is true, the quote is marked as valid; if false, it is invalid. + Task ValidateQuote(int quoteId, bool isValidate); + } +} diff --git a/WF_EF_Api/Shared/ISourceService.cs b/WF_EF_Api/Shared/ISourceService.cs new file mode 100644 index 0000000..228078e --- /dev/null +++ b/WF_EF_Api/Shared/ISourceService.cs @@ -0,0 +1,47 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Shared +{ + public interface ISourceService + { + // Retrieves a source by its unique identifier (id). + // 'id' is the unique identifier of the source. + Task GetSourceById(int id); + + // Retrieves a source by its title. + // 'title' is the title of the source to be retrieved. + Task GetSourceByTitle(string title); + + // Retrieves a source by its date. + // 'date' is the date associated with the source to be retrieved. + Task GetSourceByDate(string date); + + // Retrieves a source by its type. + // 'type' is the type of the source to be retrieved. + Task GetSourceByType(string type); + + // Retrieves all sources, with pagination support. + // This returns a list of all sources in the system. + Task> GetAll(); + + // Adds a new source to the system. + // 'source' is the source object that will be added. + Task AddSource(TSource source); + + // Updates an existing source identified by its unique identifier ('id'). + // 'id' is the unique identifier of the source to be updated + // 'source' contains the updated source data. + Task UpdateSource(int id, TSource source); + + // Removes a source from the system based on its unique identifier ('id'). + // 'id' is the unique identifier of the source to be removed. + Task RemoveSource(int id); + + // Retrieves the unique identifier of the last added source. + Task GetLastSourceId(); + } +} diff --git a/WF_EF_Api/Shared/IUserService.cs b/WF_EF_Api/Shared/IUserService.cs new file mode 100644 index 0000000..d8028ee --- /dev/null +++ b/WF_EF_Api/Shared/IUserService.cs @@ -0,0 +1,67 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Shared +{ + public interface IUserService + { + // Retrieves a user by their unique identifier (id). + // 'id' is the unique identifier of the user. + Task GetUserById(int id); + + // Retrieves a user by their username. + // 'username' is the username of the user to be retrieved. + Task GetUserByUsername(string username); + + // Retrieves a user by their email address. + // 'email' is the email address of the user to be retrieved. + Task GetUserByEmail(string email); + + // Retrieves all users. + // This returns a list of users with pagination information (e.g., total count, page size). + Task> GetAllUser(); + + // Retrieves a subset of users based on the provided index and page size. + // 'index' is the starting point for pagination (page number). + // 'pageSize' is the number of users per page. + Task> GetSomeUser(int index, int pageSize); + + // Adds a new user to the system. + // 'user' is the user object that will be added to the system. + Task AddUser(TUser user); + + // Updates the details of an existing user identified by 'userId'. + // 'userId' is the ID of the user to be updated, and 'user' contains the new user data. + Task UpdateUser(int userId, TUser user); + + // Removes a user from the system based on their unique identifier ('userId'). + // 'userId' is the unique identifier of the user to be removed. + Task RemoveUser(int userId); + + // Retrieves the hashed password for a given username. + // 'username' is the username for which the password hash is to be retrieved. + Task GetHashPassword(string username); + + + // Checks if a username already exists. + // 'username' is the username to check for existence. + Task ExistUsername(string username); + + // Checks if an email address already exists. + // 'email' is the email address to check for existence. + Task ExistEmail(string email); + + // Sets the admin role for a user. + // 'isAdmin' is a boolean indicating whether the user should have admin privileges. + Task SetAdminRole(bool isAdmin); + + // Retrieves the total count of users. + Task CountUser(); + + // Retrieves the last user ID. + Task GetLastUserId(); + } +} diff --git a/WF_EF_Api/Shared/PaginationResult.cs b/WF_EF_Api/Shared/PaginationResult.cs new file mode 100644 index 0000000..5347d3e --- /dev/null +++ b/WF_EF_Api/Shared/PaginationResult.cs @@ -0,0 +1,33 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +// Represents a paginated result set for a collection of items. +public class PaginationResult +{ + // Total number in the item List. + public int totalCount { get; set; } + + // The current page index (starting from 0). + public int pageIndex { get; set; } + + // The number of items displayed per page. + public int countPerPage { get; set; } + + // The list of items for the current page. + public List items { get; set; } + + // Constructor to initialize a new instance of the PaginationResult class. + // 'totalCount' is the total number of items, 'pageIndex' is the current page, + // 'countPerPage' is the number of items per page, and 'items' is the list of items for the current page. + public PaginationResult(int totalCount, int pageIndex, int countPerPage, List items) + { + this.totalCount = totalCount; // Sets the total number of items available. + this.pageIndex = pageIndex; // Sets the current page index (starting from 1). + this.countPerPage = countPerPage; // Sets the number of items per page. + this.items = items; // Sets the items for the current page. + } +} + diff --git a/WF_EF_Api/Shared/Shared.csproj b/WF_EF_Api/Shared/Shared.csproj new file mode 100644 index 0000000..bb23fb7 --- /dev/null +++ b/WF_EF_Api/Shared/Shared.csproj @@ -0,0 +1,9 @@ + + + + net8.0 + enable + enable + + + diff --git a/WF_EF_Api/StubbedContextLib/StubbedContextLib.csproj b/WF_EF_Api/StubbedContextLib/StubbedContextLib.csproj new file mode 100644 index 0000000..bb23fb7 --- /dev/null +++ b/WF_EF_Api/StubbedContextLib/StubbedContextLib.csproj @@ -0,0 +1,9 @@ + + + + net8.0 + enable + enable + + + diff --git a/WF_EF_Api/TestModel2Entities/TestModel2Entities.csproj b/WF_EF_Api/TestModel2Entities/TestModel2Entities.csproj new file mode 100644 index 0000000..bb23fb7 --- /dev/null +++ b/WF_EF_Api/TestModel2Entities/TestModel2Entities.csproj @@ -0,0 +1,9 @@ + + + + net8.0 + enable + enable + + + diff --git a/WF_EF_Api/WF_EF_Api.sln b/WF_EF_Api/WF_EF_Api.sln new file mode 100644 index 0000000..bff150d --- /dev/null +++ b/WF_EF_Api/WF_EF_Api.sln @@ -0,0 +1,79 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 17 +VisualStudioVersion = 17.9.34723.18 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ConsoleTest", "ConsoleTest\ConsoleTest.csproj", "{A8B0E4D8-0726-4248-BB6D-DAA2545270B1}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Shared", "Shared\Shared.csproj", "{792EF125-E2D4-457C-B536-BDAEFB49D14E}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Entity", "Entity\Entity.csproj", "{69A4450C-AA43-4622-A866-9A5F7C8A2C14}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Contextlib", "Contextlib\Contextlib.csproj", "{32977454-CE94-4532-AE26-29F6951B78CF}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "StubbedContextLib", "StubbedContextLib\StubbedContextLib.csproj", "{5CD69B14-C6AE-4628-A374-996C486E25F2}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TestModel2Entities", "TestModel2Entities\TestModel2Entities.csproj", "{2CF20FAC-C2F1-4048-9D46-F39081B0FBEF}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Entities", "Model\Entities.csproj", "{C51815EE-ED06-4F38-955E-7EBB72C0A7EF}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Model2Entities", "Model2entities\Model2Entities.csproj", "{4A1CBA3D-C798-4E19-865F-39F919F1205A}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "XUnitTest", "XUnitTest\XUnitTest.csproj", "{48002CA2-7CFF-4077-90CF-392476320CE3}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WfApi", "WfApi\WfApi.csproj", "{D4EEE1BF-CDCB-4E66-997B-7A5984DA7995}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {A8B0E4D8-0726-4248-BB6D-DAA2545270B1}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {A8B0E4D8-0726-4248-BB6D-DAA2545270B1}.Debug|Any CPU.Build.0 = Debug|Any CPU + {A8B0E4D8-0726-4248-BB6D-DAA2545270B1}.Release|Any CPU.ActiveCfg = Release|Any CPU + {A8B0E4D8-0726-4248-BB6D-DAA2545270B1}.Release|Any CPU.Build.0 = Release|Any CPU + {792EF125-E2D4-457C-B536-BDAEFB49D14E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {792EF125-E2D4-457C-B536-BDAEFB49D14E}.Debug|Any CPU.Build.0 = Debug|Any CPU + {792EF125-E2D4-457C-B536-BDAEFB49D14E}.Release|Any CPU.ActiveCfg = Release|Any CPU + {792EF125-E2D4-457C-B536-BDAEFB49D14E}.Release|Any CPU.Build.0 = Release|Any CPU + {69A4450C-AA43-4622-A866-9A5F7C8A2C14}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {69A4450C-AA43-4622-A866-9A5F7C8A2C14}.Debug|Any CPU.Build.0 = Debug|Any CPU + {69A4450C-AA43-4622-A866-9A5F7C8A2C14}.Release|Any CPU.ActiveCfg = Release|Any CPU + {69A4450C-AA43-4622-A866-9A5F7C8A2C14}.Release|Any CPU.Build.0 = Release|Any CPU + {32977454-CE94-4532-AE26-29F6951B78CF}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {32977454-CE94-4532-AE26-29F6951B78CF}.Debug|Any CPU.Build.0 = Debug|Any CPU + {32977454-CE94-4532-AE26-29F6951B78CF}.Release|Any CPU.ActiveCfg = Release|Any CPU + {32977454-CE94-4532-AE26-29F6951B78CF}.Release|Any CPU.Build.0 = Release|Any CPU + {5CD69B14-C6AE-4628-A374-996C486E25F2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {5CD69B14-C6AE-4628-A374-996C486E25F2}.Debug|Any CPU.Build.0 = Debug|Any CPU + {5CD69B14-C6AE-4628-A374-996C486E25F2}.Release|Any CPU.ActiveCfg = Release|Any CPU + {5CD69B14-C6AE-4628-A374-996C486E25F2}.Release|Any CPU.Build.0 = Release|Any CPU + {2CF20FAC-C2F1-4048-9D46-F39081B0FBEF}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {2CF20FAC-C2F1-4048-9D46-F39081B0FBEF}.Debug|Any CPU.Build.0 = Debug|Any CPU + {2CF20FAC-C2F1-4048-9D46-F39081B0FBEF}.Release|Any CPU.ActiveCfg = Release|Any CPU + {2CF20FAC-C2F1-4048-9D46-F39081B0FBEF}.Release|Any CPU.Build.0 = Release|Any CPU + {C51815EE-ED06-4F38-955E-7EBB72C0A7EF}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {C51815EE-ED06-4F38-955E-7EBB72C0A7EF}.Debug|Any CPU.Build.0 = Debug|Any CPU + {C51815EE-ED06-4F38-955E-7EBB72C0A7EF}.Release|Any CPU.ActiveCfg = Release|Any CPU + {C51815EE-ED06-4F38-955E-7EBB72C0A7EF}.Release|Any CPU.Build.0 = Release|Any CPU + {4A1CBA3D-C798-4E19-865F-39F919F1205A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {4A1CBA3D-C798-4E19-865F-39F919F1205A}.Debug|Any CPU.Build.0 = Debug|Any CPU + {4A1CBA3D-C798-4E19-865F-39F919F1205A}.Release|Any CPU.ActiveCfg = Release|Any CPU + {4A1CBA3D-C798-4E19-865F-39F919F1205A}.Release|Any CPU.Build.0 = Release|Any CPU + {48002CA2-7CFF-4077-90CF-392476320CE3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {48002CA2-7CFF-4077-90CF-392476320CE3}.Debug|Any CPU.Build.0 = Debug|Any CPU + {48002CA2-7CFF-4077-90CF-392476320CE3}.Release|Any CPU.ActiveCfg = Release|Any CPU + {48002CA2-7CFF-4077-90CF-392476320CE3}.Release|Any CPU.Build.0 = Release|Any CPU + {D4EEE1BF-CDCB-4E66-997B-7A5984DA7995}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {D4EEE1BF-CDCB-4E66-997B-7A5984DA7995}.Debug|Any CPU.Build.0 = Debug|Any CPU + {D4EEE1BF-CDCB-4E66-997B-7A5984DA7995}.Release|Any CPU.ActiveCfg = Release|Any CPU + {D4EEE1BF-CDCB-4E66-997B-7A5984DA7995}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {EC43AAEE-68F6-4CA2-A195-14A91E7D53C0} + EndGlobalSection +EndGlobal diff --git a/WF_EF_Api/WfApi/Controllers/WeatherForecastController.cs b/WF_EF_Api/WfApi/Controllers/WeatherForecastController.cs new file mode 100644 index 0000000..c618314 --- /dev/null +++ b/WF_EF_Api/WfApi/Controllers/WeatherForecastController.cs @@ -0,0 +1,33 @@ +using Microsoft.AspNetCore.Mvc; + +namespace WfApi.Controllers +{ + [ApiController] + [Route("[controller]")] + public class WeatherForecastController : ControllerBase + { + private static readonly string[] Summaries = new[] + { + "Freezing", "Bracing", "Chilly", "Cool", "Mild", "Warm", "Balmy", "Hot", "Sweltering", "Scorching" + }; + + private readonly ILogger _logger; + + public WeatherForecastController(ILogger logger) + { + _logger = logger; + } + + [HttpGet(Name = "GetWeatherForecast")] + public IEnumerable Get() + { + return Enumerable.Range(1, 5).Select(index => new WeatherForecast + { + Date = DateOnly.FromDateTime(DateTime.Now.AddDays(index)), + TemperatureC = Random.Shared.Next(-20, 55), + Summary = Summaries[Random.Shared.Next(Summaries.Length)] + }) + .ToArray(); + } + } +} diff --git a/WF_EF_Api/WfApi/Dockerfile b/WF_EF_Api/WfApi/Dockerfile new file mode 100644 index 0000000..a318a5b --- /dev/null +++ b/WF_EF_Api/WfApi/Dockerfile @@ -0,0 +1,25 @@ +#See https://aka.ms/customizecontainer to learn how to customize your debug container and how Visual Studio uses this Dockerfile to build your images for faster debugging. + +FROM mcr.microsoft.com/dotnet/aspnet:8.0 AS base +USER app +WORKDIR /app +EXPOSE 8080 +EXPOSE 8081 + +FROM mcr.microsoft.com/dotnet/sdk:8.0 AS build +ARG BUILD_CONFIGURATION=Release +WORKDIR /src +COPY ["WfApi/WfApi.csproj", "WfApi/"] +RUN dotnet restore "./WfApi/WfApi.csproj" +COPY . . +WORKDIR "/src/WfApi" +RUN dotnet build "./WfApi.csproj" -c $BUILD_CONFIGURATION -o /app/build + +FROM build AS publish +ARG BUILD_CONFIGURATION=Release +RUN dotnet publish "./WfApi.csproj" -c $BUILD_CONFIGURATION -o /app/publish /p:UseAppHost=false + +FROM base AS final +WORKDIR /app +COPY --from=publish /app/publish . +ENTRYPOINT ["dotnet", "WfApi.dll"] \ No newline at end of file diff --git a/WF_EF_Api/WfApi/Program.cs b/WF_EF_Api/WfApi/Program.cs new file mode 100644 index 0000000..15eacee --- /dev/null +++ b/WF_EF_Api/WfApi/Program.cs @@ -0,0 +1,25 @@ +var builder = WebApplication.CreateBuilder(args); + +// Add services to the container. + +builder.Services.AddControllers(); +// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle +builder.Services.AddEndpointsApiExplorer(); +builder.Services.AddSwaggerGen(); + +var app = builder.Build(); + +// Configure the HTTP request pipeline. +if (app.Environment.IsDevelopment()) +{ + app.UseSwagger(); + app.UseSwaggerUI(); +} + +app.UseHttpsRedirection(); + +app.UseAuthorization(); + +app.MapControllers(); + +app.Run(); diff --git a/WF_EF_Api/WfApi/Properties/launchSettings.json b/WF_EF_Api/WfApi/Properties/launchSettings.json new file mode 100644 index 0000000..6e4ee26 --- /dev/null +++ b/WF_EF_Api/WfApi/Properties/launchSettings.json @@ -0,0 +1,52 @@ +{ + "profiles": { + "http": { + "commandName": "Project", + "launchBrowser": true, + "launchUrl": "swagger", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + }, + "dotnetRunMessages": true, + "applicationUrl": "http://localhost:5239" + }, + "https": { + "commandName": "Project", + "launchBrowser": true, + "launchUrl": "swagger", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + }, + "dotnetRunMessages": true, + "applicationUrl": "https://localhost:7250;http://localhost:5239" + }, + "IIS Express": { + "commandName": "IISExpress", + "launchBrowser": true, + "launchUrl": "swagger", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + } + }, + "Container (Dockerfile)": { + "commandName": "Docker", + "launchBrowser": true, + "launchUrl": "{Scheme}://{ServiceHost}:{ServicePort}/swagger", + "environmentVariables": { + "ASPNETCORE_HTTPS_PORTS": "8081", + "ASPNETCORE_HTTP_PORTS": "8080" + }, + "publishAllPorts": true, + "useSSL": true + } + }, + "$schema": "http://json.schemastore.org/launchsettings.json", + "iisSettings": { + "windowsAuthentication": false, + "anonymousAuthentication": true, + "iisExpress": { + "applicationUrl": "http://localhost:23612", + "sslPort": 44320 + } + } +} \ No newline at end of file diff --git a/WF_EF_Api/WfApi/WeatherForecast.cs b/WF_EF_Api/WfApi/WeatherForecast.cs new file mode 100644 index 0000000..cb85aa4 --- /dev/null +++ b/WF_EF_Api/WfApi/WeatherForecast.cs @@ -0,0 +1,13 @@ +namespace WfApi +{ + public class WeatherForecast + { + public DateOnly Date { get; set; } + + public int TemperatureC { get; set; } + + public int TemperatureF => 32 + (int)(TemperatureC / 0.5556); + + public string? Summary { get; set; } + } +} diff --git a/WF_EF_Api/WfApi/WfApi.csproj b/WF_EF_Api/WfApi/WfApi.csproj new file mode 100644 index 0000000..ff8c292 --- /dev/null +++ b/WF_EF_Api/WfApi/WfApi.csproj @@ -0,0 +1,16 @@ + + + + net8.0 + enable + enable + 283a610b-b95e-4b09-af22-b7d3270a917d + Linux + + + + + + + + diff --git a/WF_EF_Api/WfApi/WfApi.http b/WF_EF_Api/WfApi/WfApi.http new file mode 100644 index 0000000..4fd1d65 --- /dev/null +++ b/WF_EF_Api/WfApi/WfApi.http @@ -0,0 +1,6 @@ +@WfApi_HostAddress = http://localhost:5239 + +GET {{WfApi_HostAddress}}/weatherforecast/ +Accept: application/json + +### diff --git a/WF_EF_Api/WfApi/appsettings.Development.json b/WF_EF_Api/WfApi/appsettings.Development.json new file mode 100644 index 0000000..ff66ba6 --- /dev/null +++ b/WF_EF_Api/WfApi/appsettings.Development.json @@ -0,0 +1,8 @@ +{ + "Logging": { + "LogLevel": { + "Default": "Information", + "Microsoft.AspNetCore": "Warning" + } + } +} diff --git a/WF_EF_Api/WfApi/appsettings.json b/WF_EF_Api/WfApi/appsettings.json new file mode 100644 index 0000000..4d56694 --- /dev/null +++ b/WF_EF_Api/WfApi/appsettings.json @@ -0,0 +1,9 @@ +{ + "Logging": { + "LogLevel": { + "Default": "Information", + "Microsoft.AspNetCore": "Warning" + } + }, + "AllowedHosts": "*" +} diff --git a/WF_EF_Api/XUnitTest/UnitTest1.cs b/WF_EF_Api/XUnitTest/UnitTest1.cs new file mode 100644 index 0000000..f8a0369 --- /dev/null +++ b/WF_EF_Api/XUnitTest/UnitTest1.cs @@ -0,0 +1,11 @@ +namespace XUnitTest +{ + public class UnitTest1 + { + [Fact] + public void Test1() + { + + } + } +} \ No newline at end of file diff --git a/WF_EF_Api/XUnitTest/XUnitTest.csproj b/WF_EF_Api/XUnitTest/XUnitTest.csproj new file mode 100644 index 0000000..3aa9860 --- /dev/null +++ b/WF_EF_Api/XUnitTest/XUnitTest.csproj @@ -0,0 +1,23 @@ + + + + net8.0 + enable + enable + + false + true + + + + + + + + + + + + + + From 6755e632745e05b2cfbf8f96e84542e06d1a9f0a Mon Sep 17 00:00:00 2001 From: kekentin Date: Wed, 12 Mar 2025 17:29:04 +0100 Subject: [PATCH 02/65] =?UTF-8?q?D=C3=A9but=20Relation=20Users=20et=20Imag?= =?UTF-8?q?es=20relier?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- WF_EF_Api/ConsoleTest/Program.cs | 2 +- WF_EF_Api/Contextlib/Contextlib.csproj | 18 ++ WF_EF_Api/Contextlib/WTFContext.cs | 31 +++ WF_EF_Api/Entity/Admin.cs | 13 + WF_EF_Api/Entity/Character.cs | 15 ++ WF_EF_Api/Entity/Commentary.cs | 17 ++ WF_EF_Api/Entity/DailyQuote.cs | 13 + WF_EF_Api/Entity/Favorite.cs | 14 + WF_EF_Api/Entity/Images.cs | 19 ++ WF_EF_Api/Entity/LangEnum.cs | 15 ++ WF_EF_Api/Entity/Question.cs | 20 ++ WF_EF_Api/Entity/Quiz.cs | 16 ++ WF_EF_Api/Entity/QuizQuestion.cs | 14 + WF_EF_Api/Entity/Quote.cs | 20 ++ WF_EF_Api/Entity/RecordQuiz.cs | 16 ++ WF_EF_Api/Entity/Source.cs | 15 ++ WF_EF_Api/Entity/Users.cs | 26 ++ .../Model/{Entities.csproj => Model.csproj} | 0 WF_EF_Api/Shared/IFavoriteService.cs | 1 + ...0250312160314_myFirstMigration.Designer.cs | 205 +++++++++++++++ .../20250312160314_myFirstMigration.cs | 149 +++++++++++ .../20250312162514_migr2.Designer.cs | 248 ++++++++++++++++++ .../Migrations/20250312162514_migr2.cs | 89 +++++++ .../Migrations/StubWTFContextModelSnapshot.cs | 245 +++++++++++++++++ WF_EF_Api/StubbedContextLib/StubWTFContext.cs | 34 +++ .../StubbedContextLib.csproj | 12 + WF_EF_Api/WF_EF_Api.sln | 28 +- 27 files changed, 1280 insertions(+), 15 deletions(-) create mode 100644 WF_EF_Api/Contextlib/WTFContext.cs create mode 100644 WF_EF_Api/Entity/Admin.cs create mode 100644 WF_EF_Api/Entity/Character.cs create mode 100644 WF_EF_Api/Entity/Commentary.cs create mode 100644 WF_EF_Api/Entity/DailyQuote.cs create mode 100644 WF_EF_Api/Entity/Favorite.cs create mode 100644 WF_EF_Api/Entity/Images.cs create mode 100644 WF_EF_Api/Entity/LangEnum.cs create mode 100644 WF_EF_Api/Entity/Question.cs create mode 100644 WF_EF_Api/Entity/Quiz.cs create mode 100644 WF_EF_Api/Entity/QuizQuestion.cs create mode 100644 WF_EF_Api/Entity/Quote.cs create mode 100644 WF_EF_Api/Entity/RecordQuiz.cs create mode 100644 WF_EF_Api/Entity/Source.cs create mode 100644 WF_EF_Api/Entity/Users.cs rename WF_EF_Api/Model/{Entities.csproj => Model.csproj} (100%) create mode 100644 WF_EF_Api/StubbedContextLib/Migrations/20250312160314_myFirstMigration.Designer.cs create mode 100644 WF_EF_Api/StubbedContextLib/Migrations/20250312160314_myFirstMigration.cs create mode 100644 WF_EF_Api/StubbedContextLib/Migrations/20250312162514_migr2.Designer.cs create mode 100644 WF_EF_Api/StubbedContextLib/Migrations/20250312162514_migr2.cs create mode 100644 WF_EF_Api/StubbedContextLib/Migrations/StubWTFContextModelSnapshot.cs create mode 100644 WF_EF_Api/StubbedContextLib/StubWTFContext.cs diff --git a/WF_EF_Api/ConsoleTest/Program.cs b/WF_EF_Api/ConsoleTest/Program.cs index af0744a..127ed44 100644 --- a/WF_EF_Api/ConsoleTest/Program.cs +++ b/WF_EF_Api/ConsoleTest/Program.cs @@ -1 +1 @@ - +Console.WriteLine("bonjour"); \ No newline at end of file diff --git a/WF_EF_Api/Contextlib/Contextlib.csproj b/WF_EF_Api/Contextlib/Contextlib.csproj index bb23fb7..805901c 100644 --- a/WF_EF_Api/Contextlib/Contextlib.csproj +++ b/WF_EF_Api/Contextlib/Contextlib.csproj @@ -6,4 +6,22 @@ enable + + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + + + + + + diff --git a/WF_EF_Api/Contextlib/WTFContext.cs b/WF_EF_Api/Contextlib/WTFContext.cs new file mode 100644 index 0000000..c27565d --- /dev/null +++ b/WF_EF_Api/Contextlib/WTFContext.cs @@ -0,0 +1,31 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Entity; +using Microsoft.EntityFrameworkCore; + +namespace Contextlib +{ + public class WTFContext : DbContext + { + public DbSet Images { get; set; } + public DbSet Users { get; set; } + //public DbSet Admin { get; set; } + public DbSet Question { get; set; } + public DbSet Quiz { get; set; } + //public DbSet QuizQuestion { get; set; } + //public DbSet RecordQuiz { get; set; } + public DbSet Source { get; set; } + public DbSet Character { get; set; } + public DbSet Quote { get; set; } + //public DbSet DailyQuote { get; set; } + //public DbSet Favorite { get; set; } + //public DbSet Commentary { get; set; } + + + protected override void OnConfiguring(DbContextOptionsBuilder options) + => options.UseSqlServer(@"Server=(localdb)\mssqllocaldb;Database=myFirstDatabase.mdf;Trusted_Connection=True;"); + } +} diff --git a/WF_EF_Api/Entity/Admin.cs b/WF_EF_Api/Entity/Admin.cs new file mode 100644 index 0000000..4b1ea8e --- /dev/null +++ b/WF_EF_Api/Entity/Admin.cs @@ -0,0 +1,13 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Entity +{ + public class Admin + { + //public int IdUsers { get; set; } + } +} diff --git a/WF_EF_Api/Entity/Character.cs b/WF_EF_Api/Entity/Character.cs new file mode 100644 index 0000000..22643e6 --- /dev/null +++ b/WF_EF_Api/Entity/Character.cs @@ -0,0 +1,15 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Entity +{ + public class Character + { + public int Id { get; set; } + public string Name { get; set; } + //public int IdImage { get; set; } + } +} diff --git a/WF_EF_Api/Entity/Commentary.cs b/WF_EF_Api/Entity/Commentary.cs new file mode 100644 index 0000000..b07ecdf --- /dev/null +++ b/WF_EF_Api/Entity/Commentary.cs @@ -0,0 +1,17 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Entity +{ + public class Commentary + { + public int Id { get; set; } + //public int IdUsers { get; set; } + //public int IdQuote { get; set; } + public DateTime DateCommentary { get; set; } + public string Comment { get; set; } + } +} diff --git a/WF_EF_Api/Entity/DailyQuote.cs b/WF_EF_Api/Entity/DailyQuote.cs new file mode 100644 index 0000000..350290c --- /dev/null +++ b/WF_EF_Api/Entity/DailyQuote.cs @@ -0,0 +1,13 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Entity +{ + public class DailyQuote + { + public int IdQuote { get; set; } + } +} diff --git a/WF_EF_Api/Entity/Favorite.cs b/WF_EF_Api/Entity/Favorite.cs new file mode 100644 index 0000000..0d6705e --- /dev/null +++ b/WF_EF_Api/Entity/Favorite.cs @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Entity +{ + public class Favorite + { + //public int IdUsers { get; set; } + //public int IdQuote { get; set; } + } +} diff --git a/WF_EF_Api/Entity/Images.cs b/WF_EF_Api/Entity/Images.cs new file mode 100644 index 0000000..27fc63f --- /dev/null +++ b/WF_EF_Api/Entity/Images.cs @@ -0,0 +1,19 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel.DataAnnotations.Schema; +using System.ComponentModel.DataAnnotations; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Entity +{ + public class Images + { + [Key] + [DatabaseGenerated(DatabaseGeneratedOption.Identity)] + public int Id { get; set; } + public string ImgPath { get; set; } + public ICollection Users { get; set; } = new List(); + } +} diff --git a/WF_EF_Api/Entity/LangEnum.cs b/WF_EF_Api/Entity/LangEnum.cs new file mode 100644 index 0000000..a3238c3 --- /dev/null +++ b/WF_EF_Api/Entity/LangEnum.cs @@ -0,0 +1,15 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Entity +{ + public enum LangEnum + { + vo, + fr, + en + } +} diff --git a/WF_EF_Api/Entity/Question.cs b/WF_EF_Api/Entity/Question.cs new file mode 100644 index 0000000..5bc982c --- /dev/null +++ b/WF_EF_Api/Entity/Question.cs @@ -0,0 +1,20 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Entity +{ + public class Question + { + public int Id { get; set; } + public string Text { get; set; } + public string AnswerA { get; set; } + public string AnswerB { get; set; } + public string AnswerC { get; set; } + public string AnswerD { get; set; } + public string CorrectAnswer { get; set; } + + } +} diff --git a/WF_EF_Api/Entity/Quiz.cs b/WF_EF_Api/Entity/Quiz.cs new file mode 100644 index 0000000..11e7bb5 --- /dev/null +++ b/WF_EF_Api/Entity/Quiz.cs @@ -0,0 +1,16 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Entity +{ + public class Quiz + { + public int Id { get; set; } + public string Title { get; set; } + //public int IdImage { get; set; } + public int NbQuestion { get; set; } + } +} diff --git a/WF_EF_Api/Entity/QuizQuestion.cs b/WF_EF_Api/Entity/QuizQuestion.cs new file mode 100644 index 0000000..a62ba83 --- /dev/null +++ b/WF_EF_Api/Entity/QuizQuestion.cs @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Entity +{ + public class QuizQuestion + { + //public int IdQuiz { get; set; } + //public int IdQuestion { get; set; } + } +} diff --git a/WF_EF_Api/Entity/Quote.cs b/WF_EF_Api/Entity/Quote.cs new file mode 100644 index 0000000..57621c1 --- /dev/null +++ b/WF_EF_Api/Entity/Quote.cs @@ -0,0 +1,20 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Entity +{ + public class Quote + { + public int Id { get; set; } + public string Content { get; set; } + public int Likes { get; set; } + public LangEnum Langage { get; set; } + public bool IsValid { get; set; } + //public int IdCharacter { get; set; } + //public int IdSource { get; set; } + //public int IdUsersPropose { get; set; } + } +} diff --git a/WF_EF_Api/Entity/RecordQuiz.cs b/WF_EF_Api/Entity/RecordQuiz.cs new file mode 100644 index 0000000..5ddc02d --- /dev/null +++ b/WF_EF_Api/Entity/RecordQuiz.cs @@ -0,0 +1,16 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Entity +{ + public class RecordQuiz + { + public int IdUsers { get; set; } + public int IdQuiz { get; set; } + public int NbPoint { get; set; } + public int TimeQuiz { get; set; } + } +} diff --git a/WF_EF_Api/Entity/Source.cs b/WF_EF_Api/Entity/Source.cs new file mode 100644 index 0000000..18f242e --- /dev/null +++ b/WF_EF_Api/Entity/Source.cs @@ -0,0 +1,15 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Entity +{ + public class Source + { + public int Id { get; set; } + public string Title { get; set; } + public int Year { get; set; } + } +} diff --git a/WF_EF_Api/Entity/Users.cs b/WF_EF_Api/Entity/Users.cs new file mode 100644 index 0000000..c5049f7 --- /dev/null +++ b/WF_EF_Api/Entity/Users.cs @@ -0,0 +1,26 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel.DataAnnotations; +using System.ComponentModel.DataAnnotations.Schema; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Entity +{ + public class Users + { + [Key] + [DatabaseGenerated(DatabaseGeneratedOption.Identity)] + public int Id { get; set; } + public string UserName { get; set; } + public string Email { get; set; } + public string Password { get; set; } + + [ForeignKey(nameof(Images))] + public int IdImage { get; set; } + public Images Images { get; set; } + + public DateTime Created { get; set; } + } +} diff --git a/WF_EF_Api/Model/Entities.csproj b/WF_EF_Api/Model/Model.csproj similarity index 100% rename from WF_EF_Api/Model/Entities.csproj rename to WF_EF_Api/Model/Model.csproj diff --git a/WF_EF_Api/Shared/IFavoriteService.cs b/WF_EF_Api/Shared/IFavoriteService.cs index 53ca0a7..3b2de7f 100644 --- a/WF_EF_Api/Shared/IFavoriteService.cs +++ b/WF_EF_Api/Shared/IFavoriteService.cs @@ -26,3 +26,4 @@ namespace Shared // 'quoteId' is the unique identifier of the quote to be removed from all users' favorites. Task RemoveAllFavoriteForQuote(int quoteId); } +} diff --git a/WF_EF_Api/StubbedContextLib/Migrations/20250312160314_myFirstMigration.Designer.cs b/WF_EF_Api/StubbedContextLib/Migrations/20250312160314_myFirstMigration.Designer.cs new file mode 100644 index 0000000..516d42a --- /dev/null +++ b/WF_EF_Api/StubbedContextLib/Migrations/20250312160314_myFirstMigration.Designer.cs @@ -0,0 +1,205 @@ +// +using System; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Metadata; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; +using StubbedContextLib; + +#nullable disable + +namespace StubbedContextLib.Migrations +{ + [DbContext(typeof(StubWTFContext))] + [Migration("20250312160314_myFirstMigration")] + partial class myFirstMigration + { + /// + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("ProductVersion", "9.0.3") + .HasAnnotation("Relational:MaxIdentifierLength", 128); + + SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder); + + modelBuilder.Entity("Entity.Character", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("Name") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.HasKey("Id"); + + b.ToTable("Character"); + }); + + modelBuilder.Entity("Entity.Images", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("ImgPath") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.HasKey("Id"); + + b.ToTable("Images"); + }); + + modelBuilder.Entity("Entity.Question", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("AnswerA") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("AnswerB") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("AnswerC") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("AnswerD") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("CorrectAnswer") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Text") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.HasKey("Id"); + + b.ToTable("Question"); + }); + + modelBuilder.Entity("Entity.Quiz", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("NbQuestion") + .HasColumnType("int"); + + b.Property("Title") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.HasKey("Id"); + + b.ToTable("Quiz"); + }); + + modelBuilder.Entity("Entity.Quote", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("Content") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("IsValid") + .HasColumnType("bit"); + + b.Property("Langage") + .HasColumnType("int"); + + b.Property("Likes") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.ToTable("Quote"); + }); + + modelBuilder.Entity("Entity.Source", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("Title") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Year") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.ToTable("Source"); + }); + + modelBuilder.Entity("Entity.Users", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("Created") + .HasColumnType("datetime2"); + + b.Property("Email") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Password") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("UserName") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.HasKey("Id"); + + b.ToTable("Users"); + + b.HasData( + new + { + Id = 1, + Created = new DateTime(2000, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified), + Email = "dev@gmail.com", + Password = "1234", + UserName = "Dev" + }); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/WF_EF_Api/StubbedContextLib/Migrations/20250312160314_myFirstMigration.cs b/WF_EF_Api/StubbedContextLib/Migrations/20250312160314_myFirstMigration.cs new file mode 100644 index 0000000..6fd3de5 --- /dev/null +++ b/WF_EF_Api/StubbedContextLib/Migrations/20250312160314_myFirstMigration.cs @@ -0,0 +1,149 @@ +using System; +using Microsoft.EntityFrameworkCore.Migrations; + +#nullable disable + +namespace StubbedContextLib.Migrations +{ + /// + public partial class myFirstMigration : Migration + { + /// + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.CreateTable( + name: "Character", + columns: table => new + { + Id = table.Column(type: "int", nullable: false) + .Annotation("SqlServer:Identity", "1, 1"), + Name = table.Column(type: "nvarchar(max)", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Character", x => x.Id); + }); + + migrationBuilder.CreateTable( + name: "Images", + columns: table => new + { + Id = table.Column(type: "int", nullable: false) + .Annotation("SqlServer:Identity", "1, 1"), + ImgPath = table.Column(type: "nvarchar(max)", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Images", x => x.Id); + }); + + migrationBuilder.CreateTable( + name: "Question", + columns: table => new + { + Id = table.Column(type: "int", nullable: false) + .Annotation("SqlServer:Identity", "1, 1"), + Text = table.Column(type: "nvarchar(max)", nullable: false), + AnswerA = table.Column(type: "nvarchar(max)", nullable: false), + AnswerB = table.Column(type: "nvarchar(max)", nullable: false), + AnswerC = table.Column(type: "nvarchar(max)", nullable: false), + AnswerD = table.Column(type: "nvarchar(max)", nullable: false), + CorrectAnswer = table.Column(type: "nvarchar(max)", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Question", x => x.Id); + }); + + migrationBuilder.CreateTable( + name: "Quiz", + columns: table => new + { + Id = table.Column(type: "int", nullable: false) + .Annotation("SqlServer:Identity", "1, 1"), + Title = table.Column(type: "nvarchar(max)", nullable: false), + NbQuestion = table.Column(type: "int", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Quiz", x => x.Id); + }); + + migrationBuilder.CreateTable( + name: "Quote", + columns: table => new + { + Id = table.Column(type: "int", nullable: false) + .Annotation("SqlServer:Identity", "1, 1"), + Content = table.Column(type: "nvarchar(max)", nullable: false), + Likes = table.Column(type: "int", nullable: false), + Langage = table.Column(type: "int", nullable: false), + IsValid = table.Column(type: "bit", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Quote", x => x.Id); + }); + + migrationBuilder.CreateTable( + name: "Source", + columns: table => new + { + Id = table.Column(type: "int", nullable: false) + .Annotation("SqlServer:Identity", "1, 1"), + Title = table.Column(type: "nvarchar(max)", nullable: false), + Year = table.Column(type: "int", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Source", x => x.Id); + }); + + migrationBuilder.CreateTable( + name: "Users", + columns: table => new + { + Id = table.Column(type: "int", nullable: false) + .Annotation("SqlServer:Identity", "1, 1"), + UserName = table.Column(type: "nvarchar(max)", nullable: false), + Email = table.Column(type: "nvarchar(max)", nullable: false), + Password = table.Column(type: "nvarchar(max)", nullable: false), + Created = table.Column(type: "datetime2", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Users", x => x.Id); + }); + + migrationBuilder.InsertData( + table: "Users", + columns: new[] { "Id", "Created", "Email", "Password", "UserName" }, + values: new object[] { 1, new DateTime(2000, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified), "dev@gmail.com", "1234", "Dev" }); + } + + /// + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropTable( + name: "Character"); + + migrationBuilder.DropTable( + name: "Images"); + + migrationBuilder.DropTable( + name: "Question"); + + migrationBuilder.DropTable( + name: "Quiz"); + + migrationBuilder.DropTable( + name: "Quote"); + + migrationBuilder.DropTable( + name: "Source"); + + migrationBuilder.DropTable( + name: "Users"); + } + } +} diff --git a/WF_EF_Api/StubbedContextLib/Migrations/20250312162514_migr2.Designer.cs b/WF_EF_Api/StubbedContextLib/Migrations/20250312162514_migr2.Designer.cs new file mode 100644 index 0000000..d84e486 --- /dev/null +++ b/WF_EF_Api/StubbedContextLib/Migrations/20250312162514_migr2.Designer.cs @@ -0,0 +1,248 @@ +// +using System; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Metadata; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; +using StubbedContextLib; + +#nullable disable + +namespace StubbedContextLib.Migrations +{ + [DbContext(typeof(StubWTFContext))] + [Migration("20250312162514_migr2")] + partial class migr2 + { + /// + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("ProductVersion", "9.0.3") + .HasAnnotation("Relational:MaxIdentifierLength", 128); + + SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder); + + modelBuilder.Entity("Entity.Character", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("Name") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.HasKey("Id"); + + b.ToTable("Character"); + }); + + modelBuilder.Entity("Entity.Images", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("ImgPath") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.HasKey("Id"); + + b.ToTable("Images"); + + b.HasData( + new + { + Id = 1, + ImgPath = "coucou" + }, + new + { + Id = 2, + ImgPath = "bonjour" + }); + }); + + modelBuilder.Entity("Entity.Question", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("AnswerA") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("AnswerB") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("AnswerC") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("AnswerD") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("CorrectAnswer") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Text") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.HasKey("Id"); + + b.ToTable("Question"); + }); + + modelBuilder.Entity("Entity.Quiz", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("NbQuestion") + .HasColumnType("int"); + + b.Property("Title") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.HasKey("Id"); + + b.ToTable("Quiz"); + }); + + modelBuilder.Entity("Entity.Quote", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("Content") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("IsValid") + .HasColumnType("bit"); + + b.Property("Langage") + .HasColumnType("int"); + + b.Property("Likes") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.ToTable("Quote"); + }); + + modelBuilder.Entity("Entity.Source", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("Title") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Year") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.ToTable("Source"); + }); + + modelBuilder.Entity("Entity.Users", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("Created") + .HasColumnType("datetime2"); + + b.Property("Email") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("IdImage") + .HasColumnType("int"); + + b.Property("Password") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("UserName") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.HasKey("Id"); + + b.HasIndex("IdImage"); + + b.ToTable("Users"); + + b.HasData( + new + { + Id = 1, + Created = new DateTime(2000, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified), + Email = "dev@gmail.com", + IdImage = 1, + Password = "1234", + UserName = "Dev" + }, + new + { + Id = 2, + Created = new DateTime(2000, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified), + Email = "admin@gmail.com", + IdImage = 1, + Password = "1234", + UserName = "Admin" + }); + }); + + modelBuilder.Entity("Entity.Users", b => + { + b.HasOne("Entity.Images", "Images") + .WithMany("Users") + .HasForeignKey("IdImage") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Images"); + }); + + modelBuilder.Entity("Entity.Images", b => + { + b.Navigation("Users"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/WF_EF_Api/StubbedContextLib/Migrations/20250312162514_migr2.cs b/WF_EF_Api/StubbedContextLib/Migrations/20250312162514_migr2.cs new file mode 100644 index 0000000..01e2609 --- /dev/null +++ b/WF_EF_Api/StubbedContextLib/Migrations/20250312162514_migr2.cs @@ -0,0 +1,89 @@ +using System; +using Microsoft.EntityFrameworkCore.Migrations; + +#nullable disable + +#pragma warning disable CA1814 // Prefer jagged arrays over multidimensional + +namespace StubbedContextLib.Migrations +{ + /// + public partial class migr2 : Migration + { + /// + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.AddColumn( + name: "IdImage", + table: "Users", + type: "int", + nullable: false, + defaultValue: 0); + + migrationBuilder.InsertData( + table: "Images", + columns: new[] { "Id", "ImgPath" }, + values: new object[,] + { + { 1, "coucou" }, + { 2, "bonjour" } + }); + + migrationBuilder.UpdateData( + table: "Users", + keyColumn: "Id", + keyValue: 1, + column: "IdImage", + value: 1); + + migrationBuilder.InsertData( + table: "Users", + columns: new[] { "Id", "Created", "Email", "IdImage", "Password", "UserName" }, + values: new object[] { 2, new DateTime(2000, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified), "admin@gmail.com", 1, "1234", "Admin" }); + + migrationBuilder.CreateIndex( + name: "IX_Users_IdImage", + table: "Users", + column: "IdImage"); + + migrationBuilder.AddForeignKey( + name: "FK_Users_Images_IdImage", + table: "Users", + column: "IdImage", + principalTable: "Images", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + } + + /// + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropForeignKey( + name: "FK_Users_Images_IdImage", + table: "Users"); + + migrationBuilder.DropIndex( + name: "IX_Users_IdImage", + table: "Users"); + + migrationBuilder.DeleteData( + table: "Images", + keyColumn: "Id", + keyValue: 2); + + migrationBuilder.DeleteData( + table: "Users", + keyColumn: "Id", + keyValue: 2); + + migrationBuilder.DeleteData( + table: "Images", + keyColumn: "Id", + keyValue: 1); + + migrationBuilder.DropColumn( + name: "IdImage", + table: "Users"); + } + } +} diff --git a/WF_EF_Api/StubbedContextLib/Migrations/StubWTFContextModelSnapshot.cs b/WF_EF_Api/StubbedContextLib/Migrations/StubWTFContextModelSnapshot.cs new file mode 100644 index 0000000..4a848c7 --- /dev/null +++ b/WF_EF_Api/StubbedContextLib/Migrations/StubWTFContextModelSnapshot.cs @@ -0,0 +1,245 @@ +// +using System; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Metadata; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; +using StubbedContextLib; + +#nullable disable + +namespace StubbedContextLib.Migrations +{ + [DbContext(typeof(StubWTFContext))] + partial class StubWTFContextModelSnapshot : ModelSnapshot + { + protected override void BuildModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("ProductVersion", "9.0.3") + .HasAnnotation("Relational:MaxIdentifierLength", 128); + + SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder); + + modelBuilder.Entity("Entity.Character", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("Name") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.HasKey("Id"); + + b.ToTable("Character"); + }); + + modelBuilder.Entity("Entity.Images", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("ImgPath") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.HasKey("Id"); + + b.ToTable("Images"); + + b.HasData( + new + { + Id = 1, + ImgPath = "coucou" + }, + new + { + Id = 2, + ImgPath = "bonjour" + }); + }); + + modelBuilder.Entity("Entity.Question", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("AnswerA") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("AnswerB") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("AnswerC") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("AnswerD") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("CorrectAnswer") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Text") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.HasKey("Id"); + + b.ToTable("Question"); + }); + + modelBuilder.Entity("Entity.Quiz", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("NbQuestion") + .HasColumnType("int"); + + b.Property("Title") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.HasKey("Id"); + + b.ToTable("Quiz"); + }); + + modelBuilder.Entity("Entity.Quote", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("Content") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("IsValid") + .HasColumnType("bit"); + + b.Property("Langage") + .HasColumnType("int"); + + b.Property("Likes") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.ToTable("Quote"); + }); + + modelBuilder.Entity("Entity.Source", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("Title") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Year") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.ToTable("Source"); + }); + + modelBuilder.Entity("Entity.Users", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("Created") + .HasColumnType("datetime2"); + + b.Property("Email") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("IdImage") + .HasColumnType("int"); + + b.Property("Password") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("UserName") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.HasKey("Id"); + + b.HasIndex("IdImage"); + + b.ToTable("Users"); + + b.HasData( + new + { + Id = 1, + Created = new DateTime(2000, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified), + Email = "dev@gmail.com", + IdImage = 1, + Password = "1234", + UserName = "Dev" + }, + new + { + Id = 2, + Created = new DateTime(2000, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified), + Email = "admin@gmail.com", + IdImage = 1, + Password = "1234", + UserName = "Admin" + }); + }); + + modelBuilder.Entity("Entity.Users", b => + { + b.HasOne("Entity.Images", "Images") + .WithMany("Users") + .HasForeignKey("IdImage") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Images"); + }); + + modelBuilder.Entity("Entity.Images", b => + { + b.Navigation("Users"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/WF_EF_Api/StubbedContextLib/StubWTFContext.cs b/WF_EF_Api/StubbedContextLib/StubWTFContext.cs new file mode 100644 index 0000000..8d983a4 --- /dev/null +++ b/WF_EF_Api/StubbedContextLib/StubWTFContext.cs @@ -0,0 +1,34 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Contextlib; +using Entity; +using Microsoft.EntityFrameworkCore; + +namespace StubbedContextLib +{ + public class StubWTFContext : WTFContext + { + protected override void OnModelCreating(ModelBuilder modelBuilder) + { + base.OnModelCreating(modelBuilder); + + modelBuilder.Entity() + .HasMany(i => i.Users) + .WithOne(u => u.Images) + .HasForeignKey(u => u.IdImage) + .IsRequired(); + + modelBuilder.Entity().HasData( + new Images { Id = 1, ImgPath = "coucou" }, + new Images { Id = 2, ImgPath = "bonjour" } + ); + modelBuilder.Entity().HasData( + new Users { Id = 1, UserName = "Dev", Created = new DateTime(2000, 01, 01), Email = "dev@gmail.com", Password = "1234", IdImage = 1 }, + new Users { Id = 2, UserName = "Admin", Created = new DateTime(2000, 01, 01), Email = "admin@gmail.com", Password = "1234", IdImage = 1 } + ); + } + } +} diff --git a/WF_EF_Api/StubbedContextLib/StubbedContextLib.csproj b/WF_EF_Api/StubbedContextLib/StubbedContextLib.csproj index bb23fb7..9a838f3 100644 --- a/WF_EF_Api/StubbedContextLib/StubbedContextLib.csproj +++ b/WF_EF_Api/StubbedContextLib/StubbedContextLib.csproj @@ -6,4 +6,16 @@ enable + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + + + + + + + diff --git a/WF_EF_Api/WF_EF_Api.sln b/WF_EF_Api/WF_EF_Api.sln index bff150d..2b163b7 100644 --- a/WF_EF_Api/WF_EF_Api.sln +++ b/WF_EF_Api/WF_EF_Api.sln @@ -3,25 +3,25 @@ Microsoft Visual Studio Solution File, Format Version 12.00 # Visual Studio Version 17 VisualStudioVersion = 17.9.34723.18 MinimumVisualStudioVersion = 10.0.40219.1 -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ConsoleTest", "ConsoleTest\ConsoleTest.csproj", "{A8B0E4D8-0726-4248-BB6D-DAA2545270B1}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ConsoleTest", "ConsoleTest\ConsoleTest.csproj", "{A8B0E4D8-0726-4248-BB6D-DAA2545270B1}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Shared", "Shared\Shared.csproj", "{792EF125-E2D4-457C-B536-BDAEFB49D14E}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Shared", "Shared\Shared.csproj", "{792EF125-E2D4-457C-B536-BDAEFB49D14E}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Entity", "Entity\Entity.csproj", "{69A4450C-AA43-4622-A866-9A5F7C8A2C14}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Entity", "Entity\Entity.csproj", "{69A4450C-AA43-4622-A866-9A5F7C8A2C14}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Contextlib", "Contextlib\Contextlib.csproj", "{32977454-CE94-4532-AE26-29F6951B78CF}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Contextlib", "Contextlib\Contextlib.csproj", "{32977454-CE94-4532-AE26-29F6951B78CF}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "StubbedContextLib", "StubbedContextLib\StubbedContextLib.csproj", "{5CD69B14-C6AE-4628-A374-996C486E25F2}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "StubbedContextLib", "StubbedContextLib\StubbedContextLib.csproj", "{5CD69B14-C6AE-4628-A374-996C486E25F2}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TestModel2Entities", "TestModel2Entities\TestModel2Entities.csproj", "{2CF20FAC-C2F1-4048-9D46-F39081B0FBEF}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TestModel2Entities", "TestModel2Entities\TestModel2Entities.csproj", "{2CF20FAC-C2F1-4048-9D46-F39081B0FBEF}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Entities", "Model\Entities.csproj", "{C51815EE-ED06-4F38-955E-7EBB72C0A7EF}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Model2Entities", "Model2entities\Model2Entities.csproj", "{4A1CBA3D-C798-4E19-865F-39F919F1205A}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Model2Entities", "Model2entities\Model2Entities.csproj", "{4A1CBA3D-C798-4E19-865F-39F919F1205A}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "XUnitTest", "XUnitTest\XUnitTest.csproj", "{48002CA2-7CFF-4077-90CF-392476320CE3}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "XUnitTest", "XUnitTest\XUnitTest.csproj", "{48002CA2-7CFF-4077-90CF-392476320CE3}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "WfApi", "WfApi\WfApi.csproj", "{D4EEE1BF-CDCB-4E66-997B-7A5984DA7995}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WfApi", "WfApi\WfApi.csproj", "{D4EEE1BF-CDCB-4E66-997B-7A5984DA7995}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Model", "Model\Model.csproj", "{708875DC-7ED1-4FD1-9321-3E00B2E7709B}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -53,10 +53,6 @@ Global {2CF20FAC-C2F1-4048-9D46-F39081B0FBEF}.Debug|Any CPU.Build.0 = Debug|Any CPU {2CF20FAC-C2F1-4048-9D46-F39081B0FBEF}.Release|Any CPU.ActiveCfg = Release|Any CPU {2CF20FAC-C2F1-4048-9D46-F39081B0FBEF}.Release|Any CPU.Build.0 = Release|Any CPU - {C51815EE-ED06-4F38-955E-7EBB72C0A7EF}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {C51815EE-ED06-4F38-955E-7EBB72C0A7EF}.Debug|Any CPU.Build.0 = Debug|Any CPU - {C51815EE-ED06-4F38-955E-7EBB72C0A7EF}.Release|Any CPU.ActiveCfg = Release|Any CPU - {C51815EE-ED06-4F38-955E-7EBB72C0A7EF}.Release|Any CPU.Build.0 = Release|Any CPU {4A1CBA3D-C798-4E19-865F-39F919F1205A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {4A1CBA3D-C798-4E19-865F-39F919F1205A}.Debug|Any CPU.Build.0 = Debug|Any CPU {4A1CBA3D-C798-4E19-865F-39F919F1205A}.Release|Any CPU.ActiveCfg = Release|Any CPU @@ -69,6 +65,10 @@ Global {D4EEE1BF-CDCB-4E66-997B-7A5984DA7995}.Debug|Any CPU.Build.0 = Debug|Any CPU {D4EEE1BF-CDCB-4E66-997B-7A5984DA7995}.Release|Any CPU.ActiveCfg = Release|Any CPU {D4EEE1BF-CDCB-4E66-997B-7A5984DA7995}.Release|Any CPU.Build.0 = Release|Any CPU + {708875DC-7ED1-4FD1-9321-3E00B2E7709B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {708875DC-7ED1-4FD1-9321-3E00B2E7709B}.Debug|Any CPU.Build.0 = Debug|Any CPU + {708875DC-7ED1-4FD1-9321-3E00B2E7709B}.Release|Any CPU.ActiveCfg = Release|Any CPU + {708875DC-7ED1-4FD1-9321-3E00B2E7709B}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE From 4fd8b07cc64d9368e4c91eb591b6e229cbf1b3ff Mon Sep 17 00:00:00 2001 From: Kevin MONDEJAR Date: Thu, 13 Mar 2025 12:02:29 +0100 Subject: [PATCH 03/65] =?UTF-8?q?modif=20entity=20+=20ajout=20donn=C3=A9es?= =?UTF-8?q?=20stuber?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- WF_EF_Api/Contextlib/WTFContext.cs | 28 ++--- WF_EF_Api/Entity/Admin.cs | 8 +- WF_EF_Api/Entity/Character.cs | 15 ++- WF_EF_Api/Entity/Commentary.cs | 24 +++- WF_EF_Api/Entity/DailyQuote.cs | 6 + WF_EF_Api/Entity/Favorite.cs | 15 ++- WF_EF_Api/Entity/Images.cs | 7 ++ WF_EF_Api/Entity/LangEnum.cs | 3 +- WF_EF_Api/Entity/Question.cs | 23 ++++ WF_EF_Api/Entity/Quiz.cs | 18 ++- WF_EF_Api/Entity/QuizQuestion.cs | 15 ++- WF_EF_Api/Entity/Quote.cs | 34 +++++- WF_EF_Api/Entity/RecordQuiz.cs | 1 + WF_EF_Api/Entity/Source.cs | 16 ++- WF_EF_Api/Entity/TypeSrcEnum.cs | 16 +++ WF_EF_Api/Entity/Users.cs | 20 ++- WF_EF_Api/StubbedContextLib/StubWTFContext.cs | 115 ++++++++++++++++-- 17 files changed, 325 insertions(+), 39 deletions(-) create mode 100644 WF_EF_Api/Entity/TypeSrcEnum.cs diff --git a/WF_EF_Api/Contextlib/WTFContext.cs b/WF_EF_Api/Contextlib/WTFContext.cs index c27565d..02880c7 100644 --- a/WF_EF_Api/Contextlib/WTFContext.cs +++ b/WF_EF_Api/Contextlib/WTFContext.cs @@ -10,22 +10,22 @@ namespace Contextlib { public class WTFContext : DbContext { - public DbSet Images { get; set; } - public DbSet Users { get; set; } - //public DbSet Admin { get; set; } - public DbSet Question { get; set; } - public DbSet Quiz { get; set; } - //public DbSet QuizQuestion { get; set; } - //public DbSet RecordQuiz { get; set; } - public DbSet Source { get; set; } - public DbSet Character { get; set; } - public DbSet Quote { get; set; } - //public DbSet DailyQuote { get; set; } - //public DbSet Favorite { get; set; } - //public DbSet Commentary { get; set; } + public DbSet admins { get; set; } + public DbSet characters { get; set; } + public DbSet comments { get; set; } + public DbSet dailyquotes { get; set; } + public DbSet favorites { get; set; } + public DbSet images { get; set; } + public DbSet question { get; set; } + public DbSet quizzes { get; set; } + public DbSet quizQuestions { get; set; } + public DbSet quotes { get; set; } + //public DbSet records { get; set; } + public DbSet sources { get; set; } + public DbSet users { get; set; } protected override void OnConfiguring(DbContextOptionsBuilder options) - => options.UseSqlServer(@"Server=(localdb)\mssqllocaldb;Database=myFirstDatabase.mdf;Trusted_Connection=True;"); + => options.UseSqlServer(@"Server=(localdb)\mssqllocaldb;Database=WfDatabase.mdf;Trusted_Connection=True;"); } } diff --git a/WF_EF_Api/Entity/Admin.cs b/WF_EF_Api/Entity/Admin.cs index 4b1ea8e..0c62388 100644 --- a/WF_EF_Api/Entity/Admin.cs +++ b/WF_EF_Api/Entity/Admin.cs @@ -1,5 +1,7 @@ using System; using System.Collections.Generic; +using System.ComponentModel.DataAnnotations; +using System.ComponentModel.DataAnnotations.Schema; using System.Linq; using System.Text; using System.Threading.Tasks; @@ -8,6 +10,10 @@ namespace Entity { public class Admin { - //public int IdUsers { get; set; } + [Key] + [ForeignKey(nameof(Users))] + public int IdUsers { get; set; } + + public Users User { get; set; } = null!; } } diff --git a/WF_EF_Api/Entity/Character.cs b/WF_EF_Api/Entity/Character.cs index 22643e6..f1ba455 100644 --- a/WF_EF_Api/Entity/Character.cs +++ b/WF_EF_Api/Entity/Character.cs @@ -1,5 +1,7 @@ using System; using System.Collections.Generic; +using System.ComponentModel.DataAnnotations; +using System.ComponentModel.DataAnnotations.Schema; using System.Linq; using System.Text; using System.Threading.Tasks; @@ -8,8 +10,19 @@ namespace Entity { public class Character { + [Key] + [DatabaseGenerated(DatabaseGeneratedOption.Identity)] public int Id { get; set; } + + [Required] + [StringLength(50)] public string Name { get; set; } - //public int IdImage { get; set; } + + [ForeignKey(nameof(Images))] + public int IdImage { get; set; } + + public Images Images { get; set; } = null!; + + public ICollection Quotes { get; set; } = new List(); } } diff --git a/WF_EF_Api/Entity/Commentary.cs b/WF_EF_Api/Entity/Commentary.cs index b07ecdf..07649d2 100644 --- a/WF_EF_Api/Entity/Commentary.cs +++ b/WF_EF_Api/Entity/Commentary.cs @@ -1,5 +1,7 @@ using System; using System.Collections.Generic; +using System.ComponentModel.DataAnnotations.Schema; +using System.ComponentModel.DataAnnotations; using System.Linq; using System.Text; using System.Threading.Tasks; @@ -8,10 +10,28 @@ namespace Entity { public class Commentary { + [Key] + [DatabaseGenerated(DatabaseGeneratedOption.Identity)] public int Id { get; set; } - //public int IdUsers { get; set; } - //public int IdQuote { get; set; } + + [Required] + [ForeignKey(nameof(Users))] + public int IdUsers { get; set; } + + [Required] + [ForeignKey(nameof(Quote))] + public int IdQuote { get; set; } + + [Required] + [Column("DateCommentary", TypeName = "date")] public DateTime DateCommentary { get; set; } + + [Required] + [MaxLength(100)] public string Comment { get; set; } + + public Quote Quote { get; set; } = null!; + + public Users Users { get; set; } = null!; } } diff --git a/WF_EF_Api/Entity/DailyQuote.cs b/WF_EF_Api/Entity/DailyQuote.cs index 350290c..04aa8c5 100644 --- a/WF_EF_Api/Entity/DailyQuote.cs +++ b/WF_EF_Api/Entity/DailyQuote.cs @@ -1,5 +1,7 @@ using System; using System.Collections.Generic; +using System.ComponentModel.DataAnnotations; +using System.ComponentModel.DataAnnotations.Schema; using System.Linq; using System.Text; using System.Threading.Tasks; @@ -8,6 +10,10 @@ namespace Entity { public class DailyQuote { + [Key] + [ForeignKey(nameof(Quote))] public int IdQuote { get; set; } + + public Quote Quote { get; set; } = null!; } } diff --git a/WF_EF_Api/Entity/Favorite.cs b/WF_EF_Api/Entity/Favorite.cs index 0d6705e..51165d5 100644 --- a/WF_EF_Api/Entity/Favorite.cs +++ b/WF_EF_Api/Entity/Favorite.cs @@ -1,5 +1,7 @@ using System; using System.Collections.Generic; +using System.ComponentModel.DataAnnotations; +using System.ComponentModel.DataAnnotations.Schema; using System.Linq; using System.Text; using System.Threading.Tasks; @@ -8,7 +10,16 @@ namespace Entity { public class Favorite { - //public int IdUsers { get; set; } - //public int IdQuote { get; set; } + [Key] + [ForeignKey(nameof(Users))] + public int IdUsers { get; set; } + + [Key] + [ForeignKey(nameof(Quote))] + public int IdQuote { get; set; } + + public Users User { get; set; } = null!; + + public Quote Quote { get; set; } = null!; } } diff --git a/WF_EF_Api/Entity/Images.cs b/WF_EF_Api/Entity/Images.cs index 27fc63f..d03b214 100644 --- a/WF_EF_Api/Entity/Images.cs +++ b/WF_EF_Api/Entity/Images.cs @@ -13,7 +13,14 @@ namespace Entity [Key] [DatabaseGenerated(DatabaseGeneratedOption.Identity)] public int Id { get; set; } + + [Required] public string ImgPath { get; set; } + + public ICollection Characters { get; set; } = new List(); + public ICollection Users { get; set; } = new List(); + + public ICollection Quizs { get; set; } = new List(); } } diff --git a/WF_EF_Api/Entity/LangEnum.cs b/WF_EF_Api/Entity/LangEnum.cs index a3238c3..3f8f2a1 100644 --- a/WF_EF_Api/Entity/LangEnum.cs +++ b/WF_EF_Api/Entity/LangEnum.cs @@ -9,7 +9,6 @@ namespace Entity public enum LangEnum { vo, - fr, - en + vf } } diff --git a/WF_EF_Api/Entity/Question.cs b/WF_EF_Api/Entity/Question.cs index 5bc982c..df66009 100644 --- a/WF_EF_Api/Entity/Question.cs +++ b/WF_EF_Api/Entity/Question.cs @@ -1,5 +1,7 @@ using System; using System.Collections.Generic; +using System.ComponentModel.DataAnnotations.Schema; +using System.ComponentModel.DataAnnotations; using System.Linq; using System.Text; using System.Threading.Tasks; @@ -8,13 +10,34 @@ namespace Entity { public class Question { + [Key] + [DatabaseGenerated(DatabaseGeneratedOption.Identity)] public int Id { get; set; } + + [Required] + [StringLength(50)] public string Text { get; set; } + + [Required] + [StringLength(50)] public string AnswerA { get; set; } + + [Required] + [StringLength(50)] public string AnswerB { get; set; } + + [Required] + [StringLength(50)] public string AnswerC { get; set; } + + [Required] + [StringLength(50)] public string AnswerD { get; set; } + + [Required] + [StringLength(1)] public string CorrectAnswer { get; set; } + public ICollection Quizs { get; } = new List(); } } diff --git a/WF_EF_Api/Entity/Quiz.cs b/WF_EF_Api/Entity/Quiz.cs index 11e7bb5..27f69ee 100644 --- a/WF_EF_Api/Entity/Quiz.cs +++ b/WF_EF_Api/Entity/Quiz.cs @@ -1,5 +1,7 @@ using System; using System.Collections.Generic; +using System.ComponentModel.DataAnnotations.Schema; +using System.ComponentModel.DataAnnotations; using System.Linq; using System.Text; using System.Threading.Tasks; @@ -8,9 +10,23 @@ namespace Entity { public class Quiz { + [Key] + [DatabaseGenerated(DatabaseGeneratedOption.Identity)] public int Id { get; set; } + + [Required] + [StringLength(50)] public string Title { get; set; } - //public int IdImage { get; set; } + + [Required] + [ForeignKey(nameof(Images))] + public int IdImage { get; set; } + + [Required] public int NbQuestion { get; set; } + + public Images Images { get; set; } = null!; + + public ICollection Questions { get; } = new List(); } } diff --git a/WF_EF_Api/Entity/QuizQuestion.cs b/WF_EF_Api/Entity/QuizQuestion.cs index a62ba83..eaf51c3 100644 --- a/WF_EF_Api/Entity/QuizQuestion.cs +++ b/WF_EF_Api/Entity/QuizQuestion.cs @@ -1,5 +1,7 @@ using System; using System.Collections.Generic; +using System.ComponentModel.DataAnnotations; +using System.ComponentModel.DataAnnotations.Schema; using System.Linq; using System.Text; using System.Threading.Tasks; @@ -8,7 +10,16 @@ namespace Entity { public class QuizQuestion { - //public int IdQuiz { get; set; } - //public int IdQuestion { get; set; } + [Key] + [ForeignKey(nameof(Quiz))] + public int IdQuiz { get; set; } + + [Key] + [ForeignKey(nameof(Question))] + public int IdQuestion { get; set; } + + public Quiz Quiz { get; set; } = null!; + + public Question Question { get; set; } = null!; } } diff --git a/WF_EF_Api/Entity/Quote.cs b/WF_EF_Api/Entity/Quote.cs index 57621c1..adc1dd8 100644 --- a/WF_EF_Api/Entity/Quote.cs +++ b/WF_EF_Api/Entity/Quote.cs @@ -1,5 +1,7 @@ using System; using System.Collections.Generic; +using System.ComponentModel.DataAnnotations.Schema; +using System.ComponentModel.DataAnnotations; using System.Linq; using System.Text; using System.Threading.Tasks; @@ -8,13 +10,39 @@ namespace Entity { public class Quote { + [Key] + [DatabaseGenerated(DatabaseGeneratedOption.Identity)] public int Id { get; set; } + + [Required] + [StringLength(50)] public string Content { get; set; } + + [Required] public int Likes { get; set; } + + [Required] public LangEnum Langage { get; set; } + + [Required] public bool IsValid { get; set; } - //public int IdCharacter { get; set; } - //public int IdSource { get; set; } - //public int IdUsersPropose { get; set; } + + [Required] + [ForeignKey(nameof(Character))] + public int IdCharacter { get; set; } + + [Required] + [ForeignKey(nameof(Source))] + public int IdSource { get; set; } + + [Required] + [ForeignKey(nameof(Users))] + public int IdUsersPropose { get; set; } + + public ICollection DailyQuotes { get; set; } = new List(); + + public ICollection commentaries { get; set; } = new List(); + + public ICollection Favorite { get; set; } = new List(); } } diff --git a/WF_EF_Api/Entity/RecordQuiz.cs b/WF_EF_Api/Entity/RecordQuiz.cs index 5ddc02d..4a6a689 100644 --- a/WF_EF_Api/Entity/RecordQuiz.cs +++ b/WF_EF_Api/Entity/RecordQuiz.cs @@ -6,6 +6,7 @@ using System.Threading.Tasks; namespace Entity { + // Peut etre enlever car inutiliser public class RecordQuiz { public int IdUsers { get; set; } diff --git a/WF_EF_Api/Entity/Source.cs b/WF_EF_Api/Entity/Source.cs index 18f242e..4a9f77c 100644 --- a/WF_EF_Api/Entity/Source.cs +++ b/WF_EF_Api/Entity/Source.cs @@ -1,5 +1,7 @@ using System; using System.Collections.Generic; +using System.ComponentModel.DataAnnotations.Schema; +using System.ComponentModel.DataAnnotations; using System.Linq; using System.Text; using System.Threading.Tasks; @@ -8,8 +10,20 @@ namespace Entity { public class Source { + [Key] + [DatabaseGenerated(DatabaseGeneratedOption.Identity)] public int Id { get; set; } + + [Required] + [StringLength(50)] public string Title { get; set; } - public int Year { get; set; } + + [Required] + public int Year { get; set; } + + [Required] + public TypeSrcEnum TypeSrc { get; set; } + + public ICollection Quotes { get; set; } = new List(); } } diff --git a/WF_EF_Api/Entity/TypeSrcEnum.cs b/WF_EF_Api/Entity/TypeSrcEnum.cs new file mode 100644 index 0000000..b5aa4e1 --- /dev/null +++ b/WF_EF_Api/Entity/TypeSrcEnum.cs @@ -0,0 +1,16 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Entity +{ + public enum TypeSrcEnum + { + movie, + series, + book, + videogame + } +} diff --git a/WF_EF_Api/Entity/Users.cs b/WF_EF_Api/Entity/Users.cs index c5049f7..81aa506 100644 --- a/WF_EF_Api/Entity/Users.cs +++ b/WF_EF_Api/Entity/Users.cs @@ -13,14 +13,32 @@ namespace Entity [Key] [DatabaseGenerated(DatabaseGeneratedOption.Identity)] public int Id { get; set; } + + [Required] + [StringLength(50)] public string UserName { get; set; } + + [Required] + [StringLength(50)] public string Email { get; set; } + + [Required] + [StringLength(200)] public string Password { get; set; } [ForeignKey(nameof(Images))] public int IdImage { get; set; } - public Images Images { get; set; } + [Required] + [Column("Created", TypeName = "date")] public DateTime Created { get; set; } + + public Images Images { get; set; } + + public ICollection Quotes { get; set; } = new List(); + + public ICollection Commentary { get; set; } = new List(); + + public ICollection Favorite { get; set; } = new List(); } } diff --git a/WF_EF_Api/StubbedContextLib/StubWTFContext.cs b/WF_EF_Api/StubbedContextLib/StubWTFContext.cs index 8d983a4..8ef24d8 100644 --- a/WF_EF_Api/StubbedContextLib/StubWTFContext.cs +++ b/WF_EF_Api/StubbedContextLib/StubWTFContext.cs @@ -15,20 +15,117 @@ namespace StubbedContextLib { base.OnModelCreating(modelBuilder); - modelBuilder.Entity() - .HasMany(i => i.Users) - .WithOne(u => u.Images) - .HasForeignKey(u => u.IdImage) - .IsRequired(); + modelBuilder.Entity().HasData( + new Admin() { IdUsers = 1 } + ); + + modelBuilder.Entity().HasData( + new Character() { Id = 1 , Name = "Alan Grant", IdImage = 1}, + new Character() { Id = 2, Name = "Aragorn", IdImage = 2 }, + new Character() { Id = 3, Name = "Legolas", IdImage = 3 }, + new Character() { Id = 4, Name = "Frodon", IdImage = 4 }, + new Character() { Id = 5, Name = "Dobby", IdImage = 5 }, + new Character() { Id = 6, Name = "Jon Snow", IdImage = 6 }, + new Character() { Id = 7, Name = "Daenerys Targaryen", IdImage = 7 }, + new Character() { Id = 8, Name = "Luke Skywalker", IdImage = 8 }, + new Character() { Id = 9, Name = "Princess Leia", IdImage = 9 }, + new Character() { Id = 10, Name = "Harry Potter", IdImage = 10 } + ); + + modelBuilder.Entity().HasData( + new Commentary() { Id = 1, Comment = "Ce film est le meilleur", DateCommentary = new DateTime(2025,2,3), IdQuote = 1, IdUsers = 2 }, + new Commentary() { Id = 2, Comment = "Very good", DateCommentary = new DateTime(2025, 3, 11), IdQuote = 1, IdUsers = 3 } + ); + + modelBuilder.Entity().HasData( + new DailyQuote() { IdQuote = 1}, + new DailyQuote() { IdQuote = 5} + ); + + modelBuilder.Entity().HasData( + new Favorite() { IdQuote = 2, IdUsers = 8 }, + new Favorite() { IdQuote = 5, IdUsers = 3 }, + new Favorite() { IdQuote = 9, IdUsers = 1 }, + new Favorite() { IdQuote = 4, IdUsers = 10 }, + new Favorite() { IdQuote = 3, IdUsers = 2 }, + new Favorite() { IdQuote = 6, IdUsers = 7 }, + new Favorite() { IdQuote = 1, IdUsers = 6 }, + new Favorite() { IdQuote = 8, IdUsers = 9 }, + new Favorite() { IdQuote = 10, IdUsers = 5 } + ); modelBuilder.Entity().HasData( - new Images { Id = 1, ImgPath = "coucou" }, - new Images { Id = 2, ImgPath = "bonjour" } + new Images() { Id = 1 , ImgPath = "https://th.bing.com/th/id/OIP.TJuWNCsibz8MVmhdNQEdMwHaE8?w=244&h=180&c=7&r=0&o=5&pid=1.7" }, + new Images() { Id = 2 , ImgPath = "https://th.bing.com/th/id/OIP.NgXRQ5-IknA6_qOPFhLWIwHaHK?w=165&h=180&c=7&r=0&o=5&pid=1.7" }, + new Images() { Id = 3 , ImgPath = "https://th.bing.com/th/id/OIP.XcJoJ6bC9sAMjol1pJn5UQHaLH?w=118&h=180&c=7&r=0&o=5&pid=1.7" }, + new Images() { Id = 4 , ImgPath = "https://th.bing.com/th/id/OIP.PPIESqZaNDa-qUcfSDXhdQHaGK?w=210&h=180&c=7&r=0&o=5&pid=1.7" }, + new Images() { Id = 5 , ImgPath = "https://th.bing.com/th/id/OIP.XBghSl2kfRNNtQoSxc901wHaHa?w=177&h=180&c=7&r=0&o=5&pid=1.7" }, + new Images() { Id = 6 , ImgPath = "https://th.bing.com/th/id/OIP.af1Aid64cqEKoIOBgCPxtQHaJO?w=145&h=182&c=7&r=0&o=5&pid=1.7" }, + new Images() { Id = 7 , ImgPath = "https://th.bing.com/th/id/OIP.ri5vSXr5lNTLt4DO6KQXyQHaI4?w=158&h=189&c=7&r=0&o=5&pid=1.7" }, + new Images() { Id = 8 , ImgPath = "https://th.bing.com/th/id/OIP.uPTRLR8uspCiafiunUqKfQHaMJ?w=115&h=180&c=7&r=0&o=5&pid=1.7" }, + new Images() { Id = 9 , ImgPath = "https://th.bing.com/th/id/OIP.hcJis4rKbyQtugsoFJU2ngHaM_?w=118&h=207&c=7&r=0&o=5&pid=1.7" }, + new Images() { Id = 10 , ImgPath = "https://th.bing.com/th/id/OIP.Py1_XfUrKJY_A6tYEmFS5wHaE8?w=280&h=187&c=7&r=0&o=5&pid=1.7" } + ); + + modelBuilder.Entity().HasData( + new Question() { Id = 1, Text = "Qui est le leader de la Communauté de l'Anneau ?", AnswerA = "Gimli", AnswerB = "Aragorn", AnswerC = "Frodon", AnswerD = "Gandalf", CorrectAnswer = "B" }, + new Question() { Id = 2, Text = "Dans quelle maison Harry Potter est-il ?", AnswerA = "Serdaigle", AnswerB = "Gryffondor", AnswerC = "Serpentard", AnswerD = "Poufsouffle", CorrectAnswer = "B" }, + new Question() { Id = 3, Text = "Qui est le Seigneur des Ténèbres dans la saga 'Le Seigneur des Anneaux' ?", AnswerA = "Saroumane", AnswerB = "Sauron", AnswerC = "Gollum", AnswerD = "Gothmog", CorrectAnswer = "B" }, + new Question() { Id = 4, Text = "Dans le film 'Star Wars : Episode IV', qui sauve Luke Skywalker de l'Étoile de la Mort ?", AnswerA = "Han Solo", AnswerB = "Princesse Leia", AnswerC = "Chewbacca", AnswerD = "R2-D2", CorrectAnswer = "A" }, + new Question() { Id = 5, Text = "Qui est le souverain de Narnia dans 'Le Lion, la Sorcière Blanche et l'Armoire Magique' ?", AnswerA = "Reine Jadis", AnswerB = "Aslan", AnswerC = "Edmund", AnswerD = "Lucy", CorrectAnswer = "B" }, + new Question() { Id = 6, Text = "Quel est le nom du dragon dans 'Le Hobbit' ?", AnswerA = "Smaug", AnswerB = "Falkor", AnswerC = "Norbert", AnswerD = "Shenron", CorrectAnswer = "A" }, + new Question() { Id = 7, Text = "Qui est la première personne à être mordue par un vampire dans 'Twilight' ?", AnswerA = "Bella Swan", AnswerB = "Edward Cullen", AnswerC = "Jacob Black", AnswerD = "Victoria", CorrectAnswer = "A" }, + new Question() { Id = 8, Text = "Quel personnage dit 'Que la Force soit avec toi' dans 'Star Wars' ?", AnswerA = "Obi-Wan Kenobi", AnswerB = "Yoda", AnswerC = "Han Solo", AnswerD = "Luke Skywalker", CorrectAnswer = "A" }, + new Question() { Id = 9, Text = "Dans 'Jurassic Park', quel est le nom du paléontologue sur l'île ?", AnswerA = "Dr. Ellie Sattler", AnswerB = "Alan Grant", AnswerC = "John Hammond", AnswerD = "Dennis Nedry", CorrectAnswer = "B" }, + new Question() { Id = 10, Text = "Dans 'Game of Thrones', qui est surnommée la Mère des Dragons ?", AnswerA = "Cersei Lannister", AnswerB = "Arya Stark", AnswerC = "Daenerys Targaryen", AnswerD = "Sansa Stark", CorrectAnswer = "C" } ); + + modelBuilder.Entity().HasData( + new Quiz() { Id = 1, IdImage = 1, Title = "Quiz 1", NbQuestion = 5 }, + new Quiz() { Id = 1, IdImage = 2, Title = "Quiz 2", NbQuestion = 5 } + ); + + modelBuilder.Entity().HasData( + new QuizQuestion() { IdQuestion = 1, IdQuiz = 1 }, + new QuizQuestion() { IdQuestion = 2, IdQuiz = 1 }, + new QuizQuestion() { IdQuestion = 3, IdQuiz = 1 }, + new QuizQuestion() { IdQuestion = 4, IdQuiz = 1 }, + new QuizQuestion() { IdQuestion = 5, IdQuiz = 1 }, + new QuizQuestion() { IdQuestion = 6, IdQuiz = 2 }, + new QuizQuestion() { IdQuestion = 7, IdQuiz = 2 }, + new QuizQuestion() { IdQuestion = 8, IdQuiz = 2 }, + new QuizQuestion() { IdQuestion = 9, IdQuiz = 2 }, + new QuizQuestion() { IdQuestion = 10, IdQuiz = 2 } + ); + + modelBuilder.Entity().HasData( + new Quote() { Id = 1, Content = "Je n'y crois pas. Je n'y crois pas. Ce n'est pas possible", IdCharacter = 1, IdSource = 1, IdUsersPropose = 1 , IsValid = true, Langage = LangEnum.vf, Likes = 11025}, + new Quote() { Id = 1, Content = "There is always hope", IdCharacter = 2, IdSource = 2, IdUsersPropose = 1, IsValid = true, Langage = LangEnum.vo, Likes = 11025 }, + new Quote() { Id = 1, Content = "A red sun rises. Blood has been spilled this night.", IdCharacter = 3, IdSource = 2, IdUsersPropose = 1, IsValid = true, Langage = LangEnum.vo, Likes = 11025 } + ); + + modelBuilder.Entity().HasData( + new Source() { Id = 1, Title = "Jurassic Park", TypeSrc = TypeSrcEnum.movie, Year = 1993 }, + new Source() { Id = 2, Title = "Le Seigneur des anneaux : La Communauté de l'anneau", TypeSrc = TypeSrcEnum.movie, Year = 2001 }, + new Source() { Id = 3, Title = "Game of throne", TypeSrc = TypeSrcEnum.series, Year = 2011 }, + new Source() { Id = 4, Title = "Harry Potter à l'école des sorcier", TypeSrc = TypeSrcEnum.movie, Year = 1997 }, + new Source() { Id = 5, Title = "Star Wars, épisode IV : Un nouvel espoir", TypeSrc = TypeSrcEnum.movie, Year = 1977 } + ); + modelBuilder.Entity().HasData( - new Users { Id = 1, UserName = "Dev", Created = new DateTime(2000, 01, 01), Email = "dev@gmail.com", Password = "1234", IdImage = 1 }, - new Users { Id = 2, UserName = "Admin", Created = new DateTime(2000, 01, 01), Email = "admin@gmail.com", Password = "1234", IdImage = 1 } + new Users() { Id = 1, Email = "jhonDhoe@gmail.com", Password = "1234", Created = new DateTime(2025, 5, 12), UserName = "Jhon-Dhoe", IdImage = 1 }, + new Users() { Id = 2, Email = "lucy_rose@outlook.com", Password = "abcd", Created = new DateTime(2025, 3, 19), UserName = "Lucy-Rose", IdImage = 2 }, + new Users() { Id = 3, Email = "mark.taylor@yahoo.com", Password = "5678", Created = new DateTime(2024, 11, 2), UserName = "Mark-Taylor", IdImage = 3 }, + new Users() { Id = 4, Email = "sophie.martin@gmail.com", Password = "4321", Created = new DateTime(2025, 2, 28), UserName = "Sophie-Martin", IdImage = 4 }, + new Users() { Id = 5, Email = "nathan_doe@aol.com", Password = "8765", Created = new DateTime(2025, 1, 15), UserName = "Nathan-Doe", IdImage = 5 }, + new Users() { Id = 6, Email = "ella.brown@icloud.com", Password = "2468", Created = new DateTime(2025, 4, 7), UserName = "Ella-Brown", IdImage = 6 }, + new Users() { Id = 7, Email = "oliver_smith@gmail.com", Password = "1357", Created = new DateTime(2024, 12, 25), UserName = "Oliver-Smith", IdImage = 7 }, + new Users() { Id = 8, Email = "mia.jones@outlook.com", Password = "1122", Created = new DateTime(2025, 3, 5), UserName = "Mia-Jones", IdImage = 8 }, + new Users() { Id = 9, Email = "kevin_williams@aol.com", Password = "2233", Created = new DateTime(2025, 2, 22), UserName = "Kevin-Williams", IdImage = 9 }, + new Users() { Id = 10, Email = "olivia.white@yahoo.com", Password = "3344", Created = new DateTime(2025, 1, 3), UserName = "Olivia-White", IdImage = 10 } ); + + } } } From 7ff1bacb96bfc5ea9a30f688383ede4c6984e1ef Mon Sep 17 00:00:00 2001 From: Kevin MONDEJAR Date: Fri, 14 Mar 2025 11:22:26 +0100 Subject: [PATCH 04/65] =?UTF-8?q?Fin=20ajout=20donn=C3=A9es=20stuber=20+?= =?UTF-8?q?=20d=C3=A9but=20DbManager?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- WF_EF_Api/Contextlib/DbCharacterManager.cs | 154 ++++++++++++++++++ WF_EF_Api/StubbedContextLib/StubWTFContext.cs | 12 +- 2 files changed, 164 insertions(+), 2 deletions(-) create mode 100644 WF_EF_Api/Contextlib/DbCharacterManager.cs diff --git a/WF_EF_Api/Contextlib/DbCharacterManager.cs b/WF_EF_Api/Contextlib/DbCharacterManager.cs new file mode 100644 index 0000000..65f19e9 --- /dev/null +++ b/WF_EF_Api/Contextlib/DbCharacterManager.cs @@ -0,0 +1,154 @@ +using Entity; +using Microsoft.EntityFrameworkCore; +using Shared; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Contextlib +{ + public class DbCharacterManager : ICharacterService + { + private WTFContext _context; + + /// + /// Initializes a new instance of the class. + /// + /// The instance used to interact with the database. + public DbCharacterManager(WTFContext context) + { + _context = context ?? throw new ArgumentNullException(nameof(context), "Database context cannot be null."); + } + + /// + /// Adds a new character to the database. + /// + /// The character to be added to the database. + /// A task that represents the asynchronous operation. + /// Thrown when the provided character is null. + public async Task AddCharacter(Character character) + { + if (character == null) + { + throw new ArgumentNullException(nameof(character), "Character cannot be null."); + } + + await _context.AddAsync(character); + await _context.SaveChangesAsync(); + } + + /// + /// Retrieves all characters from the database and returns them in a paginated format. + /// + /// A task representing the asynchronous operation, with a as its result containing the full list of characters and pagination information. + public Task> GetAll() + { + List charLst = _context.characters.ToList(); + + return Task.FromResult(new PaginationResult( + charLst.Count, // Total count of characters in the database + 0, // Current page (in this case, no pagination logic implemented) + charLst.Count, // Total number of items (same as count for no pagination) + charLst // The list of characters + )); + } + + /// + /// Retrieves a character by its ID from the database. + /// + /// The unique identifier of the character to retrieve. + /// A task that represents the asynchronous operation, with a as its result. + /// Thrown when no character is found with the given ID. + public async Task GetCharById(int id) + { + Character? character = await _context.characters + .FirstOrDefaultAsync(x => x.Id == id); + + if (character == null) + { + throw new KeyNotFoundException($"Error : No character found with the ID: {id}."); + } + + return character; + } + + /// + /// Retrieves a character by its name from the database. + /// + /// The name of the character to retrieve. + /// A task that represents the asynchronous operation, with a as its result. + /// Thrown when no character is found with the given name. + public async Task GetCharByName(string name) + { + Character? character = await _context.characters + .FirstOrDefaultAsync(x => x.Name.Equals(name, StringComparison.OrdinalIgnoreCase)); + + if (character == null) + { + throw new KeyNotFoundException($"Error : No character found with the name: {name}."); + } + + return character; + } + + /// + /// Retrieves the highest character ID from the database. + /// + /// The highest character ID in the database. 0 if there is no character in the database + public async Task GetLastCharId() + { + int id = await _context.characters + .OrderByDescending(x => x.Id) + .Select(x => x.Id) + .FirstOrDefaultAsync(); + return id; + } + + /// + /// Removes a character from the database by its ID. + /// + /// The ID of the character to remove. + /// A task representing the asynchronous operation. + /// Thrown when no character is found with the given ID. + public async Task RemoveCharacter(int id) + { + Character? character = await _context.characters.FirstOrDefaultAsync(x => x.Id == id); + if (character == null) + { + throw new KeyNotFoundException($"Error : Unable to delete, no character found with the ID: {id}."); + } + + _context.characters.Remove(character); + await _context.SaveChangesAsync(); + } + + /// + /// Updates a character's details by its ID. + /// + /// The ID of the character to update. + /// The updated character information. + /// A task representing the asynchronous operation. + /// /// Thrown when the provided character is null. + /// Thrown when no character is found with the given ID. + public async Task UpdateCharacter(int id, Character character) + { + if (character == null) + { + throw new ArgumentNullException(nameof(character), "The updated character data cannot be null."); + } + + Character? charUpdated = await _context.characters.FirstOrDefaultAsync(x => x.Id == id); + if (charUpdated == null) + { + throw new KeyNotFoundException($"Error : Unable to update, no character found with the ID: {id} ."); + } + + charUpdated.IdImage = character.IdImage; + charUpdated.Name = character.Name; + + await _context.SaveChangesAsync(); + } + } +} diff --git a/WF_EF_Api/StubbedContextLib/StubWTFContext.cs b/WF_EF_Api/StubbedContextLib/StubWTFContext.cs index 8ef24d8..8fda1c6 100644 --- a/WF_EF_Api/StubbedContextLib/StubWTFContext.cs +++ b/WF_EF_Api/StubbedContextLib/StubWTFContext.cs @@ -100,9 +100,17 @@ namespace StubbedContextLib modelBuilder.Entity().HasData( new Quote() { Id = 1, Content = "Je n'y crois pas. Je n'y crois pas. Ce n'est pas possible", IdCharacter = 1, IdSource = 1, IdUsersPropose = 1 , IsValid = true, Langage = LangEnum.vf, Likes = 11025}, - new Quote() { Id = 1, Content = "There is always hope", IdCharacter = 2, IdSource = 2, IdUsersPropose = 1, IsValid = true, Langage = LangEnum.vo, Likes = 11025 }, - new Quote() { Id = 1, Content = "A red sun rises. Blood has been spilled this night.", IdCharacter = 3, IdSource = 2, IdUsersPropose = 1, IsValid = true, Langage = LangEnum.vo, Likes = 11025 } + new Quote() { Id = 2, Content = "There is always hope", IdCharacter = 2, IdSource = 2, IdUsersPropose = 1, IsValid = true, Langage = LangEnum.vo, Likes = 11025 }, + new Quote() { Id = 3, Content = "A red sun rises. Blood has been spilled this night.", IdCharacter = 3, IdSource = 2, IdUsersPropose = 1, IsValid = true, Langage = LangEnum.vo, Likes = 11025 }, + new Quote() { Id = 4, Content = "I wish the Ring had never come to me.I wish none of this had happened.", IdCharacter = 4, IdSource = 2, IdUsersPropose = 1, IsValid = true, Langage = LangEnum.vo, Likes = 11025 }, + new Quote() { Id = 5, Content = "Dobby is a free elf!", IdCharacter = 5 , IdSource = 4 , IdUsersPropose = 1, IsValid = true, Langage = LangEnum.vo, Likes = 11025 }, + new Quote() { Id = 6, Content = "Winter is comming", IdCharacter = 6 , IdSource = 3, IdUsersPropose = 1, IsValid = true, Langage = LangEnum.vo, Likes = 11025 }, + new Quote() { Id = 7, Content = "Je suis la dernière Targaryen. Je suis la reine des dragons", IdCharacter = 7 , IdSource = 3, IdUsersPropose = 1, IsValid = true, Langage = LangEnum.vf, Likes = 11025 }, + new Quote() { Id = 8, Content = "Je ne suis pas prêt à affronter ça. C'est trop pour moi.", IdCharacter = 8 , IdSource = 5, IdUsersPropose = 1, IsValid = true, Langage = LangEnum.vf, Likes = 11025 }, + new Quote() { Id = 9, Content = "Aidez-moi, Obi-Wan Kenobi, vous êtes mon seul espoir.", IdCharacter = 9 , IdSource = 5, IdUsersPropose = 1, IsValid = true, Langage = LangEnum.vf, Likes = 11025 }, + new Quote() { Id = 10, Content = "La quoi ?", IdCharacter = 10 , IdSource = 4 , IdUsersPropose = 1, IsValid = true, Langage = LangEnum.vf, Likes = 11025 } ); + modelBuilder.Entity().HasData( new Source() { Id = 1, Title = "Jurassic Park", TypeSrc = TypeSrcEnum.movie, Year = 1993 }, From 7694c94feb5db6141371d1f480bed4e55c61d064 Mon Sep 17 00:00:00 2001 From: Kevin MONDEJAR Date: Fri, 14 Mar 2025 11:58:33 +0100 Subject: [PATCH 05/65] test many to many non fonctionel --- WF_EF_Api/Contextlib/Contextlib.csproj | 1 + WF_EF_Api/Contextlib/DbCharacterManager.cs | 11 +- WF_EF_Api/Contextlib/DbCommentaryManager.cs | 111 ++++++++++++++++++ WF_EF_Api/Contextlib/WTFContext.cs | 26 +++- WF_EF_Api/Entity/Favorite.cs | 8 -- WF_EF_Api/Entity/Question.cs | 2 +- WF_EF_Api/Entity/QuizQuestion.cs | 8 -- WF_EF_Api/Entity/Quote.cs | 2 +- WF_EF_Api/Entity/Users.cs | 2 +- WF_EF_Api/Shared/IComentaryService.cs | 2 +- WF_EF_Api/StubbedContextLib/StubWTFContext.cs | 6 +- 11 files changed, 143 insertions(+), 36 deletions(-) create mode 100644 WF_EF_Api/Contextlib/DbCommentaryManager.cs diff --git a/WF_EF_Api/Contextlib/Contextlib.csproj b/WF_EF_Api/Contextlib/Contextlib.csproj index 805901c..d2b9100 100644 --- a/WF_EF_Api/Contextlib/Contextlib.csproj +++ b/WF_EF_Api/Contextlib/Contextlib.csproj @@ -22,6 +22,7 @@ + diff --git a/WF_EF_Api/Contextlib/DbCharacterManager.cs b/WF_EF_Api/Contextlib/DbCharacterManager.cs index 65f19e9..db1a7c0 100644 --- a/WF_EF_Api/Contextlib/DbCharacterManager.cs +++ b/WF_EF_Api/Contextlib/DbCharacterManager.cs @@ -13,10 +13,6 @@ namespace Contextlib { private WTFContext _context; - /// - /// Initializes a new instance of the class. - /// - /// The instance used to interact with the database. public DbCharacterManager(WTFContext context) { _context = context ?? throw new ArgumentNullException(nameof(context), "Database context cannot be null."); @@ -47,12 +43,7 @@ namespace Contextlib { List charLst = _context.characters.ToList(); - return Task.FromResult(new PaginationResult( - charLst.Count, // Total count of characters in the database - 0, // Current page (in this case, no pagination logic implemented) - charLst.Count, // Total number of items (same as count for no pagination) - charLst // The list of characters - )); + return Task.FromResult(new PaginationResult(charLst.Count, 0, charLst.Count, charLst)); } /// diff --git a/WF_EF_Api/Contextlib/DbCommentaryManager.cs b/WF_EF_Api/Contextlib/DbCommentaryManager.cs new file mode 100644 index 0000000..85c7ac8 --- /dev/null +++ b/WF_EF_Api/Contextlib/DbCommentaryManager.cs @@ -0,0 +1,111 @@ +using Entity; +using Microsoft.EntityFrameworkCore; +using Shared; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Contextlib +{ + public class DbCommentManager : ICommentService + { + private WTFContext _context; + + public DbCommentManager(WTFContext context) + { + _context = context ?? throw new ArgumentNullException(nameof(context), "Database context cannot be null."); + } + + /// + /// Adds a new comment to the database. + /// + /// The comment to add. + /// A task representing the asynchronous operation. + /// Thrown when the comment is null. + public async Task AddComment(Commentary comment) + { + if (comment == null) + { + throw new ArgumentNullException(nameof(comment), "Comment cannot be null."); + } + + await _context.comments.AddAsync(comment); + await _context.SaveChangesAsync(); + } + + /// + /// Deletes all comments associated with a specific quote ID from the database. + /// + /// The ID of the quote whose comments need to be deleted. + /// A task representing the asynchronous operation. + /// Thrown when no comments are found for the provided quote ID. + public async Task DeleteCommentForQuote(int quoteId) + { + // Retrieve comments for the specific quoteId + var comments = await _context.comments.Where(x => x.IdQuote == quoteId).ToListAsync(); + if (!comments.Any()) // If no comments exist for this quoteId + { + throw new KeyNotFoundException($"No comments found for the quote ID: {quoteId}."); + } + + _context.comments.RemoveRange(comments); // Efficiently remove all comments in one batch + await _context.SaveChangesAsync(); + } + + /// + /// Deletes all comments associated with a specific user ID from the database. + /// + /// The ID of the user whose comments need to be deleted. + /// A task representing the asynchronous operation. + /// Thrown when no comments are found for the provided user ID. + public async Task DeleteCommentForUser(int userId) + { + // Retrieve comments for the specific userId + var comments = await _context.comments.Where(x => x.IdUsers == userId).ToListAsync(); + if (!comments.Any()) // If no comments exist for this userId + { + throw new KeyNotFoundException($"No comments found for the user ID: {userId}."); + } + + _context.comments.RemoveRange(comments); // Efficiently remove all comments in one batch + await _context.SaveChangesAsync(); + } + + public async Task> GetAllComment() + { + throw new NotImplementedException(); + } + + public async Task GetCommentById(int id) + { + throw new NotImplementedException(); + } + + public async Task> GetCommentByQuote(int quoteId, int index, int pageSize) + { + throw new NotImplementedException(); + } + + public async Task> GetCommentByUser(int userId, int index, int pageSize) + { + throw new NotImplementedException(); + } + + public async Task LastCommentId() + { + throw new NotImplementedException(); + } + + public async Task RemoveComment(int id) + { + throw new NotImplementedException(); + } + + public async Task UpdateComment(int id, Commentary comment) + { + throw new NotImplementedException(); + } + } +} diff --git a/WF_EF_Api/Contextlib/WTFContext.cs b/WF_EF_Api/Contextlib/WTFContext.cs index 02880c7..ad5e4e5 100644 --- a/WF_EF_Api/Contextlib/WTFContext.cs +++ b/WF_EF_Api/Contextlib/WTFContext.cs @@ -10,20 +10,40 @@ namespace Contextlib { public class WTFContext : DbContext { - public DbSet admins { get; set; } + //public DbSet admins { get; set; } public DbSet characters { get; set; } public DbSet comments { get; set; } public DbSet dailyquotes { get; set; } - public DbSet favorites { get; set; } + //public DbSet favorites { get; set; } public DbSet images { get; set; } public DbSet question { get; set; } public DbSet quizzes { get; set; } - public DbSet quizQuestions { get; set; } + //public DbSet quizQuestions { get; set; } public DbSet quotes { get; set; } //public DbSet records { get; set; } public DbSet sources { get; set; } public DbSet users { get; set; } + protected override void OnModelCreating(ModelBuilder modelBuilder) + { + base.OnModelCreating(modelBuilder); + + modelBuilder.Entity() + .HasMany(q => q.Favorite) + .WithMany(u => u.Favorite) + .UsingEntity( + l => l.HasOne().WithMany().HasForeignKey(q => q.IdQuote), + r => r.HasOne().WithMany().HasForeignKey(u => u.IdUsers) + ); + + modelBuilder.Entity() + .HasMany(q => q.Questions) + .WithMany(u => u.Quizs) + .UsingEntity( + l => l.HasOne().WithMany().HasForeignKey(q => q.IdQuestion), + r => r.HasOne().WithMany().HasForeignKey(u => u.IdQuiz) + ); + } protected override void OnConfiguring(DbContextOptionsBuilder options) => options.UseSqlServer(@"Server=(localdb)\mssqllocaldb;Database=WfDatabase.mdf;Trusted_Connection=True;"); diff --git a/WF_EF_Api/Entity/Favorite.cs b/WF_EF_Api/Entity/Favorite.cs index 51165d5..ec60347 100644 --- a/WF_EF_Api/Entity/Favorite.cs +++ b/WF_EF_Api/Entity/Favorite.cs @@ -10,16 +10,8 @@ namespace Entity { public class Favorite { - [Key] - [ForeignKey(nameof(Users))] public int IdUsers { get; set; } - [Key] - [ForeignKey(nameof(Quote))] public int IdQuote { get; set; } - - public Users User { get; set; } = null!; - - public Quote Quote { get; set; } = null!; } } diff --git a/WF_EF_Api/Entity/Question.cs b/WF_EF_Api/Entity/Question.cs index df66009..036747d 100644 --- a/WF_EF_Api/Entity/Question.cs +++ b/WF_EF_Api/Entity/Question.cs @@ -38,6 +38,6 @@ namespace Entity [StringLength(1)] public string CorrectAnswer { get; set; } - public ICollection Quizs { get; } = new List(); + public ICollection Quizs { get; set; } = new List(); } } diff --git a/WF_EF_Api/Entity/QuizQuestion.cs b/WF_EF_Api/Entity/QuizQuestion.cs index eaf51c3..5e7086b 100644 --- a/WF_EF_Api/Entity/QuizQuestion.cs +++ b/WF_EF_Api/Entity/QuizQuestion.cs @@ -10,16 +10,8 @@ namespace Entity { public class QuizQuestion { - [Key] - [ForeignKey(nameof(Quiz))] public int IdQuiz { get; set; } - [Key] - [ForeignKey(nameof(Question))] public int IdQuestion { get; set; } - - public Quiz Quiz { get; set; } = null!; - - public Question Question { get; set; } = null!; } } diff --git a/WF_EF_Api/Entity/Quote.cs b/WF_EF_Api/Entity/Quote.cs index adc1dd8..e91cd13 100644 --- a/WF_EF_Api/Entity/Quote.cs +++ b/WF_EF_Api/Entity/Quote.cs @@ -43,6 +43,6 @@ namespace Entity public ICollection commentaries { get; set; } = new List(); - public ICollection Favorite { get; set; } = new List(); + public ICollection Favorite { get; } = new List(); } } diff --git a/WF_EF_Api/Entity/Users.cs b/WF_EF_Api/Entity/Users.cs index 81aa506..80e38a7 100644 --- a/WF_EF_Api/Entity/Users.cs +++ b/WF_EF_Api/Entity/Users.cs @@ -39,6 +39,6 @@ namespace Entity public ICollection Commentary { get; set; } = new List(); - public ICollection Favorite { get; set; } = new List(); + public ICollection Favorite { get; set; } = new List(); } } diff --git a/WF_EF_Api/Shared/IComentaryService.cs b/WF_EF_Api/Shared/IComentaryService.cs index 2cf4fe1..d5c4fc6 100644 --- a/WF_EF_Api/Shared/IComentaryService.cs +++ b/WF_EF_Api/Shared/IComentaryService.cs @@ -46,7 +46,7 @@ namespace Shared // Deletes all comments made by a specific user. // 'userId' is the unique identifier of the user whose comments will be deleted. - Task DeleteCommentForuser(int userId); + Task DeleteCommentForUser(int userId); // Retrieves the last comment ID. Task LastCommentId(); diff --git a/WF_EF_Api/StubbedContextLib/StubWTFContext.cs b/WF_EF_Api/StubbedContextLib/StubWTFContext.cs index 8fda1c6..bd533d8 100644 --- a/WF_EF_Api/StubbedContextLib/StubWTFContext.cs +++ b/WF_EF_Api/StubbedContextLib/StubWTFContext.cs @@ -15,9 +15,9 @@ namespace StubbedContextLib { base.OnModelCreating(modelBuilder); - modelBuilder.Entity().HasData( + /*modelBuilder.Entity().HasData( new Admin() { IdUsers = 1 } - ); + );*/ modelBuilder.Entity().HasData( new Character() { Id = 1 , Name = "Alan Grant", IdImage = 1}, @@ -111,7 +111,7 @@ namespace StubbedContextLib new Quote() { Id = 10, Content = "La quoi ?", IdCharacter = 10 , IdSource = 4 , IdUsersPropose = 1, IsValid = true, Langage = LangEnum.vf, Likes = 11025 } ); - + modelBuilder.Entity().HasData( new Source() { Id = 1, Title = "Jurassic Park", TypeSrc = TypeSrcEnum.movie, Year = 1993 }, new Source() { Id = 2, Title = "Le Seigneur des anneaux : La Communauté de l'anneau", TypeSrc = TypeSrcEnum.movie, Year = 2001 }, From 502eba2552aad3e6aa19f4473373835ecc29a3e1 Mon Sep 17 00:00:00 2001 From: Kevin MONDEJAR Date: Fri, 14 Mar 2025 12:23:17 +0100 Subject: [PATCH 06/65] J'y suis presque --- WF_EF_Api/Contextlib/WTFContext.cs | 17 +- WF_EF_Api/Entity/Favorite.cs | 4 + WF_EF_Api/Entity/Question.cs | 2 +- WF_EF_Api/Entity/Quote.cs | 6 + ...0250312160314_myFirstMigration.Designer.cs | 205 ---- .../20250312160314_myFirstMigration.cs | 149 --- .../20250312162514_migr2.Designer.cs | 248 ---- .../Migrations/20250312162514_migr2.cs | 89 -- .../20250314112216_migrationTest1.Designer.cs | 1071 +++++++++++++++++ .../20250314112216_migrationTest1.cs | 501 ++++++++ .../Migrations/StubWTFContextModelSnapshot.cs | 885 +++++++++++++- WF_EF_Api/StubbedContextLib/StubWTFContext.cs | 97 +- 12 files changed, 2500 insertions(+), 774 deletions(-) delete mode 100644 WF_EF_Api/StubbedContextLib/Migrations/20250312160314_myFirstMigration.Designer.cs delete mode 100644 WF_EF_Api/StubbedContextLib/Migrations/20250312160314_myFirstMigration.cs delete mode 100644 WF_EF_Api/StubbedContextLib/Migrations/20250312162514_migr2.Designer.cs delete mode 100644 WF_EF_Api/StubbedContextLib/Migrations/20250312162514_migr2.cs create mode 100644 WF_EF_Api/StubbedContextLib/Migrations/20250314112216_migrationTest1.Designer.cs create mode 100644 WF_EF_Api/StubbedContextLib/Migrations/20250314112216_migrationTest1.cs diff --git a/WF_EF_Api/Contextlib/WTFContext.cs b/WF_EF_Api/Contextlib/WTFContext.cs index ad5e4e5..f98290d 100644 --- a/WF_EF_Api/Contextlib/WTFContext.cs +++ b/WF_EF_Api/Contextlib/WTFContext.cs @@ -14,7 +14,7 @@ namespace Contextlib public DbSet characters { get; set; } public DbSet comments { get; set; } public DbSet dailyquotes { get; set; } - //public DbSet favorites { get; set; } + public DbSet favorites { get; set; } public DbSet images { get; set; } public DbSet question { get; set; } public DbSet quizzes { get; set; } @@ -32,10 +32,19 @@ namespace Contextlib .HasMany(q => q.Favorite) .WithMany(u => u.Favorite) .UsingEntity( - l => l.HasOne().WithMany().HasForeignKey(q => q.IdQuote), - r => r.HasOne().WithMany().HasForeignKey(u => u.IdUsers) + l => l.HasOne(f => f.Quote) + .WithMany() + .HasForeignKey(f => f.IdQuote), + r => r.HasOne(f => f.Users) + .WithMany() + .HasForeignKey(f => f.IdUsers) ); + modelBuilder.Entity() + .HasMany(u => u.Quotes) + .WithOne(q => q.User) + .HasForeignKey(q => q.IdUsersPropose); + modelBuilder.Entity() .HasMany(q => q.Questions) .WithMany(u => u.Quizs) @@ -46,6 +55,6 @@ namespace Contextlib } protected override void OnConfiguring(DbContextOptionsBuilder options) - => options.UseSqlServer(@"Server=(localdb)\mssqllocaldb;Database=WfDatabase.mdf;Trusted_Connection=True;"); + => options.UseSqlServer(@"Server=(localdb)\mssqllocaldb;Database=Wf-Database.mdf;Trusted_Connection=True;"); } } diff --git a/WF_EF_Api/Entity/Favorite.cs b/WF_EF_Api/Entity/Favorite.cs index ec60347..06e1185 100644 --- a/WF_EF_Api/Entity/Favorite.cs +++ b/WF_EF_Api/Entity/Favorite.cs @@ -12,6 +12,10 @@ namespace Entity { public int IdUsers { get; set; } + public Users Users { get; set; } + public int IdQuote { get; set; } + + public Quote Quote { get; set; } } } diff --git a/WF_EF_Api/Entity/Question.cs b/WF_EF_Api/Entity/Question.cs index 036747d..b2e37e9 100644 --- a/WF_EF_Api/Entity/Question.cs +++ b/WF_EF_Api/Entity/Question.cs @@ -15,7 +15,7 @@ namespace Entity public int Id { get; set; } [Required] - [StringLength(50)] + [StringLength(200)] public string Text { get; set; } [Required] diff --git a/WF_EF_Api/Entity/Quote.cs b/WF_EF_Api/Entity/Quote.cs index e91cd13..976f62e 100644 --- a/WF_EF_Api/Entity/Quote.cs +++ b/WF_EF_Api/Entity/Quote.cs @@ -39,6 +39,12 @@ namespace Entity [ForeignKey(nameof(Users))] public int IdUsersPropose { get; set; } + public Users User { get; set; } = null!; + + public Source Source { get; set; } = null!; + + public Character Character { get; set; } = null!; + public ICollection DailyQuotes { get; set; } = new List(); public ICollection commentaries { get; set; } = new List(); diff --git a/WF_EF_Api/StubbedContextLib/Migrations/20250312160314_myFirstMigration.Designer.cs b/WF_EF_Api/StubbedContextLib/Migrations/20250312160314_myFirstMigration.Designer.cs deleted file mode 100644 index 516d42a..0000000 --- a/WF_EF_Api/StubbedContextLib/Migrations/20250312160314_myFirstMigration.Designer.cs +++ /dev/null @@ -1,205 +0,0 @@ -// -using System; -using Microsoft.EntityFrameworkCore; -using Microsoft.EntityFrameworkCore.Infrastructure; -using Microsoft.EntityFrameworkCore.Metadata; -using Microsoft.EntityFrameworkCore.Migrations; -using Microsoft.EntityFrameworkCore.Storage.ValueConversion; -using StubbedContextLib; - -#nullable disable - -namespace StubbedContextLib.Migrations -{ - [DbContext(typeof(StubWTFContext))] - [Migration("20250312160314_myFirstMigration")] - partial class myFirstMigration - { - /// - protected override void BuildTargetModel(ModelBuilder modelBuilder) - { -#pragma warning disable 612, 618 - modelBuilder - .HasAnnotation("ProductVersion", "9.0.3") - .HasAnnotation("Relational:MaxIdentifierLength", 128); - - SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder); - - modelBuilder.Entity("Entity.Character", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("int"); - - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); - - b.Property("Name") - .IsRequired() - .HasColumnType("nvarchar(max)"); - - b.HasKey("Id"); - - b.ToTable("Character"); - }); - - modelBuilder.Entity("Entity.Images", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("int"); - - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); - - b.Property("ImgPath") - .IsRequired() - .HasColumnType("nvarchar(max)"); - - b.HasKey("Id"); - - b.ToTable("Images"); - }); - - modelBuilder.Entity("Entity.Question", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("int"); - - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); - - b.Property("AnswerA") - .IsRequired() - .HasColumnType("nvarchar(max)"); - - b.Property("AnswerB") - .IsRequired() - .HasColumnType("nvarchar(max)"); - - b.Property("AnswerC") - .IsRequired() - .HasColumnType("nvarchar(max)"); - - b.Property("AnswerD") - .IsRequired() - .HasColumnType("nvarchar(max)"); - - b.Property("CorrectAnswer") - .IsRequired() - .HasColumnType("nvarchar(max)"); - - b.Property("Text") - .IsRequired() - .HasColumnType("nvarchar(max)"); - - b.HasKey("Id"); - - b.ToTable("Question"); - }); - - modelBuilder.Entity("Entity.Quiz", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("int"); - - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); - - b.Property("NbQuestion") - .HasColumnType("int"); - - b.Property("Title") - .IsRequired() - .HasColumnType("nvarchar(max)"); - - b.HasKey("Id"); - - b.ToTable("Quiz"); - }); - - modelBuilder.Entity("Entity.Quote", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("int"); - - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); - - b.Property("Content") - .IsRequired() - .HasColumnType("nvarchar(max)"); - - b.Property("IsValid") - .HasColumnType("bit"); - - b.Property("Langage") - .HasColumnType("int"); - - b.Property("Likes") - .HasColumnType("int"); - - b.HasKey("Id"); - - b.ToTable("Quote"); - }); - - modelBuilder.Entity("Entity.Source", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("int"); - - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); - - b.Property("Title") - .IsRequired() - .HasColumnType("nvarchar(max)"); - - b.Property("Year") - .HasColumnType("int"); - - b.HasKey("Id"); - - b.ToTable("Source"); - }); - - modelBuilder.Entity("Entity.Users", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("int"); - - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); - - b.Property("Created") - .HasColumnType("datetime2"); - - b.Property("Email") - .IsRequired() - .HasColumnType("nvarchar(max)"); - - b.Property("Password") - .IsRequired() - .HasColumnType("nvarchar(max)"); - - b.Property("UserName") - .IsRequired() - .HasColumnType("nvarchar(max)"); - - b.HasKey("Id"); - - b.ToTable("Users"); - - b.HasData( - new - { - Id = 1, - Created = new DateTime(2000, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified), - Email = "dev@gmail.com", - Password = "1234", - UserName = "Dev" - }); - }); -#pragma warning restore 612, 618 - } - } -} diff --git a/WF_EF_Api/StubbedContextLib/Migrations/20250312160314_myFirstMigration.cs b/WF_EF_Api/StubbedContextLib/Migrations/20250312160314_myFirstMigration.cs deleted file mode 100644 index 6fd3de5..0000000 --- a/WF_EF_Api/StubbedContextLib/Migrations/20250312160314_myFirstMigration.cs +++ /dev/null @@ -1,149 +0,0 @@ -using System; -using Microsoft.EntityFrameworkCore.Migrations; - -#nullable disable - -namespace StubbedContextLib.Migrations -{ - /// - public partial class myFirstMigration : Migration - { - /// - protected override void Up(MigrationBuilder migrationBuilder) - { - migrationBuilder.CreateTable( - name: "Character", - columns: table => new - { - Id = table.Column(type: "int", nullable: false) - .Annotation("SqlServer:Identity", "1, 1"), - Name = table.Column(type: "nvarchar(max)", nullable: false) - }, - constraints: table => - { - table.PrimaryKey("PK_Character", x => x.Id); - }); - - migrationBuilder.CreateTable( - name: "Images", - columns: table => new - { - Id = table.Column(type: "int", nullable: false) - .Annotation("SqlServer:Identity", "1, 1"), - ImgPath = table.Column(type: "nvarchar(max)", nullable: false) - }, - constraints: table => - { - table.PrimaryKey("PK_Images", x => x.Id); - }); - - migrationBuilder.CreateTable( - name: "Question", - columns: table => new - { - Id = table.Column(type: "int", nullable: false) - .Annotation("SqlServer:Identity", "1, 1"), - Text = table.Column(type: "nvarchar(max)", nullable: false), - AnswerA = table.Column(type: "nvarchar(max)", nullable: false), - AnswerB = table.Column(type: "nvarchar(max)", nullable: false), - AnswerC = table.Column(type: "nvarchar(max)", nullable: false), - AnswerD = table.Column(type: "nvarchar(max)", nullable: false), - CorrectAnswer = table.Column(type: "nvarchar(max)", nullable: false) - }, - constraints: table => - { - table.PrimaryKey("PK_Question", x => x.Id); - }); - - migrationBuilder.CreateTable( - name: "Quiz", - columns: table => new - { - Id = table.Column(type: "int", nullable: false) - .Annotation("SqlServer:Identity", "1, 1"), - Title = table.Column(type: "nvarchar(max)", nullable: false), - NbQuestion = table.Column(type: "int", nullable: false) - }, - constraints: table => - { - table.PrimaryKey("PK_Quiz", x => x.Id); - }); - - migrationBuilder.CreateTable( - name: "Quote", - columns: table => new - { - Id = table.Column(type: "int", nullable: false) - .Annotation("SqlServer:Identity", "1, 1"), - Content = table.Column(type: "nvarchar(max)", nullable: false), - Likes = table.Column(type: "int", nullable: false), - Langage = table.Column(type: "int", nullable: false), - IsValid = table.Column(type: "bit", nullable: false) - }, - constraints: table => - { - table.PrimaryKey("PK_Quote", x => x.Id); - }); - - migrationBuilder.CreateTable( - name: "Source", - columns: table => new - { - Id = table.Column(type: "int", nullable: false) - .Annotation("SqlServer:Identity", "1, 1"), - Title = table.Column(type: "nvarchar(max)", nullable: false), - Year = table.Column(type: "int", nullable: false) - }, - constraints: table => - { - table.PrimaryKey("PK_Source", x => x.Id); - }); - - migrationBuilder.CreateTable( - name: "Users", - columns: table => new - { - Id = table.Column(type: "int", nullable: false) - .Annotation("SqlServer:Identity", "1, 1"), - UserName = table.Column(type: "nvarchar(max)", nullable: false), - Email = table.Column(type: "nvarchar(max)", nullable: false), - Password = table.Column(type: "nvarchar(max)", nullable: false), - Created = table.Column(type: "datetime2", nullable: false) - }, - constraints: table => - { - table.PrimaryKey("PK_Users", x => x.Id); - }); - - migrationBuilder.InsertData( - table: "Users", - columns: new[] { "Id", "Created", "Email", "Password", "UserName" }, - values: new object[] { 1, new DateTime(2000, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified), "dev@gmail.com", "1234", "Dev" }); - } - - /// - protected override void Down(MigrationBuilder migrationBuilder) - { - migrationBuilder.DropTable( - name: "Character"); - - migrationBuilder.DropTable( - name: "Images"); - - migrationBuilder.DropTable( - name: "Question"); - - migrationBuilder.DropTable( - name: "Quiz"); - - migrationBuilder.DropTable( - name: "Quote"); - - migrationBuilder.DropTable( - name: "Source"); - - migrationBuilder.DropTable( - name: "Users"); - } - } -} diff --git a/WF_EF_Api/StubbedContextLib/Migrations/20250312162514_migr2.Designer.cs b/WF_EF_Api/StubbedContextLib/Migrations/20250312162514_migr2.Designer.cs deleted file mode 100644 index d84e486..0000000 --- a/WF_EF_Api/StubbedContextLib/Migrations/20250312162514_migr2.Designer.cs +++ /dev/null @@ -1,248 +0,0 @@ -// -using System; -using Microsoft.EntityFrameworkCore; -using Microsoft.EntityFrameworkCore.Infrastructure; -using Microsoft.EntityFrameworkCore.Metadata; -using Microsoft.EntityFrameworkCore.Migrations; -using Microsoft.EntityFrameworkCore.Storage.ValueConversion; -using StubbedContextLib; - -#nullable disable - -namespace StubbedContextLib.Migrations -{ - [DbContext(typeof(StubWTFContext))] - [Migration("20250312162514_migr2")] - partial class migr2 - { - /// - protected override void BuildTargetModel(ModelBuilder modelBuilder) - { -#pragma warning disable 612, 618 - modelBuilder - .HasAnnotation("ProductVersion", "9.0.3") - .HasAnnotation("Relational:MaxIdentifierLength", 128); - - SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder); - - modelBuilder.Entity("Entity.Character", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("int"); - - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); - - b.Property("Name") - .IsRequired() - .HasColumnType("nvarchar(max)"); - - b.HasKey("Id"); - - b.ToTable("Character"); - }); - - modelBuilder.Entity("Entity.Images", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("int"); - - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); - - b.Property("ImgPath") - .IsRequired() - .HasColumnType("nvarchar(max)"); - - b.HasKey("Id"); - - b.ToTable("Images"); - - b.HasData( - new - { - Id = 1, - ImgPath = "coucou" - }, - new - { - Id = 2, - ImgPath = "bonjour" - }); - }); - - modelBuilder.Entity("Entity.Question", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("int"); - - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); - - b.Property("AnswerA") - .IsRequired() - .HasColumnType("nvarchar(max)"); - - b.Property("AnswerB") - .IsRequired() - .HasColumnType("nvarchar(max)"); - - b.Property("AnswerC") - .IsRequired() - .HasColumnType("nvarchar(max)"); - - b.Property("AnswerD") - .IsRequired() - .HasColumnType("nvarchar(max)"); - - b.Property("CorrectAnswer") - .IsRequired() - .HasColumnType("nvarchar(max)"); - - b.Property("Text") - .IsRequired() - .HasColumnType("nvarchar(max)"); - - b.HasKey("Id"); - - b.ToTable("Question"); - }); - - modelBuilder.Entity("Entity.Quiz", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("int"); - - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); - - b.Property("NbQuestion") - .HasColumnType("int"); - - b.Property("Title") - .IsRequired() - .HasColumnType("nvarchar(max)"); - - b.HasKey("Id"); - - b.ToTable("Quiz"); - }); - - modelBuilder.Entity("Entity.Quote", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("int"); - - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); - - b.Property("Content") - .IsRequired() - .HasColumnType("nvarchar(max)"); - - b.Property("IsValid") - .HasColumnType("bit"); - - b.Property("Langage") - .HasColumnType("int"); - - b.Property("Likes") - .HasColumnType("int"); - - b.HasKey("Id"); - - b.ToTable("Quote"); - }); - - modelBuilder.Entity("Entity.Source", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("int"); - - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); - - b.Property("Title") - .IsRequired() - .HasColumnType("nvarchar(max)"); - - b.Property("Year") - .HasColumnType("int"); - - b.HasKey("Id"); - - b.ToTable("Source"); - }); - - modelBuilder.Entity("Entity.Users", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("int"); - - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); - - b.Property("Created") - .HasColumnType("datetime2"); - - b.Property("Email") - .IsRequired() - .HasColumnType("nvarchar(max)"); - - b.Property("IdImage") - .HasColumnType("int"); - - b.Property("Password") - .IsRequired() - .HasColumnType("nvarchar(max)"); - - b.Property("UserName") - .IsRequired() - .HasColumnType("nvarchar(max)"); - - b.HasKey("Id"); - - b.HasIndex("IdImage"); - - b.ToTable("Users"); - - b.HasData( - new - { - Id = 1, - Created = new DateTime(2000, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified), - Email = "dev@gmail.com", - IdImage = 1, - Password = "1234", - UserName = "Dev" - }, - new - { - Id = 2, - Created = new DateTime(2000, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified), - Email = "admin@gmail.com", - IdImage = 1, - Password = "1234", - UserName = "Admin" - }); - }); - - modelBuilder.Entity("Entity.Users", b => - { - b.HasOne("Entity.Images", "Images") - .WithMany("Users") - .HasForeignKey("IdImage") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.Navigation("Images"); - }); - - modelBuilder.Entity("Entity.Images", b => - { - b.Navigation("Users"); - }); -#pragma warning restore 612, 618 - } - } -} diff --git a/WF_EF_Api/StubbedContextLib/Migrations/20250312162514_migr2.cs b/WF_EF_Api/StubbedContextLib/Migrations/20250312162514_migr2.cs deleted file mode 100644 index 01e2609..0000000 --- a/WF_EF_Api/StubbedContextLib/Migrations/20250312162514_migr2.cs +++ /dev/null @@ -1,89 +0,0 @@ -using System; -using Microsoft.EntityFrameworkCore.Migrations; - -#nullable disable - -#pragma warning disable CA1814 // Prefer jagged arrays over multidimensional - -namespace StubbedContextLib.Migrations -{ - /// - public partial class migr2 : Migration - { - /// - protected override void Up(MigrationBuilder migrationBuilder) - { - migrationBuilder.AddColumn( - name: "IdImage", - table: "Users", - type: "int", - nullable: false, - defaultValue: 0); - - migrationBuilder.InsertData( - table: "Images", - columns: new[] { "Id", "ImgPath" }, - values: new object[,] - { - { 1, "coucou" }, - { 2, "bonjour" } - }); - - migrationBuilder.UpdateData( - table: "Users", - keyColumn: "Id", - keyValue: 1, - column: "IdImage", - value: 1); - - migrationBuilder.InsertData( - table: "Users", - columns: new[] { "Id", "Created", "Email", "IdImage", "Password", "UserName" }, - values: new object[] { 2, new DateTime(2000, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified), "admin@gmail.com", 1, "1234", "Admin" }); - - migrationBuilder.CreateIndex( - name: "IX_Users_IdImage", - table: "Users", - column: "IdImage"); - - migrationBuilder.AddForeignKey( - name: "FK_Users_Images_IdImage", - table: "Users", - column: "IdImage", - principalTable: "Images", - principalColumn: "Id", - onDelete: ReferentialAction.Cascade); - } - - /// - protected override void Down(MigrationBuilder migrationBuilder) - { - migrationBuilder.DropForeignKey( - name: "FK_Users_Images_IdImage", - table: "Users"); - - migrationBuilder.DropIndex( - name: "IX_Users_IdImage", - table: "Users"); - - migrationBuilder.DeleteData( - table: "Images", - keyColumn: "Id", - keyValue: 2); - - migrationBuilder.DeleteData( - table: "Users", - keyColumn: "Id", - keyValue: 2); - - migrationBuilder.DeleteData( - table: "Images", - keyColumn: "Id", - keyValue: 1); - - migrationBuilder.DropColumn( - name: "IdImage", - table: "Users"); - } - } -} diff --git a/WF_EF_Api/StubbedContextLib/Migrations/20250314112216_migrationTest1.Designer.cs b/WF_EF_Api/StubbedContextLib/Migrations/20250314112216_migrationTest1.Designer.cs new file mode 100644 index 0000000..d466b28 --- /dev/null +++ b/WF_EF_Api/StubbedContextLib/Migrations/20250314112216_migrationTest1.Designer.cs @@ -0,0 +1,1071 @@ +// +using System; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Metadata; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; +using StubbedContextLib; + +#nullable disable + +namespace StubbedContextLib.Migrations +{ + [DbContext(typeof(StubWTFContext))] + [Migration("20250314112216_migrationTest1")] + partial class migrationTest1 + { + /// + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("ProductVersion", "9.0.3") + .HasAnnotation("Relational:MaxIdentifierLength", 128); + + SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder); + + modelBuilder.Entity("Entity.Character", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("IdImage") + .HasColumnType("int"); + + b.Property("Name") + .IsRequired() + .HasMaxLength(50) + .HasColumnType("nvarchar(50)"); + + b.HasKey("Id"); + + b.HasIndex("IdImage"); + + b.ToTable("characters"); + + b.HasData( + new + { + Id = 1, + IdImage = 1, + Name = "Alan Grant" + }, + new + { + Id = 2, + IdImage = 2, + Name = "Aragorn" + }, + new + { + Id = 3, + IdImage = 3, + Name = "Legolas" + }, + new + { + Id = 4, + IdImage = 4, + Name = "Frodon" + }, + new + { + Id = 5, + IdImage = 5, + Name = "Dobby" + }, + new + { + Id = 6, + IdImage = 6, + Name = "Jon Snow" + }, + new + { + Id = 7, + IdImage = 7, + Name = "Daenerys Targaryen" + }, + new + { + Id = 8, + IdImage = 8, + Name = "Luke Skywalker" + }, + new + { + Id = 9, + IdImage = 9, + Name = "Princess Leia" + }, + new + { + Id = 10, + IdImage = 10, + Name = "Harry Potter" + }); + }); + + modelBuilder.Entity("Entity.Commentary", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("Comment") + .IsRequired() + .HasMaxLength(100) + .HasColumnType("nvarchar(100)"); + + b.Property("DateCommentary") + .HasColumnType("date") + .HasColumnName("DateCommentary"); + + b.Property("IdQuote") + .HasColumnType("int"); + + b.Property("IdUsers") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.HasIndex("IdQuote"); + + b.HasIndex("IdUsers"); + + b.ToTable("comments"); + + b.HasData( + new + { + Id = 1, + Comment = "Ce film est le meilleur", + DateCommentary = new DateTime(2025, 2, 3, 0, 0, 0, 0, DateTimeKind.Unspecified), + IdQuote = 1, + IdUsers = 2 + }, + new + { + Id = 2, + Comment = "Very good", + DateCommentary = new DateTime(2025, 3, 11, 0, 0, 0, 0, DateTimeKind.Unspecified), + IdQuote = 1, + IdUsers = 3 + }); + }); + + modelBuilder.Entity("Entity.DailyQuote", b => + { + b.Property("IdQuote") + .HasColumnType("int"); + + b.HasKey("IdQuote"); + + b.ToTable("dailyquotes"); + + b.HasData( + new + { + IdQuote = 1 + }, + new + { + IdQuote = 5 + }); + }); + + modelBuilder.Entity("Entity.Favorite", b => + { + b.Property("IdQuote") + .HasColumnType("int"); + + b.Property("IdUsers") + .HasColumnType("int"); + + b.HasKey("IdQuote", "IdUsers"); + + b.HasIndex("IdUsers"); + + b.ToTable("favorites"); + + b.HasData( + new + { + IdQuote = 2, + IdUsers = 8 + }, + new + { + IdQuote = 5, + IdUsers = 3 + }, + new + { + IdQuote = 9, + IdUsers = 1 + }, + new + { + IdQuote = 4, + IdUsers = 10 + }, + new + { + IdQuote = 3, + IdUsers = 2 + }, + new + { + IdQuote = 6, + IdUsers = 7 + }, + new + { + IdQuote = 1, + IdUsers = 6 + }, + new + { + IdQuote = 8, + IdUsers = 9 + }, + new + { + IdQuote = 10, + IdUsers = 5 + }); + }); + + modelBuilder.Entity("Entity.Images", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("ImgPath") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.HasKey("Id"); + + b.ToTable("images"); + + b.HasData( + new + { + Id = 1, + ImgPath = "https://th.bing.com/th/id/OIP.TJuWNCsibz8MVmhdNQEdMwHaE8?w=244&h=180&c=7&r=0&o=5&pid=1.7" + }, + new + { + Id = 2, + ImgPath = "https://th.bing.com/th/id/OIP.NgXRQ5-IknA6_qOPFhLWIwHaHK?w=165&h=180&c=7&r=0&o=5&pid=1.7" + }, + new + { + Id = 3, + ImgPath = "https://th.bing.com/th/id/OIP.XcJoJ6bC9sAMjol1pJn5UQHaLH?w=118&h=180&c=7&r=0&o=5&pid=1.7" + }, + new + { + Id = 4, + ImgPath = "https://th.bing.com/th/id/OIP.PPIESqZaNDa-qUcfSDXhdQHaGK?w=210&h=180&c=7&r=0&o=5&pid=1.7" + }, + new + { + Id = 5, + ImgPath = "https://th.bing.com/th/id/OIP.XBghSl2kfRNNtQoSxc901wHaHa?w=177&h=180&c=7&r=0&o=5&pid=1.7" + }, + new + { + Id = 6, + ImgPath = "https://th.bing.com/th/id/OIP.af1Aid64cqEKoIOBgCPxtQHaJO?w=145&h=182&c=7&r=0&o=5&pid=1.7" + }, + new + { + Id = 7, + ImgPath = "https://th.bing.com/th/id/OIP.ri5vSXr5lNTLt4DO6KQXyQHaI4?w=158&h=189&c=7&r=0&o=5&pid=1.7" + }, + new + { + Id = 8, + ImgPath = "https://th.bing.com/th/id/OIP.uPTRLR8uspCiafiunUqKfQHaMJ?w=115&h=180&c=7&r=0&o=5&pid=1.7" + }, + new + { + Id = 9, + ImgPath = "https://th.bing.com/th/id/OIP.hcJis4rKbyQtugsoFJU2ngHaM_?w=118&h=207&c=7&r=0&o=5&pid=1.7" + }, + new + { + Id = 10, + ImgPath = "https://th.bing.com/th/id/OIP.Py1_XfUrKJY_A6tYEmFS5wHaE8?w=280&h=187&c=7&r=0&o=5&pid=1.7" + }); + }); + + modelBuilder.Entity("Entity.Question", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("AnswerA") + .IsRequired() + .HasMaxLength(50) + .HasColumnType("nvarchar(50)"); + + b.Property("AnswerB") + .IsRequired() + .HasMaxLength(50) + .HasColumnType("nvarchar(50)"); + + b.Property("AnswerC") + .IsRequired() + .HasMaxLength(50) + .HasColumnType("nvarchar(50)"); + + b.Property("AnswerD") + .IsRequired() + .HasMaxLength(50) + .HasColumnType("nvarchar(50)"); + + b.Property("CorrectAnswer") + .IsRequired() + .HasMaxLength(1) + .HasColumnType("nvarchar(1)"); + + b.Property("Text") + .IsRequired() + .HasMaxLength(200) + .HasColumnType("nvarchar(200)"); + + b.HasKey("Id"); + + b.ToTable("question"); + + b.HasData( + new + { + Id = 1, + AnswerA = "Gimli", + AnswerB = "Aragorn", + AnswerC = "Frodon", + AnswerD = "Gandalf", + CorrectAnswer = "B", + Text = "Qui est le leader de la Communauté de l'Anneau ?" + }, + new + { + Id = 2, + AnswerA = "Serdaigle", + AnswerB = "Gryffondor", + AnswerC = "Serpentard", + AnswerD = "Poufsouffle", + CorrectAnswer = "B", + Text = "Dans quelle maison Harry Potter est-il ?" + }, + new + { + Id = 3, + AnswerA = "Saroumane", + AnswerB = "Sauron", + AnswerC = "Gollum", + AnswerD = "Gothmog", + CorrectAnswer = "B", + Text = "Qui est le Seigneur des Ténèbres dans la saga Le Seigneur des Anneaux ?" + }, + new + { + Id = 4, + AnswerA = "Han Solo", + AnswerB = "Princesse Leia", + AnswerC = "Chewbacca", + AnswerD = "R2-D2", + CorrectAnswer = "A", + Text = "Dans le film Star Wars : Episode IV, qui sauve Luke Skywalker de l'Étoile de la Mort ?" + }, + new + { + Id = 5, + AnswerA = "Reine Jadis", + AnswerB = "Aslan", + AnswerC = "Edmund", + AnswerD = "Lucy", + CorrectAnswer = "B", + Text = "Qui est le souverain de Narnia dans Le Lion, la Sorcière Blanche et l'Armoire Magique ?" + }, + new + { + Id = 6, + AnswerA = "Smaug", + AnswerB = "Falkor", + AnswerC = "Norbert", + AnswerD = "Shenron", + CorrectAnswer = "A", + Text = "Quel est le nom du dragon dans Le Hobbit ?" + }, + new + { + Id = 7, + AnswerA = "Bella Swan", + AnswerB = "Edward Cullen", + AnswerC = "Jacob Black", + AnswerD = "Victoria", + CorrectAnswer = "A", + Text = "Qui est la première personne à être mordue par un vampire dans Twilight ?" + }, + new + { + Id = 8, + AnswerA = "Obi-Wan Kenobi", + AnswerB = "Yoda", + AnswerC = "Han Solo", + AnswerD = "Luke Skywalker", + CorrectAnswer = "A", + Text = "Quel personnage dit Que la Force soit avec toi dans Star Wars ?" + }, + new + { + Id = 9, + AnswerA = "Dr. Ellie Sattler", + AnswerB = "Alan Grant", + AnswerC = "John Hammond", + AnswerD = "Dennis Nedry", + CorrectAnswer = "B", + Text = "Dans Jurassic Park, quel est le nom du paléontologue sur l'île ?" + }, + new + { + Id = 10, + AnswerA = "Cersei Lannister", + AnswerB = "Arya Stark", + AnswerC = "Daenerys Targaryen", + AnswerD = "Sansa Stark", + CorrectAnswer = "C", + Text = "Dans Game of Thrones, qui est surnommée la Mère des Dragons ?" + }); + }); + + modelBuilder.Entity("Entity.Quiz", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("IdImage") + .HasColumnType("int"); + + b.Property("NbQuestion") + .HasColumnType("int"); + + b.Property("Title") + .IsRequired() + .HasMaxLength(50) + .HasColumnType("nvarchar(50)"); + + b.HasKey("Id"); + + b.HasIndex("IdImage"); + + b.ToTable("quizzes"); + + b.HasData( + new + { + Id = 1, + IdImage = 1, + NbQuestion = 5, + Title = "Quiz 1" + }, + new + { + Id = 2, + IdImage = 2, + NbQuestion = 5, + Title = "Quiz 2" + }); + }); + + modelBuilder.Entity("Entity.QuizQuestion", b => + { + b.Property("IdQuestion") + .HasColumnType("int"); + + b.Property("IdQuiz") + .HasColumnType("int"); + + b.HasKey("IdQuestion", "IdQuiz"); + + b.HasIndex("IdQuiz"); + + b.ToTable("QuizQuestion"); + + b.HasData( + new + { + IdQuestion = 1, + IdQuiz = 1 + }, + new + { + IdQuestion = 2, + IdQuiz = 1 + }, + new + { + IdQuestion = 3, + IdQuiz = 1 + }, + new + { + IdQuestion = 4, + IdQuiz = 1 + }, + new + { + IdQuestion = 5, + IdQuiz = 1 + }, + new + { + IdQuestion = 6, + IdQuiz = 2 + }, + new + { + IdQuestion = 7, + IdQuiz = 2 + }, + new + { + IdQuestion = 8, + IdQuiz = 2 + }, + new + { + IdQuestion = 9, + IdQuiz = 2 + }, + new + { + IdQuestion = 10, + IdQuiz = 2 + }); + }); + + modelBuilder.Entity("Entity.Quote", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("Content") + .IsRequired() + .HasMaxLength(50) + .HasColumnType("nvarchar(50)"); + + b.Property("IdCharacter") + .HasColumnType("int"); + + b.Property("IdSource") + .HasColumnType("int"); + + b.Property("IdUsersPropose") + .HasColumnType("int"); + + b.Property("IsValid") + .HasColumnType("bit"); + + b.Property("Langage") + .HasColumnType("int"); + + b.Property("Likes") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.HasIndex("IdCharacter"); + + b.HasIndex("IdSource"); + + b.HasIndex("IdUsersPropose"); + + b.ToTable("quotes"); + + b.HasData( + new + { + Id = 1, + Content = "Je n'y crois pas. Je n'y crois pas. Ce n'est pas possible", + IdCharacter = 1, + IdSource = 1, + IdUsersPropose = 1, + IsValid = true, + Langage = 1, + Likes = 11025 + }, + new + { + Id = 2, + Content = "There is always hope", + IdCharacter = 2, + IdSource = 2, + IdUsersPropose = 1, + IsValid = true, + Langage = 0, + Likes = 11025 + }, + new + { + Id = 3, + Content = "A red sun rises. Blood has been spilled this night.", + IdCharacter = 3, + IdSource = 2, + IdUsersPropose = 1, + IsValid = true, + Langage = 0, + Likes = 11025 + }, + new + { + Id = 4, + Content = "I wish the Ring had never come to me.I wish none of this had happened.", + IdCharacter = 4, + IdSource = 2, + IdUsersPropose = 1, + IsValid = true, + Langage = 0, + Likes = 11025 + }, + new + { + Id = 5, + Content = "Dobby is a free elf!", + IdCharacter = 5, + IdSource = 4, + IdUsersPropose = 1, + IsValid = true, + Langage = 0, + Likes = 11025 + }, + new + { + Id = 6, + Content = "Winter is comming", + IdCharacter = 6, + IdSource = 3, + IdUsersPropose = 1, + IsValid = true, + Langage = 0, + Likes = 11025 + }, + new + { + Id = 7, + Content = "Je suis la dernière Targaryen. Je suis la reine des dragons", + IdCharacter = 7, + IdSource = 3, + IdUsersPropose = 1, + IsValid = true, + Langage = 1, + Likes = 11025 + }, + new + { + Id = 8, + Content = "Je ne suis pas prêt à affronter ça. C'est trop pour moi.", + IdCharacter = 8, + IdSource = 5, + IdUsersPropose = 1, + IsValid = true, + Langage = 1, + Likes = 11025 + }, + new + { + Id = 9, + Content = "Aidez-moi, Obi-Wan Kenobi, vous êtes mon seul espoir.", + IdCharacter = 9, + IdSource = 5, + IdUsersPropose = 1, + IsValid = true, + Langage = 1, + Likes = 11025 + }, + new + { + Id = 10, + Content = "La quoi ?", + IdCharacter = 10, + IdSource = 4, + IdUsersPropose = 1, + IsValid = true, + Langage = 1, + Likes = 11025 + }); + }); + + modelBuilder.Entity("Entity.Source", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("Title") + .IsRequired() + .HasMaxLength(50) + .HasColumnType("nvarchar(50)"); + + b.Property("TypeSrc") + .HasColumnType("int"); + + b.Property("Year") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.ToTable("sources"); + + b.HasData( + new + { + Id = 1, + Title = "Jurassic Park", + TypeSrc = 0, + Year = 1993 + }, + new + { + Id = 2, + Title = "Le Seigneur des anneaux : La Communauté de l'anneau", + TypeSrc = 0, + Year = 2001 + }, + new + { + Id = 3, + Title = "Game of throne", + TypeSrc = 1, + Year = 2011 + }, + new + { + Id = 4, + Title = "Harry Potter à l'école des sorcier", + TypeSrc = 0, + Year = 1997 + }, + new + { + Id = 5, + Title = "Star Wars, épisode IV : Un nouvel espoir", + TypeSrc = 0, + Year = 1977 + }); + }); + + modelBuilder.Entity("Entity.Users", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("Created") + .HasColumnType("date") + .HasColumnName("Created"); + + b.Property("Email") + .IsRequired() + .HasMaxLength(50) + .HasColumnType("nvarchar(50)"); + + b.Property("IdImage") + .HasColumnType("int"); + + b.Property("Password") + .IsRequired() + .HasMaxLength(200) + .HasColumnType("nvarchar(200)"); + + b.Property("UserName") + .IsRequired() + .HasMaxLength(50) + .HasColumnType("nvarchar(50)"); + + b.HasKey("Id"); + + b.HasIndex("IdImage"); + + b.ToTable("users"); + + b.HasData( + new + { + Id = 1, + Created = new DateTime(2025, 5, 12, 0, 0, 0, 0, DateTimeKind.Unspecified), + Email = "jhonDhoe@gmail.com", + IdImage = 1, + Password = "1234", + UserName = "Jhon-Dhoe" + }, + new + { + Id = 2, + Created = new DateTime(2025, 3, 19, 0, 0, 0, 0, DateTimeKind.Unspecified), + Email = "lucy_rose@outlook.com", + IdImage = 2, + Password = "abcd", + UserName = "Lucy-Rose" + }, + new + { + Id = 3, + Created = new DateTime(2024, 11, 2, 0, 0, 0, 0, DateTimeKind.Unspecified), + Email = "mark.taylor@yahoo.com", + IdImage = 3, + Password = "5678", + UserName = "Mark-Taylor" + }, + new + { + Id = 4, + Created = new DateTime(2025, 2, 28, 0, 0, 0, 0, DateTimeKind.Unspecified), + Email = "sophie.martin@gmail.com", + IdImage = 4, + Password = "4321", + UserName = "Sophie-Martin" + }, + new + { + Id = 5, + Created = new DateTime(2025, 1, 15, 0, 0, 0, 0, DateTimeKind.Unspecified), + Email = "nathan_doe@aol.com", + IdImage = 5, + Password = "8765", + UserName = "Nathan-Doe" + }, + new + { + Id = 6, + Created = new DateTime(2025, 4, 7, 0, 0, 0, 0, DateTimeKind.Unspecified), + Email = "ella.brown@icloud.com", + IdImage = 6, + Password = "2468", + UserName = "Ella-Brown" + }, + new + { + Id = 7, + Created = new DateTime(2024, 12, 25, 0, 0, 0, 0, DateTimeKind.Unspecified), + Email = "oliver_smith@gmail.com", + IdImage = 7, + Password = "1357", + UserName = "Oliver-Smith" + }, + new + { + Id = 8, + Created = new DateTime(2025, 3, 5, 0, 0, 0, 0, DateTimeKind.Unspecified), + Email = "mia.jones@outlook.com", + IdImage = 8, + Password = "1122", + UserName = "Mia-Jones" + }, + new + { + Id = 9, + Created = new DateTime(2025, 2, 22, 0, 0, 0, 0, DateTimeKind.Unspecified), + Email = "kevin_williams@aol.com", + IdImage = 9, + Password = "2233", + UserName = "Kevin-Williams" + }, + new + { + Id = 10, + Created = new DateTime(2025, 1, 3, 0, 0, 0, 0, DateTimeKind.Unspecified), + Email = "olivia.white@yahoo.com", + IdImage = 10, + Password = "3344", + UserName = "Olivia-White" + }); + }); + + modelBuilder.Entity("Entity.Character", b => + { + b.HasOne("Entity.Images", "Images") + .WithMany("Characters") + .HasForeignKey("IdImage") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Images"); + }); + + modelBuilder.Entity("Entity.Commentary", b => + { + b.HasOne("Entity.Quote", "Quote") + .WithMany("commentaries") + .HasForeignKey("IdQuote") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("Entity.Users", "Users") + .WithMany("Commentary") + .HasForeignKey("IdUsers") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Quote"); + + b.Navigation("Users"); + }); + + modelBuilder.Entity("Entity.DailyQuote", b => + { + b.HasOne("Entity.Quote", "Quote") + .WithMany("DailyQuotes") + .HasForeignKey("IdQuote") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Quote"); + }); + + modelBuilder.Entity("Entity.Favorite", b => + { + b.HasOne("Entity.Quote", "Quote") + .WithMany() + .HasForeignKey("IdQuote") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("Entity.Users", "Users") + .WithMany() + .HasForeignKey("IdUsers") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Quote"); + + b.Navigation("Users"); + }); + + modelBuilder.Entity("Entity.Quiz", b => + { + b.HasOne("Entity.Images", "Images") + .WithMany("Quizs") + .HasForeignKey("IdImage") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Images"); + }); + + modelBuilder.Entity("Entity.QuizQuestion", b => + { + b.HasOne("Entity.Question", null) + .WithMany() + .HasForeignKey("IdQuestion") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("Entity.Quiz", null) + .WithMany() + .HasForeignKey("IdQuiz") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("Entity.Quote", b => + { + b.HasOne("Entity.Character", "Character") + .WithMany("Quotes") + .HasForeignKey("IdCharacter") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("Entity.Source", "Source") + .WithMany("Quotes") + .HasForeignKey("IdSource") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("Entity.Users", "User") + .WithMany("Quotes") + .HasForeignKey("IdUsersPropose") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Character"); + + b.Navigation("Source"); + + b.Navigation("User"); + }); + + modelBuilder.Entity("Entity.Users", b => + { + b.HasOne("Entity.Images", "Images") + .WithMany("Users") + .HasForeignKey("IdImage") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Images"); + }); + + modelBuilder.Entity("Entity.Character", b => + { + b.Navigation("Quotes"); + }); + + modelBuilder.Entity("Entity.Images", b => + { + b.Navigation("Characters"); + + b.Navigation("Quizs"); + + b.Navigation("Users"); + }); + + modelBuilder.Entity("Entity.Quote", b => + { + b.Navigation("DailyQuotes"); + + b.Navigation("commentaries"); + }); + + modelBuilder.Entity("Entity.Source", b => + { + b.Navigation("Quotes"); + }); + + modelBuilder.Entity("Entity.Users", b => + { + b.Navigation("Commentary"); + + b.Navigation("Quotes"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/WF_EF_Api/StubbedContextLib/Migrations/20250314112216_migrationTest1.cs b/WF_EF_Api/StubbedContextLib/Migrations/20250314112216_migrationTest1.cs new file mode 100644 index 0000000..a85f30b --- /dev/null +++ b/WF_EF_Api/StubbedContextLib/Migrations/20250314112216_migrationTest1.cs @@ -0,0 +1,501 @@ +using System; +using Microsoft.EntityFrameworkCore.Migrations; + +#nullable disable + +#pragma warning disable CA1814 // Prefer jagged arrays over multidimensional + +namespace StubbedContextLib.Migrations +{ + /// + public partial class migrationTest1 : Migration + { + /// + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.CreateTable( + name: "images", + columns: table => new + { + Id = table.Column(type: "int", nullable: false) + .Annotation("SqlServer:Identity", "1, 1"), + ImgPath = table.Column(type: "nvarchar(max)", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_images", x => x.Id); + }); + + migrationBuilder.CreateTable( + name: "question", + columns: table => new + { + Id = table.Column(type: "int", nullable: false) + .Annotation("SqlServer:Identity", "1, 1"), + Text = table.Column(type: "nvarchar(200)", maxLength: 200, nullable: false), + AnswerA = table.Column(type: "nvarchar(50)", maxLength: 50, nullable: false), + AnswerB = table.Column(type: "nvarchar(50)", maxLength: 50, nullable: false), + AnswerC = table.Column(type: "nvarchar(50)", maxLength: 50, nullable: false), + AnswerD = table.Column(type: "nvarchar(50)", maxLength: 50, nullable: false), + CorrectAnswer = table.Column(type: "nvarchar(1)", maxLength: 1, nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_question", x => x.Id); + }); + + migrationBuilder.CreateTable( + name: "sources", + columns: table => new + { + Id = table.Column(type: "int", nullable: false) + .Annotation("SqlServer:Identity", "1, 1"), + Title = table.Column(type: "nvarchar(50)", maxLength: 50, nullable: false), + Year = table.Column(type: "int", nullable: false), + TypeSrc = table.Column(type: "int", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_sources", x => x.Id); + }); + + migrationBuilder.CreateTable( + name: "characters", + columns: table => new + { + Id = table.Column(type: "int", nullable: false) + .Annotation("SqlServer:Identity", "1, 1"), + Name = table.Column(type: "nvarchar(50)", maxLength: 50, nullable: false), + IdImage = table.Column(type: "int", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_characters", x => x.Id); + table.ForeignKey( + name: "FK_characters_images_IdImage", + column: x => x.IdImage, + principalTable: "images", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateTable( + name: "quizzes", + columns: table => new + { + Id = table.Column(type: "int", nullable: false) + .Annotation("SqlServer:Identity", "1, 1"), + Title = table.Column(type: "nvarchar(50)", maxLength: 50, nullable: false), + IdImage = table.Column(type: "int", nullable: false), + NbQuestion = table.Column(type: "int", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_quizzes", x => x.Id); + table.ForeignKey( + name: "FK_quizzes_images_IdImage", + column: x => x.IdImage, + principalTable: "images", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateTable( + name: "users", + columns: table => new + { + Id = table.Column(type: "int", nullable: false) + .Annotation("SqlServer:Identity", "1, 1"), + UserName = table.Column(type: "nvarchar(50)", maxLength: 50, nullable: false), + Email = table.Column(type: "nvarchar(50)", maxLength: 50, nullable: false), + Password = table.Column(type: "nvarchar(200)", maxLength: 200, nullable: false), + IdImage = table.Column(type: "int", nullable: false), + Created = table.Column(type: "date", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_users", x => x.Id); + table.ForeignKey( + name: "FK_users_images_IdImage", + column: x => x.IdImage, + principalTable: "images", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateTable( + name: "QuizQuestion", + columns: table => new + { + IdQuiz = table.Column(type: "int", nullable: false), + IdQuestion = table.Column(type: "int", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_QuizQuestion", x => new { x.IdQuestion, x.IdQuiz }); + table.ForeignKey( + name: "FK_QuizQuestion_question_IdQuestion", + column: x => x.IdQuestion, + principalTable: "question", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + table.ForeignKey( + name: "FK_QuizQuestion_quizzes_IdQuiz", + column: x => x.IdQuiz, + principalTable: "quizzes", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateTable( + name: "quotes", + columns: table => new + { + Id = table.Column(type: "int", nullable: false) + .Annotation("SqlServer:Identity", "1, 1"), + Content = table.Column(type: "nvarchar(50)", maxLength: 50, nullable: false), + Likes = table.Column(type: "int", nullable: false), + Langage = table.Column(type: "int", nullable: false), + IsValid = table.Column(type: "bit", nullable: false), + IdCharacter = table.Column(type: "int", nullable: false), + IdSource = table.Column(type: "int", nullable: false), + IdUsersPropose = table.Column(type: "int", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_quotes", x => x.Id); + table.ForeignKey( + name: "FK_quotes_characters_IdCharacter", + column: x => x.IdCharacter, + principalTable: "characters", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + table.ForeignKey( + name: "FK_quotes_sources_IdSource", + column: x => x.IdSource, + principalTable: "sources", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + table.ForeignKey( + name: "FK_quotes_users_IdUsersPropose", + column: x => x.IdUsersPropose, + principalTable: "users", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateTable( + name: "comments", + columns: table => new + { + Id = table.Column(type: "int", nullable: false) + .Annotation("SqlServer:Identity", "1, 1"), + IdUsers = table.Column(type: "int", nullable: false), + IdQuote = table.Column(type: "int", nullable: false), + DateCommentary = table.Column(type: "date", nullable: false), + Comment = table.Column(type: "nvarchar(100)", maxLength: 100, nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_comments", x => x.Id); + table.ForeignKey( + name: "FK_comments_quotes_IdQuote", + column: x => x.IdQuote, + principalTable: "quotes", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + table.ForeignKey( + name: "FK_comments_users_IdUsers", + column: x => x.IdUsers, + principalTable: "users", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateTable( + name: "dailyquotes", + columns: table => new + { + IdQuote = table.Column(type: "int", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_dailyquotes", x => x.IdQuote); + table.ForeignKey( + name: "FK_dailyquotes_quotes_IdQuote", + column: x => x.IdQuote, + principalTable: "quotes", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateTable( + name: "favorites", + columns: table => new + { + IdUsers = table.Column(type: "int", nullable: false), + IdQuote = table.Column(type: "int", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_favorites", x => new { x.IdQuote, x.IdUsers }); + table.ForeignKey( + name: "FK_favorites_quotes_IdQuote", + column: x => x.IdQuote, + principalTable: "quotes", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + table.ForeignKey( + name: "FK_favorites_users_IdUsers", + column: x => x.IdUsers, + principalTable: "users", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.InsertData( + table: "images", + columns: new[] { "Id", "ImgPath" }, + values: new object[,] + { + { 1, "https://th.bing.com/th/id/OIP.TJuWNCsibz8MVmhdNQEdMwHaE8?w=244&h=180&c=7&r=0&o=5&pid=1.7" }, + { 2, "https://th.bing.com/th/id/OIP.NgXRQ5-IknA6_qOPFhLWIwHaHK?w=165&h=180&c=7&r=0&o=5&pid=1.7" }, + { 3, "https://th.bing.com/th/id/OIP.XcJoJ6bC9sAMjol1pJn5UQHaLH?w=118&h=180&c=7&r=0&o=5&pid=1.7" }, + { 4, "https://th.bing.com/th/id/OIP.PPIESqZaNDa-qUcfSDXhdQHaGK?w=210&h=180&c=7&r=0&o=5&pid=1.7" }, + { 5, "https://th.bing.com/th/id/OIP.XBghSl2kfRNNtQoSxc901wHaHa?w=177&h=180&c=7&r=0&o=5&pid=1.7" }, + { 6, "https://th.bing.com/th/id/OIP.af1Aid64cqEKoIOBgCPxtQHaJO?w=145&h=182&c=7&r=0&o=5&pid=1.7" }, + { 7, "https://th.bing.com/th/id/OIP.ri5vSXr5lNTLt4DO6KQXyQHaI4?w=158&h=189&c=7&r=0&o=5&pid=1.7" }, + { 8, "https://th.bing.com/th/id/OIP.uPTRLR8uspCiafiunUqKfQHaMJ?w=115&h=180&c=7&r=0&o=5&pid=1.7" }, + { 9, "https://th.bing.com/th/id/OIP.hcJis4rKbyQtugsoFJU2ngHaM_?w=118&h=207&c=7&r=0&o=5&pid=1.7" }, + { 10, "https://th.bing.com/th/id/OIP.Py1_XfUrKJY_A6tYEmFS5wHaE8?w=280&h=187&c=7&r=0&o=5&pid=1.7" } + }); + + migrationBuilder.InsertData( + table: "question", + columns: new[] { "Id", "AnswerA", "AnswerB", "AnswerC", "AnswerD", "CorrectAnswer", "Text" }, + values: new object[,] + { + { 1, "Gimli", "Aragorn", "Frodon", "Gandalf", "B", "Qui est le leader de la Communauté de l'Anneau ?" }, + { 2, "Serdaigle", "Gryffondor", "Serpentard", "Poufsouffle", "B", "Dans quelle maison Harry Potter est-il ?" }, + { 3, "Saroumane", "Sauron", "Gollum", "Gothmog", "B", "Qui est le Seigneur des Ténèbres dans la saga Le Seigneur des Anneaux ?" }, + { 4, "Han Solo", "Princesse Leia", "Chewbacca", "R2-D2", "A", "Dans le film Star Wars : Episode IV, qui sauve Luke Skywalker de l'Étoile de la Mort ?" }, + { 5, "Reine Jadis", "Aslan", "Edmund", "Lucy", "B", "Qui est le souverain de Narnia dans Le Lion, la Sorcière Blanche et l'Armoire Magique ?" }, + { 6, "Smaug", "Falkor", "Norbert", "Shenron", "A", "Quel est le nom du dragon dans Le Hobbit ?" }, + { 7, "Bella Swan", "Edward Cullen", "Jacob Black", "Victoria", "A", "Qui est la première personne à être mordue par un vampire dans Twilight ?" }, + { 8, "Obi-Wan Kenobi", "Yoda", "Han Solo", "Luke Skywalker", "A", "Quel personnage dit Que la Force soit avec toi dans Star Wars ?" }, + { 9, "Dr. Ellie Sattler", "Alan Grant", "John Hammond", "Dennis Nedry", "B", "Dans Jurassic Park, quel est le nom du paléontologue sur l'île ?" }, + { 10, "Cersei Lannister", "Arya Stark", "Daenerys Targaryen", "Sansa Stark", "C", "Dans Game of Thrones, qui est surnommée la Mère des Dragons ?" } + }); + + migrationBuilder.InsertData( + table: "sources", + columns: new[] { "Id", "Title", "TypeSrc", "Year" }, + values: new object[,] + { + { 1, "Jurassic Park", 0, 1993 }, + { 2, "Le Seigneur des anneaux : La Communauté de l'anneau", 0, 2001 }, + { 3, "Game of throne", 1, 2011 }, + { 4, "Harry Potter à l'école des sorcier", 0, 1997 }, + { 5, "Star Wars, épisode IV : Un nouvel espoir", 0, 1977 } + }); + + migrationBuilder.InsertData( + table: "characters", + columns: new[] { "Id", "IdImage", "Name" }, + values: new object[,] + { + { 1, 1, "Alan Grant" }, + { 2, 2, "Aragorn" }, + { 3, 3, "Legolas" }, + { 4, 4, "Frodon" }, + { 5, 5, "Dobby" }, + { 6, 6, "Jon Snow" }, + { 7, 7, "Daenerys Targaryen" }, + { 8, 8, "Luke Skywalker" }, + { 9, 9, "Princess Leia" }, + { 10, 10, "Harry Potter" } + }); + + migrationBuilder.InsertData( + table: "quizzes", + columns: new[] { "Id", "IdImage", "NbQuestion", "Title" }, + values: new object[,] + { + { 1, 1, 5, "Quiz 1" }, + { 2, 2, 5, "Quiz 2" } + }); + + migrationBuilder.InsertData( + table: "users", + columns: new[] { "Id", "Created", "Email", "IdImage", "Password", "UserName" }, + values: new object[,] + { + { 1, new DateTime(2025, 5, 12, 0, 0, 0, 0, DateTimeKind.Unspecified), "jhonDhoe@gmail.com", 1, "1234", "Jhon-Dhoe" }, + { 2, new DateTime(2025, 3, 19, 0, 0, 0, 0, DateTimeKind.Unspecified), "lucy_rose@outlook.com", 2, "abcd", "Lucy-Rose" }, + { 3, new DateTime(2024, 11, 2, 0, 0, 0, 0, DateTimeKind.Unspecified), "mark.taylor@yahoo.com", 3, "5678", "Mark-Taylor" }, + { 4, new DateTime(2025, 2, 28, 0, 0, 0, 0, DateTimeKind.Unspecified), "sophie.martin@gmail.com", 4, "4321", "Sophie-Martin" }, + { 5, new DateTime(2025, 1, 15, 0, 0, 0, 0, DateTimeKind.Unspecified), "nathan_doe@aol.com", 5, "8765", "Nathan-Doe" }, + { 6, new DateTime(2025, 4, 7, 0, 0, 0, 0, DateTimeKind.Unspecified), "ella.brown@icloud.com", 6, "2468", "Ella-Brown" }, + { 7, new DateTime(2024, 12, 25, 0, 0, 0, 0, DateTimeKind.Unspecified), "oliver_smith@gmail.com", 7, "1357", "Oliver-Smith" }, + { 8, new DateTime(2025, 3, 5, 0, 0, 0, 0, DateTimeKind.Unspecified), "mia.jones@outlook.com", 8, "1122", "Mia-Jones" }, + { 9, new DateTime(2025, 2, 22, 0, 0, 0, 0, DateTimeKind.Unspecified), "kevin_williams@aol.com", 9, "2233", "Kevin-Williams" }, + { 10, new DateTime(2025, 1, 3, 0, 0, 0, 0, DateTimeKind.Unspecified), "olivia.white@yahoo.com", 10, "3344", "Olivia-White" } + }); + + migrationBuilder.InsertData( + table: "QuizQuestion", + columns: new[] { "IdQuestion", "IdQuiz" }, + values: new object[,] + { + { 1, 1 }, + { 2, 1 }, + { 3, 1 }, + { 4, 1 }, + { 5, 1 }, + { 6, 2 }, + { 7, 2 }, + { 8, 2 }, + { 9, 2 }, + { 10, 2 } + }); + + migrationBuilder.InsertData( + table: "quotes", + columns: new[] { "Id", "Content", "IdCharacter", "IdSource", "IdUsersPropose", "IsValid", "Langage", "Likes" }, + values: new object[,] + { + { 1, "Je n'y crois pas. Je n'y crois pas. Ce n'est pas possible", 1, 1, 1, true, 1, 11025 }, + { 2, "There is always hope", 2, 2, 1, true, 0, 11025 }, + { 3, "A red sun rises. Blood has been spilled this night.", 3, 2, 1, true, 0, 11025 }, + { 4, "I wish the Ring had never come to me.I wish none of this had happened.", 4, 2, 1, true, 0, 11025 }, + { 5, "Dobby is a free elf!", 5, 4, 1, true, 0, 11025 }, + { 6, "Winter is comming", 6, 3, 1, true, 0, 11025 }, + { 7, "Je suis la dernière Targaryen. Je suis la reine des dragons", 7, 3, 1, true, 1, 11025 }, + { 8, "Je ne suis pas prêt à affronter ça. C'est trop pour moi.", 8, 5, 1, true, 1, 11025 }, + { 9, "Aidez-moi, Obi-Wan Kenobi, vous êtes mon seul espoir.", 9, 5, 1, true, 1, 11025 }, + { 10, "La quoi ?", 10, 4, 1, true, 1, 11025 } + }); + + migrationBuilder.InsertData( + table: "comments", + columns: new[] { "Id", "Comment", "DateCommentary", "IdQuote", "IdUsers" }, + values: new object[,] + { + { 1, "Ce film est le meilleur", new DateTime(2025, 2, 3, 0, 0, 0, 0, DateTimeKind.Unspecified), 1, 2 }, + { 2, "Very good", new DateTime(2025, 3, 11, 0, 0, 0, 0, DateTimeKind.Unspecified), 1, 3 } + }); + + migrationBuilder.InsertData( + table: "dailyquotes", + column: "IdQuote", + values: new object[] + { + 1, + 5 + }); + + migrationBuilder.InsertData( + table: "favorites", + columns: new[] { "IdQuote", "IdUsers" }, + values: new object[,] + { + { 1, 6 }, + { 2, 8 }, + { 3, 2 }, + { 4, 10 }, + { 5, 3 }, + { 6, 7 }, + { 8, 9 }, + { 9, 1 }, + { 10, 5 } + }); + + migrationBuilder.CreateIndex( + name: "IX_characters_IdImage", + table: "characters", + column: "IdImage"); + + migrationBuilder.CreateIndex( + name: "IX_comments_IdQuote", + table: "comments", + column: "IdQuote"); + + migrationBuilder.CreateIndex( + name: "IX_comments_IdUsers", + table: "comments", + column: "IdUsers"); + + migrationBuilder.CreateIndex( + name: "IX_favorites_IdUsers", + table: "favorites", + column: "IdUsers"); + + migrationBuilder.CreateIndex( + name: "IX_QuizQuestion_IdQuiz", + table: "QuizQuestion", + column: "IdQuiz"); + + migrationBuilder.CreateIndex( + name: "IX_quizzes_IdImage", + table: "quizzes", + column: "IdImage"); + + migrationBuilder.CreateIndex( + name: "IX_quotes_IdCharacter", + table: "quotes", + column: "IdCharacter"); + + migrationBuilder.CreateIndex( + name: "IX_quotes_IdSource", + table: "quotes", + column: "IdSource"); + + migrationBuilder.CreateIndex( + name: "IX_quotes_IdUsersPropose", + table: "quotes", + column: "IdUsersPropose"); + + migrationBuilder.CreateIndex( + name: "IX_users_IdImage", + table: "users", + column: "IdImage"); + } + + /// + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropTable( + name: "comments"); + + migrationBuilder.DropTable( + name: "dailyquotes"); + + migrationBuilder.DropTable( + name: "favorites"); + + migrationBuilder.DropTable( + name: "QuizQuestion"); + + migrationBuilder.DropTable( + name: "quotes"); + + migrationBuilder.DropTable( + name: "question"); + + migrationBuilder.DropTable( + name: "quizzes"); + + migrationBuilder.DropTable( + name: "characters"); + + migrationBuilder.DropTable( + name: "sources"); + + migrationBuilder.DropTable( + name: "users"); + + migrationBuilder.DropTable( + name: "images"); + } + } +} diff --git a/WF_EF_Api/StubbedContextLib/Migrations/StubWTFContextModelSnapshot.cs b/WF_EF_Api/StubbedContextLib/Migrations/StubWTFContextModelSnapshot.cs index 4a848c7..21818ec 100644 --- a/WF_EF_Api/StubbedContextLib/Migrations/StubWTFContextModelSnapshot.cs +++ b/WF_EF_Api/StubbedContextLib/Migrations/StubWTFContextModelSnapshot.cs @@ -30,13 +30,213 @@ namespace StubbedContextLib.Migrations SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + b.Property("IdImage") + .HasColumnType("int"); + b.Property("Name") .IsRequired() - .HasColumnType("nvarchar(max)"); + .HasMaxLength(50) + .HasColumnType("nvarchar(50)"); + + b.HasKey("Id"); + + b.HasIndex("IdImage"); + + b.ToTable("characters"); + + b.HasData( + new + { + Id = 1, + IdImage = 1, + Name = "Alan Grant" + }, + new + { + Id = 2, + IdImage = 2, + Name = "Aragorn" + }, + new + { + Id = 3, + IdImage = 3, + Name = "Legolas" + }, + new + { + Id = 4, + IdImage = 4, + Name = "Frodon" + }, + new + { + Id = 5, + IdImage = 5, + Name = "Dobby" + }, + new + { + Id = 6, + IdImage = 6, + Name = "Jon Snow" + }, + new + { + Id = 7, + IdImage = 7, + Name = "Daenerys Targaryen" + }, + new + { + Id = 8, + IdImage = 8, + Name = "Luke Skywalker" + }, + new + { + Id = 9, + IdImage = 9, + Name = "Princess Leia" + }, + new + { + Id = 10, + IdImage = 10, + Name = "Harry Potter" + }); + }); + + modelBuilder.Entity("Entity.Commentary", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("Comment") + .IsRequired() + .HasMaxLength(100) + .HasColumnType("nvarchar(100)"); + + b.Property("DateCommentary") + .HasColumnType("date") + .HasColumnName("DateCommentary"); + + b.Property("IdQuote") + .HasColumnType("int"); + + b.Property("IdUsers") + .HasColumnType("int"); b.HasKey("Id"); - b.ToTable("Character"); + b.HasIndex("IdQuote"); + + b.HasIndex("IdUsers"); + + b.ToTable("comments"); + + b.HasData( + new + { + Id = 1, + Comment = "Ce film est le meilleur", + DateCommentary = new DateTime(2025, 2, 3, 0, 0, 0, 0, DateTimeKind.Unspecified), + IdQuote = 1, + IdUsers = 2 + }, + new + { + Id = 2, + Comment = "Very good", + DateCommentary = new DateTime(2025, 3, 11, 0, 0, 0, 0, DateTimeKind.Unspecified), + IdQuote = 1, + IdUsers = 3 + }); + }); + + modelBuilder.Entity("Entity.DailyQuote", b => + { + b.Property("IdQuote") + .HasColumnType("int"); + + b.HasKey("IdQuote"); + + b.ToTable("dailyquotes"); + + b.HasData( + new + { + IdQuote = 1 + }, + new + { + IdQuote = 5 + }); + }); + + modelBuilder.Entity("Entity.Favorite", b => + { + b.Property("IdQuote") + .HasColumnType("int"); + + b.Property("IdUsers") + .HasColumnType("int"); + + b.HasKey("IdQuote", "IdUsers"); + + b.HasIndex("IdUsers"); + + b.ToTable("favorites"); + + b.HasData( + new + { + IdQuote = 2, + IdUsers = 8 + }, + new + { + IdQuote = 5, + IdUsers = 3 + }, + new + { + IdQuote = 9, + IdUsers = 1 + }, + new + { + IdQuote = 4, + IdUsers = 10 + }, + new + { + IdQuote = 3, + IdUsers = 2 + }, + new + { + IdQuote = 6, + IdUsers = 7 + }, + new + { + IdQuote = 1, + IdUsers = 6 + }, + new + { + IdQuote = 8, + IdUsers = 9 + }, + new + { + IdQuote = 10, + IdUsers = 5 + }); }); modelBuilder.Entity("Entity.Images", b => @@ -53,18 +253,58 @@ namespace StubbedContextLib.Migrations b.HasKey("Id"); - b.ToTable("Images"); + b.ToTable("images"); b.HasData( new { Id = 1, - ImgPath = "coucou" + ImgPath = "https://th.bing.com/th/id/OIP.TJuWNCsibz8MVmhdNQEdMwHaE8?w=244&h=180&c=7&r=0&o=5&pid=1.7" }, new { Id = 2, - ImgPath = "bonjour" + ImgPath = "https://th.bing.com/th/id/OIP.NgXRQ5-IknA6_qOPFhLWIwHaHK?w=165&h=180&c=7&r=0&o=5&pid=1.7" + }, + new + { + Id = 3, + ImgPath = "https://th.bing.com/th/id/OIP.XcJoJ6bC9sAMjol1pJn5UQHaLH?w=118&h=180&c=7&r=0&o=5&pid=1.7" + }, + new + { + Id = 4, + ImgPath = "https://th.bing.com/th/id/OIP.PPIESqZaNDa-qUcfSDXhdQHaGK?w=210&h=180&c=7&r=0&o=5&pid=1.7" + }, + new + { + Id = 5, + ImgPath = "https://th.bing.com/th/id/OIP.XBghSl2kfRNNtQoSxc901wHaHa?w=177&h=180&c=7&r=0&o=5&pid=1.7" + }, + new + { + Id = 6, + ImgPath = "https://th.bing.com/th/id/OIP.af1Aid64cqEKoIOBgCPxtQHaJO?w=145&h=182&c=7&r=0&o=5&pid=1.7" + }, + new + { + Id = 7, + ImgPath = "https://th.bing.com/th/id/OIP.ri5vSXr5lNTLt4DO6KQXyQHaI4?w=158&h=189&c=7&r=0&o=5&pid=1.7" + }, + new + { + Id = 8, + ImgPath = "https://th.bing.com/th/id/OIP.uPTRLR8uspCiafiunUqKfQHaMJ?w=115&h=180&c=7&r=0&o=5&pid=1.7" + }, + new + { + Id = 9, + ImgPath = "https://th.bing.com/th/id/OIP.hcJis4rKbyQtugsoFJU2ngHaM_?w=118&h=207&c=7&r=0&o=5&pid=1.7" + }, + new + { + Id = 10, + ImgPath = "https://th.bing.com/th/id/OIP.Py1_XfUrKJY_A6tYEmFS5wHaE8?w=280&h=187&c=7&r=0&o=5&pid=1.7" }); }); @@ -78,31 +318,139 @@ namespace StubbedContextLib.Migrations b.Property("AnswerA") .IsRequired() - .HasColumnType("nvarchar(max)"); + .HasMaxLength(50) + .HasColumnType("nvarchar(50)"); b.Property("AnswerB") .IsRequired() - .HasColumnType("nvarchar(max)"); + .HasMaxLength(50) + .HasColumnType("nvarchar(50)"); b.Property("AnswerC") .IsRequired() - .HasColumnType("nvarchar(max)"); + .HasMaxLength(50) + .HasColumnType("nvarchar(50)"); b.Property("AnswerD") .IsRequired() - .HasColumnType("nvarchar(max)"); + .HasMaxLength(50) + .HasColumnType("nvarchar(50)"); b.Property("CorrectAnswer") .IsRequired() - .HasColumnType("nvarchar(max)"); + .HasMaxLength(1) + .HasColumnType("nvarchar(1)"); b.Property("Text") .IsRequired() - .HasColumnType("nvarchar(max)"); + .HasMaxLength(200) + .HasColumnType("nvarchar(200)"); b.HasKey("Id"); - b.ToTable("Question"); + b.ToTable("question"); + + b.HasData( + new + { + Id = 1, + AnswerA = "Gimli", + AnswerB = "Aragorn", + AnswerC = "Frodon", + AnswerD = "Gandalf", + CorrectAnswer = "B", + Text = "Qui est le leader de la Communauté de l'Anneau ?" + }, + new + { + Id = 2, + AnswerA = "Serdaigle", + AnswerB = "Gryffondor", + AnswerC = "Serpentard", + AnswerD = "Poufsouffle", + CorrectAnswer = "B", + Text = "Dans quelle maison Harry Potter est-il ?" + }, + new + { + Id = 3, + AnswerA = "Saroumane", + AnswerB = "Sauron", + AnswerC = "Gollum", + AnswerD = "Gothmog", + CorrectAnswer = "B", + Text = "Qui est le Seigneur des Ténèbres dans la saga Le Seigneur des Anneaux ?" + }, + new + { + Id = 4, + AnswerA = "Han Solo", + AnswerB = "Princesse Leia", + AnswerC = "Chewbacca", + AnswerD = "R2-D2", + CorrectAnswer = "A", + Text = "Dans le film Star Wars : Episode IV, qui sauve Luke Skywalker de l'Étoile de la Mort ?" + }, + new + { + Id = 5, + AnswerA = "Reine Jadis", + AnswerB = "Aslan", + AnswerC = "Edmund", + AnswerD = "Lucy", + CorrectAnswer = "B", + Text = "Qui est le souverain de Narnia dans Le Lion, la Sorcière Blanche et l'Armoire Magique ?" + }, + new + { + Id = 6, + AnswerA = "Smaug", + AnswerB = "Falkor", + AnswerC = "Norbert", + AnswerD = "Shenron", + CorrectAnswer = "A", + Text = "Quel est le nom du dragon dans Le Hobbit ?" + }, + new + { + Id = 7, + AnswerA = "Bella Swan", + AnswerB = "Edward Cullen", + AnswerC = "Jacob Black", + AnswerD = "Victoria", + CorrectAnswer = "A", + Text = "Qui est la première personne à être mordue par un vampire dans Twilight ?" + }, + new + { + Id = 8, + AnswerA = "Obi-Wan Kenobi", + AnswerB = "Yoda", + AnswerC = "Han Solo", + AnswerD = "Luke Skywalker", + CorrectAnswer = "A", + Text = "Quel personnage dit Que la Force soit avec toi dans Star Wars ?" + }, + new + { + Id = 9, + AnswerA = "Dr. Ellie Sattler", + AnswerB = "Alan Grant", + AnswerC = "John Hammond", + AnswerD = "Dennis Nedry", + CorrectAnswer = "B", + Text = "Dans Jurassic Park, quel est le nom du paléontologue sur l'île ?" + }, + new + { + Id = 10, + AnswerA = "Cersei Lannister", + AnswerB = "Arya Stark", + AnswerC = "Daenerys Targaryen", + AnswerD = "Sansa Stark", + CorrectAnswer = "C", + Text = "Dans Game of Thrones, qui est surnommée la Mère des Dragons ?" + }); }); modelBuilder.Entity("Entity.Quiz", b => @@ -113,16 +461,105 @@ namespace StubbedContextLib.Migrations SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + b.Property("IdImage") + .HasColumnType("int"); + b.Property("NbQuestion") .HasColumnType("int"); b.Property("Title") .IsRequired() - .HasColumnType("nvarchar(max)"); + .HasMaxLength(50) + .HasColumnType("nvarchar(50)"); b.HasKey("Id"); - b.ToTable("Quiz"); + b.HasIndex("IdImage"); + + b.ToTable("quizzes"); + + b.HasData( + new + { + Id = 1, + IdImage = 1, + NbQuestion = 5, + Title = "Quiz 1" + }, + new + { + Id = 2, + IdImage = 2, + NbQuestion = 5, + Title = "Quiz 2" + }); + }); + + modelBuilder.Entity("Entity.QuizQuestion", b => + { + b.Property("IdQuestion") + .HasColumnType("int"); + + b.Property("IdQuiz") + .HasColumnType("int"); + + b.HasKey("IdQuestion", "IdQuiz"); + + b.HasIndex("IdQuiz"); + + b.ToTable("QuizQuestion"); + + b.HasData( + new + { + IdQuestion = 1, + IdQuiz = 1 + }, + new + { + IdQuestion = 2, + IdQuiz = 1 + }, + new + { + IdQuestion = 3, + IdQuiz = 1 + }, + new + { + IdQuestion = 4, + IdQuiz = 1 + }, + new + { + IdQuestion = 5, + IdQuiz = 1 + }, + new + { + IdQuestion = 6, + IdQuiz = 2 + }, + new + { + IdQuestion = 7, + IdQuiz = 2 + }, + new + { + IdQuestion = 8, + IdQuiz = 2 + }, + new + { + IdQuestion = 9, + IdQuiz = 2 + }, + new + { + IdQuestion = 10, + IdQuiz = 2 + }); }); modelBuilder.Entity("Entity.Quote", b => @@ -135,7 +572,17 @@ namespace StubbedContextLib.Migrations b.Property("Content") .IsRequired() - .HasColumnType("nvarchar(max)"); + .HasMaxLength(50) + .HasColumnType("nvarchar(50)"); + + b.Property("IdCharacter") + .HasColumnType("int"); + + b.Property("IdSource") + .HasColumnType("int"); + + b.Property("IdUsersPropose") + .HasColumnType("int"); b.Property("IsValid") .HasColumnType("bit"); @@ -148,7 +595,125 @@ namespace StubbedContextLib.Migrations b.HasKey("Id"); - b.ToTable("Quote"); + b.HasIndex("IdCharacter"); + + b.HasIndex("IdSource"); + + b.HasIndex("IdUsersPropose"); + + b.ToTable("quotes"); + + b.HasData( + new + { + Id = 1, + Content = "Je n'y crois pas. Je n'y crois pas. Ce n'est pas possible", + IdCharacter = 1, + IdSource = 1, + IdUsersPropose = 1, + IsValid = true, + Langage = 1, + Likes = 11025 + }, + new + { + Id = 2, + Content = "There is always hope", + IdCharacter = 2, + IdSource = 2, + IdUsersPropose = 1, + IsValid = true, + Langage = 0, + Likes = 11025 + }, + new + { + Id = 3, + Content = "A red sun rises. Blood has been spilled this night.", + IdCharacter = 3, + IdSource = 2, + IdUsersPropose = 1, + IsValid = true, + Langage = 0, + Likes = 11025 + }, + new + { + Id = 4, + Content = "I wish the Ring had never come to me.I wish none of this had happened.", + IdCharacter = 4, + IdSource = 2, + IdUsersPropose = 1, + IsValid = true, + Langage = 0, + Likes = 11025 + }, + new + { + Id = 5, + Content = "Dobby is a free elf!", + IdCharacter = 5, + IdSource = 4, + IdUsersPropose = 1, + IsValid = true, + Langage = 0, + Likes = 11025 + }, + new + { + Id = 6, + Content = "Winter is comming", + IdCharacter = 6, + IdSource = 3, + IdUsersPropose = 1, + IsValid = true, + Langage = 0, + Likes = 11025 + }, + new + { + Id = 7, + Content = "Je suis la dernière Targaryen. Je suis la reine des dragons", + IdCharacter = 7, + IdSource = 3, + IdUsersPropose = 1, + IsValid = true, + Langage = 1, + Likes = 11025 + }, + new + { + Id = 8, + Content = "Je ne suis pas prêt à affronter ça. C'est trop pour moi.", + IdCharacter = 8, + IdSource = 5, + IdUsersPropose = 1, + IsValid = true, + Langage = 1, + Likes = 11025 + }, + new + { + Id = 9, + Content = "Aidez-moi, Obi-Wan Kenobi, vous êtes mon seul espoir.", + IdCharacter = 9, + IdSource = 5, + IdUsersPropose = 1, + IsValid = true, + Langage = 1, + Likes = 11025 + }, + new + { + Id = 10, + Content = "La quoi ?", + IdCharacter = 10, + IdSource = 4, + IdUsersPropose = 1, + IsValid = true, + Langage = 1, + Likes = 11025 + }); }); modelBuilder.Entity("Entity.Source", b => @@ -161,14 +726,55 @@ namespace StubbedContextLib.Migrations b.Property("Title") .IsRequired() - .HasColumnType("nvarchar(max)"); + .HasMaxLength(50) + .HasColumnType("nvarchar(50)"); + + b.Property("TypeSrc") + .HasColumnType("int"); b.Property("Year") .HasColumnType("int"); b.HasKey("Id"); - b.ToTable("Source"); + b.ToTable("sources"); + + b.HasData( + new + { + Id = 1, + Title = "Jurassic Park", + TypeSrc = 0, + Year = 1993 + }, + new + { + Id = 2, + Title = "Le Seigneur des anneaux : La Communauté de l'anneau", + TypeSrc = 0, + Year = 2001 + }, + new + { + Id = 3, + Title = "Game of throne", + TypeSrc = 1, + Year = 2011 + }, + new + { + Id = 4, + Title = "Harry Potter à l'école des sorcier", + TypeSrc = 0, + Year = 1997 + }, + new + { + Id = 5, + Title = "Star Wars, épisode IV : Un nouvel espoir", + TypeSrc = 0, + Year = 1977 + }); }); modelBuilder.Entity("Entity.Users", b => @@ -180,50 +786,239 @@ namespace StubbedContextLib.Migrations SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); b.Property("Created") - .HasColumnType("datetime2"); + .HasColumnType("date") + .HasColumnName("Created"); b.Property("Email") .IsRequired() - .HasColumnType("nvarchar(max)"); + .HasMaxLength(50) + .HasColumnType("nvarchar(50)"); b.Property("IdImage") .HasColumnType("int"); b.Property("Password") .IsRequired() - .HasColumnType("nvarchar(max)"); + .HasMaxLength(200) + .HasColumnType("nvarchar(200)"); b.Property("UserName") .IsRequired() - .HasColumnType("nvarchar(max)"); + .HasMaxLength(50) + .HasColumnType("nvarchar(50)"); b.HasKey("Id"); b.HasIndex("IdImage"); - b.ToTable("Users"); + b.ToTable("users"); b.HasData( new { Id = 1, - Created = new DateTime(2000, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified), - Email = "dev@gmail.com", + Created = new DateTime(2025, 5, 12, 0, 0, 0, 0, DateTimeKind.Unspecified), + Email = "jhonDhoe@gmail.com", IdImage = 1, Password = "1234", - UserName = "Dev" + UserName = "Jhon-Dhoe" }, new { Id = 2, - Created = new DateTime(2000, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified), - Email = "admin@gmail.com", - IdImage = 1, - Password = "1234", - UserName = "Admin" + Created = new DateTime(2025, 3, 19, 0, 0, 0, 0, DateTimeKind.Unspecified), + Email = "lucy_rose@outlook.com", + IdImage = 2, + Password = "abcd", + UserName = "Lucy-Rose" + }, + new + { + Id = 3, + Created = new DateTime(2024, 11, 2, 0, 0, 0, 0, DateTimeKind.Unspecified), + Email = "mark.taylor@yahoo.com", + IdImage = 3, + Password = "5678", + UserName = "Mark-Taylor" + }, + new + { + Id = 4, + Created = new DateTime(2025, 2, 28, 0, 0, 0, 0, DateTimeKind.Unspecified), + Email = "sophie.martin@gmail.com", + IdImage = 4, + Password = "4321", + UserName = "Sophie-Martin" + }, + new + { + Id = 5, + Created = new DateTime(2025, 1, 15, 0, 0, 0, 0, DateTimeKind.Unspecified), + Email = "nathan_doe@aol.com", + IdImage = 5, + Password = "8765", + UserName = "Nathan-Doe" + }, + new + { + Id = 6, + Created = new DateTime(2025, 4, 7, 0, 0, 0, 0, DateTimeKind.Unspecified), + Email = "ella.brown@icloud.com", + IdImage = 6, + Password = "2468", + UserName = "Ella-Brown" + }, + new + { + Id = 7, + Created = new DateTime(2024, 12, 25, 0, 0, 0, 0, DateTimeKind.Unspecified), + Email = "oliver_smith@gmail.com", + IdImage = 7, + Password = "1357", + UserName = "Oliver-Smith" + }, + new + { + Id = 8, + Created = new DateTime(2025, 3, 5, 0, 0, 0, 0, DateTimeKind.Unspecified), + Email = "mia.jones@outlook.com", + IdImage = 8, + Password = "1122", + UserName = "Mia-Jones" + }, + new + { + Id = 9, + Created = new DateTime(2025, 2, 22, 0, 0, 0, 0, DateTimeKind.Unspecified), + Email = "kevin_williams@aol.com", + IdImage = 9, + Password = "2233", + UserName = "Kevin-Williams" + }, + new + { + Id = 10, + Created = new DateTime(2025, 1, 3, 0, 0, 0, 0, DateTimeKind.Unspecified), + Email = "olivia.white@yahoo.com", + IdImage = 10, + Password = "3344", + UserName = "Olivia-White" }); }); + modelBuilder.Entity("Entity.Character", b => + { + b.HasOne("Entity.Images", "Images") + .WithMany("Characters") + .HasForeignKey("IdImage") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Images"); + }); + + modelBuilder.Entity("Entity.Commentary", b => + { + b.HasOne("Entity.Quote", "Quote") + .WithMany("commentaries") + .HasForeignKey("IdQuote") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("Entity.Users", "Users") + .WithMany("Commentary") + .HasForeignKey("IdUsers") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Quote"); + + b.Navigation("Users"); + }); + + modelBuilder.Entity("Entity.DailyQuote", b => + { + b.HasOne("Entity.Quote", "Quote") + .WithMany("DailyQuotes") + .HasForeignKey("IdQuote") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Quote"); + }); + + modelBuilder.Entity("Entity.Favorite", b => + { + b.HasOne("Entity.Quote", "Quote") + .WithMany() + .HasForeignKey("IdQuote") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("Entity.Users", "Users") + .WithMany() + .HasForeignKey("IdUsers") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Quote"); + + b.Navigation("Users"); + }); + + modelBuilder.Entity("Entity.Quiz", b => + { + b.HasOne("Entity.Images", "Images") + .WithMany("Quizs") + .HasForeignKey("IdImage") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Images"); + }); + + modelBuilder.Entity("Entity.QuizQuestion", b => + { + b.HasOne("Entity.Question", null) + .WithMany() + .HasForeignKey("IdQuestion") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("Entity.Quiz", null) + .WithMany() + .HasForeignKey("IdQuiz") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("Entity.Quote", b => + { + b.HasOne("Entity.Character", "Character") + .WithMany("Quotes") + .HasForeignKey("IdCharacter") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("Entity.Source", "Source") + .WithMany("Quotes") + .HasForeignKey("IdSource") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("Entity.Users", "User") + .WithMany("Quotes") + .HasForeignKey("IdUsersPropose") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Character"); + + b.Navigation("Source"); + + b.Navigation("User"); + }); + modelBuilder.Entity("Entity.Users", b => { b.HasOne("Entity.Images", "Images") @@ -235,10 +1030,38 @@ namespace StubbedContextLib.Migrations b.Navigation("Images"); }); + modelBuilder.Entity("Entity.Character", b => + { + b.Navigation("Quotes"); + }); + modelBuilder.Entity("Entity.Images", b => { + b.Navigation("Characters"); + + b.Navigation("Quizs"); + b.Navigation("Users"); }); + + modelBuilder.Entity("Entity.Quote", b => + { + b.Navigation("DailyQuotes"); + + b.Navigation("commentaries"); + }); + + modelBuilder.Entity("Entity.Source", b => + { + b.Navigation("Quotes"); + }); + + modelBuilder.Entity("Entity.Users", b => + { + b.Navigation("Commentary"); + + b.Navigation("Quotes"); + }); #pragma warning restore 612, 618 } } diff --git a/WF_EF_Api/StubbedContextLib/StubWTFContext.cs b/WF_EF_Api/StubbedContextLib/StubWTFContext.cs index bd533d8..6df9912 100644 --- a/WF_EF_Api/StubbedContextLib/StubWTFContext.cs +++ b/WF_EF_Api/StubbedContextLib/StubWTFContext.cs @@ -19,6 +19,32 @@ namespace StubbedContextLib new Admin() { IdUsers = 1 } );*/ + modelBuilder.Entity().HasData( + new Images() { Id = 1, ImgPath = "https://th.bing.com/th/id/OIP.TJuWNCsibz8MVmhdNQEdMwHaE8?w=244&h=180&c=7&r=0&o=5&pid=1.7" }, + new Images() { Id = 2, ImgPath = "https://th.bing.com/th/id/OIP.NgXRQ5-IknA6_qOPFhLWIwHaHK?w=165&h=180&c=7&r=0&o=5&pid=1.7" }, + new Images() { Id = 3, ImgPath = "https://th.bing.com/th/id/OIP.XcJoJ6bC9sAMjol1pJn5UQHaLH?w=118&h=180&c=7&r=0&o=5&pid=1.7" }, + new Images() { Id = 4, ImgPath = "https://th.bing.com/th/id/OIP.PPIESqZaNDa-qUcfSDXhdQHaGK?w=210&h=180&c=7&r=0&o=5&pid=1.7" }, + new Images() { Id = 5, ImgPath = "https://th.bing.com/th/id/OIP.XBghSl2kfRNNtQoSxc901wHaHa?w=177&h=180&c=7&r=0&o=5&pid=1.7" }, + new Images() { Id = 6, ImgPath = "https://th.bing.com/th/id/OIP.af1Aid64cqEKoIOBgCPxtQHaJO?w=145&h=182&c=7&r=0&o=5&pid=1.7" }, + new Images() { Id = 7, ImgPath = "https://th.bing.com/th/id/OIP.ri5vSXr5lNTLt4DO6KQXyQHaI4?w=158&h=189&c=7&r=0&o=5&pid=1.7" }, + new Images() { Id = 8, ImgPath = "https://th.bing.com/th/id/OIP.uPTRLR8uspCiafiunUqKfQHaMJ?w=115&h=180&c=7&r=0&o=5&pid=1.7" }, + new Images() { Id = 9, ImgPath = "https://th.bing.com/th/id/OIP.hcJis4rKbyQtugsoFJU2ngHaM_?w=118&h=207&c=7&r=0&o=5&pid=1.7" }, + new Images() { Id = 10, ImgPath = "https://th.bing.com/th/id/OIP.Py1_XfUrKJY_A6tYEmFS5wHaE8?w=280&h=187&c=7&r=0&o=5&pid=1.7" } + ); + + modelBuilder.Entity().HasData( + new Users() { Id = 1, Email = "jhonDhoe@gmail.com", Password = "1234", Created = new DateTime(2025, 5, 12), UserName = "Jhon-Dhoe", IdImage = 1 }, + new Users() { Id = 2, Email = "lucy_rose@outlook.com", Password = "abcd", Created = new DateTime(2025, 3, 19), UserName = "Lucy-Rose", IdImage = 2 }, + new Users() { Id = 3, Email = "mark.taylor@yahoo.com", Password = "5678", Created = new DateTime(2024, 11, 2), UserName = "Mark-Taylor", IdImage = 3 }, + new Users() { Id = 4, Email = "sophie.martin@gmail.com", Password = "4321", Created = new DateTime(2025, 2, 28), UserName = "Sophie-Martin", IdImage = 4 }, + new Users() { Id = 5, Email = "nathan_doe@aol.com", Password = "8765", Created = new DateTime(2025, 1, 15), UserName = "Nathan-Doe", IdImage = 5 }, + new Users() { Id = 6, Email = "ella.brown@icloud.com", Password = "2468", Created = new DateTime(2025, 4, 7), UserName = "Ella-Brown", IdImage = 6 }, + new Users() { Id = 7, Email = "oliver_smith@gmail.com", Password = "1357", Created = new DateTime(2024, 12, 25), UserName = "Oliver-Smith", IdImage = 7 }, + new Users() { Id = 8, Email = "mia.jones@outlook.com", Password = "1122", Created = new DateTime(2025, 3, 5), UserName = "Mia-Jones", IdImage = 8 }, + new Users() { Id = 9, Email = "kevin_williams@aol.com", Password = "2233", Created = new DateTime(2025, 2, 22), UserName = "Kevin-Williams", IdImage = 9 }, + new Users() { Id = 10, Email = "olivia.white@yahoo.com", Password = "3344", Created = new DateTime(2025, 1, 3), UserName = "Olivia-White", IdImage = 10 } + ); + modelBuilder.Entity().HasData( new Character() { Id = 1 , Name = "Alan Grant", IdImage = 1}, new Character() { Id = 2, Name = "Aragorn", IdImage = 2 }, @@ -32,6 +58,19 @@ namespace StubbedContextLib new Character() { Id = 10, Name = "Harry Potter", IdImage = 10 } ); + modelBuilder.Entity().HasData( + new Quote() { Id = 1, Content = "Je n'y crois pas. Je n'y crois pas. Ce n'est pas possible", IdCharacter = 1, IdSource = 1, IdUsersPropose = 1, IsValid = true, Langage = LangEnum.vf, Likes = 11025 }, + new Quote() { Id = 2, Content = "There is always hope", IdCharacter = 2, IdSource = 2, IdUsersPropose = 1, IsValid = true, Langage = LangEnum.vo, Likes = 11025 }, + new Quote() { Id = 3, Content = "A red sun rises. Blood has been spilled this night.", IdCharacter = 3, IdSource = 2, IdUsersPropose = 1, IsValid = true, Langage = LangEnum.vo, Likes = 11025 }, + new Quote() { Id = 4, Content = "I wish the Ring had never come to me.I wish none of this had happened.", IdCharacter = 4, IdSource = 2, IdUsersPropose = 1, IsValid = true, Langage = LangEnum.vo, Likes = 11025 }, + new Quote() { Id = 5, Content = "Dobby is a free elf!", IdCharacter = 5, IdSource = 4, IdUsersPropose = 1, IsValid = true, Langage = LangEnum.vo, Likes = 11025 }, + new Quote() { Id = 6, Content = "Winter is comming", IdCharacter = 6, IdSource = 3, IdUsersPropose = 1, IsValid = true, Langage = LangEnum.vo, Likes = 11025 }, + new Quote() { Id = 7, Content = "Je suis la dernière Targaryen. Je suis la reine des dragons", IdCharacter = 7, IdSource = 3, IdUsersPropose = 1, IsValid = true, Langage = LangEnum.vf, Likes = 11025 }, + new Quote() { Id = 8, Content = "Je ne suis pas prêt à affronter ça. C'est trop pour moi.", IdCharacter = 8, IdSource = 5, IdUsersPropose = 1, IsValid = true, Langage = LangEnum.vf, Likes = 11025 }, + new Quote() { Id = 9, Content = "Aidez-moi, Obi-Wan Kenobi, vous êtes mon seul espoir.", IdCharacter = 9, IdSource = 5, IdUsersPropose = 1, IsValid = true, Langage = LangEnum.vf, Likes = 11025 }, + new Quote() { Id = 10, Content = "La quoi ?", IdCharacter = 10, IdSource = 4, IdUsersPropose = 1, IsValid = true, Langage = LangEnum.vf, Likes = 11025 } + ); + modelBuilder.Entity().HasData( new Commentary() { Id = 1, Comment = "Ce film est le meilleur", DateCommentary = new DateTime(2025,2,3), IdQuote = 1, IdUsers = 2 }, new Commentary() { Id = 2, Comment = "Very good", DateCommentary = new DateTime(2025, 3, 11), IdQuote = 1, IdUsers = 3 } @@ -54,35 +93,24 @@ namespace StubbedContextLib new Favorite() { IdQuote = 10, IdUsers = 5 } ); - modelBuilder.Entity().HasData( - new Images() { Id = 1 , ImgPath = "https://th.bing.com/th/id/OIP.TJuWNCsibz8MVmhdNQEdMwHaE8?w=244&h=180&c=7&r=0&o=5&pid=1.7" }, - new Images() { Id = 2 , ImgPath = "https://th.bing.com/th/id/OIP.NgXRQ5-IknA6_qOPFhLWIwHaHK?w=165&h=180&c=7&r=0&o=5&pid=1.7" }, - new Images() { Id = 3 , ImgPath = "https://th.bing.com/th/id/OIP.XcJoJ6bC9sAMjol1pJn5UQHaLH?w=118&h=180&c=7&r=0&o=5&pid=1.7" }, - new Images() { Id = 4 , ImgPath = "https://th.bing.com/th/id/OIP.PPIESqZaNDa-qUcfSDXhdQHaGK?w=210&h=180&c=7&r=0&o=5&pid=1.7" }, - new Images() { Id = 5 , ImgPath = "https://th.bing.com/th/id/OIP.XBghSl2kfRNNtQoSxc901wHaHa?w=177&h=180&c=7&r=0&o=5&pid=1.7" }, - new Images() { Id = 6 , ImgPath = "https://th.bing.com/th/id/OIP.af1Aid64cqEKoIOBgCPxtQHaJO?w=145&h=182&c=7&r=0&o=5&pid=1.7" }, - new Images() { Id = 7 , ImgPath = "https://th.bing.com/th/id/OIP.ri5vSXr5lNTLt4DO6KQXyQHaI4?w=158&h=189&c=7&r=0&o=5&pid=1.7" }, - new Images() { Id = 8 , ImgPath = "https://th.bing.com/th/id/OIP.uPTRLR8uspCiafiunUqKfQHaMJ?w=115&h=180&c=7&r=0&o=5&pid=1.7" }, - new Images() { Id = 9 , ImgPath = "https://th.bing.com/th/id/OIP.hcJis4rKbyQtugsoFJU2ngHaM_?w=118&h=207&c=7&r=0&o=5&pid=1.7" }, - new Images() { Id = 10 , ImgPath = "https://th.bing.com/th/id/OIP.Py1_XfUrKJY_A6tYEmFS5wHaE8?w=280&h=187&c=7&r=0&o=5&pid=1.7" } - ); + modelBuilder.Entity().HasData( new Question() { Id = 1, Text = "Qui est le leader de la Communauté de l'Anneau ?", AnswerA = "Gimli", AnswerB = "Aragorn", AnswerC = "Frodon", AnswerD = "Gandalf", CorrectAnswer = "B" }, new Question() { Id = 2, Text = "Dans quelle maison Harry Potter est-il ?", AnswerA = "Serdaigle", AnswerB = "Gryffondor", AnswerC = "Serpentard", AnswerD = "Poufsouffle", CorrectAnswer = "B" }, - new Question() { Id = 3, Text = "Qui est le Seigneur des Ténèbres dans la saga 'Le Seigneur des Anneaux' ?", AnswerA = "Saroumane", AnswerB = "Sauron", AnswerC = "Gollum", AnswerD = "Gothmog", CorrectAnswer = "B" }, - new Question() { Id = 4, Text = "Dans le film 'Star Wars : Episode IV', qui sauve Luke Skywalker de l'Étoile de la Mort ?", AnswerA = "Han Solo", AnswerB = "Princesse Leia", AnswerC = "Chewbacca", AnswerD = "R2-D2", CorrectAnswer = "A" }, - new Question() { Id = 5, Text = "Qui est le souverain de Narnia dans 'Le Lion, la Sorcière Blanche et l'Armoire Magique' ?", AnswerA = "Reine Jadis", AnswerB = "Aslan", AnswerC = "Edmund", AnswerD = "Lucy", CorrectAnswer = "B" }, - new Question() { Id = 6, Text = "Quel est le nom du dragon dans 'Le Hobbit' ?", AnswerA = "Smaug", AnswerB = "Falkor", AnswerC = "Norbert", AnswerD = "Shenron", CorrectAnswer = "A" }, - new Question() { Id = 7, Text = "Qui est la première personne à être mordue par un vampire dans 'Twilight' ?", AnswerA = "Bella Swan", AnswerB = "Edward Cullen", AnswerC = "Jacob Black", AnswerD = "Victoria", CorrectAnswer = "A" }, - new Question() { Id = 8, Text = "Quel personnage dit 'Que la Force soit avec toi' dans 'Star Wars' ?", AnswerA = "Obi-Wan Kenobi", AnswerB = "Yoda", AnswerC = "Han Solo", AnswerD = "Luke Skywalker", CorrectAnswer = "A" }, - new Question() { Id = 9, Text = "Dans 'Jurassic Park', quel est le nom du paléontologue sur l'île ?", AnswerA = "Dr. Ellie Sattler", AnswerB = "Alan Grant", AnswerC = "John Hammond", AnswerD = "Dennis Nedry", CorrectAnswer = "B" }, - new Question() { Id = 10, Text = "Dans 'Game of Thrones', qui est surnommée la Mère des Dragons ?", AnswerA = "Cersei Lannister", AnswerB = "Arya Stark", AnswerC = "Daenerys Targaryen", AnswerD = "Sansa Stark", CorrectAnswer = "C" } + new Question() { Id = 3, Text = "Qui est le Seigneur des Ténèbres dans la saga Le Seigneur des Anneaux ?", AnswerA = "Saroumane", AnswerB = "Sauron", AnswerC = "Gollum", AnswerD = "Gothmog", CorrectAnswer = "B" }, + new Question() { Id = 4, Text = "Dans le film Star Wars : Episode IV, qui sauve Luke Skywalker de l'Étoile de la Mort ?", AnswerA = "Han Solo", AnswerB = "Princesse Leia", AnswerC = "Chewbacca", AnswerD = "R2-D2", CorrectAnswer = "A" }, + new Question() { Id = 5, Text = "Qui est le souverain de Narnia dans Le Lion, la Sorcière Blanche et l'Armoire Magique ?", AnswerA = "Reine Jadis", AnswerB = "Aslan", AnswerC = "Edmund", AnswerD = "Lucy", CorrectAnswer = "B" }, + new Question() { Id = 6, Text = "Quel est le nom du dragon dans Le Hobbit ?", AnswerA = "Smaug", AnswerB = "Falkor", AnswerC = "Norbert", AnswerD = "Shenron", CorrectAnswer = "A" }, + new Question() { Id = 7, Text = "Qui est la première personne à être mordue par un vampire dans Twilight ?", AnswerA = "Bella Swan", AnswerB = "Edward Cullen", AnswerC = "Jacob Black", AnswerD = "Victoria", CorrectAnswer = "A" }, + new Question() { Id = 8, Text = "Quel personnage dit Que la Force soit avec toi dans Star Wars ?", AnswerA = "Obi-Wan Kenobi", AnswerB = "Yoda", AnswerC = "Han Solo", AnswerD = "Luke Skywalker", CorrectAnswer = "A" }, + new Question() { Id = 9, Text = "Dans Jurassic Park, quel est le nom du paléontologue sur l'île ?", AnswerA = "Dr. Ellie Sattler", AnswerB = "Alan Grant", AnswerC = "John Hammond", AnswerD = "Dennis Nedry", CorrectAnswer = "B" }, + new Question() { Id = 10, Text = "Dans Game of Thrones, qui est surnommée la Mère des Dragons ?", AnswerA = "Cersei Lannister", AnswerB = "Arya Stark", AnswerC = "Daenerys Targaryen", AnswerD = "Sansa Stark", CorrectAnswer = "C" } ); modelBuilder.Entity().HasData( new Quiz() { Id = 1, IdImage = 1, Title = "Quiz 1", NbQuestion = 5 }, - new Quiz() { Id = 1, IdImage = 2, Title = "Quiz 2", NbQuestion = 5 } + new Quiz() { Id = 2, IdImage = 2, Title = "Quiz 2", NbQuestion = 5 } ); modelBuilder.Entity().HasData( @@ -98,20 +126,6 @@ namespace StubbedContextLib new QuizQuestion() { IdQuestion = 10, IdQuiz = 2 } ); - modelBuilder.Entity().HasData( - new Quote() { Id = 1, Content = "Je n'y crois pas. Je n'y crois pas. Ce n'est pas possible", IdCharacter = 1, IdSource = 1, IdUsersPropose = 1 , IsValid = true, Langage = LangEnum.vf, Likes = 11025}, - new Quote() { Id = 2, Content = "There is always hope", IdCharacter = 2, IdSource = 2, IdUsersPropose = 1, IsValid = true, Langage = LangEnum.vo, Likes = 11025 }, - new Quote() { Id = 3, Content = "A red sun rises. Blood has been spilled this night.", IdCharacter = 3, IdSource = 2, IdUsersPropose = 1, IsValid = true, Langage = LangEnum.vo, Likes = 11025 }, - new Quote() { Id = 4, Content = "I wish the Ring had never come to me.I wish none of this had happened.", IdCharacter = 4, IdSource = 2, IdUsersPropose = 1, IsValid = true, Langage = LangEnum.vo, Likes = 11025 }, - new Quote() { Id = 5, Content = "Dobby is a free elf!", IdCharacter = 5 , IdSource = 4 , IdUsersPropose = 1, IsValid = true, Langage = LangEnum.vo, Likes = 11025 }, - new Quote() { Id = 6, Content = "Winter is comming", IdCharacter = 6 , IdSource = 3, IdUsersPropose = 1, IsValid = true, Langage = LangEnum.vo, Likes = 11025 }, - new Quote() { Id = 7, Content = "Je suis la dernière Targaryen. Je suis la reine des dragons", IdCharacter = 7 , IdSource = 3, IdUsersPropose = 1, IsValid = true, Langage = LangEnum.vf, Likes = 11025 }, - new Quote() { Id = 8, Content = "Je ne suis pas prêt à affronter ça. C'est trop pour moi.", IdCharacter = 8 , IdSource = 5, IdUsersPropose = 1, IsValid = true, Langage = LangEnum.vf, Likes = 11025 }, - new Quote() { Id = 9, Content = "Aidez-moi, Obi-Wan Kenobi, vous êtes mon seul espoir.", IdCharacter = 9 , IdSource = 5, IdUsersPropose = 1, IsValid = true, Langage = LangEnum.vf, Likes = 11025 }, - new Quote() { Id = 10, Content = "La quoi ?", IdCharacter = 10 , IdSource = 4 , IdUsersPropose = 1, IsValid = true, Langage = LangEnum.vf, Likes = 11025 } - ); - - modelBuilder.Entity().HasData( new Source() { Id = 1, Title = "Jurassic Park", TypeSrc = TypeSrcEnum.movie, Year = 1993 }, new Source() { Id = 2, Title = "Le Seigneur des anneaux : La Communauté de l'anneau", TypeSrc = TypeSrcEnum.movie, Year = 2001 }, @@ -120,18 +134,7 @@ namespace StubbedContextLib new Source() { Id = 5, Title = "Star Wars, épisode IV : Un nouvel espoir", TypeSrc = TypeSrcEnum.movie, Year = 1977 } ); - modelBuilder.Entity().HasData( - new Users() { Id = 1, Email = "jhonDhoe@gmail.com", Password = "1234", Created = new DateTime(2025, 5, 12), UserName = "Jhon-Dhoe", IdImage = 1 }, - new Users() { Id = 2, Email = "lucy_rose@outlook.com", Password = "abcd", Created = new DateTime(2025, 3, 19), UserName = "Lucy-Rose", IdImage = 2 }, - new Users() { Id = 3, Email = "mark.taylor@yahoo.com", Password = "5678", Created = new DateTime(2024, 11, 2), UserName = "Mark-Taylor", IdImage = 3 }, - new Users() { Id = 4, Email = "sophie.martin@gmail.com", Password = "4321", Created = new DateTime(2025, 2, 28), UserName = "Sophie-Martin", IdImage = 4 }, - new Users() { Id = 5, Email = "nathan_doe@aol.com", Password = "8765", Created = new DateTime(2025, 1, 15), UserName = "Nathan-Doe", IdImage = 5 }, - new Users() { Id = 6, Email = "ella.brown@icloud.com", Password = "2468", Created = new DateTime(2025, 4, 7), UserName = "Ella-Brown", IdImage = 6 }, - new Users() { Id = 7, Email = "oliver_smith@gmail.com", Password = "1357", Created = new DateTime(2024, 12, 25), UserName = "Oliver-Smith", IdImage = 7 }, - new Users() { Id = 8, Email = "mia.jones@outlook.com", Password = "1122", Created = new DateTime(2025, 3, 5), UserName = "Mia-Jones", IdImage = 8 }, - new Users() { Id = 9, Email = "kevin_williams@aol.com", Password = "2233", Created = new DateTime(2025, 2, 22), UserName = "Kevin-Williams", IdImage = 9 }, - new Users() { Id = 10, Email = "olivia.white@yahoo.com", Password = "3344", Created = new DateTime(2025, 1, 3), UserName = "Olivia-White", IdImage = 10 } - ); + } From d8f941f8ecb00f7762c316098b2e34dcbb6d136b Mon Sep 17 00:00:00 2001 From: Kevin MONDEJAR Date: Fri, 14 Mar 2025 12:24:43 +0100 Subject: [PATCH 07/65] J'y suis presque (et bah non) --- WF_EF_Api/StubbedContextLib/StubbedContextLib.csproj | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/WF_EF_Api/StubbedContextLib/StubbedContextLib.csproj b/WF_EF_Api/StubbedContextLib/StubbedContextLib.csproj index 9a838f3..4ae6e1b 100644 --- a/WF_EF_Api/StubbedContextLib/StubbedContextLib.csproj +++ b/WF_EF_Api/StubbedContextLib/StubbedContextLib.csproj @@ -18,4 +18,8 @@ + + + + From 0a91cae33cc99d113589667bee96fde5c6e43a49 Mon Sep 17 00:00:00 2001 From: lebeaulato Date: Mon, 17 Mar 2025 15:26:49 +0100 Subject: [PATCH 08/65] =?UTF-8?q?API=20instanci=C3=A9e=20+=20route=20GET?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 3 + WF_EF_Api/DTO/CharacterDTO.cs | 15 ++ WF_EF_Api/DTO/CommentaryDTO.cs | 17 +++ WF_EF_Api/DTO/DTO.csproj | 9 ++ WF_EF_Api/DTO/FavoriteDTO.cs | 14 ++ WF_EF_Api/DTO/ImageDTO.cs | 14 ++ WF_EF_Api/DTO/QuestionDTO.cs | 19 +++ WF_EF_Api/DTO/QuizDTO.cs | 16 ++ WF_EF_Api/DTO/QuizQuestionDTO.cs | 14 ++ WF_EF_Api/DTO/QuoteDTO.cs | 21 +++ WF_EF_Api/DTO/ResultsDTO.cs | 16 ++ WF_EF_Api/DTO/SourceDTO.cs | 16 ++ WF_EF_Api/DTO/TypeSrcEnumDTO.cs | 16 ++ WF_EF_Api/DTO/UserDTO.cs | 12 ++ WF_EF_Api/StubApi/StubApi.csproj | 14 ++ WF_EF_Api/StubApi/UserService.cs | 108 ++++++++++++++ WF_EF_Api/WF_EF_Api.sln | 12 ++ .../WfApi/Controllers/UsersController.cs | 140 ++++++++++++++++++ .../Controllers/WeatherForecastController.cs | 33 ----- WF_EF_Api/WfApi/Program.cs | 31 +++- WF_EF_Api/WfApi/WfApi.csproj | 8 + 21 files changed, 514 insertions(+), 34 deletions(-) create mode 100644 WF_EF_Api/DTO/CharacterDTO.cs create mode 100644 WF_EF_Api/DTO/CommentaryDTO.cs create mode 100644 WF_EF_Api/DTO/DTO.csproj create mode 100644 WF_EF_Api/DTO/FavoriteDTO.cs create mode 100644 WF_EF_Api/DTO/ImageDTO.cs create mode 100644 WF_EF_Api/DTO/QuestionDTO.cs create mode 100644 WF_EF_Api/DTO/QuizDTO.cs create mode 100644 WF_EF_Api/DTO/QuizQuestionDTO.cs create mode 100644 WF_EF_Api/DTO/QuoteDTO.cs create mode 100644 WF_EF_Api/DTO/ResultsDTO.cs create mode 100644 WF_EF_Api/DTO/SourceDTO.cs create mode 100644 WF_EF_Api/DTO/TypeSrcEnumDTO.cs create mode 100644 WF_EF_Api/DTO/UserDTO.cs create mode 100644 WF_EF_Api/StubApi/StubApi.csproj create mode 100644 WF_EF_Api/StubApi/UserService.cs create mode 100644 WF_EF_Api/WfApi/Controllers/UsersController.cs delete mode 100644 WF_EF_Api/WfApi/Controllers/WeatherForecastController.cs diff --git a/README.md b/README.md index 94b08a7..81ae64e 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,5 @@ # WF-PmAPI +### Paquets +NSwag.AspNetCore + diff --git a/WF_EF_Api/DTO/CharacterDTO.cs b/WF_EF_Api/DTO/CharacterDTO.cs new file mode 100644 index 0000000..00d402c --- /dev/null +++ b/WF_EF_Api/DTO/CharacterDTO.cs @@ -0,0 +1,15 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace DTO +{ + public class CharacterDTO + { + public int Id { get; set; } + public string Name { get; set; } + public string imagePath { get; set; } + } +} diff --git a/WF_EF_Api/DTO/CommentaryDTO.cs b/WF_EF_Api/DTO/CommentaryDTO.cs new file mode 100644 index 0000000..b901f14 --- /dev/null +++ b/WF_EF_Api/DTO/CommentaryDTO.cs @@ -0,0 +1,17 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace DTO +{ + public class CommentaryDTO + { + public int Id { get; set; } + public string Comment { get; set; } + public DateTime Date { get; set; } + public string User { get; set; } + public string ImagePath { get; set; } + } +} diff --git a/WF_EF_Api/DTO/DTO.csproj b/WF_EF_Api/DTO/DTO.csproj new file mode 100644 index 0000000..bb23fb7 --- /dev/null +++ b/WF_EF_Api/DTO/DTO.csproj @@ -0,0 +1,9 @@ + + + + net8.0 + enable + enable + + + diff --git a/WF_EF_Api/DTO/FavoriteDTO.cs b/WF_EF_Api/DTO/FavoriteDTO.cs new file mode 100644 index 0000000..16173a4 --- /dev/null +++ b/WF_EF_Api/DTO/FavoriteDTO.cs @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace DTO +{ + public class FavoriteDTO + { + public int IdUser { get; set; } + public int IdQuote { get; set; } + } +} diff --git a/WF_EF_Api/DTO/ImageDTO.cs b/WF_EF_Api/DTO/ImageDTO.cs new file mode 100644 index 0000000..2037793 --- /dev/null +++ b/WF_EF_Api/DTO/ImageDTO.cs @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace DTO +{ + public class ImageDTO + { + public int IdImage { get; set; } + public string ImagePath { get; set; } + } +} diff --git a/WF_EF_Api/DTO/QuestionDTO.cs b/WF_EF_Api/DTO/QuestionDTO.cs new file mode 100644 index 0000000..cdf2fb1 --- /dev/null +++ b/WF_EF_Api/DTO/QuestionDTO.cs @@ -0,0 +1,19 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace DTO +{ + public class QuestionDTO + { + public int Id { get; set; } + public string Question { get; set; } + public string AnswerA { get; set; } + public string AnswerB { get; set; } + public string AnswerC { get; set; } + public string AnswerD { get; set; } + public string CorrectAnswer { get; set; } + } +} diff --git a/WF_EF_Api/DTO/QuizDTO.cs b/WF_EF_Api/DTO/QuizDTO.cs new file mode 100644 index 0000000..abdeb3a --- /dev/null +++ b/WF_EF_Api/DTO/QuizDTO.cs @@ -0,0 +1,16 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace DTO +{ + public class QuizDTO + { + public int Id { get; set; } + public int NbQuestion { get; set; } + public string ImagePath { get; set; } + public string Title { get; set; } + } +} diff --git a/WF_EF_Api/DTO/QuizQuestionDTO.cs b/WF_EF_Api/DTO/QuizQuestionDTO.cs new file mode 100644 index 0000000..fe5cf76 --- /dev/null +++ b/WF_EF_Api/DTO/QuizQuestionDTO.cs @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace DTO +{ + public class QuizQuestionDTO + { + public int IdQuestion { get; set; } + public int IdQuiz { get; set; } + } +} diff --git a/WF_EF_Api/DTO/QuoteDTO.cs b/WF_EF_Api/DTO/QuoteDTO.cs new file mode 100644 index 0000000..6d35842 --- /dev/null +++ b/WF_EF_Api/DTO/QuoteDTO.cs @@ -0,0 +1,21 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace DTO +{ + public class QuoteDTO + { + public int Id { get; set; } + public string Content { get; set; } + public string Character { get; set; } + public string ImagePath { get; set; } + public string TitleSource { get; set; } + public DateTime DateSource { get; set; } + public int Like { get; set; } + public string Langage { get; set; } + public TypeSrcEnumDTO Type { get; set; } + } +} diff --git a/WF_EF_Api/DTO/ResultsDTO.cs b/WF_EF_Api/DTO/ResultsDTO.cs new file mode 100644 index 0000000..de28b59 --- /dev/null +++ b/WF_EF_Api/DTO/ResultsDTO.cs @@ -0,0 +1,16 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace DTO +{ + public class ResultsDTO + { + public int IdQuiz { get; set; } + public int IdUser { get; set; } + public int Time { get; set; } + public int NbPoint { get; set; } + } +} diff --git a/WF_EF_Api/DTO/SourceDTO.cs b/WF_EF_Api/DTO/SourceDTO.cs new file mode 100644 index 0000000..9db4871 --- /dev/null +++ b/WF_EF_Api/DTO/SourceDTO.cs @@ -0,0 +1,16 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace DTO +{ + public class SourceDTO + { + public int Id { get; set; } + public string Title { get; set; } + public DateTime Date { get; set; } + public TypeSrcEnumDTO Type { get; set; } + } +} diff --git a/WF_EF_Api/DTO/TypeSrcEnumDTO.cs b/WF_EF_Api/DTO/TypeSrcEnumDTO.cs new file mode 100644 index 0000000..8d5049d --- /dev/null +++ b/WF_EF_Api/DTO/TypeSrcEnumDTO.cs @@ -0,0 +1,16 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace DTO +{ + public enum TypeSrcEnumDTO + { + movie, + serie, + book, + videogame + } +} diff --git a/WF_EF_Api/DTO/UserDTO.cs b/WF_EF_Api/DTO/UserDTO.cs new file mode 100644 index 0000000..672cde3 --- /dev/null +++ b/WF_EF_Api/DTO/UserDTO.cs @@ -0,0 +1,12 @@ +namespace DTO +{ + public class UserDTO + { + public int Id { get; set; } + public string Pseudo { get; set; } + public string Password { get; set; } + public string Email { get; set; } + public string Years { get; set; } + public string ImageProfil { get; set; } + } +} diff --git a/WF_EF_Api/StubApi/StubApi.csproj b/WF_EF_Api/StubApi/StubApi.csproj new file mode 100644 index 0000000..de86de5 --- /dev/null +++ b/WF_EF_Api/StubApi/StubApi.csproj @@ -0,0 +1,14 @@ + + + + net8.0 + enable + enable + + + + + + + + diff --git a/WF_EF_Api/StubApi/UserService.cs b/WF_EF_Api/StubApi/UserService.cs new file mode 100644 index 0000000..039d8ab --- /dev/null +++ b/WF_EF_Api/StubApi/UserService.cs @@ -0,0 +1,108 @@ +using Shared; +using DTO; +namespace StubApi +{ + public class UserService : IUserService + { + private readonly List _users; + + public UserService() + { + _users = new List + { + new UserDTO { Id = 1, Pseudo = "dev", Password = "1234", Email = "testeur@example.com", Years = "2023", ImageProfil = "https://image_profil_1" }, + new UserDTO { Id = 2, Pseudo = "admin", Password = "admin123", Email = "admin@example.com", Years = "2024", ImageProfil = "https://image_profil_2" }, + new UserDTO { Id = 3, Pseudo = "user123", Password = "password123", Email = "user123@example.com", Years = "2022", ImageProfil = "https://image_profil_3" }, + new UserDTO { Id = 4, Pseudo = "testuser", Password = "testpass", Email = "testuser@example.com", Years = "2025", ImageProfil = "https://image_profil_4" }, + new UserDTO { Id = 5, Pseudo = "johnDoe", Password = "john123", Email = "johndoe@example.com", Years = "2021", ImageProfil = "https://image_profil_5" }, + new UserDTO { Id = 6, Pseudo = "janedoe", Password = "jane123", Email = "janedoe@example.com", Years = "2023", ImageProfil = "https://image_profil_6" }, + new UserDTO { Id = 7, Pseudo = "mark_smith", Password = "mark1234", Email = "marks@example.com", Years = "2022", ImageProfil = "https://image_profil_7" }, + new UserDTO { Id = 8, Pseudo = "alice", Password = "alicepass", Email = "alice@example.com", Years = "2024", ImageProfil = "https://image_profil_8" }, + new UserDTO { Id = 9, Pseudo = "bob_lee", Password = "bob123", Email = "bob@example.com", Years = "2021", ImageProfil = "https://image_profil_9" }, + new UserDTO { Id = 10, Pseudo = "lucas", Password = "lucaspass", Email = "lucas@example.com", Years = "2023", ImageProfil = "https://image_profil_10" }, + new UserDTO { Id = 11, Pseudo = "emily", Password = "emily2024", Email = "emily@example.com", Years = "2022", ImageProfil = "https://image_profil_11" }, + new UserDTO { Id = 12, Pseudo = "chris", Password = "chris1234", Email = "chris@example.com", Years = "2024", ImageProfil = "https://image_profil_12" }, + new UserDTO { Id = 13, Pseudo = "susan", Password = "susan123", Email = "susan@example.com", Years = "2023", ImageProfil = "https://image_profil_13" }, + new UserDTO { Id = 14, Pseudo = "michael", Password = "michael2025", Email = "michael@example.com", Years = "2022", ImageProfil = "https://image_profil_14" }, + new UserDTO { Id = 15, Pseudo = "olivia", Password = "olivia2024", Email = "olivia@example.com", Years = "2024", ImageProfil = "https://image_profil_15" }, + new UserDTO { Id = 16, Pseudo = "david", Password = "david123", Email = "david@example.com", Years = "2021", ImageProfil = "https://image_profil_16" }, + new UserDTO { Id = 17, Pseudo = "laura", Password = "laura456", Email = "laura@example.com", Years = "2023", ImageProfil = "https://image_profil_17" }, + new UserDTO { Id = 18, Pseudo = "steve", Password = "steve789", Email = "steve@example.com", Years = "2022", ImageProfil = "https://image_profil_18" }, + new UserDTO { Id = 19, Pseudo = "tina", Password = "tina321", Email = "tina@example.com", Years = "2024", ImageProfil = "https://image_profil_19" }, + new UserDTO { Id = 20, Pseudo = "peter", Password = "peter123", Email = "peter@example.com", Years = "2025", ImageProfil = "https://image_profil_20" } + + }; + } + + public async Task AddUser(UserDTO user) + { + throw new NotImplementedException(); + } + + public async Task CountUser() + { + throw new NotImplementedException(); + } + + public async Task ExistEmail(string email) + { + throw new NotImplementedException(); + } + + public async Task ExistUsername(string username) + { + throw new NotImplementedException(); + } + + public async Task> GetAllUser() + { + return new PaginationResult(_users.Count,0,_users.Count, _users); + } + + public async Task GetHashPassword(string username) + { + return _users.FirstOrDefault(u => u.Pseudo == username).Password; + } + + public async Task GetLastUserId() + { + throw new NotImplementedException(); + } + + public async Task> GetSomeUser(int index, int pageSize) + { + return new PaginationResult(_users.Count, index, pageSize, _users.Skip(index* pageSize).Take(pageSize).ToList()); + } + + public async Task GetUserByEmail(string email) + { + return _users.FirstOrDefault(u => u.Email == email); + } + + public async Task GetUserById(int id) + { + return _users.FirstOrDefault(u => u.Id == id); + } + + + public async Task GetUserByUsername(string username) + { + return _users.FirstOrDefault(u => u.Pseudo == username); + } + + public async Task RemoveUser(int userId) + { + throw new NotImplementedException(); + } + + public async Task SetAdminRole(bool isAdmin) + { + throw new NotImplementedException(); + } + + public async Task UpdateUser(int userId, UserDTO user) + { + throw new NotImplementedException(); + } + } +} diff --git a/WF_EF_Api/WF_EF_Api.sln b/WF_EF_Api/WF_EF_Api.sln index 2b163b7..3942dd1 100644 --- a/WF_EF_Api/WF_EF_Api.sln +++ b/WF_EF_Api/WF_EF_Api.sln @@ -23,6 +23,10 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "WfApi", "WfApi\WfApi.csproj EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Model", "Model\Model.csproj", "{708875DC-7ED1-4FD1-9321-3E00B2E7709B}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "StubApi", "StubApi\StubApi.csproj", "{4C5F324C-28C3-4153-B402-A07B099C24C6}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DTO", "DTO\DTO.csproj", "{99F43B70-4143-4807-9EE7-B8A799B1E702}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -69,6 +73,14 @@ Global {708875DC-7ED1-4FD1-9321-3E00B2E7709B}.Debug|Any CPU.Build.0 = Debug|Any CPU {708875DC-7ED1-4FD1-9321-3E00B2E7709B}.Release|Any CPU.ActiveCfg = Release|Any CPU {708875DC-7ED1-4FD1-9321-3E00B2E7709B}.Release|Any CPU.Build.0 = Release|Any CPU + {4C5F324C-28C3-4153-B402-A07B099C24C6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {4C5F324C-28C3-4153-B402-A07B099C24C6}.Debug|Any CPU.Build.0 = Debug|Any CPU + {4C5F324C-28C3-4153-B402-A07B099C24C6}.Release|Any CPU.ActiveCfg = Release|Any CPU + {4C5F324C-28C3-4153-B402-A07B099C24C6}.Release|Any CPU.Build.0 = Release|Any CPU + {99F43B70-4143-4807-9EE7-B8A799B1E702}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {99F43B70-4143-4807-9EE7-B8A799B1E702}.Debug|Any CPU.Build.0 = Debug|Any CPU + {99F43B70-4143-4807-9EE7-B8A799B1E702}.Release|Any CPU.ActiveCfg = Release|Any CPU + {99F43B70-4143-4807-9EE7-B8A799B1E702}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/WF_EF_Api/WfApi/Controllers/UsersController.cs b/WF_EF_Api/WfApi/Controllers/UsersController.cs new file mode 100644 index 0000000..7fb0e56 --- /dev/null +++ b/WF_EF_Api/WfApi/Controllers/UsersController.cs @@ -0,0 +1,140 @@ +using DTO; +using Microsoft.AspNetCore.Http; +using Microsoft.AspNetCore.Mvc; +using Shared; +using System.Net; +namespace WfApi.Controllers +{ + [ApiController] + [Route("api/v1/users")] //Version API + + public class UsersController : ControllerBase + { + private readonly IUserService _user; + + private readonly ILogger _logger; + public UsersController(IUserService userService, ILogger logger) + { + _user = userService; + _logger = logger; + + } + + //===================================== ROUTE GET ===================================== + + [HttpGet("id/{id}")] // Indiquer que l'id est dans l'URL + public async Task Get(int id) + { + try + { + var result = _user.GetUserById(id); + + if(result.IsCompletedSuccessfully) + { + return await Task.FromResult(Ok(result)); + } + else + { + return NoContent(); + } + } + catch (Exception) + { + return StatusCode((int)HttpStatusCode.InternalServerError, new { message = "Internal Server Error" }); + } + } + + + [HttpGet("all")] // Indiquer que l'id est dans l'URL + public async Task GetAllUsers(int index =0, int count = 5) + { + try + { + var result = _user.GetSomeUser(index, count); + + if (result.IsCompletedSuccessfully) + { + return await Task.FromResult(Ok(result)); + } + else + { + return NoContent(); + } + } + catch (Exception) + { + return StatusCode((int)HttpStatusCode.InternalServerError, new { message = "Internal Server Error" }); + } + } + + + [HttpGet("hashpassword/{username}")] // Indiquer que l'id est dans l'URL + public async Task GetHashPassword(string username) + { + try + { + var result = _user.GetHashPassword(username); + + if (result.IsCompletedSuccessfully) + { + return await Task.FromResult(Ok(result)); + } + else + { + return NoContent(); + } + } + catch (Exception) + { + return StatusCode((int)HttpStatusCode.InternalServerError, new { message = "Internal Server Error" }); + } + } + + + [HttpGet("username/{username}")] // Indiquer que l'id est dans l'URL + public async Task GetUserByUsername(string username) + { + try + { + var result = _user.GetUserByUsername(username); + + if (result.IsCompletedSuccessfully) + { + return await Task.FromResult(Ok(result)); + } + else + { + return NoContent(); + } + } + catch (Exception) + { + return StatusCode((int)HttpStatusCode.InternalServerError, new { message = "Internal Server Error" }); + } + } + [HttpGet("email/{email}")] // Indiquer que l'id est dans l'URL + public async Task GetUserByEmail(string email) + { + try + { + var result = _user.GetUserByEmail(email); + + if (result.IsCompletedSuccessfully) + { + return await Task.FromResult(Ok(result)); + } + else + { + return NoContent(); + } + } + catch (Exception) + { + return StatusCode((int)HttpStatusCode.InternalServerError, new { message = "Internal Server Error" }); + } + } + + + + } +} diff --git a/WF_EF_Api/WfApi/Controllers/WeatherForecastController.cs b/WF_EF_Api/WfApi/Controllers/WeatherForecastController.cs deleted file mode 100644 index c618314..0000000 --- a/WF_EF_Api/WfApi/Controllers/WeatherForecastController.cs +++ /dev/null @@ -1,33 +0,0 @@ -using Microsoft.AspNetCore.Mvc; - -namespace WfApi.Controllers -{ - [ApiController] - [Route("[controller]")] - public class WeatherForecastController : ControllerBase - { - private static readonly string[] Summaries = new[] - { - "Freezing", "Bracing", "Chilly", "Cool", "Mild", "Warm", "Balmy", "Hot", "Sweltering", "Scorching" - }; - - private readonly ILogger _logger; - - public WeatherForecastController(ILogger logger) - { - _logger = logger; - } - - [HttpGet(Name = "GetWeatherForecast")] - public IEnumerable Get() - { - return Enumerable.Range(1, 5).Select(index => new WeatherForecast - { - Date = DateOnly.FromDateTime(DateTime.Now.AddDays(index)), - TemperatureC = Random.Shared.Next(-20, 55), - Summary = Summaries[Random.Shared.Next(Summaries.Length)] - }) - .ToArray(); - } - } -} diff --git a/WF_EF_Api/WfApi/Program.cs b/WF_EF_Api/WfApi/Program.cs index 15eacee..0e7d0a2 100644 --- a/WF_EF_Api/WfApi/Program.cs +++ b/WF_EF_Api/WfApi/Program.cs @@ -1,8 +1,37 @@ +using DTO; +using Shared; +using StubApi; + var builder = WebApplication.CreateBuilder(args); +builder.Services.AddScoped, UserService>(); // Add services to the container. builder.Services.AddControllers(); +builder.Services.AddOpenApiDocument(options => { + options.PostProcess = document => + { + document.Info = new NSwag.OpenApiInfo + { + Version = "v1", + Title = "WtfAPI", + Description = "What The Fantasy Site API", + TermsOfService = "", + Contact = new NSwag.OpenApiContact + { + Name = "The PM Mobile What The Fantasy team", + Url = "" + }, + License = new NSwag.OpenApiLicense + { + Name = "No license", + Url = "https://license.fr" + } + }; + }; +}); + + // Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle builder.Services.AddEndpointsApiExplorer(); builder.Services.AddSwaggerGen(); @@ -12,7 +41,7 @@ var app = builder.Build(); // Configure the HTTP request pipeline. if (app.Environment.IsDevelopment()) { - app.UseSwagger(); + app.UseOpenApi(); // Active la documentation OpenAPI app.UseSwaggerUI(); } diff --git a/WF_EF_Api/WfApi/WfApi.csproj b/WF_EF_Api/WfApi/WfApi.csproj index ff8c292..a68150a 100644 --- a/WF_EF_Api/WfApi/WfApi.csproj +++ b/WF_EF_Api/WfApi/WfApi.csproj @@ -6,11 +6,19 @@ enable 283a610b-b95e-4b09-af22-b7d3270a917d Linux + true + $(NoWarn);1591 + + + + + + From fdcf26413cc4cf64f13f4b63ad79eee5e9c739be Mon Sep 17 00:00:00 2001 From: lebeaulato Date: Mon, 17 Mar 2025 16:46:19 +0100 Subject: [PATCH 09/65] routes api fait, ne sauvegardent pas encore --- WF_EF_Api/Shared/IUserService.cs | 4 +- WF_EF_Api/StubApi/UserService.cs | 25 ++- .../WfApi/Controllers/UsersController.cs | 161 +++++++++++++++++- 3 files changed, 178 insertions(+), 12 deletions(-) diff --git a/WF_EF_Api/Shared/IUserService.cs b/WF_EF_Api/Shared/IUserService.cs index d8028ee..29fe4bf 100644 --- a/WF_EF_Api/Shared/IUserService.cs +++ b/WF_EF_Api/Shared/IUserService.cs @@ -35,11 +35,11 @@ namespace Shared // Updates the details of an existing user identified by 'userId'. // 'userId' is the ID of the user to be updated, and 'user' contains the new user data. - Task UpdateUser(int userId, TUser user); + Task UpdateUser(int userId, TUser user, TUser existingUser); // Removes a user from the system based on their unique identifier ('userId'). // 'userId' is the unique identifier of the user to be removed. - Task RemoveUser(int userId); + Task RemoveUser(TUser user); // Retrieves the hashed password for a given username. // 'username' is the username for which the password hash is to be retrieved. diff --git a/WF_EF_Api/StubApi/UserService.cs b/WF_EF_Api/StubApi/UserService.cs index 039d8ab..7fd167a 100644 --- a/WF_EF_Api/StubApi/UserService.cs +++ b/WF_EF_Api/StubApi/UserService.cs @@ -41,17 +41,19 @@ namespace StubApi public async Task CountUser() { - throw new NotImplementedException(); + return _users.Count; } public async Task ExistEmail(string email) { - throw new NotImplementedException(); + if (_users.FirstOrDefault(u => u.Email == email) == null) return false; + return true; } public async Task ExistUsername(string username) { - throw new NotImplementedException(); + if (_users.FirstOrDefault(u => u.Pseudo == username) == null) return false; + return true; } public async Task> GetAllUser() @@ -64,7 +66,7 @@ namespace StubApi return _users.FirstOrDefault(u => u.Pseudo == username).Password; } - public async Task GetLastUserId() + public async Task GetLastUserId() // JE VOIS PAS L'INTERET { throw new NotImplementedException(); } @@ -90,7 +92,7 @@ namespace StubApi return _users.FirstOrDefault(u => u.Pseudo == username); } - public async Task RemoveUser(int userId) + public async Task RemoveUser(UserDTO user) { throw new NotImplementedException(); } @@ -100,9 +102,18 @@ namespace StubApi throw new NotImplementedException(); } - public async Task UpdateUser(int userId, UserDTO user) + + + public async Task UpdateUser(int userId, UserDTO user, UserDTO existingUser) { - throw new NotImplementedException(); + + // Update users properties + existingUser.Pseudo = user.Pseudo; + existingUser.Password = user.Password; + existingUser.Email = user.Email; + existingUser.Years = user.Years; + existingUser.ImageProfil = user.ImageProfil; + return existingUser; } } } diff --git a/WF_EF_Api/WfApi/Controllers/UsersController.cs b/WF_EF_Api/WfApi/Controllers/UsersController.cs index 7fb0e56..a60300f 100644 --- a/WF_EF_Api/WfApi/Controllers/UsersController.cs +++ b/WF_EF_Api/WfApi/Controllers/UsersController.cs @@ -28,8 +28,8 @@ namespace WfApi.Controllers try { var result = _user.GetUserById(id); - - if(result.IsCompletedSuccessfully) + + if (result.IsCompletedSuccessfully) { return await Task.FromResult(Ok(result)); } @@ -46,7 +46,7 @@ namespace WfApi.Controllers [HttpGet("all")] // Indiquer que l'id est dans l'URL - public async Task GetAllUsers(int index =0, int count = 5) + public async Task GetAllUsers(int index = 0, int count = 5) { try { @@ -135,6 +135,161 @@ namespace WfApi.Controllers } + [HttpGet("countuser")] // Indiquer que l'id est dans l'URL + public async Task GetCountUser() + { + try + { + var result = _user.CountUser(); + + if (result.IsCompletedSuccessfully) + { + return await Task.FromResult(Ok(result)); + } + else + { + return NoContent(); + } + } + catch (Exception) + { + return StatusCode((int)HttpStatusCode.InternalServerError, new { message = "Internal Server Error" }); + } + } + + + + [HttpGet("existusername/{username}")] // Indiquer que l'id est dans l'URL + public async Task GetExistUsername(string username) + { + try + { + var result = _user.ExistUsername(username); + + if (result.IsCompletedSuccessfully) + { + return await Task.FromResult(Ok(result)); + } + else + { + return NoContent(); + } + } + catch (Exception) + { + return StatusCode((int)HttpStatusCode.InternalServerError, new { message = "Internal Server Error" }); + } + } + + + [HttpGet("existemail/{email}")] // Indiquer que l'id est dans l'URL + public async Task GetExistEmail(string email) + { + try + { + var result = _user.ExistEmail(email); + + if (result.IsCompletedSuccessfully) + { + return await Task.FromResult(Ok(result)); + } + else + { + return NoContent(); + } + } + catch (Exception) + { + return StatusCode((int)HttpStatusCode.InternalServerError, new { message = "Internal Server Error" }); + } + } + + //===================================== ROUTE PUT ===================================== + + + [HttpPut()] + public async Task UpdateUser([FromQuery] int id, [FromBody] UserDTO updateduser) + { + try + { + if (updateduser == null) + { + return BadRequest(new { message = "Player data is required." }); + } + + + var existingUser = _user.GetUserById(id).Result; + if (existingUser == null) + { + return NotFound(new { message = "Player not found." }); + } + + var result = _user.UpdateUser(id,updateduser,existingUser); + + return Ok(result); + } + catch (Exception ex) + { + return StatusCode((int)HttpStatusCode.InternalServerError, new { message = "Internal server error." }); + } + } + + + + //===================================== ROUTE POST ===================================== + + [HttpPost] + public async Task CreatePlayer([FromBody] UserDTO newUser) + { + try + { + if (newUser == null) + { + return BadRequest(new { message = "Les données du joueur sont requises." }); + } + + var existingPlayer = _user.GetUserById(newUser.Id).Result; + if (existingPlayer != null) + { + return Conflict(new { message = "Un utilisateur avec cet ID existe déjà." }); + } + + _user.AddUser(newUser); + + return CreatedAtAction(nameof(GetAllUsers), new { id = newUser.Id }, newUser); + } + catch (Exception ex) + { + return StatusCode((int)HttpStatusCode.InternalServerError, new { message = "Erreur interne du serveur." }); + } + } + + + + //===================================== ROUTE DELETE ===================================== + + [HttpDelete] // /api/v1/players?id=51 + public async Task DeletePlayer([FromQuery] int id) + { + try + { + + var existingPlayer = _user.GetUserById(id).Result; + if (existingPlayer == null) + { + return NotFound(new { message = "Player not found." }); + } + + _user.RemoveUser(existingPlayer); + + return Ok(new { message = $"Player {id} deleted successfully." }); + } + catch (Exception ex) + { + return StatusCode((int)HttpStatusCode.InternalServerError, new { message = "Internal server error." }); + } + } + } } From 6eaa80172be81e6be995a0d1121ad0a08a514189 Mon Sep 17 00:00:00 2001 From: lebeaulato Date: Mon, 17 Mar 2025 17:31:38 +0100 Subject: [PATCH 10/65] Controller de quote --- WF_EF_Api/DTO/QuoteDTO.cs | 4 +- WF_EF_Api/DTO/TypeLangageDTO.cs | 15 ++ WF_EF_Api/Shared/IQuoteService.cs | 2 +- WF_EF_Api/StubApi/QuoteService.cs | 136 ++++++++++++++++++ .../WfApi/Controllers/QuotesController.cs | 71 +++++++++ WF_EF_Api/WfApi/Program.cs | 3 +- 6 files changed, 227 insertions(+), 4 deletions(-) create mode 100644 WF_EF_Api/DTO/TypeLangageDTO.cs create mode 100644 WF_EF_Api/StubApi/QuoteService.cs create mode 100644 WF_EF_Api/WfApi/Controllers/QuotesController.cs diff --git a/WF_EF_Api/DTO/QuoteDTO.cs b/WF_EF_Api/DTO/QuoteDTO.cs index 6d35842..510fa30 100644 --- a/WF_EF_Api/DTO/QuoteDTO.cs +++ b/WF_EF_Api/DTO/QuoteDTO.cs @@ -13,9 +13,9 @@ namespace DTO public string Character { get; set; } public string ImagePath { get; set; } public string TitleSource { get; set; } - public DateTime DateSource { get; set; } + public int DateSource { get; set; } public int Like { get; set; } - public string Langage { get; set; } + public TypeLangageDTO Langage { get; set; } public TypeSrcEnumDTO Type { get; set; } } } diff --git a/WF_EF_Api/DTO/TypeLangageDTO.cs b/WF_EF_Api/DTO/TypeLangageDTO.cs new file mode 100644 index 0000000..1320c27 --- /dev/null +++ b/WF_EF_Api/DTO/TypeLangageDTO.cs @@ -0,0 +1,15 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace DTO +{ + public enum TypeLangageDTO + { + vo, + vf, + ve + } +} diff --git a/WF_EF_Api/Shared/IQuoteService.cs b/WF_EF_Api/Shared/IQuoteService.cs index 5a4e5e9..d9ece83 100644 --- a/WF_EF_Api/Shared/IQuoteService.cs +++ b/WF_EF_Api/Shared/IQuoteService.cs @@ -25,7 +25,7 @@ namespace Shared // Retrieves all available quotes but filtered by language. // 'lang' is a language code used to filter the quotes in the chosen language. - Task> GetAllQuoteLang(int lang); + Task> GetAllQuoteLang(int index, int pageSize, int lang); // Retrieves a page of quote suggestions based on the index (pagination) and language. // 'index' is the starting point for pagination diff --git a/WF_EF_Api/StubApi/QuoteService.cs b/WF_EF_Api/StubApi/QuoteService.cs new file mode 100644 index 0000000..d45e6b6 --- /dev/null +++ b/WF_EF_Api/StubApi/QuoteService.cs @@ -0,0 +1,136 @@ +using DTO; +using Shared; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace StubApi +{ + public class QuoteService : IQuoteService + { + private readonly List _quotes; + + public QuoteService() + { + _quotes = new List + { + new QuoteDTO{Id=1, Content="Que la force soit avec toi", Character="Obi-Wan", ImagePath="http://image1", TitleSource="Star Wars", DateSource=1977, Like=32, Langage=TypeLangageDTO.vo, Type=TypeSrcEnumDTO.movie}, + new QuoteDTO{Id=2, Content="Je suis ton père", Character="Darth Vader", ImagePath="http://image2", TitleSource="Star Wars", DateSource=1980, Like=120, Langage=TypeLangageDTO.vo, Type=TypeSrcEnumDTO.movie}, + new QuoteDTO{Id=3, Content="Que la vengeance commence", Character="Anakin Skywalker", ImagePath="http://image3", TitleSource="Star Wars: Episode III", DateSource=2005, Like=95, Langage=TypeLangageDTO.vo, Type=TypeSrcEnumDTO.movie}, + new QuoteDTO{Id=4, Content="J'adore l'odeur du napalm au matin", Character="Kilgore", ImagePath="http://image4", TitleSource="Apocalypse Now", DateSource=1979, Like=56, Langage=TypeLangageDTO.vo, Type=TypeSrcEnumDTO.movie}, + new QuoteDTO{Id=5, Content="Je suis Groot", Character="Groot", ImagePath="http://image5", TitleSource="Guardians of the Galaxy", DateSource=2014, Like=200, Langage=TypeLangageDTO.vo, Type=TypeSrcEnumDTO.movie}, + new QuoteDTO{Id=6, Content="La vie est un rêve", Character="Don Quichotte", ImagePath="http://image6", TitleSource="Don Quichotte", DateSource=1605, Like=34, Langage=TypeLangageDTO.vf, Type=TypeSrcEnumDTO.book}, + new QuoteDTO{Id=7, Content="To infinity and beyond!", Character="Buzz Lightyear", ImagePath="http://image7", TitleSource="Toy Story", DateSource=1995, Like=180, Langage=TypeLangageDTO.vo, Type=TypeSrcEnumDTO.movie}, + new QuoteDTO{Id=8, Content="Je ne suis pas un héros", Character="Bruce Wayne", ImagePath="http://image8", TitleSource="The Dark Knight", DateSource=2008, Like=250, Langage=TypeLangageDTO.vo, Type=TypeSrcEnumDTO.movie}, + new QuoteDTO{Id=9, Content="Je suis le maître du jeu", Character="Jigsaw", ImagePath="http://image9", TitleSource="Saw", DateSource=2004, Like=65, Langage=TypeLangageDTO.vo, Type=TypeSrcEnumDTO.movie}, + new QuoteDTO{Id=10, Content="Liberté, égalité, fraternité", Character="La devise de la France", ImagePath="http://image10", TitleSource="Révolution française", DateSource=1789, Like=300, Langage=TypeLangageDTO.vf, Type=TypeSrcEnumDTO.book}, + new QuoteDTO{Id=11, Content="Un petit pas pour l'homme, un grand pas pour l'humanité", Character="Neil Armstrong", ImagePath="http://image11", TitleSource="Moon landing", DateSource=1969, Like=500, Langage=TypeLangageDTO.vo, Type=TypeSrcEnumDTO.book}, + new QuoteDTO{Id=12, Content="C'est la vie", Character="Charles", ImagePath="http://image12", TitleSource="French Movie", DateSource=2013, Like=45, Langage=TypeLangageDTO.vf, Type=TypeSrcEnumDTO.movie}, + new QuoteDTO{Id=13, Content="Voici Johnny!", Character="Jack Torrance", ImagePath="http://image13", TitleSource="The Shining", DateSource=1980, Like=300, Langage=TypeLangageDTO.vo, Type=TypeSrcEnumDTO.movie}, + new QuoteDTO{Id=14, Content="Je suis un simple serveur", Character="Hannibal", ImagePath="http://image14", TitleSource="The Silence of the Lambs", DateSource=1991, Like=200, Langage=TypeLangageDTO.vo, Type=TypeSrcEnumDTO.movie}, + new QuoteDTO{Id=15, Content="N'attends pas le moment parfait, prends le moment et rends-le parfait", Character="Zig Ziglar", ImagePath="http://image15", TitleSource="Motivation", DateSource=1995, Like=150, Langage=TypeLangageDTO.vf, Type=TypeSrcEnumDTO.book}, + new QuoteDTO{Id=16, Content="Le seul vrai voyage est de changer de regard", Character="Marcel Proust", ImagePath="http://image16", TitleSource="À la recherche du temps perdu", DateSource=1913, Like=125, Langage=TypeLangageDTO.vf, Type=TypeSrcEnumDTO.book}, + new QuoteDTO{Id=17, Content="La force sera avec toi, toujours", Character="Obi-Wan Kenobi", ImagePath="http://image17", TitleSource="Star Wars: Episode IV", DateSource=1977, Like=320, Langage=TypeLangageDTO.vo, Type=TypeSrcEnumDTO.movie}, + new QuoteDTO{Id=18, Content="J'ai toujours rêvé d'être un gangster", Character="Henry Hill", ImagePath="http://image18", TitleSource="Goodfellas", DateSource=1990, Like=500, Langage=TypeLangageDTO.vo, Type=TypeSrcEnumDTO.movie}, + new QuoteDTO{Id=19, Content="Je vous ai compris", Character="De Gaulle", ImagePath="http://image19", TitleSource="Discours de Gaulle", DateSource=1958, Like=250, Langage=TypeLangageDTO.vf, Type=TypeSrcEnumDTO.book}, + new QuoteDTO{Id=20, Content="Courage, fuyons!", Character="Frédéric", ImagePath="http://image20", TitleSource="Le Pourceau", DateSource=1834, Like=75, Langage=TypeLangageDTO.vf, Type=TypeSrcEnumDTO.book} + }; + } + + public async Task AddQuote(QuoteDTO quote) + { + throw new NotImplementedException(); + } + + public async Task CountQuotes() + { + throw new NotImplementedException(); + } + + public async Task> GetAllQuote() + { + throw new NotImplementedException(); + } + + public async Task> GetAllQuoteLang(int index, int pageSize, int lang) + { + //TypeLangageDTO langageType = lang; + //var listQuote = _quotes.Find(q => q.Langage == langageType); + //return new PaginationResult(_quotes.Count, index, pageSize, _quotes.Skip(index * pageSize).Take(pageSize).ToList()); + throw new NotImplementedException(); + + } + + public async Task GetDayliQuote(int lang) + { + throw new NotImplementedException(); + } + + public async Task> GetFavorites(int index, int pageSize, int UserId) + { + throw new NotImplementedException(); + } + + public async Task> GetInvalidQuote(int index, int pageSize) + { + throw new NotImplementedException(); + } + + public async Task GetLastQuoteId() // JE VOIS PAS L'INTERET + { + throw new NotImplementedException(); + } + + public async Task GetQuoteById(int id) + { + return _quotes.FirstOrDefault(q => q.Id == id); + } + + public async Task> GetSomeQuote(int index, int pageSize) + { + return new PaginationResult(_quotes.Count, index, pageSize, _quotes.Skip(index * pageSize).Take(pageSize).ToList()); + } + + public async Task> GetSuggestions(int index, int pageSize, int lang) + { + throw new NotImplementedException(); + } + + public async Task> GetValidQuote(int index, int pageSize) + { + throw new NotImplementedException(); + } + + public async Task RemoveQuote(int quoteId) + { + throw new NotImplementedException(); + } + + public async Task> SearchByCharacter(string character, int index, int pageSize, int lang) + { + throw new NotImplementedException(); + } + + public async Task> SearchByContent(string content, int index, int pageSize, int lang) + { + throw new NotImplementedException(); + } + + public async Task> SearchBySource(string source, int index, int pageSize, int lang) + { + throw new NotImplementedException(); + } + + public async Task UpdateQuote(int quoteId, QuoteDTO quote) + { + throw new NotImplementedException(); + } + + public async Task ValidateQuote(int quoteId, bool isValidate) + { + throw new NotImplementedException(); + } + } +} diff --git a/WF_EF_Api/WfApi/Controllers/QuotesController.cs b/WF_EF_Api/WfApi/Controllers/QuotesController.cs new file mode 100644 index 0000000..0a50e01 --- /dev/null +++ b/WF_EF_Api/WfApi/Controllers/QuotesController.cs @@ -0,0 +1,71 @@ +using DTO; +using Microsoft.AspNetCore.Http; +using Microsoft.AspNetCore.Mvc; +using Shared; +using System.Net; + +namespace WfApi.Controllers +{ + [ApiController] + [Route("api/v1/quote")] //Version API + public class QuotesController : ControllerBase + { + private readonly IQuoteService _quote; + + private readonly ILogger _logger; + public QuotesController(IQuoteService quoteService, ILogger logger) + { + _quote = quoteService; + _logger = logger; + + } + + + + //===================================== ROUTE GET ===================================== + [HttpGet("id/{id}")] // Indiquer que l'id est dans l'URL + public async Task GetQuote(int id) + { + try + { + var result = _quote.GetQuoteById(id); + + if (result.IsCompletedSuccessfully) + { + return await Task.FromResult(Ok(result)); + } + else + { + return NoContent(); + } + } + catch (Exception) + { + return StatusCode((int)HttpStatusCode.InternalServerError, new { message = "Internal Server Error" }); + } + } + + + [HttpGet("all")] // Indiquer que l'id est dans l'URL + public async Task GetAllQuote(int index = 0, int count = 10) + { + try + { + var result = _quote.GetSomeQuote(index, count); + + if (result.IsCompletedSuccessfully) + { + return await Task.FromResult(Ok(result)); + } + else + { + return NoContent(); + } + } + catch (Exception) + { + return StatusCode((int)HttpStatusCode.InternalServerError, new { message = "Internal Server Error" }); + } + } + } +} diff --git a/WF_EF_Api/WfApi/Program.cs b/WF_EF_Api/WfApi/Program.cs index 0e7d0a2..5813f96 100644 --- a/WF_EF_Api/WfApi/Program.cs +++ b/WF_EF_Api/WfApi/Program.cs @@ -5,6 +5,7 @@ using StubApi; var builder = WebApplication.CreateBuilder(args); builder.Services.AddScoped, UserService>(); +builder.Services.AddScoped, QuoteService>(); // Add services to the container. builder.Services.AddControllers(); @@ -14,7 +15,7 @@ builder.Services.AddOpenApiDocument(options => { document.Info = new NSwag.OpenApiInfo { Version = "v1", - Title = "WtfAPI", + Title = "What The Fantasy's API", Description = "What The Fantasy Site API", TermsOfService = "", Contact = new NSwag.OpenApiContact From 8ccde0b1250ee9be57de1150dea4db852c5e0e90 Mon Sep 17 00:00:00 2001 From: kekentin Date: Mon, 17 Mar 2025 17:34:37 +0100 Subject: [PATCH 11/65] Build qui marche , verifier que la supretion / insertion / deplacement marche entre : - User/Commentary/Quote - User/Favorite/Quote --- WF_EF_Api/Contextlib/DbCommentaryManager.cs | 2 +- WF_EF_Api/Contextlib/WTFContext.cs | 21 ++++++ WF_EF_Api/Entity/Commentary.cs | 4 +- WF_EF_Api/Entity/Quote.cs | 13 ++-- WF_EF_Api/Entity/Source.cs | 2 +- WF_EF_Api/Entity/Users.cs | 2 - ...20250317163102_migrationTest1.Designer.cs} | 66 +++++++++---------- ...t1.cs => 20250317163102_migrationTest1.cs} | 39 +++++------ .../Migrations/StubWTFContextModelSnapshot.cs | 64 ++++++++---------- WF_EF_Api/StubbedContextLib/StubWTFContext.cs | 4 +- .../StubbedContextLib.csproj | 4 -- 11 files changed, 108 insertions(+), 113 deletions(-) rename WF_EF_Api/StubbedContextLib/Migrations/{20250314112216_migrationTest1.Designer.cs => 20250317163102_migrationTest1.Designer.cs} (94%) rename WF_EF_Api/StubbedContextLib/Migrations/{20250314112216_migrationTest1.cs => 20250317163102_migrationTest1.cs} (92%) diff --git a/WF_EF_Api/Contextlib/DbCommentaryManager.cs b/WF_EF_Api/Contextlib/DbCommentaryManager.cs index 85c7ac8..002082f 100644 --- a/WF_EF_Api/Contextlib/DbCommentaryManager.cs +++ b/WF_EF_Api/Contextlib/DbCommentaryManager.cs @@ -63,7 +63,7 @@ namespace Contextlib public async Task DeleteCommentForUser(int userId) { // Retrieve comments for the specific userId - var comments = await _context.comments.Where(x => x.IdUsers == userId).ToListAsync(); + var comments = await _context.comments.Where(x => x.IdUser == userId).ToListAsync(); if (!comments.Any()) // If no comments exist for this userId { throw new KeyNotFoundException($"No comments found for the user ID: {userId}."); diff --git a/WF_EF_Api/Contextlib/WTFContext.cs b/WF_EF_Api/Contextlib/WTFContext.cs index f98290d..e0f0a31 100644 --- a/WF_EF_Api/Contextlib/WTFContext.cs +++ b/WF_EF_Api/Contextlib/WTFContext.cs @@ -34,17 +34,38 @@ namespace Contextlib .UsingEntity( l => l.HasOne(f => f.Quote) .WithMany() + .OnDelete(DeleteBehavior.ClientCascade) .HasForeignKey(f => f.IdQuote), r => r.HasOne(f => f.Users) .WithMany() + .OnDelete(DeleteBehavior.ClientCascade) .HasForeignKey(f => f.IdUsers) ); modelBuilder.Entity() .HasMany(u => u.Quotes) .WithOne(q => q.User) + .OnDelete(DeleteBehavior.ClientSetNull) .HasForeignKey(q => q.IdUsersPropose); + modelBuilder.Entity() + .HasMany() + .WithMany() + .UsingEntity( + i => i.HasKey(e => new { e.IdUser, e.IdQuote }) + ); + + modelBuilder.Entity() + .HasOne(c => c.User) + .WithMany() + .HasForeignKey(c => c.IdUser); + + modelBuilder.Entity() + .HasMany(q => q.Commentarys) + .WithOne(c => c.Quote) + .OnDelete(DeleteBehavior.ClientCascade) + .HasForeignKey(c => c.IdQuote); + modelBuilder.Entity() .HasMany(q => q.Questions) .WithMany(u => u.Quizs) diff --git a/WF_EF_Api/Entity/Commentary.cs b/WF_EF_Api/Entity/Commentary.cs index 07649d2..92b2908 100644 --- a/WF_EF_Api/Entity/Commentary.cs +++ b/WF_EF_Api/Entity/Commentary.cs @@ -16,7 +16,7 @@ namespace Entity [Required] [ForeignKey(nameof(Users))] - public int IdUsers { get; set; } + public int IdUser { get; set; } [Required] [ForeignKey(nameof(Quote))] @@ -32,6 +32,6 @@ namespace Entity public Quote Quote { get; set; } = null!; - public Users Users { get; set; } = null!; + public Users User { get; set; } = null!; } } diff --git a/WF_EF_Api/Entity/Quote.cs b/WF_EF_Api/Entity/Quote.cs index 976f62e..37d5f00 100644 --- a/WF_EF_Api/Entity/Quote.cs +++ b/WF_EF_Api/Entity/Quote.cs @@ -15,7 +15,7 @@ namespace Entity public int Id { get; set; } [Required] - [StringLength(50)] + [StringLength(100)] public string Content { get; set; } [Required] @@ -35,11 +35,12 @@ namespace Entity [ForeignKey(nameof(Source))] public int IdSource { get; set; } - [Required] [ForeignKey(nameof(Users))] - public int IdUsersPropose { get; set; } - - public Users User { get; set; } = null!; + public int? IdUsersPropose { get; set; } + //Réson de pour quoi j'ai mis le user en nullable et mis .OnDelete(DeleteBehavior.ClientSetNull) dans WTFContext + //https://learn.microsoft.com/fr-fr/ef/core/saving/cascade-delete + //Les suppressions en cascade sont nécessaires quand une entité dépendante/enfant ne peut plus être associée à son entité principale/parente actuelle. Cela peut se produire à la suite de la suppression de l’entité principale/parente, ou quand l’entité principale/parente existe toujours mais que l’entité dépendante/enfant ne lui est plus associée. + public Users? User { get; set; } = null!; public Source Source { get; set; } = null!; @@ -47,7 +48,7 @@ namespace Entity public ICollection DailyQuotes { get; set; } = new List(); - public ICollection commentaries { get; set; } = new List(); + public ICollection Commentarys { get; set; } = new List(); public ICollection Favorite { get; } = new List(); } diff --git a/WF_EF_Api/Entity/Source.cs b/WF_EF_Api/Entity/Source.cs index 4a9f77c..60cda07 100644 --- a/WF_EF_Api/Entity/Source.cs +++ b/WF_EF_Api/Entity/Source.cs @@ -15,7 +15,7 @@ namespace Entity public int Id { get; set; } [Required] - [StringLength(50)] + [StringLength(100)] public string Title { get; set; } [Required] diff --git a/WF_EF_Api/Entity/Users.cs b/WF_EF_Api/Entity/Users.cs index 80e38a7..e7a8101 100644 --- a/WF_EF_Api/Entity/Users.cs +++ b/WF_EF_Api/Entity/Users.cs @@ -37,8 +37,6 @@ namespace Entity public ICollection Quotes { get; set; } = new List(); - public ICollection Commentary { get; set; } = new List(); - public ICollection Favorite { get; set; } = new List(); } } diff --git a/WF_EF_Api/StubbedContextLib/Migrations/20250314112216_migrationTest1.Designer.cs b/WF_EF_Api/StubbedContextLib/Migrations/20250317163102_migrationTest1.Designer.cs similarity index 94% rename from WF_EF_Api/StubbedContextLib/Migrations/20250314112216_migrationTest1.Designer.cs rename to WF_EF_Api/StubbedContextLib/Migrations/20250317163102_migrationTest1.Designer.cs index d466b28..e352e28 100644 --- a/WF_EF_Api/StubbedContextLib/Migrations/20250314112216_migrationTest1.Designer.cs +++ b/WF_EF_Api/StubbedContextLib/Migrations/20250317163102_migrationTest1.Designer.cs @@ -12,7 +12,7 @@ using StubbedContextLib; namespace StubbedContextLib.Migrations { [DbContext(typeof(StubWTFContext))] - [Migration("20250314112216_migrationTest1")] + [Migration("20250317163102_migrationTest1")] partial class migrationTest1 { /// @@ -112,11 +112,11 @@ namespace StubbedContextLib.Migrations modelBuilder.Entity("Entity.Commentary", b => { - b.Property("Id") - .ValueGeneratedOnAdd() + b.Property("IdUser") .HasColumnType("int"); - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + b.Property("IdQuote") + .HasColumnType("int"); b.Property("Comment") .IsRequired() @@ -127,36 +127,34 @@ namespace StubbedContextLib.Migrations .HasColumnType("date") .HasColumnName("DateCommentary"); - b.Property("IdQuote") + b.Property("Id") + .ValueGeneratedOnAdd() .HasColumnType("int"); - b.Property("IdUsers") - .HasColumnType("int"); + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); - b.HasKey("Id"); + b.HasKey("IdUser", "IdQuote"); b.HasIndex("IdQuote"); - b.HasIndex("IdUsers"); - b.ToTable("comments"); b.HasData( new { - Id = 1, + IdUser = 2, + IdQuote = 1, Comment = "Ce film est le meilleur", DateCommentary = new DateTime(2025, 2, 3, 0, 0, 0, 0, DateTimeKind.Unspecified), - IdQuote = 1, - IdUsers = 2 + Id = 1 }, new { - Id = 2, + IdUser = 3, + IdQuote = 1, Comment = "Very good", DateCommentary = new DateTime(2025, 3, 11, 0, 0, 0, 0, DateTimeKind.Unspecified), - IdQuote = 1, - IdUsers = 3 + Id = 2 }); }); @@ -575,8 +573,8 @@ namespace StubbedContextLib.Migrations b.Property("Content") .IsRequired() - .HasMaxLength(50) - .HasColumnType("nvarchar(50)"); + .HasMaxLength(100) + .HasColumnType("nvarchar(100)"); b.Property("IdCharacter") .HasColumnType("int"); @@ -584,7 +582,7 @@ namespace StubbedContextLib.Migrations b.Property("IdSource") .HasColumnType("int"); - b.Property("IdUsersPropose") + b.Property("IdUsersPropose") .HasColumnType("int"); b.Property("IsValid") @@ -729,8 +727,8 @@ namespace StubbedContextLib.Migrations b.Property("Title") .IsRequired() - .HasMaxLength(50) - .HasColumnType("nvarchar(50)"); + .HasMaxLength(100) + .HasColumnType("nvarchar(100)"); b.Property("TypeSrc") .HasColumnType("int"); @@ -923,20 +921,20 @@ namespace StubbedContextLib.Migrations modelBuilder.Entity("Entity.Commentary", b => { b.HasOne("Entity.Quote", "Quote") - .WithMany("commentaries") + .WithMany("Commentarys") .HasForeignKey("IdQuote") - .OnDelete(DeleteBehavior.Cascade) + .OnDelete(DeleteBehavior.ClientCascade) .IsRequired(); - b.HasOne("Entity.Users", "Users") - .WithMany("Commentary") - .HasForeignKey("IdUsers") + b.HasOne("Entity.Users", "User") + .WithMany() + .HasForeignKey("IdUser") .OnDelete(DeleteBehavior.Cascade) .IsRequired(); b.Navigation("Quote"); - b.Navigation("Users"); + b.Navigation("User"); }); modelBuilder.Entity("Entity.DailyQuote", b => @@ -955,13 +953,13 @@ namespace StubbedContextLib.Migrations b.HasOne("Entity.Quote", "Quote") .WithMany() .HasForeignKey("IdQuote") - .OnDelete(DeleteBehavior.Cascade) + .OnDelete(DeleteBehavior.ClientCascade) .IsRequired(); b.HasOne("Entity.Users", "Users") .WithMany() .HasForeignKey("IdUsers") - .OnDelete(DeleteBehavior.Cascade) + .OnDelete(DeleteBehavior.ClientCascade) .IsRequired(); b.Navigation("Quote"); @@ -1011,9 +1009,7 @@ namespace StubbedContextLib.Migrations b.HasOne("Entity.Users", "User") .WithMany("Quotes") - .HasForeignKey("IdUsersPropose") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); + .HasForeignKey("IdUsersPropose"); b.Navigation("Character"); @@ -1049,9 +1045,9 @@ namespace StubbedContextLib.Migrations modelBuilder.Entity("Entity.Quote", b => { - b.Navigation("DailyQuotes"); + b.Navigation("Commentarys"); - b.Navigation("commentaries"); + b.Navigation("DailyQuotes"); }); modelBuilder.Entity("Entity.Source", b => @@ -1061,8 +1057,6 @@ namespace StubbedContextLib.Migrations modelBuilder.Entity("Entity.Users", b => { - b.Navigation("Commentary"); - b.Navigation("Quotes"); }); #pragma warning restore 612, 618 diff --git a/WF_EF_Api/StubbedContextLib/Migrations/20250314112216_migrationTest1.cs b/WF_EF_Api/StubbedContextLib/Migrations/20250317163102_migrationTest1.cs similarity index 92% rename from WF_EF_Api/StubbedContextLib/Migrations/20250314112216_migrationTest1.cs rename to WF_EF_Api/StubbedContextLib/Migrations/20250317163102_migrationTest1.cs index a85f30b..437370b 100644 --- a/WF_EF_Api/StubbedContextLib/Migrations/20250314112216_migrationTest1.cs +++ b/WF_EF_Api/StubbedContextLib/Migrations/20250317163102_migrationTest1.cs @@ -50,7 +50,7 @@ namespace StubbedContextLib.Migrations { Id = table.Column(type: "int", nullable: false) .Annotation("SqlServer:Identity", "1, 1"), - Title = table.Column(type: "nvarchar(50)", maxLength: 50, nullable: false), + Title = table.Column(type: "nvarchar(100)", maxLength: 100, nullable: false), Year = table.Column(type: "int", nullable: false), TypeSrc = table.Column(type: "int", nullable: false) }, @@ -153,13 +153,13 @@ namespace StubbedContextLib.Migrations { Id = table.Column(type: "int", nullable: false) .Annotation("SqlServer:Identity", "1, 1"), - Content = table.Column(type: "nvarchar(50)", maxLength: 50, nullable: false), + Content = table.Column(type: "nvarchar(100)", maxLength: 100, nullable: false), Likes = table.Column(type: "int", nullable: false), Langage = table.Column(type: "int", nullable: false), IsValid = table.Column(type: "bit", nullable: false), IdCharacter = table.Column(type: "int", nullable: false), IdSource = table.Column(type: "int", nullable: false), - IdUsersPropose = table.Column(type: "int", nullable: false) + IdUsersPropose = table.Column(type: "int", nullable: true) }, constraints: table => { @@ -180,33 +180,31 @@ namespace StubbedContextLib.Migrations name: "FK_quotes_users_IdUsersPropose", column: x => x.IdUsersPropose, principalTable: "users", - principalColumn: "Id", - onDelete: ReferentialAction.Cascade); + principalColumn: "Id"); }); migrationBuilder.CreateTable( name: "comments", columns: table => new { + IdUser = table.Column(type: "int", nullable: false), + IdQuote = table.Column(type: "int", nullable: false), Id = table.Column(type: "int", nullable: false) .Annotation("SqlServer:Identity", "1, 1"), - IdUsers = table.Column(type: "int", nullable: false), - IdQuote = table.Column(type: "int", nullable: false), DateCommentary = table.Column(type: "date", nullable: false), Comment = table.Column(type: "nvarchar(100)", maxLength: 100, nullable: false) }, constraints: table => { - table.PrimaryKey("PK_comments", x => x.Id); + table.PrimaryKey("PK_comments", x => new { x.IdUser, x.IdQuote }); table.ForeignKey( name: "FK_comments_quotes_IdQuote", column: x => x.IdQuote, principalTable: "quotes", - principalColumn: "Id", - onDelete: ReferentialAction.Cascade); + principalColumn: "Id"); table.ForeignKey( - name: "FK_comments_users_IdUsers", - column: x => x.IdUsers, + name: "FK_comments_users_IdUser", + column: x => x.IdUser, principalTable: "users", principalColumn: "Id", onDelete: ReferentialAction.Cascade); @@ -243,14 +241,12 @@ namespace StubbedContextLib.Migrations name: "FK_favorites_quotes_IdQuote", column: x => x.IdQuote, principalTable: "quotes", - principalColumn: "Id", - onDelete: ReferentialAction.Cascade); + principalColumn: "Id"); table.ForeignKey( name: "FK_favorites_users_IdUsers", column: x => x.IdUsers, principalTable: "users", - principalColumn: "Id", - onDelete: ReferentialAction.Cascade); + principalColumn: "Id"); }); migrationBuilder.InsertData( @@ -378,11 +374,11 @@ namespace StubbedContextLib.Migrations migrationBuilder.InsertData( table: "comments", - columns: new[] { "Id", "Comment", "DateCommentary", "IdQuote", "IdUsers" }, + columns: new[] { "IdQuote", "IdUser", "Comment", "DateCommentary", "Id" }, values: new object[,] { - { 1, "Ce film est le meilleur", new DateTime(2025, 2, 3, 0, 0, 0, 0, DateTimeKind.Unspecified), 1, 2 }, - { 2, "Very good", new DateTime(2025, 3, 11, 0, 0, 0, 0, DateTimeKind.Unspecified), 1, 3 } + { 1, 2, "Ce film est le meilleur", new DateTime(2025, 2, 3, 0, 0, 0, 0, DateTimeKind.Unspecified), 1 }, + { 1, 3, "Very good", new DateTime(2025, 3, 11, 0, 0, 0, 0, DateTimeKind.Unspecified), 2 } }); migrationBuilder.InsertData( @@ -420,11 +416,6 @@ namespace StubbedContextLib.Migrations table: "comments", column: "IdQuote"); - migrationBuilder.CreateIndex( - name: "IX_comments_IdUsers", - table: "comments", - column: "IdUsers"); - migrationBuilder.CreateIndex( name: "IX_favorites_IdUsers", table: "favorites", diff --git a/WF_EF_Api/StubbedContextLib/Migrations/StubWTFContextModelSnapshot.cs b/WF_EF_Api/StubbedContextLib/Migrations/StubWTFContextModelSnapshot.cs index 21818ec..275cb8a 100644 --- a/WF_EF_Api/StubbedContextLib/Migrations/StubWTFContextModelSnapshot.cs +++ b/WF_EF_Api/StubbedContextLib/Migrations/StubWTFContextModelSnapshot.cs @@ -109,11 +109,11 @@ namespace StubbedContextLib.Migrations modelBuilder.Entity("Entity.Commentary", b => { - b.Property("Id") - .ValueGeneratedOnAdd() + b.Property("IdUser") .HasColumnType("int"); - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + b.Property("IdQuote") + .HasColumnType("int"); b.Property("Comment") .IsRequired() @@ -124,36 +124,34 @@ namespace StubbedContextLib.Migrations .HasColumnType("date") .HasColumnName("DateCommentary"); - b.Property("IdQuote") + b.Property("Id") + .ValueGeneratedOnAdd() .HasColumnType("int"); - b.Property("IdUsers") - .HasColumnType("int"); + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); - b.HasKey("Id"); + b.HasKey("IdUser", "IdQuote"); b.HasIndex("IdQuote"); - b.HasIndex("IdUsers"); - b.ToTable("comments"); b.HasData( new { - Id = 1, + IdUser = 2, + IdQuote = 1, Comment = "Ce film est le meilleur", DateCommentary = new DateTime(2025, 2, 3, 0, 0, 0, 0, DateTimeKind.Unspecified), - IdQuote = 1, - IdUsers = 2 + Id = 1 }, new { - Id = 2, + IdUser = 3, + IdQuote = 1, Comment = "Very good", DateCommentary = new DateTime(2025, 3, 11, 0, 0, 0, 0, DateTimeKind.Unspecified), - IdQuote = 1, - IdUsers = 3 + Id = 2 }); }); @@ -572,8 +570,8 @@ namespace StubbedContextLib.Migrations b.Property("Content") .IsRequired() - .HasMaxLength(50) - .HasColumnType("nvarchar(50)"); + .HasMaxLength(100) + .HasColumnType("nvarchar(100)"); b.Property("IdCharacter") .HasColumnType("int"); @@ -581,7 +579,7 @@ namespace StubbedContextLib.Migrations b.Property("IdSource") .HasColumnType("int"); - b.Property("IdUsersPropose") + b.Property("IdUsersPropose") .HasColumnType("int"); b.Property("IsValid") @@ -726,8 +724,8 @@ namespace StubbedContextLib.Migrations b.Property("Title") .IsRequired() - .HasMaxLength(50) - .HasColumnType("nvarchar(50)"); + .HasMaxLength(100) + .HasColumnType("nvarchar(100)"); b.Property("TypeSrc") .HasColumnType("int"); @@ -920,20 +918,20 @@ namespace StubbedContextLib.Migrations modelBuilder.Entity("Entity.Commentary", b => { b.HasOne("Entity.Quote", "Quote") - .WithMany("commentaries") + .WithMany("Commentarys") .HasForeignKey("IdQuote") - .OnDelete(DeleteBehavior.Cascade) + .OnDelete(DeleteBehavior.ClientCascade) .IsRequired(); - b.HasOne("Entity.Users", "Users") - .WithMany("Commentary") - .HasForeignKey("IdUsers") + b.HasOne("Entity.Users", "User") + .WithMany() + .HasForeignKey("IdUser") .OnDelete(DeleteBehavior.Cascade) .IsRequired(); b.Navigation("Quote"); - b.Navigation("Users"); + b.Navigation("User"); }); modelBuilder.Entity("Entity.DailyQuote", b => @@ -952,13 +950,13 @@ namespace StubbedContextLib.Migrations b.HasOne("Entity.Quote", "Quote") .WithMany() .HasForeignKey("IdQuote") - .OnDelete(DeleteBehavior.Cascade) + .OnDelete(DeleteBehavior.ClientCascade) .IsRequired(); b.HasOne("Entity.Users", "Users") .WithMany() .HasForeignKey("IdUsers") - .OnDelete(DeleteBehavior.Cascade) + .OnDelete(DeleteBehavior.ClientCascade) .IsRequired(); b.Navigation("Quote"); @@ -1008,9 +1006,7 @@ namespace StubbedContextLib.Migrations b.HasOne("Entity.Users", "User") .WithMany("Quotes") - .HasForeignKey("IdUsersPropose") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); + .HasForeignKey("IdUsersPropose"); b.Navigation("Character"); @@ -1046,9 +1042,9 @@ namespace StubbedContextLib.Migrations modelBuilder.Entity("Entity.Quote", b => { - b.Navigation("DailyQuotes"); + b.Navigation("Commentarys"); - b.Navigation("commentaries"); + b.Navigation("DailyQuotes"); }); modelBuilder.Entity("Entity.Source", b => @@ -1058,8 +1054,6 @@ namespace StubbedContextLib.Migrations modelBuilder.Entity("Entity.Users", b => { - b.Navigation("Commentary"); - b.Navigation("Quotes"); }); #pragma warning restore 612, 618 diff --git a/WF_EF_Api/StubbedContextLib/StubWTFContext.cs b/WF_EF_Api/StubbedContextLib/StubWTFContext.cs index 6df9912..ffc1d06 100644 --- a/WF_EF_Api/StubbedContextLib/StubWTFContext.cs +++ b/WF_EF_Api/StubbedContextLib/StubWTFContext.cs @@ -72,8 +72,8 @@ namespace StubbedContextLib ); modelBuilder.Entity().HasData( - new Commentary() { Id = 1, Comment = "Ce film est le meilleur", DateCommentary = new DateTime(2025,2,3), IdQuote = 1, IdUsers = 2 }, - new Commentary() { Id = 2, Comment = "Very good", DateCommentary = new DateTime(2025, 3, 11), IdQuote = 1, IdUsers = 3 } + new Commentary() { Id = 1, Comment = "Ce film est le meilleur", DateCommentary = new DateTime(2025,2,3), IdQuote = 1, IdUser = 2 }, + new Commentary() { Id = 2, Comment = "Very good", DateCommentary = new DateTime(2025, 3, 11), IdQuote = 1, IdUser = 3 } ); modelBuilder.Entity().HasData( diff --git a/WF_EF_Api/StubbedContextLib/StubbedContextLib.csproj b/WF_EF_Api/StubbedContextLib/StubbedContextLib.csproj index 4ae6e1b..9a838f3 100644 --- a/WF_EF_Api/StubbedContextLib/StubbedContextLib.csproj +++ b/WF_EF_Api/StubbedContextLib/StubbedContextLib.csproj @@ -18,8 +18,4 @@ - - - - From 4b4b0495fa1015ff278fb77781e955d2631cd5e1 Mon Sep 17 00:00:00 2001 From: Kevin MONDEJAR Date: Tue, 18 Mar 2025 14:39:31 +0100 Subject: [PATCH 12/65] ajout methodes extentions ToDto() --- WF_EF_Api/DTO/ResultsDTO.cs | 16 --- WF_EF_Api/DTO/SourceDTO.cs | 2 +- WF_EF_Api/DTO/UserDTO.cs | 2 +- WF_EF_Api/Dto2Entities/Dto2Entities.csproj | 14 ++ WF_EF_Api/Dto2Entities/Extention.cs | 149 +++++++++++++++++++++ WF_EF_Api/Entity/LangEnum.cs | 3 +- WF_EF_Api/Entity/Quote.cs | 6 + WF_EF_Api/Entity/RecordQuiz.cs | 17 --- WF_EF_Api/StubApi/UserService.cs | 42 +++--- WF_EF_Api/WF_EF_Api.sln | 20 +-- 10 files changed, 201 insertions(+), 70 deletions(-) delete mode 100644 WF_EF_Api/DTO/ResultsDTO.cs create mode 100644 WF_EF_Api/Dto2Entities/Dto2Entities.csproj create mode 100644 WF_EF_Api/Dto2Entities/Extention.cs delete mode 100644 WF_EF_Api/Entity/RecordQuiz.cs diff --git a/WF_EF_Api/DTO/ResultsDTO.cs b/WF_EF_Api/DTO/ResultsDTO.cs deleted file mode 100644 index de28b59..0000000 --- a/WF_EF_Api/DTO/ResultsDTO.cs +++ /dev/null @@ -1,16 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace DTO -{ - public class ResultsDTO - { - public int IdQuiz { get; set; } - public int IdUser { get; set; } - public int Time { get; set; } - public int NbPoint { get; set; } - } -} diff --git a/WF_EF_Api/DTO/SourceDTO.cs b/WF_EF_Api/DTO/SourceDTO.cs index 9db4871..fbb40b7 100644 --- a/WF_EF_Api/DTO/SourceDTO.cs +++ b/WF_EF_Api/DTO/SourceDTO.cs @@ -10,7 +10,7 @@ namespace DTO { public int Id { get; set; } public string Title { get; set; } - public DateTime Date { get; set; } + public int Date { get; set; } public TypeSrcEnumDTO Type { get; set; } } } diff --git a/WF_EF_Api/DTO/UserDTO.cs b/WF_EF_Api/DTO/UserDTO.cs index 672cde3..a01494b 100644 --- a/WF_EF_Api/DTO/UserDTO.cs +++ b/WF_EF_Api/DTO/UserDTO.cs @@ -6,7 +6,7 @@ public string Pseudo { get; set; } public string Password { get; set; } public string Email { get; set; } - public string Years { get; set; } + public DateTime date { get; set; } public string ImageProfil { get; set; } } } diff --git a/WF_EF_Api/Dto2Entities/Dto2Entities.csproj b/WF_EF_Api/Dto2Entities/Dto2Entities.csproj new file mode 100644 index 0000000..beed701 --- /dev/null +++ b/WF_EF_Api/Dto2Entities/Dto2Entities.csproj @@ -0,0 +1,14 @@ + + + + net8.0 + enable + enable + + + + + + + + diff --git a/WF_EF_Api/Dto2Entities/Extention.cs b/WF_EF_Api/Dto2Entities/Extention.cs new file mode 100644 index 0000000..62ed743 --- /dev/null +++ b/WF_EF_Api/Dto2Entities/Extention.cs @@ -0,0 +1,149 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Entity; +using DTO; +using System.Reflection.Metadata; + +namespace Dto2Entities +{ + public static class Extention + { + // --------------------------- ToDto --------------------------- \\ + + public static CharacterDTO ToDto(this Character item) + { + CharacterDTO character = new CharacterDTO(); + character.Id = item.Id; + character.Name = item.Name; + character.imagePath = item.Images.ImgPath; + return character; + } + + public static CommentaryDTO ToDto(this Commentary item) + { + CommentaryDTO commentary = new CommentaryDTO(); + commentary.Id = item.Id; + commentary.Date = item.DateCommentary; + commentary.Comment = item.Comment; + commentary.User = item.Users.UserName; + commentary.ImagePath = item.Users.Images.ImgPath; + return commentary; + } + + // Surement a refaire car Faoirite Entity modifier sur branche EF + public static FavoriteDTO ToDto(this Favorite item) + { + FavoriteDTO favorite = new FavoriteDTO(); + favorite.IdUser = item.IdUsers; + favorite.IdQuote = item.IdQuote; + return favorite; + } + + public static ImageDTO ToDto(this Images item) + { + ImageDTO image = new ImageDTO(); + image.IdImage = item.Id; + image.ImagePath = item.ImgPath; + return image; + } + + public static QuestionDTO ToDto(this Question item) + { + QuestionDTO question = new QuestionDTO(); + question.Id = item.Id; + question.Question = item.Text; + question.AnswerA = item.AnswerA; + question.AnswerB = item.AnswerB; + question.AnswerC = item.AnswerC; + question.AnswerD = item.AnswerD; + question.CorrectAnswer = item.CorrectAnswer; + return question; + } + + public static QuizDTO ToDto(this Quiz item) + { + QuizDTO quiz = new QuizDTO(); + quiz.Id = item.Id; + quiz.NbQuestion = item.NbQuestion; + quiz.Title = item.Title; + quiz.ImagePath = item.Images.ImgPath; + return quiz; + } + + // Surement a refaire car QuizQuestion Entity modifier sur branche EF + public static QuizQuestionDTO ToDto(this QuizQuestion item) + { + QuizQuestionDTO quizQuestion = new QuizQuestionDTO(); + quizQuestion.IdQuiz = item.IdQuiz; + quizQuestion.IdQuestion = item.IdQuestion; + return quizQuestion; + } + + public static QuoteDTO ToDto(this Quote item) + { + QuoteDTO quote = new QuoteDTO(); + quote.Id = item.Id; + quote.Content = item.Content; + quote.DateSource = item.Source.Year; + quote.Character = item.Character.Name; + quote.TitleSource = item.Source.Title; + quote.Langage = item.Langage.ToDto(); + quote.ImagePath = item.Character.Images.ImgPath; + quote.Like = item.Likes; + quote.Type = item.Source.TypeSrc.ToDto(); + return quote; + } + + public static SourceDTO ToDto(this Source item) + { + SourceDTO source = new SourceDTO(); + source.Id = item.Id; + source.Date = item.Year; + source.Title = item.Title; + source.Type = item.TypeSrc.ToDto(); + return source; + } + + public static UserDTO ToDto(this Users item) + { + UserDTO user = new UserDTO(); + user.Id = item.Id; + user.Pseudo = item.UserName; + user.Password = item.Password; + user.Email = item.Email; + user.date = item.Created; + user.ImageProfil = item.Images.ImgPath; + return user; + } + + public static TypeLangageDTO ToDto(this LangEnum item) + { + switch (item) + { + case LangEnum.vf: return TypeLangageDTO.vf; + case LangEnum.vo: return TypeLangageDTO.vo; + case LangEnum.ve: return TypeLangageDTO.ve; + default: return TypeLangageDTO.vo; + } + } + + public static TypeSrcEnumDTO ToDto(this TypeSrcEnum item) + { + switch (item) + { + case TypeSrcEnum.movie: return TypeSrcEnumDTO.movie; + case TypeSrcEnum.book: return TypeSrcEnumDTO.book; + case TypeSrcEnum.series: return TypeSrcEnumDTO.serie; + case TypeSrcEnum.videogame: return TypeSrcEnumDTO.videogame; + default: return TypeSrcEnumDTO.movie; + } + } + + // --------------------------- ToEntity --------------------------- \\ + + + } +} diff --git a/WF_EF_Api/Entity/LangEnum.cs b/WF_EF_Api/Entity/LangEnum.cs index 3f8f2a1..dd70bb1 100644 --- a/WF_EF_Api/Entity/LangEnum.cs +++ b/WF_EF_Api/Entity/LangEnum.cs @@ -9,6 +9,7 @@ namespace Entity public enum LangEnum { vo, - vf + vf, + ve } } diff --git a/WF_EF_Api/Entity/Quote.cs b/WF_EF_Api/Entity/Quote.cs index adc1dd8..5cd144a 100644 --- a/WF_EF_Api/Entity/Quote.cs +++ b/WF_EF_Api/Entity/Quote.cs @@ -39,6 +39,12 @@ namespace Entity [ForeignKey(nameof(Users))] public int IdUsersPropose { get; set; } + public Users? User { get; set; } = null!; + + public Source Source { get; set; } = null!; + + public Character Character { get; set; } = null!; + public ICollection DailyQuotes { get; set; } = new List(); public ICollection commentaries { get; set; } = new List(); diff --git a/WF_EF_Api/Entity/RecordQuiz.cs b/WF_EF_Api/Entity/RecordQuiz.cs deleted file mode 100644 index 4a6a689..0000000 --- a/WF_EF_Api/Entity/RecordQuiz.cs +++ /dev/null @@ -1,17 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace Entity -{ - // Peut etre enlever car inutiliser - public class RecordQuiz - { - public int IdUsers { get; set; } - public int IdQuiz { get; set; } - public int NbPoint { get; set; } - public int TimeQuiz { get; set; } - } -} diff --git a/WF_EF_Api/StubApi/UserService.cs b/WF_EF_Api/StubApi/UserService.cs index 7fd167a..4ce870b 100644 --- a/WF_EF_Api/StubApi/UserService.cs +++ b/WF_EF_Api/StubApi/UserService.cs @@ -10,26 +10,26 @@ namespace StubApi { _users = new List { - new UserDTO { Id = 1, Pseudo = "dev", Password = "1234", Email = "testeur@example.com", Years = "2023", ImageProfil = "https://image_profil_1" }, - new UserDTO { Id = 2, Pseudo = "admin", Password = "admin123", Email = "admin@example.com", Years = "2024", ImageProfil = "https://image_profil_2" }, - new UserDTO { Id = 3, Pseudo = "user123", Password = "password123", Email = "user123@example.com", Years = "2022", ImageProfil = "https://image_profil_3" }, - new UserDTO { Id = 4, Pseudo = "testuser", Password = "testpass", Email = "testuser@example.com", Years = "2025", ImageProfil = "https://image_profil_4" }, - new UserDTO { Id = 5, Pseudo = "johnDoe", Password = "john123", Email = "johndoe@example.com", Years = "2021", ImageProfil = "https://image_profil_5" }, - new UserDTO { Id = 6, Pseudo = "janedoe", Password = "jane123", Email = "janedoe@example.com", Years = "2023", ImageProfil = "https://image_profil_6" }, - new UserDTO { Id = 7, Pseudo = "mark_smith", Password = "mark1234", Email = "marks@example.com", Years = "2022", ImageProfil = "https://image_profil_7" }, - new UserDTO { Id = 8, Pseudo = "alice", Password = "alicepass", Email = "alice@example.com", Years = "2024", ImageProfil = "https://image_profil_8" }, - new UserDTO { Id = 9, Pseudo = "bob_lee", Password = "bob123", Email = "bob@example.com", Years = "2021", ImageProfil = "https://image_profil_9" }, - new UserDTO { Id = 10, Pseudo = "lucas", Password = "lucaspass", Email = "lucas@example.com", Years = "2023", ImageProfil = "https://image_profil_10" }, - new UserDTO { Id = 11, Pseudo = "emily", Password = "emily2024", Email = "emily@example.com", Years = "2022", ImageProfil = "https://image_profil_11" }, - new UserDTO { Id = 12, Pseudo = "chris", Password = "chris1234", Email = "chris@example.com", Years = "2024", ImageProfil = "https://image_profil_12" }, - new UserDTO { Id = 13, Pseudo = "susan", Password = "susan123", Email = "susan@example.com", Years = "2023", ImageProfil = "https://image_profil_13" }, - new UserDTO { Id = 14, Pseudo = "michael", Password = "michael2025", Email = "michael@example.com", Years = "2022", ImageProfil = "https://image_profil_14" }, - new UserDTO { Id = 15, Pseudo = "olivia", Password = "olivia2024", Email = "olivia@example.com", Years = "2024", ImageProfil = "https://image_profil_15" }, - new UserDTO { Id = 16, Pseudo = "david", Password = "david123", Email = "david@example.com", Years = "2021", ImageProfil = "https://image_profil_16" }, - new UserDTO { Id = 17, Pseudo = "laura", Password = "laura456", Email = "laura@example.com", Years = "2023", ImageProfil = "https://image_profil_17" }, - new UserDTO { Id = 18, Pseudo = "steve", Password = "steve789", Email = "steve@example.com", Years = "2022", ImageProfil = "https://image_profil_18" }, - new UserDTO { Id = 19, Pseudo = "tina", Password = "tina321", Email = "tina@example.com", Years = "2024", ImageProfil = "https://image_profil_19" }, - new UserDTO { Id = 20, Pseudo = "peter", Password = "peter123", Email = "peter@example.com", Years = "2025", ImageProfil = "https://image_profil_20" } + new UserDTO { Id = 1, Pseudo = "dev", Password = "1234", Email = "testeur@example.com", date = new DateTime(2025,1,1), ImageProfil = "https://image_profil_1" }, + new UserDTO { Id = 2, Pseudo = "admin", Password = "admin123", Email = "admin@example.com", date = new DateTime(2025,1,1), ImageProfil = "https://image_profil_2" }, + new UserDTO { Id = 3, Pseudo = "user123", Password = "password123", Email = "user123@example.com", date = new DateTime(2022,1,1), ImageProfil = "https://image_profil_3" }, + new UserDTO { Id = 4, Pseudo = "testuser", Password = "testpass", Email = "testuser@example.com", date = new DateTime(2024,1,1), ImageProfil = "https://image_profil_4" }, + new UserDTO { Id = 5, Pseudo = "johnDoe", Password = "john123", Email = "johndoe@example.com", date = new DateTime(2021,1,1), ImageProfil = "https://image_profil_5" }, + new UserDTO { Id = 6, Pseudo = "janedoe", Password = "jane123", Email = "janedoe@example.com", date = new DateTime(2023,1,1), ImageProfil = "https://image_profil_6" }, + new UserDTO { Id = 7, Pseudo = "mark_smith", Password = "mark1234", Email = "marks@example.com", date = new DateTime(2022,1,1), ImageProfil = "https://image_profil_7" }, + new UserDTO { Id = 8, Pseudo = "alice", Password = "alicepass", Email = "alice@example.com", date = new DateTime(2025,1,1), ImageProfil = "https://image_profil_8" }, + new UserDTO { Id = 9, Pseudo = "bob_lee", Password = "bob123", Email = "bob@example.com", date = new DateTime(2021,1,1), ImageProfil = "https://image_profil_9" }, + new UserDTO { Id = 10, Pseudo = "lucas", Password = "lucaspass", Email = "lucas@example.com", date = new DateTime(2023,1,1), ImageProfil = "https://image_profil_10" }, + new UserDTO { Id = 11, Pseudo = "emily", Password = "emily2024", Email = "emily@example.com", date = new DateTime(2022,1,1), ImageProfil = "https://image_profil_11" }, + new UserDTO { Id = 12, Pseudo = "chris", Password = "chris1234", Email = "chris@example.com", date = new DateTime(2025,1,1), ImageProfil = "https://image_profil_12" }, + new UserDTO { Id = 13, Pseudo = "susan", Password = "susan123", Email = "susan@example.com", date = new DateTime(2023,1,1), ImageProfil = "https://image_profil_13" }, + new UserDTO { Id = 14, Pseudo = "michael", Password = "michael2025", Email = "michael@example.com", date = new DateTime(2022,1,1), ImageProfil = "https://image_profil_14" }, + new UserDTO { Id = 15, Pseudo = "olivia", Password = "olivia2024", Email = "olivia@example.com", date = new DateTime(2025,1,1), ImageProfil = "https://image_profil_15" }, + new UserDTO { Id = 16, Pseudo = "david", Password = "david123", Email = "david@example.com", date = new DateTime(2021,1,1), ImageProfil = "https://image_profil_16" }, + new UserDTO { Id = 17, Pseudo = "laura", Password = "laura456", Email = "laura@example.com", date = new DateTime(2023,1,1), ImageProfil = "https://image_profil_17" }, + new UserDTO { Id = 18, Pseudo = "steve", Password = "steve789", Email = "steve@example.com", date = new DateTime(2022,1,1), ImageProfil = "https://image_profil_18" }, + new UserDTO { Id = 19, Pseudo = "tina", Password = "tina321", Email = "tina@example.com", date = new DateTime(2025,1,1), ImageProfil = "https://image_profil_19" }, + new UserDTO { Id = 20, Pseudo = "peter", Password = "peter123", Email = "peter@example.com", date = new DateTime(2024,1,1), ImageProfil = "https://image_profil_20" } }; } @@ -111,7 +111,7 @@ namespace StubApi existingUser.Pseudo = user.Pseudo; existingUser.Password = user.Password; existingUser.Email = user.Email; - existingUser.Years = user.Years; + existingUser.date = user.date; existingUser.ImageProfil = user.ImageProfil; return existingUser; } diff --git a/WF_EF_Api/WF_EF_Api.sln b/WF_EF_Api/WF_EF_Api.sln index 3942dd1..2fc3a9e 100644 --- a/WF_EF_Api/WF_EF_Api.sln +++ b/WF_EF_Api/WF_EF_Api.sln @@ -15,17 +15,15 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "StubbedContextLib", "Stubbe EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TestModel2Entities", "TestModel2Entities\TestModel2Entities.csproj", "{2CF20FAC-C2F1-4048-9D46-F39081B0FBEF}" EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Model2Entities", "Model2entities\Model2Entities.csproj", "{4A1CBA3D-C798-4E19-865F-39F919F1205A}" -EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "XUnitTest", "XUnitTest\XUnitTest.csproj", "{48002CA2-7CFF-4077-90CF-392476320CE3}" EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "WfApi", "WfApi\WfApi.csproj", "{D4EEE1BF-CDCB-4E66-997B-7A5984DA7995}" EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Model", "Model\Model.csproj", "{708875DC-7ED1-4FD1-9321-3E00B2E7709B}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "StubApi", "StubApi\StubApi.csproj", "{4C5F324C-28C3-4153-B402-A07B099C24C6}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "StubApi", "StubApi\StubApi.csproj", "{4C5F324C-28C3-4153-B402-A07B099C24C6}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DTO", "DTO\DTO.csproj", "{99F43B70-4143-4807-9EE7-B8A799B1E702}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DTO", "DTO\DTO.csproj", "{99F43B70-4143-4807-9EE7-B8A799B1E702}" +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Dto2Entities", "Dto2Entities\Dto2Entities.csproj", "{08194729-E222-4C9A-B860-D944225B8895}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -57,10 +55,6 @@ Global {2CF20FAC-C2F1-4048-9D46-F39081B0FBEF}.Debug|Any CPU.Build.0 = Debug|Any CPU {2CF20FAC-C2F1-4048-9D46-F39081B0FBEF}.Release|Any CPU.ActiveCfg = Release|Any CPU {2CF20FAC-C2F1-4048-9D46-F39081B0FBEF}.Release|Any CPU.Build.0 = Release|Any CPU - {4A1CBA3D-C798-4E19-865F-39F919F1205A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {4A1CBA3D-C798-4E19-865F-39F919F1205A}.Debug|Any CPU.Build.0 = Debug|Any CPU - {4A1CBA3D-C798-4E19-865F-39F919F1205A}.Release|Any CPU.ActiveCfg = Release|Any CPU - {4A1CBA3D-C798-4E19-865F-39F919F1205A}.Release|Any CPU.Build.0 = Release|Any CPU {48002CA2-7CFF-4077-90CF-392476320CE3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {48002CA2-7CFF-4077-90CF-392476320CE3}.Debug|Any CPU.Build.0 = Debug|Any CPU {48002CA2-7CFF-4077-90CF-392476320CE3}.Release|Any CPU.ActiveCfg = Release|Any CPU @@ -69,10 +63,6 @@ Global {D4EEE1BF-CDCB-4E66-997B-7A5984DA7995}.Debug|Any CPU.Build.0 = Debug|Any CPU {D4EEE1BF-CDCB-4E66-997B-7A5984DA7995}.Release|Any CPU.ActiveCfg = Release|Any CPU {D4EEE1BF-CDCB-4E66-997B-7A5984DA7995}.Release|Any CPU.Build.0 = Release|Any CPU - {708875DC-7ED1-4FD1-9321-3E00B2E7709B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {708875DC-7ED1-4FD1-9321-3E00B2E7709B}.Debug|Any CPU.Build.0 = Debug|Any CPU - {708875DC-7ED1-4FD1-9321-3E00B2E7709B}.Release|Any CPU.ActiveCfg = Release|Any CPU - {708875DC-7ED1-4FD1-9321-3E00B2E7709B}.Release|Any CPU.Build.0 = Release|Any CPU {4C5F324C-28C3-4153-B402-A07B099C24C6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {4C5F324C-28C3-4153-B402-A07B099C24C6}.Debug|Any CPU.Build.0 = Debug|Any CPU {4C5F324C-28C3-4153-B402-A07B099C24C6}.Release|Any CPU.ActiveCfg = Release|Any CPU @@ -81,6 +71,10 @@ Global {99F43B70-4143-4807-9EE7-B8A799B1E702}.Debug|Any CPU.Build.0 = Debug|Any CPU {99F43B70-4143-4807-9EE7-B8A799B1E702}.Release|Any CPU.ActiveCfg = Release|Any CPU {99F43B70-4143-4807-9EE7-B8A799B1E702}.Release|Any CPU.Build.0 = Release|Any CPU + {08194729-E222-4C9A-B860-D944225B8895}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {08194729-E222-4C9A-B860-D944225B8895}.Debug|Any CPU.Build.0 = Debug|Any CPU + {08194729-E222-4C9A-B860-D944225B8895}.Release|Any CPU.ActiveCfg = Release|Any CPU + {08194729-E222-4C9A-B860-D944225B8895}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE From 61fa6f89d76ff509ec613e03a543d46f6db3764c Mon Sep 17 00:00:00 2001 From: Kevin MONDEJAR Date: Tue, 18 Mar 2025 15:22:36 +0100 Subject: [PATCH 13/65] db manager --- WF_EF_Api/Contextlib/DbCommentaryManager.cs | 73 +- WF_EF_Api/Dto2Entities/Dto2Entities.csproj | 14 + .../20250318135625_migr1.Designer.cs | 1065 +++++++++++++++++ .../Migrations/20250318135625_migr1.cs | 22 + 4 files changed, 1162 insertions(+), 12 deletions(-) create mode 100644 WF_EF_Api/Dto2Entities/Dto2Entities.csproj create mode 100644 WF_EF_Api/StubbedContextLib/Migrations/20250318135625_migr1.Designer.cs create mode 100644 WF_EF_Api/StubbedContextLib/Migrations/20250318135625_migr1.cs diff --git a/WF_EF_Api/Contextlib/DbCommentaryManager.cs b/WF_EF_Api/Contextlib/DbCommentaryManager.cs index 002082f..558aa46 100644 --- a/WF_EF_Api/Contextlib/DbCommentaryManager.cs +++ b/WF_EF_Api/Contextlib/DbCommentaryManager.cs @@ -43,14 +43,13 @@ namespace Contextlib /// Thrown when no comments are found for the provided quote ID. public async Task DeleteCommentForQuote(int quoteId) { - // Retrieve comments for the specific quoteId var comments = await _context.comments.Where(x => x.IdQuote == quoteId).ToListAsync(); - if (!comments.Any()) // If no comments exist for this quoteId + if (!comments.Any()) { throw new KeyNotFoundException($"No comments found for the quote ID: {quoteId}."); } - _context.comments.RemoveRange(comments); // Efficiently remove all comments in one batch + _context.comments.RemoveRange(comments); await _context.SaveChangesAsync(); } @@ -62,45 +61,95 @@ namespace Contextlib /// Thrown when no comments are found for the provided user ID. public async Task DeleteCommentForUser(int userId) { - // Retrieve comments for the specific userId var comments = await _context.comments.Where(x => x.IdUser == userId).ToListAsync(); - if (!comments.Any()) // If no comments exist for this userId + if (!comments.Any()) { throw new KeyNotFoundException($"No comments found for the user ID: {userId}."); } - _context.comments.RemoveRange(comments); // Efficiently remove all comments in one batch + _context.comments.RemoveRange(comments); await _context.SaveChangesAsync(); } public async Task> GetAllComment() { - throw new NotImplementedException(); + var comments = _context.comments.ToList(); + return new PaginationResult(comments.Count, 0, comments.Count, comments); } public async Task GetCommentById(int id) { - throw new NotImplementedException(); + var comment = await _context.comments.Where(x => x.Id == id).FirstOrDefaultAsync(); + if(comment == null) + { + throw new KeyNotFoundException($"No comments found with the given ID: {id}."); + } + return comment; } public async Task> GetCommentByQuote(int quoteId, int index, int pageSize) { - throw new NotImplementedException(); + var comments = await _context.comments.Where(x => x.IdQuote == quoteId).ToListAsync(); + if (!comments.Any()) + { + throw new KeyNotFoundException($"No comments found for the quote ID: {quoteId}."); + } + if ((index * pageSize + pageSize) > comments.Count) + { + if (pageSize > comments.Count) + { + return new PaginationResult(comments.Count(), index, pageSize, comments); + } + else + { + return new PaginationResult(pageSize, index, pageSize, comments.Skip(index * pageSize - (((index * pageSize) + pageSize) - comments.Count)).Take(pageSize).ToList()); + } + + } + return new PaginationResult(comments.Count, index, pageSize, comments.Skip(index * pageSize).Take(pageSize).ToList()); } public async Task> GetCommentByUser(int userId, int index, int pageSize) { - throw new NotImplementedException(); + var comments = await _context.comments.Where(x => x.IdUser == userId).ToListAsync(); + if (!comments.Any()) + { + throw new KeyNotFoundException($"No comments found for the user ID: {userId}."); + } + if ((index * pageSize + pageSize) > comments.Count) + { + if (pageSize > comments.Count) + { + return new PaginationResult(comments.Count(), index, pageSize, comments); + } + else + { + return new PaginationResult(pageSize, index, pageSize, comments.Skip(index * pageSize - (((index * pageSize) + pageSize) - comments.Count)).Take(pageSize).ToList()); + } + + } + return new PaginationResult(comments.Count, index, pageSize, comments.Skip(index * pageSize).Take(pageSize).ToList()); } public async Task LastCommentId() { - throw new NotImplementedException(); + var last = _context.comments.OrderByDescending(x => x.Id).FirstOrDefault(); + if(last == null) + { + return 0; + } + return last.Id; } public async Task RemoveComment(int id) { - throw new NotImplementedException(); + var comment = await _context.comments.Where(x => x.Id == id).FirstOrDefaultAsync(); + if (comment == null) + { + throw new KeyNotFoundException($"No comments found with the given ID: {id}."); + } + _context.comments.Remove(comment); + await _context.SaveChangesAsync(); } public async Task UpdateComment(int id, Commentary comment) diff --git a/WF_EF_Api/Dto2Entities/Dto2Entities.csproj b/WF_EF_Api/Dto2Entities/Dto2Entities.csproj new file mode 100644 index 0000000..beed701 --- /dev/null +++ b/WF_EF_Api/Dto2Entities/Dto2Entities.csproj @@ -0,0 +1,14 @@ + + + + net8.0 + enable + enable + + + + + + + + diff --git a/WF_EF_Api/StubbedContextLib/Migrations/20250318135625_migr1.Designer.cs b/WF_EF_Api/StubbedContextLib/Migrations/20250318135625_migr1.Designer.cs new file mode 100644 index 0000000..2ba04f3 --- /dev/null +++ b/WF_EF_Api/StubbedContextLib/Migrations/20250318135625_migr1.Designer.cs @@ -0,0 +1,1065 @@ +// +using System; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Metadata; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; +using StubbedContextLib; + +#nullable disable + +namespace StubbedContextLib.Migrations +{ + [DbContext(typeof(StubWTFContext))] + [Migration("20250318135625_migr1")] + partial class migr1 + { + /// + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("ProductVersion", "9.0.3") + .HasAnnotation("Relational:MaxIdentifierLength", 128); + + SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder); + + modelBuilder.Entity("Entity.Character", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("IdImage") + .HasColumnType("int"); + + b.Property("Name") + .IsRequired() + .HasMaxLength(50) + .HasColumnType("nvarchar(50)"); + + b.HasKey("Id"); + + b.HasIndex("IdImage"); + + b.ToTable("characters"); + + b.HasData( + new + { + Id = 1, + IdImage = 1, + Name = "Alan Grant" + }, + new + { + Id = 2, + IdImage = 2, + Name = "Aragorn" + }, + new + { + Id = 3, + IdImage = 3, + Name = "Legolas" + }, + new + { + Id = 4, + IdImage = 4, + Name = "Frodon" + }, + new + { + Id = 5, + IdImage = 5, + Name = "Dobby" + }, + new + { + Id = 6, + IdImage = 6, + Name = "Jon Snow" + }, + new + { + Id = 7, + IdImage = 7, + Name = "Daenerys Targaryen" + }, + new + { + Id = 8, + IdImage = 8, + Name = "Luke Skywalker" + }, + new + { + Id = 9, + IdImage = 9, + Name = "Princess Leia" + }, + new + { + Id = 10, + IdImage = 10, + Name = "Harry Potter" + }); + }); + + modelBuilder.Entity("Entity.Commentary", b => + { + b.Property("IdUser") + .HasColumnType("int"); + + b.Property("IdQuote") + .HasColumnType("int"); + + b.Property("Comment") + .IsRequired() + .HasMaxLength(100) + .HasColumnType("nvarchar(100)"); + + b.Property("DateCommentary") + .HasColumnType("date") + .HasColumnName("DateCommentary"); + + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.HasKey("IdUser", "IdQuote"); + + b.HasIndex("IdQuote"); + + b.ToTable("comments"); + + b.HasData( + new + { + IdUser = 2, + IdQuote = 1, + Comment = "Ce film est le meilleur", + DateCommentary = new DateTime(2025, 2, 3, 0, 0, 0, 0, DateTimeKind.Unspecified), + Id = 1 + }, + new + { + IdUser = 3, + IdQuote = 1, + Comment = "Very good", + DateCommentary = new DateTime(2025, 3, 11, 0, 0, 0, 0, DateTimeKind.Unspecified), + Id = 2 + }); + }); + + modelBuilder.Entity("Entity.DailyQuote", b => + { + b.Property("IdQuote") + .HasColumnType("int"); + + b.HasKey("IdQuote"); + + b.ToTable("dailyquotes"); + + b.HasData( + new + { + IdQuote = 1 + }, + new + { + IdQuote = 5 + }); + }); + + modelBuilder.Entity("Entity.Favorite", b => + { + b.Property("IdQuote") + .HasColumnType("int"); + + b.Property("IdUsers") + .HasColumnType("int"); + + b.HasKey("IdQuote", "IdUsers"); + + b.HasIndex("IdUsers"); + + b.ToTable("favorites"); + + b.HasData( + new + { + IdQuote = 2, + IdUsers = 8 + }, + new + { + IdQuote = 5, + IdUsers = 3 + }, + new + { + IdQuote = 9, + IdUsers = 1 + }, + new + { + IdQuote = 4, + IdUsers = 10 + }, + new + { + IdQuote = 3, + IdUsers = 2 + }, + new + { + IdQuote = 6, + IdUsers = 7 + }, + new + { + IdQuote = 1, + IdUsers = 6 + }, + new + { + IdQuote = 8, + IdUsers = 9 + }, + new + { + IdQuote = 10, + IdUsers = 5 + }); + }); + + modelBuilder.Entity("Entity.Images", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("ImgPath") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.HasKey("Id"); + + b.ToTable("images"); + + b.HasData( + new + { + Id = 1, + ImgPath = "https://th.bing.com/th/id/OIP.TJuWNCsibz8MVmhdNQEdMwHaE8?w=244&h=180&c=7&r=0&o=5&pid=1.7" + }, + new + { + Id = 2, + ImgPath = "https://th.bing.com/th/id/OIP.NgXRQ5-IknA6_qOPFhLWIwHaHK?w=165&h=180&c=7&r=0&o=5&pid=1.7" + }, + new + { + Id = 3, + ImgPath = "https://th.bing.com/th/id/OIP.XcJoJ6bC9sAMjol1pJn5UQHaLH?w=118&h=180&c=7&r=0&o=5&pid=1.7" + }, + new + { + Id = 4, + ImgPath = "https://th.bing.com/th/id/OIP.PPIESqZaNDa-qUcfSDXhdQHaGK?w=210&h=180&c=7&r=0&o=5&pid=1.7" + }, + new + { + Id = 5, + ImgPath = "https://th.bing.com/th/id/OIP.XBghSl2kfRNNtQoSxc901wHaHa?w=177&h=180&c=7&r=0&o=5&pid=1.7" + }, + new + { + Id = 6, + ImgPath = "https://th.bing.com/th/id/OIP.af1Aid64cqEKoIOBgCPxtQHaJO?w=145&h=182&c=7&r=0&o=5&pid=1.7" + }, + new + { + Id = 7, + ImgPath = "https://th.bing.com/th/id/OIP.ri5vSXr5lNTLt4DO6KQXyQHaI4?w=158&h=189&c=7&r=0&o=5&pid=1.7" + }, + new + { + Id = 8, + ImgPath = "https://th.bing.com/th/id/OIP.uPTRLR8uspCiafiunUqKfQHaMJ?w=115&h=180&c=7&r=0&o=5&pid=1.7" + }, + new + { + Id = 9, + ImgPath = "https://th.bing.com/th/id/OIP.hcJis4rKbyQtugsoFJU2ngHaM_?w=118&h=207&c=7&r=0&o=5&pid=1.7" + }, + new + { + Id = 10, + ImgPath = "https://th.bing.com/th/id/OIP.Py1_XfUrKJY_A6tYEmFS5wHaE8?w=280&h=187&c=7&r=0&o=5&pid=1.7" + }); + }); + + modelBuilder.Entity("Entity.Question", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("AnswerA") + .IsRequired() + .HasMaxLength(50) + .HasColumnType("nvarchar(50)"); + + b.Property("AnswerB") + .IsRequired() + .HasMaxLength(50) + .HasColumnType("nvarchar(50)"); + + b.Property("AnswerC") + .IsRequired() + .HasMaxLength(50) + .HasColumnType("nvarchar(50)"); + + b.Property("AnswerD") + .IsRequired() + .HasMaxLength(50) + .HasColumnType("nvarchar(50)"); + + b.Property("CorrectAnswer") + .IsRequired() + .HasMaxLength(1) + .HasColumnType("nvarchar(1)"); + + b.Property("Text") + .IsRequired() + .HasMaxLength(200) + .HasColumnType("nvarchar(200)"); + + b.HasKey("Id"); + + b.ToTable("question"); + + b.HasData( + new + { + Id = 1, + AnswerA = "Gimli", + AnswerB = "Aragorn", + AnswerC = "Frodon", + AnswerD = "Gandalf", + CorrectAnswer = "B", + Text = "Qui est le leader de la Communauté de l'Anneau ?" + }, + new + { + Id = 2, + AnswerA = "Serdaigle", + AnswerB = "Gryffondor", + AnswerC = "Serpentard", + AnswerD = "Poufsouffle", + CorrectAnswer = "B", + Text = "Dans quelle maison Harry Potter est-il ?" + }, + new + { + Id = 3, + AnswerA = "Saroumane", + AnswerB = "Sauron", + AnswerC = "Gollum", + AnswerD = "Gothmog", + CorrectAnswer = "B", + Text = "Qui est le Seigneur des Ténèbres dans la saga Le Seigneur des Anneaux ?" + }, + new + { + Id = 4, + AnswerA = "Han Solo", + AnswerB = "Princesse Leia", + AnswerC = "Chewbacca", + AnswerD = "R2-D2", + CorrectAnswer = "A", + Text = "Dans le film Star Wars : Episode IV, qui sauve Luke Skywalker de l'Étoile de la Mort ?" + }, + new + { + Id = 5, + AnswerA = "Reine Jadis", + AnswerB = "Aslan", + AnswerC = "Edmund", + AnswerD = "Lucy", + CorrectAnswer = "B", + Text = "Qui est le souverain de Narnia dans Le Lion, la Sorcière Blanche et l'Armoire Magique ?" + }, + new + { + Id = 6, + AnswerA = "Smaug", + AnswerB = "Falkor", + AnswerC = "Norbert", + AnswerD = "Shenron", + CorrectAnswer = "A", + Text = "Quel est le nom du dragon dans Le Hobbit ?" + }, + new + { + Id = 7, + AnswerA = "Bella Swan", + AnswerB = "Edward Cullen", + AnswerC = "Jacob Black", + AnswerD = "Victoria", + CorrectAnswer = "A", + Text = "Qui est la première personne à être mordue par un vampire dans Twilight ?" + }, + new + { + Id = 8, + AnswerA = "Obi-Wan Kenobi", + AnswerB = "Yoda", + AnswerC = "Han Solo", + AnswerD = "Luke Skywalker", + CorrectAnswer = "A", + Text = "Quel personnage dit Que la Force soit avec toi dans Star Wars ?" + }, + new + { + Id = 9, + AnswerA = "Dr. Ellie Sattler", + AnswerB = "Alan Grant", + AnswerC = "John Hammond", + AnswerD = "Dennis Nedry", + CorrectAnswer = "B", + Text = "Dans Jurassic Park, quel est le nom du paléontologue sur l'île ?" + }, + new + { + Id = 10, + AnswerA = "Cersei Lannister", + AnswerB = "Arya Stark", + AnswerC = "Daenerys Targaryen", + AnswerD = "Sansa Stark", + CorrectAnswer = "C", + Text = "Dans Game of Thrones, qui est surnommée la Mère des Dragons ?" + }); + }); + + modelBuilder.Entity("Entity.Quiz", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("IdImage") + .HasColumnType("int"); + + b.Property("NbQuestion") + .HasColumnType("int"); + + b.Property("Title") + .IsRequired() + .HasMaxLength(50) + .HasColumnType("nvarchar(50)"); + + b.HasKey("Id"); + + b.HasIndex("IdImage"); + + b.ToTable("quizzes"); + + b.HasData( + new + { + Id = 1, + IdImage = 1, + NbQuestion = 5, + Title = "Quiz 1" + }, + new + { + Id = 2, + IdImage = 2, + NbQuestion = 5, + Title = "Quiz 2" + }); + }); + + modelBuilder.Entity("Entity.QuizQuestion", b => + { + b.Property("IdQuestion") + .HasColumnType("int"); + + b.Property("IdQuiz") + .HasColumnType("int"); + + b.HasKey("IdQuestion", "IdQuiz"); + + b.HasIndex("IdQuiz"); + + b.ToTable("QuizQuestion"); + + b.HasData( + new + { + IdQuestion = 1, + IdQuiz = 1 + }, + new + { + IdQuestion = 2, + IdQuiz = 1 + }, + new + { + IdQuestion = 3, + IdQuiz = 1 + }, + new + { + IdQuestion = 4, + IdQuiz = 1 + }, + new + { + IdQuestion = 5, + IdQuiz = 1 + }, + new + { + IdQuestion = 6, + IdQuiz = 2 + }, + new + { + IdQuestion = 7, + IdQuiz = 2 + }, + new + { + IdQuestion = 8, + IdQuiz = 2 + }, + new + { + IdQuestion = 9, + IdQuiz = 2 + }, + new + { + IdQuestion = 10, + IdQuiz = 2 + }); + }); + + modelBuilder.Entity("Entity.Quote", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("Content") + .IsRequired() + .HasMaxLength(100) + .HasColumnType("nvarchar(100)"); + + b.Property("IdCharacter") + .HasColumnType("int"); + + b.Property("IdSource") + .HasColumnType("int"); + + b.Property("IdUsersPropose") + .HasColumnType("int"); + + b.Property("IsValid") + .HasColumnType("bit"); + + b.Property("Langage") + .HasColumnType("int"); + + b.Property("Likes") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.HasIndex("IdCharacter"); + + b.HasIndex("IdSource"); + + b.HasIndex("IdUsersPropose"); + + b.ToTable("quotes"); + + b.HasData( + new + { + Id = 1, + Content = "Je n'y crois pas. Je n'y crois pas. Ce n'est pas possible", + IdCharacter = 1, + IdSource = 1, + IdUsersPropose = 1, + IsValid = true, + Langage = 1, + Likes = 11025 + }, + new + { + Id = 2, + Content = "There is always hope", + IdCharacter = 2, + IdSource = 2, + IdUsersPropose = 1, + IsValid = true, + Langage = 0, + Likes = 11025 + }, + new + { + Id = 3, + Content = "A red sun rises. Blood has been spilled this night.", + IdCharacter = 3, + IdSource = 2, + IdUsersPropose = 1, + IsValid = true, + Langage = 0, + Likes = 11025 + }, + new + { + Id = 4, + Content = "I wish the Ring had never come to me.I wish none of this had happened.", + IdCharacter = 4, + IdSource = 2, + IdUsersPropose = 1, + IsValid = true, + Langage = 0, + Likes = 11025 + }, + new + { + Id = 5, + Content = "Dobby is a free elf!", + IdCharacter = 5, + IdSource = 4, + IdUsersPropose = 1, + IsValid = true, + Langage = 0, + Likes = 11025 + }, + new + { + Id = 6, + Content = "Winter is comming", + IdCharacter = 6, + IdSource = 3, + IdUsersPropose = 1, + IsValid = true, + Langage = 0, + Likes = 11025 + }, + new + { + Id = 7, + Content = "Je suis la dernière Targaryen. Je suis la reine des dragons", + IdCharacter = 7, + IdSource = 3, + IdUsersPropose = 1, + IsValid = true, + Langage = 1, + Likes = 11025 + }, + new + { + Id = 8, + Content = "Je ne suis pas prêt à affronter ça. C'est trop pour moi.", + IdCharacter = 8, + IdSource = 5, + IdUsersPropose = 1, + IsValid = true, + Langage = 1, + Likes = 11025 + }, + new + { + Id = 9, + Content = "Aidez-moi, Obi-Wan Kenobi, vous êtes mon seul espoir.", + IdCharacter = 9, + IdSource = 5, + IdUsersPropose = 1, + IsValid = true, + Langage = 1, + Likes = 11025 + }, + new + { + Id = 10, + Content = "La quoi ?", + IdCharacter = 10, + IdSource = 4, + IdUsersPropose = 1, + IsValid = true, + Langage = 1, + Likes = 11025 + }); + }); + + modelBuilder.Entity("Entity.Source", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("Title") + .IsRequired() + .HasMaxLength(100) + .HasColumnType("nvarchar(100)"); + + b.Property("TypeSrc") + .HasColumnType("int"); + + b.Property("Year") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.ToTable("sources"); + + b.HasData( + new + { + Id = 1, + Title = "Jurassic Park", + TypeSrc = 0, + Year = 1993 + }, + new + { + Id = 2, + Title = "Le Seigneur des anneaux : La Communauté de l'anneau", + TypeSrc = 0, + Year = 2001 + }, + new + { + Id = 3, + Title = "Game of throne", + TypeSrc = 1, + Year = 2011 + }, + new + { + Id = 4, + Title = "Harry Potter à l'école des sorcier", + TypeSrc = 0, + Year = 1997 + }, + new + { + Id = 5, + Title = "Star Wars, épisode IV : Un nouvel espoir", + TypeSrc = 0, + Year = 1977 + }); + }); + + modelBuilder.Entity("Entity.Users", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("Created") + .HasColumnType("date") + .HasColumnName("Created"); + + b.Property("Email") + .IsRequired() + .HasMaxLength(50) + .HasColumnType("nvarchar(50)"); + + b.Property("IdImage") + .HasColumnType("int"); + + b.Property("Password") + .IsRequired() + .HasMaxLength(200) + .HasColumnType("nvarchar(200)"); + + b.Property("UserName") + .IsRequired() + .HasMaxLength(50) + .HasColumnType("nvarchar(50)"); + + b.HasKey("Id"); + + b.HasIndex("IdImage"); + + b.ToTable("users"); + + b.HasData( + new + { + Id = 1, + Created = new DateTime(2025, 5, 12, 0, 0, 0, 0, DateTimeKind.Unspecified), + Email = "jhonDhoe@gmail.com", + IdImage = 1, + Password = "1234", + UserName = "Jhon-Dhoe" + }, + new + { + Id = 2, + Created = new DateTime(2025, 3, 19, 0, 0, 0, 0, DateTimeKind.Unspecified), + Email = "lucy_rose@outlook.com", + IdImage = 2, + Password = "abcd", + UserName = "Lucy-Rose" + }, + new + { + Id = 3, + Created = new DateTime(2024, 11, 2, 0, 0, 0, 0, DateTimeKind.Unspecified), + Email = "mark.taylor@yahoo.com", + IdImage = 3, + Password = "5678", + UserName = "Mark-Taylor" + }, + new + { + Id = 4, + Created = new DateTime(2025, 2, 28, 0, 0, 0, 0, DateTimeKind.Unspecified), + Email = "sophie.martin@gmail.com", + IdImage = 4, + Password = "4321", + UserName = "Sophie-Martin" + }, + new + { + Id = 5, + Created = new DateTime(2025, 1, 15, 0, 0, 0, 0, DateTimeKind.Unspecified), + Email = "nathan_doe@aol.com", + IdImage = 5, + Password = "8765", + UserName = "Nathan-Doe" + }, + new + { + Id = 6, + Created = new DateTime(2025, 4, 7, 0, 0, 0, 0, DateTimeKind.Unspecified), + Email = "ella.brown@icloud.com", + IdImage = 6, + Password = "2468", + UserName = "Ella-Brown" + }, + new + { + Id = 7, + Created = new DateTime(2024, 12, 25, 0, 0, 0, 0, DateTimeKind.Unspecified), + Email = "oliver_smith@gmail.com", + IdImage = 7, + Password = "1357", + UserName = "Oliver-Smith" + }, + new + { + Id = 8, + Created = new DateTime(2025, 3, 5, 0, 0, 0, 0, DateTimeKind.Unspecified), + Email = "mia.jones@outlook.com", + IdImage = 8, + Password = "1122", + UserName = "Mia-Jones" + }, + new + { + Id = 9, + Created = new DateTime(2025, 2, 22, 0, 0, 0, 0, DateTimeKind.Unspecified), + Email = "kevin_williams@aol.com", + IdImage = 9, + Password = "2233", + UserName = "Kevin-Williams" + }, + new + { + Id = 10, + Created = new DateTime(2025, 1, 3, 0, 0, 0, 0, DateTimeKind.Unspecified), + Email = "olivia.white@yahoo.com", + IdImage = 10, + Password = "3344", + UserName = "Olivia-White" + }); + }); + + modelBuilder.Entity("Entity.Character", b => + { + b.HasOne("Entity.Images", "Images") + .WithMany("Characters") + .HasForeignKey("IdImage") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Images"); + }); + + modelBuilder.Entity("Entity.Commentary", b => + { + b.HasOne("Entity.Quote", "Quote") + .WithMany("Commentarys") + .HasForeignKey("IdQuote") + .OnDelete(DeleteBehavior.ClientCascade) + .IsRequired(); + + b.HasOne("Entity.Users", "User") + .WithMany() + .HasForeignKey("IdUser") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Quote"); + + b.Navigation("User"); + }); + + modelBuilder.Entity("Entity.DailyQuote", b => + { + b.HasOne("Entity.Quote", "Quote") + .WithMany("DailyQuotes") + .HasForeignKey("IdQuote") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Quote"); + }); + + modelBuilder.Entity("Entity.Favorite", b => + { + b.HasOne("Entity.Quote", "Quote") + .WithMany() + .HasForeignKey("IdQuote") + .OnDelete(DeleteBehavior.ClientCascade) + .IsRequired(); + + b.HasOne("Entity.Users", "Users") + .WithMany() + .HasForeignKey("IdUsers") + .OnDelete(DeleteBehavior.ClientCascade) + .IsRequired(); + + b.Navigation("Quote"); + + b.Navigation("Users"); + }); + + modelBuilder.Entity("Entity.Quiz", b => + { + b.HasOne("Entity.Images", "Images") + .WithMany("Quizs") + .HasForeignKey("IdImage") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Images"); + }); + + modelBuilder.Entity("Entity.QuizQuestion", b => + { + b.HasOne("Entity.Question", null) + .WithMany() + .HasForeignKey("IdQuestion") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("Entity.Quiz", null) + .WithMany() + .HasForeignKey("IdQuiz") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("Entity.Quote", b => + { + b.HasOne("Entity.Character", "Character") + .WithMany("Quotes") + .HasForeignKey("IdCharacter") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("Entity.Source", "Source") + .WithMany("Quotes") + .HasForeignKey("IdSource") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("Entity.Users", "User") + .WithMany("Quotes") + .HasForeignKey("IdUsersPropose"); + + b.Navigation("Character"); + + b.Navigation("Source"); + + b.Navigation("User"); + }); + + modelBuilder.Entity("Entity.Users", b => + { + b.HasOne("Entity.Images", "Images") + .WithMany("Users") + .HasForeignKey("IdImage") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Images"); + }); + + modelBuilder.Entity("Entity.Character", b => + { + b.Navigation("Quotes"); + }); + + modelBuilder.Entity("Entity.Images", b => + { + b.Navigation("Characters"); + + b.Navigation("Quizs"); + + b.Navigation("Users"); + }); + + modelBuilder.Entity("Entity.Quote", b => + { + b.Navigation("Commentarys"); + + b.Navigation("DailyQuotes"); + }); + + modelBuilder.Entity("Entity.Source", b => + { + b.Navigation("Quotes"); + }); + + modelBuilder.Entity("Entity.Users", b => + { + b.Navigation("Quotes"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/WF_EF_Api/StubbedContextLib/Migrations/20250318135625_migr1.cs b/WF_EF_Api/StubbedContextLib/Migrations/20250318135625_migr1.cs new file mode 100644 index 0000000..00b10fb --- /dev/null +++ b/WF_EF_Api/StubbedContextLib/Migrations/20250318135625_migr1.cs @@ -0,0 +1,22 @@ +using Microsoft.EntityFrameworkCore.Migrations; + +#nullable disable + +namespace StubbedContextLib.Migrations +{ + /// + public partial class migr1 : Migration + { + /// + protected override void Up(MigrationBuilder migrationBuilder) + { + + } + + /// + protected override void Down(MigrationBuilder migrationBuilder) + { + + } + } +} From eb71b3aba19965bef263b219db2bcd409c01da8b Mon Sep 17 00:00:00 2001 From: Leni BEAULATON Date: Wed, 19 Mar 2025 10:23:51 +0100 Subject: [PATCH 14/65] Ajout et suppression user API --- WF_EF_Api/StubApi/UserService.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/WF_EF_Api/StubApi/UserService.cs b/WF_EF_Api/StubApi/UserService.cs index 4ce870b..2b812e7 100644 --- a/WF_EF_Api/StubApi/UserService.cs +++ b/WF_EF_Api/StubApi/UserService.cs @@ -36,7 +36,7 @@ namespace StubApi public async Task AddUser(UserDTO user) { - throw new NotImplementedException(); + _users.Add(user); } public async Task CountUser() @@ -94,7 +94,7 @@ namespace StubApi public async Task RemoveUser(UserDTO user) { - throw new NotImplementedException(); + _users.Remove(user); } public async Task SetAdminRole(bool isAdmin) From f726c7c7453b52b31ea95fecd25e7a48bfda69eb Mon Sep 17 00:00:00 2001 From: Leni BEAULATON Date: Wed, 19 Mar 2025 11:46:30 +0100 Subject: [PATCH 15/65] REST API + Documentation --- WF_EF_Api/Shared/IUserService.cs | 2 +- WF_EF_Api/StubApi/UserService.cs | 19 +- .../WfApi/Controllers/UsersController.cs | 414 ++++++++++++++++-- 3 files changed, 396 insertions(+), 39 deletions(-) diff --git a/WF_EF_Api/Shared/IUserService.cs b/WF_EF_Api/Shared/IUserService.cs index 29fe4bf..74bf04a 100644 --- a/WF_EF_Api/Shared/IUserService.cs +++ b/WF_EF_Api/Shared/IUserService.cs @@ -35,7 +35,7 @@ namespace Shared // Updates the details of an existing user identified by 'userId'. // 'userId' is the ID of the user to be updated, and 'user' contains the new user data. - Task UpdateUser(int userId, TUser user, TUser existingUser); + Task UpdateUser(int userId, TUser user); // Removes a user from the system based on their unique identifier ('userId'). // 'userId' is the unique identifier of the user to be removed. diff --git a/WF_EF_Api/StubApi/UserService.cs b/WF_EF_Api/StubApi/UserService.cs index 2b812e7..315d9a5 100644 --- a/WF_EF_Api/StubApi/UserService.cs +++ b/WF_EF_Api/StubApi/UserService.cs @@ -104,16 +104,19 @@ namespace StubApi - public async Task UpdateUser(int userId, UserDTO user, UserDTO existingUser) + public async Task UpdateUser(int userId, UserDTO user) { - + UserDTO userUpdate = new UserDTO(); + userUpdate = GetUserById(userId).Result; + // Update users properties - existingUser.Pseudo = user.Pseudo; - existingUser.Password = user.Password; - existingUser.Email = user.Email; - existingUser.date = user.date; - existingUser.ImageProfil = user.ImageProfil; - return existingUser; + userUpdate.Pseudo = user.Pseudo; + userUpdate.Password = user.Password; + userUpdate.Email = user.Email; + userUpdate.date = user.date; + userUpdate.ImageProfil = user.ImageProfil; + + return userUpdate; } } } diff --git a/WF_EF_Api/WfApi/Controllers/UsersController.cs b/WF_EF_Api/WfApi/Controllers/UsersController.cs index a60300f..400c835 100644 --- a/WF_EF_Api/WfApi/Controllers/UsersController.cs +++ b/WF_EF_Api/WfApi/Controllers/UsersController.cs @@ -21,8 +21,34 @@ namespace WfApi.Controllers } //===================================== ROUTE GET ===================================== - - [HttpGet("id/{id}")] // Indiquer que l'id est dans l'URL + /// + /// Gets a user by their unique identifier. + /// + /// The unique identifier of the user + /// + /// + /// ## **Sample request**: + /// + /// GET /users/{id} + /// + /// Where `{id}` is the unique identifier of the user you want to retrieve. + /// + /// ## **Returns** + /// + /// - **200 OK** : Returns the user data if the user with the given ID exists. + /// - **204 No Content** : No user found for the provided ID, or the operation failed. + /// - **500 Internal Server Error** : If there is an exception during the process. + /// + /// ## **Error Handling** + /// - In case of an internal server error (e.g., database issues), a `500 Internal Server Error` will be returned with an error message. + /// + /// Returns the user data corresponding to the provided ID + /// No content if no user is found or the operation fails + /// Internal server error in case of an exception + [ProducesResponseType(StatusCodes.Status200OK)] + [ProducesResponseType(StatusCodes.Status204NoContent)] + [ProducesResponseType(StatusCodes.Status500InternalServerError)] + [HttpGet("{id}")] // Indiquer que l'id est dans l'URL public async Task Get(int id) { try @@ -45,7 +71,35 @@ namespace WfApi.Controllers } - [HttpGet("all")] // Indiquer que l'id est dans l'URL + /// + /// Gets a list of users with pagination support. + /// + /// The index of the page to retrieve (default is 0) + /// The number of users to retrieve per page (default is 5) + /// + /// + /// ## **Sample request**: + /// + /// GET /users/all?index=0&count=5 + /// + /// The `index` parameter specifies the page number to retrieve (starting from 0), and the `count` parameter specifies how many users to return per page. + /// + /// ## **Returns** + /// + /// - **200 OK** : Returns a list of users if the operation is successful. + /// - **204 No Content** : If no users are found or the operation fails. + /// - **500 Internal Server Error** : If there is an exception during the execution of the request. + /// + /// ## **Error Handling** + /// - In case of an internal server error (e.g., database issues), a `500 Internal Server Error` is returned with an error message. + /// + /// Returns a list of users + /// No content if no users are found or the operation fails + /// Internal server error in case of an exception + [HttpGet("all")] + [ProducesResponseType(StatusCodes.Status200OK)] + [ProducesResponseType(StatusCodes.Status204NoContent)] + [ProducesResponseType(StatusCodes.Status500InternalServerError)] public async Task GetAllUsers(int index = 0, int count = 5) { try @@ -68,9 +122,45 @@ namespace WfApi.Controllers } - [HttpGet("hashpassword/{username}")] // Indiquer que l'id est dans l'URL - public async Task GetHashPassword(string username) + /// + /// Gets the hashed password for a given username. + /// + /// The username to retrieve the hashed password for + /// + /// + /// ## **Sample request**: + /// + /// GET /users/hashpassword?username=johndoe + /// + /// The `username` parameter specifies the username for which to retrieve the hashed password. + /// + /// ## **Returns** + /// + /// - **200 OK** : Returns the hashed password for the user if the username exists. + /// - **400 Bad Request** : If no username is provided or if the username is invalid. + /// - **204 No Content** : If no hashed password is found for the provided username. + /// - **500 Internal Server Error** : If an exception occurs while processing the request. + /// + /// ## **Error Handling** + /// - In case of a missing or invalid `username`, a `400 Bad Request` is returned with a relevant message. + /// - If there is an exception during the process (e.g., database errors), a `500 Internal Server Error` is returned. + /// + /// Returns the hashed password for the provided username + /// Bad request if no username is provided or invalid + /// No content if no hashed password is found + /// Internal server error in case of an exception + [HttpGet("hashpassword")] + [ProducesResponseType(StatusCodes.Status200OK)] + [ProducesResponseType(StatusCodes.Status400BadRequest)] + [ProducesResponseType(StatusCodes.Status204NoContent)] + [ProducesResponseType(StatusCodes.Status500InternalServerError)] + public async Task GetHashPassword([FromQuery] string username) { + if (string.IsNullOrWhiteSpace(username)) + { + return BadRequest(new { message = "No user defined" }); + } + try { var result = _user.GetHashPassword(username); @@ -91,9 +181,45 @@ namespace WfApi.Controllers } - [HttpGet("username/{username}")] // Indiquer que l'id est dans l'URL - public async Task GetUserByUsername(string username) + /// + /// Gets a user by their username. + /// + /// The username to retrieve the user + /// + /// + /// ## **Sample request**: + /// + /// GET /users/username?username=johndoe + /// + /// The `username` parameter specifies the username of the user you want to retrieve. + /// + /// ## **Returns** + /// + /// - **200 OK** : Returns the user data if the username exists. + /// - **400 Bad Request** : If no username is provided or if the username is invalid. + /// - **204 No Content** : If no user is found with the provided username. + /// - **500 Internal Server Error** : If an exception occurs while processing the request. + /// + /// ## **Error Handling** + /// - In case of a missing or invalid `username`, a `400 Bad Request` is returned with a relevant message. + /// - If there is an exception during the process (e.g., database errors), a `500 Internal Server Error` is returned. + /// + /// Returns the user data for the provided username + /// Bad request if no username is provided or invalid + /// No content if no user is found with the provided username + /// Internal server error in case of an exception + [HttpGet("username")] + [ProducesResponseType(StatusCodes.Status200OK)] + [ProducesResponseType(StatusCodes.Status400BadRequest)] + [ProducesResponseType(StatusCodes.Status204NoContent)] + [ProducesResponseType(StatusCodes.Status500InternalServerError)] + public async Task GetUserByUsername([FromQuery] string username) { + if (string.IsNullOrWhiteSpace(username)) + { + return BadRequest(new { message = "No user defined" }); + } + try { var result = _user.GetUserByUsername(username); @@ -112,9 +238,46 @@ namespace WfApi.Controllers return StatusCode((int)HttpStatusCode.InternalServerError, new { message = "Internal Server Error" }); } } - [HttpGet("email/{email}")] // Indiquer que l'id est dans l'URL - public async Task GetUserByEmail(string email) + + + /// + /// Gets a user by their email address. + /// + /// The email address of the user + /// + /// + /// ## **Sample request**: + /// + /// GET /users/email?email=johndoe@example.com + /// + /// The `email` parameter specifies the email address of the user you want to retrieve. + /// + /// ## **Returns** + /// + /// - **200 OK** : Returns the user data if the email exists. + /// - **400 Bad Request** : If no email is provided or if the email is invalid. + /// - **204 No Content** : If no user is found with the provided email. + /// - **500 Internal Server Error** : If an exception occurs while processing the request. + /// + /// ## **Error Handling** + /// - In case of a missing or invalid `email`, a `400 Bad Request` is returned with a relevant message. + /// - If there is an exception during the process (e.g., database errors), a `500 Internal Server Error` is returned. + /// + /// Returns the user data for the provided email + /// Bad request if no email is provided or invalid + /// No content if no user is found with the provided email + /// Internal server error in case of an exception + [HttpGet("email")] + [ProducesResponseType(StatusCodes.Status200OK)] + [ProducesResponseType(StatusCodes.Status400BadRequest)] + [ProducesResponseType(StatusCodes.Status204NoContent)] + [ProducesResponseType(StatusCodes.Status500InternalServerError)] + public async Task GetUserByEmail([FromQuery] string email) { + if (string.IsNullOrWhiteSpace(email)) + { + return BadRequest(new { message = "No user email defined" }); + } try { var result = _user.GetUserByEmail(email); @@ -135,7 +298,33 @@ namespace WfApi.Controllers } - [HttpGet("countuser")] // Indiquer que l'id est dans l'URL + /// + /// Gets the total number of users. + /// + /// + /// + /// ## **Sample request**: + /// + /// GET /users/count + /// + /// This endpoint returns the total number of users present in the system. + /// + /// ## **Returns** + /// + /// - **200 OK** : Returns the total count of users. + /// - **204 No Content** : If no users are found or the operation fails. + /// - **500 Internal Server Error** : If an exception occurs while processing the request. + /// + /// ## **Error Handling** + /// - In case of an exception during the process (e.g., database errors), a `500 Internal Server Error` is returned with a relevant message. + /// + /// Returns the total count of users + /// No content if the count could not be retrieved + /// Internal server error in case of an exception + [HttpGet("count")] + [ProducesResponseType(StatusCodes.Status200OK)] + [ProducesResponseType(StatusCodes.Status204NoContent)] + [ProducesResponseType(StatusCodes.Status500InternalServerError)] public async Task GetCountUser() { try @@ -159,9 +348,45 @@ namespace WfApi.Controllers - [HttpGet("existusername/{username}")] // Indiquer que l'id est dans l'URL - public async Task GetExistUsername(string username) + /// + /// Checks if a user exists by their username. + /// + /// The username to check for existence + /// + /// + /// ## **Sample request**: + /// + /// GET /users/existusername?username=johndoe + /// + /// The `username` parameter specifies the username to check if it exists in the system. + /// + /// ## **Returns** + /// + /// - **200 OK** : If the username exists, returns a success message. + /// - **400 Bad Request** : If no username is provided or if the username is invalid. + /// - **404 Not Found** : If the user with the specified username does not exist. + /// - **500 Internal Server Error** : If an exception occurs while processing the request. + /// + /// ## **Error Handling** + /// - In case of a missing or invalid `username`, a `400 Bad Request` is returned with a relevant message. + /// - If the user does not exist, a `404 Not Found` response is returned. + /// - If there is an exception during the process (e.g., database errors), a `500 Internal Server Error` is returned with an appropriate message. + /// + /// Returns a success message if the username exists + /// Bad request if no username is provided or invalid + /// Not found if the user with the provided username does not exist + /// Internal server error in case of an exception + [HttpGet("existusername")] + [ProducesResponseType(StatusCodes.Status200OK)] + [ProducesResponseType(StatusCodes.Status400BadRequest)] + [ProducesResponseType(StatusCodes.Status404NotFound)] + [ProducesResponseType(StatusCodes.Status500InternalServerError)] + public async Task GetExistUsername([FromQuery] string username) { + if (string.IsNullOrWhiteSpace(username)) + { + return BadRequest(new { message = "No user defined" }); + } try { var result = _user.ExistUsername(username); @@ -172,7 +397,7 @@ namespace WfApi.Controllers } else { - return NoContent(); + return NotFound("User not found"); } } catch (Exception) @@ -182,9 +407,45 @@ namespace WfApi.Controllers } - [HttpGet("existemail/{email}")] // Indiquer que l'id est dans l'URL - public async Task GetExistEmail(string email) + /// + /// Checks if a user exists by their email address. + /// + /// The email address to check for existence + /// + /// + /// ## **Sample request**: + /// + /// GET /users/existemail?email=johndoe@example.com + /// + /// The `email` parameter specifies the email address to check if it exists in the system. + /// + /// ## **Returns** + /// + /// - **200 OK** : If the email exists, returns a success message. + /// - **400 Bad Request** : If no email is provided or if the email is invalid. + /// - **404 Not Found** : If the user with the specified email does not exist. + /// - **500 Internal Server Error** : If an exception occurs while processing the request. + /// + /// ## **Error Handling** + /// - In case of a missing or invalid `email`, a `400 Bad Request` is returned with a relevant message. + /// - If the user does not exist, a `404 Not Found` response is returned. + /// - If there is an exception during the process (e.g., database errors), a `500 Internal Server Error` is returned with an appropriate message. + /// + /// Returns a success message if the email exists + /// Bad request if no email is provided or invalid + /// Not found if the user with the provided email does not exist + /// Internal server error in case of an exception + [HttpGet("existemail")] + [ProducesResponseType(StatusCodes.Status200OK)] + [ProducesResponseType(StatusCodes.Status400BadRequest)] + [ProducesResponseType(StatusCodes.Status404NotFound)] + [ProducesResponseType(StatusCodes.Status500InternalServerError)] + public async Task GetExistEmail([FromQuery] string email) { + if (string.IsNullOrWhiteSpace(email)) + { + return BadRequest(new { message = "No user email defined" }); + } try { var result = _user.ExistEmail(email); @@ -195,7 +456,7 @@ namespace WfApi.Controllers } else { - return NoContent(); + return NotFound("User email not found"); } } catch (Exception) @@ -207,7 +468,42 @@ namespace WfApi.Controllers //===================================== ROUTE PUT ===================================== + /// + /// Updates an existing user's data. + /// + /// The ID of the user to update + /// The updated user data + /// + /// + /// ## **Sample request**: + /// + /// PUT /users?id=1 + /// Body: + /// { + /// "username": "newusername", + /// "email": "newemail@example.com", + /// "fullName": "New Name" + /// } + /// + /// The `id` parameter specifies the user ID to be updated, and the body contains the updated user data. + /// + /// ## **Returns** + /// + /// - **200 OK** : If the user was successfully updated. + /// - **400 Bad Request** : If the provided user data is invalid or missing. + /// - **500 Internal Server Error** : If an error occurs while processing the update. + /// + /// ## **Error Handling** + /// - If the `updateduser` object is `null`, a `400 Bad Request` is returned with a message indicating that player data is required. + /// - If an exception occurs during the process (e.g., database errors), a `500 Internal Server Error` is returned with an appropriate message. + /// + /// Returns the updated user data + /// Bad request if no user data is provided or invalid + /// Internal server error in case of an exception [HttpPut()] + [ProducesResponseType(StatusCodes.Status200OK)] + [ProducesResponseType(StatusCodes.Status400BadRequest)] + [ProducesResponseType(StatusCodes.Status500InternalServerError)] public async Task UpdateUser([FromQuery] int id, [FromBody] UserDTO updateduser) { try @@ -217,18 +513,11 @@ namespace WfApi.Controllers return BadRequest(new { message = "Player data is required." }); } - - var existingUser = _user.GetUserById(id).Result; - if (existingUser == null) - { - return NotFound(new { message = "Player not found." }); - } - - var result = _user.UpdateUser(id,updateduser,existingUser); + var result = _user.UpdateUser(id,updateduser); return Ok(result); } - catch (Exception ex) + catch (Exception) { return StatusCode((int)HttpStatusCode.InternalServerError, new { message = "Internal server error." }); } @@ -238,8 +527,47 @@ namespace WfApi.Controllers //===================================== ROUTE POST ===================================== + /// + /// Creates a new user in the system. + /// + /// The user data to create the new user + /// + /// + /// ## **Sample request**: + /// + /// POST /users + /// Body: + /// { + /// "id": 123, + /// "username": "newuser", + /// "email": "newuser@example.com", + /// "fullName": "New User" + /// } + /// + /// The `newUser` parameter in the body contains the data of the new user to be created. + /// + /// ## **Returns** + /// + /// - **201 Created** : If the user was successfully created. The location of the created resource is returned in the response header. + /// - **400 Bad Request** : If the provided user data is invalid or missing. + /// - **409 Conflict** : If a user with the specified ID already exists. + /// - **500 Internal Server Error** : If an error occurs while processing the creation of the user. + /// + /// ## **Error Handling** + /// - If the `newUser` object is `null`, a `400 Bad Request` is returned with a message indicating that user data is required. + /// - If the user already exists (based on `Id`), a `409 Conflict` is returned with a message indicating that a user with this ID already exists. + /// - If there is an exception during the process (e.g., database errors), a `500 Internal Server Error` is returned with an appropriate message. + /// + /// Returns the created user and its location + /// Bad request if no user data is provided or invalid + /// Conflict if a user with the same ID already exists + /// Internal server error in case of an exception [HttpPost] - public async Task CreatePlayer([FromBody] UserDTO newUser) + [ProducesResponseType(StatusCodes.Status201Created)] + [ProducesResponseType(StatusCodes.Status400BadRequest)] + [ProducesResponseType(StatusCodes.Status409Conflict)] + [ProducesResponseType(StatusCodes.Status500InternalServerError)] + public async Task CreateUser([FromBody] UserDTO newUser) { try { @@ -258,7 +586,7 @@ namespace WfApi.Controllers return CreatedAtAction(nameof(GetAllUsers), new { id = newUser.Id }, newUser); } - catch (Exception ex) + catch (Exception) { return StatusCode((int)HttpStatusCode.InternalServerError, new { message = "Erreur interne du serveur." }); } @@ -268,7 +596,35 @@ namespace WfApi.Controllers //===================================== ROUTE DELETE ===================================== + /// + /// Deletes a player by their ID. + /// + /// The ID of the player to be deleted + /// + /// + /// ## **Sample request**: + /// + /// DELETE /api/v1/players?id=51 + /// + /// The `id` parameter specifies the ID of the player to be deleted. + /// + /// ## **Returns** + /// + /// - **200 OK** : If the player was successfully deleted, a success message is returned. + /// - **404 Not Found** : If no player with the given ID is found. + /// - **500 Internal Server Error** : If an error occurs while deleting the player. + /// + /// ## **Error Handling** + /// - If no player is found with the specified `id`, a `404 Not Found` response is returned with a message "Player not found." + /// - If there is an exception during the process (e.g., database errors), a `500 Internal Server Error` response is returned with a message "Internal server error." + /// + /// Returns a success message indicating the player was deleted + /// Not found if no player with the specified ID is found + /// Internal server error in case of an exception [HttpDelete] // /api/v1/players?id=51 + [ProducesResponseType(StatusCodes.Status200OK)] + [ProducesResponseType(StatusCodes.Status404NotFound)] + [ProducesResponseType(StatusCodes.Status500InternalServerError)] public async Task DeletePlayer([FromQuery] int id) { try @@ -284,12 +640,10 @@ namespace WfApi.Controllers return Ok(new { message = $"Player {id} deleted successfully." }); } - catch (Exception ex) + catch (Exception) { return StatusCode((int)HttpStatusCode.InternalServerError, new { message = "Internal server error." }); } } - - } } From 925592aa8163a6f474ee154c02b2eddc3f1b986c Mon Sep 17 00:00:00 2001 From: Leni BEAULATON Date: Wed, 19 Mar 2025 11:55:12 +0100 Subject: [PATCH 16/65] drone.yml --- .drone.yml | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 .drone.yml diff --git a/.drone.yml b/.drone.yml new file mode 100644 index 0000000..6b39127 --- /dev/null +++ b/.drone.yml @@ -0,0 +1,23 @@ +image: mcr.microsoft.com/dotnet/sdk:8.0 + +volumes: + - name: docs + path: /docs + +- dotnet new tool-manifest +- dotnet tool install NSwag.ConsoleCore +- dotnet nswag aspnetcore2openapi /output:/docs/swagger.json + +volumes: +- name: docs + temp: {} + +image: hub.codefirst.iut.uca.fr/thomas.bellembois/codefirst-docdeployer +volumes: + - name: docs + path: /docs + +commands: + - /entrypoint.sh + +depends_on: [ previous_job_name ] \ No newline at end of file From 2ec1bc76a41d4ef09013ef53b2205c0d29a6cb9f Mon Sep 17 00:00:00 2001 From: kekentin Date: Wed, 19 Mar 2025 12:00:52 +0100 Subject: [PATCH 17/65] Avancement Service Quote --- WF_EF_Api/StubApi/QuoteService.cs | 12 ++--- .../WfApi/Controllers/QuotesController.cs | 45 ++++++++++++++++++- WF_EF_Api/WfApi/WfApi.csproj | 1 + 3 files changed, 51 insertions(+), 7 deletions(-) diff --git a/WF_EF_Api/StubApi/QuoteService.cs b/WF_EF_Api/StubApi/QuoteService.cs index d45e6b6..e05f3ae 100644 --- a/WF_EF_Api/StubApi/QuoteService.cs +++ b/WF_EF_Api/StubApi/QuoteService.cs @@ -39,22 +39,22 @@ namespace StubApi }; } - public async Task AddQuote(QuoteDTO quote) + public async Task AddQuote(QuoteDTO quote) { - throw new NotImplementedException(); + _quotes.Add(quote); } public async Task CountQuotes() { - throw new NotImplementedException(); + return _quotes.Count; } public async Task> GetAllQuote() { - throw new NotImplementedException(); + return new PaginationResult(_quotes.Count, 0, _quotes.Count, _quotes); } - public async Task> GetAllQuoteLang(int index, int pageSize, int lang) + public async Task> GetAllQuoteLang(int index, int pageSize, TypeLangageDTO lang) { //TypeLangageDTO langageType = lang; //var listQuote = _quotes.Find(q => q.Langage == langageType); @@ -105,7 +105,7 @@ namespace StubApi public async Task RemoveQuote(int quoteId) { - throw new NotImplementedException(); + _quotes.Remove( GetQuoteById(quoteId).Result ); } public async Task> SearchByCharacter(string character, int index, int pageSize, int lang) diff --git a/WF_EF_Api/WfApi/Controllers/QuotesController.cs b/WF_EF_Api/WfApi/Controllers/QuotesController.cs index 0a50e01..f5cd6ef 100644 --- a/WF_EF_Api/WfApi/Controllers/QuotesController.cs +++ b/WF_EF_Api/WfApi/Controllers/QuotesController.cs @@ -2,6 +2,7 @@ using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc; using Shared; +using System; using System.Net; namespace WfApi.Controllers @@ -23,7 +24,7 @@ namespace WfApi.Controllers //===================================== ROUTE GET ===================================== - [HttpGet("id/{id}")] // Indiquer que l'id est dans l'URL + [HttpGet("{id}")] // Indiquer que l'id est dans l'URL public async Task GetQuote(int id) { try @@ -67,5 +68,47 @@ namespace WfApi.Controllers return StatusCode((int)HttpStatusCode.InternalServerError, new { message = "Internal Server Error" }); } } + [HttpGet("allbylang")] // Indiquer que l'id est dans l'URL + public async Task GetAllQuoteByLang(TypeLangageDTO lang,int index = 0, int count = 10) + { + try + { + var result = _quote.GetAllQuoteLang(index, count,(int)lang); + + if (result.IsCompletedSuccessfully) + { + return await Task.FromResult(Ok(result)); + } + else + { + return NoContent(); + } + } + catch (Exception) + { + return StatusCode((int)HttpStatusCode.InternalServerError, new { message = "Internal Server Error" }); + } + } + [HttpDelete("delete")] + public async Task DeleteQuote([FromQuery] int idQuote) + { + try + { + var result = _quote.RemoveQuote(idQuote); + + if (result.IsCompletedSuccessfully) + { + return await Task.FromResult(Ok(result)); + } + else + { + return NotFound(); + } + } + catch (Exception) + { + return StatusCode((int)HttpStatusCode.InternalServerError, new { message = "Internal Server Error" }); + } + } } } diff --git a/WF_EF_Api/WfApi/WfApi.csproj b/WF_EF_Api/WfApi/WfApi.csproj index a68150a..ab7442c 100644 --- a/WF_EF_Api/WfApi/WfApi.csproj +++ b/WF_EF_Api/WfApi/WfApi.csproj @@ -17,6 +17,7 @@ + From d3bfd171cdfbb9def47f75f4cfc31a62905817b0 Mon Sep 17 00:00:00 2001 From: Kevin MONDEJAR Date: Thu, 20 Mar 2025 10:42:43 +0100 Subject: [PATCH 18/65] =?UTF-8?q?ajout=20suivi=20des=20=C3=A9tape=20readme?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 51 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) diff --git a/README.md b/README.md index 94b08a7..40e9d37 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,53 @@ # WF-PmAPI +🟨 En cours / ✅ Fait / ❌ Pas fait + +### Critères Entity Framework + +niveau | description | coeff | jalon | État +--- | --- | --- | --- | --- +☢️ | Le dépôt doit être accessible par l'enseignant | ☢️ | J1 | ✅ +☢️ | un .gitignore doit exister au premier push | ☢️ | J1 | ✅ +🎬 | les *projets* et les tests compilent | 1 | J1 & J2 | ✅ +🎬 | le projet et le tests s'exécutent sans bug (concernant la partie persistance) | 3 | J1 & J2 | ✅ +🟢 | Transcription du modèle : Modèle vers entités (et inversement) | 2 | J1 | 🟨 +🟢 | Requêtes CRUD simples (sur une table) | 1 | J1 | 🟨 +🟢 | Utilisation de LINQ to Entities | 2 | J1 | +🟡 | Injection / indépendance du fournisseur | 1 | J1 | ❌ +🟡 | Requêtes CRUD sur des données complexes (images par exemple) | 2 | J1 | 🟨 +🟢 | Tests - Appli Console | 1 | J1 | ❌ +🟢 | Tests - Tests unitaires (avec SQLite in memory) | 2 | J1 | ❌ +🟢 | Tests - Données stubbées et/ou Moq | 1 | J1 | ✅ +🟡 | CI : build, tests, Sonar (doc?) | 1 | J1 | ❌ +🟡 | Utilisation de relations (One-to-One, One-to-Many, Many-to-Many) (+ mapping, TU, Requêtes) | 4 | J1 | 🟨 +🟢 | Liens avec le web service | 2 | J1 | ❌ +🟡 | Utilisation d'un *Logger* | 1 | J1 | ❌ +🟡 | Déploiement | 4 | J2 | ❌ +🔴 | Unit of Work / Repository + extras (héritage, accès concurrents...) | 8 | J2 | ❌ +🟢 | Utilisation dans le projet | 2 | J2 | ❌ +🟢 | mon dépôt possède un readme qui apporte quelque chose... | 2 | J2 | ❌ + + +### Critères Web API + +niveau | description | coeff | jalon | État +--- | --- | --- | --- | --- +☢️ | Le dépôt doit être accessible par l'enseignant | ☢️ | J1 | +☢️ | un .gitignore doit exister au premier push | ☢️ | J1 | +🎬 | les *projets* et les tests compilent | 1 | J1 & J2 | +🎬 | le projet et le tests s'exécutent sans bug (concernant la partie web api) | 4 | J1 & J2 | +🟢 | Modèle <-> DTO | 1 | J1 | +🟢 | Entities <-> DTO | 1 | J1 | 🟨 +🟡 | Authentification | 4 | J1 | +🟢 | Requêtes GET, PUT, POST, DELETE sur des données simples (1 seul type d'objet en retour, propriétés de types natifs) | 2 | J1 | +🟡 | Pagination & filtrage | 2 | J1 | +🟢 | Injection de service | 2 | J1 | +🟡 | Requêtes GET, PUT, POST, DELETE sur des données complexes (plusieurs données complexes en retour) | 4 | J1 | +🟢 | Tests - Appli Console (consommation des requêtes) | 4 | J1 | +🟢 | Tests - Tests unitaires (avec Stub et/ou Moq) | 2 | J1 | +🟡 | CI : build, tests, Sonar, Documentation (en particulier Swagger avec exemples...) | 1 | J1 | +🟢 | Liens avec la persistance en base de données | 4 | J1 | +🟡 | Utilisation d'un *Logger* | 1 | J1 | +🟡 | Déploiement | 4 | J2 | +🟡 | Utilisation dans le projet | 4 | J2 | +🎬 | mon dépôt possède un readme qui apporte quelque chose... | 1 | J2 | \ No newline at end of file From d0c0519ca0c23e6a80f984a8648aaf55e28c1dcc Mon Sep 17 00:00:00 2001 From: Kevin MONDEJAR Date: Thu, 20 Mar 2025 12:01:14 +0100 Subject: [PATCH 19/65] ajout console test + continuation dbmanager + injection fournisseur --- WF_EF_Api/ConsoleTest/ConsoleTest.csproj | 8 ++ WF_EF_Api/ConsoleTest/Program.cs | 42 +++++++- WF_EF_Api/Contextlib/DbCommentaryManager.cs | 19 +++- WF_EF_Api/Contextlib/DbFavoriteManager.cs | 40 +++++++ WF_EF_Api/Contextlib/DbImagesManager.cs | 101 ++++++++++++++++++ WF_EF_Api/Contextlib/DbQuestionSerice.cs | 73 +++++++++++++ WF_EF_Api/Contextlib/WTFContext.cs | 15 ++- WF_EF_Api/Shared/IImagesService.cs | 2 +- WF_EF_Api/StubbedContextLib/StubWTFContext.cs | 14 ++- WF_EF_Api/TestEf/Program.cs | 2 + WF_EF_Api/TestEf/TestEf.csproj | 10 ++ WF_EF_Api/WF_EF_Api.sln | 6 -- WF_EF_Api/XUnitTest/UnitTest1.cs | 11 -- WF_EF_Api/XUnitTest/XUnitTest.csproj | 5 + 14 files changed, 324 insertions(+), 24 deletions(-) create mode 100644 WF_EF_Api/Contextlib/DbFavoriteManager.cs create mode 100644 WF_EF_Api/Contextlib/DbImagesManager.cs create mode 100644 WF_EF_Api/Contextlib/DbQuestionSerice.cs create mode 100644 WF_EF_Api/TestEf/Program.cs create mode 100644 WF_EF_Api/TestEf/TestEf.csproj delete mode 100644 WF_EF_Api/XUnitTest/UnitTest1.cs diff --git a/WF_EF_Api/ConsoleTest/ConsoleTest.csproj b/WF_EF_Api/ConsoleTest/ConsoleTest.csproj index 206b89a..9a4ee54 100644 --- a/WF_EF_Api/ConsoleTest/ConsoleTest.csproj +++ b/WF_EF_Api/ConsoleTest/ConsoleTest.csproj @@ -7,4 +7,12 @@ enable + + + + + + + + diff --git a/WF_EF_Api/ConsoleTest/Program.cs b/WF_EF_Api/ConsoleTest/Program.cs index 127ed44..6a3e921 100644 --- a/WF_EF_Api/ConsoleTest/Program.cs +++ b/WF_EF_Api/ConsoleTest/Program.cs @@ -1 +1,41 @@ -Console.WriteLine("bonjour"); \ No newline at end of file +using Contextlib; +using Microsoft.Data.Sqlite; +using Microsoft.EntityFrameworkCore; +using Microsoft.Extensions.Options; +using StubbedContextLib; +using static System.Net.WebRequestMethods; + +var connection = new SqliteConnection("DataSource=:memory:"); +connection.Open(); +var options = new DbContextOptionsBuilder() + .UseSqlite(connection) + .Options; + +using (var _context = new StubWTFContext(options)) +{ + _context.Database.EnsureCreated(); + + // ---- Test Image ---- // + + var imageManager = new DbImagesManager(_context); + await imageManager.AddImage(new Entity.Images() { Id = 11, ImgPath = "https://www.bing.com/ck/a?!&&p=390428c2820add92760900204667aa721b17d4eb9e8537c91544d76283d06b14JmltdHM9MTc0MjQyODgwMA&ptn=3&ver=2&hsh=4&fclid=297ef5ed-ac44-66f2-2498-e058adb06776&u=a1aHR0cHM6Ly93d3cucG9rZXBlZGlhLmZyL01hamFzcGlj&ntb=1" }); + + // ---- Test Character ---- // + + var characterManager = new DbCharacterManager(_context); + + + await characterManager.AddCharacter(new Entity.Character() { Id = 11, Name = "Majespic", IdImage = 11}); + + // recupération données + var characters = await characterManager.GetAll(); + // affichage des dponnées récupérer + foreach (var charac in characters.items) + { + Console.WriteLine("(" + charac.Id + ") " + charac.Name + " / Image ref :" + charac.IdImage); + } + + +} + + diff --git a/WF_EF_Api/Contextlib/DbCommentaryManager.cs b/WF_EF_Api/Contextlib/DbCommentaryManager.cs index 558aa46..56c0398 100644 --- a/WF_EF_Api/Contextlib/DbCommentaryManager.cs +++ b/WF_EF_Api/Contextlib/DbCommentaryManager.cs @@ -73,7 +73,7 @@ namespace Contextlib public async Task> GetAllComment() { - var comments = _context.comments.ToList(); + var comments = await _context.comments.ToListAsync(); return new PaginationResult(comments.Count, 0, comments.Count, comments); } @@ -133,7 +133,7 @@ namespace Contextlib public async Task LastCommentId() { - var last = _context.comments.OrderByDescending(x => x.Id).FirstOrDefault(); + var last = await _context.comments.OrderByDescending(x => x.Id).FirstOrDefaultAsync(); if(last == null) { return 0; @@ -154,7 +154,20 @@ namespace Contextlib public async Task UpdateComment(int id, Commentary comment) { - throw new NotImplementedException(); + var com = await _context.comments.Where(x => x.Id == id).FirstOrDefaultAsync(); + if (comment == null) + { + throw new ArgumentNullException(nameof(comment), "The updated comment data cannot be null."); + } + if (com == null) + { + throw new KeyNotFoundException($"No comments found with the given ID: {id}."); + } + com.Comment = comment.Comment; + com.DateCommentary = comment.DateCommentary; + com.IdQuote = comment.IdQuote; + com.IdUser = comment.IdUser; + await _context.SaveChangesAsync(); } } } diff --git a/WF_EF_Api/Contextlib/DbFavoriteManager.cs b/WF_EF_Api/Contextlib/DbFavoriteManager.cs new file mode 100644 index 0000000..314da25 --- /dev/null +++ b/WF_EF_Api/Contextlib/DbFavoriteManager.cs @@ -0,0 +1,40 @@ +using Entity; +using Shared; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Contextlib +{ + public class DbFavoriteManager : IFavoriteService + { + private WTFContext _context; + + public DbFavoriteManager(WTFContext context) + { + _context = context ?? throw new ArgumentNullException(nameof(context), "Database context cannot be null."); + } + + public async Task AddFavorite(int quoteid, int userId) + { + throw new NotImplementedException(); + } + + public async Task RemoveAllFavoriteForQuote(int quoteId) + { + throw new NotImplementedException(); + } + + public async Task RemoveAllFavoriteForUser(int userId) + { + throw new NotImplementedException(); + } + + public async Task RemoveFavorite(int quoteid, int userId) + { + throw new NotImplementedException(); + } + } +} diff --git a/WF_EF_Api/Contextlib/DbImagesManager.cs b/WF_EF_Api/Contextlib/DbImagesManager.cs new file mode 100644 index 0000000..2ef9d7b --- /dev/null +++ b/WF_EF_Api/Contextlib/DbImagesManager.cs @@ -0,0 +1,101 @@ +using Entity; +using Microsoft.EntityFrameworkCore; +using Shared; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Xml.Linq; + +namespace Contextlib +{ + public class DbImagesManager : IImagesService + { + private WTFContext _context; + + public DbImagesManager(WTFContext context) + { + _context = context ?? throw new ArgumentNullException(nameof(context), "Database context cannot be null."); + } + + public async Task AddImage(Images image) + { + await _context.AddAsync(image); + await _context.SaveChangesAsync(); + } + + public async Task> GetAllImage() + { + var images = await _context.images.ToListAsync(); + return new PaginationResult(images.Count, 0, images.Count, images); + } + + public async Task GetImageById(int id) + { + var image = await _context.images.Where(x => x.Id == id).FirstOrDefaultAsync(); + if (image == null) + { + throw new KeyNotFoundException($"No image found with the given ID: {id}."); + } + return image; + } + + public async Task GetLastImageId() + { + var last = await _context.images.OrderByDescending(x => x.Id).FirstOrDefaultAsync(); + if (last == null) + { + return 0; + } + return last.Id; + } + + public async Task> GetSomeImage(int index, int pageSize) + { + var images = await _context.images.ToListAsync(); + if (!images.Any()) + { + throw new KeyNotFoundException($"No images found"); + } + if ((index * pageSize + pageSize) > images.Count) + { + if (pageSize > images.Count) + { + return new PaginationResult(images.Count(), index, pageSize, images); + } + else + { + return new PaginationResult(pageSize, index, pageSize, images.Skip(index * pageSize - (((index * pageSize) + pageSize) - images.Count)).Take(pageSize).ToList()); + } + } + return new PaginationResult(images.Count, index, pageSize, images.Skip(index * pageSize).Take(pageSize).ToList()); + } + + public async Task RemoveImage(int id) + { + var image = await _context.images.Where(x => x.Id == id).FirstOrDefaultAsync(); + if (image == null) + { + throw new KeyNotFoundException($"No image found with the given ID: {id}."); + } + _context.images.Remove(image); + await _context.SaveChangesAsync(); + } + + public async Task UpdateImage(int id, Images image) + { + var img = await _context.images.Where(x => x.Id == id).FirstOrDefaultAsync(); + if (image == null) + { + throw new ArgumentNullException(nameof(image), "The updated image data cannot be null."); + } + if (img == null) + { + throw new KeyNotFoundException($"No image found with the given ID: {id}."); + } + img.ImgPath = image.ImgPath; + await _context.SaveChangesAsync(); + } + } +} diff --git a/WF_EF_Api/Contextlib/DbQuestionSerice.cs b/WF_EF_Api/Contextlib/DbQuestionSerice.cs new file mode 100644 index 0000000..010f38c --- /dev/null +++ b/WF_EF_Api/Contextlib/DbQuestionSerice.cs @@ -0,0 +1,73 @@ +using Entity; +using Shared; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Contextlib +{ + public class DbQuestionSerice : IQuestionService + { + public Task AddQuestion(Question question) + { + throw new NotImplementedException(); + } + + public Task CountQuestions() + { + throw new NotImplementedException(); + } + + public Task> GetAllQuestion() + { + throw new NotImplementedException(); + } + + public Task> GetInvalidQuestion(int index, int pageSize) + { + throw new NotImplementedException(); + } + + public Task GetQuestionById(int id) + { + throw new NotImplementedException(); + } + + public Task GetRandomQuestion() + { + throw new NotImplementedException(); + } + + public Task GetRandomQuestionQuoteToCharacter() + { + throw new NotImplementedException(); + } + + public Task GetRandomQuestionQuoteToSource() + { + throw new NotImplementedException(); + } + + public Task> GetSomeQuestion(int index, int pageSize) + { + throw new NotImplementedException(); + } + + public Task RemoveQuestion(int id) + { + throw new NotImplementedException(); + } + + public Task UpdateQuestion(int id, Question question) + { + throw new NotImplementedException(); + } + + public Task ValidateQuestion(int id, bool isvalid) + { + throw new NotImplementedException(); + } + } +} diff --git a/WF_EF_Api/Contextlib/WTFContext.cs b/WF_EF_Api/Contextlib/WTFContext.cs index e0f0a31..4b95f3b 100644 --- a/WF_EF_Api/Contextlib/WTFContext.cs +++ b/WF_EF_Api/Contextlib/WTFContext.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using System.Linq; +using System.Runtime.CompilerServices; using System.Text; using System.Threading.Tasks; using Entity; @@ -75,7 +76,19 @@ namespace Contextlib ); } + public WTFContext() + { } + + public WTFContext(DbContextOptions options) + : base(options) + { } + protected override void OnConfiguring(DbContextOptionsBuilder options) - => options.UseSqlServer(@"Server=(localdb)\mssqllocaldb;Database=Wf-Database.mdf;Trusted_Connection=True;"); + { + if (!options.IsConfigured) + { + options.UseSqlServer(@"Server=(localdb)\mssqllocaldb;Database=Wf-Database.mdf;Trusted_Connection=True;"); + } + } } } diff --git a/WF_EF_Api/Shared/IImagesService.cs b/WF_EF_Api/Shared/IImagesService.cs index e2d0465..0bc6bf0 100644 --- a/WF_EF_Api/Shared/IImagesService.cs +++ b/WF_EF_Api/Shared/IImagesService.cs @@ -10,7 +10,7 @@ namespace Shared { // Retrieves an image by its unique identifier (id). // 'id' is the unique identifier of the image. - Task GetImageById(string id); + Task GetImageById(int id); // Retrieves all images, with pagination support. // This returns a list of all images in the system. diff --git a/WF_EF_Api/StubbedContextLib/StubWTFContext.cs b/WF_EF_Api/StubbedContextLib/StubWTFContext.cs index ffc1d06..7c04527 100644 --- a/WF_EF_Api/StubbedContextLib/StubWTFContext.cs +++ b/WF_EF_Api/StubbedContextLib/StubWTFContext.cs @@ -6,6 +6,7 @@ using System.Threading.Tasks; using Contextlib; using Entity; using Microsoft.EntityFrameworkCore; +using Microsoft.Extensions.Options; namespace StubbedContextLib { @@ -133,10 +134,21 @@ namespace StubbedContextLib new Source() { Id = 4, Title = "Harry Potter à l'école des sorcier", TypeSrc = TypeSrcEnum.movie, Year = 1997 }, new Source() { Id = 5, Title = "Star Wars, épisode IV : Un nouvel espoir", TypeSrc = TypeSrcEnum.movie, Year = 1977 } ); + } - + public StubWTFContext() + { } + public StubWTFContext(DbContextOptions options) + : base(options) + { } + protected override void OnConfiguring(DbContextOptionsBuilder options) + { + if (!options.IsConfigured) + { + options.UseSqlServer(@"Server=(localdb)\mssqllocaldb;Database=Wf-Database.mdf;Trusted_Connection=True;"); + } } } } diff --git a/WF_EF_Api/TestEf/Program.cs b/WF_EF_Api/TestEf/Program.cs new file mode 100644 index 0000000..83fa4f4 --- /dev/null +++ b/WF_EF_Api/TestEf/Program.cs @@ -0,0 +1,2 @@ +// See https://aka.ms/new-console-template for more information +Console.WriteLine("Hello, World!"); diff --git a/WF_EF_Api/TestEf/TestEf.csproj b/WF_EF_Api/TestEf/TestEf.csproj new file mode 100644 index 0000000..206b89a --- /dev/null +++ b/WF_EF_Api/TestEf/TestEf.csproj @@ -0,0 +1,10 @@ + + + + Exe + net8.0 + enable + enable + + + diff --git a/WF_EF_Api/WF_EF_Api.sln b/WF_EF_Api/WF_EF_Api.sln index 2b163b7..b82d44f 100644 --- a/WF_EF_Api/WF_EF_Api.sln +++ b/WF_EF_Api/WF_EF_Api.sln @@ -13,8 +13,6 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Contextlib", "Contextlib\Co EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "StubbedContextLib", "StubbedContextLib\StubbedContextLib.csproj", "{5CD69B14-C6AE-4628-A374-996C486E25F2}" EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TestModel2Entities", "TestModel2Entities\TestModel2Entities.csproj", "{2CF20FAC-C2F1-4048-9D46-F39081B0FBEF}" -EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Model2Entities", "Model2entities\Model2Entities.csproj", "{4A1CBA3D-C798-4E19-865F-39F919F1205A}" EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "XUnitTest", "XUnitTest\XUnitTest.csproj", "{48002CA2-7CFF-4077-90CF-392476320CE3}" @@ -49,10 +47,6 @@ Global {5CD69B14-C6AE-4628-A374-996C486E25F2}.Debug|Any CPU.Build.0 = Debug|Any CPU {5CD69B14-C6AE-4628-A374-996C486E25F2}.Release|Any CPU.ActiveCfg = Release|Any CPU {5CD69B14-C6AE-4628-A374-996C486E25F2}.Release|Any CPU.Build.0 = Release|Any CPU - {2CF20FAC-C2F1-4048-9D46-F39081B0FBEF}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {2CF20FAC-C2F1-4048-9D46-F39081B0FBEF}.Debug|Any CPU.Build.0 = Debug|Any CPU - {2CF20FAC-C2F1-4048-9D46-F39081B0FBEF}.Release|Any CPU.ActiveCfg = Release|Any CPU - {2CF20FAC-C2F1-4048-9D46-F39081B0FBEF}.Release|Any CPU.Build.0 = Release|Any CPU {4A1CBA3D-C798-4E19-865F-39F919F1205A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {4A1CBA3D-C798-4E19-865F-39F919F1205A}.Debug|Any CPU.Build.0 = Debug|Any CPU {4A1CBA3D-C798-4E19-865F-39F919F1205A}.Release|Any CPU.ActiveCfg = Release|Any CPU diff --git a/WF_EF_Api/XUnitTest/UnitTest1.cs b/WF_EF_Api/XUnitTest/UnitTest1.cs deleted file mode 100644 index f8a0369..0000000 --- a/WF_EF_Api/XUnitTest/UnitTest1.cs +++ /dev/null @@ -1,11 +0,0 @@ -namespace XUnitTest -{ - public class UnitTest1 - { - [Fact] - public void Test1() - { - - } - } -} \ No newline at end of file diff --git a/WF_EF_Api/XUnitTest/XUnitTest.csproj b/WF_EF_Api/XUnitTest/XUnitTest.csproj index 3aa9860..29b8b14 100644 --- a/WF_EF_Api/XUnitTest/XUnitTest.csproj +++ b/WF_EF_Api/XUnitTest/XUnitTest.csproj @@ -11,11 +11,16 @@ + + + + + From a6fdb3242e3f1de387c6f000ca50682c4eeee51b Mon Sep 17 00:00:00 2001 From: Leni BEAULATON Date: Thu, 20 Mar 2025 14:49:48 +0100 Subject: [PATCH 20/65] =?UTF-8?q?Mise=20=C3=A0=20jour=20de=20'WF=5FEF=5FAp?= =?UTF-8?q?i/XUnitTest/UnitTest1.cs'?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- WF_EF_Api/XUnitTest/UnitTest1.cs | 292 +++++++++++++++++++++++++++++-- 1 file changed, 282 insertions(+), 10 deletions(-) diff --git a/WF_EF_Api/XUnitTest/UnitTest1.cs b/WF_EF_Api/XUnitTest/UnitTest1.cs index f8a0369..6ab3df3 100644 --- a/WF_EF_Api/XUnitTest/UnitTest1.cs +++ b/WF_EF_Api/XUnitTest/UnitTest1.cs @@ -1,11 +1,283 @@ -namespace XUnitTest -{ - public class UnitTest1 - { - [Fact] - public void Test1() - { - - } - } +using Microsoft.AspNetCore.Mvc; +using Microsoft.Extensions.Logging; +using Moq; + + +using WfApi.Controllers; +using Shared; +using DTO; + +namespace XUnitTest +{ + public class UnitTest1 + { + private readonly Mock> _mockUserService; + private readonly Mock> _mockLogger; + private readonly UsersController _userController; + + public UnitTest1() + { + // Initialisation des mocks + _mockUserService = new Mock>(); + _mockLogger = new Mock>(); + _userController = new UsersController(_mockUserService.Object, _mockLogger.Object); + } + + + + [Fact] + public async Task Get_ReturnsOk_WhenUserExists() + { + // Arrange + var userId = 1; + var userDTO = new UserDTO + { + Id = userId, + Pseudo = "test", + Email = "test@unitaire.fr", + ImageProfil = "http://test", + Password = "1234" + }; + + _mockUserService.Setup(service => service.GetUserById(userId)).ReturnsAsync(userDTO); + + // Act + var result = await _userController.Get(userId); + + // Assert + Assert.IsType(result); + } + + + + + [Fact] + public async Task GetAllUsers_ReturnsOk() + { + // Arrange + var userDTO = new UserDTO + { + Id = 1, + Pseudo = "test", + Email = "test@unitaire.fr", + ImageProfil = "http://test", + Password = "1234" + }; + var userDTO2 = new UserDTO + { + Id = 2, + Pseudo = "test", + Email = "test@unitaire.fr", + ImageProfil = "http://test", + Password = "1234" + }; + + _mockUserService.Setup(service => service.GetUserById(1)).ReturnsAsync(userDTO); + _mockUserService.Setup(service => service.GetUserById(2)).ReturnsAsync(userDTO); + + // Act + var result = await _userController.GetAllUsers(); + + // Assert + Assert.IsType(result); + } + + + + [Fact] + public async Task GetHashPassword_ReturnsOk_WhenPasswordHashIsFound() + { + // Arrange + var username = "testUser"; + var expectedHash = "hashedPassword"; + + var taskResult = Task.FromResult(expectedHash); + _mockUserService.Setup(service => service.GetHashPassword(username)).Returns(taskResult); + + // Act + var result = await _userController.GetHashPassword(username); + + // Assert + Assert.IsType(result); + } + + [Fact] + public async Task GetUserByUsername_ReturnsOk_WhenPasswordHashIsFound() + { + // Arrange + var username = "testUser"; + var userDTO = new UserDTO + { + Id = 1, + Pseudo = "testUser", + Email = "test@unitaire.fr", + ImageProfil = "http://test", + Password = "1234" + }; + + var taskResult = Task.FromResult(userDTO); + _mockUserService.Setup(service => service.GetUserByUsername(username)).Returns(taskResult); + + // Act + var result = await _userController.GetUserByUsername(username); + + // Assert + Assert.IsType(result); + } + + [Fact] + public async Task GetUserByEmail_ReturnsOk_WhenUserExists() + { + // Arrange + var email = "test@unitaire.fr"; + var userDTO = new UserDTO + { + Id = 1, + Pseudo = "testUser", + Email = email, + ImageProfil = "http://test", + Password = "1234" + }; + + + var taskResult = Task.FromResult(userDTO); + _mockUserService.Setup(service => service.GetUserByEmail(email)).Returns(taskResult); + + // Act + var result = await _userController.GetUserByEmail(email); + + // Assert + Assert.IsType(result); + } + + [Fact] + public async Task GetCountUser_ReturnsOk_WhenCountIsSuccessful() + { + // Arrange + var expectedCount = 5; + var taskResult = Task.FromResult(expectedCount); + + _mockUserService.Setup(service => service.CountUser()).Returns(taskResult); + + // Act + var result = await _userController.GetCountUser(); + + // Assert + Assert.IsType(result); + } + + [Fact] + public async Task GetExistUsername_ReturnsOk_WhenUserExists() + { + // Arrange + var username = "testUser"; + var taskResult = Task.FromResult(true); + + + _mockUserService.Setup(service => service.ExistUsername(username)).Returns(taskResult); + + // Act + var result = await _userController.GetExistUsername(username); + + // Assert + Assert.IsType(result); + + } + + [Fact] + public async Task GetExistEmail_ReturnsOk_WhenEmailExists() + { + // Arrange + var email = "test@unitaire.fr"; + var taskResult = Task.FromResult(true); + + _mockUserService.Setup(service => service.ExistEmail(email)).Returns(taskResult); + + // Act + var result = await _userController.GetExistEmail(email); + + // Assert + Assert.IsType(result); + + } + [Fact] + public async Task UpdateUser_ReturnsOk_WhenUserDataIsValid() + { + // Arrange + var id = 1; + var updatedUser = new UserDTO + { + Id = id, + Pseudo = "UpdatedUser", + Email = "updated@unitaire.fr", + ImageProfil = "http://updatedImage.com", + Password = "newPassword123" + }; + + var taskResult = Task.FromResult(updatedUser); + + _mockUserService.Setup(service => service.UpdateUser(id, updatedUser)).Returns(taskResult); + + // Act + var result = await _userController.UpdateUser(id, updatedUser); + + // Assert + var okResult = Assert.IsType(result); + + Assert.IsType(result); + } + [Fact] + public async Task CreateUser_ReturnsCreatedAtAction_WhenUserIsValid() + { + // Arrange + var newUser = new UserDTO + { + Id = 2, + Pseudo = "NewUser", + Email = "newuser@unitaire.fr", + ImageProfil = "http://newuserimage.com", + Password = "newPassword123" + }; + + _mockUserService.Setup(service => service.GetUserById(newUser.Id)).ReturnsAsync((UserDTO)null); + + _mockUserService.Setup(service => service.AddUser(newUser)).Verifiable(); + + // Act + var result = await _userController.CreateUser(newUser); + + // Assert + var createdResult = Assert.IsType(result); + Assert.Equal(newUser.Id, createdResult.RouteValues["id"]); + } + + + [Fact] + public async Task DeletePlayer_ReturnsOk_WhenPlayerExists() + { + // Arrange + var id = 1; + var existingPlayer = new UserDTO + { + Id = id, + Pseudo = "ExistingUser", + Email = "existing@unitaire.fr", + ImageProfil = "http://existingimage.com", + Password = "existingPassword123" + }; + + _mockUserService.Setup(service => service.GetUserById(id)).ReturnsAsync(existingPlayer); + + _mockUserService.Setup(service => service.RemoveUser(existingPlayer)).Verifiable(); + + // Act + var result = await _userController.DeletePlayer(id); + + // Assert + Assert.IsType(result); + + } + + + } } \ No newline at end of file From dc010f74ccc0d2c9e2430f847668b8459e50f5af Mon Sep 17 00:00:00 2001 From: Leni BEAULATON Date: Thu, 20 Mar 2025 14:53:42 +0100 Subject: [PATCH 21/65] Correction fichier de test --- WF_EF_Api/StubApi/QuoteService.cs | 5 +++++ WF_EF_Api/XUnitTest/{UnitTest1.cs => ApiUnitTest.cs} | 0 WF_EF_Api/XUnitTest/XUnitTest.csproj | 7 +++++++ 3 files changed, 12 insertions(+) rename WF_EF_Api/XUnitTest/{UnitTest1.cs => ApiUnitTest.cs} (100%) diff --git a/WF_EF_Api/StubApi/QuoteService.cs b/WF_EF_Api/StubApi/QuoteService.cs index e05f3ae..50e6284 100644 --- a/WF_EF_Api/StubApi/QuoteService.cs +++ b/WF_EF_Api/StubApi/QuoteService.cs @@ -63,6 +63,11 @@ namespace StubApi } + public Task> GetAllQuoteLang(int index, int pageSize, int lang) + { + throw new NotImplementedException(); + } + public async Task GetDayliQuote(int lang) { throw new NotImplementedException(); diff --git a/WF_EF_Api/XUnitTest/UnitTest1.cs b/WF_EF_Api/XUnitTest/ApiUnitTest.cs similarity index 100% rename from WF_EF_Api/XUnitTest/UnitTest1.cs rename to WF_EF_Api/XUnitTest/ApiUnitTest.cs diff --git a/WF_EF_Api/XUnitTest/XUnitTest.csproj b/WF_EF_Api/XUnitTest/XUnitTest.csproj index 3aa9860..d4e6dcc 100644 --- a/WF_EF_Api/XUnitTest/XUnitTest.csproj +++ b/WF_EF_Api/XUnitTest/XUnitTest.csproj @@ -12,10 +12,17 @@ + + + + + + + From 9ff0dc316c488aeb290dd0773a159317623549e7 Mon Sep 17 00:00:00 2001 From: Leni BEAULATON Date: Thu, 20 Mar 2025 14:54:39 +0100 Subject: [PATCH 22/65] =?UTF-8?q?Mise=20=C3=A0=20jour=20de=20'README.md'?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 81ae64e..2e0f5ac 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,6 @@ # WF-PmAPI ### Paquets -NSwag.AspNetCore +NSwag.AspNetCore
+Moq From 96f55a3532148e468e8b7868b269e1e05eee0905 Mon Sep 17 00:00:00 2001 From: Kevin MONDEJAR Date: Thu, 20 Mar 2025 15:15:13 +0100 Subject: [PATCH 23/65] suite test console (fin image + character) --- WF_EF_Api/ConsoleTest/Program.cs | 105 ++++++++++++++++++-- WF_EF_Api/Contextlib/DbCharacterManager.cs | 29 ++++-- WF_EF_Api/Contextlib/DbCommentaryManager.cs | 40 ++++++-- WF_EF_Api/Contextlib/DbImagesManager.cs | 12 ++- 4 files changed, 159 insertions(+), 27 deletions(-) diff --git a/WF_EF_Api/ConsoleTest/Program.cs b/WF_EF_Api/ConsoleTest/Program.cs index 6a3e921..7a36b87 100644 --- a/WF_EF_Api/ConsoleTest/Program.cs +++ b/WF_EF_Api/ConsoleTest/Program.cs @@ -1,8 +1,10 @@ using Contextlib; +using Entity; using Microsoft.Data.Sqlite; using Microsoft.EntityFrameworkCore; using Microsoft.Extensions.Options; using StubbedContextLib; +using static System.Net.Mime.MediaTypeNames; using static System.Net.WebRequestMethods; var connection = new SqliteConnection("DataSource=:memory:"); @@ -18,24 +20,115 @@ using (var _context = new StubWTFContext(options)) // ---- Test Image ---- // var imageManager = new DbImagesManager(_context); - await imageManager.AddImage(new Entity.Images() { Id = 11, ImgPath = "https://www.bing.com/ck/a?!&&p=390428c2820add92760900204667aa721b17d4eb9e8537c91544d76283d06b14JmltdHM9MTc0MjQyODgwMA&ptn=3&ver=2&hsh=4&fclid=297ef5ed-ac44-66f2-2498-e058adb06776&u=a1aHR0cHM6Ly93d3cucG9rZXBlZGlhLmZyL01hamFzcGlj&ntb=1" }); + + + await imageManager.AddImage(new Images() { Id = 11, ImgPath = "https://www.bing.com/ck/a?!&&p=390428c2820add92760900204667aa721b17d4eb9e8537c91544d76283d06b14JmltdHM9MTc0MjQyODgwMA&ptn=3&ver=2&hsh=4&fclid=297ef5ed-ac44-66f2-2498-e058adb06776&u=a1aHR0cHM6Ly93d3cucG9rZXBlZGlhLmZyL01hamFzcGlj&ntb=1" }); + await imageManager.AddImage(new Images() { Id = 12, ImgPath = "https://www.bing.com/images/search?view=detailV2&ccid=t57OzeAT&id=1CCCBB65825E5FB93F10CA6D29EFDBBFEB5CDF27&thid=OIP.t57OzeATZKjBDDrzXqbc5gHaE7&mediaurl=https%3a%2f%2fimg-19.commentcamarche.net%2fP51ArxVXHJKsgdTzGDaqajlWJ3s%3d%2f1500x%2fsmart%2f7b5dd43e607643fea1a61960e3f66fc4%2fccmcms-commentcamarche%2f39481621.jpg&cdnurl=https%3a%2f%2fth.bing.com%2fth%2fid%2fR.b79ececde01364a8c10c3af35ea6dce6%3frik%3dJ99c67%252fb7yltyg%26pid%3dImgRaw%26r%3d0&exph=999&expw=1500&q=image&simid=608026907577902968&ck=0D54F216D075AD6E0ABC46B3AAB7E80A&selectedIndex=19&itb=0" }); + Console.WriteLine("---- Test ajout image (id : 11, 12)"); + var images = await imageManager.GetAllImage(); + foreach (var image in images.items) + { + Console.WriteLine($"- ({image.Id}) : {(image.ImgPath.Length <= 40 ? image.ImgPath : image.ImgPath.Substring(0, 40)+"...")}"); + + + } + Console.WriteLine(""); + + + await imageManager.UpdateImage(12, new Images() { ImgPath = "https://testUpdate/stub"}); + Console.WriteLine("---- Test mise a jour image (id : 12)"); + images = await imageManager.GetAllImage(); + foreach (var image in images.items) + { + Console.WriteLine($"- ({image.Id}) : {(image.ImgPath.Length <= 40 ? image.ImgPath : image.ImgPath.Substring(0, 40) + "...")}"); + } + Console.WriteLine(""); + + + await imageManager.RemoveImage(12); + Console.WriteLine("---- Test suppression image (id : 12)"); + images = await imageManager.GetAllImage(); + foreach (var image in images.items) + { + Console.WriteLine($"- ({image.Id}) : {(image.ImgPath.Length <= 40 ? image.ImgPath : image.ImgPath.Substring(0, 40) + "...")}"); + } + Console.WriteLine(""); + + + Console.WriteLine("---- Test getById image (id : 11)"); + var img = await imageManager.GetImageById(11); + Console.WriteLine($"- ({img.Id}) : {(img.ImgPath.Length <= 40 ? img.ImgPath : img.ImgPath.Substring(0, 40) + "...")}"); + Console.WriteLine(""); + + + Console.WriteLine("---- Test getSomme image (nb : 5, page : 1)"); + images = await imageManager.GetSomeImage(1,5); + foreach (var image in images.items) + { + Console.WriteLine($"- ({image.Id}) : {(image.ImgPath.Length <= 40 ? image.ImgPath : image.ImgPath.Substring(0, 40) + "...")}"); + } + Console.WriteLine(""); + + + Console.WriteLine("---- Test LastId image"); + var id = await imageManager.GetLastImageId(); + Console.WriteLine($"- Last image id : {id}"); + Console.WriteLine(""); + + Console.WriteLine("-------------------------------------------------------------------------------"); // ---- Test Character ---- // var characterManager = new DbCharacterManager(_context); - - await characterManager.AddCharacter(new Entity.Character() { Id = 11, Name = "Majespic", IdImage = 11}); - // recupération données + await characterManager.AddCharacter(new Character() { Id = 11, Name = "Vipélière", IdImage = 11 }); + Console.WriteLine("---- Test ajout charcter (id : 11)"); var characters = await characterManager.GetAll(); - // affichage des dponnées récupérer foreach (var charac in characters.items) { - Console.WriteLine("(" + charac.Id + ") " + charac.Name + " / Image ref :" + charac.IdImage); + Console.WriteLine($"- ({charac.Id}) : {charac.Name} -> {charac.IdImage} : {(charac.Images.ImgPath.Length <= 40 ? charac.Images.ImgPath : charac.Images.ImgPath.Substring(0, 40) + "...")}"); + } + Console.WriteLine(""); + + + await characterManager.UpdateCharacter(11,new Character() {Name = "Majespic"}); + Console.WriteLine("---- Test mise a jour charcter (id : 11)"); + characters = await characterManager.GetAll(); + foreach (var charac in characters.items) + { + Console.WriteLine($"- ({charac.Id}) : {charac.Name} -> {charac.IdImage} : {(charac.Images.ImgPath.Length <= 40 ? charac.Images.ImgPath : charac.Images.ImgPath.Substring(0, 40) + "...")}"); } + Console.WriteLine(""); + await characterManager.RemoveCharacter(11); + Console.WriteLine("---- Test sup (id : 5)"); + characters = await characterManager.GetAll(); + foreach (var charac in characters.items) + { + Console.WriteLine($"- ({charac.Id}) : {charac.Name} -> {charac.IdImage} : {(charac.Images.ImgPath.Length <= 40 ? charac.Images.ImgPath : charac.Images.ImgPath.Substring(0, 40) + "...")}"); + } + Console.WriteLine(""); + + + Console.WriteLine("---- Test GetById (id : 5)"); + var chara = await characterManager.GetCharById(5); + Console.WriteLine($"- ({chara.Id}) : {chara.Name} -> {chara.IdImage} : {(chara.Images.ImgPath.Length <= 40 ? chara.Images.ImgPath : chara.Images.ImgPath.Substring(0, 40) + "...")}"); + Console.WriteLine(""); + + + Console.WriteLine("---- Test GetByName (name : Jon Snow)"); + chara = await characterManager.GetCharByName("Jon Snow"); + Console.WriteLine($"- ({chara.Id}) : {chara.Name} -> {chara.IdImage} : {(chara.Images.ImgPath.Length <= 40 ? chara.Images.ImgPath : chara.Images.ImgPath.Substring(0, 40) + "...")}"); + Console.WriteLine(""); + + + Console.WriteLine("---- Test LastId Character"); + id = await characterManager.GetLastCharId(); + Console.WriteLine($"- Last character id : {id}"); + Console.WriteLine(""); } + diff --git a/WF_EF_Api/Contextlib/DbCharacterManager.cs b/WF_EF_Api/Contextlib/DbCharacterManager.cs index db1a7c0..e0d75e1 100644 --- a/WF_EF_Api/Contextlib/DbCharacterManager.cs +++ b/WF_EF_Api/Contextlib/DbCharacterManager.cs @@ -41,7 +41,7 @@ namespace Contextlib /// A task representing the asynchronous operation, with a as its result containing the full list of characters and pagination information. public Task> GetAll() { - List charLst = _context.characters.ToList(); + List charLst = _context.characters.Include(i => i.Images).ToList(); return Task.FromResult(new PaginationResult(charLst.Count, 0, charLst.Count, charLst)); } @@ -55,6 +55,7 @@ namespace Contextlib public async Task GetCharById(int id) { Character? character = await _context.characters + .Include(i => i.Images) .FirstOrDefaultAsync(x => x.Id == id); if (character == null) @@ -73,8 +74,9 @@ namespace Contextlib /// Thrown when no character is found with the given name. public async Task GetCharByName(string name) { - Character? character = await _context.characters - .FirstOrDefaultAsync(x => x.Name.Equals(name, StringComparison.OrdinalIgnoreCase)); + var character = await _context.characters + .Where(c => EF.Functions.Like(c.Name, name)) + .FirstOrDefaultAsync(); if (character == null) { @@ -129,17 +131,26 @@ namespace Contextlib { throw new ArgumentNullException(nameof(character), "The updated character data cannot be null."); } - + var modif = false; Character? charUpdated = await _context.characters.FirstOrDefaultAsync(x => x.Id == id); if (charUpdated == null) { throw new KeyNotFoundException($"Error : Unable to update, no character found with the ID: {id} ."); } - - charUpdated.IdImage = character.IdImage; - charUpdated.Name = character.Name; - - await _context.SaveChangesAsync(); + if (character.IdImage != 0) + { + charUpdated.IdImage = character.IdImage; + modif = true; + } + if (character.Name != null) + { + charUpdated.Name = character.Name; + modif = true; + } + if (modif) + { + await _context.SaveChangesAsync(); + } } } } diff --git a/WF_EF_Api/Contextlib/DbCommentaryManager.cs b/WF_EF_Api/Contextlib/DbCommentaryManager.cs index 56c0398..e5bde4f 100644 --- a/WF_EF_Api/Contextlib/DbCommentaryManager.cs +++ b/WF_EF_Api/Contextlib/DbCommentaryManager.cs @@ -1,5 +1,6 @@ using Entity; using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Update; using Shared; using System; using System.Collections.Generic; @@ -61,7 +62,7 @@ namespace Contextlib /// Thrown when no comments are found for the provided user ID. public async Task DeleteCommentForUser(int userId) { - var comments = await _context.comments.Where(x => x.IdUser == userId).ToListAsync(); + var comments = await _context.comments.Include(c => c.User).Where(x => x.IdUser == userId).ToListAsync(); if (!comments.Any()) { throw new KeyNotFoundException($"No comments found for the user ID: {userId}."); @@ -73,13 +74,13 @@ namespace Contextlib public async Task> GetAllComment() { - var comments = await _context.comments.ToListAsync(); + var comments = await _context.comments.Include(c => c.User).ToListAsync(); return new PaginationResult(comments.Count, 0, comments.Count, comments); } public async Task GetCommentById(int id) { - var comment = await _context.comments.Where(x => x.Id == id).FirstOrDefaultAsync(); + var comment = await _context.comments.Include(c => c.User).Where(x => x.Id == id).FirstOrDefaultAsync(); if(comment == null) { throw new KeyNotFoundException($"No comments found with the given ID: {id}."); @@ -89,7 +90,7 @@ namespace Contextlib public async Task> GetCommentByQuote(int quoteId, int index, int pageSize) { - var comments = await _context.comments.Where(x => x.IdQuote == quoteId).ToListAsync(); + var comments = await _context.comments.Include(c => c.User).Where(x => x.IdQuote == quoteId).ToListAsync(); if (!comments.Any()) { throw new KeyNotFoundException($"No comments found for the quote ID: {quoteId}."); @@ -111,7 +112,7 @@ namespace Contextlib public async Task> GetCommentByUser(int userId, int index, int pageSize) { - var comments = await _context.comments.Where(x => x.IdUser == userId).ToListAsync(); + var comments = await _context.comments.Include(c => c.User).Where(x => x.IdUser == userId).ToListAsync(); if (!comments.Any()) { throw new KeyNotFoundException($"No comments found for the user ID: {userId}."); @@ -154,6 +155,7 @@ namespace Contextlib public async Task UpdateComment(int id, Commentary comment) { + var modif = false; var com = await _context.comments.Where(x => x.Id == id).FirstOrDefaultAsync(); if (comment == null) { @@ -163,11 +165,29 @@ namespace Contextlib { throw new KeyNotFoundException($"No comments found with the given ID: {id}."); } - com.Comment = comment.Comment; - com.DateCommentary = comment.DateCommentary; - com.IdQuote = comment.IdQuote; - com.IdUser = comment.IdUser; - await _context.SaveChangesAsync(); + if (comment.Comment != null) + { + com.Comment = comment.Comment; + modif = true; + } + if(comment.DateCommentary != null){ + com.DateCommentary = comment.DateCommentary; + modif = true; + } + if(comment.IdQuote != 0) + { + com.IdQuote = comment.IdQuote; + modif = true; + } + if (comment.IdUser != 0) + { + com.IdUser = comment.IdUser; + modif = true; + } + if (modif) + { + await _context.SaveChangesAsync(); + } } } } diff --git a/WF_EF_Api/Contextlib/DbImagesManager.cs b/WF_EF_Api/Contextlib/DbImagesManager.cs index 2ef9d7b..ad51785 100644 --- a/WF_EF_Api/Contextlib/DbImagesManager.cs +++ b/WF_EF_Api/Contextlib/DbImagesManager.cs @@ -85,6 +85,7 @@ namespace Contextlib public async Task UpdateImage(int id, Images image) { + var modif = false; var img = await _context.images.Where(x => x.Id == id).FirstOrDefaultAsync(); if (image == null) { @@ -94,8 +95,15 @@ namespace Contextlib { throw new KeyNotFoundException($"No image found with the given ID: {id}."); } - img.ImgPath = image.ImgPath; - await _context.SaveChangesAsync(); + if (image.ImgPath != null) + { + img.ImgPath = image.ImgPath; + modif = true; + } + if (modif) + { + await _context.SaveChangesAsync(); + } } } } From ec34797b7683d0e57892bd29269c1601a63b168e Mon Sep 17 00:00:00 2001 From: kekentin Date: Thu, 20 Mar 2025 15:24:28 +0100 Subject: [PATCH 24/65] =?UTF-8?q?Cr=C3=A9ation=20de=20nouvelle=20route=20p?= =?UTF-8?q?our=20l'API?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- WF_EF_Api/DTO/QuoteDTO.cs | 1 + WF_EF_Api/Shared/IQuoteService.cs | 9 +- WF_EF_Api/StubApi/QuoteService.cs | 84 +++++++++++-------- .../WfApi/Controllers/QuotesController.cs | 51 ++++++++++- WF_EF_Api/WfApi/WeatherForecast.cs | 13 --- 5 files changed, 104 insertions(+), 54 deletions(-) delete mode 100644 WF_EF_Api/WfApi/WeatherForecast.cs diff --git a/WF_EF_Api/DTO/QuoteDTO.cs b/WF_EF_Api/DTO/QuoteDTO.cs index 510fa30..a60b283 100644 --- a/WF_EF_Api/DTO/QuoteDTO.cs +++ b/WF_EF_Api/DTO/QuoteDTO.cs @@ -17,5 +17,6 @@ namespace DTO public int Like { get; set; } public TypeLangageDTO Langage { get; set; } public TypeSrcEnumDTO Type { get; set; } + public Boolean IsValide { get; set; } } } diff --git a/WF_EF_Api/Shared/IQuoteService.cs b/WF_EF_Api/Shared/IQuoteService.cs index d9ece83..c37fb5a 100644 --- a/WF_EF_Api/Shared/IQuoteService.cs +++ b/WF_EF_Api/Shared/IQuoteService.cs @@ -10,7 +10,7 @@ namespace Shared { // Retrieves the daily quote in a specified language. // 'lang' is a language code. - Task GetDayliQuote(int lang); + Task GetDailyQuote(DateOnly date, int lang); // Retrieves a specific quote by its unique identifier (id). Task GetQuoteById(int id); @@ -27,6 +27,9 @@ namespace Shared // 'lang' is a language code used to filter the quotes in the chosen language. Task> GetAllQuoteLang(int index, int pageSize, int lang); + // Retrieves all inavailable quotes but filtered by language. + // 'lang' is a language code used to filter the quotes in the chosen language. + Task> GetInvalidQuote(int index, int pageSize, int lang); // Retrieves a page of quote suggestions based on the index (pagination) and language. // 'index' is the starting point for pagination // 'pageSize' determines the number of quotes per page @@ -83,14 +86,12 @@ namespace Shared // Removes a quote based on its unique identifier ('quoteId'). Task RemoveQuote(int quoteId); - // Returns the total number of quotes available. - Task CountQuotes(); - // Retrieves the last ID. Task GetLastQuoteId(); // Validates or invalidates a quote based on the 'quoteId' and a boolean value ('isValidate'). // If 'isValidate' is true, the quote is marked as valid; if false, it is invalid. Task ValidateQuote(int quoteId, bool isValidate); + } } diff --git a/WF_EF_Api/StubApi/QuoteService.cs b/WF_EF_Api/StubApi/QuoteService.cs index e05f3ae..53e261d 100644 --- a/WF_EF_Api/StubApi/QuoteService.cs +++ b/WF_EF_Api/StubApi/QuoteService.cs @@ -16,26 +16,26 @@ namespace StubApi { _quotes = new List { - new QuoteDTO{Id=1, Content="Que la force soit avec toi", Character="Obi-Wan", ImagePath="http://image1", TitleSource="Star Wars", DateSource=1977, Like=32, Langage=TypeLangageDTO.vo, Type=TypeSrcEnumDTO.movie}, - new QuoteDTO{Id=2, Content="Je suis ton père", Character="Darth Vader", ImagePath="http://image2", TitleSource="Star Wars", DateSource=1980, Like=120, Langage=TypeLangageDTO.vo, Type=TypeSrcEnumDTO.movie}, - new QuoteDTO{Id=3, Content="Que la vengeance commence", Character="Anakin Skywalker", ImagePath="http://image3", TitleSource="Star Wars: Episode III", DateSource=2005, Like=95, Langage=TypeLangageDTO.vo, Type=TypeSrcEnumDTO.movie}, - new QuoteDTO{Id=4, Content="J'adore l'odeur du napalm au matin", Character="Kilgore", ImagePath="http://image4", TitleSource="Apocalypse Now", DateSource=1979, Like=56, Langage=TypeLangageDTO.vo, Type=TypeSrcEnumDTO.movie}, - new QuoteDTO{Id=5, Content="Je suis Groot", Character="Groot", ImagePath="http://image5", TitleSource="Guardians of the Galaxy", DateSource=2014, Like=200, Langage=TypeLangageDTO.vo, Type=TypeSrcEnumDTO.movie}, - new QuoteDTO{Id=6, Content="La vie est un rêve", Character="Don Quichotte", ImagePath="http://image6", TitleSource="Don Quichotte", DateSource=1605, Like=34, Langage=TypeLangageDTO.vf, Type=TypeSrcEnumDTO.book}, - new QuoteDTO{Id=7, Content="To infinity and beyond!", Character="Buzz Lightyear", ImagePath="http://image7", TitleSource="Toy Story", DateSource=1995, Like=180, Langage=TypeLangageDTO.vo, Type=TypeSrcEnumDTO.movie}, - new QuoteDTO{Id=8, Content="Je ne suis pas un héros", Character="Bruce Wayne", ImagePath="http://image8", TitleSource="The Dark Knight", DateSource=2008, Like=250, Langage=TypeLangageDTO.vo, Type=TypeSrcEnumDTO.movie}, - new QuoteDTO{Id=9, Content="Je suis le maître du jeu", Character="Jigsaw", ImagePath="http://image9", TitleSource="Saw", DateSource=2004, Like=65, Langage=TypeLangageDTO.vo, Type=TypeSrcEnumDTO.movie}, - new QuoteDTO{Id=10, Content="Liberté, égalité, fraternité", Character="La devise de la France", ImagePath="http://image10", TitleSource="Révolution française", DateSource=1789, Like=300, Langage=TypeLangageDTO.vf, Type=TypeSrcEnumDTO.book}, - new QuoteDTO{Id=11, Content="Un petit pas pour l'homme, un grand pas pour l'humanité", Character="Neil Armstrong", ImagePath="http://image11", TitleSource="Moon landing", DateSource=1969, Like=500, Langage=TypeLangageDTO.vo, Type=TypeSrcEnumDTO.book}, - new QuoteDTO{Id=12, Content="C'est la vie", Character="Charles", ImagePath="http://image12", TitleSource="French Movie", DateSource=2013, Like=45, Langage=TypeLangageDTO.vf, Type=TypeSrcEnumDTO.movie}, - new QuoteDTO{Id=13, Content="Voici Johnny!", Character="Jack Torrance", ImagePath="http://image13", TitleSource="The Shining", DateSource=1980, Like=300, Langage=TypeLangageDTO.vo, Type=TypeSrcEnumDTO.movie}, - new QuoteDTO{Id=14, Content="Je suis un simple serveur", Character="Hannibal", ImagePath="http://image14", TitleSource="The Silence of the Lambs", DateSource=1991, Like=200, Langage=TypeLangageDTO.vo, Type=TypeSrcEnumDTO.movie}, - new QuoteDTO{Id=15, Content="N'attends pas le moment parfait, prends le moment et rends-le parfait", Character="Zig Ziglar", ImagePath="http://image15", TitleSource="Motivation", DateSource=1995, Like=150, Langage=TypeLangageDTO.vf, Type=TypeSrcEnumDTO.book}, - new QuoteDTO{Id=16, Content="Le seul vrai voyage est de changer de regard", Character="Marcel Proust", ImagePath="http://image16", TitleSource="À la recherche du temps perdu", DateSource=1913, Like=125, Langage=TypeLangageDTO.vf, Type=TypeSrcEnumDTO.book}, - new QuoteDTO{Id=17, Content="La force sera avec toi, toujours", Character="Obi-Wan Kenobi", ImagePath="http://image17", TitleSource="Star Wars: Episode IV", DateSource=1977, Like=320, Langage=TypeLangageDTO.vo, Type=TypeSrcEnumDTO.movie}, - new QuoteDTO{Id=18, Content="J'ai toujours rêvé d'être un gangster", Character="Henry Hill", ImagePath="http://image18", TitleSource="Goodfellas", DateSource=1990, Like=500, Langage=TypeLangageDTO.vo, Type=TypeSrcEnumDTO.movie}, - new QuoteDTO{Id=19, Content="Je vous ai compris", Character="De Gaulle", ImagePath="http://image19", TitleSource="Discours de Gaulle", DateSource=1958, Like=250, Langage=TypeLangageDTO.vf, Type=TypeSrcEnumDTO.book}, - new QuoteDTO{Id=20, Content="Courage, fuyons!", Character="Frédéric", ImagePath="http://image20", TitleSource="Le Pourceau", DateSource=1834, Like=75, Langage=TypeLangageDTO.vf, Type=TypeSrcEnumDTO.book} + new QuoteDTO{Id=0, Content="Que la force soit avec toi", Character="Obi-Wan", ImagePath="http://image1", TitleSource="Star Wars", DateSource=1977, Like=32, Langage=TypeLangageDTO.vo, Type=TypeSrcEnumDTO.movie,IsValide=true}, + new QuoteDTO{Id=1, Content="Je suis ton père", Character="Darth Vader", ImagePath="http://image2", TitleSource="Star Wars", DateSource=1980, Like=120, Langage=TypeLangageDTO.vo, Type=TypeSrcEnumDTO.movie,IsValide=true}, + new QuoteDTO{Id=2, Content="Que la vengeance commence", Character="Anakin Skywalker", ImagePath="http://image3", TitleSource="Star Wars: Episode III", DateSource=2005, Like=95, Langage=TypeLangageDTO.vo, Type=TypeSrcEnumDTO.movie,IsValide=true}, + new QuoteDTO{Id=3, Content="J'adore l'odeur du napalm au matin", Character="Kilgore", ImagePath="http://image4", TitleSource="Apocalypse Now", DateSource=1979, Like=56, Langage=TypeLangageDTO.vo, Type=TypeSrcEnumDTO.movie,IsValide=true}, + new QuoteDTO{Id=4, Content="Je suis Groot", Character="Groot", ImagePath="http://image5", TitleSource="Guardians of the Galaxy", DateSource=2014, Like=200, Langage=TypeLangageDTO.vo, Type=TypeSrcEnumDTO.movie,IsValide=true}, + new QuoteDTO{Id=5, Content="La vie est un rêve", Character="Don Quichotte", ImagePath="http://image6", TitleSource="Don Quichotte", DateSource=1605, Like=34, Langage=TypeLangageDTO.vf, Type=TypeSrcEnumDTO.book,IsValide=true}, + new QuoteDTO{Id=6, Content="To infinity and beyond!", Character="Buzz Lightyear", ImagePath="http://image7", TitleSource="Toy Story", DateSource=1995, Like=180, Langage=TypeLangageDTO.vo, Type=TypeSrcEnumDTO.movie,IsValide=true}, + new QuoteDTO{Id=7, Content="Je ne suis pas un héros", Character="Bruce Wayne", ImagePath="http://image8", TitleSource="The Dark Knight", DateSource=2008, Like=250, Langage=TypeLangageDTO.vo, Type=TypeSrcEnumDTO.movie,IsValide=true}, + new QuoteDTO{Id=8, Content="Je suis le maître du jeu", Character="Jigsaw", ImagePath="http://image9", TitleSource="Saw", DateSource=2004, Like=65, Langage=TypeLangageDTO.vo, Type=TypeSrcEnumDTO.movie,IsValide=true}, + new QuoteDTO{Id=9, Content="Liberté, égalité, fraternité", Character="La devise de la France", ImagePath="http://image10", TitleSource="Révolution française", DateSource=1789, Like=300, Langage=TypeLangageDTO.vf, Type=TypeSrcEnumDTO.book,IsValide=true}, + new QuoteDTO{Id=10, Content="Un petit pas pour l'homme, un grand pas pour l'humanité", Character="Neil Armstrong", ImagePath="http://image11", TitleSource="Moon landing", DateSource=1969, Like=500, Langage=TypeLangageDTO.vo, Type=TypeSrcEnumDTO.book,IsValide=true}, + new QuoteDTO{Id=11, Content="C'est la vie", Character="Charles", ImagePath="http://image12", TitleSource="French Movie", DateSource=2013, Like=45, Langage=TypeLangageDTO.vf, Type=TypeSrcEnumDTO.movie,IsValide=true}, + new QuoteDTO{Id=12, Content="Voici Johnny!", Character="Jack Torrance", ImagePath="http://image13", TitleSource="The Shining", DateSource=1980, Like=300, Langage=TypeLangageDTO.vo, Type=TypeSrcEnumDTO.movie,IsValide=true}, + new QuoteDTO{Id=13, Content="Je suis un simple serveur", Character="Hannibal", ImagePath="http://image14", TitleSource="The Silence of the Lambs", DateSource=1991, Like=200, Langage=TypeLangageDTO.vo, Type=TypeSrcEnumDTO.movie,IsValide=true}, + new QuoteDTO{Id=14, Content="N'attends pas le moment parfait, prends le moment et rends-le parfait", Character="Zig Ziglar", ImagePath="http://image15", TitleSource="Motivation", DateSource=1995, Like=150, Langage=TypeLangageDTO.vf, Type=TypeSrcEnumDTO.book,IsValide=true}, + new QuoteDTO{Id=15, Content="Le seul vrai voyage est de changer de regard", Character="Marcel Proust", ImagePath="http://image16", TitleSource="À la recherche du temps perdu", DateSource=1913, Like=125, Langage=TypeLangageDTO.vf, Type=TypeSrcEnumDTO.book,IsValide=true}, + new QuoteDTO{Id=16, Content="La force sera avec toi, toujours", Character="Obi-Wan Kenobi", ImagePath="http://image17", TitleSource="Star Wars: Episode IV", DateSource=1977, Like=320, Langage=TypeLangageDTO.vo, Type=TypeSrcEnumDTO.movie,IsValide=true}, + new QuoteDTO{Id=17, Content="J'ai toujours rêvé d'être un gangster", Character="Henry Hill", ImagePath="http://image18", TitleSource="Goodfellas", DateSource=1990, Like=500, Langage=TypeLangageDTO.vo, Type=TypeSrcEnumDTO.movie,IsValide=true}, + new QuoteDTO{Id=18, Content="Je vous ai compris", Character="De Gaulle", ImagePath="http://image19", TitleSource="Discours de Gaulle", DateSource=1958, Like=250, Langage=TypeLangageDTO.vf, Type=TypeSrcEnumDTO.book,IsValide=true}, + new QuoteDTO{Id=19, Content="Courage, fuyons!", Character="Frédéric", ImagePath="http://image20", TitleSource="Le Pourceau", DateSource=1834, Like=75, Langage=TypeLangageDTO.vf, Type=TypeSrcEnumDTO.book,IsValide=false} }; } @@ -44,28 +44,30 @@ namespace StubApi _quotes.Add(quote); } - public async Task CountQuotes() - { - return _quotes.Count; - } - public async Task> GetAllQuote() { - return new PaginationResult(_quotes.Count, 0, _quotes.Count, _quotes); + return new PaginationResult(_quotes.Where(q=>q.IsValide == true).ToList().Count, + 0, + _quotes.Count, + _quotes.Where(q => q.IsValide == true).ToList()); } - public async Task> GetAllQuoteLang(int index, int pageSize, TypeLangageDTO lang) + public async Task> GetAllQuoteLang(int index, int pageSize, int lang) { - //TypeLangageDTO langageType = lang; - //var listQuote = _quotes.Find(q => q.Langage == langageType); - //return new PaginationResult(_quotes.Count, index, pageSize, _quotes.Skip(index * pageSize).Take(pageSize).ToList()); - throw new NotImplementedException(); + TypeLangageDTO langageType = (TypeLangageDTO)lang; + + return new PaginationResult(_quotes.Where(q => q.IsValide = true).ToList().Count, + index, + pageSize, + _quotes.Where(q => q.IsValide == true && q.Langage == langageType ).ToList().Skip(index * pageSize).Take(pageSize).ToList() + ); } - public async Task GetDayliQuote(int lang) + public async Task GetDailyQuote(DateOnly date, int lang) { - throw new NotImplementedException(); + int nb = _quotes.Where(q => q.Langage == (TypeLangageDTO)lang && q.IsValide == true).Count(); + return _quotes.Where(q => q.Langage == (TypeLangageDTO)lang && q.IsValide == true).ToList().Find(q => q.Id == date.DayNumber%nb) ?? _quotes.Where(q => q.Langage == (TypeLangageDTO)lang && q.IsValide == true).First(); } public async Task> GetFavorites(int index, int pageSize, int UserId) @@ -90,7 +92,11 @@ namespace StubApi public async Task> GetSomeQuote(int index, int pageSize) { - return new PaginationResult(_quotes.Count, index, pageSize, _quotes.Skip(index * pageSize).Take(pageSize).ToList()); + return new PaginationResult(_quotes.Where(q => q.IsValide = true).ToList().Count, + index, + pageSize, + _quotes.Where(q => q.IsValide = true).ToList().Skip(index * pageSize).Take(pageSize).ToList() + ); } public async Task> GetSuggestions(int index, int pageSize, int lang) @@ -132,5 +138,15 @@ namespace StubApi { throw new NotImplementedException(); } + public async Task> GetInvalidQuote(int index, int pageSize, int lang) + { + TypeLangageDTO langageType = (TypeLangageDTO)lang; + + return new PaginationResult(_quotes.Where(q => q.IsValide == false && q.Langage == langageType).ToList().Count, + index, + pageSize, + _quotes.Where(q => q.IsValide == false && q.Langage == langageType).ToList().Skip(index * pageSize).Take(pageSize).ToList() + ); + } } } diff --git a/WF_EF_Api/WfApi/Controllers/QuotesController.cs b/WF_EF_Api/WfApi/Controllers/QuotesController.cs index f5cd6ef..173d30f 100644 --- a/WF_EF_Api/WfApi/Controllers/QuotesController.cs +++ b/WF_EF_Api/WfApi/Controllers/QuotesController.cs @@ -2,7 +2,6 @@ using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc; using Shared; -using System; using System.Net; namespace WfApi.Controllers @@ -47,7 +46,7 @@ namespace WfApi.Controllers } - [HttpGet("all")] // Indiquer que l'id est dans l'URL + [HttpGet("all")] public async Task GetAllQuote(int index = 0, int count = 10) { try @@ -68,7 +67,7 @@ namespace WfApi.Controllers return StatusCode((int)HttpStatusCode.InternalServerError, new { message = "Internal Server Error" }); } } - [HttpGet("allbylang")] // Indiquer que l'id est dans l'URL + [HttpGet("allbylang")] public async Task GetAllQuoteByLang(TypeLangageDTO lang,int index = 0, int count = 10) { try @@ -89,6 +88,52 @@ namespace WfApi.Controllers return StatusCode((int)HttpStatusCode.InternalServerError, new { message = "Internal Server Error" }); } } + [HttpGet("dailyquote")] + public async Task GetDailyQuote([FromQuery] int year, [FromQuery] int month, [FromQuery] int day, TypeLangageDTO lang) + { + try + { + DateOnly date = new DateOnly(year, month, day); + + var result = _quote.GetDailyQuote(date, (int)lang); + + if (result.IsCompletedSuccessfully) + { + return await Task.FromResult(Ok(result)); + } + else + { + return NoContent(); + } + } + catch (Exception) + { + return StatusCode((int)HttpStatusCode.InternalServerError, new { message = "Internal Server Error" }); + } + } + [HttpGet("invalid")] + public async Task GetInvalidQuote(TypeLangageDTO lang, int index = 0, int count = 10) + { + try + { + var result = _quote.GetInvalidQuote(index, count, (int)lang); + + if (result.IsCompletedSuccessfully) + { + return await Task.FromResult(Ok(result)); + } + else + { + return NoContent(); + } + } + catch (Exception) + { + return StatusCode((int)HttpStatusCode.InternalServerError, new { message = "Internal Server Error" }); + } + } + + //===================================== ROUTE DELETE ===================================== [HttpDelete("delete")] public async Task DeleteQuote([FromQuery] int idQuote) { diff --git a/WF_EF_Api/WfApi/WeatherForecast.cs b/WF_EF_Api/WfApi/WeatherForecast.cs deleted file mode 100644 index cb85aa4..0000000 --- a/WF_EF_Api/WfApi/WeatherForecast.cs +++ /dev/null @@ -1,13 +0,0 @@ -namespace WfApi -{ - public class WeatherForecast - { - public DateOnly Date { get; set; } - - public int TemperatureC { get; set; } - - public int TemperatureF => 32 + (int)(TemperatureC / 0.5556); - - public string? Summary { get; set; } - } -} From 6584bf6cafc5d3efd9854f92502258a52a78e6bd Mon Sep 17 00:00:00 2001 From: kekentin Date: Thu, 20 Mar 2025 15:36:21 +0100 Subject: [PATCH 25/65] merge --- WF_EF_Api/Contextlib/Contextlib.csproj | 1 + 1 file changed, 1 insertion(+) diff --git a/WF_EF_Api/Contextlib/Contextlib.csproj b/WF_EF_Api/Contextlib/Contextlib.csproj index 805901c..d2b9100 100644 --- a/WF_EF_Api/Contextlib/Contextlib.csproj +++ b/WF_EF_Api/Contextlib/Contextlib.csproj @@ -22,6 +22,7 @@ + From 57e2af4a452a22eb2c562276735430c491382e98 Mon Sep 17 00:00:00 2001 From: Kevin MONDEJAR Date: Tue, 25 Mar 2025 13:44:15 +0100 Subject: [PATCH 26/65] =?UTF-8?q?Mise=20=C3=A0=20jour=20de=20'README.md'?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 40e9d37..7a262d4 100644 --- a/README.md +++ b/README.md @@ -11,11 +11,11 @@ niveau | description | coeff | jalon | État 🎬 | les *projets* et les tests compilent | 1 | J1 & J2 | ✅ 🎬 | le projet et le tests s'exécutent sans bug (concernant la partie persistance) | 3 | J1 & J2 | ✅ 🟢 | Transcription du modèle : Modèle vers entités (et inversement) | 2 | J1 | 🟨 -🟢 | Requêtes CRUD simples (sur une table) | 1 | J1 | 🟨 -🟢 | Utilisation de LINQ to Entities | 2 | J1 | -🟡 | Injection / indépendance du fournisseur | 1 | J1 | ❌ -🟡 | Requêtes CRUD sur des données complexes (images par exemple) | 2 | J1 | 🟨 -🟢 | Tests - Appli Console | 1 | J1 | ❌ +🟢 | Requêtes CRUD simples (sur une table) | 1 | J1 | ✅ +🟢 | Utilisation de LINQ to Entities | 2 | J1 | ✅ +🟡 | Injection / indépendance du fournisseur | 1 | J1 | ✅ +🟡 | Requêtes CRUD sur des données complexes (images par exemple) | 2 | J1 | ✅ +🟢 | Tests - Appli Console | 1 | J1 | ✅ 🟢 | Tests - Tests unitaires (avec SQLite in memory) | 2 | J1 | ❌ 🟢 | Tests - Données stubbées et/ou Moq | 1 | J1 | ✅ 🟡 | CI : build, tests, Sonar (doc?) | 1 | J1 | ❌ @@ -25,7 +25,7 @@ niveau | description | coeff | jalon | État 🟡 | Déploiement | 4 | J2 | ❌ 🔴 | Unit of Work / Repository + extras (héritage, accès concurrents...) | 8 | J2 | ❌ 🟢 | Utilisation dans le projet | 2 | J2 | ❌ -🟢 | mon dépôt possède un readme qui apporte quelque chose... | 2 | J2 | ❌ +🟢 | mon dépôt possède un readme qui apporte quelque chose... | 2 | J2 | ✅ ### Critères Web API From b6e78e4950e56930352f9d5cb7d24231dc2118f7 Mon Sep 17 00:00:00 2001 From: Kevin MONDEJAR Date: Tue, 25 Mar 2025 14:01:21 +0100 Subject: [PATCH 27/65] Generic mappers (to use in extention methode) --- WF_EF_Api/Shared/Mapper.cs | 47 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 WF_EF_Api/Shared/Mapper.cs diff --git a/WF_EF_Api/Shared/Mapper.cs b/WF_EF_Api/Shared/Mapper.cs new file mode 100644 index 0000000..890c8d3 --- /dev/null +++ b/WF_EF_Api/Shared/Mapper.cs @@ -0,0 +1,47 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Shared +{ + public class Mapper where T : class + where U : class + { + readonly HashSet> mapper = new HashSet>(); + + public bool AddMapping(T t, U u) + { + var mapping = new Tuple(t, u); + if (mapper.Contains(mapping)) return false; + mapper.Add(mapping); + return true; + } + + public T? GetT(U u) + { + var result = mapper.Where(tuple => ReferenceEquals(tuple.Item2, u)); + if (result.Count() != 1) + { + return null; + } + return result.First().Item1; + } + + public U? GetU(T t) + { + var result = mapper.Where(tuple => ReferenceEquals(tuple.Item1, t)); + if (result.Count() != 1) + { + return null; + } + return result.First().Item2; + } + + public void Reset() + { + mapper.Clear(); + } + } +} From d8c91fd73e29fc8a29182a2ca1501ed4f2ddbec4 Mon Sep 17 00:00:00 2001 From: Kevin MONDEJAR Date: Tue, 25 Mar 2025 16:36:44 +0100 Subject: [PATCH 28/65] GenericRepository + Modification DbManager + Mapper --- WF_EF_Api/ConsoleTest/Program.cs | 6 +- WF_EF_Api/Contextlib/Contextlib.csproj | 1 + WF_EF_Api/Contextlib/DbCharacterManager.cs | 84 ++++------ WF_EF_Api/Contextlib/DbCommentaryManager.cs | 11 +- WF_EF_Api/Contextlib/DbImagesManager.cs | 87 ++++------ WF_EF_Api/Contextlib/DbQuestionManager.cs | 155 ++++++++++++++++++ WF_EF_Api/Contextlib/DbQuestionSerice.cs | 73 --------- WF_EF_Api/Contextlib/GenericRepository.cs | 120 ++++++++++++++ WF_EF_Api/Entity/Question.cs | 3 + WF_EF_Api/StubbedContextLib/StubWTFContext.cs | 18 +- 10 files changed, 364 insertions(+), 194 deletions(-) create mode 100644 WF_EF_Api/Contextlib/DbQuestionManager.cs delete mode 100644 WF_EF_Api/Contextlib/DbQuestionSerice.cs create mode 100644 WF_EF_Api/Contextlib/GenericRepository.cs diff --git a/WF_EF_Api/ConsoleTest/Program.cs b/WF_EF_Api/ConsoleTest/Program.cs index 7a36b87..4c4c4f5 100644 --- a/WF_EF_Api/ConsoleTest/Program.cs +++ b/WF_EF_Api/ConsoleTest/Program.cs @@ -22,8 +22,8 @@ using (var _context = new StubWTFContext(options)) var imageManager = new DbImagesManager(_context); - await imageManager.AddImage(new Images() { Id = 11, ImgPath = "https://www.bing.com/ck/a?!&&p=390428c2820add92760900204667aa721b17d4eb9e8537c91544d76283d06b14JmltdHM9MTc0MjQyODgwMA&ptn=3&ver=2&hsh=4&fclid=297ef5ed-ac44-66f2-2498-e058adb06776&u=a1aHR0cHM6Ly93d3cucG9rZXBlZGlhLmZyL01hamFzcGlj&ntb=1" }); - await imageManager.AddImage(new Images() { Id = 12, ImgPath = "https://www.bing.com/images/search?view=detailV2&ccid=t57OzeAT&id=1CCCBB65825E5FB93F10CA6D29EFDBBFEB5CDF27&thid=OIP.t57OzeATZKjBDDrzXqbc5gHaE7&mediaurl=https%3a%2f%2fimg-19.commentcamarche.net%2fP51ArxVXHJKsgdTzGDaqajlWJ3s%3d%2f1500x%2fsmart%2f7b5dd43e607643fea1a61960e3f66fc4%2fccmcms-commentcamarche%2f39481621.jpg&cdnurl=https%3a%2f%2fth.bing.com%2fth%2fid%2fR.b79ececde01364a8c10c3af35ea6dce6%3frik%3dJ99c67%252fb7yltyg%26pid%3dImgRaw%26r%3d0&exph=999&expw=1500&q=image&simid=608026907577902968&ck=0D54F216D075AD6E0ABC46B3AAB7E80A&selectedIndex=19&itb=0" }); + await imageManager.AddImage(new Images() { Id = 0, ImgPath = "https://www.bing.com/ck/a?!&&p=390428c2820add92760900204667aa721b17d4eb9e8537c91544d76283d06b14JmltdHM9MTc0MjQyODgwMA&ptn=3&ver=2&hsh=4&fclid=297ef5ed-ac44-66f2-2498-e058adb06776&u=a1aHR0cHM6Ly93d3cucG9rZXBlZGlhLmZyL01hamFzcGlj&ntb=1" }); + await imageManager.AddImage(new Images() { Id = 0, ImgPath = "https://www.bing.com/images/search?view=detailV2&ccid=t57OzeAT&id=1CCCBB65825E5FB93F10CA6D29EFDBBFEB5CDF27&thid=OIP.t57OzeATZKjBDDrzXqbc5gHaE7&mediaurl=https%3a%2f%2fimg-19.commentcamarche.net%2fP51ArxVXHJKsgdTzGDaqajlWJ3s%3d%2f1500x%2fsmart%2f7b5dd43e607643fea1a61960e3f66fc4%2fccmcms-commentcamarche%2f39481621.jpg&cdnurl=https%3a%2f%2fth.bing.com%2fth%2fid%2fR.b79ececde01364a8c10c3af35ea6dce6%3frik%3dJ99c67%252fb7yltyg%26pid%3dImgRaw%26r%3d0&exph=999&expw=1500&q=image&simid=608026907577902968&ck=0D54F216D075AD6E0ABC46B3AAB7E80A&selectedIndex=19&itb=0" }); Console.WriteLine("---- Test ajout image (id : 11, 12)"); var images = await imageManager.GetAllImage(); foreach (var image in images.items) @@ -82,7 +82,7 @@ using (var _context = new StubWTFContext(options)) var characterManager = new DbCharacterManager(_context); - await characterManager.AddCharacter(new Character() { Id = 11, Name = "Vipélière", IdImage = 11 }); + await characterManager.AddCharacter(new Character() { Id = 0, Name = "Vipélière", IdImage = 11 }); Console.WriteLine("---- Test ajout charcter (id : 11)"); var characters = await characterManager.GetAll(); foreach (var charac in characters.items) diff --git a/WF_EF_Api/Contextlib/Contextlib.csproj b/WF_EF_Api/Contextlib/Contextlib.csproj index d2b9100..960e394 100644 --- a/WF_EF_Api/Contextlib/Contextlib.csproj +++ b/WF_EF_Api/Contextlib/Contextlib.csproj @@ -18,6 +18,7 @@ all runtime; build; native; contentfiles; analyzers; buildtransitive + diff --git a/WF_EF_Api/Contextlib/DbCharacterManager.cs b/WF_EF_Api/Contextlib/DbCharacterManager.cs index e0d75e1..9b36686 100644 --- a/WF_EF_Api/Contextlib/DbCharacterManager.cs +++ b/WF_EF_Api/Contextlib/DbCharacterManager.cs @@ -12,10 +12,12 @@ namespace Contextlib public class DbCharacterManager : ICharacterService { private WTFContext _context; + private GenericRepository _repo; public DbCharacterManager(WTFContext context) { _context = context ?? throw new ArgumentNullException(nameof(context), "Database context cannot be null."); + _repo = new GenericRepository(_context); } /// @@ -28,10 +30,9 @@ namespace Contextlib { if (character == null) { - throw new ArgumentNullException(nameof(character), "Character cannot be null."); + throw new ArgumentNullException(nameof(character), "character cannot be null."); } - - await _context.AddAsync(character); + _repo.Insert(character); await _context.SaveChangesAsync(); } @@ -39,11 +40,10 @@ namespace Contextlib /// Retrieves all characters from the database and returns them in a paginated format. /// /// A task representing the asynchronous operation, with a as its result containing the full list of characters and pagination information. - public Task> GetAll() + public async Task> GetAll() { - List charLst = _context.characters.Include(i => i.Images).ToList(); - - return Task.FromResult(new PaginationResult(charLst.Count, 0, charLst.Count, charLst)); + List charLst = _repo.GetItems(0, _repo.Count(), [nameof(Character.Images)]).ToList(); + return new PaginationResult(charLst.Count, 0, charLst.Count, charLst); } /// @@ -54,15 +54,11 @@ namespace Contextlib /// Thrown when no character is found with the given ID. public async Task GetCharById(int id) { - Character? character = await _context.characters - .Include(i => i.Images) - .FirstOrDefaultAsync(x => x.Id == id); - + Character? character = _repo.GetById(id, item => item.Id == id, nameof(Character.Images)); if (character == null) { throw new KeyNotFoundException($"Error : No character found with the ID: {id}."); } - return character; } @@ -74,9 +70,7 @@ namespace Contextlib /// Thrown when no character is found with the given name. public async Task GetCharByName(string name) { - var character = await _context.characters - .Where(c => EF.Functions.Like(c.Name, name)) - .FirstOrDefaultAsync(); + var character = _repo.GetItems(item => item.Name == name,0,1, [nameof(Character.Images)]).FirstOrDefault(); if (character == null) { @@ -92,11 +86,16 @@ namespace Contextlib /// The highest character ID in the database. 0 if there is no character in the database public async Task GetLastCharId() { - int id = await _context.characters - .OrderByDescending(x => x.Id) - .Select(x => x.Id) - .FirstOrDefaultAsync(); - return id; + PaginationResult characters = await GetAll(); + int lastCharId = 0; + foreach (Character character in characters.items) + { + if (character.Id >= lastCharId) + { + lastCharId = character.Id + 1; + } + } + return lastCharId; } /// @@ -107,13 +106,7 @@ namespace Contextlib /// Thrown when no character is found with the given ID. public async Task RemoveCharacter(int id) { - Character? character = await _context.characters.FirstOrDefaultAsync(x => x.Id == id); - if (character == null) - { - throw new KeyNotFoundException($"Error : Unable to delete, no character found with the ID: {id}."); - } - - _context.characters.Remove(character); + _repo.Delete(id); await _context.SaveChangesAsync(); } @@ -127,29 +120,22 @@ namespace Contextlib /// Thrown when no character is found with the given ID. public async Task UpdateCharacter(int id, Character character) { - if (character == null) - { - throw new ArgumentNullException(nameof(character), "The updated character data cannot be null."); - } - var modif = false; - Character? charUpdated = await _context.characters.FirstOrDefaultAsync(x => x.Id == id); - if (charUpdated == null) - { - throw new KeyNotFoundException($"Error : Unable to update, no character found with the ID: {id} ."); - } - if (character.IdImage != 0) - { - charUpdated.IdImage = character.IdImage; - modif = true; - } - if (character.Name != null) - { - charUpdated.Name = character.Name; - modif = true; - } - if (modif) + Character? charac = _repo.GetById(id); + if (charac != null && charac != null) { - await _context.SaveChangesAsync(); + bool change = false; + if (character.IdImage != 0) + { + charac.IdImage = character.IdImage; + change = true; + } + if (character.Name != null) + { + charac.Name = character.Name; + change = true; + } + _repo.Update(charac); + if (change) _context.SaveChanges(); } } } diff --git a/WF_EF_Api/Contextlib/DbCommentaryManager.cs b/WF_EF_Api/Contextlib/DbCommentaryManager.cs index e5bde4f..c498637 100644 --- a/WF_EF_Api/Contextlib/DbCommentaryManager.cs +++ b/WF_EF_Api/Contextlib/DbCommentaryManager.cs @@ -13,10 +13,12 @@ namespace Contextlib public class DbCommentManager : ICommentService { private WTFContext _context; + private GenericRepository _repo; public DbCommentManager(WTFContext context) { _context = context ?? throw new ArgumentNullException(nameof(context), "Database context cannot be null."); + _repo = new GenericRepository(context); } /// @@ -32,7 +34,7 @@ namespace Contextlib throw new ArgumentNullException(nameof(comment), "Comment cannot be null."); } - await _context.comments.AddAsync(comment); + _repo.Insert(comment); await _context.SaveChangesAsync(); } @@ -144,12 +146,7 @@ namespace Contextlib public async Task RemoveComment(int id) { - var comment = await _context.comments.Where(x => x.Id == id).FirstOrDefaultAsync(); - if (comment == null) - { - throw new KeyNotFoundException($"No comments found with the given ID: {id}."); - } - _context.comments.Remove(comment); + _repo.Delete(id); await _context.SaveChangesAsync(); } diff --git a/WF_EF_Api/Contextlib/DbImagesManager.cs b/WF_EF_Api/Contextlib/DbImagesManager.cs index ad51785..999f546 100644 --- a/WF_EF_Api/Contextlib/DbImagesManager.cs +++ b/WF_EF_Api/Contextlib/DbImagesManager.cs @@ -13,97 +13,78 @@ namespace Contextlib public class DbImagesManager : IImagesService { private WTFContext _context; + private GenericRepository _repository; public DbImagesManager(WTFContext context) { _context = context ?? throw new ArgumentNullException(nameof(context), "Database context cannot be null."); + _repository = new GenericRepository(context); } public async Task AddImage(Images image) { - await _context.AddAsync(image); + _repository.Insert(image); await _context.SaveChangesAsync(); } public async Task> GetAllImage() { - var images = await _context.images.ToListAsync(); - return new PaginationResult(images.Count, 0, images.Count, images); + return new PaginationResult(await CountImage(), 0, await CountImage(), _repository.GetItems(0, await CountImage()).ToList()); } public async Task GetImageById(int id) { - var image = await _context.images.Where(x => x.Id == id).FirstOrDefaultAsync(); - if (image == null) - { - throw new KeyNotFoundException($"No image found with the given ID: {id}."); - } - return image; + return _repository.GetById(id); } public async Task GetLastImageId() { - var last = await _context.images.OrderByDescending(x => x.Id).FirstOrDefaultAsync(); - if (last == null) + var last = await GetAllImage(); + int id = 1; { - return 0; + foreach (Images image in last.items) + { + if(image.Id >= id) + id = image.Id + 1; + } } - return last.Id; + return id; } public async Task> GetSomeImage(int index, int pageSize) { - var images = await _context.images.ToListAsync(); - if (!images.Any()) - { - throw new KeyNotFoundException($"No images found"); - } - if ((index * pageSize + pageSize) > images.Count) - { - if (pageSize > images.Count) - { - return new PaginationResult(images.Count(), index, pageSize, images); - } - else - { - return new PaginationResult(pageSize, index, pageSize, images.Skip(index * pageSize - (((index * pageSize) + pageSize) - images.Count)).Take(pageSize).ToList()); - } - } - return new PaginationResult(images.Count, index, pageSize, images.Skip(index * pageSize).Take(pageSize).ToList()); + var images = _repository.GetItems(index, pageSize); + return new PaginationResult(images.Count(),index,pageSize,images.ToList()); } public async Task RemoveImage(int id) { - var image = await _context.images.Where(x => x.Id == id).FirstOrDefaultAsync(); - if (image == null) - { - throw new KeyNotFoundException($"No image found with the given ID: {id}."); - } - _context.images.Remove(image); + _repository.Delete(id); await _context.SaveChangesAsync(); } public async Task UpdateImage(int id, Images image) { + var img = _repository.GetById(id); var modif = false; - var img = await _context.images.Where(x => x.Id == id).FirstOrDefaultAsync(); - if (image == null) + if (image != null && img != null) { - throw new ArgumentNullException(nameof(image), "The updated image data cannot be null."); - } - if (img == null) - { - throw new KeyNotFoundException($"No image found with the given ID: {id}."); - } - if (image.ImgPath != null) - { - img.ImgPath = image.ImgPath; - modif = true; - } - if (modif) - { - await _context.SaveChangesAsync(); - } + if (image.ImgPath != null) + { + img.ImgPath = image.ImgPath; + modif = true; + } + _repository.Update(img); + if (modif) + { + await _context.SaveChangesAsync(); + } + } + } + + public async Task CountImage() + { + return await _context.images.CountAsync(); } } } diff --git a/WF_EF_Api/Contextlib/DbQuestionManager.cs b/WF_EF_Api/Contextlib/DbQuestionManager.cs new file mode 100644 index 0000000..5e323b7 --- /dev/null +++ b/WF_EF_Api/Contextlib/DbQuestionManager.cs @@ -0,0 +1,155 @@ +using Entity; +using Microsoft.EntityFrameworkCore; +using Shared; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Contextlib +{ + public class DbQuestionManager : IQuestionService + { + private WTFContext _context; + private GenericRepository _repository; + + public DbQuestionManager(WTFContext context) + { + _context = context ?? throw new ArgumentNullException(nameof(context), "Database context cannot be null."); + _repository = new GenericRepository(context); + } + + public async Task AddQuestion(Question question) + { + _repository.Insert(question); + await _context.SaveChangesAsync(); + } + + public async Task CountQuestions() + { + return _repository.Count(); + } + + public async Task> GetAllQuestion() + { + return new PaginationResult(_repository.Count(), 0, _repository.Count(), _repository.GetItems(0,_repository.Count()).ToList()); + } + + public async Task> GetInvalidQuestion(int index, int pageSize) + { + List questionList = _repository.GetItems(item => item.IsValid == false, index, pageSize).ToList(); + return new PaginationResult(questionList.Count(), index, pageSize, questionList); + } + + public async Task GetQuestionById(int id) + { + return _repository.GetById(id); + } + + public async Task GetRandomQuestion() + { + Random rnd = new Random(); + Question? question = null; + while(question == null) + { + question = await GetQuestionById(rnd.Next(0, await LastId()-1)); + } + return question; + } + + public async Task GetRandomQuestionQuoteToCharacter() + { + //dabord implémenter get random quote + throw new NotImplementedException(); + } + + public async Task GetRandomQuestionQuoteToSource() + { + //dabord implémenter get random quote + throw new NotImplementedException(); + } + + public async Task> GetSomeQuestion(int index, int pageSize) + { + List questionList = _repository.GetItems(item => item.IsValid == false, index, pageSize).ToList(); + return new PaginationResult(questionList.Count(), index, pageSize, questionList); + } + + public async Task RemoveQuestion(int id) + { + _repository.Delete(id); + await _context.SaveChangesAsync(); + } + + public async Task UpdateQuestion(int id, Question question) + { + Question? questionUpdated = await GetQuestionById(id); + if (question != null && questionUpdated != null) + { + bool modified = false; + if (question.IsValid != questionUpdated.IsValid) + { + questionUpdated.IsValid = question.IsValid; + modified = true; + } + if (question.Text != null) + { + questionUpdated.Text = question.Text; + modified = true; + } + if (question.AnswerA != null) + { + questionUpdated.AnswerA = question.AnswerA; + modified = true; + } + if (question.AnswerB != null) + { + questionUpdated.AnswerB = question.AnswerB; + modified = true; + } + if (question.AnswerC != null) + { + questionUpdated.AnswerC = question.AnswerC; + modified = true; + } + if (question.AnswerD != null) + { + questionUpdated.AnswerD = question.AnswerD; + modified = true; + } + if (question.CorrectAnswer != null) + { + questionUpdated.CorrectAnswer = question.CorrectAnswer; + modified = true; + } + _repository.Update(questionUpdated); + if(modified) _context.SaveChanges(); + } + ; + + } + + public async Task ValidateQuestion(int id, bool isvalid) + { + Question? question = await GetQuestionById(id); + if (question == null) throw new KeyNotFoundException($"Aucune question avec l'id {id}"); + question.IsValid = isvalid; + _repository.Update(question); + } + + public async Task LastId() + { + PaginationResult questions = await GetAllQuestion(); + int id = 1; + foreach (Question question in questions.items) + { + if (question.Id >= id) + { + id = question.Id + 1; + } + } + return id; + } + } +} diff --git a/WF_EF_Api/Contextlib/DbQuestionSerice.cs b/WF_EF_Api/Contextlib/DbQuestionSerice.cs deleted file mode 100644 index 010f38c..0000000 --- a/WF_EF_Api/Contextlib/DbQuestionSerice.cs +++ /dev/null @@ -1,73 +0,0 @@ -using Entity; -using Shared; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace Contextlib -{ - public class DbQuestionSerice : IQuestionService - { - public Task AddQuestion(Question question) - { - throw new NotImplementedException(); - } - - public Task CountQuestions() - { - throw new NotImplementedException(); - } - - public Task> GetAllQuestion() - { - throw new NotImplementedException(); - } - - public Task> GetInvalidQuestion(int index, int pageSize) - { - throw new NotImplementedException(); - } - - public Task GetQuestionById(int id) - { - throw new NotImplementedException(); - } - - public Task GetRandomQuestion() - { - throw new NotImplementedException(); - } - - public Task GetRandomQuestionQuoteToCharacter() - { - throw new NotImplementedException(); - } - - public Task GetRandomQuestionQuoteToSource() - { - throw new NotImplementedException(); - } - - public Task> GetSomeQuestion(int index, int pageSize) - { - throw new NotImplementedException(); - } - - public Task RemoveQuestion(int id) - { - throw new NotImplementedException(); - } - - public Task UpdateQuestion(int id, Question question) - { - throw new NotImplementedException(); - } - - public Task ValidateQuestion(int id, bool isvalid) - { - throw new NotImplementedException(); - } - } -} diff --git a/WF_EF_Api/Contextlib/GenericRepository.cs b/WF_EF_Api/Contextlib/GenericRepository.cs new file mode 100644 index 0000000..0bee129 --- /dev/null +++ b/WF_EF_Api/Contextlib/GenericRepository.cs @@ -0,0 +1,120 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Linq.Expressions; +using System.Text; +using System.Threading.Tasks; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Metadata.Internal; + +namespace Contextlib +{ + public class GenericRepository where T : class + { + private DbContext Context { get; set; } + private DbSet Set { get; set; } + + public GenericRepository(DbContext context) + { + Context = context; + Set = Context.Set(); + } + + public virtual T? GetById(object id) + => Set.Find(id); + + public virtual T? GetById(object id, Expression>? filter = null, params string[] includeProperties) + { + IQueryable query = Set; + if (filter != null) + { + query = query.Where(filter); + } + foreach (string includeProperty in includeProperties) + { + query = query.Include(includeProperty); + } + return query.FirstOrDefault(); + } + + public virtual IEnumerable GetItems(Expression>? filter = null, + int index = 0, int count = 10, + params string[] includeProperties) + => GetItems(filter, null, index, count, includeProperties); + + public virtual IEnumerable GetItems(Func, IOrderedQueryable>? orderBy = null, + int index = 0, int count = 10, + params string[] includeProperties) + => GetItems(null, orderBy, index, count, includeProperties); + + public virtual IEnumerable GetItems(int index = 0, int count = 10, + params string[] includeProperties) + => GetItems(null, null, index, count, includeProperties); + + public virtual IEnumerable GetItems(Expression>? filter = null, + Func, IOrderedQueryable>? orderBy = null, + int index = 0, int count = 10, + params string[] includeProperties) + { + IQueryable query = Set; + if (filter != null) + { + query = query.Where(filter); + } + foreach (string includeProperty in includeProperties) + { + query = query.Include(includeProperty); + } + if (orderBy != null) + { + query = orderBy(query); + } + return query.Skip(index * count) + .Take(count) + .ToList(); + } + + public virtual void Insert(T entity) + { + if (Set.Entry(entity).IsKeySet) + return; + Set.Add(entity); + } + + public virtual void Insert(params T[] entities) + { + foreach (var entity in entities) + { + Insert(entity); + } + } + + public virtual void Delete(object id) + { + T? entity = Set.Find(id); + if (entity == null) return; + Delete(entity); + } + + public virtual void Delete(T entity) + { + if (Context.Entry(entity).State == EntityState.Detached) + { + Set.Attach(entity); + } + Set.Remove(entity); + } + + public virtual void Update(T entity) + { + Set.Attach(entity); + Context.Entry(entity).State = EntityState.Modified; + } + + public virtual int Count() + { + return Set.Count(); + } + + } +} diff --git a/WF_EF_Api/Entity/Question.cs b/WF_EF_Api/Entity/Question.cs index b2e37e9..19c211b 100644 --- a/WF_EF_Api/Entity/Question.cs +++ b/WF_EF_Api/Entity/Question.cs @@ -38,6 +38,9 @@ namespace Entity [StringLength(1)] public string CorrectAnswer { get; set; } + [Required] + public bool IsValid { get; set; } + public ICollection Quizs { get; set; } = new List(); } } diff --git a/WF_EF_Api/StubbedContextLib/StubWTFContext.cs b/WF_EF_Api/StubbedContextLib/StubWTFContext.cs index 7c04527..7381211 100644 --- a/WF_EF_Api/StubbedContextLib/StubWTFContext.cs +++ b/WF_EF_Api/StubbedContextLib/StubWTFContext.cs @@ -97,16 +97,16 @@ namespace StubbedContextLib modelBuilder.Entity().HasData( - new Question() { Id = 1, Text = "Qui est le leader de la Communauté de l'Anneau ?", AnswerA = "Gimli", AnswerB = "Aragorn", AnswerC = "Frodon", AnswerD = "Gandalf", CorrectAnswer = "B" }, + new Question() { Id = 1, Text = "Qui est le leader de la Communauté de l'Anneau ?", AnswerA = "Gimli", AnswerB = "Aragorn", AnswerC = "Frodon", AnswerD = "Gandalf", CorrectAnswer = "B", IsValid = true }, new Question() { Id = 2, Text = "Dans quelle maison Harry Potter est-il ?", AnswerA = "Serdaigle", AnswerB = "Gryffondor", AnswerC = "Serpentard", AnswerD = "Poufsouffle", CorrectAnswer = "B" }, - new Question() { Id = 3, Text = "Qui est le Seigneur des Ténèbres dans la saga Le Seigneur des Anneaux ?", AnswerA = "Saroumane", AnswerB = "Sauron", AnswerC = "Gollum", AnswerD = "Gothmog", CorrectAnswer = "B" }, - new Question() { Id = 4, Text = "Dans le film Star Wars : Episode IV, qui sauve Luke Skywalker de l'Étoile de la Mort ?", AnswerA = "Han Solo", AnswerB = "Princesse Leia", AnswerC = "Chewbacca", AnswerD = "R2-D2", CorrectAnswer = "A" }, - new Question() { Id = 5, Text = "Qui est le souverain de Narnia dans Le Lion, la Sorcière Blanche et l'Armoire Magique ?", AnswerA = "Reine Jadis", AnswerB = "Aslan", AnswerC = "Edmund", AnswerD = "Lucy", CorrectAnswer = "B" }, - new Question() { Id = 6, Text = "Quel est le nom du dragon dans Le Hobbit ?", AnswerA = "Smaug", AnswerB = "Falkor", AnswerC = "Norbert", AnswerD = "Shenron", CorrectAnswer = "A" }, - new Question() { Id = 7, Text = "Qui est la première personne à être mordue par un vampire dans Twilight ?", AnswerA = "Bella Swan", AnswerB = "Edward Cullen", AnswerC = "Jacob Black", AnswerD = "Victoria", CorrectAnswer = "A" }, - new Question() { Id = 8, Text = "Quel personnage dit Que la Force soit avec toi dans Star Wars ?", AnswerA = "Obi-Wan Kenobi", AnswerB = "Yoda", AnswerC = "Han Solo", AnswerD = "Luke Skywalker", CorrectAnswer = "A" }, - new Question() { Id = 9, Text = "Dans Jurassic Park, quel est le nom du paléontologue sur l'île ?", AnswerA = "Dr. Ellie Sattler", AnswerB = "Alan Grant", AnswerC = "John Hammond", AnswerD = "Dennis Nedry", CorrectAnswer = "B" }, - new Question() { Id = 10, Text = "Dans Game of Thrones, qui est surnommée la Mère des Dragons ?", AnswerA = "Cersei Lannister", AnswerB = "Arya Stark", AnswerC = "Daenerys Targaryen", AnswerD = "Sansa Stark", CorrectAnswer = "C" } + new Question() { Id = 3, Text = "Qui est le Seigneur des Ténèbres dans la saga Le Seigneur des Anneaux ?", AnswerA = "Saroumane", AnswerB = "Sauron", AnswerC = "Gollum", AnswerD = "Gothmog", CorrectAnswer = "B", IsValid = true }, + new Question() { Id = 4, Text = "Dans le film Star Wars : Episode IV, qui sauve Luke Skywalker de l'Étoile de la Mort ?", AnswerA = "Han Solo", AnswerB = "Princesse Leia", AnswerC = "Chewbacca", AnswerD = "R2-D2", CorrectAnswer = "A", IsValid = true }, + new Question() { Id = 5, Text = "Qui est le souverain de Narnia dans Le Lion, la Sorcière Blanche et l'Armoire Magique ?", AnswerA = "Reine Jadis", AnswerB = "Aslan", AnswerC = "Edmund", AnswerD = "Lucy", CorrectAnswer = "B", IsValid = true }, + new Question() { Id = 6, Text = "Quel est le nom du dragon dans Le Hobbit ?", AnswerA = "Smaug", AnswerB = "Falkor", AnswerC = "Norbert", AnswerD = "Shenron", CorrectAnswer = "A", IsValid = true }, + new Question() { Id = 7, Text = "Qui est la première personne à être mordue par un vampire dans Twilight ?", AnswerA = "Bella Swan", AnswerB = "Edward Cullen", AnswerC = "Jacob Black", AnswerD = "Victoria", CorrectAnswer = "A", IsValid = true }, + new Question() { Id = 8, Text = "Quel personnage dit Que la Force soit avec toi dans Star Wars ?", AnswerA = "Obi-Wan Kenobi", AnswerB = "Yoda", AnswerC = "Han Solo", AnswerD = "Luke Skywalker", CorrectAnswer = "A", IsValid = true }, + new Question() { Id = 9, Text = "Dans Jurassic Park, quel est le nom du paléontologue sur l'île ?", AnswerA = "Dr. Ellie Sattler", AnswerB = "Alan Grant", AnswerC = "John Hammond", AnswerD = "Dennis Nedry", CorrectAnswer = "B", IsValid = true }, + new Question() { Id = 10, Text = "Dans Game of Thrones, qui est surnommée la Mère des Dragons ?", AnswerA = "Cersei Lannister", AnswerB = "Arya Stark", AnswerC = "Daenerys Targaryen", AnswerD = "Sansa Stark", CorrectAnswer = "C", IsValid = true } ); modelBuilder.Entity().HasData( From 1599968013ec9b7921e52d3c29528a812523cddd Mon Sep 17 00:00:00 2001 From: Kevin MONDEJAR Date: Tue, 25 Mar 2025 16:44:51 +0100 Subject: [PATCH 29/65] =?UTF-8?q?Mise=20=C3=A0=20jour=20de=20'README.md'?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 7a262d4..c6429b0 100644 --- a/README.md +++ b/README.md @@ -23,7 +23,7 @@ niveau | description | coeff | jalon | État 🟢 | Liens avec le web service | 2 | J1 | ❌ 🟡 | Utilisation d'un *Logger* | 1 | J1 | ❌ 🟡 | Déploiement | 4 | J2 | ❌ -🔴 | Unit of Work / Repository + extras (héritage, accès concurrents...) | 8 | J2 | ❌ +🔴 | Unit of Work❌ / Repository✅ + extras (héritage, accès concurrents...) | 8 | J2 | 🟨 🟢 | Utilisation dans le projet | 2 | J2 | ❌ 🟢 | mon dépôt possède un readme qui apporte quelque chose... | 2 | J2 | ✅ From a5b6fac9a6e0030e45187af6adee52c659365517 Mon Sep 17 00:00:00 2001 From: Kevin MONDEJAR Date: Tue, 25 Mar 2025 17:17:14 +0100 Subject: [PATCH 30/65] =?UTF-8?q?debut=20CI=20(a=20finir=20mais=20pas=20to?= =?UTF-8?q?uche,=20j'ai=20un=20mod=C3=A8le=20complet=20et=20fonctionnel=20?= =?UTF-8?q?entre=20les=20main)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .drone.yml | 91 ++++++++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 75 insertions(+), 16 deletions(-) diff --git a/.drone.yml b/.drone.yml index 6b39127..ed13d1e 100644 --- a/.drone.yml +++ b/.drone.yml @@ -1,23 +1,82 @@ -image: mcr.microsoft.com/dotnet/sdk:8.0 +kind: pipeline +type: docker +name: CI_ApiPm -volumes: - - name: docs - path: /docs +trigger: + event: + - push + branch: + exclude: + - master -- dotnet new tool-manifest -- dotnet tool install NSwag.ConsoleCore -- dotnet nswag aspnetcore2openapi /output:/docs/swagger.json +steps: + - name: retore & build + image: mcr.microsoft.com/dotnet/sdk:8.0 + commands: + - dotnet build --configuration Release + depend_on: [clone] -volumes: -- name: docs - temp: {} + - name: test + image: mcr.microsoft.com/dotnet/sdk:8.0 + commands: + - dotnet test + depends_on: [retore & build] + + - name: publish + image: mcr.microsoft.com/dotnet/sdk:8.0 + commands: + - dotnet publish -c Release -o out + depends_on: [retore & build, test] + +--- + +kind: pipeline +type: docker +name: CI_ApiPm_Master + +trigger: + event: + - push + branch: + - master -image: hub.codefirst.iut.uca.fr/thomas.bellembois/codefirst-docdeployer volumes: - - name: docs - path: /docs + - name: doc + temp: {} + + +steps: + - name: retore & build + image: mcr.microsoft.com/dotnet/sdk:8.0 + commands: + - dotnet build --configuration Release + depend_on: [clone] -commands: - - /entrypoint.sh + - name: test + image: mcr.microsoft.com/dotnet/sdk:8.0 + commands: + - dotnet test + depends_on: [retore & build] -depends_on: [ previous_job_name ] \ No newline at end of file + - name: generate doc + image: mcr.microsoft.com/dotnet/sdk:8.0 + volumes: + - name: doc + path: /doc + commands: + - dotnet new tool-manifest + - dotnet tool install NSwag.ConsoleCore + - dotnet restore + - cd WF_EF_Api/WfApi + - dotnet nswag aspnetcore2openapi /output:/doc/swagger.json + depends_on: [clone, retore & build] + + #- name: code-inspection + # image: hub.codefirst.iut.uca.fr/marc.chevaldonne:codefirs-dronsonarplugin-dotnet8 + # secret: [SECRET_SONAR_LOGIN] + # A FINIR + - name: publish + image: mcr.microsoft.com/dotnet/sdk:8.0 + commands: + - dotnet publish -c Release -o out + depends_on: [retore & build, test] \ No newline at end of file From 960a966f06fc50a923c1d3c7f73a40af2be6c83b Mon Sep 17 00:00:00 2001 From: kekentin Date: Thu, 27 Mar 2025 11:59:54 +0100 Subject: [PATCH 31/65] =?UTF-8?q?Cr=C3=A9ation=20DbUsersManager=20pour=20d?= =?UTF-8?q?=C3=A9buter=20relation=20User=20de=20API=20=C3=A0=20EF=20Fait?= =?UTF-8?q?=20en=20binome=20avec=20L=C3=A9ni?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- WF_EF_Api/Contextlib/DbCharacterManager.cs | 2 +- WF_EF_Api/Contextlib/DbUsersManager.cs | 154 +++++++++++++++++++++ WF_EF_Api/Contextlib/WTFContext.cs | 4 + WF_EF_Api/Dto2Entities/Extention.cs | 4 +- WF_EF_Api/Entity/Quote.cs | 6 - WF_EF_Api/Entity/Users.cs | 5 + 6 files changed, 166 insertions(+), 9 deletions(-) create mode 100644 WF_EF_Api/Contextlib/DbUsersManager.cs diff --git a/WF_EF_Api/Contextlib/DbCharacterManager.cs b/WF_EF_Api/Contextlib/DbCharacterManager.cs index 9b36686..e81dc1d 100644 --- a/WF_EF_Api/Contextlib/DbCharacterManager.cs +++ b/WF_EF_Api/Contextlib/DbCharacterManager.cs @@ -121,7 +121,7 @@ namespace Contextlib public async Task UpdateCharacter(int id, Character character) { Character? charac = _repo.GetById(id); - if (charac != null && charac != null) + if (charac != null) { bool change = false; if (character.IdImage != 0) diff --git a/WF_EF_Api/Contextlib/DbUsersManager.cs b/WF_EF_Api/Contextlib/DbUsersManager.cs new file mode 100644 index 0000000..d816444 --- /dev/null +++ b/WF_EF_Api/Contextlib/DbUsersManager.cs @@ -0,0 +1,154 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Entity; +using Shared; + +namespace Contextlib +{ + public class DbUsersManager : IUserService + { + private WTFContext _context; + private GenericRepository _repo; + + public DbUsersManager( WTFContext context ) + { + _context = context ?? throw new ArgumentNullException(nameof(context), "Database context cannot be null."); + _repo = new GenericRepository(_context); + } + + public async Task AddUser(Users user) + { + if (user == null) { + throw new ArgumentNullException(nameof(user), "user cannot be null."); + } + _repo.Insert(user); + await _context.SaveChangesAsync(); + } + + public async Task CountUser() + { + return _repo.Count(); + } + + public async Task ExistEmail(string email) + { + throw new NotImplementedException(); + } + + public async Task ExistUsername(string username) + { + throw new NotImplementedException(); + } + + public async Task> GetAllUser() + { + List users = _repo.GetItems(0,_repo.Count(),[nameof(Users.Images)]).ToList(); + return new PaginationResult(users.Count,0,users.Count,users); + } + + public async Task GetHashPassword(string username) + { + throw new NotImplementedException(); + } + + public async Task GetLastUserId() + { + PaginationResult users = await GetAllUser(); + int lastUserId = 0; + foreach (Users user in users.items) + { + if (user.Id >= lastUserId) + { + lastUserId = user.Id + 1; + } + } + return lastUserId; + } + + public async Task> GetSomeUser(int index, int pageSize) + { + List users = _repo.GetItems(index, pageSize, [nameof(Users.Images)]).ToList(); + return new PaginationResult(users.Count, index, pageSize, users); + } + + public async Task GetUserByEmail(string email) + { + var user = _repo.GetItems(item => item.Email == email, 0, 1, [nameof(Character.Images)]).FirstOrDefault(); + + if (user == null) + { + throw new KeyNotFoundException($"Error : No user found with the email: {email}."); + } + + return user; + } + + public async Task GetUserById(int id) + { + Users? user =_repo.GetById(id, item => item.Id == id, nameof(Users.Images)); + if (user == null) + { + throw new KeyNotFoundException($"Error : No users found with the ID: {id}."); + } + return user; + } + + public async Task GetUserByUsername(string username) + { + var user = _repo.GetItems(item => item.UserName == username, 0, 1, [nameof(Character.Images)]).FirstOrDefault(); + + if (user == null) + { + throw new KeyNotFoundException($"Error : No user found with the name: {username}."); + } + + return user; + } + + public async Task RemoveUser(Users user) + { + _repo.Delete(user); + await _context.SaveChangesAsync(); + } + + public async Task SetAdminRole(bool isAdmin) + { + throw new NotImplementedException(); + } + + public async Task UpdateUser(int userId, Users user) + { + Users? u = _repo.GetById(userId); + if (u != null) + { + bool change = false; + if (user.IdImage != 0) + { + u.IdImage = user.IdImage; + change = true; + } + if (user.UserName != null) + { + u.UserName = user.UserName; + change = true; + } + if (user.Email != null) + { + u.Email = user.Email; + change = true; + } + if (user.Password != null) + { + u.Password = user.Password; + change = true; + } + _repo.Update(u); + if (change)_context.SaveChanges(); + } + return u; + } + } +} diff --git a/WF_EF_Api/Contextlib/WTFContext.cs b/WF_EF_Api/Contextlib/WTFContext.cs index 4b95f3b..2706b88 100644 --- a/WF_EF_Api/Contextlib/WTFContext.cs +++ b/WF_EF_Api/Contextlib/WTFContext.cs @@ -24,6 +24,7 @@ namespace Contextlib //public DbSet records { get; set; } public DbSet sources { get; set; } public DbSet users { get; set; } + public DbSet admins { get; set; } protected override void OnModelCreating(ModelBuilder modelBuilder) { @@ -74,6 +75,9 @@ namespace Contextlib l => l.HasOne().WithMany().HasForeignKey(q => q.IdQuestion), r => r.HasOne().WithMany().HasForeignKey(u => u.IdQuiz) ); + modelBuilder.Entity() + .HasOne(a => a.User) + .WithOne(u => u.admin); } public WTFContext() diff --git a/WF_EF_Api/Dto2Entities/Extention.cs b/WF_EF_Api/Dto2Entities/Extention.cs index 62ed743..fb300ef 100644 --- a/WF_EF_Api/Dto2Entities/Extention.cs +++ b/WF_EF_Api/Dto2Entities/Extention.cs @@ -28,8 +28,8 @@ namespace Dto2Entities commentary.Id = item.Id; commentary.Date = item.DateCommentary; commentary.Comment = item.Comment; - commentary.User = item.Users.UserName; - commentary.ImagePath = item.Users.Images.ImgPath; + commentary.User = item.User.UserName; + commentary.ImagePath = item.User.Images.ImgPath; return commentary; } diff --git a/WF_EF_Api/Entity/Quote.cs b/WF_EF_Api/Entity/Quote.cs index 68b12c1..37d5f00 100644 --- a/WF_EF_Api/Entity/Quote.cs +++ b/WF_EF_Api/Entity/Quote.cs @@ -46,12 +46,6 @@ namespace Entity public Character Character { get; set; } = null!; - public Users? User { get; set; } = null!; - - public Source Source { get; set; } = null!; - - public Character Character { get; set; } = null!; - public ICollection DailyQuotes { get; set; } = new List(); public ICollection Commentarys { get; set; } = new List(); diff --git a/WF_EF_Api/Entity/Users.cs b/WF_EF_Api/Entity/Users.cs index e7a8101..6b834eb 100644 --- a/WF_EF_Api/Entity/Users.cs +++ b/WF_EF_Api/Entity/Users.cs @@ -38,5 +38,10 @@ namespace Entity public ICollection Quotes { get; set; } = new List(); public ICollection Favorite { get; set; } = new List(); + + + [ForeignKey(nameof(Admin))] + public int Idadmin { get; set; } + public Admin admin { get; set; } } } From 1056339f263051ce7a6d8a6a4a695f2e335e83fa Mon Sep 17 00:00:00 2001 From: kekentin Date: Fri, 28 Mar 2025 10:23:12 +0100 Subject: [PATCH 32/65] finition DbUsersManager --- WF_EF_Api/Contextlib/DbUsersManager.cs | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/WF_EF_Api/Contextlib/DbUsersManager.cs b/WF_EF_Api/Contextlib/DbUsersManager.cs index d816444..e4d2940 100644 --- a/WF_EF_Api/Contextlib/DbUsersManager.cs +++ b/WF_EF_Api/Contextlib/DbUsersManager.cs @@ -35,12 +35,14 @@ namespace Contextlib public async Task ExistEmail(string email) { - throw new NotImplementedException(); + IQueryable users = _context.users.Where(u=>u.Email == email); + return users != null; } public async Task ExistUsername(string username) { - throw new NotImplementedException(); + IQueryable users = _context.users.Where(u => u.UserName == username); + return users != null; } public async Task> GetAllUser() @@ -51,7 +53,12 @@ namespace Contextlib public async Task GetHashPassword(string username) { - throw new NotImplementedException(); + Users? user = _context.users.Where(u=>u.UserName == username).FirstOrDefault(); + if (user != null) + { + return ""; + } + return user.Password; } public async Task GetLastUserId() From 0aeb05fa884cfcafcb982fc7dbf9559784ecc176 Mon Sep 17 00:00:00 2001 From: kekentin Date: Fri, 28 Mar 2025 10:53:28 +0100 Subject: [PATCH 33/65] Finition des ToEntity --- WF_EF_Api/Dto2Entities/Extention.cs | 130 +++++++++++++++++++++++++++- 1 file changed, 129 insertions(+), 1 deletion(-) diff --git a/WF_EF_Api/Dto2Entities/Extention.cs b/WF_EF_Api/Dto2Entities/Extention.cs index fb300ef..a417220 100644 --- a/WF_EF_Api/Dto2Entities/Extention.cs +++ b/WF_EF_Api/Dto2Entities/Extention.cs @@ -144,6 +144,134 @@ namespace Dto2Entities // --------------------------- ToEntity --------------------------- \\ - + + public static Character ToEntity(this CharacterDTO item) + { + Character character = new Character(); + character.Id = item.Id; + character.Name = item.Name; + character.Images.ImgPath = item.imagePath ; + return character; + } + + public static Commentary ToEntity(this CommentaryDTO item) + { + Commentary commentary = new Commentary(); + commentary.Id = item.Id; + commentary.DateCommentary = item.Date; + commentary.Comment = item.Comment; + commentary.User.UserName = item.User; + commentary.User.Images.ImgPath = item.ImagePath; + return commentary; + } + + // Surement a refaire car Faoirite Entity modifier sur branche EF + public static Favorite ToEntity(this FavoriteDTO item) + { + Favorite favorite = new Favorite(); + favorite.IdUsers = item.IdUser; + favorite.IdQuote = item.IdQuote; + return favorite; + } + + public static Images ToEntity(this ImageDTO item) + { + Images image = new Images(); + image.Id = item.IdImage; + image.ImgPath = item.ImagePath; + return image; + } + + public static Question ToEntity(this QuestionDTO item) + { + Question question = new Question(); + question.Id = item.Id; + question.Text = item.Question; + question.AnswerA = item.AnswerA; + question.AnswerB = item.AnswerB; + question.AnswerC = item.AnswerC; + question.AnswerD = item.AnswerD; + question.CorrectAnswer = item.CorrectAnswer; + return question; + } + + public static Quiz ToEntity(this QuizDTO item) + { + Quiz quiz = new Quiz(); + quiz.Id = item.Id; + quiz.NbQuestion = item.NbQuestion; + quiz.Title = item.Title; + quiz.Images.ImgPath = item.ImagePath; + return quiz; + } + + // Surement a refaire car QuizQuestion Entity modifier sur branche EF + public static QuizQuestion ToEntity(this QuizQuestionDTO item) + { + QuizQuestion quizQuestion = new QuizQuestion(); + quizQuestion.IdQuiz = item.IdQuiz; + quizQuestion.IdQuestion = item.IdQuestion; + return quizQuestion; + } + + public static Quote ToEntity(this QuoteDTO item) + { + Quote quote = new Quote(); + quote.Id = item.Id; + quote.Content = item.Content; + quote.Source.Year = item.DateSource; + quote.Character.Name = item.Character; + quote.Source.Title = item.TitleSource; + quote.Langage = item.Langage.ToEntity(); + quote.Character.Images.ImgPath = item.ImagePath; + quote.Likes = item.Like; + quote.Source.TypeSrc = item.Type.ToEntity(); + return quote; + } + + public static Source ToEntity(this SourceDTO item) + { + Source source = new Source(); + source.Id = item.Id; + source.Year = item.Date; + source.Title = item.Title; + source.TypeSrc = item.Type.ToEntity(); + return source; + } + + public static Users ToEntity(this UserDTO item) + { + Users user = new Users(); + user.Id = item.Id; + user.UserName = item.Pseudo; + user.Password = item.Password; + user.Email = item.Email; + user.Created = item.date; + user.Images.ImgPath = item.ImageProfil; + return user; + } + + public static LangEnum ToEntity(this TypeLangageDTO item) + { + switch (item) + { + case TypeLangageDTO.vf: return LangEnum.vf; + case TypeLangageDTO.vo: return LangEnum.vo; + case TypeLangageDTO.ve: return LangEnum.ve; + default: return LangEnum.vo; + } + } + + public static TypeSrcEnum ToEntity(this TypeSrcEnumDTO item) + { + switch (item) + { + case TypeSrcEnumDTO.movie: return TypeSrcEnum.movie; + case TypeSrcEnumDTO.book: return TypeSrcEnum.book; + case TypeSrcEnumDTO.serie: return TypeSrcEnum.series; + case TypeSrcEnumDTO.videogame: return TypeSrcEnum.videogame; + default: return TypeSrcEnum.movie; + } + } } } From af4f9c8ba0d64724de2e085d231cf5db400ee39c Mon Sep 17 00:00:00 2001 From: Leni BEAULATON Date: Fri, 28 Mar 2025 11:04:56 +0100 Subject: [PATCH 34/65] Services API --- WF_EF_Api/Dto2Entities/Extention.cs | 10 ++ WF_EF_Api/ServicesApi/ServicesApi.csproj | 9 ++ WF_EF_Api/ServicesApi/UserService.cs | 92 +++++++++++++++++++ .../{QuoteService.cs => QuoteServiceStub.cs} | 4 +- .../{UserService.cs => UserServiceStub.cs} | 4 +- WF_EF_Api/WfApi/Program.cs | 11 ++- 6 files changed, 123 insertions(+), 7 deletions(-) create mode 100644 WF_EF_Api/ServicesApi/ServicesApi.csproj create mode 100644 WF_EF_Api/ServicesApi/UserService.cs rename WF_EF_Api/StubApi/{QuoteService.cs => QuoteServiceStub.cs} (97%) rename WF_EF_Api/StubApi/{UserService.cs => UserServiceStub.cs} (96%) diff --git a/WF_EF_Api/Dto2Entities/Extention.cs b/WF_EF_Api/Dto2Entities/Extention.cs index fb300ef..ad38331 100644 --- a/WF_EF_Api/Dto2Entities/Extention.cs +++ b/WF_EF_Api/Dto2Entities/Extention.cs @@ -119,6 +119,16 @@ namespace Dto2Entities return user; } + public static List ToDto(this List users) + { + List userDTOs = new List(); + foreach (Users user in users) + { + userDTOs.Add(ToDto(user)); + } + return userDTOs; + } + public static TypeLangageDTO ToDto(this LangEnum item) { switch (item) diff --git a/WF_EF_Api/ServicesApi/ServicesApi.csproj b/WF_EF_Api/ServicesApi/ServicesApi.csproj new file mode 100644 index 0000000..bb23fb7 --- /dev/null +++ b/WF_EF_Api/ServicesApi/ServicesApi.csproj @@ -0,0 +1,9 @@ + + + + net8.0 + enable + enable + + + diff --git a/WF_EF_Api/ServicesApi/UserService.cs b/WF_EF_Api/ServicesApi/UserService.cs new file mode 100644 index 0000000..cf71433 --- /dev/null +++ b/WF_EF_Api/ServicesApi/UserService.cs @@ -0,0 +1,92 @@ +using Shared; +using DTO; +using Contextlib; +using Entity; +using System.Xml.XPath; +using Dto2Entities; +namespace ServicesApi +{ + public class UserService : IUserService + { + + private IUserService userService; + + public UserService(IUserService user) + { + userService = user; + } + + public async Task AddUser(UserDTO user) + { + //await userService.AddUser(user); Quand les toEntity seront présents + } + + public async Task CountUser() + { + return await userService.CountUser(); + } + + public async Task ExistEmail(string email) + { + return await userService.ExistEmail(email); + } + + public async Task ExistUsername(string username) + { + return await userService.ExistUsername(username); + } + + public async Task> GetAllUser() + { + var users = userService.GetAllUser().Result.items; + return new PaginationResult(users.Count(), 0, 10, users.ToDto()); + } + + public async Task GetHashPassword(string username) + { + return await userService.GetHashPassword(username); + } + + public async Task GetLastUserId() + { + return await userService.GetLastUserId(); + } + + public async Task> GetSomeUser(int index, int pageSize) + { + var users = userService.GetSomeUser(index, pageSize).Result.items; + return new PaginationResult(users.Count(),index, pageSize, users.ToDto()); + } + + public async Task GetUserByEmail(string email) + { + return userService.GetUserByEmail(email).Result.ToDto(); + } + + public async Task GetUserById(int id) + { + return userService.GetUserById(id).Result.ToDto(); + } + + public async Task GetUserByUsername(string username) + { + return userService.GetUserByUsername(username).Result.ToDto(); + } + + public async Task RemoveUser(UserDTO user) + { + //await userService.RemoveUser(user); Quand les toEntity seront présents + } + + public async Task SetAdminRole(bool isAdmin) + { + await userService.SetAdminRole(isAdmin); + } + + public async Task UpdateUser(int userId, UserDTO user) + { + //await userService.UpdateUser(userId, user); Quand les toEntity seront présents + throw new NotImplementedException(); + } + } +} diff --git a/WF_EF_Api/StubApi/QuoteService.cs b/WF_EF_Api/StubApi/QuoteServiceStub.cs similarity index 97% rename from WF_EF_Api/StubApi/QuoteService.cs rename to WF_EF_Api/StubApi/QuoteServiceStub.cs index 53e261d..f0521b3 100644 --- a/WF_EF_Api/StubApi/QuoteService.cs +++ b/WF_EF_Api/StubApi/QuoteServiceStub.cs @@ -8,11 +8,11 @@ using System.Threading.Tasks; namespace StubApi { - public class QuoteService : IQuoteService + public class QuoteServiceStub : IQuoteService { private readonly List _quotes; - public QuoteService() + public QuoteServiceStub() { _quotes = new List { diff --git a/WF_EF_Api/StubApi/UserService.cs b/WF_EF_Api/StubApi/UserServiceStub.cs similarity index 96% rename from WF_EF_Api/StubApi/UserService.cs rename to WF_EF_Api/StubApi/UserServiceStub.cs index 315d9a5..b9c21f8 100644 --- a/WF_EF_Api/StubApi/UserService.cs +++ b/WF_EF_Api/StubApi/UserServiceStub.cs @@ -2,11 +2,11 @@ using DTO; namespace StubApi { - public class UserService : IUserService + public class UserServiceStub : IUserService { private readonly List _users; - public UserService() + public UserServiceStub() { _users = new List { diff --git a/WF_EF_Api/WfApi/Program.cs b/WF_EF_Api/WfApi/Program.cs index 5813f96..4232aa1 100644 --- a/WF_EF_Api/WfApi/Program.cs +++ b/WF_EF_Api/WfApi/Program.cs @@ -1,11 +1,16 @@ using DTO; using Shared; using StubApi; - +using Contextlib; +using Entity; var builder = WebApplication.CreateBuilder(args); +//API +builder.Services.AddScoped, UserServiceStub>(); +builder.Services.AddScoped, QuoteServiceStub>(); + -builder.Services.AddScoped, UserService>(); -builder.Services.AddScoped, QuoteService>(); +//EF +builder.Services.AddScoped, DbUsersManager>(); // Add services to the container. builder.Services.AddControllers(); From 4d2985f73f0e5fb0a7fbd2d2c3393ee29817b91a Mon Sep 17 00:00:00 2001 From: Leni BEAULATON Date: Fri, 28 Mar 2025 11:07:12 +0100 Subject: [PATCH 35/65] Services API --- WF_EF_Api/ServicesApi/UserService.cs | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/WF_EF_Api/ServicesApi/UserService.cs b/WF_EF_Api/ServicesApi/UserService.cs index cf71433..367cd2b 100644 --- a/WF_EF_Api/ServicesApi/UserService.cs +++ b/WF_EF_Api/ServicesApi/UserService.cs @@ -16,9 +16,11 @@ namespace ServicesApi userService = user; } + + public async Task AddUser(UserDTO user) { - //await userService.AddUser(user); Quand les toEntity seront présents + await userService.AddUser(user.ToEntity()); } public async Task CountUser() @@ -75,7 +77,7 @@ namespace ServicesApi public async Task RemoveUser(UserDTO user) { - //await userService.RemoveUser(user); Quand les toEntity seront présents + await userService.RemoveUser(user.ToEntity()); } public async Task SetAdminRole(bool isAdmin) @@ -85,7 +87,7 @@ namespace ServicesApi public async Task UpdateUser(int userId, UserDTO user) { - //await userService.UpdateUser(userId, user); Quand les toEntity seront présents + await userService.UpdateUser(userId, user.ToEntity()); throw new NotImplementedException(); } } From 3029f097bc9e3f962226e9afd6d86541d4aeb5d4 Mon Sep 17 00:00:00 2001 From: Leni BEAULATON Date: Fri, 28 Mar 2025 11:24:26 +0100 Subject: [PATCH 36/65] =?UTF-8?q?Normalement=20=C3=A7a=20marche,=20j'ai=20?= =?UTF-8?q?juste=20un=20pb=20de=20commande=20dotnet=20qui=20n'est=20pas=20?= =?UTF-8?q?reconnu=20sur=20la=20machine?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- WF_EF_Api/Contextlib/WTFContext.cs | 6 +++--- WF_EF_Api/Entity/Users.cs | 6 +++--- WF_EF_Api/ServicesApi/ServicesApi.csproj | 7 +++++++ WF_EF_Api/WF_EF_Api.sln | 11 ++++++----- WF_EF_Api/WfApi/Program.cs | 5 ++++- WF_EF_Api/WfApi/WfApi.csproj | 4 ++++ 6 files changed, 27 insertions(+), 12 deletions(-) diff --git a/WF_EF_Api/Contextlib/WTFContext.cs b/WF_EF_Api/Contextlib/WTFContext.cs index 2706b88..e82284d 100644 --- a/WF_EF_Api/Contextlib/WTFContext.cs +++ b/WF_EF_Api/Contextlib/WTFContext.cs @@ -75,9 +75,9 @@ namespace Contextlib l => l.HasOne().WithMany().HasForeignKey(q => q.IdQuestion), r => r.HasOne().WithMany().HasForeignKey(u => u.IdQuiz) ); - modelBuilder.Entity() - .HasOne(a => a.User) - .WithOne(u => u.admin); + //modelBuilder.Entity() + // .HasOne(a => a.User) + // .WithOne(u => u.admin); } public WTFContext() diff --git a/WF_EF_Api/Entity/Users.cs b/WF_EF_Api/Entity/Users.cs index 6b834eb..abcf80e 100644 --- a/WF_EF_Api/Entity/Users.cs +++ b/WF_EF_Api/Entity/Users.cs @@ -40,8 +40,8 @@ namespace Entity public ICollection Favorite { get; set; } = new List(); - [ForeignKey(nameof(Admin))] - public int Idadmin { get; set; } - public Admin admin { get; set; } + //[ForeignKey(nameof(Admin))] + //public int Idadmin { get; set; } + //public Admin admin { get; set; } } } diff --git a/WF_EF_Api/ServicesApi/ServicesApi.csproj b/WF_EF_Api/ServicesApi/ServicesApi.csproj index bb23fb7..89650c8 100644 --- a/WF_EF_Api/ServicesApi/ServicesApi.csproj +++ b/WF_EF_Api/ServicesApi/ServicesApi.csproj @@ -6,4 +6,11 @@ enable + + + + + + + diff --git a/WF_EF_Api/WF_EF_Api.sln b/WF_EF_Api/WF_EF_Api.sln index 728c68b..bb798b1 100644 --- a/WF_EF_Api/WF_EF_Api.sln +++ b/WF_EF_Api/WF_EF_Api.sln @@ -1,4 +1,3 @@ - Microsoft Visual Studio Solution File, Format Version 12.00 # Visual Studio Version 17 VisualStudioVersion = 17.9.34723.18 @@ -25,6 +24,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DTO", "DTO\DTO.csproj", "{9 EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Dto2Entities", "Dto2Entities\Dto2Entities.csproj", "{08194729-E222-4C9A-B860-D944225B8895}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ServicesApi", "ServicesApi\ServicesApi.csproj", "{6A9AC3D2-C1CD-450A-BD3C-22FAFC9B5328}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -55,10 +56,6 @@ Global {2CF20FAC-C2F1-4048-9D46-F39081B0FBEF}.Debug|Any CPU.Build.0 = Debug|Any CPU {2CF20FAC-C2F1-4048-9D46-F39081B0FBEF}.Release|Any CPU.ActiveCfg = Release|Any CPU {2CF20FAC-C2F1-4048-9D46-F39081B0FBEF}.Release|Any CPU.Build.0 = Release|Any CPU - {4A1CBA3D-C798-4E19-865F-39F919F1205A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {4A1CBA3D-C798-4E19-865F-39F919F1205A}.Debug|Any CPU.Build.0 = Debug|Any CPU - {4A1CBA3D-C798-4E19-865F-39F919F1205A}.Release|Any CPU.ActiveCfg = Release|Any CPU - {4A1CBA3D-C798-4E19-865F-39F919F1205A}.Release|Any CPU.Build.0 = Release|Any CPU {48002CA2-7CFF-4077-90CF-392476320CE3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {48002CA2-7CFF-4077-90CF-392476320CE3}.Debug|Any CPU.Build.0 = Debug|Any CPU {48002CA2-7CFF-4077-90CF-392476320CE3}.Release|Any CPU.ActiveCfg = Release|Any CPU @@ -79,6 +76,10 @@ Global {08194729-E222-4C9A-B860-D944225B8895}.Debug|Any CPU.Build.0 = Debug|Any CPU {08194729-E222-4C9A-B860-D944225B8895}.Release|Any CPU.ActiveCfg = Release|Any CPU {08194729-E222-4C9A-B860-D944225B8895}.Release|Any CPU.Build.0 = Release|Any CPU + {6A9AC3D2-C1CD-450A-BD3C-22FAFC9B5328}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {6A9AC3D2-C1CD-450A-BD3C-22FAFC9B5328}.Debug|Any CPU.Build.0 = Debug|Any CPU + {6A9AC3D2-C1CD-450A-BD3C-22FAFC9B5328}.Release|Any CPU.ActiveCfg = Release|Any CPU + {6A9AC3D2-C1CD-450A-BD3C-22FAFC9B5328}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/WF_EF_Api/WfApi/Program.cs b/WF_EF_Api/WfApi/Program.cs index 4232aa1..524f35a 100644 --- a/WF_EF_Api/WfApi/Program.cs +++ b/WF_EF_Api/WfApi/Program.cs @@ -3,13 +3,16 @@ using Shared; using StubApi; using Contextlib; using Entity; +using StubbedContextLib; +using ServicesApi; var builder = WebApplication.CreateBuilder(args); //API -builder.Services.AddScoped, UserServiceStub>(); +builder.Services.AddScoped, UserService>(); builder.Services.AddScoped, QuoteServiceStub>(); //EF +builder.Services.AddScoped(); builder.Services.AddScoped, DbUsersManager>(); // Add services to the container. diff --git a/WF_EF_Api/WfApi/WfApi.csproj b/WF_EF_Api/WfApi/WfApi.csproj index ab7442c..0416a92 100644 --- a/WF_EF_Api/WfApi/WfApi.csproj +++ b/WF_EF_Api/WfApi/WfApi.csproj @@ -17,9 +17,13 @@ + + + + From aa8cb64d6f77e120c4c65a33bd2c65ee8cb881ab Mon Sep 17 00:00:00 2001 From: kekentin Date: Fri, 28 Mar 2025 11:25:46 +0100 Subject: [PATCH 37/65] Debut rajoue ToDto / ToEntity avec des list --- WF_EF_Api/Dto2Entities/Extention.cs | 40 +++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/WF_EF_Api/Dto2Entities/Extention.cs b/WF_EF_Api/Dto2Entities/Extention.cs index a417220..a0b2a61 100644 --- a/WF_EF_Api/Dto2Entities/Extention.cs +++ b/WF_EF_Api/Dto2Entities/Extention.cs @@ -22,6 +22,16 @@ namespace Dto2Entities return character; } + public static List ToDto(this List item) + { + List characterDTOs = new List(); + foreach (Character character in item) + { + characterDTOs.Add(character.ToDto()); + } + return characterDTOs; + } + public static CommentaryDTO ToDto(this Commentary item) { CommentaryDTO commentary = new CommentaryDTO(); @@ -33,6 +43,16 @@ namespace Dto2Entities return commentary; } + public static List ToDto(this List item) + { + List commentaryDTOs = new List(); + foreach (Commentary commentary in item) + { + commentaryDTOs.Add(commentary.ToDto()); + } + return commentaryDTOs; + } + // Surement a refaire car Faoirite Entity modifier sur branche EF public static FavoriteDTO ToDto(this Favorite item) { @@ -42,6 +62,16 @@ namespace Dto2Entities return favorite; } + public static List ToDto(this List item) + { + List favoriteDTOs = new List(); + foreach (Favorite favorite in item) + { + favoriteDTOs.Add(favorite.ToDto()); + } + return favoriteDTOs; + } + public static ImageDTO ToDto(this Images item) { ImageDTO image = new ImageDTO(); @@ -50,6 +80,16 @@ namespace Dto2Entities return image; } + public static List ToDto(this List item) + { + List imageDTOs = new List(); + foreach (Images images in item) + { + imageDTOs.Add(images.ToDto()); + } + return imageDTOs; + } + public static QuestionDTO ToDto(this Question item) { QuestionDTO question = new QuestionDTO(); From 50fb9d8d68fd58fbcd38315fa0487877ef38268d Mon Sep 17 00:00:00 2001 From: kekentin Date: Fri, 28 Mar 2025 11:46:55 +0100 Subject: [PATCH 38/65] Finition ToDto / ToEntity avec des lists --- WF_EF_Api/Dto2Entities/Extention.cs | 159 ++- .../20250328102709_migr5.Designer.cs | 1107 +++++++++++++++++ .../Migrations/20250328102709_migr5.cs | 126 ++ .../Migrations/StubWTFContextModelSnapshot.cs | 42 + 4 files changed, 1429 insertions(+), 5 deletions(-) create mode 100644 WF_EF_Api/StubbedContextLib/Migrations/20250328102709_migr5.Designer.cs create mode 100644 WF_EF_Api/StubbedContextLib/Migrations/20250328102709_migr5.cs diff --git a/WF_EF_Api/Dto2Entities/Extention.cs b/WF_EF_Api/Dto2Entities/Extention.cs index b58d527..5d7d85f 100644 --- a/WF_EF_Api/Dto2Entities/Extention.cs +++ b/WF_EF_Api/Dto2Entities/Extention.cs @@ -103,6 +103,16 @@ namespace Dto2Entities return question; } + public static List ToDto(this List item) + { + List questionDTOs = new List(); + foreach (Question question in item) + { + questionDTOs.Add(question.ToDto()); + } + return questionDTOs; + } + public static QuizDTO ToDto(this Quiz item) { QuizDTO quiz = new QuizDTO(); @@ -113,6 +123,16 @@ namespace Dto2Entities return quiz; } + public static List ToDto(this List item) + { + List quizDTOs = new List(); + foreach (Quiz quiz in item) + { + quizDTOs.Add(quiz.ToDto()); + } + return quizDTOs; + } + // Surement a refaire car QuizQuestion Entity modifier sur branche EF public static QuizQuestionDTO ToDto(this QuizQuestion item) { @@ -122,6 +142,16 @@ namespace Dto2Entities return quizQuestion; } + public static List ToDto(this List item) + { + List quizQuestionDTOs = new List(); + foreach (QuizQuestion quizQuestion in item) + { + quizQuestionDTOs.Add(quizQuestion.ToDto()); + } + return quizQuestionDTOs; + } + public static QuoteDTO ToDto(this Quote item) { QuoteDTO quote = new QuoteDTO(); @@ -137,6 +167,16 @@ namespace Dto2Entities return quote; } + public static List ToDto(this List item) + { + List quoteDTOs = new List(); + foreach (Quote quote in item) + { + quoteDTOs.Add(quote.ToDto()); + } + return quoteDTOs; + } + public static SourceDTO ToDto(this Source item) { SourceDTO source = new SourceDTO(); @@ -147,6 +187,16 @@ namespace Dto2Entities return source; } + public static List ToDto(this List item) + { + List sourceDTOs = new List(); + foreach (Source source in item) + { + sourceDTOs.Add(source.ToDto()); + } + return sourceDTOs; + } + public static UserDTO ToDto(this Users item) { UserDTO user = new UserDTO(); @@ -159,14 +209,14 @@ namespace Dto2Entities return user; } - public static List ToDto(this List users) + public static List ToDto(this List item) { - List userDTOs = new List(); - foreach (Users user in users) + List users = new List(); + foreach (Users user in item) { - userDTOs.Add(ToDto(user)); + users.Add(user.ToDto()); } - return userDTOs; + return users; } public static TypeLangageDTO ToDto(this LangEnum item) @@ -204,6 +254,16 @@ namespace Dto2Entities return character; } + public static List ToEntity(this List item) + { + List characters = new List(); + foreach (CharacterDTO character in item) + { + characters.Add(character.ToEntity()); + } + return characters; + } + public static Commentary ToEntity(this CommentaryDTO item) { Commentary commentary = new Commentary(); @@ -215,6 +275,16 @@ namespace Dto2Entities return commentary; } + public static List ToEntity(this List item) + { + List commentarys = new List(); + foreach (CommentaryDTO commentary in item) + { + commentarys.Add(commentary.ToEntity()); + } + return commentarys; + } + // Surement a refaire car Faoirite Entity modifier sur branche EF public static Favorite ToEntity(this FavoriteDTO item) { @@ -224,6 +294,16 @@ namespace Dto2Entities return favorite; } + public static List ToEntity(this List item) + { + List favorites = new List(); + foreach (FavoriteDTO favorite in item) + { + favorites.Add(favorite.ToEntity()); + } + return favorites; + } + public static Images ToEntity(this ImageDTO item) { Images image = new Images(); @@ -232,6 +312,16 @@ namespace Dto2Entities return image; } + public static List ToEntity(this List item) + { + List images = new List(); + foreach (ImageDTO image in item) + { + images.Add(image.ToEntity()); + } + return images; + } + public static Question ToEntity(this QuestionDTO item) { Question question = new Question(); @@ -244,6 +334,15 @@ namespace Dto2Entities question.CorrectAnswer = item.CorrectAnswer; return question; } + public static List ToEntity(this List item) + { + List questions = new List(); + foreach (QuestionDTO question in item) + { + questions.Add(question.ToEntity()); + } + return questions; + } public static Quiz ToEntity(this QuizDTO item) { @@ -255,6 +354,16 @@ namespace Dto2Entities return quiz; } + public static List ToEntity(this List item) + { + List quizs = new List(); + foreach (QuizDTO quiz in item) + { + quizs.Add(quiz.ToEntity()); + } + return quizs; + } + // Surement a refaire car QuizQuestion Entity modifier sur branche EF public static QuizQuestion ToEntity(this QuizQuestionDTO item) { @@ -264,6 +373,16 @@ namespace Dto2Entities return quizQuestion; } + public static List ToEntity(this List item) + { + List quizQuestions = new List(); + foreach (QuizQuestionDTO quizQuestion in item) + { + quizQuestions.Add(quizQuestion.ToEntity()); + } + return quizQuestions; + } + public static Quote ToEntity(this QuoteDTO item) { Quote quote = new Quote(); @@ -279,6 +398,16 @@ namespace Dto2Entities return quote; } + public static List ToEntity(this List item) + { + List quotes = new List(); + foreach (QuoteDTO quote in item) + { + quotes.Add(quote.ToEntity()); + } + return quotes; + } + public static Source ToEntity(this SourceDTO item) { Source source = new Source(); @@ -289,6 +418,16 @@ namespace Dto2Entities return source; } + public static List ToEntity(this List item) + { + List sources = new List(); + foreach (SourceDTO source in item) + { + sources.Add(source.ToEntity()); + } + return sources; + } + public static Users ToEntity(this UserDTO item) { Users user = new Users(); @@ -301,6 +440,16 @@ namespace Dto2Entities return user; } + public static List ToEntity(this List item) + { + List users = new List(); + foreach (UserDTO user in item) + { + users.Add(user.ToEntity()); + } + return users; + } + public static LangEnum ToEntity(this TypeLangageDTO item) { switch (item) diff --git a/WF_EF_Api/StubbedContextLib/Migrations/20250328102709_migr5.Designer.cs b/WF_EF_Api/StubbedContextLib/Migrations/20250328102709_migr5.Designer.cs new file mode 100644 index 0000000..7e637c8 --- /dev/null +++ b/WF_EF_Api/StubbedContextLib/Migrations/20250328102709_migr5.Designer.cs @@ -0,0 +1,1107 @@ +// +using System; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Metadata; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; +using StubbedContextLib; + +#nullable disable + +namespace StubbedContextLib.Migrations +{ + [DbContext(typeof(StubWTFContext))] + [Migration("20250328102709_migr5")] + partial class migr5 + { + /// + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("ProductVersion", "9.0.3") + .HasAnnotation("Relational:MaxIdentifierLength", 128); + + SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder); + + modelBuilder.Entity("Entity.Admin", b => + { + b.Property("IdUsers") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("IdUsers")); + + b.Property("UserId") + .HasColumnType("int"); + + b.HasKey("IdUsers"); + + b.HasIndex("UserId"); + + b.ToTable("admins"); + }); + + modelBuilder.Entity("Entity.Character", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("IdImage") + .HasColumnType("int"); + + b.Property("Name") + .IsRequired() + .HasMaxLength(50) + .HasColumnType("nvarchar(50)"); + + b.HasKey("Id"); + + b.HasIndex("IdImage"); + + b.ToTable("characters"); + + b.HasData( + new + { + Id = 1, + IdImage = 1, + Name = "Alan Grant" + }, + new + { + Id = 2, + IdImage = 2, + Name = "Aragorn" + }, + new + { + Id = 3, + IdImage = 3, + Name = "Legolas" + }, + new + { + Id = 4, + IdImage = 4, + Name = "Frodon" + }, + new + { + Id = 5, + IdImage = 5, + Name = "Dobby" + }, + new + { + Id = 6, + IdImage = 6, + Name = "Jon Snow" + }, + new + { + Id = 7, + IdImage = 7, + Name = "Daenerys Targaryen" + }, + new + { + Id = 8, + IdImage = 8, + Name = "Luke Skywalker" + }, + new + { + Id = 9, + IdImage = 9, + Name = "Princess Leia" + }, + new + { + Id = 10, + IdImage = 10, + Name = "Harry Potter" + }); + }); + + modelBuilder.Entity("Entity.Commentary", b => + { + b.Property("IdUser") + .HasColumnType("int"); + + b.Property("IdQuote") + .HasColumnType("int"); + + b.Property("Comment") + .IsRequired() + .HasMaxLength(100) + .HasColumnType("nvarchar(100)"); + + b.Property("DateCommentary") + .HasColumnType("date") + .HasColumnName("DateCommentary"); + + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.HasKey("IdUser", "IdQuote"); + + b.HasIndex("IdQuote"); + + b.ToTable("comments"); + + b.HasData( + new + { + IdUser = 2, + IdQuote = 1, + Comment = "Ce film est le meilleur", + DateCommentary = new DateTime(2025, 2, 3, 0, 0, 0, 0, DateTimeKind.Unspecified), + Id = 1 + }, + new + { + IdUser = 3, + IdQuote = 1, + Comment = "Very good", + DateCommentary = new DateTime(2025, 3, 11, 0, 0, 0, 0, DateTimeKind.Unspecified), + Id = 2 + }); + }); + + modelBuilder.Entity("Entity.DailyQuote", b => + { + b.Property("IdQuote") + .HasColumnType("int"); + + b.HasKey("IdQuote"); + + b.ToTable("dailyquotes"); + + b.HasData( + new + { + IdQuote = 1 + }, + new + { + IdQuote = 5 + }); + }); + + modelBuilder.Entity("Entity.Favorite", b => + { + b.Property("IdQuote") + .HasColumnType("int"); + + b.Property("IdUsers") + .HasColumnType("int"); + + b.HasKey("IdQuote", "IdUsers"); + + b.HasIndex("IdUsers"); + + b.ToTable("favorites"); + + b.HasData( + new + { + IdQuote = 2, + IdUsers = 8 + }, + new + { + IdQuote = 5, + IdUsers = 3 + }, + new + { + IdQuote = 9, + IdUsers = 1 + }, + new + { + IdQuote = 4, + IdUsers = 10 + }, + new + { + IdQuote = 3, + IdUsers = 2 + }, + new + { + IdQuote = 6, + IdUsers = 7 + }, + new + { + IdQuote = 1, + IdUsers = 6 + }, + new + { + IdQuote = 8, + IdUsers = 9 + }, + new + { + IdQuote = 10, + IdUsers = 5 + }); + }); + + modelBuilder.Entity("Entity.Images", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("ImgPath") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.HasKey("Id"); + + b.ToTable("images"); + + b.HasData( + new + { + Id = 1, + ImgPath = "https://th.bing.com/th/id/OIP.TJuWNCsibz8MVmhdNQEdMwHaE8?w=244&h=180&c=7&r=0&o=5&pid=1.7" + }, + new + { + Id = 2, + ImgPath = "https://th.bing.com/th/id/OIP.NgXRQ5-IknA6_qOPFhLWIwHaHK?w=165&h=180&c=7&r=0&o=5&pid=1.7" + }, + new + { + Id = 3, + ImgPath = "https://th.bing.com/th/id/OIP.XcJoJ6bC9sAMjol1pJn5UQHaLH?w=118&h=180&c=7&r=0&o=5&pid=1.7" + }, + new + { + Id = 4, + ImgPath = "https://th.bing.com/th/id/OIP.PPIESqZaNDa-qUcfSDXhdQHaGK?w=210&h=180&c=7&r=0&o=5&pid=1.7" + }, + new + { + Id = 5, + ImgPath = "https://th.bing.com/th/id/OIP.XBghSl2kfRNNtQoSxc901wHaHa?w=177&h=180&c=7&r=0&o=5&pid=1.7" + }, + new + { + Id = 6, + ImgPath = "https://th.bing.com/th/id/OIP.af1Aid64cqEKoIOBgCPxtQHaJO?w=145&h=182&c=7&r=0&o=5&pid=1.7" + }, + new + { + Id = 7, + ImgPath = "https://th.bing.com/th/id/OIP.ri5vSXr5lNTLt4DO6KQXyQHaI4?w=158&h=189&c=7&r=0&o=5&pid=1.7" + }, + new + { + Id = 8, + ImgPath = "https://th.bing.com/th/id/OIP.uPTRLR8uspCiafiunUqKfQHaMJ?w=115&h=180&c=7&r=0&o=5&pid=1.7" + }, + new + { + Id = 9, + ImgPath = "https://th.bing.com/th/id/OIP.hcJis4rKbyQtugsoFJU2ngHaM_?w=118&h=207&c=7&r=0&o=5&pid=1.7" + }, + new + { + Id = 10, + ImgPath = "https://th.bing.com/th/id/OIP.Py1_XfUrKJY_A6tYEmFS5wHaE8?w=280&h=187&c=7&r=0&o=5&pid=1.7" + }); + }); + + modelBuilder.Entity("Entity.Question", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("AnswerA") + .IsRequired() + .HasMaxLength(50) + .HasColumnType("nvarchar(50)"); + + b.Property("AnswerB") + .IsRequired() + .HasMaxLength(50) + .HasColumnType("nvarchar(50)"); + + b.Property("AnswerC") + .IsRequired() + .HasMaxLength(50) + .HasColumnType("nvarchar(50)"); + + b.Property("AnswerD") + .IsRequired() + .HasMaxLength(50) + .HasColumnType("nvarchar(50)"); + + b.Property("CorrectAnswer") + .IsRequired() + .HasMaxLength(1) + .HasColumnType("nvarchar(1)"); + + b.Property("IsValid") + .HasColumnType("bit"); + + b.Property("Text") + .IsRequired() + .HasMaxLength(200) + .HasColumnType("nvarchar(200)"); + + b.HasKey("Id"); + + b.ToTable("question"); + + b.HasData( + new + { + Id = 1, + AnswerA = "Gimli", + AnswerB = "Aragorn", + AnswerC = "Frodon", + AnswerD = "Gandalf", + CorrectAnswer = "B", + IsValid = true, + Text = "Qui est le leader de la Communauté de l'Anneau ?" + }, + new + { + Id = 2, + AnswerA = "Serdaigle", + AnswerB = "Gryffondor", + AnswerC = "Serpentard", + AnswerD = "Poufsouffle", + CorrectAnswer = "B", + IsValid = false, + Text = "Dans quelle maison Harry Potter est-il ?" + }, + new + { + Id = 3, + AnswerA = "Saroumane", + AnswerB = "Sauron", + AnswerC = "Gollum", + AnswerD = "Gothmog", + CorrectAnswer = "B", + IsValid = true, + Text = "Qui est le Seigneur des Ténèbres dans la saga Le Seigneur des Anneaux ?" + }, + new + { + Id = 4, + AnswerA = "Han Solo", + AnswerB = "Princesse Leia", + AnswerC = "Chewbacca", + AnswerD = "R2-D2", + CorrectAnswer = "A", + IsValid = true, + Text = "Dans le film Star Wars : Episode IV, qui sauve Luke Skywalker de l'Étoile de la Mort ?" + }, + new + { + Id = 5, + AnswerA = "Reine Jadis", + AnswerB = "Aslan", + AnswerC = "Edmund", + AnswerD = "Lucy", + CorrectAnswer = "B", + IsValid = true, + Text = "Qui est le souverain de Narnia dans Le Lion, la Sorcière Blanche et l'Armoire Magique ?" + }, + new + { + Id = 6, + AnswerA = "Smaug", + AnswerB = "Falkor", + AnswerC = "Norbert", + AnswerD = "Shenron", + CorrectAnswer = "A", + IsValid = true, + Text = "Quel est le nom du dragon dans Le Hobbit ?" + }, + new + { + Id = 7, + AnswerA = "Bella Swan", + AnswerB = "Edward Cullen", + AnswerC = "Jacob Black", + AnswerD = "Victoria", + CorrectAnswer = "A", + IsValid = true, + Text = "Qui est la première personne à être mordue par un vampire dans Twilight ?" + }, + new + { + Id = 8, + AnswerA = "Obi-Wan Kenobi", + AnswerB = "Yoda", + AnswerC = "Han Solo", + AnswerD = "Luke Skywalker", + CorrectAnswer = "A", + IsValid = true, + Text = "Quel personnage dit Que la Force soit avec toi dans Star Wars ?" + }, + new + { + Id = 9, + AnswerA = "Dr. Ellie Sattler", + AnswerB = "Alan Grant", + AnswerC = "John Hammond", + AnswerD = "Dennis Nedry", + CorrectAnswer = "B", + IsValid = true, + Text = "Dans Jurassic Park, quel est le nom du paléontologue sur l'île ?" + }, + new + { + Id = 10, + AnswerA = "Cersei Lannister", + AnswerB = "Arya Stark", + AnswerC = "Daenerys Targaryen", + AnswerD = "Sansa Stark", + CorrectAnswer = "C", + IsValid = true, + Text = "Dans Game of Thrones, qui est surnommée la Mère des Dragons ?" + }); + }); + + modelBuilder.Entity("Entity.Quiz", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("IdImage") + .HasColumnType("int"); + + b.Property("NbQuestion") + .HasColumnType("int"); + + b.Property("Title") + .IsRequired() + .HasMaxLength(50) + .HasColumnType("nvarchar(50)"); + + b.HasKey("Id"); + + b.HasIndex("IdImage"); + + b.ToTable("quizzes"); + + b.HasData( + new + { + Id = 1, + IdImage = 1, + NbQuestion = 5, + Title = "Quiz 1" + }, + new + { + Id = 2, + IdImage = 2, + NbQuestion = 5, + Title = "Quiz 2" + }); + }); + + modelBuilder.Entity("Entity.QuizQuestion", b => + { + b.Property("IdQuestion") + .HasColumnType("int"); + + b.Property("IdQuiz") + .HasColumnType("int"); + + b.HasKey("IdQuestion", "IdQuiz"); + + b.HasIndex("IdQuiz"); + + b.ToTable("QuizQuestion"); + + b.HasData( + new + { + IdQuestion = 1, + IdQuiz = 1 + }, + new + { + IdQuestion = 2, + IdQuiz = 1 + }, + new + { + IdQuestion = 3, + IdQuiz = 1 + }, + new + { + IdQuestion = 4, + IdQuiz = 1 + }, + new + { + IdQuestion = 5, + IdQuiz = 1 + }, + new + { + IdQuestion = 6, + IdQuiz = 2 + }, + new + { + IdQuestion = 7, + IdQuiz = 2 + }, + new + { + IdQuestion = 8, + IdQuiz = 2 + }, + new + { + IdQuestion = 9, + IdQuiz = 2 + }, + new + { + IdQuestion = 10, + IdQuiz = 2 + }); + }); + + modelBuilder.Entity("Entity.Quote", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("Content") + .IsRequired() + .HasMaxLength(100) + .HasColumnType("nvarchar(100)"); + + b.Property("IdCharacter") + .HasColumnType("int"); + + b.Property("IdSource") + .HasColumnType("int"); + + b.Property("IdUsersPropose") + .HasColumnType("int"); + + b.Property("IsValid") + .HasColumnType("bit"); + + b.Property("Langage") + .HasColumnType("int"); + + b.Property("Likes") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.HasIndex("IdCharacter"); + + b.HasIndex("IdSource"); + + b.HasIndex("IdUsersPropose"); + + b.ToTable("quotes"); + + b.HasData( + new + { + Id = 1, + Content = "Je n'y crois pas. Je n'y crois pas. Ce n'est pas possible", + IdCharacter = 1, + IdSource = 1, + IdUsersPropose = 1, + IsValid = true, + Langage = 1, + Likes = 11025 + }, + new + { + Id = 2, + Content = "There is always hope", + IdCharacter = 2, + IdSource = 2, + IdUsersPropose = 1, + IsValid = true, + Langage = 0, + Likes = 11025 + }, + new + { + Id = 3, + Content = "A red sun rises. Blood has been spilled this night.", + IdCharacter = 3, + IdSource = 2, + IdUsersPropose = 1, + IsValid = true, + Langage = 0, + Likes = 11025 + }, + new + { + Id = 4, + Content = "I wish the Ring had never come to me.I wish none of this had happened.", + IdCharacter = 4, + IdSource = 2, + IdUsersPropose = 1, + IsValid = true, + Langage = 0, + Likes = 11025 + }, + new + { + Id = 5, + Content = "Dobby is a free elf!", + IdCharacter = 5, + IdSource = 4, + IdUsersPropose = 1, + IsValid = true, + Langage = 0, + Likes = 11025 + }, + new + { + Id = 6, + Content = "Winter is comming", + IdCharacter = 6, + IdSource = 3, + IdUsersPropose = 1, + IsValid = true, + Langage = 0, + Likes = 11025 + }, + new + { + Id = 7, + Content = "Je suis la dernière Targaryen. Je suis la reine des dragons", + IdCharacter = 7, + IdSource = 3, + IdUsersPropose = 1, + IsValid = true, + Langage = 1, + Likes = 11025 + }, + new + { + Id = 8, + Content = "Je ne suis pas prêt à affronter ça. C'est trop pour moi.", + IdCharacter = 8, + IdSource = 5, + IdUsersPropose = 1, + IsValid = true, + Langage = 1, + Likes = 11025 + }, + new + { + Id = 9, + Content = "Aidez-moi, Obi-Wan Kenobi, vous êtes mon seul espoir.", + IdCharacter = 9, + IdSource = 5, + IdUsersPropose = 1, + IsValid = true, + Langage = 1, + Likes = 11025 + }, + new + { + Id = 10, + Content = "La quoi ?", + IdCharacter = 10, + IdSource = 4, + IdUsersPropose = 1, + IsValid = true, + Langage = 1, + Likes = 11025 + }); + }); + + modelBuilder.Entity("Entity.Source", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("Title") + .IsRequired() + .HasMaxLength(100) + .HasColumnType("nvarchar(100)"); + + b.Property("TypeSrc") + .HasColumnType("int"); + + b.Property("Year") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.ToTable("sources"); + + b.HasData( + new + { + Id = 1, + Title = "Jurassic Park", + TypeSrc = 0, + Year = 1993 + }, + new + { + Id = 2, + Title = "Le Seigneur des anneaux : La Communauté de l'anneau", + TypeSrc = 0, + Year = 2001 + }, + new + { + Id = 3, + Title = "Game of throne", + TypeSrc = 1, + Year = 2011 + }, + new + { + Id = 4, + Title = "Harry Potter à l'école des sorcier", + TypeSrc = 0, + Year = 1997 + }, + new + { + Id = 5, + Title = "Star Wars, épisode IV : Un nouvel espoir", + TypeSrc = 0, + Year = 1977 + }); + }); + + modelBuilder.Entity("Entity.Users", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("Created") + .HasColumnType("date") + .HasColumnName("Created"); + + b.Property("Email") + .IsRequired() + .HasMaxLength(50) + .HasColumnType("nvarchar(50)"); + + b.Property("IdImage") + .HasColumnType("int"); + + b.Property("Password") + .IsRequired() + .HasMaxLength(200) + .HasColumnType("nvarchar(200)"); + + b.Property("UserName") + .IsRequired() + .HasMaxLength(50) + .HasColumnType("nvarchar(50)"); + + b.HasKey("Id"); + + b.HasIndex("IdImage"); + + b.ToTable("users"); + + b.HasData( + new + { + Id = 1, + Created = new DateTime(2025, 5, 12, 0, 0, 0, 0, DateTimeKind.Unspecified), + Email = "jhonDhoe@gmail.com", + IdImage = 1, + Password = "1234", + UserName = "Jhon-Dhoe" + }, + new + { + Id = 2, + Created = new DateTime(2025, 3, 19, 0, 0, 0, 0, DateTimeKind.Unspecified), + Email = "lucy_rose@outlook.com", + IdImage = 2, + Password = "abcd", + UserName = "Lucy-Rose" + }, + new + { + Id = 3, + Created = new DateTime(2024, 11, 2, 0, 0, 0, 0, DateTimeKind.Unspecified), + Email = "mark.taylor@yahoo.com", + IdImage = 3, + Password = "5678", + UserName = "Mark-Taylor" + }, + new + { + Id = 4, + Created = new DateTime(2025, 2, 28, 0, 0, 0, 0, DateTimeKind.Unspecified), + Email = "sophie.martin@gmail.com", + IdImage = 4, + Password = "4321", + UserName = "Sophie-Martin" + }, + new + { + Id = 5, + Created = new DateTime(2025, 1, 15, 0, 0, 0, 0, DateTimeKind.Unspecified), + Email = "nathan_doe@aol.com", + IdImage = 5, + Password = "8765", + UserName = "Nathan-Doe" + }, + new + { + Id = 6, + Created = new DateTime(2025, 4, 7, 0, 0, 0, 0, DateTimeKind.Unspecified), + Email = "ella.brown@icloud.com", + IdImage = 6, + Password = "2468", + UserName = "Ella-Brown" + }, + new + { + Id = 7, + Created = new DateTime(2024, 12, 25, 0, 0, 0, 0, DateTimeKind.Unspecified), + Email = "oliver_smith@gmail.com", + IdImage = 7, + Password = "1357", + UserName = "Oliver-Smith" + }, + new + { + Id = 8, + Created = new DateTime(2025, 3, 5, 0, 0, 0, 0, DateTimeKind.Unspecified), + Email = "mia.jones@outlook.com", + IdImage = 8, + Password = "1122", + UserName = "Mia-Jones" + }, + new + { + Id = 9, + Created = new DateTime(2025, 2, 22, 0, 0, 0, 0, DateTimeKind.Unspecified), + Email = "kevin_williams@aol.com", + IdImage = 9, + Password = "2233", + UserName = "Kevin-Williams" + }, + new + { + Id = 10, + Created = new DateTime(2025, 1, 3, 0, 0, 0, 0, DateTimeKind.Unspecified), + Email = "olivia.white@yahoo.com", + IdImage = 10, + Password = "3344", + UserName = "Olivia-White" + }); + }); + + modelBuilder.Entity("Entity.Admin", b => + { + b.HasOne("Entity.Users", "User") + .WithMany() + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("User"); + }); + + modelBuilder.Entity("Entity.Character", b => + { + b.HasOne("Entity.Images", "Images") + .WithMany("Characters") + .HasForeignKey("IdImage") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Images"); + }); + + modelBuilder.Entity("Entity.Commentary", b => + { + b.HasOne("Entity.Quote", "Quote") + .WithMany("Commentarys") + .HasForeignKey("IdQuote") + .OnDelete(DeleteBehavior.ClientCascade) + .IsRequired(); + + b.HasOne("Entity.Users", "User") + .WithMany() + .HasForeignKey("IdUser") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Quote"); + + b.Navigation("User"); + }); + + modelBuilder.Entity("Entity.DailyQuote", b => + { + b.HasOne("Entity.Quote", "Quote") + .WithMany("DailyQuotes") + .HasForeignKey("IdQuote") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Quote"); + }); + + modelBuilder.Entity("Entity.Favorite", b => + { + b.HasOne("Entity.Quote", "Quote") + .WithMany() + .HasForeignKey("IdQuote") + .OnDelete(DeleteBehavior.ClientCascade) + .IsRequired(); + + b.HasOne("Entity.Users", "Users") + .WithMany() + .HasForeignKey("IdUsers") + .OnDelete(DeleteBehavior.ClientCascade) + .IsRequired(); + + b.Navigation("Quote"); + + b.Navigation("Users"); + }); + + modelBuilder.Entity("Entity.Quiz", b => + { + b.HasOne("Entity.Images", "Images") + .WithMany("Quizs") + .HasForeignKey("IdImage") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Images"); + }); + + modelBuilder.Entity("Entity.QuizQuestion", b => + { + b.HasOne("Entity.Question", null) + .WithMany() + .HasForeignKey("IdQuestion") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("Entity.Quiz", null) + .WithMany() + .HasForeignKey("IdQuiz") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("Entity.Quote", b => + { + b.HasOne("Entity.Character", "Character") + .WithMany("Quotes") + .HasForeignKey("IdCharacter") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("Entity.Source", "Source") + .WithMany("Quotes") + .HasForeignKey("IdSource") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("Entity.Users", "User") + .WithMany("Quotes") + .HasForeignKey("IdUsersPropose"); + + b.Navigation("Character"); + + b.Navigation("Source"); + + b.Navigation("User"); + }); + + modelBuilder.Entity("Entity.Users", b => + { + b.HasOne("Entity.Images", "Images") + .WithMany("Users") + .HasForeignKey("IdImage") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Images"); + }); + + modelBuilder.Entity("Entity.Character", b => + { + b.Navigation("Quotes"); + }); + + modelBuilder.Entity("Entity.Images", b => + { + b.Navigation("Characters"); + + b.Navigation("Quizs"); + + b.Navigation("Users"); + }); + + modelBuilder.Entity("Entity.Quote", b => + { + b.Navigation("Commentarys"); + + b.Navigation("DailyQuotes"); + }); + + modelBuilder.Entity("Entity.Source", b => + { + b.Navigation("Quotes"); + }); + + modelBuilder.Entity("Entity.Users", b => + { + b.Navigation("Quotes"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/WF_EF_Api/StubbedContextLib/Migrations/20250328102709_migr5.cs b/WF_EF_Api/StubbedContextLib/Migrations/20250328102709_migr5.cs new file mode 100644 index 0000000..28c1b1d --- /dev/null +++ b/WF_EF_Api/StubbedContextLib/Migrations/20250328102709_migr5.cs @@ -0,0 +1,126 @@ +using Microsoft.EntityFrameworkCore.Migrations; + +#nullable disable + +namespace StubbedContextLib.Migrations +{ + /// + public partial class migr5 : Migration + { + /// + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.AddColumn( + name: "IsValid", + table: "question", + type: "bit", + nullable: false, + defaultValue: false); + + migrationBuilder.CreateTable( + name: "admins", + columns: table => new + { + IdUsers = table.Column(type: "int", nullable: false) + .Annotation("SqlServer:Identity", "1, 1"), + UserId = table.Column(type: "int", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_admins", x => x.IdUsers); + table.ForeignKey( + name: "FK_admins_users_UserId", + column: x => x.UserId, + principalTable: "users", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.UpdateData( + table: "question", + keyColumn: "Id", + keyValue: 1, + column: "IsValid", + value: true); + + migrationBuilder.UpdateData( + table: "question", + keyColumn: "Id", + keyValue: 2, + column: "IsValid", + value: false); + + migrationBuilder.UpdateData( + table: "question", + keyColumn: "Id", + keyValue: 3, + column: "IsValid", + value: true); + + migrationBuilder.UpdateData( + table: "question", + keyColumn: "Id", + keyValue: 4, + column: "IsValid", + value: true); + + migrationBuilder.UpdateData( + table: "question", + keyColumn: "Id", + keyValue: 5, + column: "IsValid", + value: true); + + migrationBuilder.UpdateData( + table: "question", + keyColumn: "Id", + keyValue: 6, + column: "IsValid", + value: true); + + migrationBuilder.UpdateData( + table: "question", + keyColumn: "Id", + keyValue: 7, + column: "IsValid", + value: true); + + migrationBuilder.UpdateData( + table: "question", + keyColumn: "Id", + keyValue: 8, + column: "IsValid", + value: true); + + migrationBuilder.UpdateData( + table: "question", + keyColumn: "Id", + keyValue: 9, + column: "IsValid", + value: true); + + migrationBuilder.UpdateData( + table: "question", + keyColumn: "Id", + keyValue: 10, + column: "IsValid", + value: true); + + migrationBuilder.CreateIndex( + name: "IX_admins_UserId", + table: "admins", + column: "UserId"); + } + + /// + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropTable( + name: "admins"); + + migrationBuilder.DropColumn( + name: "IsValid", + table: "question"); + } + } +} diff --git a/WF_EF_Api/StubbedContextLib/Migrations/StubWTFContextModelSnapshot.cs b/WF_EF_Api/StubbedContextLib/Migrations/StubWTFContextModelSnapshot.cs index 275cb8a..f07d603 100644 --- a/WF_EF_Api/StubbedContextLib/Migrations/StubWTFContextModelSnapshot.cs +++ b/WF_EF_Api/StubbedContextLib/Migrations/StubWTFContextModelSnapshot.cs @@ -22,6 +22,24 @@ namespace StubbedContextLib.Migrations SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder); + modelBuilder.Entity("Entity.Admin", b => + { + b.Property("IdUsers") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("IdUsers")); + + b.Property("UserId") + .HasColumnType("int"); + + b.HasKey("IdUsers"); + + b.HasIndex("UserId"); + + b.ToTable("admins"); + }); + modelBuilder.Entity("Entity.Character", b => { b.Property("Id") @@ -339,6 +357,9 @@ namespace StubbedContextLib.Migrations .HasMaxLength(1) .HasColumnType("nvarchar(1)"); + b.Property("IsValid") + .HasColumnType("bit"); + b.Property("Text") .IsRequired() .HasMaxLength(200) @@ -357,6 +378,7 @@ namespace StubbedContextLib.Migrations AnswerC = "Frodon", AnswerD = "Gandalf", CorrectAnswer = "B", + IsValid = true, Text = "Qui est le leader de la Communauté de l'Anneau ?" }, new @@ -367,6 +389,7 @@ namespace StubbedContextLib.Migrations AnswerC = "Serpentard", AnswerD = "Poufsouffle", CorrectAnswer = "B", + IsValid = false, Text = "Dans quelle maison Harry Potter est-il ?" }, new @@ -377,6 +400,7 @@ namespace StubbedContextLib.Migrations AnswerC = "Gollum", AnswerD = "Gothmog", CorrectAnswer = "B", + IsValid = true, Text = "Qui est le Seigneur des Ténèbres dans la saga Le Seigneur des Anneaux ?" }, new @@ -387,6 +411,7 @@ namespace StubbedContextLib.Migrations AnswerC = "Chewbacca", AnswerD = "R2-D2", CorrectAnswer = "A", + IsValid = true, Text = "Dans le film Star Wars : Episode IV, qui sauve Luke Skywalker de l'Étoile de la Mort ?" }, new @@ -397,6 +422,7 @@ namespace StubbedContextLib.Migrations AnswerC = "Edmund", AnswerD = "Lucy", CorrectAnswer = "B", + IsValid = true, Text = "Qui est le souverain de Narnia dans Le Lion, la Sorcière Blanche et l'Armoire Magique ?" }, new @@ -407,6 +433,7 @@ namespace StubbedContextLib.Migrations AnswerC = "Norbert", AnswerD = "Shenron", CorrectAnswer = "A", + IsValid = true, Text = "Quel est le nom du dragon dans Le Hobbit ?" }, new @@ -417,6 +444,7 @@ namespace StubbedContextLib.Migrations AnswerC = "Jacob Black", AnswerD = "Victoria", CorrectAnswer = "A", + IsValid = true, Text = "Qui est la première personne à être mordue par un vampire dans Twilight ?" }, new @@ -427,6 +455,7 @@ namespace StubbedContextLib.Migrations AnswerC = "Han Solo", AnswerD = "Luke Skywalker", CorrectAnswer = "A", + IsValid = true, Text = "Quel personnage dit Que la Force soit avec toi dans Star Wars ?" }, new @@ -437,6 +466,7 @@ namespace StubbedContextLib.Migrations AnswerC = "John Hammond", AnswerD = "Dennis Nedry", CorrectAnswer = "B", + IsValid = true, Text = "Dans Jurassic Park, quel est le nom du paléontologue sur l'île ?" }, new @@ -447,6 +477,7 @@ namespace StubbedContextLib.Migrations AnswerC = "Daenerys Targaryen", AnswerD = "Sansa Stark", CorrectAnswer = "C", + IsValid = true, Text = "Dans Game of Thrones, qui est surnommée la Mère des Dragons ?" }); }); @@ -904,6 +935,17 @@ namespace StubbedContextLib.Migrations }); }); + modelBuilder.Entity("Entity.Admin", b => + { + b.HasOne("Entity.Users", "User") + .WithMany() + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("User"); + }); + modelBuilder.Entity("Entity.Character", b => { b.HasOne("Entity.Images", "Images") From fee5b07fac6a696415c14e3dda3eaeca2ff2da50 Mon Sep 17 00:00:00 2001 From: Leni BEAULATON Date: Fri, 28 Mar 2025 11:51:28 +0100 Subject: [PATCH 39/65] Quote Services --- WF_EF_Api/ServicesApi/QuoteService.cs | 112 ++++++++++++++++++++++++++ WF_EF_Api/ServicesApi/UserService.cs | 3 +- 2 files changed, 113 insertions(+), 2 deletions(-) create mode 100644 WF_EF_Api/ServicesApi/QuoteService.cs diff --git a/WF_EF_Api/ServicesApi/QuoteService.cs b/WF_EF_Api/ServicesApi/QuoteService.cs new file mode 100644 index 0000000..eee85b7 --- /dev/null +++ b/WF_EF_Api/ServicesApi/QuoteService.cs @@ -0,0 +1,112 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using DTO; +using Dto2Entities; +using Entity; +using Shared; + +namespace ServicesApi +{ + public class QuoteService : IQuoteService + { + private IQuoteService quoteService; + + public QuoteService(IQuoteService quote) + { + quoteService = quote; + } + + public async Task AddQuote(QuoteDTO quote) + { + await quoteService.AddQuote(quote.ToEntity()); + } + + public async Task> GetAllQuote() + { + throw new NotImplementedException(); + } + + public async Task> GetAllQuoteLang(int index, int pageSize, int lang) + { + throw new NotImplementedException(); + } + + public async Task GetDailyQuote(DateOnly date, int lang) + { + return quoteService.GetDailyQuote(date, lang).Result.ToDto(); + } + + public async Task> GetFavorites(int index, int pageSize, int UserId) + { + throw new NotImplementedException(); + } + + public async Task> GetInvalidQuote(int index, int pageSize, int lang) + { + throw new NotImplementedException(); + } + + public async Task> GetInvalidQuote(int index, int pageSize) + { + throw new NotImplementedException(); + } + + public async Task GetLastQuoteId() + { + return await quoteService.GetLastQuoteId(); + } + + public async Task GetQuoteById(int id) + { + return quoteService.GetQuoteById(id).Result.ToDto(); + } + + public async Task> GetSomeQuote(int index, int pageSize) + { + throw new NotImplementedException(); + } + + public async Task> GetSuggestions(int index, int pageSize, int lang) + { + throw new NotImplementedException(); + } + + public async Task> GetValidQuote(int index, int pageSize) + { + throw new NotImplementedException(); + } + + public async Task RemoveQuote(int quoteId) + { + await quoteService.RemoveQuote(quoteId); + } + + public async Task> SearchByCharacter(string character, int index, int pageSize, int lang) + { + throw new NotImplementedException(); + } + + public async Task> SearchByContent(string content, int index, int pageSize, int lang) + { + throw new NotImplementedException(); + } + + public async Task> SearchBySource(string source, int index, int pageSize, int lang) + { + throw new NotImplementedException(); + } + + public async Task UpdateQuote(int quoteId, QuoteDTO quote) + { + await quoteService.UpdateQuote(quoteId, quote.ToEntity()); + } + + public async Task ValidateQuote(int quoteId, bool isValidate) + { + await quoteService.ValidateQuote(quoteId, isValidate); + } + } +} diff --git a/WF_EF_Api/ServicesApi/UserService.cs b/WF_EF_Api/ServicesApi/UserService.cs index 367cd2b..064fd63 100644 --- a/WF_EF_Api/ServicesApi/UserService.cs +++ b/WF_EF_Api/ServicesApi/UserService.cs @@ -87,8 +87,7 @@ namespace ServicesApi public async Task UpdateUser(int userId, UserDTO user) { - await userService.UpdateUser(userId, user.ToEntity()); - throw new NotImplementedException(); + return userService.UpdateUser(userId, user.ToEntity()).Result.ToDto(); } } } From f7f0be36e59ca07dcdb422dbca4c3cc40cc4ca3d Mon Sep 17 00:00:00 2001 From: Leni BEAULATON Date: Fri, 28 Mar 2025 12:00:32 +0100 Subject: [PATCH 40/65] =?UTF-8?q?Pr=C3=A9paration=20dans=20program=20des?= =?UTF-8?q?=20services?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- WF_EF_Api/Contextlib/DbCommentaryManager.cs | 4 ++-- WF_EF_Api/WfApi/Program.cs | 7 ++++++- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/WF_EF_Api/Contextlib/DbCommentaryManager.cs b/WF_EF_Api/Contextlib/DbCommentaryManager.cs index c498637..c866245 100644 --- a/WF_EF_Api/Contextlib/DbCommentaryManager.cs +++ b/WF_EF_Api/Contextlib/DbCommentaryManager.cs @@ -10,12 +10,12 @@ using System.Threading.Tasks; namespace Contextlib { - public class DbCommentManager : ICommentService + public class DbCommentaryManager : ICommentService { private WTFContext _context; private GenericRepository _repo; - public DbCommentManager(WTFContext context) + public DbCommentaryManager(WTFContext context) { _context = context ?? throw new ArgumentNullException(nameof(context), "Database context cannot be null."); _repo = new GenericRepository(context); diff --git a/WF_EF_Api/WfApi/Program.cs b/WF_EF_Api/WfApi/Program.cs index 524f35a..01c0c1e 100644 --- a/WF_EF_Api/WfApi/Program.cs +++ b/WF_EF_Api/WfApi/Program.cs @@ -8,12 +8,17 @@ using ServicesApi; var builder = WebApplication.CreateBuilder(args); //API builder.Services.AddScoped, UserService>(); -builder.Services.AddScoped, QuoteServiceStub>(); +builder.Services.AddScoped, QuoteServiceStub>(); // Retirer "Stub" //EF builder.Services.AddScoped(); builder.Services.AddScoped, DbUsersManager>(); +// builder.Services.AddScoped, DbQuoteManager>(); Quand DbQuoteManager sera prsent +//builder.Services.AddScoped, DbCharacterManager>(); +//builder.Services.AddScoped, DbCommentaryManager>(); +//... + // Add services to the container. builder.Services.AddControllers(); From 69716c4f9be17981d3e5f5a5d9dd4e05724b4924 Mon Sep 17 00:00:00 2001 From: kekentin Date: Mon, 31 Mar 2025 16:17:47 +0200 Subject: [PATCH 41/65] finition route pour Quote --- .../WfApi/Controllers/QuotesController.cs | 154 ++++++++++++++++++ 1 file changed, 154 insertions(+) diff --git a/WF_EF_Api/WfApi/Controllers/QuotesController.cs b/WF_EF_Api/WfApi/Controllers/QuotesController.cs index 173d30f..e2dd44d 100644 --- a/WF_EF_Api/WfApi/Controllers/QuotesController.cs +++ b/WF_EF_Api/WfApi/Controllers/QuotesController.cs @@ -1,4 +1,5 @@ using DTO; +using Entity; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc; using Shared; @@ -132,6 +133,159 @@ namespace WfApi.Controllers return StatusCode((int)HttpStatusCode.InternalServerError, new { message = "Internal Server Error" }); } } + [HttpGet("suggest")] + public async Task GetSuggestQuote(TypeLangageDTO lang, int index = 0, int count = 10) + { + try + { + var result = _quote.GetSuggestions(index, count, (int)lang); + + if (result.IsCompletedSuccessfully) + { + return await Task.FromResult(Ok(result)); + } + else + { + return NoContent(); + } + } + catch (Exception) + { + return StatusCode((int)HttpStatusCode.InternalServerError, new { message = "Internal Server Error" }); + } + } + [HttpGet("searchByCharacter")] + public async Task GetQuoteSearchByCharacter(TypeLangageDTO lang, string character, int index = 0, int count = 10) + { + try + { + var result = _quote.SearchByCharacter(character, index, count, (int)lang); + + if (result.IsCompletedSuccessfully) + { + return await Task.FromResult(Ok(result)); + } + else + { + return NoContent(); + } + } + catch (Exception) + { + return StatusCode((int)HttpStatusCode.InternalServerError, new { message = "Internal Server Error" }); + } + } + [HttpGet("searchByCharac")] + public async Task GetQuoteSearchBySource(TypeLangageDTO lang, string source, int index = 0, int count = 10) + { + try + { + var result = _quote.SearchBySource(source, index, count, (int)lang); + + if (result.IsCompletedSuccessfully) + { + return await Task.FromResult(Ok(result)); + } + else + { + return NoContent(); + } + } + catch (Exception) + { + return StatusCode((int)HttpStatusCode.InternalServerError, new { message = "Internal Server Error" }); + } + } + [HttpGet("searchByContent")] + public async Task GetQuoteSearchByContent(TypeLangageDTO lang, string content, int index = 0, int count = 10) + { + try + { + var result = _quote.SearchByContent(content, index, count, (int)lang); + + if (result.IsCompletedSuccessfully) + { + return await Task.FromResult(Ok(result)); + } + else + { + return NoContent(); + } + } + catch (Exception) + { + return StatusCode((int)HttpStatusCode.InternalServerError, new { message = "Internal Server Error" }); + } + } + + //===================================== ROUTE POST ===================================== + + [HttpPost] + public async Task CreateQuote([FromBody] QuoteDTO newQuote) + { + try + { + if (newQuote == null) + { + return BadRequest(new { message = "Les données de la quote sont requises." }); + } + + var existingPlayer = _quote.GetQuoteById(newQuote.Id).Result; + if (existingPlayer != null) + { + return Conflict(new { message = "Une quote avec cet ID existe déjà." }); + } + + _quote.AddQuote(newQuote); + + return CreatedAtAction(nameof(GetAllQuote), new { id = newQuote.Id }, newQuote); + } + catch (Exception) + { + return StatusCode((int)HttpStatusCode.InternalServerError, new { message = "Erreur interne du serveur." }); + } + } + //===================================== ROUTE PUT ===================================== + [HttpPut()] + public async Task UpdateQuote([FromQuery] int id, [FromBody] QuoteDTO updatedquote) + { + try + { + if (updatedquote == null) + { + return BadRequest(new { message = "Quote data is required." }); + } + + var result = _quote.UpdateQuote(id, updatedquote); + + return Ok(result); + } + catch (Exception) + { + return StatusCode((int)HttpStatusCode.InternalServerError, new { message = "Internal server error." }); + } + } + [HttpPut("valide")] + public async Task ValideQuote([FromQuery] int id) + { + try + { + var updatedquote = _quote.GetQuoteById(id).Result; + if (updatedquote == null) + { + return BadRequest(new { message = "Id Quote is underfined." }); + } + updatedquote.IsValide = true; + var result = _quote.UpdateQuote(id, updatedquote); + + return Ok(result); + } + catch (Exception) + { + return StatusCode((int)HttpStatusCode.InternalServerError, new { message = "Internal server error." }); + } + } + //===================================== ROUTE DELETE ===================================== [HttpDelete("delete")] From 4b1edf0e1697f01f1aa3726c1802e4c4178f6029 Mon Sep 17 00:00:00 2001 From: Leni BEAULATON Date: Mon, 31 Mar 2025 16:18:43 +0200 Subject: [PATCH 42/65] Service des citations --- WF_EF_Api/Contextlib/DbQuoteManager.cs | 126 +++++++++++++++++++++++++ WF_EF_Api/Contextlib/DbUsersManager.cs | 2 + WF_EF_Api/ServicesApi/QuoteService.cs | 18 ++-- WF_EF_Api/WfApi/Program.cs | 8 +- 4 files changed, 144 insertions(+), 10 deletions(-) create mode 100644 WF_EF_Api/Contextlib/DbQuoteManager.cs diff --git a/WF_EF_Api/Contextlib/DbQuoteManager.cs b/WF_EF_Api/Contextlib/DbQuoteManager.cs new file mode 100644 index 0000000..a5fc2d1 --- /dev/null +++ b/WF_EF_Api/Contextlib/DbQuoteManager.cs @@ -0,0 +1,126 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Entity; +using Shared; + +namespace Contextlib +{ + public class DbQuoteManager : IQuoteService + { + private WTFContext _context; + private GenericRepository _repo; + + public DbQuoteManager(WTFContext context) + { + _context = context ?? throw new ArgumentNullException(nameof(context), "Database context cannot be null."); + _repo = new GenericRepository(_context); + } + + + + + + public async Task AddQuote(Quote quote) + { + if (quote == null) + { + throw new ArgumentNullException(nameof(quote), "quote cannot be null."); + } + _repo.Insert(quote); + await _context.SaveChangesAsync(); + } + + public async Task> GetAllQuote() + { + List quotes = _repo.GetItems(0, _repo.Count(), [nameof(Quote.Id)]).ToList(); + return new PaginationResult(quotes.Count, 0, quotes.Count, quotes); + } + + public async Task> GetAllQuoteLang(int index, int pageSize, int lang) + { + throw new NotImplementedException(); + } + + public async Task GetDailyQuote(DateOnly date, int lang) + { + throw new NotImplementedException(); + } + + public async Task> GetFavorites(int index, int pageSize, int UserId) + { + throw new NotImplementedException(); + } + + public async Task> GetInvalidQuote(int index, int pageSize, int lang) + { + throw new NotImplementedException(); + } + + public async Task> GetInvalidQuote(int index, int pageSize) + { + throw new NotImplementedException(); + } + + public async Task GetLastQuoteId() + { + throw new NotImplementedException(); + } + + public async Task GetQuoteById(int id) + { + throw new NotImplementedException(); + } + + public async Task> GetSomeQuote(int index, int pageSize) + { + throw new NotImplementedException(); + } + + public async Task> GetSuggestions(int index, int pageSize, int lang) + { + throw new NotImplementedException(); + } + + public async Task> GetValidQuote(int index, int pageSize) + { + throw new NotImplementedException(); + } + + + + + + public async Task RemoveQuote(int quoteId) + { + throw new NotImplementedException(); + } + + public async Task> SearchByCharacter(string character, int index, int pageSize, int lang) + { + throw new NotImplementedException(); + } + + public async Task> SearchByContent(string content, int index, int pageSize, int lang) + { + throw new NotImplementedException(); + } + + public async Task> SearchBySource(string source, int index, int pageSize, int lang) + { + throw new NotImplementedException(); + } + + public async Task UpdateQuote(int quoteId, Quote quote) + { + throw new NotImplementedException(); + } + + public async Task ValidateQuote(int quoteId, bool isValidate) + { + throw new NotImplementedException(); + } + } +} diff --git a/WF_EF_Api/Contextlib/DbUsersManager.cs b/WF_EF_Api/Contextlib/DbUsersManager.cs index e4d2940..6389403 100644 --- a/WF_EF_Api/Contextlib/DbUsersManager.cs +++ b/WF_EF_Api/Contextlib/DbUsersManager.cs @@ -19,6 +19,8 @@ namespace Contextlib _repo = new GenericRepository(_context); } + + public async Task AddUser(Users user) { if (user == null) { diff --git a/WF_EF_Api/ServicesApi/QuoteService.cs b/WF_EF_Api/ServicesApi/QuoteService.cs index eee85b7..2a76c86 100644 --- a/WF_EF_Api/ServicesApi/QuoteService.cs +++ b/WF_EF_Api/ServicesApi/QuoteService.cs @@ -26,7 +26,8 @@ namespace ServicesApi public async Task> GetAllQuote() { - throw new NotImplementedException(); + var quotes = quoteService.GetAllQuote().Result.items; + return new PaginationResult(quotes.Count(), 0, 10, quotes.ToDto()); } public async Task> GetAllQuoteLang(int index, int pageSize, int lang) @@ -41,17 +42,20 @@ namespace ServicesApi public async Task> GetFavorites(int index, int pageSize, int UserId) { - throw new NotImplementedException(); + var quotes = quoteService.GetFavorites(index, pageSize, UserId).Result.items; + return new PaginationResult(quotes.Count(), 0, 10, quotes.ToDto()); } public async Task> GetInvalidQuote(int index, int pageSize, int lang) { - throw new NotImplementedException(); + var quotes = quoteService.GetInvalidQuote(index, pageSize, lang).Result.items; + return new PaginationResult(quotes.Count(), 0, 10, quotes.ToDto()); } public async Task> GetInvalidQuote(int index, int pageSize) { - throw new NotImplementedException(); + var quotes = quoteService.GetInvalidQuote(index, pageSize).Result.items; + return new PaginationResult(quotes.Count(), 0, 10, quotes.ToDto()); } public async Task GetLastQuoteId() @@ -66,12 +70,14 @@ namespace ServicesApi public async Task> GetSomeQuote(int index, int pageSize) { - throw new NotImplementedException(); + var quotes = quoteService.GetSomeQuote(index, pageSize).Result.items; + return new PaginationResult(quotes.Count(), 0, 10, quotes.ToDto()); } public async Task> GetSuggestions(int index, int pageSize, int lang) { - throw new NotImplementedException(); + var quotes = quoteService.GetSuggestions(index, pageSize, lang).Result.items; + return new PaginationResult(quotes.Count(), 0, 10, quotes.ToDto()); } public async Task> GetValidQuote(int index, int pageSize) diff --git a/WF_EF_Api/WfApi/Program.cs b/WF_EF_Api/WfApi/Program.cs index 01c0c1e..54d221a 100644 --- a/WF_EF_Api/WfApi/Program.cs +++ b/WF_EF_Api/WfApi/Program.cs @@ -8,15 +8,15 @@ using ServicesApi; var builder = WebApplication.CreateBuilder(args); //API builder.Services.AddScoped, UserService>(); -builder.Services.AddScoped, QuoteServiceStub>(); // Retirer "Stub" +builder.Services.AddScoped, QuoteService>(); //EF builder.Services.AddScoped(); builder.Services.AddScoped, DbUsersManager>(); -// builder.Services.AddScoped, DbQuoteManager>(); Quand DbQuoteManager sera prsent -//builder.Services.AddScoped, DbCharacterManager>(); -//builder.Services.AddScoped, DbCommentaryManager>(); +builder.Services.AddScoped, DbQuoteManager>(); +//builder.Services.AddScoped, DbCharacterManager>(); +//builder.Services.AddScoped, DbCommentaryManager>(); //... // Add services to the container. From ad8d0023b6a74b022138399c1b5c033f00e25af1 Mon Sep 17 00:00:00 2001 From: Leni BEAULATON Date: Mon, 31 Mar 2025 17:14:07 +0200 Subject: [PATCH 43/65] Test des commentaires dans api --- WF_EF_Api/Contextlib/DbCommentaryManager.cs | 20 ++-- WF_EF_Api/ServicesApi/CommentaryService.cs | 75 +++++++++++++ WF_EF_Api/ServicesApi/QuoteService.cs | 16 ++- WF_EF_Api/Shared/IComentaryService.cs | 22 ++-- .../Controllers/CommentariesController.cs | 102 ++++++++++++++++++ .../WfApi/Controllers/UsersController.cs | 6 +- WF_EF_Api/WfApi/Program.cs | 3 +- 7 files changed, 214 insertions(+), 30 deletions(-) create mode 100644 WF_EF_Api/ServicesApi/CommentaryService.cs create mode 100644 WF_EF_Api/WfApi/Controllers/CommentariesController.cs diff --git a/WF_EF_Api/Contextlib/DbCommentaryManager.cs b/WF_EF_Api/Contextlib/DbCommentaryManager.cs index c866245..b18ae99 100644 --- a/WF_EF_Api/Contextlib/DbCommentaryManager.cs +++ b/WF_EF_Api/Contextlib/DbCommentaryManager.cs @@ -10,7 +10,7 @@ using System.Threading.Tasks; namespace Contextlib { - public class DbCommentaryManager : ICommentService + public class DbCommentaryManager : ICommentaryService { private WTFContext _context; private GenericRepository _repo; @@ -44,7 +44,7 @@ namespace Contextlib /// The ID of the quote whose comments need to be deleted. /// A task representing the asynchronous operation. /// Thrown when no comments are found for the provided quote ID. - public async Task DeleteCommentForQuote(int quoteId) + public async Task DeleteCommentaryForQuote(int quoteId) { var comments = await _context.comments.Where(x => x.IdQuote == quoteId).ToListAsync(); if (!comments.Any()) @@ -62,7 +62,7 @@ namespace Contextlib /// The ID of the user whose comments need to be deleted. /// A task representing the asynchronous operation. /// Thrown when no comments are found for the provided user ID. - public async Task DeleteCommentForUser(int userId) + public async Task DeleteCommentaryForUser(int userId) { var comments = await _context.comments.Include(c => c.User).Where(x => x.IdUser == userId).ToListAsync(); if (!comments.Any()) @@ -74,13 +74,13 @@ namespace Contextlib await _context.SaveChangesAsync(); } - public async Task> GetAllComment() + public async Task> GetAllCommentary() { var comments = await _context.comments.Include(c => c.User).ToListAsync(); return new PaginationResult(comments.Count, 0, comments.Count, comments); } - public async Task GetCommentById(int id) + public async Task GetCommentaryById(int id) { var comment = await _context.comments.Include(c => c.User).Where(x => x.Id == id).FirstOrDefaultAsync(); if(comment == null) @@ -90,7 +90,7 @@ namespace Contextlib return comment; } - public async Task> GetCommentByQuote(int quoteId, int index, int pageSize) + public async Task> GetCommentaryByQuote(int quoteId, int index, int pageSize) { var comments = await _context.comments.Include(c => c.User).Where(x => x.IdQuote == quoteId).ToListAsync(); if (!comments.Any()) @@ -112,7 +112,7 @@ namespace Contextlib return new PaginationResult(comments.Count, index, pageSize, comments.Skip(index * pageSize).Take(pageSize).ToList()); } - public async Task> GetCommentByUser(int userId, int index, int pageSize) + public async Task> GetCommentaryByUser(int userId, int index, int pageSize) { var comments = await _context.comments.Include(c => c.User).Where(x => x.IdUser == userId).ToListAsync(); if (!comments.Any()) @@ -134,7 +134,7 @@ namespace Contextlib return new PaginationResult(comments.Count, index, pageSize, comments.Skip(index * pageSize).Take(pageSize).ToList()); } - public async Task LastCommentId() + public async Task LastCommentaryId() { var last = await _context.comments.OrderByDescending(x => x.Id).FirstOrDefaultAsync(); if(last == null) @@ -144,13 +144,13 @@ namespace Contextlib return last.Id; } - public async Task RemoveComment(int id) + public async Task RemoveCommentary(int id) { _repo.Delete(id); await _context.SaveChangesAsync(); } - public async Task UpdateComment(int id, Commentary comment) + public async Task UpdateCommentary(int id, Commentary comment) { var modif = false; var com = await _context.comments.Where(x => x.Id == id).FirstOrDefaultAsync(); diff --git a/WF_EF_Api/ServicesApi/CommentaryService.cs b/WF_EF_Api/ServicesApi/CommentaryService.cs new file mode 100644 index 0000000..211f6a4 --- /dev/null +++ b/WF_EF_Api/ServicesApi/CommentaryService.cs @@ -0,0 +1,75 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using DTO; +using Entity; +using Shared; +using Dto2Entities; + +namespace ServicesApi +{ + public class CommentaryService : ICommentaryService + { + private ICommentaryService commentaryService; + + public CommentaryService(ICommentaryService commentary) + { + commentaryService = commentary; + } + + public async Task AddComment(CommentaryDTO commentary) + { + await commentaryService.AddComment(commentary.ToEntity()); + } + + public async Task DeleteCommentaryForQuote(int quoteId) + { + await commentaryService.DeleteCommentaryForQuote(quoteId); + } + + public async Task DeleteCommentaryForUser(int userId) + { + await commentaryService.DeleteCommentaryForUser(userId); + } + + public async Task> GetAllCommentary() + { + var commentaries = commentaryService.GetAllCommentary().Result.items; + return new PaginationResult(commentaries.Count(), 0, 10, commentaries.ToDto()); + } + + public async Task GetCommentaryById(int id) + { + return commentaryService.GetCommentaryById(id).Result.ToDto(); + } + + public async Task> GetCommentaryByQuote(int quoteId, int index, int pageSize) + { + var commentaries = commentaryService.GetCommentaryByQuote(quoteId,index,pageSize).Result.items; + return new PaginationResult(commentaries.Count(), 0, 10, commentaries.ToDto()); + } + + public async Task> GetCommentaryByUser(int userId, int index, int pageSize) + { + var commentaries = commentaryService.GetCommentaryByUser(userId, index,pageSize).Result.items; + return new PaginationResult(commentaries.Count(), 0, 10, commentaries.ToDto()); + } + + public async Task LastCommentaryId() + { + return await commentaryService.LastCommentaryId(); + } + + public async Task RemoveCommentary(int id) + { + await commentaryService.RemoveCommentary(id); + } + + public async Task UpdateCommentary(int id, CommentaryDTO commentary) + { + await commentaryService.UpdateCommentary(id,commentary.ToEntity()); + } + } +} diff --git a/WF_EF_Api/ServicesApi/QuoteService.cs b/WF_EF_Api/ServicesApi/QuoteService.cs index 2a76c86..fc1be81 100644 --- a/WF_EF_Api/ServicesApi/QuoteService.cs +++ b/WF_EF_Api/ServicesApi/QuoteService.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using System.Linq; +using System.Reflection.Metadata; using System.Text; using System.Threading.Tasks; using DTO; @@ -32,7 +33,8 @@ namespace ServicesApi public async Task> GetAllQuoteLang(int index, int pageSize, int lang) { - throw new NotImplementedException(); + var quotes = quoteService.GetAllQuoteLang(index, pageSize,lang).Result.items; + return new PaginationResult(quotes.Count(), 0, 10, quotes.ToDto()); } public async Task GetDailyQuote(DateOnly date, int lang) @@ -82,7 +84,8 @@ namespace ServicesApi public async Task> GetValidQuote(int index, int pageSize) { - throw new NotImplementedException(); + var quotes = quoteService.GetValidQuote(index, pageSize).Result.items; + return new PaginationResult(quotes.Count(), 0, 10, quotes.ToDto()); } public async Task RemoveQuote(int quoteId) @@ -92,17 +95,20 @@ namespace ServicesApi public async Task> SearchByCharacter(string character, int index, int pageSize, int lang) { - throw new NotImplementedException(); + var quotes = quoteService.SearchByCharacter(character, index, pageSize, lang).Result.items; + return new PaginationResult(quotes.Count(), 0, 10, quotes.ToDto()); } public async Task> SearchByContent(string content, int index, int pageSize, int lang) { - throw new NotImplementedException(); + var quotes = quoteService.SearchByContent(content, index, pageSize, lang).Result.items; + return new PaginationResult(quotes.Count(), 0, 10, quotes.ToDto()); } public async Task> SearchBySource(string source, int index, int pageSize, int lang) { - throw new NotImplementedException(); + var quotes = quoteService.SearchBySource(source, index, pageSize, lang).Result.items; + return new PaginationResult(quotes.Count(), 0, 10, quotes.ToDto()); } public async Task UpdateQuote(int quoteId, QuoteDTO quote) diff --git a/WF_EF_Api/Shared/IComentaryService.cs b/WF_EF_Api/Shared/IComentaryService.cs index d5c4fc6..b546360 100644 --- a/WF_EF_Api/Shared/IComentaryService.cs +++ b/WF_EF_Api/Shared/IComentaryService.cs @@ -6,49 +6,49 @@ using System.Threading.Tasks; namespace Shared { - public interface ICommentService + public interface ICommentaryService { // Retrieves a comment by its unique identifier (id). // 'id' is the unique identifier of the comment. - Task GetCommentById(int id); + Task GetCommentaryById(int id); // Retrieves comments related to a specific quote, with pagination. // 'quoteId' is the unique identifier of the quote. // 'index' is the page number (for pagination). // 'pageSize' is the number of comments per page. - Task> GetCommentByQuote(int quoteId, int index, int pageSize); + Task> GetCommentaryByQuote(int quoteId, int index, int pageSize); // Retrieves all comments, with pagination support. // This returns a list of all comments. - Task> GetAllComment(); + Task> GetAllCommentary(); // Retrieves comments made by a specific user, with pagination. // 'userId' is the unique identifier of the user. // 'index' is the page number (for pagination). // 'pageSize' is the number of comments per page. - Task> GetCommentByUser(int userId, int index, int pageSize); + Task> GetCommentaryByUser(int userId, int index, int pageSize); // Adds a new commenT. // 'comment' is the comment object that will be added. - Task AddComment(TComment comment); + Task AddComment(TComment commentary); // Updates an existing comment identified by 'id'. // 'id' is the unique identifier of the comment, and 'comment' contains the updated comment data. - Task UpdateComment(int id, TComment comment); + Task UpdateCommentary(int id, TComment comment); // Removes a comment based on its unique identifier ('id'). // 'id' is the unique identifier of the comment to be removed. - Task RemoveComment(int id); + Task RemoveCommentary(int id); // Deletes all comments related to a specific quote. // 'quoteId' is the unique identifier of the quote for which comments will be deleted. - Task DeleteCommentForQuote(int quoteId); + Task DeleteCommentaryForQuote(int quoteId); // Deletes all comments made by a specific user. // 'userId' is the unique identifier of the user whose comments will be deleted. - Task DeleteCommentForUser(int userId); + Task DeleteCommentaryForUser(int userId); // Retrieves the last comment ID. - Task LastCommentId(); + Task LastCommentaryId(); } } diff --git a/WF_EF_Api/WfApi/Controllers/CommentariesController.cs b/WF_EF_Api/WfApi/Controllers/CommentariesController.cs new file mode 100644 index 0000000..737acea --- /dev/null +++ b/WF_EF_Api/WfApi/Controllers/CommentariesController.cs @@ -0,0 +1,102 @@ +using System.Net; +using DTO; +using Entity; +using Microsoft.AspNetCore.Mvc; +using Shared; + +namespace WfApi.Controllers +{ + [ApiController] + [Route("api/v1/commentary")] //Version API + public class CommentariesController : ControllerBase + { + private readonly ICommentaryService _commentary; + + private readonly ILogger _logger; + public CommentariesController(ICommentaryService commentaryService, ILogger logger) + { + _commentary = commentaryService; + _logger = logger; + } + + + + [HttpGet("{id}")] // Indiquer que l'id est dans l'URL + public async Task GetCommentary(int id, int index = 0, int count = 5) + { + try + { + var result = _commentary.GetCommentaryByQuote(id, index, count); + + if (result.IsCompletedSuccessfully) + { + return await Task.FromResult(Ok(result)); + } + else + { + return NoContent(); + } + } + catch (Exception) + { + return StatusCode((int)HttpStatusCode.InternalServerError, new { message = "Internal Server Error" }); + } + } + + [HttpPost] + [ProducesResponseType(StatusCodes.Status201Created)] + [ProducesResponseType(StatusCodes.Status400BadRequest)] + [ProducesResponseType(StatusCodes.Status409Conflict)] + [ProducesResponseType(StatusCodes.Status500InternalServerError)] + public async Task CreateCommentary([FromBody] CommentaryDTO newCommentary) + { + try + { + if (newCommentary == null) + { + return BadRequest(new { message = "Comment data is required." }); + } + + var existingPlayer = _commentary.GetCommentaryById(newCommentary.Id).Result; + if (existingPlayer != null) + { + return Conflict(new { message = "A comment with this ID already exists." }); + } + + _commentary.AddComment(newCommentary); + + return CreatedAtAction(nameof(GetCommentary), new { id = newCommentary.Id }, newCommentary); + } + catch (Exception) + { + return StatusCode((int)HttpStatusCode.InternalServerError, new { message = "Erreur interne du serveur." }); + } + } + + + [HttpDelete] // /api/v1/commentary?id=51 + [ProducesResponseType(StatusCodes.Status200OK)] + [ProducesResponseType(StatusCodes.Status404NotFound)] + [ProducesResponseType(StatusCodes.Status500InternalServerError)] + public async Task DeleteCommentary([FromQuery] int id) + { + try + { + + var existingCommentary = _commentary.GetCommentaryById(id).Result; + if (existingCommentary == null) + { + return NotFound(new { message = "Commentary not found." }); + } + + _commentary.RemoveCommentary(existingCommentary.Id); + + return Ok(new { message = $"Commentary {id} deleted successfully." }); + } + catch (Exception) + { + return StatusCode((int)HttpStatusCode.InternalServerError, new { message = "Internal server error." }); + } + } + } +} diff --git a/WF_EF_Api/WfApi/Controllers/UsersController.cs b/WF_EF_Api/WfApi/Controllers/UsersController.cs index 400c835..1950bbd 100644 --- a/WF_EF_Api/WfApi/Controllers/UsersController.cs +++ b/WF_EF_Api/WfApi/Controllers/UsersController.cs @@ -573,13 +573,13 @@ namespace WfApi.Controllers { if (newUser == null) { - return BadRequest(new { message = "Les données du joueur sont requises." }); - } + return BadRequest(new { message = "User data is required." }); + } var existingPlayer = _user.GetUserById(newUser.Id).Result; if (existingPlayer != null) { - return Conflict(new { message = "Un utilisateur avec cet ID existe déjà." }); + return Conflict(new { message = "A user with this ID already exists." }); } _user.AddUser(newUser); diff --git a/WF_EF_Api/WfApi/Program.cs b/WF_EF_Api/WfApi/Program.cs index 54d221a..6e4cd69 100644 --- a/WF_EF_Api/WfApi/Program.cs +++ b/WF_EF_Api/WfApi/Program.cs @@ -9,6 +9,7 @@ var builder = WebApplication.CreateBuilder(args); //API builder.Services.AddScoped, UserService>(); builder.Services.AddScoped, QuoteService>(); +builder.Services.AddScoped, CommentaryService>(); //EF @@ -16,7 +17,7 @@ builder.Services.AddScoped(); builder.Services.AddScoped, DbUsersManager>(); builder.Services.AddScoped, DbQuoteManager>(); //builder.Services.AddScoped, DbCharacterManager>(); -//builder.Services.AddScoped, DbCommentaryManager>(); +builder.Services.AddScoped, DbCommentaryManager>(); //... // Add services to the container. From b7a0800b088b4221ff00fb901ac6947aad03c38f Mon Sep 17 00:00:00 2001 From: kekentin Date: Mon, 31 Mar 2025 17:15:32 +0200 Subject: [PATCH 44/65] Avancement DbQuoteManager --- WF_EF_Api/Contextlib/DbQuoteManager.cs | 54 ++++++++++++++++++++++---- WF_EF_Api/WfApi/Program.cs | 1 + 2 files changed, 47 insertions(+), 8 deletions(-) diff --git a/WF_EF_Api/Contextlib/DbQuoteManager.cs b/WF_EF_Api/Contextlib/DbQuoteManager.cs index a5fc2d1..9d8b2f7 100644 --- a/WF_EF_Api/Contextlib/DbQuoteManager.cs +++ b/WF_EF_Api/Contextlib/DbQuoteManager.cs @@ -4,6 +4,7 @@ using System.Linq; using System.Text; using System.Threading.Tasks; using Entity; +using Microsoft.EntityFrameworkCore.Metadata.Internal; using Shared; namespace Contextlib @@ -35,43 +36,80 @@ namespace Contextlib public async Task> GetAllQuote() { - List quotes = _repo.GetItems(0, _repo.Count(), [nameof(Quote.Id)]).ToList(); + List quotes = _repo.GetItems(item=> item.IsValid, + 0, _repo.Count(), [] + ).ToList(); return new PaginationResult(quotes.Count, 0, quotes.Count, quotes); } public async Task> GetAllQuoteLang(int index, int pageSize, int lang) { - throw new NotImplementedException(); + List quotes = _repo.GetItems(item => item.IsValid && item.Langage==(LangEnum)lang , + index, pageSize, [] + ).ToList(); + + return new PaginationResult(quotes.Count, index, pageSize, quotes); } public async Task GetDailyQuote(DateOnly date, int lang) { - throw new NotImplementedException(); + List quotes = _repo.GetItems(item => item.IsValid && item.Langage == (LangEnum)lang, + 0, _repo.Count(), [] + ).ToList(); + Quote quote = _repo.GetById(date.DayNumber % quotes.Count()) ?? quotes.First(); + + return quote; } public async Task> GetFavorites(int index, int pageSize, int UserId) { - throw new NotImplementedException(); + List quotes = _repo.GetItems(item => item.IsValid && item.Favorite.Where(p=>p.Id==UserId)!=null , + index, pageSize, [nameof(Quote.Favorite)] + ).ToList(); + + return new PaginationResult(quotes.Count, index, pageSize, quotes); } public async Task> GetInvalidQuote(int index, int pageSize, int lang) { - throw new NotImplementedException(); + List quotes = _repo.GetItems(item => !item.IsValid && item.Langage == (LangEnum)lang, + index, pageSize, [] + ).ToList(); + + return new PaginationResult(quotes.Count, index, pageSize, quotes); } public async Task> GetInvalidQuote(int index, int pageSize) { - throw new NotImplementedException(); + List quotes = _repo.GetItems(item => !item.IsValid, + index, pageSize, [] + ).ToList(); + + return new PaginationResult(quotes.Count, index, pageSize, quotes); } public async Task GetLastQuoteId() { - throw new NotImplementedException(); + PaginationResult users = await GetAllQuote(); + int lastQuoteId = 0; + foreach (Quote quote in users.items) + { + if (quote.Id >= lastQuoteId) + { + lastQuoteId = quote.Id + 1; + } + } + return lastQuoteId; } public async Task GetQuoteById(int id) { - throw new NotImplementedException(); + Quote? quote = _repo.GetById(id, item => item.Id == id, []); + if (quote == null) + { + throw new KeyNotFoundException($"Error : No quotes found with the ID: {id}."); + } + return quote; } public async Task> GetSomeQuote(int index, int pageSize) diff --git a/WF_EF_Api/WfApi/Program.cs b/WF_EF_Api/WfApi/Program.cs index 54d221a..3eb2b8d 100644 --- a/WF_EF_Api/WfApi/Program.cs +++ b/WF_EF_Api/WfApi/Program.cs @@ -13,6 +13,7 @@ builder.Services.AddScoped, QuoteService>(); //EF builder.Services.AddScoped(); + builder.Services.AddScoped, DbUsersManager>(); builder.Services.AddScoped, DbQuoteManager>(); //builder.Services.AddScoped, DbCharacterManager>(); From 5ecf9e768fdee5ee89f3595f19da9a3810a44ef5 Mon Sep 17 00:00:00 2001 From: kekentin Date: Mon, 31 Mar 2025 17:32:37 +0200 Subject: [PATCH 45/65] correction Include --- WF_EF_Api/Contextlib/DbCommentaryManager.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/WF_EF_Api/Contextlib/DbCommentaryManager.cs b/WF_EF_Api/Contextlib/DbCommentaryManager.cs index b18ae99..f39e4df 100644 --- a/WF_EF_Api/Contextlib/DbCommentaryManager.cs +++ b/WF_EF_Api/Contextlib/DbCommentaryManager.cs @@ -76,13 +76,13 @@ namespace Contextlib public async Task> GetAllCommentary() { - var comments = await _context.comments.Include(c => c.User).ToListAsync(); + var comments = await _context.comments.Include(c => c.User).Include(c=>c.User.Images).ToListAsync(); return new PaginationResult(comments.Count, 0, comments.Count, comments); } public async Task GetCommentaryById(int id) { - var comment = await _context.comments.Include(c => c.User).Where(x => x.Id == id).FirstOrDefaultAsync(); + var comment = await _context.comments.Include(c => c.User).Include(c => c.User.Images).Where(x => x.Id == id).FirstOrDefaultAsync(); if(comment == null) { throw new KeyNotFoundException($"No comments found with the given ID: {id}."); @@ -92,7 +92,7 @@ namespace Contextlib public async Task> GetCommentaryByQuote(int quoteId, int index, int pageSize) { - var comments = await _context.comments.Include(c => c.User).Where(x => x.IdQuote == quoteId).ToListAsync(); + var comments = await _context.comments.Include(c => c.User).Include(c => c.User.Images).Where(x => x.IdQuote == quoteId).ToListAsync(); if (!comments.Any()) { throw new KeyNotFoundException($"No comments found for the quote ID: {quoteId}."); From b9503cbab4a312c0a585b7d03d500c6d99eb8e2a Mon Sep 17 00:00:00 2001 From: Leni BEAULATON Date: Tue, 1 Apr 2025 12:00:29 +0200 Subject: [PATCH 46/65] =?UTF-8?q?Impl=C3=A9mentation=20des=20service=20qua?= =?UTF-8?q?si=20finie?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- WF_EF_Api/ConsoleTest/ConsoleTest.csproj | 4 + WF_EF_Api/Contextlib/DbCommentaryManager.cs | 19 +++- WF_EF_Api/DTO/DTO.csproj | 7 ++ WF_EF_Api/Dto2Entities/Dto2Entities.csproj | 7 ++ WF_EF_Api/Entity/Entity.csproj | 7 ++ WF_EF_Api/ServicesApi/CharacterService.cs | 59 ++++++++++++ WF_EF_Api/ServicesApi/CommentaryService.cs | 4 +- WF_EF_Api/ServicesApi/FavoriteService.cs | 45 ++++++++++ WF_EF_Api/ServicesApi/ImageService.cs | 59 ++++++++++++ WF_EF_Api/ServicesApi/QuestionService.cs | 89 +++++++++++++++++++ WF_EF_Api/ServicesApi/ServicesApi.csproj | 7 ++ WF_EF_Api/ServicesApi/SourceService.cs | 69 ++++++++++++++ WF_EF_Api/Shared/IComentaryService.cs | 2 +- WF_EF_Api/Shared/Shared.csproj | 7 ++ WF_EF_Api/StubApi/StubApi.csproj | 7 ++ .../TestModel2Entities.csproj | 7 ++ .../Controllers/CommentariesController.cs | 10 +-- WF_EF_Api/WfApi/Program.cs | 13 ++- WF_EF_Api/WfApi/WfApi.csproj | 4 + WF_EF_Api/XUnitTest/XUnitTest.csproj | 4 + 20 files changed, 419 insertions(+), 11 deletions(-) create mode 100644 WF_EF_Api/ServicesApi/CharacterService.cs create mode 100644 WF_EF_Api/ServicesApi/FavoriteService.cs create mode 100644 WF_EF_Api/ServicesApi/ImageService.cs create mode 100644 WF_EF_Api/ServicesApi/QuestionService.cs create mode 100644 WF_EF_Api/ServicesApi/SourceService.cs diff --git a/WF_EF_Api/ConsoleTest/ConsoleTest.csproj b/WF_EF_Api/ConsoleTest/ConsoleTest.csproj index 9a4ee54..73a6de7 100644 --- a/WF_EF_Api/ConsoleTest/ConsoleTest.csproj +++ b/WF_EF_Api/ConsoleTest/ConsoleTest.csproj @@ -8,6 +8,10 @@ + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + diff --git a/WF_EF_Api/Contextlib/DbCommentaryManager.cs b/WF_EF_Api/Contextlib/DbCommentaryManager.cs index f39e4df..78f7ae4 100644 --- a/WF_EF_Api/Contextlib/DbCommentaryManager.cs +++ b/WF_EF_Api/Contextlib/DbCommentaryManager.cs @@ -27,13 +27,30 @@ namespace Contextlib /// The comment to add. /// A task representing the asynchronous operation. /// Thrown when the comment is null. - public async Task AddComment(Commentary comment) + public async Task AddComment(Commentary comment, int idQuote) { if (comment == null) { throw new ArgumentNullException(nameof(comment), "Comment cannot be null."); } + var quote = await _context.quotes + .Include(q => q.Commentarys) // collection des commentaires est chargée + .FirstOrDefaultAsync(q => q.Id == idQuote); + + if (quote == null) + { + throw new ArgumentException("Quote not exist", nameof(idQuote)); + } + + // Lien entre le commentaire et la citation + comment.Quote = quote; + comment.IdQuote = idQuote; + + // Ajout commentaire à la collection des commentaires de la citation + quote.Commentarys.Add(comment); + + _repo.Insert(comment); await _context.SaveChangesAsync(); } diff --git a/WF_EF_Api/DTO/DTO.csproj b/WF_EF_Api/DTO/DTO.csproj index bb23fb7..99264a0 100644 --- a/WF_EF_Api/DTO/DTO.csproj +++ b/WF_EF_Api/DTO/DTO.csproj @@ -6,4 +6,11 @@ enable + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + + diff --git a/WF_EF_Api/Dto2Entities/Dto2Entities.csproj b/WF_EF_Api/Dto2Entities/Dto2Entities.csproj index beed701..7455396 100644 --- a/WF_EF_Api/Dto2Entities/Dto2Entities.csproj +++ b/WF_EF_Api/Dto2Entities/Dto2Entities.csproj @@ -6,6 +6,13 @@ enable + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + + diff --git a/WF_EF_Api/Entity/Entity.csproj b/WF_EF_Api/Entity/Entity.csproj index bb23fb7..99264a0 100644 --- a/WF_EF_Api/Entity/Entity.csproj +++ b/WF_EF_Api/Entity/Entity.csproj @@ -6,4 +6,11 @@ enable + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + + diff --git a/WF_EF_Api/ServicesApi/CharacterService.cs b/WF_EF_Api/ServicesApi/CharacterService.cs new file mode 100644 index 0000000..399586a --- /dev/null +++ b/WF_EF_Api/ServicesApi/CharacterService.cs @@ -0,0 +1,59 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using DTO; +using Entity; +using Shared; +using Dto2Entities; + +namespace ServicesApi +{ + public class CharacterService : ICharacterService + { + private ICharacterService characterService; + + public CharacterService(ICharacterService character) + { + characterService = character; + } + + + public async Task AddCharacter(CharacterDTO character) + { + await characterService.AddCharacter(character.ToEntity()); + } + + public async Task> GetAll() + { + var characters = characterService.GetAll().Result.items; + return new PaginationResult(characters.Count(), 0, 10, characters.ToDto()); + } + + public async Task GetCharById(int id) + { + return characterService.GetCharById(id).Result.ToDto(); + } + + public async Task GetCharByName(string name) + { + return characterService.GetCharByName(name).Result.ToDto(); + } + + public async Task GetLastCharId() + { + return await characterService.GetLastCharId(); + } + + public async Task RemoveCharacter(int id) + { + await characterService.RemoveCharacter(id); + } + + public async Task UpdateCharacter(int id, CharacterDTO character) + { + await characterService.UpdateCharacter(id, character.ToEntity()); + } + } +} diff --git a/WF_EF_Api/ServicesApi/CommentaryService.cs b/WF_EF_Api/ServicesApi/CommentaryService.cs index 211f6a4..e151c03 100644 --- a/WF_EF_Api/ServicesApi/CommentaryService.cs +++ b/WF_EF_Api/ServicesApi/CommentaryService.cs @@ -19,9 +19,9 @@ namespace ServicesApi commentaryService = commentary; } - public async Task AddComment(CommentaryDTO commentary) + public async Task AddComment(CommentaryDTO commentary, int idQuote) { - await commentaryService.AddComment(commentary.ToEntity()); + await commentaryService.AddComment(commentary.ToEntity(), idQuote); } public async Task DeleteCommentaryForQuote(int quoteId) diff --git a/WF_EF_Api/ServicesApi/FavoriteService.cs b/WF_EF_Api/ServicesApi/FavoriteService.cs new file mode 100644 index 0000000..d3b3802 --- /dev/null +++ b/WF_EF_Api/ServicesApi/FavoriteService.cs @@ -0,0 +1,45 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using DTO; +using Entity; +using Shared; +using Dto2Entities; +using static System.Net.Mime.MediaTypeNames; + +namespace ServicesApi +{ + public class FavoriteService : IFavoriteService + { + + private IFavoriteService favoriteService; + + public FavoriteService(IFavoriteService favorite) + { + favoriteService = favorite; + } + + + public async Task AddFavorite(int quoteid, int userId) + { + await favoriteService.AddFavorite(quoteid, userId); + } + + public async Task RemoveAllFavoriteForQuote(int quoteId) + { + await favoriteService.RemoveAllFavoriteForQuote(quoteId); + } + + public async Task RemoveAllFavoriteForUser(int userId) + { + await favoriteService.RemoveAllFavoriteForUser(userId); + } + + public async Task RemoveFavorite(int quoteid, int userId) + { + await favoriteService.RemoveFavorite(quoteid, userId); + } + } +} diff --git a/WF_EF_Api/ServicesApi/ImageService.cs b/WF_EF_Api/ServicesApi/ImageService.cs new file mode 100644 index 0000000..caefb31 --- /dev/null +++ b/WF_EF_Api/ServicesApi/ImageService.cs @@ -0,0 +1,59 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using DTO; +using Entity; +using Shared; +using Dto2Entities; + +namespace ServicesApi +{ + public class ImageService : IImagesService + { + private IImagesService imageService; + + public ImageService(IImagesService image) + { + imageService = image; + } + + public async Task AddImage(ImageDTO image) + { + await imageService.AddImage(image.ToEntity()); + } + + public async Task> GetAllImage() + { + var images = imageService.GetAllImage().Result.items; + return new PaginationResult(images.Count(), 0, 10, images.ToDto()); + } + + public async Task GetImageById(int id) + { + return imageService.GetImageById(id).Result.ToDto(); + } + + public async Task GetLastImageId() + { + return await imageService.GetLastImageId(); + } + + public async Task> GetSomeImage(int index, int pageSize) + { + var images = imageService.GetSomeImage(index,pageSize).Result.items; + return new PaginationResult(images.Count(), 0, 10, images.ToDto()); + } + + public async Task RemoveImage(int id) + { + await imageService.RemoveImage(id); + } + + public async Task UpdateImage(int id, ImageDTO image) + { + await imageService.UpdateImage(id, image.ToEntity()); + } + } +} diff --git a/WF_EF_Api/ServicesApi/QuestionService.cs b/WF_EF_Api/ServicesApi/QuestionService.cs new file mode 100644 index 0000000..4d71308 --- /dev/null +++ b/WF_EF_Api/ServicesApi/QuestionService.cs @@ -0,0 +1,89 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using DTO; +using Entity; +using Shared; +using Dto2Entities; +using static System.Net.Mime.MediaTypeNames; +using Microsoft.EntityFrameworkCore.Metadata.Internal; + +namespace ServicesApi +{ + public class QuestionService : IQuestionService + { + private IQuestionService questionService; + + public QuestionService(IQuestionService question) + { + questionService = question; + } + + + + public async Task AddQuestion(QuestionDTO question) + { + await questionService.AddQuestion(question.ToEntity()); + } + + public async Task CountQuestions() + { + return await questionService.CountQuestions(); + } + + public async Task> GetAllQuestion() + { + var questions = questionService.GetAllQuestion().Result.items; + return new PaginationResult(questions.Count(), 0, 10, questions.ToDto()); + } + + public async Task> GetInvalidQuestion(int index, int pageSize) + { + var questions = questionService.GetInvalidQuestion(index,pageSize).Result.items; + return new PaginationResult(questions.Count(), 0, 10, questions.ToDto()); + } + + public async Task GetQuestionById(int id) + { + return questionService.GetQuestionById(id).Result.ToDto(); + } + + public async Task GetRandomQuestion() + { + return questionService.GetRandomQuestion().Result.ToDto(); + } + + public async Task GetRandomQuestionQuoteToCharacter() + { + return questionService.GetRandomQuestionQuoteToCharacter().Result.ToDto(); + } + + public async Task GetRandomQuestionQuoteToSource() + { + return questionService.GetRandomQuestionQuoteToSource().Result.ToDto(); + } + + public async Task> GetSomeQuestion(int index, int pageSize) + { + var questions = questionService.GetSomeQuestion(index, pageSize).Result.items; + return new PaginationResult(questions.Count(), 0, 10, questions.ToDto()); + } + + public async Task RemoveQuestion(int id) + { + await questionService.RemoveQuestion(id); + } + + public async Task UpdateQuestion(int id, QuestionDTO question) + { + await questionService.UpdateQuestion(id, question.ToEntity()); + } + + public async Task ValidateQuestion(int id, bool isvalid) + { + await questionService.ValidateQuestion(id, isvalid); + } + } +} diff --git a/WF_EF_Api/ServicesApi/ServicesApi.csproj b/WF_EF_Api/ServicesApi/ServicesApi.csproj index 89650c8..074190e 100644 --- a/WF_EF_Api/ServicesApi/ServicesApi.csproj +++ b/WF_EF_Api/ServicesApi/ServicesApi.csproj @@ -6,6 +6,13 @@ enable + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + + diff --git a/WF_EF_Api/ServicesApi/SourceService.cs b/WF_EF_Api/ServicesApi/SourceService.cs new file mode 100644 index 0000000..f767fdc --- /dev/null +++ b/WF_EF_Api/ServicesApi/SourceService.cs @@ -0,0 +1,69 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using DTO; +using Entity; +using Shared; +using Dto2Entities; +using static System.Net.Mime.MediaTypeNames; +using static System.Runtime.InteropServices.JavaScript.JSType; + +namespace ServicesApi +{ + public class SourceService : ISourceService + { + private ISourceService srcService; + + public SourceService(ISourceService src) + { + srcService = src; + } + public async Task AddSource(SourceDTO source) + { + await srcService.AddSource(source.ToEntity()); + } + + public async Task> GetAll() + { + var sources = srcService.GetAll().Result.items; + return new PaginationResult(sources.Count(), 0, 10, sources.ToDto()); + } + + public async Task GetLastSourceId() + { + return await srcService.GetLastSourceId(); + } + + public async Task GetSourceByDate(string date) + { + return srcService.GetSourceByDate(date).Result.ToDto(); + } + + public async Task GetSourceById(int id) + { + return srcService.GetSourceById(id).Result.ToDto(); + } + + public async Task GetSourceByTitle(string title) + { + return srcService.GetSourceByTitle(title).Result.ToDto(); + } + + public async Task GetSourceByType(string type) + { + return srcService.GetSourceByType(type).Result.ToDto(); + } + + public async Task RemoveSource(int id) + { + await srcService.RemoveSource(id); + } + + public async Task UpdateSource(int id, SourceDTO source) + { + await srcService.UpdateSource(id, source.ToEntity()); + } + } +} diff --git a/WF_EF_Api/Shared/IComentaryService.cs b/WF_EF_Api/Shared/IComentaryService.cs index b546360..3808b6d 100644 --- a/WF_EF_Api/Shared/IComentaryService.cs +++ b/WF_EF_Api/Shared/IComentaryService.cs @@ -30,7 +30,7 @@ namespace Shared // Adds a new commenT. // 'comment' is the comment object that will be added. - Task AddComment(TComment commentary); + Task AddComment(TComment commentary, int idQuote); // Updates an existing comment identified by 'id'. // 'id' is the unique identifier of the comment, and 'comment' contains the updated comment data. diff --git a/WF_EF_Api/Shared/Shared.csproj b/WF_EF_Api/Shared/Shared.csproj index bb23fb7..99264a0 100644 --- a/WF_EF_Api/Shared/Shared.csproj +++ b/WF_EF_Api/Shared/Shared.csproj @@ -6,4 +6,11 @@ enable + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + + diff --git a/WF_EF_Api/StubApi/StubApi.csproj b/WF_EF_Api/StubApi/StubApi.csproj index de86de5..2df8a10 100644 --- a/WF_EF_Api/StubApi/StubApi.csproj +++ b/WF_EF_Api/StubApi/StubApi.csproj @@ -6,6 +6,13 @@ enable + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + + diff --git a/WF_EF_Api/TestModel2Entities/TestModel2Entities.csproj b/WF_EF_Api/TestModel2Entities/TestModel2Entities.csproj index bb23fb7..99264a0 100644 --- a/WF_EF_Api/TestModel2Entities/TestModel2Entities.csproj +++ b/WF_EF_Api/TestModel2Entities/TestModel2Entities.csproj @@ -6,4 +6,11 @@ enable + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + + diff --git a/WF_EF_Api/WfApi/Controllers/CommentariesController.cs b/WF_EF_Api/WfApi/Controllers/CommentariesController.cs index 737acea..29b579b 100644 --- a/WF_EF_Api/WfApi/Controllers/CommentariesController.cs +++ b/WF_EF_Api/WfApi/Controllers/CommentariesController.cs @@ -48,7 +48,7 @@ namespace WfApi.Controllers [ProducesResponseType(StatusCodes.Status400BadRequest)] [ProducesResponseType(StatusCodes.Status409Conflict)] [ProducesResponseType(StatusCodes.Status500InternalServerError)] - public async Task CreateCommentary([FromBody] CommentaryDTO newCommentary) + public async Task CreateCommentary([FromBody] CommentaryDTO newCommentary, int idQuote) { try { @@ -57,14 +57,14 @@ namespace WfApi.Controllers return BadRequest(new { message = "Comment data is required." }); } - var existingPlayer = _commentary.GetCommentaryById(newCommentary.Id).Result; - if (existingPlayer != null) + var existingCommentary = _commentary.GetCommentaryById(newCommentary.Id).Result; + if (existingCommentary != null) { return Conflict(new { message = "A comment with this ID already exists." }); } - _commentary.AddComment(newCommentary); - + await _commentary.AddComment(newCommentary, idQuote); + return CreatedAtAction(nameof(GetCommentary), new { id = newCommentary.Id }, newCommentary); } catch (Exception) diff --git a/WF_EF_Api/WfApi/Program.cs b/WF_EF_Api/WfApi/Program.cs index 184781b..04a65b8 100644 --- a/WF_EF_Api/WfApi/Program.cs +++ b/WF_EF_Api/WfApi/Program.cs @@ -5,11 +5,17 @@ using Contextlib; using Entity; using StubbedContextLib; using ServicesApi; -var builder = WebApplication.CreateBuilder(args); + //API +var builder = WebApplication.CreateBuilder(args); + builder.Services.AddScoped, UserService>(); builder.Services.AddScoped, QuoteService>(); builder.Services.AddScoped, CommentaryService>(); +builder.Services.AddScoped, CharacterService>(); +builder.Services.AddScoped, ImageService>(); +builder.Services.AddScoped, SourceService>(); +builder.Services.AddScoped, QuestionService>(); //EF @@ -17,8 +23,11 @@ builder.Services.AddScoped(); builder.Services.AddScoped, DbUsersManager>(); builder.Services.AddScoped, DbQuoteManager>(); -//builder.Services.AddScoped, DbCharacterManager>(); builder.Services.AddScoped, DbCommentaryManager>(); +builder.Services.AddScoped, DbCharacterManager>(); +builder.Services.AddScoped, DbImagesManager>(); +builder.Services.AddScoped, SourceService>(); +builder.Services.AddScoped, QuestionService>(); //... // Add services to the container. diff --git a/WF_EF_Api/WfApi/WfApi.csproj b/WF_EF_Api/WfApi/WfApi.csproj index 0416a92..638d2f5 100644 --- a/WF_EF_Api/WfApi/WfApi.csproj +++ b/WF_EF_Api/WfApi/WfApi.csproj @@ -11,6 +11,10 @@ + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + diff --git a/WF_EF_Api/XUnitTest/XUnitTest.csproj b/WF_EF_Api/XUnitTest/XUnitTest.csproj index 312f514..0578038 100644 --- a/WF_EF_Api/XUnitTest/XUnitTest.csproj +++ b/WF_EF_Api/XUnitTest/XUnitTest.csproj @@ -11,6 +11,10 @@ + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + From e51db914c2987ca157592bf05178c024426ac95e Mon Sep 17 00:00:00 2001 From: kekentin Date: Tue, 1 Apr 2025 12:02:56 +0200 Subject: [PATCH 47/65] Correction Quote avec les ThenInclude qui marche pas dans le GenericRepository --- WF_EF_Api/Contextlib/DbQuoteManager.cs | 49 ++++++------ WF_EF_Api/StubbedContextLib/StubWTFContext.cs | 2 +- .../Controllers/CommentariesController.cs | 4 +- .../WfApi/Controllers/QuotesController.cs | 75 ++++++++++++++----- .../WfApi/Controllers/UsersController.cs | 34 ++++----- WF_EF_Api/WfApi/Program.cs | 1 + 6 files changed, 102 insertions(+), 63 deletions(-) diff --git a/WF_EF_Api/Contextlib/DbQuoteManager.cs b/WF_EF_Api/Contextlib/DbQuoteManager.cs index 9d8b2f7..24915ce 100644 --- a/WF_EF_Api/Contextlib/DbQuoteManager.cs +++ b/WF_EF_Api/Contextlib/DbQuoteManager.cs @@ -4,6 +4,7 @@ using System.Linq; using System.Text; using System.Threading.Tasks; using Entity; +using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore.Metadata.Internal; using Shared; @@ -21,9 +22,6 @@ namespace Contextlib } - - - public async Task AddQuote(Quote quote) { if (quote == null) @@ -36,26 +34,25 @@ namespace Contextlib public async Task> GetAllQuote() { - List quotes = _repo.GetItems(item=> item.IsValid, - 0, _repo.Count(), [] - ).ToList(); + List quotes = _context.quotes.Where(item => item.IsValid) + .Include(q => q.Source).Include(q => q.Character).ThenInclude(c => c.Images) + .ToList(); return new PaginationResult(quotes.Count, 0, quotes.Count, quotes); } public async Task> GetAllQuoteLang(int index, int pageSize, int lang) { - List quotes = _repo.GetItems(item => item.IsValid && item.Langage==(LangEnum)lang , - index, pageSize, [] - ).ToList(); - + List quotes = _context.quotes.Where(item => item.IsValid && item.Langage == (LangEnum)lang) + .Include(q => q.Source).Include(q => q.Character).ThenInclude(c => c.Images) + .Skip(index * pageSize).Take(pageSize).ToList(); return new PaginationResult(quotes.Count, index, pageSize, quotes); } public async Task GetDailyQuote(DateOnly date, int lang) { - List quotes = _repo.GetItems(item => item.IsValid && item.Langage == (LangEnum)lang, - 0, _repo.Count(), [] - ).ToList(); + List quotes = _context.quotes.Where(item => item.IsValid && item.Langage == (LangEnum)lang) + .Include(q => q.Source).Include(q => q.Character).ThenInclude(c => c.Images).Include(q => q.Favorite) + .ToList(); Quote quote = _repo.GetById(date.DayNumber % quotes.Count()) ?? quotes.First(); return quote; @@ -63,36 +60,36 @@ namespace Contextlib public async Task> GetFavorites(int index, int pageSize, int UserId) { - List quotes = _repo.GetItems(item => item.IsValid && item.Favorite.Where(p=>p.Id==UserId)!=null , - index, pageSize, [nameof(Quote.Favorite)] - ).ToList(); + List quotes = _context.quotes.Where(item => item.IsValid && item.Favorite.Where(p => p.Id == UserId) != null) + .Include(q => q.Source).Include(q => q.Character).ThenInclude(c => c.Images).Include(q => q.Favorite) + .Skip(index * pageSize).Take(pageSize).ToList(); return new PaginationResult(quotes.Count, index, pageSize, quotes); } public async Task> GetInvalidQuote(int index, int pageSize, int lang) { - List quotes = _repo.GetItems(item => !item.IsValid && item.Langage == (LangEnum)lang, - index, pageSize, [] - ).ToList(); + List quotes = _context.quotes.Where(item => !item.IsValid && item.Langage == (LangEnum)lang) + .Include(q => q.Source).Include(q => q.Character).ThenInclude(c => c.Images) + .Skip(index * pageSize).Take(pageSize).ToList(); return new PaginationResult(quotes.Count, index, pageSize, quotes); } public async Task> GetInvalidQuote(int index, int pageSize) { - List quotes = _repo.GetItems(item => !item.IsValid, - index, pageSize, [] - ).ToList(); + List quotes = _context.quotes.Where(item => !item.IsValid) + .Include(q => q.Source).Include(q => q.Character).ThenInclude(c => c.Images) + .Skip(index * pageSize).Take(pageSize).ToList(); return new PaginationResult(quotes.Count, index, pageSize, quotes); } public async Task GetLastQuoteId() { - PaginationResult users = await GetAllQuote(); + PaginationResult quotes = await GetAllQuote(); int lastQuoteId = 0; - foreach (Quote quote in users.items) + foreach (Quote quote in quotes.items) { if (quote.Id >= lastQuoteId) { @@ -104,7 +101,9 @@ namespace Contextlib public async Task GetQuoteById(int id) { - Quote? quote = _repo.GetById(id, item => item.Id == id, []); + Quote? quote = _context.quotes.Where(item => item.Id == id) + .Include(q => q.Source).Include(q => q.Character).ThenInclude(c => c.Images) + .First(); if (quote == null) { throw new KeyNotFoundException($"Error : No quotes found with the ID: {id}."); diff --git a/WF_EF_Api/StubbedContextLib/StubWTFContext.cs b/WF_EF_Api/StubbedContextLib/StubWTFContext.cs index 7381211..677e88e 100644 --- a/WF_EF_Api/StubbedContextLib/StubWTFContext.cs +++ b/WF_EF_Api/StubbedContextLib/StubWTFContext.cs @@ -69,7 +69,7 @@ namespace StubbedContextLib new Quote() { Id = 7, Content = "Je suis la dernière Targaryen. Je suis la reine des dragons", IdCharacter = 7, IdSource = 3, IdUsersPropose = 1, IsValid = true, Langage = LangEnum.vf, Likes = 11025 }, new Quote() { Id = 8, Content = "Je ne suis pas prêt à affronter ça. C'est trop pour moi.", IdCharacter = 8, IdSource = 5, IdUsersPropose = 1, IsValid = true, Langage = LangEnum.vf, Likes = 11025 }, new Quote() { Id = 9, Content = "Aidez-moi, Obi-Wan Kenobi, vous êtes mon seul espoir.", IdCharacter = 9, IdSource = 5, IdUsersPropose = 1, IsValid = true, Langage = LangEnum.vf, Likes = 11025 }, - new Quote() { Id = 10, Content = "La quoi ?", IdCharacter = 10, IdSource = 4, IdUsersPropose = 1, IsValid = true, Langage = LangEnum.vf, Likes = 11025 } + new Quote() { Id = 10, Content = "La quoi ?", IdCharacter = 10, IdSource = 4, IdUsersPropose = 1, IsValid = false, Langage = LangEnum.vf, Likes = 11025 } ); modelBuilder.Entity().HasData( diff --git a/WF_EF_Api/WfApi/Controllers/CommentariesController.cs b/WF_EF_Api/WfApi/Controllers/CommentariesController.cs index 737acea..6d47769 100644 --- a/WF_EF_Api/WfApi/Controllers/CommentariesController.cs +++ b/WF_EF_Api/WfApi/Controllers/CommentariesController.cs @@ -26,9 +26,9 @@ namespace WfApi.Controllers { try { - var result = _commentary.GetCommentaryByQuote(id, index, count); + var result =await _commentary.GetCommentaryByQuote(id, index, count); - if (result.IsCompletedSuccessfully) + if (result != null) { return await Task.FromResult(Ok(result)); } diff --git a/WF_EF_Api/WfApi/Controllers/QuotesController.cs b/WF_EF_Api/WfApi/Controllers/QuotesController.cs index e2dd44d..521a2a2 100644 --- a/WF_EF_Api/WfApi/Controllers/QuotesController.cs +++ b/WF_EF_Api/WfApi/Controllers/QuotesController.cs @@ -25,13 +25,16 @@ namespace WfApi.Controllers //===================================== ROUTE GET ===================================== [HttpGet("{id}")] // Indiquer que l'id est dans l'URL + [ProducesResponseType(StatusCodes.Status200OK)] + [ProducesResponseType(StatusCodes.Status204NoContent)] + [ProducesResponseType(StatusCodes.Status500InternalServerError)] public async Task GetQuote(int id) { try { - var result = _quote.GetQuoteById(id); + var result = await _quote.GetQuoteById(id); - if (result.IsCompletedSuccessfully) + if (result!=null) { return await Task.FromResult(Ok(result)); } @@ -48,13 +51,16 @@ namespace WfApi.Controllers [HttpGet("all")] + [ProducesResponseType(StatusCodes.Status200OK)] + [ProducesResponseType(StatusCodes.Status204NoContent)] + [ProducesResponseType(StatusCodes.Status500InternalServerError)] public async Task GetAllQuote(int index = 0, int count = 10) { try { - var result = _quote.GetSomeQuote(index, count); + var result = await _quote.GetSomeQuote(index, count); - if (result.IsCompletedSuccessfully) + if (result != null) { return await Task.FromResult(Ok(result)); } @@ -69,13 +75,16 @@ namespace WfApi.Controllers } } [HttpGet("allbylang")] + [ProducesResponseType(StatusCodes.Status200OK)] + [ProducesResponseType(StatusCodes.Status204NoContent)] + [ProducesResponseType(StatusCodes.Status500InternalServerError)] public async Task GetAllQuoteByLang(TypeLangageDTO lang,int index = 0, int count = 10) { try { - var result = _quote.GetAllQuoteLang(index, count,(int)lang); + var result = await _quote.GetAllQuoteLang(index, count,(int)lang); - if (result.IsCompletedSuccessfully) + if (result != null) { return await Task.FromResult(Ok(result)); } @@ -90,15 +99,18 @@ namespace WfApi.Controllers } } [HttpGet("dailyquote")] + [ProducesResponseType(StatusCodes.Status200OK)] + [ProducesResponseType(StatusCodes.Status204NoContent)] + [ProducesResponseType(StatusCodes.Status500InternalServerError)] public async Task GetDailyQuote([FromQuery] int year, [FromQuery] int month, [FromQuery] int day, TypeLangageDTO lang) { try { DateOnly date = new DateOnly(year, month, day); - var result = _quote.GetDailyQuote(date, (int)lang); + var result = await _quote.GetDailyQuote(date, (int)lang); - if (result.IsCompletedSuccessfully) + if (result != null) { return await Task.FromResult(Ok(result)); } @@ -113,13 +125,16 @@ namespace WfApi.Controllers } } [HttpGet("invalid")] + [ProducesResponseType(StatusCodes.Status200OK)] + [ProducesResponseType(StatusCodes.Status204NoContent)] + [ProducesResponseType(StatusCodes.Status500InternalServerError)] public async Task GetInvalidQuote(TypeLangageDTO lang, int index = 0, int count = 10) { try { - var result = _quote.GetInvalidQuote(index, count, (int)lang); + var result =await _quote.GetInvalidQuote(index, count, (int)lang); - if (result.IsCompletedSuccessfully) + if (result != null) { return await Task.FromResult(Ok(result)); } @@ -134,13 +149,16 @@ namespace WfApi.Controllers } } [HttpGet("suggest")] + [ProducesResponseType(StatusCodes.Status200OK)] + [ProducesResponseType(StatusCodes.Status204NoContent)] + [ProducesResponseType(StatusCodes.Status500InternalServerError)] public async Task GetSuggestQuote(TypeLangageDTO lang, int index = 0, int count = 10) { try { - var result = _quote.GetSuggestions(index, count, (int)lang); + var result = await _quote.GetSuggestions(index, count, (int)lang); - if (result.IsCompletedSuccessfully) + if (result != null) { return await Task.FromResult(Ok(result)); } @@ -155,13 +173,16 @@ namespace WfApi.Controllers } } [HttpGet("searchByCharacter")] + [ProducesResponseType(StatusCodes.Status200OK)] + [ProducesResponseType(StatusCodes.Status204NoContent)] + [ProducesResponseType(StatusCodes.Status500InternalServerError)] public async Task GetQuoteSearchByCharacter(TypeLangageDTO lang, string character, int index = 0, int count = 10) { try { - var result = _quote.SearchByCharacter(character, index, count, (int)lang); + var result = await _quote.SearchByCharacter(character, index, count, (int)lang); - if (result.IsCompletedSuccessfully) + if (result != null) { return await Task.FromResult(Ok(result)); } @@ -176,13 +197,16 @@ namespace WfApi.Controllers } } [HttpGet("searchByCharac")] + [ProducesResponseType(StatusCodes.Status200OK)] + [ProducesResponseType(StatusCodes.Status204NoContent)] + [ProducesResponseType(StatusCodes.Status500InternalServerError)] public async Task GetQuoteSearchBySource(TypeLangageDTO lang, string source, int index = 0, int count = 10) { try { - var result = _quote.SearchBySource(source, index, count, (int)lang); + var result = await _quote.SearchBySource(source, index, count, (int)lang); - if (result.IsCompletedSuccessfully) + if (result != null) { return await Task.FromResult(Ok(result)); } @@ -197,13 +221,16 @@ namespace WfApi.Controllers } } [HttpGet("searchByContent")] + [ProducesResponseType(StatusCodes.Status200OK)] + [ProducesResponseType(StatusCodes.Status204NoContent)] + [ProducesResponseType(StatusCodes.Status500InternalServerError)] public async Task GetQuoteSearchByContent(TypeLangageDTO lang, string content, int index = 0, int count = 10) { try { - var result = _quote.SearchByContent(content, index, count, (int)lang); + var result =await _quote.SearchByContent(content, index, count, (int)lang); - if (result.IsCompletedSuccessfully) + if (result != null) { return await Task.FromResult(Ok(result)); } @@ -221,6 +248,9 @@ namespace WfApi.Controllers //===================================== ROUTE POST ===================================== [HttpPost] + [ProducesResponseType(StatusCodes.Status200OK)] + [ProducesResponseType(StatusCodes.Status204NoContent)] + [ProducesResponseType(StatusCodes.Status500InternalServerError)] public async Task CreateQuote([FromBody] QuoteDTO newQuote) { try @@ -247,6 +277,9 @@ namespace WfApi.Controllers } //===================================== ROUTE PUT ===================================== [HttpPut()] + [ProducesResponseType(StatusCodes.Status200OK)] + [ProducesResponseType(StatusCodes.Status204NoContent)] + [ProducesResponseType(StatusCodes.Status500InternalServerError)] public async Task UpdateQuote([FromQuery] int id, [FromBody] QuoteDTO updatedquote) { try @@ -266,6 +299,9 @@ namespace WfApi.Controllers } } [HttpPut("valide")] + [ProducesResponseType(StatusCodes.Status200OK)] + [ProducesResponseType(StatusCodes.Status204NoContent)] + [ProducesResponseType(StatusCodes.Status500InternalServerError)] public async Task ValideQuote([FromQuery] int id) { try @@ -289,6 +325,9 @@ namespace WfApi.Controllers //===================================== ROUTE DELETE ===================================== [HttpDelete("delete")] + [ProducesResponseType(StatusCodes.Status200OK)] + [ProducesResponseType(StatusCodes.Status204NoContent)] + [ProducesResponseType(StatusCodes.Status500InternalServerError)] public async Task DeleteQuote([FromQuery] int idQuote) { try diff --git a/WF_EF_Api/WfApi/Controllers/UsersController.cs b/WF_EF_Api/WfApi/Controllers/UsersController.cs index 1950bbd..701f486 100644 --- a/WF_EF_Api/WfApi/Controllers/UsersController.cs +++ b/WF_EF_Api/WfApi/Controllers/UsersController.cs @@ -53,9 +53,9 @@ namespace WfApi.Controllers { try { - var result = _user.GetUserById(id); + var result =await _user.GetUserById(id); - if (result.IsCompletedSuccessfully) + if (result != null) { return await Task.FromResult(Ok(result)); } @@ -104,9 +104,9 @@ namespace WfApi.Controllers { try { - var result = _user.GetSomeUser(index, count); + var result =await _user.GetSomeUser(index, count); - if (result.IsCompletedSuccessfully) + if (result != null) { return await Task.FromResult(Ok(result)); } @@ -163,9 +163,9 @@ namespace WfApi.Controllers try { - var result = _user.GetHashPassword(username); + var result =await _user.GetHashPassword(username); - if (result.IsCompletedSuccessfully) + if (result != null) { return await Task.FromResult(Ok(result)); } @@ -222,9 +222,9 @@ namespace WfApi.Controllers try { - var result = _user.GetUserByUsername(username); - - if (result.IsCompletedSuccessfully) + var result =await _user.GetUserByUsername(username); + + if (result != null) { return await Task.FromResult(Ok(result)); } @@ -280,9 +280,9 @@ namespace WfApi.Controllers } try { - var result = _user.GetUserByEmail(email); + var result =await _user.GetUserByEmail(email); - if (result.IsCompletedSuccessfully) + if (result != null) { return await Task.FromResult(Ok(result)); } @@ -329,9 +329,9 @@ namespace WfApi.Controllers { try { - var result = _user.CountUser(); + var result =await _user.CountUser(); - if (result.IsCompletedSuccessfully) + if (result!=null) { return await Task.FromResult(Ok(result)); } @@ -389,9 +389,9 @@ namespace WfApi.Controllers } try { - var result = _user.ExistUsername(username); + var result =await _user.ExistUsername(username); - if (result.IsCompletedSuccessfully) + if (result!=null) { return await Task.FromResult(Ok(result)); } @@ -448,9 +448,9 @@ namespace WfApi.Controllers } try { - var result = _user.ExistEmail(email); + var result =await _user.ExistEmail(email); - if (result.IsCompletedSuccessfully) + if (result!=null) { return await Task.FromResult(Ok(result)); } diff --git a/WF_EF_Api/WfApi/Program.cs b/WF_EF_Api/WfApi/Program.cs index 184781b..5c683a3 100644 --- a/WF_EF_Api/WfApi/Program.cs +++ b/WF_EF_Api/WfApi/Program.cs @@ -15,6 +15,7 @@ builder.Services.AddScoped, CommentaryService> //EF builder.Services.AddScoped(); + builder.Services.AddScoped, DbUsersManager>(); builder.Services.AddScoped, DbQuoteManager>(); //builder.Services.AddScoped, DbCharacterManager>(); From 8471e6cfd50227037555f6650ed659ac091cc613 Mon Sep 17 00:00:00 2001 From: kekentin Date: Tue, 1 Apr 2025 16:50:49 +0200 Subject: [PATCH 48/65] Correction Lien Quote Controlleur --- WF_EF_Api/Contextlib/DbQuoteManager.cs | 106 +- WF_EF_Api/Contextlib/WTFContext.cs | 1 - WF_EF_Api/DTO/TypeLangageDTO.cs | 3 +- WF_EF_Api/Dto2Entities/Extention.cs | 2 - WF_EF_Api/Entity/DailyQuote.cs | 19 - WF_EF_Api/Entity/LangEnum.cs | 3 +- WF_EF_Api/Entity/Quote.cs | 2 - .../20250401141906_suprDailyQuote.Designer.cs | 1074 +++++++++++++++++ .../20250401141906_suprDailyQuote.cs | 61 + .../Migrations/StubWTFContextModelSnapshot.cs | 35 +- WF_EF_Api/StubbedContextLib/StubWTFContext.cs | 4 - .../WfApi/Controllers/QuotesController.cs | 2 +- WF_EF_Api/WfApi/Program.cs | 7 +- 13 files changed, 1229 insertions(+), 90 deletions(-) delete mode 100644 WF_EF_Api/Entity/DailyQuote.cs create mode 100644 WF_EF_Api/StubbedContextLib/Migrations/20250401141906_suprDailyQuote.Designer.cs create mode 100644 WF_EF_Api/StubbedContextLib/Migrations/20250401141906_suprDailyQuote.cs diff --git a/WF_EF_Api/Contextlib/DbQuoteManager.cs b/WF_EF_Api/Contextlib/DbQuoteManager.cs index 24915ce..b098b0e 100644 --- a/WF_EF_Api/Contextlib/DbQuoteManager.cs +++ b/WF_EF_Api/Contextlib/DbQuoteManager.cs @@ -1,4 +1,5 @@ using System; +using System.Collections; using System.Collections.Generic; using System.Linq; using System.Text; @@ -48,12 +49,13 @@ namespace Contextlib return new PaginationResult(quotes.Count, index, pageSize, quotes); } - public async Task GetDailyQuote(DateOnly date, int lang) + public async Task GetDailyQuote(DateOnly date, int lang) { List quotes = _context.quotes.Where(item => item.IsValid && item.Langage == (LangEnum)lang) .Include(q => q.Source).Include(q => q.Character).ThenInclude(c => c.Images).Include(q => q.Favorite) .ToList(); - Quote quote = _repo.GetById(date.DayNumber % quotes.Count()) ?? quotes.First(); + if (quotes.Count() == 0) return null; + Quote quote = quotes[ date.DayNumber % quotes.Count() ] ; return quote; } @@ -113,51 +115,115 @@ namespace Contextlib public async Task> GetSomeQuote(int index, int pageSize) { - throw new NotImplementedException(); + List quotes = _context.quotes.Where(item => item.IsValid) + .Include(q => q.Source).Include(q => q.Character).ThenInclude(c => c.Images) + .Skip(index * pageSize).Take(pageSize).ToList(); + return new PaginationResult(quotes.Count, index, pageSize, quotes); } - public async Task> GetSuggestions(int index, int pageSize, int lang) + public async Task> GetSuggestions(int index, int pageSize, int lang) // A changer Suggestion Random { - throw new NotImplementedException(); + List quotes = _context.quotes.Where(item => item.IsValid && item.Langage == (LangEnum)lang) + .Include(q => q.Source).Include(q => q.Character).ThenInclude(c => c.Images) + //.OrderBy(q=> new Random() ) + .Skip(index * pageSize).Take(pageSize).ToList(); + + return new PaginationResult(quotes.Count, index, pageSize, quotes); } public async Task> GetValidQuote(int index, int pageSize) { - throw new NotImplementedException(); - } - - - - + List quotes = _context.quotes.Where(item => item.IsValid) + .Include(q => q.Source).Include(q => q.Character).ThenInclude(c => c.Images) + .Skip(index * pageSize).Take(pageSize).ToList(); - public async Task RemoveQuote(int quoteId) - { - throw new NotImplementedException(); + return new PaginationResult(quotes.Count, index, pageSize, quotes); } - + public async Task> SearchByCharacter(string character, int index, int pageSize, int lang) { - throw new NotImplementedException(); + List quotes = _context.quotes.Where(item => item.IsValid && item.Langage==(LangEnum)lang && (item.Character.Name).Contains(character)) + .Include(q => q.Source).Include(q => q.Character).ThenInclude(c => c.Images) + .Skip(index * pageSize).Take(pageSize).ToList(); + + return new PaginationResult(quotes.Count, index, pageSize, quotes); } public async Task> SearchByContent(string content, int index, int pageSize, int lang) { - throw new NotImplementedException(); + List quotes = _context.quotes.Where(item => item.IsValid && item.Langage == (LangEnum)lang && (item.Content).Contains(content)) + .Include(q => q.Source).Include(q => q.Character).ThenInclude(c => c.Images) + .Skip(index * pageSize).Take(pageSize).ToList(); + + return new PaginationResult(quotes.Count, index, pageSize, quotes); } public async Task> SearchBySource(string source, int index, int pageSize, int lang) { - throw new NotImplementedException(); + List quotes = _context.quotes.Where(item => item.IsValid && item.Langage == (LangEnum)lang && (item.Source.Title).Contains(source)) + .Include(q => q.Source).Include(q => q.Character).ThenInclude(c => c.Images) + .Skip(index * pageSize).Take(pageSize).ToList(); + + return new PaginationResult(quotes.Count, index, pageSize, quotes); + } + + + + + + public async Task RemoveQuote(int quoteId) + { + _repo.Delete( _repo.GetById(quoteId) ); + await _context.SaveChangesAsync(); } public async Task UpdateQuote(int quoteId, Quote quote) { - throw new NotImplementedException(); + Quote? q = _repo.GetById(quoteId); + if (q != null) + { + bool change = false; + if (quote.IdSource != 0) + { + q.IdSource = quote.IdSource; + change = true; + } + if (quote.IdCharacter != 0) + { + q.IdCharacter = quote.IdCharacter; + change = true; + } + if (quote.IdSource != 0) + { + q.IdSource = quote.IdSource; + change = true; + } + if (quote.IdUsersPropose !=0) + { + q.IdUsersPropose = quote.IdUsersPropose; + change = true; + } + if (quote.Content != null || quote.Content =="") + { + q.Content = quote.Content; + change = true; + } + _repo.Update(q); + if (change) _context.SaveChanges(); + } + return ; } public async Task ValidateQuote(int quoteId, bool isValidate) { - throw new NotImplementedException(); + Quote? q = _repo.GetById(quoteId); + if (q != null) + { + q.IsValid = isValidate; + _repo.Update(q); + _context.SaveChanges(); + } + return; } } } diff --git a/WF_EF_Api/Contextlib/WTFContext.cs b/WF_EF_Api/Contextlib/WTFContext.cs index e82284d..1a765f7 100644 --- a/WF_EF_Api/Contextlib/WTFContext.cs +++ b/WF_EF_Api/Contextlib/WTFContext.cs @@ -14,7 +14,6 @@ namespace Contextlib //public DbSet admins { get; set; } public DbSet characters { get; set; } public DbSet comments { get; set; } - public DbSet dailyquotes { get; set; } public DbSet favorites { get; set; } public DbSet images { get; set; } public DbSet question { get; set; } diff --git a/WF_EF_Api/DTO/TypeLangageDTO.cs b/WF_EF_Api/DTO/TypeLangageDTO.cs index 1320c27..855168f 100644 --- a/WF_EF_Api/DTO/TypeLangageDTO.cs +++ b/WF_EF_Api/DTO/TypeLangageDTO.cs @@ -9,7 +9,6 @@ namespace DTO public enum TypeLangageDTO { vo, - vf, - ve + vf } } diff --git a/WF_EF_Api/Dto2Entities/Extention.cs b/WF_EF_Api/Dto2Entities/Extention.cs index 5d7d85f..c0366d6 100644 --- a/WF_EF_Api/Dto2Entities/Extention.cs +++ b/WF_EF_Api/Dto2Entities/Extention.cs @@ -225,7 +225,6 @@ namespace Dto2Entities { case LangEnum.vf: return TypeLangageDTO.vf; case LangEnum.vo: return TypeLangageDTO.vo; - case LangEnum.ve: return TypeLangageDTO.ve; default: return TypeLangageDTO.vo; } } @@ -456,7 +455,6 @@ namespace Dto2Entities { case TypeLangageDTO.vf: return LangEnum.vf; case TypeLangageDTO.vo: return LangEnum.vo; - case TypeLangageDTO.ve: return LangEnum.ve; default: return LangEnum.vo; } } diff --git a/WF_EF_Api/Entity/DailyQuote.cs b/WF_EF_Api/Entity/DailyQuote.cs deleted file mode 100644 index 04aa8c5..0000000 --- a/WF_EF_Api/Entity/DailyQuote.cs +++ /dev/null @@ -1,19 +0,0 @@ -using System; -using System.Collections.Generic; -using System.ComponentModel.DataAnnotations; -using System.ComponentModel.DataAnnotations.Schema; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace Entity -{ - public class DailyQuote - { - [Key] - [ForeignKey(nameof(Quote))] - public int IdQuote { get; set; } - - public Quote Quote { get; set; } = null!; - } -} diff --git a/WF_EF_Api/Entity/LangEnum.cs b/WF_EF_Api/Entity/LangEnum.cs index dd70bb1..3f8f2a1 100644 --- a/WF_EF_Api/Entity/LangEnum.cs +++ b/WF_EF_Api/Entity/LangEnum.cs @@ -9,7 +9,6 @@ namespace Entity public enum LangEnum { vo, - vf, - ve + vf } } diff --git a/WF_EF_Api/Entity/Quote.cs b/WF_EF_Api/Entity/Quote.cs index 37d5f00..08b148b 100644 --- a/WF_EF_Api/Entity/Quote.cs +++ b/WF_EF_Api/Entity/Quote.cs @@ -46,8 +46,6 @@ namespace Entity public Character Character { get; set; } = null!; - public ICollection DailyQuotes { get; set; } = new List(); - public ICollection Commentarys { get; set; } = new List(); public ICollection Favorite { get; } = new List(); diff --git a/WF_EF_Api/StubbedContextLib/Migrations/20250401141906_suprDailyQuote.Designer.cs b/WF_EF_Api/StubbedContextLib/Migrations/20250401141906_suprDailyQuote.Designer.cs new file mode 100644 index 0000000..89c0f87 --- /dev/null +++ b/WF_EF_Api/StubbedContextLib/Migrations/20250401141906_suprDailyQuote.Designer.cs @@ -0,0 +1,1074 @@ +// +using System; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Metadata; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; +using StubbedContextLib; + +#nullable disable + +namespace StubbedContextLib.Migrations +{ + [DbContext(typeof(StubWTFContext))] + [Migration("20250401141906_suprDailyQuote")] + partial class suprDailyQuote + { + /// + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("ProductVersion", "9.0.3") + .HasAnnotation("Relational:MaxIdentifierLength", 128); + + SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder); + + modelBuilder.Entity("Entity.Admin", b => + { + b.Property("IdUsers") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("IdUsers")); + + b.Property("UserId") + .HasColumnType("int"); + + b.HasKey("IdUsers"); + + b.HasIndex("UserId"); + + b.ToTable("admins"); + }); + + modelBuilder.Entity("Entity.Character", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("IdImage") + .HasColumnType("int"); + + b.Property("Name") + .IsRequired() + .HasMaxLength(50) + .HasColumnType("nvarchar(50)"); + + b.HasKey("Id"); + + b.HasIndex("IdImage"); + + b.ToTable("characters"); + + b.HasData( + new + { + Id = 1, + IdImage = 1, + Name = "Alan Grant" + }, + new + { + Id = 2, + IdImage = 2, + Name = "Aragorn" + }, + new + { + Id = 3, + IdImage = 3, + Name = "Legolas" + }, + new + { + Id = 4, + IdImage = 4, + Name = "Frodon" + }, + new + { + Id = 5, + IdImage = 5, + Name = "Dobby" + }, + new + { + Id = 6, + IdImage = 6, + Name = "Jon Snow" + }, + new + { + Id = 7, + IdImage = 7, + Name = "Daenerys Targaryen" + }, + new + { + Id = 8, + IdImage = 8, + Name = "Luke Skywalker" + }, + new + { + Id = 9, + IdImage = 9, + Name = "Princess Leia" + }, + new + { + Id = 10, + IdImage = 10, + Name = "Harry Potter" + }); + }); + + modelBuilder.Entity("Entity.Commentary", b => + { + b.Property("IdUser") + .HasColumnType("int"); + + b.Property("IdQuote") + .HasColumnType("int"); + + b.Property("Comment") + .IsRequired() + .HasMaxLength(100) + .HasColumnType("nvarchar(100)"); + + b.Property("DateCommentary") + .HasColumnType("date") + .HasColumnName("DateCommentary"); + + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.HasKey("IdUser", "IdQuote"); + + b.HasIndex("IdQuote"); + + b.ToTable("comments"); + + b.HasData( + new + { + IdUser = 2, + IdQuote = 1, + Comment = "Ce film est le meilleur", + DateCommentary = new DateTime(2025, 2, 3, 0, 0, 0, 0, DateTimeKind.Unspecified), + Id = 1 + }, + new + { + IdUser = 3, + IdQuote = 1, + Comment = "Very good", + DateCommentary = new DateTime(2025, 3, 11, 0, 0, 0, 0, DateTimeKind.Unspecified), + Id = 2 + }); + }); + + modelBuilder.Entity("Entity.Favorite", b => + { + b.Property("IdQuote") + .HasColumnType("int"); + + b.Property("IdUsers") + .HasColumnType("int"); + + b.HasKey("IdQuote", "IdUsers"); + + b.HasIndex("IdUsers"); + + b.ToTable("favorites"); + + b.HasData( + new + { + IdQuote = 2, + IdUsers = 8 + }, + new + { + IdQuote = 5, + IdUsers = 3 + }, + new + { + IdQuote = 9, + IdUsers = 1 + }, + new + { + IdQuote = 4, + IdUsers = 10 + }, + new + { + IdQuote = 3, + IdUsers = 2 + }, + new + { + IdQuote = 6, + IdUsers = 7 + }, + new + { + IdQuote = 1, + IdUsers = 6 + }, + new + { + IdQuote = 8, + IdUsers = 9 + }, + new + { + IdQuote = 10, + IdUsers = 5 + }); + }); + + modelBuilder.Entity("Entity.Images", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("ImgPath") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.HasKey("Id"); + + b.ToTable("images"); + + b.HasData( + new + { + Id = 1, + ImgPath = "https://th.bing.com/th/id/OIP.TJuWNCsibz8MVmhdNQEdMwHaE8?w=244&h=180&c=7&r=0&o=5&pid=1.7" + }, + new + { + Id = 2, + ImgPath = "https://th.bing.com/th/id/OIP.NgXRQ5-IknA6_qOPFhLWIwHaHK?w=165&h=180&c=7&r=0&o=5&pid=1.7" + }, + new + { + Id = 3, + ImgPath = "https://th.bing.com/th/id/OIP.XcJoJ6bC9sAMjol1pJn5UQHaLH?w=118&h=180&c=7&r=0&o=5&pid=1.7" + }, + new + { + Id = 4, + ImgPath = "https://th.bing.com/th/id/OIP.PPIESqZaNDa-qUcfSDXhdQHaGK?w=210&h=180&c=7&r=0&o=5&pid=1.7" + }, + new + { + Id = 5, + ImgPath = "https://th.bing.com/th/id/OIP.XBghSl2kfRNNtQoSxc901wHaHa?w=177&h=180&c=7&r=0&o=5&pid=1.7" + }, + new + { + Id = 6, + ImgPath = "https://th.bing.com/th/id/OIP.af1Aid64cqEKoIOBgCPxtQHaJO?w=145&h=182&c=7&r=0&o=5&pid=1.7" + }, + new + { + Id = 7, + ImgPath = "https://th.bing.com/th/id/OIP.ri5vSXr5lNTLt4DO6KQXyQHaI4?w=158&h=189&c=7&r=0&o=5&pid=1.7" + }, + new + { + Id = 8, + ImgPath = "https://th.bing.com/th/id/OIP.uPTRLR8uspCiafiunUqKfQHaMJ?w=115&h=180&c=7&r=0&o=5&pid=1.7" + }, + new + { + Id = 9, + ImgPath = "https://th.bing.com/th/id/OIP.hcJis4rKbyQtugsoFJU2ngHaM_?w=118&h=207&c=7&r=0&o=5&pid=1.7" + }, + new + { + Id = 10, + ImgPath = "https://th.bing.com/th/id/OIP.Py1_XfUrKJY_A6tYEmFS5wHaE8?w=280&h=187&c=7&r=0&o=5&pid=1.7" + }); + }); + + modelBuilder.Entity("Entity.Question", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("AnswerA") + .IsRequired() + .HasMaxLength(50) + .HasColumnType("nvarchar(50)"); + + b.Property("AnswerB") + .IsRequired() + .HasMaxLength(50) + .HasColumnType("nvarchar(50)"); + + b.Property("AnswerC") + .IsRequired() + .HasMaxLength(50) + .HasColumnType("nvarchar(50)"); + + b.Property("AnswerD") + .IsRequired() + .HasMaxLength(50) + .HasColumnType("nvarchar(50)"); + + b.Property("CorrectAnswer") + .IsRequired() + .HasMaxLength(1) + .HasColumnType("nvarchar(1)"); + + b.Property("IsValid") + .HasColumnType("bit"); + + b.Property("Text") + .IsRequired() + .HasMaxLength(200) + .HasColumnType("nvarchar(200)"); + + b.HasKey("Id"); + + b.ToTable("question"); + + b.HasData( + new + { + Id = 1, + AnswerA = "Gimli", + AnswerB = "Aragorn", + AnswerC = "Frodon", + AnswerD = "Gandalf", + CorrectAnswer = "B", + IsValid = true, + Text = "Qui est le leader de la Communauté de l'Anneau ?" + }, + new + { + Id = 2, + AnswerA = "Serdaigle", + AnswerB = "Gryffondor", + AnswerC = "Serpentard", + AnswerD = "Poufsouffle", + CorrectAnswer = "B", + IsValid = false, + Text = "Dans quelle maison Harry Potter est-il ?" + }, + new + { + Id = 3, + AnswerA = "Saroumane", + AnswerB = "Sauron", + AnswerC = "Gollum", + AnswerD = "Gothmog", + CorrectAnswer = "B", + IsValid = true, + Text = "Qui est le Seigneur des Ténèbres dans la saga Le Seigneur des Anneaux ?" + }, + new + { + Id = 4, + AnswerA = "Han Solo", + AnswerB = "Princesse Leia", + AnswerC = "Chewbacca", + AnswerD = "R2-D2", + CorrectAnswer = "A", + IsValid = true, + Text = "Dans le film Star Wars : Episode IV, qui sauve Luke Skywalker de l'Étoile de la Mort ?" + }, + new + { + Id = 5, + AnswerA = "Reine Jadis", + AnswerB = "Aslan", + AnswerC = "Edmund", + AnswerD = "Lucy", + CorrectAnswer = "B", + IsValid = true, + Text = "Qui est le souverain de Narnia dans Le Lion, la Sorcière Blanche et l'Armoire Magique ?" + }, + new + { + Id = 6, + AnswerA = "Smaug", + AnswerB = "Falkor", + AnswerC = "Norbert", + AnswerD = "Shenron", + CorrectAnswer = "A", + IsValid = true, + Text = "Quel est le nom du dragon dans Le Hobbit ?" + }, + new + { + Id = 7, + AnswerA = "Bella Swan", + AnswerB = "Edward Cullen", + AnswerC = "Jacob Black", + AnswerD = "Victoria", + CorrectAnswer = "A", + IsValid = true, + Text = "Qui est la première personne à être mordue par un vampire dans Twilight ?" + }, + new + { + Id = 8, + AnswerA = "Obi-Wan Kenobi", + AnswerB = "Yoda", + AnswerC = "Han Solo", + AnswerD = "Luke Skywalker", + CorrectAnswer = "A", + IsValid = true, + Text = "Quel personnage dit Que la Force soit avec toi dans Star Wars ?" + }, + new + { + Id = 9, + AnswerA = "Dr. Ellie Sattler", + AnswerB = "Alan Grant", + AnswerC = "John Hammond", + AnswerD = "Dennis Nedry", + CorrectAnswer = "B", + IsValid = true, + Text = "Dans Jurassic Park, quel est le nom du paléontologue sur l'île ?" + }, + new + { + Id = 10, + AnswerA = "Cersei Lannister", + AnswerB = "Arya Stark", + AnswerC = "Daenerys Targaryen", + AnswerD = "Sansa Stark", + CorrectAnswer = "C", + IsValid = true, + Text = "Dans Game of Thrones, qui est surnommée la Mère des Dragons ?" + }); + }); + + modelBuilder.Entity("Entity.Quiz", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("IdImage") + .HasColumnType("int"); + + b.Property("NbQuestion") + .HasColumnType("int"); + + b.Property("Title") + .IsRequired() + .HasMaxLength(50) + .HasColumnType("nvarchar(50)"); + + b.HasKey("Id"); + + b.HasIndex("IdImage"); + + b.ToTable("quizzes"); + + b.HasData( + new + { + Id = 1, + IdImage = 1, + NbQuestion = 5, + Title = "Quiz 1" + }, + new + { + Id = 2, + IdImage = 2, + NbQuestion = 5, + Title = "Quiz 2" + }); + }); + + modelBuilder.Entity("Entity.QuizQuestion", b => + { + b.Property("IdQuestion") + .HasColumnType("int"); + + b.Property("IdQuiz") + .HasColumnType("int"); + + b.HasKey("IdQuestion", "IdQuiz"); + + b.HasIndex("IdQuiz"); + + b.ToTable("QuizQuestion"); + + b.HasData( + new + { + IdQuestion = 1, + IdQuiz = 1 + }, + new + { + IdQuestion = 2, + IdQuiz = 1 + }, + new + { + IdQuestion = 3, + IdQuiz = 1 + }, + new + { + IdQuestion = 4, + IdQuiz = 1 + }, + new + { + IdQuestion = 5, + IdQuiz = 1 + }, + new + { + IdQuestion = 6, + IdQuiz = 2 + }, + new + { + IdQuestion = 7, + IdQuiz = 2 + }, + new + { + IdQuestion = 8, + IdQuiz = 2 + }, + new + { + IdQuestion = 9, + IdQuiz = 2 + }, + new + { + IdQuestion = 10, + IdQuiz = 2 + }); + }); + + modelBuilder.Entity("Entity.Quote", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("Content") + .IsRequired() + .HasMaxLength(100) + .HasColumnType("nvarchar(100)"); + + b.Property("IdCharacter") + .HasColumnType("int"); + + b.Property("IdSource") + .HasColumnType("int"); + + b.Property("IdUsersPropose") + .HasColumnType("int"); + + b.Property("IsValid") + .HasColumnType("bit"); + + b.Property("Langage") + .HasColumnType("int"); + + b.Property("Likes") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.HasIndex("IdCharacter"); + + b.HasIndex("IdSource"); + + b.HasIndex("IdUsersPropose"); + + b.ToTable("quotes"); + + b.HasData( + new + { + Id = 1, + Content = "Je n'y crois pas. Je n'y crois pas. Ce n'est pas possible", + IdCharacter = 1, + IdSource = 1, + IdUsersPropose = 1, + IsValid = true, + Langage = 1, + Likes = 11025 + }, + new + { + Id = 2, + Content = "There is always hope", + IdCharacter = 2, + IdSource = 2, + IdUsersPropose = 1, + IsValid = true, + Langage = 0, + Likes = 11025 + }, + new + { + Id = 3, + Content = "A red sun rises. Blood has been spilled this night.", + IdCharacter = 3, + IdSource = 2, + IdUsersPropose = 1, + IsValid = true, + Langage = 0, + Likes = 11025 + }, + new + { + Id = 4, + Content = "I wish the Ring had never come to me.I wish none of this had happened.", + IdCharacter = 4, + IdSource = 2, + IdUsersPropose = 1, + IsValid = true, + Langage = 0, + Likes = 11025 + }, + new + { + Id = 5, + Content = "Dobby is a free elf!", + IdCharacter = 5, + IdSource = 4, + IdUsersPropose = 1, + IsValid = true, + Langage = 0, + Likes = 11025 + }, + new + { + Id = 6, + Content = "Winter is comming", + IdCharacter = 6, + IdSource = 3, + IdUsersPropose = 1, + IsValid = true, + Langage = 0, + Likes = 11025 + }, + new + { + Id = 7, + Content = "Je suis la dernière Targaryen. Je suis la reine des dragons", + IdCharacter = 7, + IdSource = 3, + IdUsersPropose = 1, + IsValid = true, + Langage = 1, + Likes = 11025 + }, + new + { + Id = 8, + Content = "Je ne suis pas prêt à affronter ça. C'est trop pour moi.", + IdCharacter = 8, + IdSource = 5, + IdUsersPropose = 1, + IsValid = true, + Langage = 1, + Likes = 11025 + }, + new + { + Id = 9, + Content = "Aidez-moi, Obi-Wan Kenobi, vous êtes mon seul espoir.", + IdCharacter = 9, + IdSource = 5, + IdUsersPropose = 1, + IsValid = true, + Langage = 1, + Likes = 11025 + }, + new + { + Id = 10, + Content = "La quoi ?", + IdCharacter = 10, + IdSource = 4, + IdUsersPropose = 1, + IsValid = false, + Langage = 1, + Likes = 11025 + }); + }); + + modelBuilder.Entity("Entity.Source", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("Title") + .IsRequired() + .HasMaxLength(100) + .HasColumnType("nvarchar(100)"); + + b.Property("TypeSrc") + .HasColumnType("int"); + + b.Property("Year") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.ToTable("sources"); + + b.HasData( + new + { + Id = 1, + Title = "Jurassic Park", + TypeSrc = 0, + Year = 1993 + }, + new + { + Id = 2, + Title = "Le Seigneur des anneaux : La Communauté de l'anneau", + TypeSrc = 0, + Year = 2001 + }, + new + { + Id = 3, + Title = "Game of throne", + TypeSrc = 1, + Year = 2011 + }, + new + { + Id = 4, + Title = "Harry Potter à l'école des sorcier", + TypeSrc = 0, + Year = 1997 + }, + new + { + Id = 5, + Title = "Star Wars, épisode IV : Un nouvel espoir", + TypeSrc = 0, + Year = 1977 + }); + }); + + modelBuilder.Entity("Entity.Users", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("Created") + .HasColumnType("date") + .HasColumnName("Created"); + + b.Property("Email") + .IsRequired() + .HasMaxLength(50) + .HasColumnType("nvarchar(50)"); + + b.Property("IdImage") + .HasColumnType("int"); + + b.Property("Password") + .IsRequired() + .HasMaxLength(200) + .HasColumnType("nvarchar(200)"); + + b.Property("UserName") + .IsRequired() + .HasMaxLength(50) + .HasColumnType("nvarchar(50)"); + + b.HasKey("Id"); + + b.HasIndex("IdImage"); + + b.ToTable("users"); + + b.HasData( + new + { + Id = 1, + Created = new DateTime(2025, 5, 12, 0, 0, 0, 0, DateTimeKind.Unspecified), + Email = "jhonDhoe@gmail.com", + IdImage = 1, + Password = "1234", + UserName = "Jhon-Dhoe" + }, + new + { + Id = 2, + Created = new DateTime(2025, 3, 19, 0, 0, 0, 0, DateTimeKind.Unspecified), + Email = "lucy_rose@outlook.com", + IdImage = 2, + Password = "abcd", + UserName = "Lucy-Rose" + }, + new + { + Id = 3, + Created = new DateTime(2024, 11, 2, 0, 0, 0, 0, DateTimeKind.Unspecified), + Email = "mark.taylor@yahoo.com", + IdImage = 3, + Password = "5678", + UserName = "Mark-Taylor" + }, + new + { + Id = 4, + Created = new DateTime(2025, 2, 28, 0, 0, 0, 0, DateTimeKind.Unspecified), + Email = "sophie.martin@gmail.com", + IdImage = 4, + Password = "4321", + UserName = "Sophie-Martin" + }, + new + { + Id = 5, + Created = new DateTime(2025, 1, 15, 0, 0, 0, 0, DateTimeKind.Unspecified), + Email = "nathan_doe@aol.com", + IdImage = 5, + Password = "8765", + UserName = "Nathan-Doe" + }, + new + { + Id = 6, + Created = new DateTime(2025, 4, 7, 0, 0, 0, 0, DateTimeKind.Unspecified), + Email = "ella.brown@icloud.com", + IdImage = 6, + Password = "2468", + UserName = "Ella-Brown" + }, + new + { + Id = 7, + Created = new DateTime(2024, 12, 25, 0, 0, 0, 0, DateTimeKind.Unspecified), + Email = "oliver_smith@gmail.com", + IdImage = 7, + Password = "1357", + UserName = "Oliver-Smith" + }, + new + { + Id = 8, + Created = new DateTime(2025, 3, 5, 0, 0, 0, 0, DateTimeKind.Unspecified), + Email = "mia.jones@outlook.com", + IdImage = 8, + Password = "1122", + UserName = "Mia-Jones" + }, + new + { + Id = 9, + Created = new DateTime(2025, 2, 22, 0, 0, 0, 0, DateTimeKind.Unspecified), + Email = "kevin_williams@aol.com", + IdImage = 9, + Password = "2233", + UserName = "Kevin-Williams" + }, + new + { + Id = 10, + Created = new DateTime(2025, 1, 3, 0, 0, 0, 0, DateTimeKind.Unspecified), + Email = "olivia.white@yahoo.com", + IdImage = 10, + Password = "3344", + UserName = "Olivia-White" + }); + }); + + modelBuilder.Entity("Entity.Admin", b => + { + b.HasOne("Entity.Users", "User") + .WithMany() + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("User"); + }); + + modelBuilder.Entity("Entity.Character", b => + { + b.HasOne("Entity.Images", "Images") + .WithMany("Characters") + .HasForeignKey("IdImage") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Images"); + }); + + modelBuilder.Entity("Entity.Commentary", b => + { + b.HasOne("Entity.Quote", "Quote") + .WithMany("Commentarys") + .HasForeignKey("IdQuote") + .OnDelete(DeleteBehavior.ClientCascade) + .IsRequired(); + + b.HasOne("Entity.Users", "User") + .WithMany() + .HasForeignKey("IdUser") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Quote"); + + b.Navigation("User"); + }); + + modelBuilder.Entity("Entity.Favorite", b => + { + b.HasOne("Entity.Quote", "Quote") + .WithMany() + .HasForeignKey("IdQuote") + .OnDelete(DeleteBehavior.ClientCascade) + .IsRequired(); + + b.HasOne("Entity.Users", "Users") + .WithMany() + .HasForeignKey("IdUsers") + .OnDelete(DeleteBehavior.ClientCascade) + .IsRequired(); + + b.Navigation("Quote"); + + b.Navigation("Users"); + }); + + modelBuilder.Entity("Entity.Quiz", b => + { + b.HasOne("Entity.Images", "Images") + .WithMany("Quizs") + .HasForeignKey("IdImage") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Images"); + }); + + modelBuilder.Entity("Entity.QuizQuestion", b => + { + b.HasOne("Entity.Question", null) + .WithMany() + .HasForeignKey("IdQuestion") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("Entity.Quiz", null) + .WithMany() + .HasForeignKey("IdQuiz") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("Entity.Quote", b => + { + b.HasOne("Entity.Character", "Character") + .WithMany("Quotes") + .HasForeignKey("IdCharacter") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("Entity.Source", "Source") + .WithMany("Quotes") + .HasForeignKey("IdSource") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("Entity.Users", "User") + .WithMany("Quotes") + .HasForeignKey("IdUsersPropose"); + + b.Navigation("Character"); + + b.Navigation("Source"); + + b.Navigation("User"); + }); + + modelBuilder.Entity("Entity.Users", b => + { + b.HasOne("Entity.Images", "Images") + .WithMany("Users") + .HasForeignKey("IdImage") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Images"); + }); + + modelBuilder.Entity("Entity.Character", b => + { + b.Navigation("Quotes"); + }); + + modelBuilder.Entity("Entity.Images", b => + { + b.Navigation("Characters"); + + b.Navigation("Quizs"); + + b.Navigation("Users"); + }); + + modelBuilder.Entity("Entity.Quote", b => + { + b.Navigation("Commentarys"); + }); + + modelBuilder.Entity("Entity.Source", b => + { + b.Navigation("Quotes"); + }); + + modelBuilder.Entity("Entity.Users", b => + { + b.Navigation("Quotes"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/WF_EF_Api/StubbedContextLib/Migrations/20250401141906_suprDailyQuote.cs b/WF_EF_Api/StubbedContextLib/Migrations/20250401141906_suprDailyQuote.cs new file mode 100644 index 0000000..1f3b252 --- /dev/null +++ b/WF_EF_Api/StubbedContextLib/Migrations/20250401141906_suprDailyQuote.cs @@ -0,0 +1,61 @@ +using Microsoft.EntityFrameworkCore.Migrations; + +#nullable disable + +namespace StubbedContextLib.Migrations +{ + /// + public partial class suprDailyQuote : Migration + { + /// + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropTable( + name: "dailyquotes"); + + migrationBuilder.UpdateData( + table: "quotes", + keyColumn: "Id", + keyValue: 10, + column: "IsValid", + value: false); + } + + /// + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.CreateTable( + name: "dailyquotes", + columns: table => new + { + IdQuote = table.Column(type: "int", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_dailyquotes", x => x.IdQuote); + table.ForeignKey( + name: "FK_dailyquotes_quotes_IdQuote", + column: x => x.IdQuote, + principalTable: "quotes", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.InsertData( + table: "dailyquotes", + column: "IdQuote", + values: new object[] + { + 1, + 5 + }); + + migrationBuilder.UpdateData( + table: "quotes", + keyColumn: "Id", + keyValue: 10, + column: "IsValid", + value: true); + } + } +} diff --git a/WF_EF_Api/StubbedContextLib/Migrations/StubWTFContextModelSnapshot.cs b/WF_EF_Api/StubbedContextLib/Migrations/StubWTFContextModelSnapshot.cs index f07d603..37b2e66 100644 --- a/WF_EF_Api/StubbedContextLib/Migrations/StubWTFContextModelSnapshot.cs +++ b/WF_EF_Api/StubbedContextLib/Migrations/StubWTFContextModelSnapshot.cs @@ -173,26 +173,6 @@ namespace StubbedContextLib.Migrations }); }); - modelBuilder.Entity("Entity.DailyQuote", b => - { - b.Property("IdQuote") - .HasColumnType("int"); - - b.HasKey("IdQuote"); - - b.ToTable("dailyquotes"); - - b.HasData( - new - { - IdQuote = 1 - }, - new - { - IdQuote = 5 - }); - }); - modelBuilder.Entity("Entity.Favorite", b => { b.Property("IdQuote") @@ -739,7 +719,7 @@ namespace StubbedContextLib.Migrations IdCharacter = 10, IdSource = 4, IdUsersPropose = 1, - IsValid = true, + IsValid = false, Langage = 1, Likes = 11025 }); @@ -976,17 +956,6 @@ namespace StubbedContextLib.Migrations b.Navigation("User"); }); - modelBuilder.Entity("Entity.DailyQuote", b => - { - b.HasOne("Entity.Quote", "Quote") - .WithMany("DailyQuotes") - .HasForeignKey("IdQuote") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.Navigation("Quote"); - }); - modelBuilder.Entity("Entity.Favorite", b => { b.HasOne("Entity.Quote", "Quote") @@ -1085,8 +1054,6 @@ namespace StubbedContextLib.Migrations modelBuilder.Entity("Entity.Quote", b => { b.Navigation("Commentarys"); - - b.Navigation("DailyQuotes"); }); modelBuilder.Entity("Entity.Source", b => diff --git a/WF_EF_Api/StubbedContextLib/StubWTFContext.cs b/WF_EF_Api/StubbedContextLib/StubWTFContext.cs index 677e88e..864c6af 100644 --- a/WF_EF_Api/StubbedContextLib/StubWTFContext.cs +++ b/WF_EF_Api/StubbedContextLib/StubWTFContext.cs @@ -77,10 +77,6 @@ namespace StubbedContextLib new Commentary() { Id = 2, Comment = "Very good", DateCommentary = new DateTime(2025, 3, 11), IdQuote = 1, IdUser = 3 } ); - modelBuilder.Entity().HasData( - new DailyQuote() { IdQuote = 1}, - new DailyQuote() { IdQuote = 5} - ); modelBuilder.Entity().HasData( new Favorite() { IdQuote = 2, IdUsers = 8 }, diff --git a/WF_EF_Api/WfApi/Controllers/QuotesController.cs b/WF_EF_Api/WfApi/Controllers/QuotesController.cs index 521a2a2..de062f0 100644 --- a/WF_EF_Api/WfApi/Controllers/QuotesController.cs +++ b/WF_EF_Api/WfApi/Controllers/QuotesController.cs @@ -196,7 +196,7 @@ namespace WfApi.Controllers return StatusCode((int)HttpStatusCode.InternalServerError, new { message = "Internal Server Error" }); } } - [HttpGet("searchByCharac")] + [HttpGet("searchBySource")] [ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status204NoContent)] [ProducesResponseType(StatusCodes.Status500InternalServerError)] diff --git a/WF_EF_Api/WfApi/Program.cs b/WF_EF_Api/WfApi/Program.cs index 5d57fb9..f4dd552 100644 --- a/WF_EF_Api/WfApi/Program.cs +++ b/WF_EF_Api/WfApi/Program.cs @@ -5,6 +5,7 @@ using Contextlib; using Entity; using StubbedContextLib; using ServicesApi; +using Microsoft.EntityFrameworkCore; //API var builder = WebApplication.CreateBuilder(args); @@ -14,7 +15,7 @@ builder.Services.AddScoped, QuoteService>(); builder.Services.AddScoped, CommentaryService>(); builder.Services.AddScoped, CharacterService>(); builder.Services.AddScoped, ImageService>(); -builder.Services.AddScoped, SourceService>(); +//builder.Services.AddScoped, SourceService>(); builder.Services.AddScoped, QuestionService>(); @@ -27,8 +28,8 @@ builder.Services.AddScoped, DbQuoteManager>(); builder.Services.AddScoped, DbCommentaryManager>(); builder.Services.AddScoped, DbCharacterManager>(); builder.Services.AddScoped, DbImagesManager>(); -builder.Services.AddScoped, SourceService>(); -builder.Services.AddScoped, QuestionService>(); +//builder.Services.AddScoped, DbSourceManager>(); +builder.Services.AddScoped, DbQuestionManager>(); //... // Add services to the container. From 42face1ba21dd88147e02fd6f9decbb94fad3a22 Mon Sep 17 00:00:00 2001 From: Kevin MONDEJAR Date: Tue, 1 Apr 2025 17:22:39 +0200 Subject: [PATCH 49/65] mise en fonction de certaine routes --- WF_EF_Api/Contextlib/DbQuoteManager.cs | 38 +- WF_EF_Api/Dto2Entities/Extention.cs | 3 +- ...0250401143030_myFirstMigration.Designer.cs | 1107 +++++++++++++++++ .../20250401143030_myFirstMigration.cs | 32 + .../Migrations/StubWTFContextModelSnapshot.cs | 2 +- .../WfApi/Controllers/QuotesController.cs | 1 + WF_EF_Api/WfApi/Program.cs | 8 +- 7 files changed, 1176 insertions(+), 15 deletions(-) create mode 100644 WF_EF_Api/StubbedContextLib/Migrations/20250401143030_myFirstMigration.Designer.cs create mode 100644 WF_EF_Api/StubbedContextLib/Migrations/20250401143030_myFirstMigration.cs diff --git a/WF_EF_Api/Contextlib/DbQuoteManager.cs b/WF_EF_Api/Contextlib/DbQuoteManager.cs index 24915ce..57bac38 100644 --- a/WF_EF_Api/Contextlib/DbQuoteManager.cs +++ b/WF_EF_Api/Contextlib/DbQuoteManager.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using System.Linq; +using System.Security.Cryptography; using System.Text; using System.Threading.Tasks; using Entity; @@ -42,18 +43,24 @@ namespace Contextlib public async Task> GetAllQuoteLang(int index, int pageSize, int lang) { - List quotes = _context.quotes.Where(item => item.IsValid && item.Langage == (LangEnum)lang) + List quotes = await _context.quotes.Where(item => item.IsValid && item.Langage == (LangEnum)lang) .Include(q => q.Source).Include(q => q.Character).ThenInclude(c => c.Images) - .Skip(index * pageSize).Take(pageSize).ToList(); + .Skip(index * pageSize).Take(pageSize).ToListAsync(); return new PaginationResult(quotes.Count, index, pageSize, quotes); } public async Task GetDailyQuote(DateOnly date, int lang) { - List quotes = _context.quotes.Where(item => item.IsValid && item.Langage == (LangEnum)lang) + List quotes = await _context.quotes.Where(item => item.IsValid && item.Langage == (LangEnum)lang) .Include(q => q.Source).Include(q => q.Character).ThenInclude(c => c.Images).Include(q => q.Favorite) - .ToList(); - Quote quote = _repo.GetById(date.DayNumber % quotes.Count()) ?? quotes.First(); + .ToListAsync(); + + Quote quote = quotes[date.DayNumber % quotes.Count()]; + /*Quote quote = await _context.quotes.Where(item => item.Id == date.DayNumber % quotes.Count()) + .Include(q => q.Source).Include(q => q.Character).ThenInclude(c => c.Images).Include(q => q.Favorite) + .FirstOrDefaultAsync() ?? quotes.First();*/ + + //Quote quote = _repo.GetById(date.DayNumber % quotes.Count()) ?? quotes.First(); return quote; } @@ -113,17 +120,29 @@ namespace Contextlib public async Task> GetSomeQuote(int index, int pageSize) { - throw new NotImplementedException(); + List quotes = _context.quotes.Where(item => item.IsValid) + .Include(q => q.Source).Include(q => q.Character).ThenInclude(c => c.Images) + .Skip(index * pageSize).Take(pageSize).ToList(); + + return new PaginationResult(quotes.Count, index, pageSize, quotes); } public async Task> GetSuggestions(int index, int pageSize, int lang) { - throw new NotImplementedException(); + List quotes = _context.quotes.Where(item => item.IsValid && item.Langage == (LangEnum)lang) + .Include(q => q.Source).Include(q => q.Character).ThenInclude(c => c.Images) // rajouter un mélange random + .Skip(index * pageSize).Take(pageSize).ToList(); + + return new PaginationResult(quotes.Count, index, pageSize, quotes); } public async Task> GetValidQuote(int index, int pageSize) { - throw new NotImplementedException(); + List quotes = _context.quotes.Where(item => item.IsValid) + .Include(q => q.Source).Include(q => q.Character).ThenInclude(c => c.Images) + .Skip(index * pageSize).Take(pageSize).ToList(); + + return new PaginationResult(quotes.Count, index, pageSize, quotes); } @@ -132,7 +151,8 @@ namespace Contextlib public async Task RemoveQuote(int quoteId) { - throw new NotImplementedException(); + _repo.Delete(quoteId); + await _context.SaveChangesAsync(); } public async Task> SearchByCharacter(string character, int index, int pageSize, int lang) diff --git a/WF_EF_Api/Dto2Entities/Extention.cs b/WF_EF_Api/Dto2Entities/Extention.cs index 5d7d85f..4697a74 100644 --- a/WF_EF_Api/Dto2Entities/Extention.cs +++ b/WF_EF_Api/Dto2Entities/Extention.cs @@ -164,6 +164,7 @@ namespace Dto2Entities quote.ImagePath = item.Character.Images.ImgPath; quote.Like = item.Likes; quote.Type = item.Source.TypeSrc.ToDto(); + quote.IsValide = item.IsValid; return quote; } @@ -473,4 +474,4 @@ namespace Dto2Entities } } } -} +} \ No newline at end of file diff --git a/WF_EF_Api/StubbedContextLib/Migrations/20250401143030_myFirstMigration.Designer.cs b/WF_EF_Api/StubbedContextLib/Migrations/20250401143030_myFirstMigration.Designer.cs new file mode 100644 index 0000000..de2bfe4 --- /dev/null +++ b/WF_EF_Api/StubbedContextLib/Migrations/20250401143030_myFirstMigration.Designer.cs @@ -0,0 +1,1107 @@ +// +using System; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Metadata; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; +using StubbedContextLib; + +#nullable disable + +namespace StubbedContextLib.Migrations +{ + [DbContext(typeof(StubWTFContext))] + [Migration("20250401143030_myFirstMigration")] + partial class myFirstMigration + { + /// + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("ProductVersion", "9.0.3") + .HasAnnotation("Relational:MaxIdentifierLength", 128); + + SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder); + + modelBuilder.Entity("Entity.Admin", b => + { + b.Property("IdUsers") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("IdUsers")); + + b.Property("UserId") + .HasColumnType("int"); + + b.HasKey("IdUsers"); + + b.HasIndex("UserId"); + + b.ToTable("admins"); + }); + + modelBuilder.Entity("Entity.Character", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("IdImage") + .HasColumnType("int"); + + b.Property("Name") + .IsRequired() + .HasMaxLength(50) + .HasColumnType("nvarchar(50)"); + + b.HasKey("Id"); + + b.HasIndex("IdImage"); + + b.ToTable("characters"); + + b.HasData( + new + { + Id = 1, + IdImage = 1, + Name = "Alan Grant" + }, + new + { + Id = 2, + IdImage = 2, + Name = "Aragorn" + }, + new + { + Id = 3, + IdImage = 3, + Name = "Legolas" + }, + new + { + Id = 4, + IdImage = 4, + Name = "Frodon" + }, + new + { + Id = 5, + IdImage = 5, + Name = "Dobby" + }, + new + { + Id = 6, + IdImage = 6, + Name = "Jon Snow" + }, + new + { + Id = 7, + IdImage = 7, + Name = "Daenerys Targaryen" + }, + new + { + Id = 8, + IdImage = 8, + Name = "Luke Skywalker" + }, + new + { + Id = 9, + IdImage = 9, + Name = "Princess Leia" + }, + new + { + Id = 10, + IdImage = 10, + Name = "Harry Potter" + }); + }); + + modelBuilder.Entity("Entity.Commentary", b => + { + b.Property("IdUser") + .HasColumnType("int"); + + b.Property("IdQuote") + .HasColumnType("int"); + + b.Property("Comment") + .IsRequired() + .HasMaxLength(100) + .HasColumnType("nvarchar(100)"); + + b.Property("DateCommentary") + .HasColumnType("date") + .HasColumnName("DateCommentary"); + + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.HasKey("IdUser", "IdQuote"); + + b.HasIndex("IdQuote"); + + b.ToTable("comments"); + + b.HasData( + new + { + IdUser = 2, + IdQuote = 1, + Comment = "Ce film est le meilleur", + DateCommentary = new DateTime(2025, 2, 3, 0, 0, 0, 0, DateTimeKind.Unspecified), + Id = 1 + }, + new + { + IdUser = 3, + IdQuote = 1, + Comment = "Very good", + DateCommentary = new DateTime(2025, 3, 11, 0, 0, 0, 0, DateTimeKind.Unspecified), + Id = 2 + }); + }); + + modelBuilder.Entity("Entity.DailyQuote", b => + { + b.Property("IdQuote") + .HasColumnType("int"); + + b.HasKey("IdQuote"); + + b.ToTable("dailyquotes"); + + b.HasData( + new + { + IdQuote = 1 + }, + new + { + IdQuote = 5 + }); + }); + + modelBuilder.Entity("Entity.Favorite", b => + { + b.Property("IdQuote") + .HasColumnType("int"); + + b.Property("IdUsers") + .HasColumnType("int"); + + b.HasKey("IdQuote", "IdUsers"); + + b.HasIndex("IdUsers"); + + b.ToTable("favorites"); + + b.HasData( + new + { + IdQuote = 2, + IdUsers = 8 + }, + new + { + IdQuote = 5, + IdUsers = 3 + }, + new + { + IdQuote = 9, + IdUsers = 1 + }, + new + { + IdQuote = 4, + IdUsers = 10 + }, + new + { + IdQuote = 3, + IdUsers = 2 + }, + new + { + IdQuote = 6, + IdUsers = 7 + }, + new + { + IdQuote = 1, + IdUsers = 6 + }, + new + { + IdQuote = 8, + IdUsers = 9 + }, + new + { + IdQuote = 10, + IdUsers = 5 + }); + }); + + modelBuilder.Entity("Entity.Images", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("ImgPath") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.HasKey("Id"); + + b.ToTable("images"); + + b.HasData( + new + { + Id = 1, + ImgPath = "https://th.bing.com/th/id/OIP.TJuWNCsibz8MVmhdNQEdMwHaE8?w=244&h=180&c=7&r=0&o=5&pid=1.7" + }, + new + { + Id = 2, + ImgPath = "https://th.bing.com/th/id/OIP.NgXRQ5-IknA6_qOPFhLWIwHaHK?w=165&h=180&c=7&r=0&o=5&pid=1.7" + }, + new + { + Id = 3, + ImgPath = "https://th.bing.com/th/id/OIP.XcJoJ6bC9sAMjol1pJn5UQHaLH?w=118&h=180&c=7&r=0&o=5&pid=1.7" + }, + new + { + Id = 4, + ImgPath = "https://th.bing.com/th/id/OIP.PPIESqZaNDa-qUcfSDXhdQHaGK?w=210&h=180&c=7&r=0&o=5&pid=1.7" + }, + new + { + Id = 5, + ImgPath = "https://th.bing.com/th/id/OIP.XBghSl2kfRNNtQoSxc901wHaHa?w=177&h=180&c=7&r=0&o=5&pid=1.7" + }, + new + { + Id = 6, + ImgPath = "https://th.bing.com/th/id/OIP.af1Aid64cqEKoIOBgCPxtQHaJO?w=145&h=182&c=7&r=0&o=5&pid=1.7" + }, + new + { + Id = 7, + ImgPath = "https://th.bing.com/th/id/OIP.ri5vSXr5lNTLt4DO6KQXyQHaI4?w=158&h=189&c=7&r=0&o=5&pid=1.7" + }, + new + { + Id = 8, + ImgPath = "https://th.bing.com/th/id/OIP.uPTRLR8uspCiafiunUqKfQHaMJ?w=115&h=180&c=7&r=0&o=5&pid=1.7" + }, + new + { + Id = 9, + ImgPath = "https://th.bing.com/th/id/OIP.hcJis4rKbyQtugsoFJU2ngHaM_?w=118&h=207&c=7&r=0&o=5&pid=1.7" + }, + new + { + Id = 10, + ImgPath = "https://th.bing.com/th/id/OIP.Py1_XfUrKJY_A6tYEmFS5wHaE8?w=280&h=187&c=7&r=0&o=5&pid=1.7" + }); + }); + + modelBuilder.Entity("Entity.Question", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("AnswerA") + .IsRequired() + .HasMaxLength(50) + .HasColumnType("nvarchar(50)"); + + b.Property("AnswerB") + .IsRequired() + .HasMaxLength(50) + .HasColumnType("nvarchar(50)"); + + b.Property("AnswerC") + .IsRequired() + .HasMaxLength(50) + .HasColumnType("nvarchar(50)"); + + b.Property("AnswerD") + .IsRequired() + .HasMaxLength(50) + .HasColumnType("nvarchar(50)"); + + b.Property("CorrectAnswer") + .IsRequired() + .HasMaxLength(1) + .HasColumnType("nvarchar(1)"); + + b.Property("IsValid") + .HasColumnType("bit"); + + b.Property("Text") + .IsRequired() + .HasMaxLength(200) + .HasColumnType("nvarchar(200)"); + + b.HasKey("Id"); + + b.ToTable("question"); + + b.HasData( + new + { + Id = 1, + AnswerA = "Gimli", + AnswerB = "Aragorn", + AnswerC = "Frodon", + AnswerD = "Gandalf", + CorrectAnswer = "B", + IsValid = true, + Text = "Qui est le leader de la Communauté de l'Anneau ?" + }, + new + { + Id = 2, + AnswerA = "Serdaigle", + AnswerB = "Gryffondor", + AnswerC = "Serpentard", + AnswerD = "Poufsouffle", + CorrectAnswer = "B", + IsValid = false, + Text = "Dans quelle maison Harry Potter est-il ?" + }, + new + { + Id = 3, + AnswerA = "Saroumane", + AnswerB = "Sauron", + AnswerC = "Gollum", + AnswerD = "Gothmog", + CorrectAnswer = "B", + IsValid = true, + Text = "Qui est le Seigneur des Ténèbres dans la saga Le Seigneur des Anneaux ?" + }, + new + { + Id = 4, + AnswerA = "Han Solo", + AnswerB = "Princesse Leia", + AnswerC = "Chewbacca", + AnswerD = "R2-D2", + CorrectAnswer = "A", + IsValid = true, + Text = "Dans le film Star Wars : Episode IV, qui sauve Luke Skywalker de l'Étoile de la Mort ?" + }, + new + { + Id = 5, + AnswerA = "Reine Jadis", + AnswerB = "Aslan", + AnswerC = "Edmund", + AnswerD = "Lucy", + CorrectAnswer = "B", + IsValid = true, + Text = "Qui est le souverain de Narnia dans Le Lion, la Sorcière Blanche et l'Armoire Magique ?" + }, + new + { + Id = 6, + AnswerA = "Smaug", + AnswerB = "Falkor", + AnswerC = "Norbert", + AnswerD = "Shenron", + CorrectAnswer = "A", + IsValid = true, + Text = "Quel est le nom du dragon dans Le Hobbit ?" + }, + new + { + Id = 7, + AnswerA = "Bella Swan", + AnswerB = "Edward Cullen", + AnswerC = "Jacob Black", + AnswerD = "Victoria", + CorrectAnswer = "A", + IsValid = true, + Text = "Qui est la première personne à être mordue par un vampire dans Twilight ?" + }, + new + { + Id = 8, + AnswerA = "Obi-Wan Kenobi", + AnswerB = "Yoda", + AnswerC = "Han Solo", + AnswerD = "Luke Skywalker", + CorrectAnswer = "A", + IsValid = true, + Text = "Quel personnage dit Que la Force soit avec toi dans Star Wars ?" + }, + new + { + Id = 9, + AnswerA = "Dr. Ellie Sattler", + AnswerB = "Alan Grant", + AnswerC = "John Hammond", + AnswerD = "Dennis Nedry", + CorrectAnswer = "B", + IsValid = true, + Text = "Dans Jurassic Park, quel est le nom du paléontologue sur l'île ?" + }, + new + { + Id = 10, + AnswerA = "Cersei Lannister", + AnswerB = "Arya Stark", + AnswerC = "Daenerys Targaryen", + AnswerD = "Sansa Stark", + CorrectAnswer = "C", + IsValid = true, + Text = "Dans Game of Thrones, qui est surnommée la Mère des Dragons ?" + }); + }); + + modelBuilder.Entity("Entity.Quiz", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("IdImage") + .HasColumnType("int"); + + b.Property("NbQuestion") + .HasColumnType("int"); + + b.Property("Title") + .IsRequired() + .HasMaxLength(50) + .HasColumnType("nvarchar(50)"); + + b.HasKey("Id"); + + b.HasIndex("IdImage"); + + b.ToTable("quizzes"); + + b.HasData( + new + { + Id = 1, + IdImage = 1, + NbQuestion = 5, + Title = "Quiz 1" + }, + new + { + Id = 2, + IdImage = 2, + NbQuestion = 5, + Title = "Quiz 2" + }); + }); + + modelBuilder.Entity("Entity.QuizQuestion", b => + { + b.Property("IdQuestion") + .HasColumnType("int"); + + b.Property("IdQuiz") + .HasColumnType("int"); + + b.HasKey("IdQuestion", "IdQuiz"); + + b.HasIndex("IdQuiz"); + + b.ToTable("QuizQuestion"); + + b.HasData( + new + { + IdQuestion = 1, + IdQuiz = 1 + }, + new + { + IdQuestion = 2, + IdQuiz = 1 + }, + new + { + IdQuestion = 3, + IdQuiz = 1 + }, + new + { + IdQuestion = 4, + IdQuiz = 1 + }, + new + { + IdQuestion = 5, + IdQuiz = 1 + }, + new + { + IdQuestion = 6, + IdQuiz = 2 + }, + new + { + IdQuestion = 7, + IdQuiz = 2 + }, + new + { + IdQuestion = 8, + IdQuiz = 2 + }, + new + { + IdQuestion = 9, + IdQuiz = 2 + }, + new + { + IdQuestion = 10, + IdQuiz = 2 + }); + }); + + modelBuilder.Entity("Entity.Quote", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("Content") + .IsRequired() + .HasMaxLength(100) + .HasColumnType("nvarchar(100)"); + + b.Property("IdCharacter") + .HasColumnType("int"); + + b.Property("IdSource") + .HasColumnType("int"); + + b.Property("IdUsersPropose") + .HasColumnType("int"); + + b.Property("IsValid") + .HasColumnType("bit"); + + b.Property("Langage") + .HasColumnType("int"); + + b.Property("Likes") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.HasIndex("IdCharacter"); + + b.HasIndex("IdSource"); + + b.HasIndex("IdUsersPropose"); + + b.ToTable("quotes"); + + b.HasData( + new + { + Id = 1, + Content = "Je n'y crois pas. Je n'y crois pas. Ce n'est pas possible", + IdCharacter = 1, + IdSource = 1, + IdUsersPropose = 1, + IsValid = true, + Langage = 1, + Likes = 11025 + }, + new + { + Id = 2, + Content = "There is always hope", + IdCharacter = 2, + IdSource = 2, + IdUsersPropose = 1, + IsValid = true, + Langage = 0, + Likes = 11025 + }, + new + { + Id = 3, + Content = "A red sun rises. Blood has been spilled this night.", + IdCharacter = 3, + IdSource = 2, + IdUsersPropose = 1, + IsValid = true, + Langage = 0, + Likes = 11025 + }, + new + { + Id = 4, + Content = "I wish the Ring had never come to me.I wish none of this had happened.", + IdCharacter = 4, + IdSource = 2, + IdUsersPropose = 1, + IsValid = true, + Langage = 0, + Likes = 11025 + }, + new + { + Id = 5, + Content = "Dobby is a free elf!", + IdCharacter = 5, + IdSource = 4, + IdUsersPropose = 1, + IsValid = true, + Langage = 0, + Likes = 11025 + }, + new + { + Id = 6, + Content = "Winter is comming", + IdCharacter = 6, + IdSource = 3, + IdUsersPropose = 1, + IsValid = true, + Langage = 0, + Likes = 11025 + }, + new + { + Id = 7, + Content = "Je suis la dernière Targaryen. Je suis la reine des dragons", + IdCharacter = 7, + IdSource = 3, + IdUsersPropose = 1, + IsValid = true, + Langage = 1, + Likes = 11025 + }, + new + { + Id = 8, + Content = "Je ne suis pas prêt à affronter ça. C'est trop pour moi.", + IdCharacter = 8, + IdSource = 5, + IdUsersPropose = 1, + IsValid = true, + Langage = 1, + Likes = 11025 + }, + new + { + Id = 9, + Content = "Aidez-moi, Obi-Wan Kenobi, vous êtes mon seul espoir.", + IdCharacter = 9, + IdSource = 5, + IdUsersPropose = 1, + IsValid = true, + Langage = 1, + Likes = 11025 + }, + new + { + Id = 10, + Content = "La quoi ?", + IdCharacter = 10, + IdSource = 4, + IdUsersPropose = 1, + IsValid = false, + Langage = 1, + Likes = 11025 + }); + }); + + modelBuilder.Entity("Entity.Source", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("Title") + .IsRequired() + .HasMaxLength(100) + .HasColumnType("nvarchar(100)"); + + b.Property("TypeSrc") + .HasColumnType("int"); + + b.Property("Year") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.ToTable("sources"); + + b.HasData( + new + { + Id = 1, + Title = "Jurassic Park", + TypeSrc = 0, + Year = 1993 + }, + new + { + Id = 2, + Title = "Le Seigneur des anneaux : La Communauté de l'anneau", + TypeSrc = 0, + Year = 2001 + }, + new + { + Id = 3, + Title = "Game of throne", + TypeSrc = 1, + Year = 2011 + }, + new + { + Id = 4, + Title = "Harry Potter à l'école des sorcier", + TypeSrc = 0, + Year = 1997 + }, + new + { + Id = 5, + Title = "Star Wars, épisode IV : Un nouvel espoir", + TypeSrc = 0, + Year = 1977 + }); + }); + + modelBuilder.Entity("Entity.Users", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("Created") + .HasColumnType("date") + .HasColumnName("Created"); + + b.Property("Email") + .IsRequired() + .HasMaxLength(50) + .HasColumnType("nvarchar(50)"); + + b.Property("IdImage") + .HasColumnType("int"); + + b.Property("Password") + .IsRequired() + .HasMaxLength(200) + .HasColumnType("nvarchar(200)"); + + b.Property("UserName") + .IsRequired() + .HasMaxLength(50) + .HasColumnType("nvarchar(50)"); + + b.HasKey("Id"); + + b.HasIndex("IdImage"); + + b.ToTable("users"); + + b.HasData( + new + { + Id = 1, + Created = new DateTime(2025, 5, 12, 0, 0, 0, 0, DateTimeKind.Unspecified), + Email = "jhonDhoe@gmail.com", + IdImage = 1, + Password = "1234", + UserName = "Jhon-Dhoe" + }, + new + { + Id = 2, + Created = new DateTime(2025, 3, 19, 0, 0, 0, 0, DateTimeKind.Unspecified), + Email = "lucy_rose@outlook.com", + IdImage = 2, + Password = "abcd", + UserName = "Lucy-Rose" + }, + new + { + Id = 3, + Created = new DateTime(2024, 11, 2, 0, 0, 0, 0, DateTimeKind.Unspecified), + Email = "mark.taylor@yahoo.com", + IdImage = 3, + Password = "5678", + UserName = "Mark-Taylor" + }, + new + { + Id = 4, + Created = new DateTime(2025, 2, 28, 0, 0, 0, 0, DateTimeKind.Unspecified), + Email = "sophie.martin@gmail.com", + IdImage = 4, + Password = "4321", + UserName = "Sophie-Martin" + }, + new + { + Id = 5, + Created = new DateTime(2025, 1, 15, 0, 0, 0, 0, DateTimeKind.Unspecified), + Email = "nathan_doe@aol.com", + IdImage = 5, + Password = "8765", + UserName = "Nathan-Doe" + }, + new + { + Id = 6, + Created = new DateTime(2025, 4, 7, 0, 0, 0, 0, DateTimeKind.Unspecified), + Email = "ella.brown@icloud.com", + IdImage = 6, + Password = "2468", + UserName = "Ella-Brown" + }, + new + { + Id = 7, + Created = new DateTime(2024, 12, 25, 0, 0, 0, 0, DateTimeKind.Unspecified), + Email = "oliver_smith@gmail.com", + IdImage = 7, + Password = "1357", + UserName = "Oliver-Smith" + }, + new + { + Id = 8, + Created = new DateTime(2025, 3, 5, 0, 0, 0, 0, DateTimeKind.Unspecified), + Email = "mia.jones@outlook.com", + IdImage = 8, + Password = "1122", + UserName = "Mia-Jones" + }, + new + { + Id = 9, + Created = new DateTime(2025, 2, 22, 0, 0, 0, 0, DateTimeKind.Unspecified), + Email = "kevin_williams@aol.com", + IdImage = 9, + Password = "2233", + UserName = "Kevin-Williams" + }, + new + { + Id = 10, + Created = new DateTime(2025, 1, 3, 0, 0, 0, 0, DateTimeKind.Unspecified), + Email = "olivia.white@yahoo.com", + IdImage = 10, + Password = "3344", + UserName = "Olivia-White" + }); + }); + + modelBuilder.Entity("Entity.Admin", b => + { + b.HasOne("Entity.Users", "User") + .WithMany() + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("User"); + }); + + modelBuilder.Entity("Entity.Character", b => + { + b.HasOne("Entity.Images", "Images") + .WithMany("Characters") + .HasForeignKey("IdImage") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Images"); + }); + + modelBuilder.Entity("Entity.Commentary", b => + { + b.HasOne("Entity.Quote", "Quote") + .WithMany("Commentarys") + .HasForeignKey("IdQuote") + .OnDelete(DeleteBehavior.ClientCascade) + .IsRequired(); + + b.HasOne("Entity.Users", "User") + .WithMany() + .HasForeignKey("IdUser") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Quote"); + + b.Navigation("User"); + }); + + modelBuilder.Entity("Entity.DailyQuote", b => + { + b.HasOne("Entity.Quote", "Quote") + .WithMany("DailyQuotes") + .HasForeignKey("IdQuote") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Quote"); + }); + + modelBuilder.Entity("Entity.Favorite", b => + { + b.HasOne("Entity.Quote", "Quote") + .WithMany() + .HasForeignKey("IdQuote") + .OnDelete(DeleteBehavior.ClientCascade) + .IsRequired(); + + b.HasOne("Entity.Users", "Users") + .WithMany() + .HasForeignKey("IdUsers") + .OnDelete(DeleteBehavior.ClientCascade) + .IsRequired(); + + b.Navigation("Quote"); + + b.Navigation("Users"); + }); + + modelBuilder.Entity("Entity.Quiz", b => + { + b.HasOne("Entity.Images", "Images") + .WithMany("Quizs") + .HasForeignKey("IdImage") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Images"); + }); + + modelBuilder.Entity("Entity.QuizQuestion", b => + { + b.HasOne("Entity.Question", null) + .WithMany() + .HasForeignKey("IdQuestion") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("Entity.Quiz", null) + .WithMany() + .HasForeignKey("IdQuiz") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("Entity.Quote", b => + { + b.HasOne("Entity.Character", "Character") + .WithMany("Quotes") + .HasForeignKey("IdCharacter") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("Entity.Source", "Source") + .WithMany("Quotes") + .HasForeignKey("IdSource") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("Entity.Users", "User") + .WithMany("Quotes") + .HasForeignKey("IdUsersPropose"); + + b.Navigation("Character"); + + b.Navigation("Source"); + + b.Navigation("User"); + }); + + modelBuilder.Entity("Entity.Users", b => + { + b.HasOne("Entity.Images", "Images") + .WithMany("Users") + .HasForeignKey("IdImage") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Images"); + }); + + modelBuilder.Entity("Entity.Character", b => + { + b.Navigation("Quotes"); + }); + + modelBuilder.Entity("Entity.Images", b => + { + b.Navigation("Characters"); + + b.Navigation("Quizs"); + + b.Navigation("Users"); + }); + + modelBuilder.Entity("Entity.Quote", b => + { + b.Navigation("Commentarys"); + + b.Navigation("DailyQuotes"); + }); + + modelBuilder.Entity("Entity.Source", b => + { + b.Navigation("Quotes"); + }); + + modelBuilder.Entity("Entity.Users", b => + { + b.Navigation("Quotes"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/WF_EF_Api/StubbedContextLib/Migrations/20250401143030_myFirstMigration.cs b/WF_EF_Api/StubbedContextLib/Migrations/20250401143030_myFirstMigration.cs new file mode 100644 index 0000000..78898b5 --- /dev/null +++ b/WF_EF_Api/StubbedContextLib/Migrations/20250401143030_myFirstMigration.cs @@ -0,0 +1,32 @@ +using Microsoft.EntityFrameworkCore.Migrations; + +#nullable disable + +namespace StubbedContextLib.Migrations +{ + /// + public partial class myFirstMigration : Migration + { + /// + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.UpdateData( + table: "quotes", + keyColumn: "Id", + keyValue: 10, + column: "IsValid", + value: false); + } + + /// + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.UpdateData( + table: "quotes", + keyColumn: "Id", + keyValue: 10, + column: "IsValid", + value: true); + } + } +} diff --git a/WF_EF_Api/StubbedContextLib/Migrations/StubWTFContextModelSnapshot.cs b/WF_EF_Api/StubbedContextLib/Migrations/StubWTFContextModelSnapshot.cs index f07d603..12b5093 100644 --- a/WF_EF_Api/StubbedContextLib/Migrations/StubWTFContextModelSnapshot.cs +++ b/WF_EF_Api/StubbedContextLib/Migrations/StubWTFContextModelSnapshot.cs @@ -739,7 +739,7 @@ namespace StubbedContextLib.Migrations IdCharacter = 10, IdSource = 4, IdUsersPropose = 1, - IsValid = true, + IsValid = false, Langage = 1, Likes = 11025 }); diff --git a/WF_EF_Api/WfApi/Controllers/QuotesController.cs b/WF_EF_Api/WfApi/Controllers/QuotesController.cs index 521a2a2..312a723 100644 --- a/WF_EF_Api/WfApi/Controllers/QuotesController.cs +++ b/WF_EF_Api/WfApi/Controllers/QuotesController.cs @@ -87,6 +87,7 @@ namespace WfApi.Controllers if (result != null) { return await Task.FromResult(Ok(result)); + //return Ok(result)); } else { diff --git a/WF_EF_Api/WfApi/Program.cs b/WF_EF_Api/WfApi/Program.cs index 5d57fb9..9ad5afa 100644 --- a/WF_EF_Api/WfApi/Program.cs +++ b/WF_EF_Api/WfApi/Program.cs @@ -14,8 +14,8 @@ builder.Services.AddScoped, QuoteService>(); builder.Services.AddScoped, CommentaryService>(); builder.Services.AddScoped, CharacterService>(); builder.Services.AddScoped, ImageService>(); -builder.Services.AddScoped, SourceService>(); -builder.Services.AddScoped, QuestionService>(); +/*builder.Services.AddScoped, SourceService>(); +builder.Services.AddScoped, QuestionService>();*/ //EF @@ -27,8 +27,8 @@ builder.Services.AddScoped, DbQuoteManager>(); builder.Services.AddScoped, DbCommentaryManager>(); builder.Services.AddScoped, DbCharacterManager>(); builder.Services.AddScoped, DbImagesManager>(); -builder.Services.AddScoped, SourceService>(); -builder.Services.AddScoped, QuestionService>(); +/*builder.Services.AddScoped, SourceService>(); +builder.Services.AddScoped, QuestionService>();*/ //... // Add services to the container. From 48a15425c37425e532b6c8312510c55aea2dd8ee Mon Sep 17 00:00:00 2001 From: Kentin BRONGNIART Date: Wed, 2 Apr 2025 09:19:19 +0200 Subject: [PATCH 50/65] =?UTF-8?q?Mise=20=C3=A0=20jour=20de=20'README.md'?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 42 +++++++++++++++++++++--------------------- 1 file changed, 21 insertions(+), 21 deletions(-) diff --git a/README.md b/README.md index 22566f6..7cf3392 100644 --- a/README.md +++ b/README.md @@ -15,7 +15,7 @@ niveau | description | coeff | jalon | État ☢️ | un .gitignore doit exister au premier push | ☢️ | J1 | ✅ 🎬 | les *projets* et les tests compilent | 1 | J1 & J2 | ✅ 🎬 | le projet et le tests s'exécutent sans bug (concernant la partie persistance) | 3 | J1 & J2 | ✅ -🟢 | Transcription du modèle : Modèle vers entités (et inversement) | 2 | J1 | 🟨 +🟢 | Transcription du modèle : Modèle vers entités (et inversement) | 2 | J1 | ✅ 🟢 | Requêtes CRUD simples (sur une table) | 1 | J1 | ✅ 🟢 | Utilisation de LINQ to Entities | 2 | J1 | ✅ 🟡 | Injection / indépendance du fournisseur | 1 | J1 | ✅ @@ -24,8 +24,8 @@ niveau | description | coeff | jalon | État 🟢 | Tests - Tests unitaires (avec SQLite in memory) | 2 | J1 | ❌ 🟢 | Tests - Données stubbées et/ou Moq | 1 | J1 | ✅ 🟡 | CI : build, tests, Sonar (doc?) | 1 | J1 | ❌ -🟡 | Utilisation de relations (One-to-One, One-to-Many, Many-to-Many) (+ mapping, TU, Requêtes) | 4 | J1 | 🟨 -🟢 | Liens avec le web service | 2 | J1 | ❌ +🟡 | Utilisation de relations (One-to-One, One-to-Many, Many-to-Many) (+ mapping, TU, Requêtes) | 4 | J1 | ✅ +🟢 | Liens avec le web service | 2 | J1 | ✅ 🟡 | Utilisation d'un *Logger* | 1 | J1 | ❌ 🟡 | Déploiement | 4 | J2 | ❌ 🔴 | Unit of Work❌ / Repository✅ + extras (héritage, accès concurrents...) | 8 | J2 | 🟨 @@ -37,23 +37,23 @@ niveau | description | coeff | jalon | État niveau | description | coeff | jalon | État --- | --- | --- | --- | --- -☢️ | Le dépôt doit être accessible par l'enseignant | ☢️ | J1 | -☢️ | un .gitignore doit exister au premier push | ☢️ | J1 | -🎬 | les *projets* et les tests compilent | 1 | J1 & J2 | -🎬 | le projet et le tests s'exécutent sans bug (concernant la partie web api) | 4 | J1 & J2 | -🟢 | Modèle <-> DTO | 1 | J1 | -🟢 | Entities <-> DTO | 1 | J1 | 🟨 +☢️ | Le dépôt doit être accessible par l'enseignant | ☢️ | J1 | ✅ +☢️ | un .gitignore doit exister au premier push | ☢️ | J1 | ✅ +🎬 | les *projets* et les tests compilent | 1 | J1 & J2 | ✅ +🎬 | le projet et le tests s'exécutent sans bug (concernant la partie web api) | 4 | J1 & J2 | ✅ +🟢 | Modèle <-> DTO | 1 | J1 | ❌ +🟢 | Entities <-> DTO | 1 | J1 | ✅ 🟡 | Authentification | 4 | J1 | -🟢 | Requêtes GET, PUT, POST, DELETE sur des données simples (1 seul type d'objet en retour, propriétés de types natifs) | 2 | J1 | -🟡 | Pagination & filtrage | 2 | J1 | -🟢 | Injection de service | 2 | J1 | -🟡 | Requêtes GET, PUT, POST, DELETE sur des données complexes (plusieurs données complexes en retour) | 4 | J1 | -🟢 | Tests - Appli Console (consommation des requêtes) | 4 | J1 | -🟢 | Tests - Tests unitaires (avec Stub et/ou Moq) | 2 | J1 | -🟡 | CI : build, tests, Sonar, Documentation (en particulier Swagger avec exemples...) | 1 | J1 | -🟢 | Liens avec la persistance en base de données | 4 | J1 | -🟡 | Utilisation d'un *Logger* | 1 | J1 | -🟡 | Déploiement | 4 | J2 | -🟡 | Utilisation dans le projet | 4 | J2 | -🎬 | mon dépôt possède un readme qui apporte quelque chose... | 1 | J2 | +🟢 | Requêtes GET, PUT, POST, DELETE sur des données simples (1 seul type d'objet en retour, propriétés de types natifs) | 2 | J1 | ✅ +🟡 | Pagination & filtrage | 2 | J1 | ✅ +🟢 | Injection de service | 2 | J1 | ✅ +🟡 | Requêtes GET, PUT, POST, DELETE sur des données complexes (plusieurs données complexes en retour) | 4 | J1 | 🟨 +🟢 | Tests - Appli Console (consommation des requêtes) | 4 | J1 | 🟨 +🟢 | Tests - Tests unitaires (avec Stub et/ou Moq) | 2 | J1 | ❌ +🟡 | CI : build, tests, Sonar, Documentation (en particulier Swagger avec exemples...) | 1 | J1 | ❌ +🟢 | Liens avec la persistance en base de données | 4 | J1 | ✅ +🟡 | Utilisation d'un *Logger* | 1 | J1 | ❌ +🟡 | Déploiement | 4 | J2 | ❌ +🟡 | Utilisation dans le projet | 4 | J2 | ❌ +🎬 | mon dépôt possède un readme qui apporte quelque chose... | 1 | J2 | ✅ From 1734512b0be39ad5814453b56e909a20ee51b191 Mon Sep 17 00:00:00 2001 From: kekentin Date: Wed, 2 Apr 2025 11:44:44 +0200 Subject: [PATCH 51/65] correction route Quote --- WF_EF_Api/Contextlib/DbQuoteManager.cs | 43 ++++++++------- WF_EF_Api/Dto2Entities/Extention.cs | 4 ++ WF_EF_Api/ServicesApi/QuoteService.cs | 6 ++- .../WfApi/Controllers/QuotesController.cs | 52 ++++++++++++------- 4 files changed, 64 insertions(+), 41 deletions(-) diff --git a/WF_EF_Api/Contextlib/DbQuoteManager.cs b/WF_EF_Api/Contextlib/DbQuoteManager.cs index d72841a..ef69d71 100644 --- a/WF_EF_Api/Contextlib/DbQuoteManager.cs +++ b/WF_EF_Api/Contextlib/DbQuoteManager.cs @@ -54,20 +54,11 @@ namespace Contextlib { List quotes = await _context.quotes.Where(item => item.IsValid && item.Langage == (LangEnum)lang) .Include(q => q.Source).Include(q => q.Character).ThenInclude(c => c.Images).Include(q => q.Favorite) -<<<<<<< HEAD .ToListAsync(); + if (quotes.Count() == 0) return null; Quote quote = quotes[date.DayNumber % quotes.Count()]; - /*Quote quote = await _context.quotes.Where(item => item.Id == date.DayNumber % quotes.Count()) - .Include(q => q.Source).Include(q => q.Character).ThenInclude(c => c.Images).Include(q => q.Favorite) - .FirstOrDefaultAsync() ?? quotes.First();*/ - //Quote quote = _repo.GetById(date.DayNumber % quotes.Count()) ?? quotes.First(); -======= - .ToList(); - if (quotes.Count() == 0) return null; - Quote quote = quotes[ date.DayNumber % quotes.Count() ] ; ->>>>>>> 8471e6cfd50227037555f6650ed659ac091cc613 return quote; } @@ -113,15 +104,12 @@ namespace Contextlib return lastQuoteId; } - public async Task GetQuoteById(int id) + public async Task GetQuoteById(int id) { Quote? quote = _context.quotes.Where(item => item.Id == id) .Include(q => q.Source).Include(q => q.Character).ThenInclude(c => c.Images) - .First(); - if (quote == null) - { - throw new KeyNotFoundException($"Error : No quotes found with the ID: {id}."); - } + .FirstOrDefault(); + return quote; } @@ -186,8 +174,9 @@ namespace Contextlib public async Task RemoveQuote(int quoteId) { - - _repo.Delete( _repo.GetById(quoteId) ); + var quote = _repo.GetById(quoteId); + if (quote == null) throw new KeyNotFoundException(); + _repo.Delete( quote ); await _context.SaveChangesAsync(); } @@ -217,11 +206,27 @@ namespace Contextlib q.IdUsersPropose = quote.IdUsersPropose; change = true; } - if (quote.Content != null || quote.Content =="") + if (quote.Content != null || quote.Content == "") { q.Content = quote.Content; change = true; } + if (quote.IsValid != q.IsValid) + { + q.IsValid = quote.IsValid; + change = true; + } + if (quote.Likes != q.Likes) + { + q.Likes = quote.Likes; + change = true; + } + if (quote.Langage != q.Langage) + { + q.Langage = quote.Langage; + change = true; + } + _repo.Update(q); if (change) _context.SaveChanges(); } diff --git a/WF_EF_Api/Dto2Entities/Extention.cs b/WF_EF_Api/Dto2Entities/Extention.cs index 0fda06d..0077a6f 100644 --- a/WF_EF_Api/Dto2Entities/Extention.cs +++ b/WF_EF_Api/Dto2Entities/Extention.cs @@ -388,13 +388,17 @@ namespace Dto2Entities Quote quote = new Quote(); quote.Id = item.Id; quote.Content = item.Content; + quote.Source = new Source(); quote.Source.Year = item.DateSource; + quote.Character = new Character(); quote.Character.Name = item.Character; quote.Source.Title = item.TitleSource; quote.Langage = item.Langage.ToEntity(); + quote.Character.Images = new Images(); quote.Character.Images.ImgPath = item.ImagePath; quote.Likes = item.Like; quote.Source.TypeSrc = item.Type.ToEntity(); + quote.IsValid = item.IsValide; return quote; } diff --git a/WF_EF_Api/ServicesApi/QuoteService.cs b/WF_EF_Api/ServicesApi/QuoteService.cs index fc1be81..cdf66a2 100644 --- a/WF_EF_Api/ServicesApi/QuoteService.cs +++ b/WF_EF_Api/ServicesApi/QuoteService.cs @@ -65,9 +65,11 @@ namespace ServicesApi return await quoteService.GetLastQuoteId(); } - public async Task GetQuoteById(int id) + public async Task GetQuoteById(int id) { - return quoteService.GetQuoteById(id).Result.ToDto(); + var quote= quoteService.GetQuoteById(id).Result; + if (quote != null) return quote.ToDto(); + else return null; } public async Task> GetSomeQuote(int index, int pageSize) diff --git a/WF_EF_Api/WfApi/Controllers/QuotesController.cs b/WF_EF_Api/WfApi/Controllers/QuotesController.cs index f3a1eb2..1eda2f1 100644 --- a/WF_EF_Api/WfApi/Controllers/QuotesController.cs +++ b/WF_EF_Api/WfApi/Controllers/QuotesController.cs @@ -33,7 +33,10 @@ namespace WfApi.Controllers try { var result = await _quote.GetQuoteById(id); - + if (result == null) + { + throw new KeyNotFoundException($"Error : No quotes found with the ID: {id}."); + } if (result!=null) { return await Task.FromResult(Ok(result)); @@ -256,20 +259,27 @@ namespace WfApi.Controllers { try { - if (newQuote == null) + try { - return BadRequest(new { message = "Les données de la quote sont requises." }); - } + if (newQuote == null) + { + return BadRequest(new { message = "Les données de la quote sont requises." }); + } - var existingPlayer = _quote.GetQuoteById(newQuote.Id).Result; - if (existingPlayer != null) - { - return Conflict(new { message = "Une quote avec cet ID existe déjà." }); - } - _quote.AddQuote(newQuote); + if (await _quote.GetQuoteById(newQuote.Id) != null) + { + return Conflict(new { message = "Une quote avec cet ID existe déjà." }); + } + newQuote.IsValide=false; + var quote=_quote.AddQuote(newQuote); - return CreatedAtAction(nameof(GetAllQuote), new { id = newQuote.Id }, newQuote); + return CreatedAtAction(nameof(CreateQuote), new { id = newQuote.Id }, quote); + } + catch (KeyNotFoundException e) + { + return StatusCode((int)HttpStatusCode.NotFound, e); + } } catch (Exception) { @@ -331,22 +341,24 @@ namespace WfApi.Controllers [ProducesResponseType(StatusCodes.Status500InternalServerError)] public async Task DeleteQuote([FromQuery] int idQuote) { - try - { - var result = _quote.RemoveQuote(idQuote); - - if (result.IsCompletedSuccessfully) + try { + try { - return await Task.FromResult(Ok(result)); + _quote.RemoveQuote(idQuote).Wait(); + + + return await Task.FromResult(Ok()); + + } - else + catch (KeyNotFoundException e) { - return NotFound(); + return StatusCode((int)HttpStatusCode.NotFound, e); } } catch (Exception) { - return StatusCode((int)HttpStatusCode.InternalServerError, new { message = "Internal Server Error" }); + return StatusCode((int) HttpStatusCode.InternalServerError, new { message = "Erreur interne du serveur." }); } } } From 019ea0179714534b9997163dfc7ad2106053b615 Mon Sep 17 00:00:00 2001 From: Kevin MONDEJAR Date: Wed, 2 Apr 2025 11:56:09 +0200 Subject: [PATCH 52/65] correction routes users --- WF_EF_Api/Contextlib/DbImagesManager.cs | 7 + WF_EF_Api/Contextlib/DbQuoteManager.cs | 7 - WF_EF_Api/Contextlib/DbUsersManager.cs | 31 +- WF_EF_Api/Dto2Entities/Extention.cs | 3 +- WF_EF_Api/ServicesApi/UserService.cs | 9 +- .../20250402084447_migration2-04.Designer.cs | 1074 +++++++++++++++++ .../20250402084447_migration2-04.cs | 22 + .../WfApi/Controllers/UsersController.cs | 18 +- 8 files changed, 1147 insertions(+), 24 deletions(-) create mode 100644 WF_EF_Api/StubbedContextLib/Migrations/20250402084447_migration2-04.Designer.cs create mode 100644 WF_EF_Api/StubbedContextLib/Migrations/20250402084447_migration2-04.cs diff --git a/WF_EF_Api/Contextlib/DbImagesManager.cs b/WF_EF_Api/Contextlib/DbImagesManager.cs index 999f546..6afd953 100644 --- a/WF_EF_Api/Contextlib/DbImagesManager.cs +++ b/WF_EF_Api/Contextlib/DbImagesManager.cs @@ -1,5 +1,6 @@ using Entity; using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Metadata.Internal; using Shared; using System; using System.Collections.Generic; @@ -86,5 +87,11 @@ namespace Contextlib { return await _context.images.CountAsync(); } + + public async Task GetImageByPath(string path) + { + var image = _repository.GetItems(item => item.ImgPath == path,0,1).FirstOrDefault(); + return image; + } } } diff --git a/WF_EF_Api/Contextlib/DbQuoteManager.cs b/WF_EF_Api/Contextlib/DbQuoteManager.cs index d72841a..2cfef79 100644 --- a/WF_EF_Api/Contextlib/DbQuoteManager.cs +++ b/WF_EF_Api/Contextlib/DbQuoteManager.cs @@ -54,7 +54,6 @@ namespace Contextlib { List quotes = await _context.quotes.Where(item => item.IsValid && item.Langage == (LangEnum)lang) .Include(q => q.Source).Include(q => q.Character).ThenInclude(c => c.Images).Include(q => q.Favorite) -<<<<<<< HEAD .ToListAsync(); Quote quote = quotes[date.DayNumber % quotes.Count()]; @@ -63,12 +62,6 @@ namespace Contextlib .FirstOrDefaultAsync() ?? quotes.First();*/ //Quote quote = _repo.GetById(date.DayNumber % quotes.Count()) ?? quotes.First(); -======= - .ToList(); - if (quotes.Count() == 0) return null; - Quote quote = quotes[ date.DayNumber % quotes.Count() ] ; ->>>>>>> 8471e6cfd50227037555f6650ed659ac091cc613 - return quote; } diff --git a/WF_EF_Api/Contextlib/DbUsersManager.cs b/WF_EF_Api/Contextlib/DbUsersManager.cs index 6389403..7c30440 100644 --- a/WF_EF_Api/Contextlib/DbUsersManager.cs +++ b/WF_EF_Api/Contextlib/DbUsersManager.cs @@ -4,6 +4,7 @@ using System.Linq; using System.Text; using System.Threading.Tasks; using Entity; +using Microsoft.EntityFrameworkCore; using Shared; namespace Contextlib @@ -23,9 +24,20 @@ namespace Contextlib public async Task AddUser(Users user) { + /*if (await ExistEmail(user.Email) || (await ExistUsername(user.UserName))) + { + throw new ArgumentException("The given Email or Username Already exist"); + }*/ if (user == null) { throw new ArgumentNullException(nameof(user), "user cannot be null."); } + var dbI = new DbImagesManager(_context); + var image = await dbI.GetImageByPath(user.Images.ImgPath); + if(image != null) + { + user.IdImage = image.Id; + user.Images = image; + } _repo.Insert(user); await _context.SaveChangesAsync(); } @@ -37,13 +49,13 @@ namespace Contextlib public async Task ExistEmail(string email) { - IQueryable users = _context.users.Where(u=>u.Email == email); + Users? users = await _context.users.Where(u=>u.Email == email).FirstOrDefaultAsync(); return users != null; } public async Task ExistUsername(string username) { - IQueryable users = _context.users.Where(u => u.UserName == username); + Users? users = await _context.users.Where(u => u.UserName == username).FirstOrDefaultAsync(); return users != null; } @@ -56,7 +68,7 @@ namespace Contextlib public async Task GetHashPassword(string username) { Users? user = _context.users.Where(u=>u.UserName == username).FirstOrDefault(); - if (user != null) + if (user == null) { return ""; } @@ -130,14 +142,19 @@ namespace Contextlib public async Task UpdateUser(int userId, Users user) { - Users? u = _repo.GetById(userId); + Users? u = _repo.GetById(userId, item => item.Id == userId, nameof(Users.Images)); if (u != null) { bool change = false; - if (user.IdImage != 0) + if (user.Images.ImgPath != null) { - u.IdImage = user.IdImage; - change = true; + var dbI = new DbImagesManager(_context); + var img = await dbI.GetImageByPath(user.Images.ImgPath); + if (img != null) + { + u.IdImage = dbI.GetImageByPath(user.Images.ImgPath).Id; + change = true; + } } if (user.UserName != null) { diff --git a/WF_EF_Api/Dto2Entities/Extention.cs b/WF_EF_Api/Dto2Entities/Extention.cs index 0fda06d..bd06a55 100644 --- a/WF_EF_Api/Dto2Entities/Extention.cs +++ b/WF_EF_Api/Dto2Entities/Extention.cs @@ -206,7 +206,7 @@ namespace Dto2Entities user.Password = item.Password; user.Email = item.Email; user.date = item.Created; - user.ImageProfil = item.Images.ImgPath; + user.ImageProfil = item.Images.ImgPath; // image null avec put return user; } @@ -436,6 +436,7 @@ namespace Dto2Entities user.Password = item.Password; user.Email = item.Email; user.Created = item.date; + user.Images = new Images(); user.Images.ImgPath = item.ImageProfil; return user; } diff --git a/WF_EF_Api/ServicesApi/UserService.cs b/WF_EF_Api/ServicesApi/UserService.cs index 064fd63..6d002c9 100644 --- a/WF_EF_Api/ServicesApi/UserService.cs +++ b/WF_EF_Api/ServicesApi/UserService.cs @@ -67,7 +67,14 @@ namespace ServicesApi public async Task GetUserById(int id) { - return userService.GetUserById(id).Result.ToDto(); + try + { + return (await userService.GetUserById(id)).ToDto(); + } + catch(KeyNotFoundException e) + { + throw new KeyNotFoundException(e.Message); + } } public async Task GetUserByUsername(string username) diff --git a/WF_EF_Api/StubbedContextLib/Migrations/20250402084447_migration2-04.Designer.cs b/WF_EF_Api/StubbedContextLib/Migrations/20250402084447_migration2-04.Designer.cs new file mode 100644 index 0000000..1ecdc86 --- /dev/null +++ b/WF_EF_Api/StubbedContextLib/Migrations/20250402084447_migration2-04.Designer.cs @@ -0,0 +1,1074 @@ +// +using System; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Metadata; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; +using StubbedContextLib; + +#nullable disable + +namespace StubbedContextLib.Migrations +{ + [DbContext(typeof(StubWTFContext))] + [Migration("20250402084447_migration2-04")] + partial class migration204 + { + /// + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("ProductVersion", "9.0.3") + .HasAnnotation("Relational:MaxIdentifierLength", 128); + + SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder); + + modelBuilder.Entity("Entity.Admin", b => + { + b.Property("IdUsers") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("IdUsers")); + + b.Property("UserId") + .HasColumnType("int"); + + b.HasKey("IdUsers"); + + b.HasIndex("UserId"); + + b.ToTable("admins"); + }); + + modelBuilder.Entity("Entity.Character", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("IdImage") + .HasColumnType("int"); + + b.Property("Name") + .IsRequired() + .HasMaxLength(50) + .HasColumnType("nvarchar(50)"); + + b.HasKey("Id"); + + b.HasIndex("IdImage"); + + b.ToTable("characters"); + + b.HasData( + new + { + Id = 1, + IdImage = 1, + Name = "Alan Grant" + }, + new + { + Id = 2, + IdImage = 2, + Name = "Aragorn" + }, + new + { + Id = 3, + IdImage = 3, + Name = "Legolas" + }, + new + { + Id = 4, + IdImage = 4, + Name = "Frodon" + }, + new + { + Id = 5, + IdImage = 5, + Name = "Dobby" + }, + new + { + Id = 6, + IdImage = 6, + Name = "Jon Snow" + }, + new + { + Id = 7, + IdImage = 7, + Name = "Daenerys Targaryen" + }, + new + { + Id = 8, + IdImage = 8, + Name = "Luke Skywalker" + }, + new + { + Id = 9, + IdImage = 9, + Name = "Princess Leia" + }, + new + { + Id = 10, + IdImage = 10, + Name = "Harry Potter" + }); + }); + + modelBuilder.Entity("Entity.Commentary", b => + { + b.Property("IdUser") + .HasColumnType("int"); + + b.Property("IdQuote") + .HasColumnType("int"); + + b.Property("Comment") + .IsRequired() + .HasMaxLength(100) + .HasColumnType("nvarchar(100)"); + + b.Property("DateCommentary") + .HasColumnType("date") + .HasColumnName("DateCommentary"); + + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.HasKey("IdUser", "IdQuote"); + + b.HasIndex("IdQuote"); + + b.ToTable("comments"); + + b.HasData( + new + { + IdUser = 2, + IdQuote = 1, + Comment = "Ce film est le meilleur", + DateCommentary = new DateTime(2025, 2, 3, 0, 0, 0, 0, DateTimeKind.Unspecified), + Id = 1 + }, + new + { + IdUser = 3, + IdQuote = 1, + Comment = "Very good", + DateCommentary = new DateTime(2025, 3, 11, 0, 0, 0, 0, DateTimeKind.Unspecified), + Id = 2 + }); + }); + + modelBuilder.Entity("Entity.Favorite", b => + { + b.Property("IdQuote") + .HasColumnType("int"); + + b.Property("IdUsers") + .HasColumnType("int"); + + b.HasKey("IdQuote", "IdUsers"); + + b.HasIndex("IdUsers"); + + b.ToTable("favorites"); + + b.HasData( + new + { + IdQuote = 2, + IdUsers = 8 + }, + new + { + IdQuote = 5, + IdUsers = 3 + }, + new + { + IdQuote = 9, + IdUsers = 1 + }, + new + { + IdQuote = 4, + IdUsers = 10 + }, + new + { + IdQuote = 3, + IdUsers = 2 + }, + new + { + IdQuote = 6, + IdUsers = 7 + }, + new + { + IdQuote = 1, + IdUsers = 6 + }, + new + { + IdQuote = 8, + IdUsers = 9 + }, + new + { + IdQuote = 10, + IdUsers = 5 + }); + }); + + modelBuilder.Entity("Entity.Images", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("ImgPath") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.HasKey("Id"); + + b.ToTable("images"); + + b.HasData( + new + { + Id = 1, + ImgPath = "https://th.bing.com/th/id/OIP.TJuWNCsibz8MVmhdNQEdMwHaE8?w=244&h=180&c=7&r=0&o=5&pid=1.7" + }, + new + { + Id = 2, + ImgPath = "https://th.bing.com/th/id/OIP.NgXRQ5-IknA6_qOPFhLWIwHaHK?w=165&h=180&c=7&r=0&o=5&pid=1.7" + }, + new + { + Id = 3, + ImgPath = "https://th.bing.com/th/id/OIP.XcJoJ6bC9sAMjol1pJn5UQHaLH?w=118&h=180&c=7&r=0&o=5&pid=1.7" + }, + new + { + Id = 4, + ImgPath = "https://th.bing.com/th/id/OIP.PPIESqZaNDa-qUcfSDXhdQHaGK?w=210&h=180&c=7&r=0&o=5&pid=1.7" + }, + new + { + Id = 5, + ImgPath = "https://th.bing.com/th/id/OIP.XBghSl2kfRNNtQoSxc901wHaHa?w=177&h=180&c=7&r=0&o=5&pid=1.7" + }, + new + { + Id = 6, + ImgPath = "https://th.bing.com/th/id/OIP.af1Aid64cqEKoIOBgCPxtQHaJO?w=145&h=182&c=7&r=0&o=5&pid=1.7" + }, + new + { + Id = 7, + ImgPath = "https://th.bing.com/th/id/OIP.ri5vSXr5lNTLt4DO6KQXyQHaI4?w=158&h=189&c=7&r=0&o=5&pid=1.7" + }, + new + { + Id = 8, + ImgPath = "https://th.bing.com/th/id/OIP.uPTRLR8uspCiafiunUqKfQHaMJ?w=115&h=180&c=7&r=0&o=5&pid=1.7" + }, + new + { + Id = 9, + ImgPath = "https://th.bing.com/th/id/OIP.hcJis4rKbyQtugsoFJU2ngHaM_?w=118&h=207&c=7&r=0&o=5&pid=1.7" + }, + new + { + Id = 10, + ImgPath = "https://th.bing.com/th/id/OIP.Py1_XfUrKJY_A6tYEmFS5wHaE8?w=280&h=187&c=7&r=0&o=5&pid=1.7" + }); + }); + + modelBuilder.Entity("Entity.Question", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("AnswerA") + .IsRequired() + .HasMaxLength(50) + .HasColumnType("nvarchar(50)"); + + b.Property("AnswerB") + .IsRequired() + .HasMaxLength(50) + .HasColumnType("nvarchar(50)"); + + b.Property("AnswerC") + .IsRequired() + .HasMaxLength(50) + .HasColumnType("nvarchar(50)"); + + b.Property("AnswerD") + .IsRequired() + .HasMaxLength(50) + .HasColumnType("nvarchar(50)"); + + b.Property("CorrectAnswer") + .IsRequired() + .HasMaxLength(1) + .HasColumnType("nvarchar(1)"); + + b.Property("IsValid") + .HasColumnType("bit"); + + b.Property("Text") + .IsRequired() + .HasMaxLength(200) + .HasColumnType("nvarchar(200)"); + + b.HasKey("Id"); + + b.ToTable("question"); + + b.HasData( + new + { + Id = 1, + AnswerA = "Gimli", + AnswerB = "Aragorn", + AnswerC = "Frodon", + AnswerD = "Gandalf", + CorrectAnswer = "B", + IsValid = true, + Text = "Qui est le leader de la Communauté de l'Anneau ?" + }, + new + { + Id = 2, + AnswerA = "Serdaigle", + AnswerB = "Gryffondor", + AnswerC = "Serpentard", + AnswerD = "Poufsouffle", + CorrectAnswer = "B", + IsValid = false, + Text = "Dans quelle maison Harry Potter est-il ?" + }, + new + { + Id = 3, + AnswerA = "Saroumane", + AnswerB = "Sauron", + AnswerC = "Gollum", + AnswerD = "Gothmog", + CorrectAnswer = "B", + IsValid = true, + Text = "Qui est le Seigneur des Ténèbres dans la saga Le Seigneur des Anneaux ?" + }, + new + { + Id = 4, + AnswerA = "Han Solo", + AnswerB = "Princesse Leia", + AnswerC = "Chewbacca", + AnswerD = "R2-D2", + CorrectAnswer = "A", + IsValid = true, + Text = "Dans le film Star Wars : Episode IV, qui sauve Luke Skywalker de l'Étoile de la Mort ?" + }, + new + { + Id = 5, + AnswerA = "Reine Jadis", + AnswerB = "Aslan", + AnswerC = "Edmund", + AnswerD = "Lucy", + CorrectAnswer = "B", + IsValid = true, + Text = "Qui est le souverain de Narnia dans Le Lion, la Sorcière Blanche et l'Armoire Magique ?" + }, + new + { + Id = 6, + AnswerA = "Smaug", + AnswerB = "Falkor", + AnswerC = "Norbert", + AnswerD = "Shenron", + CorrectAnswer = "A", + IsValid = true, + Text = "Quel est le nom du dragon dans Le Hobbit ?" + }, + new + { + Id = 7, + AnswerA = "Bella Swan", + AnswerB = "Edward Cullen", + AnswerC = "Jacob Black", + AnswerD = "Victoria", + CorrectAnswer = "A", + IsValid = true, + Text = "Qui est la première personne à être mordue par un vampire dans Twilight ?" + }, + new + { + Id = 8, + AnswerA = "Obi-Wan Kenobi", + AnswerB = "Yoda", + AnswerC = "Han Solo", + AnswerD = "Luke Skywalker", + CorrectAnswer = "A", + IsValid = true, + Text = "Quel personnage dit Que la Force soit avec toi dans Star Wars ?" + }, + new + { + Id = 9, + AnswerA = "Dr. Ellie Sattler", + AnswerB = "Alan Grant", + AnswerC = "John Hammond", + AnswerD = "Dennis Nedry", + CorrectAnswer = "B", + IsValid = true, + Text = "Dans Jurassic Park, quel est le nom du paléontologue sur l'île ?" + }, + new + { + Id = 10, + AnswerA = "Cersei Lannister", + AnswerB = "Arya Stark", + AnswerC = "Daenerys Targaryen", + AnswerD = "Sansa Stark", + CorrectAnswer = "C", + IsValid = true, + Text = "Dans Game of Thrones, qui est surnommée la Mère des Dragons ?" + }); + }); + + modelBuilder.Entity("Entity.Quiz", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("IdImage") + .HasColumnType("int"); + + b.Property("NbQuestion") + .HasColumnType("int"); + + b.Property("Title") + .IsRequired() + .HasMaxLength(50) + .HasColumnType("nvarchar(50)"); + + b.HasKey("Id"); + + b.HasIndex("IdImage"); + + b.ToTable("quizzes"); + + b.HasData( + new + { + Id = 1, + IdImage = 1, + NbQuestion = 5, + Title = "Quiz 1" + }, + new + { + Id = 2, + IdImage = 2, + NbQuestion = 5, + Title = "Quiz 2" + }); + }); + + modelBuilder.Entity("Entity.QuizQuestion", b => + { + b.Property("IdQuestion") + .HasColumnType("int"); + + b.Property("IdQuiz") + .HasColumnType("int"); + + b.HasKey("IdQuestion", "IdQuiz"); + + b.HasIndex("IdQuiz"); + + b.ToTable("QuizQuestion"); + + b.HasData( + new + { + IdQuestion = 1, + IdQuiz = 1 + }, + new + { + IdQuestion = 2, + IdQuiz = 1 + }, + new + { + IdQuestion = 3, + IdQuiz = 1 + }, + new + { + IdQuestion = 4, + IdQuiz = 1 + }, + new + { + IdQuestion = 5, + IdQuiz = 1 + }, + new + { + IdQuestion = 6, + IdQuiz = 2 + }, + new + { + IdQuestion = 7, + IdQuiz = 2 + }, + new + { + IdQuestion = 8, + IdQuiz = 2 + }, + new + { + IdQuestion = 9, + IdQuiz = 2 + }, + new + { + IdQuestion = 10, + IdQuiz = 2 + }); + }); + + modelBuilder.Entity("Entity.Quote", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("Content") + .IsRequired() + .HasMaxLength(100) + .HasColumnType("nvarchar(100)"); + + b.Property("IdCharacter") + .HasColumnType("int"); + + b.Property("IdSource") + .HasColumnType("int"); + + b.Property("IdUsersPropose") + .HasColumnType("int"); + + b.Property("IsValid") + .HasColumnType("bit"); + + b.Property("Langage") + .HasColumnType("int"); + + b.Property("Likes") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.HasIndex("IdCharacter"); + + b.HasIndex("IdSource"); + + b.HasIndex("IdUsersPropose"); + + b.ToTable("quotes"); + + b.HasData( + new + { + Id = 1, + Content = "Je n'y crois pas. Je n'y crois pas. Ce n'est pas possible", + IdCharacter = 1, + IdSource = 1, + IdUsersPropose = 1, + IsValid = true, + Langage = 1, + Likes = 11025 + }, + new + { + Id = 2, + Content = "There is always hope", + IdCharacter = 2, + IdSource = 2, + IdUsersPropose = 1, + IsValid = true, + Langage = 0, + Likes = 11025 + }, + new + { + Id = 3, + Content = "A red sun rises. Blood has been spilled this night.", + IdCharacter = 3, + IdSource = 2, + IdUsersPropose = 1, + IsValid = true, + Langage = 0, + Likes = 11025 + }, + new + { + Id = 4, + Content = "I wish the Ring had never come to me.I wish none of this had happened.", + IdCharacter = 4, + IdSource = 2, + IdUsersPropose = 1, + IsValid = true, + Langage = 0, + Likes = 11025 + }, + new + { + Id = 5, + Content = "Dobby is a free elf!", + IdCharacter = 5, + IdSource = 4, + IdUsersPropose = 1, + IsValid = true, + Langage = 0, + Likes = 11025 + }, + new + { + Id = 6, + Content = "Winter is comming", + IdCharacter = 6, + IdSource = 3, + IdUsersPropose = 1, + IsValid = true, + Langage = 0, + Likes = 11025 + }, + new + { + Id = 7, + Content = "Je suis la dernière Targaryen. Je suis la reine des dragons", + IdCharacter = 7, + IdSource = 3, + IdUsersPropose = 1, + IsValid = true, + Langage = 1, + Likes = 11025 + }, + new + { + Id = 8, + Content = "Je ne suis pas prêt à affronter ça. C'est trop pour moi.", + IdCharacter = 8, + IdSource = 5, + IdUsersPropose = 1, + IsValid = true, + Langage = 1, + Likes = 11025 + }, + new + { + Id = 9, + Content = "Aidez-moi, Obi-Wan Kenobi, vous êtes mon seul espoir.", + IdCharacter = 9, + IdSource = 5, + IdUsersPropose = 1, + IsValid = true, + Langage = 1, + Likes = 11025 + }, + new + { + Id = 10, + Content = "La quoi ?", + IdCharacter = 10, + IdSource = 4, + IdUsersPropose = 1, + IsValid = false, + Langage = 1, + Likes = 11025 + }); + }); + + modelBuilder.Entity("Entity.Source", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("Title") + .IsRequired() + .HasMaxLength(100) + .HasColumnType("nvarchar(100)"); + + b.Property("TypeSrc") + .HasColumnType("int"); + + b.Property("Year") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.ToTable("sources"); + + b.HasData( + new + { + Id = 1, + Title = "Jurassic Park", + TypeSrc = 0, + Year = 1993 + }, + new + { + Id = 2, + Title = "Le Seigneur des anneaux : La Communauté de l'anneau", + TypeSrc = 0, + Year = 2001 + }, + new + { + Id = 3, + Title = "Game of throne", + TypeSrc = 1, + Year = 2011 + }, + new + { + Id = 4, + Title = "Harry Potter à l'école des sorcier", + TypeSrc = 0, + Year = 1997 + }, + new + { + Id = 5, + Title = "Star Wars, épisode IV : Un nouvel espoir", + TypeSrc = 0, + Year = 1977 + }); + }); + + modelBuilder.Entity("Entity.Users", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("Created") + .HasColumnType("date") + .HasColumnName("Created"); + + b.Property("Email") + .IsRequired() + .HasMaxLength(50) + .HasColumnType("nvarchar(50)"); + + b.Property("IdImage") + .HasColumnType("int"); + + b.Property("Password") + .IsRequired() + .HasMaxLength(200) + .HasColumnType("nvarchar(200)"); + + b.Property("UserName") + .IsRequired() + .HasMaxLength(50) + .HasColumnType("nvarchar(50)"); + + b.HasKey("Id"); + + b.HasIndex("IdImage"); + + b.ToTable("users"); + + b.HasData( + new + { + Id = 1, + Created = new DateTime(2025, 5, 12, 0, 0, 0, 0, DateTimeKind.Unspecified), + Email = "jhonDhoe@gmail.com", + IdImage = 1, + Password = "1234", + UserName = "Jhon-Dhoe" + }, + new + { + Id = 2, + Created = new DateTime(2025, 3, 19, 0, 0, 0, 0, DateTimeKind.Unspecified), + Email = "lucy_rose@outlook.com", + IdImage = 2, + Password = "abcd", + UserName = "Lucy-Rose" + }, + new + { + Id = 3, + Created = new DateTime(2024, 11, 2, 0, 0, 0, 0, DateTimeKind.Unspecified), + Email = "mark.taylor@yahoo.com", + IdImage = 3, + Password = "5678", + UserName = "Mark-Taylor" + }, + new + { + Id = 4, + Created = new DateTime(2025, 2, 28, 0, 0, 0, 0, DateTimeKind.Unspecified), + Email = "sophie.martin@gmail.com", + IdImage = 4, + Password = "4321", + UserName = "Sophie-Martin" + }, + new + { + Id = 5, + Created = new DateTime(2025, 1, 15, 0, 0, 0, 0, DateTimeKind.Unspecified), + Email = "nathan_doe@aol.com", + IdImage = 5, + Password = "8765", + UserName = "Nathan-Doe" + }, + new + { + Id = 6, + Created = new DateTime(2025, 4, 7, 0, 0, 0, 0, DateTimeKind.Unspecified), + Email = "ella.brown@icloud.com", + IdImage = 6, + Password = "2468", + UserName = "Ella-Brown" + }, + new + { + Id = 7, + Created = new DateTime(2024, 12, 25, 0, 0, 0, 0, DateTimeKind.Unspecified), + Email = "oliver_smith@gmail.com", + IdImage = 7, + Password = "1357", + UserName = "Oliver-Smith" + }, + new + { + Id = 8, + Created = new DateTime(2025, 3, 5, 0, 0, 0, 0, DateTimeKind.Unspecified), + Email = "mia.jones@outlook.com", + IdImage = 8, + Password = "1122", + UserName = "Mia-Jones" + }, + new + { + Id = 9, + Created = new DateTime(2025, 2, 22, 0, 0, 0, 0, DateTimeKind.Unspecified), + Email = "kevin_williams@aol.com", + IdImage = 9, + Password = "2233", + UserName = "Kevin-Williams" + }, + new + { + Id = 10, + Created = new DateTime(2025, 1, 3, 0, 0, 0, 0, DateTimeKind.Unspecified), + Email = "olivia.white@yahoo.com", + IdImage = 10, + Password = "3344", + UserName = "Olivia-White" + }); + }); + + modelBuilder.Entity("Entity.Admin", b => + { + b.HasOne("Entity.Users", "User") + .WithMany() + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("User"); + }); + + modelBuilder.Entity("Entity.Character", b => + { + b.HasOne("Entity.Images", "Images") + .WithMany("Characters") + .HasForeignKey("IdImage") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Images"); + }); + + modelBuilder.Entity("Entity.Commentary", b => + { + b.HasOne("Entity.Quote", "Quote") + .WithMany("Commentarys") + .HasForeignKey("IdQuote") + .OnDelete(DeleteBehavior.ClientCascade) + .IsRequired(); + + b.HasOne("Entity.Users", "User") + .WithMany() + .HasForeignKey("IdUser") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Quote"); + + b.Navigation("User"); + }); + + modelBuilder.Entity("Entity.Favorite", b => + { + b.HasOne("Entity.Quote", "Quote") + .WithMany() + .HasForeignKey("IdQuote") + .OnDelete(DeleteBehavior.ClientCascade) + .IsRequired(); + + b.HasOne("Entity.Users", "Users") + .WithMany() + .HasForeignKey("IdUsers") + .OnDelete(DeleteBehavior.ClientCascade) + .IsRequired(); + + b.Navigation("Quote"); + + b.Navigation("Users"); + }); + + modelBuilder.Entity("Entity.Quiz", b => + { + b.HasOne("Entity.Images", "Images") + .WithMany("Quizs") + .HasForeignKey("IdImage") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Images"); + }); + + modelBuilder.Entity("Entity.QuizQuestion", b => + { + b.HasOne("Entity.Question", null) + .WithMany() + .HasForeignKey("IdQuestion") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("Entity.Quiz", null) + .WithMany() + .HasForeignKey("IdQuiz") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("Entity.Quote", b => + { + b.HasOne("Entity.Character", "Character") + .WithMany("Quotes") + .HasForeignKey("IdCharacter") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("Entity.Source", "Source") + .WithMany("Quotes") + .HasForeignKey("IdSource") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("Entity.Users", "User") + .WithMany("Quotes") + .HasForeignKey("IdUsersPropose"); + + b.Navigation("Character"); + + b.Navigation("Source"); + + b.Navigation("User"); + }); + + modelBuilder.Entity("Entity.Users", b => + { + b.HasOne("Entity.Images", "Images") + .WithMany("Users") + .HasForeignKey("IdImage") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Images"); + }); + + modelBuilder.Entity("Entity.Character", b => + { + b.Navigation("Quotes"); + }); + + modelBuilder.Entity("Entity.Images", b => + { + b.Navigation("Characters"); + + b.Navigation("Quizs"); + + b.Navigation("Users"); + }); + + modelBuilder.Entity("Entity.Quote", b => + { + b.Navigation("Commentarys"); + }); + + modelBuilder.Entity("Entity.Source", b => + { + b.Navigation("Quotes"); + }); + + modelBuilder.Entity("Entity.Users", b => + { + b.Navigation("Quotes"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/WF_EF_Api/StubbedContextLib/Migrations/20250402084447_migration2-04.cs b/WF_EF_Api/StubbedContextLib/Migrations/20250402084447_migration2-04.cs new file mode 100644 index 0000000..4f1a548 --- /dev/null +++ b/WF_EF_Api/StubbedContextLib/Migrations/20250402084447_migration2-04.cs @@ -0,0 +1,22 @@ +using Microsoft.EntityFrameworkCore.Migrations; + +#nullable disable + +namespace StubbedContextLib.Migrations +{ + /// + public partial class migration204 : Migration + { + /// + protected override void Up(MigrationBuilder migrationBuilder) + { + + } + + /// + protected override void Down(MigrationBuilder migrationBuilder) + { + + } + } +} diff --git a/WF_EF_Api/WfApi/Controllers/UsersController.cs b/WF_EF_Api/WfApi/Controllers/UsersController.cs index 701f486..ea0f7ec 100644 --- a/WF_EF_Api/WfApi/Controllers/UsersController.cs +++ b/WF_EF_Api/WfApi/Controllers/UsersController.cs @@ -574,21 +574,23 @@ namespace WfApi.Controllers if (newUser == null) { return BadRequest(new { message = "User data is required." }); - } + } - var existingPlayer = _user.GetUserById(newUser.Id).Result; - if (existingPlayer != null) + try { + var existingPlayer = await _user.GetUserById(newUser.Id); return Conflict(new { message = "A user with this ID already exists." }); } + catch(KeyNotFoundException e) + { + _user.AddUser(newUser); - _user.AddUser(newUser); - - return CreatedAtAction(nameof(GetAllUsers), new { id = newUser.Id }, newUser); + return CreatedAtAction(nameof(GetAllUsers), new { id = newUser.Id }, newUser); + } } - catch (Exception) + catch (Exception e) { - return StatusCode((int)HttpStatusCode.InternalServerError, new { message = "Erreur interne du serveur." }); + return StatusCode((int)HttpStatusCode.InternalServerError, new { message = "Erreur interne du serveur." + e.Message }); } } From 48c12241d8e859875d8a4b9cadc3ff2b2f231b30 Mon Sep 17 00:00:00 2001 From: Kevin MONDEJAR Date: Wed, 2 Apr 2025 13:09:49 +0200 Subject: [PATCH 53/65] =?UTF-8?q?Route=20user=20enti=C3=A8rement=20fonctio?= =?UTF-8?q?nnelles?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- WF_EF_Api/Contextlib/DbUsersManager.cs | 7 +- WF_EF_Api/Dto2Entities/Extention.cs | 2 +- WF_EF_Api/ServicesApi/UserService.cs | 4 +- WF_EF_Api/Shared/IUserService.cs | 2 +- WF_EF_Api/StubApi/UserServiceStub.cs | 3 +- .../20250402105029_migration1.Designer.cs | 1074 +++++++++++++++++ .../Migrations/20250402105029_migration1.cs | 22 + .../WfApi/Controllers/UsersController.cs | 4 +- 8 files changed, 1110 insertions(+), 8 deletions(-) create mode 100644 WF_EF_Api/StubbedContextLib/Migrations/20250402105029_migration1.Designer.cs create mode 100644 WF_EF_Api/StubbedContextLib/Migrations/20250402105029_migration1.cs diff --git a/WF_EF_Api/Contextlib/DbUsersManager.cs b/WF_EF_Api/Contextlib/DbUsersManager.cs index 7c30440..e10ca69 100644 --- a/WF_EF_Api/Contextlib/DbUsersManager.cs +++ b/WF_EF_Api/Contextlib/DbUsersManager.cs @@ -129,8 +129,13 @@ namespace Contextlib return user; } - public async Task RemoveUser(Users user) + public async Task RemoveUser(int id) { + Users? user = _repo.GetById(id); + if (user == null) + { + throw new KeyNotFoundException($"Error : No users found with the ID: {id}."); + } _repo.Delete(user); await _context.SaveChangesAsync(); } diff --git a/WF_EF_Api/Dto2Entities/Extention.cs b/WF_EF_Api/Dto2Entities/Extention.cs index 09bcb1f..1687d94 100644 --- a/WF_EF_Api/Dto2Entities/Extention.cs +++ b/WF_EF_Api/Dto2Entities/Extention.cs @@ -206,7 +206,7 @@ namespace Dto2Entities user.Password = item.Password; user.Email = item.Email; user.date = item.Created; - user.ImageProfil = item.Images.ImgPath; // image null avec put + user.ImageProfil = item.Images.ImgPath; return user; } diff --git a/WF_EF_Api/ServicesApi/UserService.cs b/WF_EF_Api/ServicesApi/UserService.cs index 6d002c9..3a5cc02 100644 --- a/WF_EF_Api/ServicesApi/UserService.cs +++ b/WF_EF_Api/ServicesApi/UserService.cs @@ -82,9 +82,9 @@ namespace ServicesApi return userService.GetUserByUsername(username).Result.ToDto(); } - public async Task RemoveUser(UserDTO user) + public async Task RemoveUser(int id) { - await userService.RemoveUser(user.ToEntity()); + await userService.RemoveUser(id); } public async Task SetAdminRole(bool isAdmin) diff --git a/WF_EF_Api/Shared/IUserService.cs b/WF_EF_Api/Shared/IUserService.cs index 74bf04a..e55135a 100644 --- a/WF_EF_Api/Shared/IUserService.cs +++ b/WF_EF_Api/Shared/IUserService.cs @@ -39,7 +39,7 @@ namespace Shared // Removes a user from the system based on their unique identifier ('userId'). // 'userId' is the unique identifier of the user to be removed. - Task RemoveUser(TUser user); + Task RemoveUser(int id); // Retrieves the hashed password for a given username. // 'username' is the username for which the password hash is to be retrieved. diff --git a/WF_EF_Api/StubApi/UserServiceStub.cs b/WF_EF_Api/StubApi/UserServiceStub.cs index b9c21f8..71fb7f0 100644 --- a/WF_EF_Api/StubApi/UserServiceStub.cs +++ b/WF_EF_Api/StubApi/UserServiceStub.cs @@ -92,8 +92,9 @@ namespace StubApi return _users.FirstOrDefault(u => u.Pseudo == username); } - public async Task RemoveUser(UserDTO user) + public async Task RemoveUser(int id) { + var user = await GetUserById(id); _users.Remove(user); } diff --git a/WF_EF_Api/StubbedContextLib/Migrations/20250402105029_migration1.Designer.cs b/WF_EF_Api/StubbedContextLib/Migrations/20250402105029_migration1.Designer.cs new file mode 100644 index 0000000..ca444d0 --- /dev/null +++ b/WF_EF_Api/StubbedContextLib/Migrations/20250402105029_migration1.Designer.cs @@ -0,0 +1,1074 @@ +// +using System; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Metadata; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; +using StubbedContextLib; + +#nullable disable + +namespace StubbedContextLib.Migrations +{ + [DbContext(typeof(StubWTFContext))] + [Migration("20250402105029_migration1")] + partial class migration1 + { + /// + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("ProductVersion", "9.0.3") + .HasAnnotation("Relational:MaxIdentifierLength", 128); + + SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder); + + modelBuilder.Entity("Entity.Admin", b => + { + b.Property("IdUsers") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("IdUsers")); + + b.Property("UserId") + .HasColumnType("int"); + + b.HasKey("IdUsers"); + + b.HasIndex("UserId"); + + b.ToTable("admins"); + }); + + modelBuilder.Entity("Entity.Character", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("IdImage") + .HasColumnType("int"); + + b.Property("Name") + .IsRequired() + .HasMaxLength(50) + .HasColumnType("nvarchar(50)"); + + b.HasKey("Id"); + + b.HasIndex("IdImage"); + + b.ToTable("characters"); + + b.HasData( + new + { + Id = 1, + IdImage = 1, + Name = "Alan Grant" + }, + new + { + Id = 2, + IdImage = 2, + Name = "Aragorn" + }, + new + { + Id = 3, + IdImage = 3, + Name = "Legolas" + }, + new + { + Id = 4, + IdImage = 4, + Name = "Frodon" + }, + new + { + Id = 5, + IdImage = 5, + Name = "Dobby" + }, + new + { + Id = 6, + IdImage = 6, + Name = "Jon Snow" + }, + new + { + Id = 7, + IdImage = 7, + Name = "Daenerys Targaryen" + }, + new + { + Id = 8, + IdImage = 8, + Name = "Luke Skywalker" + }, + new + { + Id = 9, + IdImage = 9, + Name = "Princess Leia" + }, + new + { + Id = 10, + IdImage = 10, + Name = "Harry Potter" + }); + }); + + modelBuilder.Entity("Entity.Commentary", b => + { + b.Property("IdUser") + .HasColumnType("int"); + + b.Property("IdQuote") + .HasColumnType("int"); + + b.Property("Comment") + .IsRequired() + .HasMaxLength(100) + .HasColumnType("nvarchar(100)"); + + b.Property("DateCommentary") + .HasColumnType("date") + .HasColumnName("DateCommentary"); + + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.HasKey("IdUser", "IdQuote"); + + b.HasIndex("IdQuote"); + + b.ToTable("comments"); + + b.HasData( + new + { + IdUser = 2, + IdQuote = 1, + Comment = "Ce film est le meilleur", + DateCommentary = new DateTime(2025, 2, 3, 0, 0, 0, 0, DateTimeKind.Unspecified), + Id = 1 + }, + new + { + IdUser = 3, + IdQuote = 1, + Comment = "Very good", + DateCommentary = new DateTime(2025, 3, 11, 0, 0, 0, 0, DateTimeKind.Unspecified), + Id = 2 + }); + }); + + modelBuilder.Entity("Entity.Favorite", b => + { + b.Property("IdQuote") + .HasColumnType("int"); + + b.Property("IdUsers") + .HasColumnType("int"); + + b.HasKey("IdQuote", "IdUsers"); + + b.HasIndex("IdUsers"); + + b.ToTable("favorites"); + + b.HasData( + new + { + IdQuote = 2, + IdUsers = 8 + }, + new + { + IdQuote = 5, + IdUsers = 3 + }, + new + { + IdQuote = 9, + IdUsers = 1 + }, + new + { + IdQuote = 4, + IdUsers = 10 + }, + new + { + IdQuote = 3, + IdUsers = 2 + }, + new + { + IdQuote = 6, + IdUsers = 7 + }, + new + { + IdQuote = 1, + IdUsers = 6 + }, + new + { + IdQuote = 8, + IdUsers = 9 + }, + new + { + IdQuote = 10, + IdUsers = 5 + }); + }); + + modelBuilder.Entity("Entity.Images", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("ImgPath") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.HasKey("Id"); + + b.ToTable("images"); + + b.HasData( + new + { + Id = 1, + ImgPath = "https://th.bing.com/th/id/OIP.TJuWNCsibz8MVmhdNQEdMwHaE8?w=244&h=180&c=7&r=0&o=5&pid=1.7" + }, + new + { + Id = 2, + ImgPath = "https://th.bing.com/th/id/OIP.NgXRQ5-IknA6_qOPFhLWIwHaHK?w=165&h=180&c=7&r=0&o=5&pid=1.7" + }, + new + { + Id = 3, + ImgPath = "https://th.bing.com/th/id/OIP.XcJoJ6bC9sAMjol1pJn5UQHaLH?w=118&h=180&c=7&r=0&o=5&pid=1.7" + }, + new + { + Id = 4, + ImgPath = "https://th.bing.com/th/id/OIP.PPIESqZaNDa-qUcfSDXhdQHaGK?w=210&h=180&c=7&r=0&o=5&pid=1.7" + }, + new + { + Id = 5, + ImgPath = "https://th.bing.com/th/id/OIP.XBghSl2kfRNNtQoSxc901wHaHa?w=177&h=180&c=7&r=0&o=5&pid=1.7" + }, + new + { + Id = 6, + ImgPath = "https://th.bing.com/th/id/OIP.af1Aid64cqEKoIOBgCPxtQHaJO?w=145&h=182&c=7&r=0&o=5&pid=1.7" + }, + new + { + Id = 7, + ImgPath = "https://th.bing.com/th/id/OIP.ri5vSXr5lNTLt4DO6KQXyQHaI4?w=158&h=189&c=7&r=0&o=5&pid=1.7" + }, + new + { + Id = 8, + ImgPath = "https://th.bing.com/th/id/OIP.uPTRLR8uspCiafiunUqKfQHaMJ?w=115&h=180&c=7&r=0&o=5&pid=1.7" + }, + new + { + Id = 9, + ImgPath = "https://th.bing.com/th/id/OIP.hcJis4rKbyQtugsoFJU2ngHaM_?w=118&h=207&c=7&r=0&o=5&pid=1.7" + }, + new + { + Id = 10, + ImgPath = "https://th.bing.com/th/id/OIP.Py1_XfUrKJY_A6tYEmFS5wHaE8?w=280&h=187&c=7&r=0&o=5&pid=1.7" + }); + }); + + modelBuilder.Entity("Entity.Question", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("AnswerA") + .IsRequired() + .HasMaxLength(50) + .HasColumnType("nvarchar(50)"); + + b.Property("AnswerB") + .IsRequired() + .HasMaxLength(50) + .HasColumnType("nvarchar(50)"); + + b.Property("AnswerC") + .IsRequired() + .HasMaxLength(50) + .HasColumnType("nvarchar(50)"); + + b.Property("AnswerD") + .IsRequired() + .HasMaxLength(50) + .HasColumnType("nvarchar(50)"); + + b.Property("CorrectAnswer") + .IsRequired() + .HasMaxLength(1) + .HasColumnType("nvarchar(1)"); + + b.Property("IsValid") + .HasColumnType("bit"); + + b.Property("Text") + .IsRequired() + .HasMaxLength(200) + .HasColumnType("nvarchar(200)"); + + b.HasKey("Id"); + + b.ToTable("question"); + + b.HasData( + new + { + Id = 1, + AnswerA = "Gimli", + AnswerB = "Aragorn", + AnswerC = "Frodon", + AnswerD = "Gandalf", + CorrectAnswer = "B", + IsValid = true, + Text = "Qui est le leader de la Communauté de l'Anneau ?" + }, + new + { + Id = 2, + AnswerA = "Serdaigle", + AnswerB = "Gryffondor", + AnswerC = "Serpentard", + AnswerD = "Poufsouffle", + CorrectAnswer = "B", + IsValid = false, + Text = "Dans quelle maison Harry Potter est-il ?" + }, + new + { + Id = 3, + AnswerA = "Saroumane", + AnswerB = "Sauron", + AnswerC = "Gollum", + AnswerD = "Gothmog", + CorrectAnswer = "B", + IsValid = true, + Text = "Qui est le Seigneur des Ténèbres dans la saga Le Seigneur des Anneaux ?" + }, + new + { + Id = 4, + AnswerA = "Han Solo", + AnswerB = "Princesse Leia", + AnswerC = "Chewbacca", + AnswerD = "R2-D2", + CorrectAnswer = "A", + IsValid = true, + Text = "Dans le film Star Wars : Episode IV, qui sauve Luke Skywalker de l'Étoile de la Mort ?" + }, + new + { + Id = 5, + AnswerA = "Reine Jadis", + AnswerB = "Aslan", + AnswerC = "Edmund", + AnswerD = "Lucy", + CorrectAnswer = "B", + IsValid = true, + Text = "Qui est le souverain de Narnia dans Le Lion, la Sorcière Blanche et l'Armoire Magique ?" + }, + new + { + Id = 6, + AnswerA = "Smaug", + AnswerB = "Falkor", + AnswerC = "Norbert", + AnswerD = "Shenron", + CorrectAnswer = "A", + IsValid = true, + Text = "Quel est le nom du dragon dans Le Hobbit ?" + }, + new + { + Id = 7, + AnswerA = "Bella Swan", + AnswerB = "Edward Cullen", + AnswerC = "Jacob Black", + AnswerD = "Victoria", + CorrectAnswer = "A", + IsValid = true, + Text = "Qui est la première personne à être mordue par un vampire dans Twilight ?" + }, + new + { + Id = 8, + AnswerA = "Obi-Wan Kenobi", + AnswerB = "Yoda", + AnswerC = "Han Solo", + AnswerD = "Luke Skywalker", + CorrectAnswer = "A", + IsValid = true, + Text = "Quel personnage dit Que la Force soit avec toi dans Star Wars ?" + }, + new + { + Id = 9, + AnswerA = "Dr. Ellie Sattler", + AnswerB = "Alan Grant", + AnswerC = "John Hammond", + AnswerD = "Dennis Nedry", + CorrectAnswer = "B", + IsValid = true, + Text = "Dans Jurassic Park, quel est le nom du paléontologue sur l'île ?" + }, + new + { + Id = 10, + AnswerA = "Cersei Lannister", + AnswerB = "Arya Stark", + AnswerC = "Daenerys Targaryen", + AnswerD = "Sansa Stark", + CorrectAnswer = "C", + IsValid = true, + Text = "Dans Game of Thrones, qui est surnommée la Mère des Dragons ?" + }); + }); + + modelBuilder.Entity("Entity.Quiz", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("IdImage") + .HasColumnType("int"); + + b.Property("NbQuestion") + .HasColumnType("int"); + + b.Property("Title") + .IsRequired() + .HasMaxLength(50) + .HasColumnType("nvarchar(50)"); + + b.HasKey("Id"); + + b.HasIndex("IdImage"); + + b.ToTable("quizzes"); + + b.HasData( + new + { + Id = 1, + IdImage = 1, + NbQuestion = 5, + Title = "Quiz 1" + }, + new + { + Id = 2, + IdImage = 2, + NbQuestion = 5, + Title = "Quiz 2" + }); + }); + + modelBuilder.Entity("Entity.QuizQuestion", b => + { + b.Property("IdQuestion") + .HasColumnType("int"); + + b.Property("IdQuiz") + .HasColumnType("int"); + + b.HasKey("IdQuestion", "IdQuiz"); + + b.HasIndex("IdQuiz"); + + b.ToTable("QuizQuestion"); + + b.HasData( + new + { + IdQuestion = 1, + IdQuiz = 1 + }, + new + { + IdQuestion = 2, + IdQuiz = 1 + }, + new + { + IdQuestion = 3, + IdQuiz = 1 + }, + new + { + IdQuestion = 4, + IdQuiz = 1 + }, + new + { + IdQuestion = 5, + IdQuiz = 1 + }, + new + { + IdQuestion = 6, + IdQuiz = 2 + }, + new + { + IdQuestion = 7, + IdQuiz = 2 + }, + new + { + IdQuestion = 8, + IdQuiz = 2 + }, + new + { + IdQuestion = 9, + IdQuiz = 2 + }, + new + { + IdQuestion = 10, + IdQuiz = 2 + }); + }); + + modelBuilder.Entity("Entity.Quote", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("Content") + .IsRequired() + .HasMaxLength(100) + .HasColumnType("nvarchar(100)"); + + b.Property("IdCharacter") + .HasColumnType("int"); + + b.Property("IdSource") + .HasColumnType("int"); + + b.Property("IdUsersPropose") + .HasColumnType("int"); + + b.Property("IsValid") + .HasColumnType("bit"); + + b.Property("Langage") + .HasColumnType("int"); + + b.Property("Likes") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.HasIndex("IdCharacter"); + + b.HasIndex("IdSource"); + + b.HasIndex("IdUsersPropose"); + + b.ToTable("quotes"); + + b.HasData( + new + { + Id = 1, + Content = "Je n'y crois pas. Je n'y crois pas. Ce n'est pas possible", + IdCharacter = 1, + IdSource = 1, + IdUsersPropose = 1, + IsValid = true, + Langage = 1, + Likes = 11025 + }, + new + { + Id = 2, + Content = "There is always hope", + IdCharacter = 2, + IdSource = 2, + IdUsersPropose = 1, + IsValid = true, + Langage = 0, + Likes = 11025 + }, + new + { + Id = 3, + Content = "A red sun rises. Blood has been spilled this night.", + IdCharacter = 3, + IdSource = 2, + IdUsersPropose = 1, + IsValid = true, + Langage = 0, + Likes = 11025 + }, + new + { + Id = 4, + Content = "I wish the Ring had never come to me.I wish none of this had happened.", + IdCharacter = 4, + IdSource = 2, + IdUsersPropose = 1, + IsValid = true, + Langage = 0, + Likes = 11025 + }, + new + { + Id = 5, + Content = "Dobby is a free elf!", + IdCharacter = 5, + IdSource = 4, + IdUsersPropose = 1, + IsValid = true, + Langage = 0, + Likes = 11025 + }, + new + { + Id = 6, + Content = "Winter is comming", + IdCharacter = 6, + IdSource = 3, + IdUsersPropose = 1, + IsValid = true, + Langage = 0, + Likes = 11025 + }, + new + { + Id = 7, + Content = "Je suis la dernière Targaryen. Je suis la reine des dragons", + IdCharacter = 7, + IdSource = 3, + IdUsersPropose = 1, + IsValid = true, + Langage = 1, + Likes = 11025 + }, + new + { + Id = 8, + Content = "Je ne suis pas prêt à affronter ça. C'est trop pour moi.", + IdCharacter = 8, + IdSource = 5, + IdUsersPropose = 1, + IsValid = true, + Langage = 1, + Likes = 11025 + }, + new + { + Id = 9, + Content = "Aidez-moi, Obi-Wan Kenobi, vous êtes mon seul espoir.", + IdCharacter = 9, + IdSource = 5, + IdUsersPropose = 1, + IsValid = true, + Langage = 1, + Likes = 11025 + }, + new + { + Id = 10, + Content = "La quoi ?", + IdCharacter = 10, + IdSource = 4, + IdUsersPropose = 1, + IsValid = false, + Langage = 1, + Likes = 11025 + }); + }); + + modelBuilder.Entity("Entity.Source", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("Title") + .IsRequired() + .HasMaxLength(100) + .HasColumnType("nvarchar(100)"); + + b.Property("TypeSrc") + .HasColumnType("int"); + + b.Property("Year") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.ToTable("sources"); + + b.HasData( + new + { + Id = 1, + Title = "Jurassic Park", + TypeSrc = 0, + Year = 1993 + }, + new + { + Id = 2, + Title = "Le Seigneur des anneaux : La Communauté de l'anneau", + TypeSrc = 0, + Year = 2001 + }, + new + { + Id = 3, + Title = "Game of throne", + TypeSrc = 1, + Year = 2011 + }, + new + { + Id = 4, + Title = "Harry Potter à l'école des sorcier", + TypeSrc = 0, + Year = 1997 + }, + new + { + Id = 5, + Title = "Star Wars, épisode IV : Un nouvel espoir", + TypeSrc = 0, + Year = 1977 + }); + }); + + modelBuilder.Entity("Entity.Users", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("Created") + .HasColumnType("date") + .HasColumnName("Created"); + + b.Property("Email") + .IsRequired() + .HasMaxLength(50) + .HasColumnType("nvarchar(50)"); + + b.Property("IdImage") + .HasColumnType("int"); + + b.Property("Password") + .IsRequired() + .HasMaxLength(200) + .HasColumnType("nvarchar(200)"); + + b.Property("UserName") + .IsRequired() + .HasMaxLength(50) + .HasColumnType("nvarchar(50)"); + + b.HasKey("Id"); + + b.HasIndex("IdImage"); + + b.ToTable("users"); + + b.HasData( + new + { + Id = 1, + Created = new DateTime(2025, 5, 12, 0, 0, 0, 0, DateTimeKind.Unspecified), + Email = "jhonDhoe@gmail.com", + IdImage = 1, + Password = "1234", + UserName = "Jhon-Dhoe" + }, + new + { + Id = 2, + Created = new DateTime(2025, 3, 19, 0, 0, 0, 0, DateTimeKind.Unspecified), + Email = "lucy_rose@outlook.com", + IdImage = 2, + Password = "abcd", + UserName = "Lucy-Rose" + }, + new + { + Id = 3, + Created = new DateTime(2024, 11, 2, 0, 0, 0, 0, DateTimeKind.Unspecified), + Email = "mark.taylor@yahoo.com", + IdImage = 3, + Password = "5678", + UserName = "Mark-Taylor" + }, + new + { + Id = 4, + Created = new DateTime(2025, 2, 28, 0, 0, 0, 0, DateTimeKind.Unspecified), + Email = "sophie.martin@gmail.com", + IdImage = 4, + Password = "4321", + UserName = "Sophie-Martin" + }, + new + { + Id = 5, + Created = new DateTime(2025, 1, 15, 0, 0, 0, 0, DateTimeKind.Unspecified), + Email = "nathan_doe@aol.com", + IdImage = 5, + Password = "8765", + UserName = "Nathan-Doe" + }, + new + { + Id = 6, + Created = new DateTime(2025, 4, 7, 0, 0, 0, 0, DateTimeKind.Unspecified), + Email = "ella.brown@icloud.com", + IdImage = 6, + Password = "2468", + UserName = "Ella-Brown" + }, + new + { + Id = 7, + Created = new DateTime(2024, 12, 25, 0, 0, 0, 0, DateTimeKind.Unspecified), + Email = "oliver_smith@gmail.com", + IdImage = 7, + Password = "1357", + UserName = "Oliver-Smith" + }, + new + { + Id = 8, + Created = new DateTime(2025, 3, 5, 0, 0, 0, 0, DateTimeKind.Unspecified), + Email = "mia.jones@outlook.com", + IdImage = 8, + Password = "1122", + UserName = "Mia-Jones" + }, + new + { + Id = 9, + Created = new DateTime(2025, 2, 22, 0, 0, 0, 0, DateTimeKind.Unspecified), + Email = "kevin_williams@aol.com", + IdImage = 9, + Password = "2233", + UserName = "Kevin-Williams" + }, + new + { + Id = 10, + Created = new DateTime(2025, 1, 3, 0, 0, 0, 0, DateTimeKind.Unspecified), + Email = "olivia.white@yahoo.com", + IdImage = 10, + Password = "3344", + UserName = "Olivia-White" + }); + }); + + modelBuilder.Entity("Entity.Admin", b => + { + b.HasOne("Entity.Users", "User") + .WithMany() + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("User"); + }); + + modelBuilder.Entity("Entity.Character", b => + { + b.HasOne("Entity.Images", "Images") + .WithMany("Characters") + .HasForeignKey("IdImage") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Images"); + }); + + modelBuilder.Entity("Entity.Commentary", b => + { + b.HasOne("Entity.Quote", "Quote") + .WithMany("Commentarys") + .HasForeignKey("IdQuote") + .OnDelete(DeleteBehavior.ClientCascade) + .IsRequired(); + + b.HasOne("Entity.Users", "User") + .WithMany() + .HasForeignKey("IdUser") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Quote"); + + b.Navigation("User"); + }); + + modelBuilder.Entity("Entity.Favorite", b => + { + b.HasOne("Entity.Quote", "Quote") + .WithMany() + .HasForeignKey("IdQuote") + .OnDelete(DeleteBehavior.ClientCascade) + .IsRequired(); + + b.HasOne("Entity.Users", "Users") + .WithMany() + .HasForeignKey("IdUsers") + .OnDelete(DeleteBehavior.ClientCascade) + .IsRequired(); + + b.Navigation("Quote"); + + b.Navigation("Users"); + }); + + modelBuilder.Entity("Entity.Quiz", b => + { + b.HasOne("Entity.Images", "Images") + .WithMany("Quizs") + .HasForeignKey("IdImage") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Images"); + }); + + modelBuilder.Entity("Entity.QuizQuestion", b => + { + b.HasOne("Entity.Question", null) + .WithMany() + .HasForeignKey("IdQuestion") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("Entity.Quiz", null) + .WithMany() + .HasForeignKey("IdQuiz") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("Entity.Quote", b => + { + b.HasOne("Entity.Character", "Character") + .WithMany("Quotes") + .HasForeignKey("IdCharacter") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("Entity.Source", "Source") + .WithMany("Quotes") + .HasForeignKey("IdSource") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("Entity.Users", "User") + .WithMany("Quotes") + .HasForeignKey("IdUsersPropose"); + + b.Navigation("Character"); + + b.Navigation("Source"); + + b.Navigation("User"); + }); + + modelBuilder.Entity("Entity.Users", b => + { + b.HasOne("Entity.Images", "Images") + .WithMany("Users") + .HasForeignKey("IdImage") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Images"); + }); + + modelBuilder.Entity("Entity.Character", b => + { + b.Navigation("Quotes"); + }); + + modelBuilder.Entity("Entity.Images", b => + { + b.Navigation("Characters"); + + b.Navigation("Quizs"); + + b.Navigation("Users"); + }); + + modelBuilder.Entity("Entity.Quote", b => + { + b.Navigation("Commentarys"); + }); + + modelBuilder.Entity("Entity.Source", b => + { + b.Navigation("Quotes"); + }); + + modelBuilder.Entity("Entity.Users", b => + { + b.Navigation("Quotes"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/WF_EF_Api/StubbedContextLib/Migrations/20250402105029_migration1.cs b/WF_EF_Api/StubbedContextLib/Migrations/20250402105029_migration1.cs new file mode 100644 index 0000000..8e69aba --- /dev/null +++ b/WF_EF_Api/StubbedContextLib/Migrations/20250402105029_migration1.cs @@ -0,0 +1,22 @@ +using Microsoft.EntityFrameworkCore.Migrations; + +#nullable disable + +namespace StubbedContextLib.Migrations +{ + /// + public partial class migration1 : Migration + { + /// + protected override void Up(MigrationBuilder migrationBuilder) + { + + } + + /// + protected override void Down(MigrationBuilder migrationBuilder) + { + + } + } +} diff --git a/WF_EF_Api/WfApi/Controllers/UsersController.cs b/WF_EF_Api/WfApi/Controllers/UsersController.cs index ea0f7ec..fac14f8 100644 --- a/WF_EF_Api/WfApi/Controllers/UsersController.cs +++ b/WF_EF_Api/WfApi/Controllers/UsersController.cs @@ -638,9 +638,9 @@ namespace WfApi.Controllers return NotFound(new { message = "Player not found." }); } - _user.RemoveUser(existingPlayer); + await _user.RemoveUser(id); - return Ok(new { message = $"Player {id} deleted successfully." }); + return Ok(new { message = $"User {id} deleted successfully." }); } catch (Exception) { From e3c668428e06e7c99a5548e6aad4aad4008d8cd3 Mon Sep 17 00:00:00 2001 From: kekentin Date: Wed, 2 Apr 2025 13:23:32 +0200 Subject: [PATCH 54/65] Debut correction route Quote --- WF_EF_Api/Contextlib/DbQuoteManager.cs | 17 ++++ WF_EF_Api/Contextlib/DbSourceManager.cs | 117 ++++++++++++++++++++++++ WF_EF_Api/Shared/ISourceService.cs | 5 +- 3 files changed, 136 insertions(+), 3 deletions(-) create mode 100644 WF_EF_Api/Contextlib/DbSourceManager.cs diff --git a/WF_EF_Api/Contextlib/DbQuoteManager.cs b/WF_EF_Api/Contextlib/DbQuoteManager.cs index 9be5119..4287574 100644 --- a/WF_EF_Api/Contextlib/DbQuoteManager.cs +++ b/WF_EF_Api/Contextlib/DbQuoteManager.cs @@ -16,11 +16,18 @@ namespace Contextlib { private WTFContext _context; private GenericRepository _repo; + private DbCharacterManager _dbC; + private DbSourceManager _dbS; + private DbImagesManager _dbI; public DbQuoteManager(WTFContext context) { _context = context ?? throw new ArgumentNullException(nameof(context), "Database context cannot be null."); _repo = new GenericRepository(_context); + _dbS = new DbSourceManager(_context); + _dbC = new DbCharacterManager(_context); + _dbI = new DbImagesManager(_context); + } @@ -30,6 +37,16 @@ namespace Contextlib { throw new ArgumentNullException(nameof(quote), "quote cannot be null."); } + var c = await _dbC.GetCharByName(quote.Character.Name); + if (c != null) + { + quote.IdCharacter = c.Id; + quote.Character = c; + } + + //Image + //Source + _repo.Insert(quote); await _context.SaveChangesAsync(); } diff --git a/WF_EF_Api/Contextlib/DbSourceManager.cs b/WF_EF_Api/Contextlib/DbSourceManager.cs new file mode 100644 index 0000000..707a0bf --- /dev/null +++ b/WF_EF_Api/Contextlib/DbSourceManager.cs @@ -0,0 +1,117 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Entity; +using Shared; + +namespace Contextlib +{ + internal class DbSourceManager : ISourceService + { + private WTFContext _context; + private GenericRepository _repo; + + public DbSourceManager(WTFContext context) + { + _context = context ?? throw new ArgumentNullException(nameof(context), "Database context cannot be null."); + _repo = new GenericRepository(_context); + } + + public async Task AddSource(Source source) + { + if (source == null) + { + throw new ArgumentNullException(nameof(source), "character cannot be null."); + } + _repo.Insert(source); + await _context.SaveChangesAsync(); + } + + public async Task> GetAll() + { + List srcLst = _repo.GetItems(0, _repo.Count(), []).ToList(); + return new PaginationResult(srcLst.Count, 0, srcLst.Count, srcLst); + } + + public async Task GetLastSourceId() + { + throw new NotImplementedException(); + } + + public async Task> GetSourceByDate(int date) + { + + var srcLst = _repo.GetItems(item => item.Year == date, 0, _repo.Count(), []).ToList(); + + return new PaginationResult(srcLst.Count, 0, srcLst.Count, srcLst); + } + + public async Task GetSourceById(int id) + { + Source? source = _repo.GetById(id, item => item.Id == id, []); + if (source == null) + { + throw new KeyNotFoundException($"Error : No source found with the ID: {id}."); + } + return source; + } + + public async Task GetSourceByTitle(string title) + { + var source = _repo.GetItems(item => item.Title == title, 0, 1, []).FirstOrDefault(); + + if (source == null) + { + throw new KeyNotFoundException($"Error : No source found with the title: {title}."); + } + + return source; + } + + public async Task GetSourceByType(int type) + { + var source = _repo.GetItems(item => item.TypeSrc == (TypeSrcEnum)type, 0, 1, []).FirstOrDefault(); + + if (source == null) + { + throw new KeyNotFoundException($"Error : No source found with the type: {(TypeSrcEnum)type}."); + } + + return source; + } + + public async Task RemoveSource(int id) + { + _repo.Delete(id); + await _context.SaveChangesAsync(); + } + + public async Task UpdateSource(int id, Source source) + { + Source? src = _repo.GetById(id); + if (src != null) + { + bool change = false; + if (src.Title != source.Title) + { + src.Title = source.Title; + change = true; + } + if (src.Year != source.Year) + { + src.Year = source.Year; + change = true; + } + if (src.TypeSrc != source.TypeSrc) + { + src.TypeSrc = source.TypeSrc; + change = true; + } + _repo.Update(src); + if (change) _context.SaveChanges(); + } + } + } +} diff --git a/WF_EF_Api/Shared/ISourceService.cs b/WF_EF_Api/Shared/ISourceService.cs index 228078e..9657db7 100644 --- a/WF_EF_Api/Shared/ISourceService.cs +++ b/WF_EF_Api/Shared/ISourceService.cs @@ -18,11 +18,10 @@ namespace Shared // Retrieves a source by its date. // 'date' is the date associated with the source to be retrieved. - Task GetSourceByDate(string date); - + Task> GetSourceByDate(int date); // Retrieves a source by its type. // 'type' is the type of the source to be retrieved. - Task GetSourceByType(string type); + Task GetSourceByType(int type); // Retrieves all sources, with pagination support. // This returns a list of all sources in the system. From a263050ab6c96595e3adcfafbc7bfcaca5567ab1 Mon Sep 17 00:00:00 2001 From: kekentin Date: Wed, 2 Apr 2025 14:56:47 +0200 Subject: [PATCH 55/65] fininalisation Route Quote --- WF_EF_Api/Contextlib/DbCharacterManager.cs | 7 +--- WF_EF_Api/Contextlib/DbImagesManager.cs | 2 +- WF_EF_Api/Contextlib/DbQuoteManager.cs | 39 ++++++++++++++++++- WF_EF_Api/Contextlib/DbSourceManager.cs | 14 +------ WF_EF_Api/ServicesApi/QuoteService.cs | 4 +- WF_EF_Api/ServicesApi/SourceService.cs | 8 ++-- WF_EF_Api/Shared/IQuoteService.cs | 2 +- WF_EF_Api/StubApi/QuoteServiceStub.cs | 3 +- .../WfApi/Controllers/QuotesController.cs | 2 +- WF_EF_Api/XUnitTest/ApiUnitTest.cs | 2 +- 10 files changed, 53 insertions(+), 30 deletions(-) diff --git a/WF_EF_Api/Contextlib/DbCharacterManager.cs b/WF_EF_Api/Contextlib/DbCharacterManager.cs index e81dc1d..7d01f7f 100644 --- a/WF_EF_Api/Contextlib/DbCharacterManager.cs +++ b/WF_EF_Api/Contextlib/DbCharacterManager.cs @@ -68,15 +68,10 @@ namespace Contextlib /// The name of the character to retrieve. /// A task that represents the asynchronous operation, with a as its result. /// Thrown when no character is found with the given name. - public async Task GetCharByName(string name) + public async Task GetCharByName(string name) { var character = _repo.GetItems(item => item.Name == name,0,1, [nameof(Character.Images)]).FirstOrDefault(); - if (character == null) - { - throw new KeyNotFoundException($"Error : No character found with the name: {name}."); - } - return character; } diff --git a/WF_EF_Api/Contextlib/DbImagesManager.cs b/WF_EF_Api/Contextlib/DbImagesManager.cs index 6afd953..e549cf9 100644 --- a/WF_EF_Api/Contextlib/DbImagesManager.cs +++ b/WF_EF_Api/Contextlib/DbImagesManager.cs @@ -33,7 +33,7 @@ namespace Contextlib return new PaginationResult(await CountImage(), 0, await CountImage(), _repository.GetItems(0, await CountImage()).ToList()); } - public async Task GetImageById(int id) + public async Task GetImageById(int id) { return _repository.GetById(id); } diff --git a/WF_EF_Api/Contextlib/DbQuoteManager.cs b/WF_EF_Api/Contextlib/DbQuoteManager.cs index 4287574..0a4236a 100644 --- a/WF_EF_Api/Contextlib/DbQuoteManager.cs +++ b/WF_EF_Api/Contextlib/DbQuoteManager.cs @@ -31,24 +31,37 @@ namespace Contextlib } - public async Task AddQuote(Quote quote) + public async Task AddQuote(Quote quote) { if (quote == null) { throw new ArgumentNullException(nameof(quote), "quote cannot be null."); } + //Character var c = await _dbC.GetCharByName(quote.Character.Name); if (c != null) { quote.IdCharacter = c.Id; quote.Character = c; } - //Image + var i = await _dbI.GetImageByPath(quote.Character.Images.ImgPath); + if (i != null) + { + quote.Character.IdImage = i.Id; + quote.Character.Images = i; + } //Source + var s = await _dbS.GetSourceByTitle(quote.Source.Title); + if (s != null) + { + quote.IdSource = s.Id; + quote.Source = s; + } _repo.Insert(quote); await _context.SaveChangesAsync(); + return quote; } public async Task> GetAllQuote() @@ -197,6 +210,28 @@ namespace Contextlib public async Task UpdateQuote(int quoteId, Quote quote) { + //Character + var c = await _dbC.GetCharByName(quote.Character.Name); + if (c != null) + { + quote.IdCharacter = c.Id; + quote.Character = c; + } + //Image + var i = await _dbI.GetImageByPath(quote.Character.Images.ImgPath); + if (c != null) + { + quote.Character.IdImage = i.Id; + quote.Character.Images = i; + } + //Source + var s = await _dbS.GetSourceByTitle(quote.Source.Title); + if (c != null) + { + quote.IdSource = s.Id; + quote.Source = s; + } + Quote? q = _repo.GetById(quoteId); if (q != null) { diff --git a/WF_EF_Api/Contextlib/DbSourceManager.cs b/WF_EF_Api/Contextlib/DbSourceManager.cs index 707a0bf..c40f04e 100644 --- a/WF_EF_Api/Contextlib/DbSourceManager.cs +++ b/WF_EF_Api/Contextlib/DbSourceManager.cs @@ -58,27 +58,17 @@ namespace Contextlib return source; } - public async Task GetSourceByTitle(string title) + public async Task GetSourceByTitle(string title) { var source = _repo.GetItems(item => item.Title == title, 0, 1, []).FirstOrDefault(); - if (source == null) - { - throw new KeyNotFoundException($"Error : No source found with the title: {title}."); - } - return source; } - public async Task GetSourceByType(int type) + public async Task GetSourceByType(int type) { var source = _repo.GetItems(item => item.TypeSrc == (TypeSrcEnum)type, 0, 1, []).FirstOrDefault(); - if (source == null) - { - throw new KeyNotFoundException($"Error : No source found with the type: {(TypeSrcEnum)type}."); - } - return source; } diff --git a/WF_EF_Api/ServicesApi/QuoteService.cs b/WF_EF_Api/ServicesApi/QuoteService.cs index cdf66a2..7538781 100644 --- a/WF_EF_Api/ServicesApi/QuoteService.cs +++ b/WF_EF_Api/ServicesApi/QuoteService.cs @@ -20,9 +20,9 @@ namespace ServicesApi quoteService = quote; } - public async Task AddQuote(QuoteDTO quote) + public async Task AddQuote(QuoteDTO quote) { - await quoteService.AddQuote(quote.ToEntity()); + return (await quoteService.AddQuote(quote.ToEntity())).ToDto(); } public async Task> GetAllQuote() diff --git a/WF_EF_Api/ServicesApi/SourceService.cs b/WF_EF_Api/ServicesApi/SourceService.cs index f767fdc..4a7c8fc 100644 --- a/WF_EF_Api/ServicesApi/SourceService.cs +++ b/WF_EF_Api/ServicesApi/SourceService.cs @@ -36,9 +36,11 @@ namespace ServicesApi return await srcService.GetLastSourceId(); } - public async Task GetSourceByDate(string date) + public async Task> GetSourceByDate(int date) { - return srcService.GetSourceByDate(date).Result.ToDto(); + var sources = ( await srcService.GetSourceByDate(date)).items; + return new PaginationResult(sources.Count(), 0, 10, sources.ToDto()); + } public async Task GetSourceById(int id) @@ -51,7 +53,7 @@ namespace ServicesApi return srcService.GetSourceByTitle(title).Result.ToDto(); } - public async Task GetSourceByType(string type) + public async Task GetSourceByType(int type) { return srcService.GetSourceByType(type).Result.ToDto(); } diff --git a/WF_EF_Api/Shared/IQuoteService.cs b/WF_EF_Api/Shared/IQuoteService.cs index c37fb5a..4632463 100644 --- a/WF_EF_Api/Shared/IQuoteService.cs +++ b/WF_EF_Api/Shared/IQuoteService.cs @@ -76,7 +76,7 @@ namespace Shared // Adds a new quote. // 'quote' is the quote object that will be added. - Task AddQuote(TQuote quote); + Task AddQuote(TQuote quote); // Updates an existing quote identified by 'quoteId' with new details. // 'quoteId' is the ID of the quote to be updated diff --git a/WF_EF_Api/StubApi/QuoteServiceStub.cs b/WF_EF_Api/StubApi/QuoteServiceStub.cs index f0521b3..f06a6e1 100644 --- a/WF_EF_Api/StubApi/QuoteServiceStub.cs +++ b/WF_EF_Api/StubApi/QuoteServiceStub.cs @@ -39,9 +39,10 @@ namespace StubApi }; } - public async Task AddQuote(QuoteDTO quote) + public async Task AddQuote(QuoteDTO quote) { _quotes.Add(quote); + return quote; } public async Task> GetAllQuote() diff --git a/WF_EF_Api/WfApi/Controllers/QuotesController.cs b/WF_EF_Api/WfApi/Controllers/QuotesController.cs index 1eda2f1..a43866b 100644 --- a/WF_EF_Api/WfApi/Controllers/QuotesController.cs +++ b/WF_EF_Api/WfApi/Controllers/QuotesController.cs @@ -272,7 +272,7 @@ namespace WfApi.Controllers return Conflict(new { message = "Une quote avec cet ID existe déjà." }); } newQuote.IsValide=false; - var quote=_quote.AddQuote(newQuote); + var quote=await _quote.AddQuote(newQuote); return CreatedAtAction(nameof(CreateQuote), new { id = newQuote.Id }, quote); } diff --git a/WF_EF_Api/XUnitTest/ApiUnitTest.cs b/WF_EF_Api/XUnitTest/ApiUnitTest.cs index 6ab3df3..7591909 100644 --- a/WF_EF_Api/XUnitTest/ApiUnitTest.cs +++ b/WF_EF_Api/XUnitTest/ApiUnitTest.cs @@ -268,7 +268,7 @@ namespace XUnitTest _mockUserService.Setup(service => service.GetUserById(id)).ReturnsAsync(existingPlayer); - _mockUserService.Setup(service => service.RemoveUser(existingPlayer)).Verifiable(); + _mockUserService.Setup(service => service.RemoveUser(existingPlayer.Id)).Verifiable(); // Act var result = await _userController.DeletePlayer(id); From ff3a1a0efa367c9ca0de4506d9fc70daca269ec4 Mon Sep 17 00:00:00 2001 From: kekentin Date: Wed, 2 Apr 2025 16:04:21 +0200 Subject: [PATCH 56/65] mise a jour route --- WF_EF_Api/Contextlib/DbSourceManager.cs | 2 +- WF_EF_Api/Shared/IFavoriteService.cs | 6 +- .../Migrations/StubWTFContextModelSnapshot.cs | 28 ++-- .../WfApi/Controllers/FavoriteControleur.cs | 125 ++++++++++++++++++ WF_EF_Api/WfApi/Program.cs | 4 +- 5 files changed, 148 insertions(+), 17 deletions(-) create mode 100644 WF_EF_Api/WfApi/Controllers/FavoriteControleur.cs diff --git a/WF_EF_Api/Contextlib/DbSourceManager.cs b/WF_EF_Api/Contextlib/DbSourceManager.cs index c40f04e..6f470f7 100644 --- a/WF_EF_Api/Contextlib/DbSourceManager.cs +++ b/WF_EF_Api/Contextlib/DbSourceManager.cs @@ -8,7 +8,7 @@ using Shared; namespace Contextlib { - internal class DbSourceManager : ISourceService + public class DbSourceManager : ISourceService { private WTFContext _context; private GenericRepository _repo; diff --git a/WF_EF_Api/Shared/IFavoriteService.cs b/WF_EF_Api/Shared/IFavoriteService.cs index 3b2de7f..08a32de 100644 --- a/WF_EF_Api/Shared/IFavoriteService.cs +++ b/WF_EF_Api/Shared/IFavoriteService.cs @@ -1,12 +1,13 @@ using System; using System.Collections.Generic; using System.Linq; +using System.Reflection; using System.Text; using System.Threading.Tasks; namespace Shared { - public interface IFavoriteService + public interface IFavoriteService { // Adds a quote to a user's list of favorites. // 'quoteid' is the unique identifier of the quote to be added to favorites. @@ -25,5 +26,8 @@ namespace Shared // Removes a specific quote from the favorite lists of all users. // 'quoteId' is the unique identifier of the quote to be removed from all users' favorites. Task RemoveAllFavoriteForQuote(int quoteId); + + Task> GetFavoriteByIdUser(int userId, int index, int count); + Task GetFavorite(int userId, int idQuote); } } diff --git a/WF_EF_Api/StubbedContextLib/Migrations/StubWTFContextModelSnapshot.cs b/WF_EF_Api/StubbedContextLib/Migrations/StubWTFContextModelSnapshot.cs index 37b2e66..08ef8a9 100644 --- a/WF_EF_Api/StubbedContextLib/Migrations/StubWTFContextModelSnapshot.cs +++ b/WF_EF_Api/StubbedContextLib/Migrations/StubWTFContextModelSnapshot.cs @@ -127,11 +127,11 @@ namespace StubbedContextLib.Migrations modelBuilder.Entity("Entity.Commentary", b => { - b.Property("IdUser") + b.Property("Id") + .ValueGeneratedOnAdd() .HasColumnType("int"); - b.Property("IdQuote") - .HasColumnType("int"); + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); b.Property("Comment") .IsRequired() @@ -142,34 +142,36 @@ namespace StubbedContextLib.Migrations .HasColumnType("date") .HasColumnName("DateCommentary"); - b.Property("Id") - .ValueGeneratedOnAdd() + b.Property("IdQuote") .HasColumnType("int"); - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + b.Property("IdUser") + .HasColumnType("int"); - b.HasKey("IdUser", "IdQuote"); + b.HasKey("Id"); b.HasIndex("IdQuote"); + b.HasIndex("IdUser"); + b.ToTable("comments"); b.HasData( new { - IdUser = 2, - IdQuote = 1, + Id = 1, Comment = "Ce film est le meilleur", DateCommentary = new DateTime(2025, 2, 3, 0, 0, 0, 0, DateTimeKind.Unspecified), - Id = 1 + IdQuote = 1, + IdUser = 2 }, new { - IdUser = 3, - IdQuote = 1, + Id = 2, Comment = "Very good", DateCommentary = new DateTime(2025, 3, 11, 0, 0, 0, 0, DateTimeKind.Unspecified), - Id = 2 + IdQuote = 1, + IdUser = 3 }); }); diff --git a/WF_EF_Api/WfApi/Controllers/FavoriteControleur.cs b/WF_EF_Api/WfApi/Controllers/FavoriteControleur.cs new file mode 100644 index 0000000..2529717 --- /dev/null +++ b/WF_EF_Api/WfApi/Controllers/FavoriteControleur.cs @@ -0,0 +1,125 @@ +using System.Net; +using DTO; +using Entity; +using Microsoft.AspNetCore.Mvc; +using ServicesApi; +using Shared; + +namespace WfApi.Controllers +{ + [ApiController] + [Route("api/v1/favorite")] //Version API + public class FavoriteControleur : ControllerBase + { + private readonly IFavoriteService _favorite; + + private readonly ILogger _logger; + public FavoriteControleur(IFavoriteService favoriteService, ILogger logger) + { + _favorite = favoriteService; + _logger = logger; + } + + + + [HttpGet("{id}")] // Indiquer que l'id est dans l'URL + public async Task GetFavoriteByIdUser(int id, int index = 0, int count = 10) + { + try + { + var result = await _favorite.GetFavoriteByIdUser(id, index, count); + + if (result != null) + { + return await Task.FromResult(Ok(result)); + } + else + { + return NoContent(); + } + } + catch (Exception) + { + return StatusCode((int)HttpStatusCode.InternalServerError, new { message = "Internal Server Error" }); + } + } + + [HttpPost] + [ProducesResponseType(StatusCodes.Status201Created)] + [ProducesResponseType(StatusCodes.Status400BadRequest)] + [ProducesResponseType(StatusCodes.Status409Conflict)] + [ProducesResponseType(StatusCodes.Status500InternalServerError)] + public async Task CreateFavorite(int idUser , int idQuote) + { + try + { + + var existingFavorite = _favorite.GetFavorite(idUser,idQuote).Result; + if (existingFavorite != null) + { + return Conflict(new { message = "A favorite with this ID already exists." }); + } + + await _favorite.AddFavorite(idUser, idQuote); + var fav = new Favorite(); + fav.IdQuote = idQuote; + fav.IdUsers = idUser; + return CreatedAtAction(nameof(GetFavoriteByIdUser), new { id = idUser }, fav); + } + catch (Exception) + { + return StatusCode((int)HttpStatusCode.InternalServerError, new { message = "Erreur interne du serveur." }); + } + } + + + [HttpDelete] // /api/v1/commentary?id=51 + [ProducesResponseType(StatusCodes.Status200OK)] + [ProducesResponseType(StatusCodes.Status404NotFound)] + [ProducesResponseType(StatusCodes.Status500InternalServerError)] + public async Task DeleteFavorite([FromQuery] int idUser, [FromQuery] int idQuote) + { + try + { + + var existingFavorite = await _favorite.GetFavorite(idUser, idQuote); + if (existingFavorite == null) + { + return NotFound(new { message = "Commentary not found." }); + } + + await _favorite.RemoveFavorite(idUser, idQuote); + + return Ok(new { message = $"Favorite from user {idUser} and quote {idQuote} deleted successfully." }); + } + catch (Exception) + { + return StatusCode((int)HttpStatusCode.InternalServerError, new { message = "Internal server error." }); + } + } + [HttpDelete] // /api/v1/commentary?id=51 + [ProducesResponseType(StatusCodes.Status200OK)] + [ProducesResponseType(StatusCodes.Status404NotFound)] + [ProducesResponseType(StatusCodes.Status500InternalServerError)] + public async Task DeleteFavorite([FromQuery] int idUser, [FromQuery] int idQuote) + { + try + { + + var existingFavorite = await _favorite.GetFavorite(idUser, idQuote); + if (existingFavorite == null) + { + return NotFound(new { message = "Commentary not found." }); + } + + await _favorite.RemoveFavorite(idUser, idQuote); + + return Ok(new { message = $"Favorite from user {idUser} and quote {idQuote} deleted successfully." }); + } + catch (Exception) + { + return StatusCode((int)HttpStatusCode.InternalServerError, new { message = "Internal server error." }); + } + } + } +} diff --git a/WF_EF_Api/WfApi/Program.cs b/WF_EF_Api/WfApi/Program.cs index f4dd552..6d308be 100644 --- a/WF_EF_Api/WfApi/Program.cs +++ b/WF_EF_Api/WfApi/Program.cs @@ -15,7 +15,7 @@ builder.Services.AddScoped, QuoteService>(); builder.Services.AddScoped, CommentaryService>(); builder.Services.AddScoped, CharacterService>(); builder.Services.AddScoped, ImageService>(); -//builder.Services.AddScoped, SourceService>(); +builder.Services.AddScoped, SourceService>(); builder.Services.AddScoped, QuestionService>(); @@ -28,7 +28,7 @@ builder.Services.AddScoped, DbQuoteManager>(); builder.Services.AddScoped, DbCommentaryManager>(); builder.Services.AddScoped, DbCharacterManager>(); builder.Services.AddScoped, DbImagesManager>(); -//builder.Services.AddScoped, DbSourceManager>(); +builder.Services.AddScoped, DbSourceManager>(); builder.Services.AddScoped, DbQuestionManager>(); //... From 6e1825f6ff83d8bc861c8146f43aaf1859bd3ea3 Mon Sep 17 00:00:00 2001 From: Kevin MONDEJAR Date: Wed, 2 Apr 2025 16:06:05 +0200 Subject: [PATCH 57/65] fin route comment + debut Source --- WF_EF_Api/Contextlib/DbCommentaryManager.cs | 26 +- WF_EF_Api/Contextlib/WTFContext.cs | 2 +- WF_EF_Api/Dto2Entities/Extention.cs | 2 + WF_EF_Api/ServicesApi/CommentaryService.cs | 9 +- WF_EF_Api/ServicesApi/SourceService.cs | 7 +- .../20250317163102_migrationTest1.Designer.cs | 1065 ---------------- .../20250318135625_migr1.Designer.cs | 1065 ---------------- .../Migrations/20250318135625_migr1.cs | 22 - .../20250328102709_migr5.Designer.cs | 1107 ----------------- .../Migrations/20250328102709_migr5.cs | 126 -- .../20250401141906_suprDailyQuote.cs | 61 - ...0250401143030_myFirstMigration.Designer.cs | 1107 ----------------- .../20250401143030_myFirstMigration.cs | 32 - .../20250402084447_migration2-04.Designer.cs | 1074 ---------------- .../20250402084447_migration2-04.cs | 22 - .../Migrations/20250402105029_migration1.cs | 22 - ...r.cs => 20250402113707_pm_api.Designer.cs} | 4 +- ...ationTest1.cs => 20250402113707_pm_api.cs} | 83 +- ...cs => 20250402134601_pm_apiV2.Designer.cs} | 32 +- .../Migrations/20250402134601_pm_apiV2.cs | 86 ++ .../Migrations/StubWTFContextModelSnapshot.cs | 28 +- .../StubbedContextLib.csproj | 4 + .../Controllers/CommentariesController.cs | 14 +- .../WfApi/Controllers/QuotesController.cs | 6 +- .../WfApi/Controllers/SourceController.cs | 84 ++ 25 files changed, 293 insertions(+), 5797 deletions(-) delete mode 100644 WF_EF_Api/StubbedContextLib/Migrations/20250317163102_migrationTest1.Designer.cs delete mode 100644 WF_EF_Api/StubbedContextLib/Migrations/20250318135625_migr1.Designer.cs delete mode 100644 WF_EF_Api/StubbedContextLib/Migrations/20250318135625_migr1.cs delete mode 100644 WF_EF_Api/StubbedContextLib/Migrations/20250328102709_migr5.Designer.cs delete mode 100644 WF_EF_Api/StubbedContextLib/Migrations/20250328102709_migr5.cs delete mode 100644 WF_EF_Api/StubbedContextLib/Migrations/20250401141906_suprDailyQuote.cs delete mode 100644 WF_EF_Api/StubbedContextLib/Migrations/20250401143030_myFirstMigration.Designer.cs delete mode 100644 WF_EF_Api/StubbedContextLib/Migrations/20250401143030_myFirstMigration.cs delete mode 100644 WF_EF_Api/StubbedContextLib/Migrations/20250402084447_migration2-04.Designer.cs delete mode 100644 WF_EF_Api/StubbedContextLib/Migrations/20250402084447_migration2-04.cs delete mode 100644 WF_EF_Api/StubbedContextLib/Migrations/20250402105029_migration1.cs rename WF_EF_Api/StubbedContextLib/Migrations/{20250402105029_migration1.Designer.cs => 20250402113707_pm_api.Designer.cs} (97%) rename WF_EF_Api/StubbedContextLib/Migrations/{20250317163102_migrationTest1.cs => 20250402113707_pm_api.cs} (90%) rename WF_EF_Api/StubbedContextLib/Migrations/{20250401141906_suprDailyQuote.Designer.cs => 20250402134601_pm_apiV2.Designer.cs} (96%) create mode 100644 WF_EF_Api/StubbedContextLib/Migrations/20250402134601_pm_apiV2.cs create mode 100644 WF_EF_Api/WfApi/Controllers/SourceController.cs diff --git a/WF_EF_Api/Contextlib/DbCommentaryManager.cs b/WF_EF_Api/Contextlib/DbCommentaryManager.cs index 78f7ae4..bac04e3 100644 --- a/WF_EF_Api/Contextlib/DbCommentaryManager.cs +++ b/WF_EF_Api/Contextlib/DbCommentaryManager.cs @@ -38,20 +38,28 @@ namespace Contextlib .Include(q => q.Commentarys) // collection des commentaires est chargée .FirstOrDefaultAsync(q => q.Id == idQuote); + var dbU = new DbUsersManager(_context); + var User = await dbU.GetUserByUsername(comment.User.UserName); + if (User == null) + { + throw new ArgumentException("Quote not exist", nameof(comment.User.UserName)); + } + if (quote == null) { throw new ArgumentException("Quote not exist", nameof(idQuote)); } + comment.User = User; + comment.IdUser = User.Id; + // Lien entre le commentaire et la citation comment.Quote = quote; comment.IdQuote = idQuote; - // Ajout commentaire à la collection des commentaires de la citation - quote.Commentarys.Add(comment); - - - _repo.Insert(comment); + // Ajout commentaire à la collection des commentaires de la citation + //_repo.Insert(comment); + _context.Add(comment); await _context.SaveChangesAsync(); } @@ -163,7 +171,13 @@ namespace Contextlib public async Task RemoveCommentary(int id) { - _repo.Delete(id); + + Commentary? commentary = await GetCommentaryById(id); + if (commentary == null) + { + throw new KeyNotFoundException($"Error : No comment found with the ID: {id}."); + } + _repo.Delete(commentary); await _context.SaveChangesAsync(); } diff --git a/WF_EF_Api/Contextlib/WTFContext.cs b/WF_EF_Api/Contextlib/WTFContext.cs index 1a765f7..af9c12a 100644 --- a/WF_EF_Api/Contextlib/WTFContext.cs +++ b/WF_EF_Api/Contextlib/WTFContext.cs @@ -53,7 +53,7 @@ namespace Contextlib .HasMany() .WithMany() .UsingEntity( - i => i.HasKey(e => new { e.IdUser, e.IdQuote }) + i => i.HasKey(e => e.Id) ); modelBuilder.Entity() diff --git a/WF_EF_Api/Dto2Entities/Extention.cs b/WF_EF_Api/Dto2Entities/Extention.cs index 1687d94..6392fd3 100644 --- a/WF_EF_Api/Dto2Entities/Extention.cs +++ b/WF_EF_Api/Dto2Entities/Extention.cs @@ -270,7 +270,9 @@ namespace Dto2Entities commentary.Id = item.Id; commentary.DateCommentary = item.Date; commentary.Comment = item.Comment; + commentary.User = new Users(); commentary.User.UserName = item.User; + commentary.User.Images = new Images(); commentary.User.Images.ImgPath = item.ImagePath; return commentary; } diff --git a/WF_EF_Api/ServicesApi/CommentaryService.cs b/WF_EF_Api/ServicesApi/CommentaryService.cs index e151c03..4758ba6 100644 --- a/WF_EF_Api/ServicesApi/CommentaryService.cs +++ b/WF_EF_Api/ServicesApi/CommentaryService.cs @@ -42,7 +42,14 @@ namespace ServicesApi public async Task GetCommentaryById(int id) { - return commentaryService.GetCommentaryById(id).Result.ToDto(); + try + { + return (await commentaryService.GetCommentaryById(id)).ToDto(); + } + catch(KeyNotFoundException) + { + throw new KeyNotFoundException($"No comments found with the given ID: {id}."); + } } public async Task> GetCommentaryByQuote(int quoteId, int index, int pageSize) diff --git a/WF_EF_Api/ServicesApi/SourceService.cs b/WF_EF_Api/ServicesApi/SourceService.cs index f767fdc..217c2ad 100644 --- a/WF_EF_Api/ServicesApi/SourceService.cs +++ b/WF_EF_Api/ServicesApi/SourceService.cs @@ -36,9 +36,10 @@ namespace ServicesApi return await srcService.GetLastSourceId(); } - public async Task GetSourceByDate(string date) + public async Task> GetSourceByDate(int date) { - return srcService.GetSourceByDate(date).Result.ToDto(); + var sources = (await srcService.GetSourceByDate(date)).items; + return new PaginationResult(sources.Count(), 0, 10, sources.ToDto()); } public async Task GetSourceById(int id) @@ -51,7 +52,7 @@ namespace ServicesApi return srcService.GetSourceByTitle(title).Result.ToDto(); } - public async Task GetSourceByType(string type) + public async Task GetSourceByType(int type) { return srcService.GetSourceByType(type).Result.ToDto(); } diff --git a/WF_EF_Api/StubbedContextLib/Migrations/20250317163102_migrationTest1.Designer.cs b/WF_EF_Api/StubbedContextLib/Migrations/20250317163102_migrationTest1.Designer.cs deleted file mode 100644 index e352e28..0000000 --- a/WF_EF_Api/StubbedContextLib/Migrations/20250317163102_migrationTest1.Designer.cs +++ /dev/null @@ -1,1065 +0,0 @@ -// -using System; -using Microsoft.EntityFrameworkCore; -using Microsoft.EntityFrameworkCore.Infrastructure; -using Microsoft.EntityFrameworkCore.Metadata; -using Microsoft.EntityFrameworkCore.Migrations; -using Microsoft.EntityFrameworkCore.Storage.ValueConversion; -using StubbedContextLib; - -#nullable disable - -namespace StubbedContextLib.Migrations -{ - [DbContext(typeof(StubWTFContext))] - [Migration("20250317163102_migrationTest1")] - partial class migrationTest1 - { - /// - protected override void BuildTargetModel(ModelBuilder modelBuilder) - { -#pragma warning disable 612, 618 - modelBuilder - .HasAnnotation("ProductVersion", "9.0.3") - .HasAnnotation("Relational:MaxIdentifierLength", 128); - - SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder); - - modelBuilder.Entity("Entity.Character", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("int"); - - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); - - b.Property("IdImage") - .HasColumnType("int"); - - b.Property("Name") - .IsRequired() - .HasMaxLength(50) - .HasColumnType("nvarchar(50)"); - - b.HasKey("Id"); - - b.HasIndex("IdImage"); - - b.ToTable("characters"); - - b.HasData( - new - { - Id = 1, - IdImage = 1, - Name = "Alan Grant" - }, - new - { - Id = 2, - IdImage = 2, - Name = "Aragorn" - }, - new - { - Id = 3, - IdImage = 3, - Name = "Legolas" - }, - new - { - Id = 4, - IdImage = 4, - Name = "Frodon" - }, - new - { - Id = 5, - IdImage = 5, - Name = "Dobby" - }, - new - { - Id = 6, - IdImage = 6, - Name = "Jon Snow" - }, - new - { - Id = 7, - IdImage = 7, - Name = "Daenerys Targaryen" - }, - new - { - Id = 8, - IdImage = 8, - Name = "Luke Skywalker" - }, - new - { - Id = 9, - IdImage = 9, - Name = "Princess Leia" - }, - new - { - Id = 10, - IdImage = 10, - Name = "Harry Potter" - }); - }); - - modelBuilder.Entity("Entity.Commentary", b => - { - b.Property("IdUser") - .HasColumnType("int"); - - b.Property("IdQuote") - .HasColumnType("int"); - - b.Property("Comment") - .IsRequired() - .HasMaxLength(100) - .HasColumnType("nvarchar(100)"); - - b.Property("DateCommentary") - .HasColumnType("date") - .HasColumnName("DateCommentary"); - - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("int"); - - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); - - b.HasKey("IdUser", "IdQuote"); - - b.HasIndex("IdQuote"); - - b.ToTable("comments"); - - b.HasData( - new - { - IdUser = 2, - IdQuote = 1, - Comment = "Ce film est le meilleur", - DateCommentary = new DateTime(2025, 2, 3, 0, 0, 0, 0, DateTimeKind.Unspecified), - Id = 1 - }, - new - { - IdUser = 3, - IdQuote = 1, - Comment = "Very good", - DateCommentary = new DateTime(2025, 3, 11, 0, 0, 0, 0, DateTimeKind.Unspecified), - Id = 2 - }); - }); - - modelBuilder.Entity("Entity.DailyQuote", b => - { - b.Property("IdQuote") - .HasColumnType("int"); - - b.HasKey("IdQuote"); - - b.ToTable("dailyquotes"); - - b.HasData( - new - { - IdQuote = 1 - }, - new - { - IdQuote = 5 - }); - }); - - modelBuilder.Entity("Entity.Favorite", b => - { - b.Property("IdQuote") - .HasColumnType("int"); - - b.Property("IdUsers") - .HasColumnType("int"); - - b.HasKey("IdQuote", "IdUsers"); - - b.HasIndex("IdUsers"); - - b.ToTable("favorites"); - - b.HasData( - new - { - IdQuote = 2, - IdUsers = 8 - }, - new - { - IdQuote = 5, - IdUsers = 3 - }, - new - { - IdQuote = 9, - IdUsers = 1 - }, - new - { - IdQuote = 4, - IdUsers = 10 - }, - new - { - IdQuote = 3, - IdUsers = 2 - }, - new - { - IdQuote = 6, - IdUsers = 7 - }, - new - { - IdQuote = 1, - IdUsers = 6 - }, - new - { - IdQuote = 8, - IdUsers = 9 - }, - new - { - IdQuote = 10, - IdUsers = 5 - }); - }); - - modelBuilder.Entity("Entity.Images", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("int"); - - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); - - b.Property("ImgPath") - .IsRequired() - .HasColumnType("nvarchar(max)"); - - b.HasKey("Id"); - - b.ToTable("images"); - - b.HasData( - new - { - Id = 1, - ImgPath = "https://th.bing.com/th/id/OIP.TJuWNCsibz8MVmhdNQEdMwHaE8?w=244&h=180&c=7&r=0&o=5&pid=1.7" - }, - new - { - Id = 2, - ImgPath = "https://th.bing.com/th/id/OIP.NgXRQ5-IknA6_qOPFhLWIwHaHK?w=165&h=180&c=7&r=0&o=5&pid=1.7" - }, - new - { - Id = 3, - ImgPath = "https://th.bing.com/th/id/OIP.XcJoJ6bC9sAMjol1pJn5UQHaLH?w=118&h=180&c=7&r=0&o=5&pid=1.7" - }, - new - { - Id = 4, - ImgPath = "https://th.bing.com/th/id/OIP.PPIESqZaNDa-qUcfSDXhdQHaGK?w=210&h=180&c=7&r=0&o=5&pid=1.7" - }, - new - { - Id = 5, - ImgPath = "https://th.bing.com/th/id/OIP.XBghSl2kfRNNtQoSxc901wHaHa?w=177&h=180&c=7&r=0&o=5&pid=1.7" - }, - new - { - Id = 6, - ImgPath = "https://th.bing.com/th/id/OIP.af1Aid64cqEKoIOBgCPxtQHaJO?w=145&h=182&c=7&r=0&o=5&pid=1.7" - }, - new - { - Id = 7, - ImgPath = "https://th.bing.com/th/id/OIP.ri5vSXr5lNTLt4DO6KQXyQHaI4?w=158&h=189&c=7&r=0&o=5&pid=1.7" - }, - new - { - Id = 8, - ImgPath = "https://th.bing.com/th/id/OIP.uPTRLR8uspCiafiunUqKfQHaMJ?w=115&h=180&c=7&r=0&o=5&pid=1.7" - }, - new - { - Id = 9, - ImgPath = "https://th.bing.com/th/id/OIP.hcJis4rKbyQtugsoFJU2ngHaM_?w=118&h=207&c=7&r=0&o=5&pid=1.7" - }, - new - { - Id = 10, - ImgPath = "https://th.bing.com/th/id/OIP.Py1_XfUrKJY_A6tYEmFS5wHaE8?w=280&h=187&c=7&r=0&o=5&pid=1.7" - }); - }); - - modelBuilder.Entity("Entity.Question", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("int"); - - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); - - b.Property("AnswerA") - .IsRequired() - .HasMaxLength(50) - .HasColumnType("nvarchar(50)"); - - b.Property("AnswerB") - .IsRequired() - .HasMaxLength(50) - .HasColumnType("nvarchar(50)"); - - b.Property("AnswerC") - .IsRequired() - .HasMaxLength(50) - .HasColumnType("nvarchar(50)"); - - b.Property("AnswerD") - .IsRequired() - .HasMaxLength(50) - .HasColumnType("nvarchar(50)"); - - b.Property("CorrectAnswer") - .IsRequired() - .HasMaxLength(1) - .HasColumnType("nvarchar(1)"); - - b.Property("Text") - .IsRequired() - .HasMaxLength(200) - .HasColumnType("nvarchar(200)"); - - b.HasKey("Id"); - - b.ToTable("question"); - - b.HasData( - new - { - Id = 1, - AnswerA = "Gimli", - AnswerB = "Aragorn", - AnswerC = "Frodon", - AnswerD = "Gandalf", - CorrectAnswer = "B", - Text = "Qui est le leader de la Communauté de l'Anneau ?" - }, - new - { - Id = 2, - AnswerA = "Serdaigle", - AnswerB = "Gryffondor", - AnswerC = "Serpentard", - AnswerD = "Poufsouffle", - CorrectAnswer = "B", - Text = "Dans quelle maison Harry Potter est-il ?" - }, - new - { - Id = 3, - AnswerA = "Saroumane", - AnswerB = "Sauron", - AnswerC = "Gollum", - AnswerD = "Gothmog", - CorrectAnswer = "B", - Text = "Qui est le Seigneur des Ténèbres dans la saga Le Seigneur des Anneaux ?" - }, - new - { - Id = 4, - AnswerA = "Han Solo", - AnswerB = "Princesse Leia", - AnswerC = "Chewbacca", - AnswerD = "R2-D2", - CorrectAnswer = "A", - Text = "Dans le film Star Wars : Episode IV, qui sauve Luke Skywalker de l'Étoile de la Mort ?" - }, - new - { - Id = 5, - AnswerA = "Reine Jadis", - AnswerB = "Aslan", - AnswerC = "Edmund", - AnswerD = "Lucy", - CorrectAnswer = "B", - Text = "Qui est le souverain de Narnia dans Le Lion, la Sorcière Blanche et l'Armoire Magique ?" - }, - new - { - Id = 6, - AnswerA = "Smaug", - AnswerB = "Falkor", - AnswerC = "Norbert", - AnswerD = "Shenron", - CorrectAnswer = "A", - Text = "Quel est le nom du dragon dans Le Hobbit ?" - }, - new - { - Id = 7, - AnswerA = "Bella Swan", - AnswerB = "Edward Cullen", - AnswerC = "Jacob Black", - AnswerD = "Victoria", - CorrectAnswer = "A", - Text = "Qui est la première personne à être mordue par un vampire dans Twilight ?" - }, - new - { - Id = 8, - AnswerA = "Obi-Wan Kenobi", - AnswerB = "Yoda", - AnswerC = "Han Solo", - AnswerD = "Luke Skywalker", - CorrectAnswer = "A", - Text = "Quel personnage dit Que la Force soit avec toi dans Star Wars ?" - }, - new - { - Id = 9, - AnswerA = "Dr. Ellie Sattler", - AnswerB = "Alan Grant", - AnswerC = "John Hammond", - AnswerD = "Dennis Nedry", - CorrectAnswer = "B", - Text = "Dans Jurassic Park, quel est le nom du paléontologue sur l'île ?" - }, - new - { - Id = 10, - AnswerA = "Cersei Lannister", - AnswerB = "Arya Stark", - AnswerC = "Daenerys Targaryen", - AnswerD = "Sansa Stark", - CorrectAnswer = "C", - Text = "Dans Game of Thrones, qui est surnommée la Mère des Dragons ?" - }); - }); - - modelBuilder.Entity("Entity.Quiz", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("int"); - - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); - - b.Property("IdImage") - .HasColumnType("int"); - - b.Property("NbQuestion") - .HasColumnType("int"); - - b.Property("Title") - .IsRequired() - .HasMaxLength(50) - .HasColumnType("nvarchar(50)"); - - b.HasKey("Id"); - - b.HasIndex("IdImage"); - - b.ToTable("quizzes"); - - b.HasData( - new - { - Id = 1, - IdImage = 1, - NbQuestion = 5, - Title = "Quiz 1" - }, - new - { - Id = 2, - IdImage = 2, - NbQuestion = 5, - Title = "Quiz 2" - }); - }); - - modelBuilder.Entity("Entity.QuizQuestion", b => - { - b.Property("IdQuestion") - .HasColumnType("int"); - - b.Property("IdQuiz") - .HasColumnType("int"); - - b.HasKey("IdQuestion", "IdQuiz"); - - b.HasIndex("IdQuiz"); - - b.ToTable("QuizQuestion"); - - b.HasData( - new - { - IdQuestion = 1, - IdQuiz = 1 - }, - new - { - IdQuestion = 2, - IdQuiz = 1 - }, - new - { - IdQuestion = 3, - IdQuiz = 1 - }, - new - { - IdQuestion = 4, - IdQuiz = 1 - }, - new - { - IdQuestion = 5, - IdQuiz = 1 - }, - new - { - IdQuestion = 6, - IdQuiz = 2 - }, - new - { - IdQuestion = 7, - IdQuiz = 2 - }, - new - { - IdQuestion = 8, - IdQuiz = 2 - }, - new - { - IdQuestion = 9, - IdQuiz = 2 - }, - new - { - IdQuestion = 10, - IdQuiz = 2 - }); - }); - - modelBuilder.Entity("Entity.Quote", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("int"); - - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); - - b.Property("Content") - .IsRequired() - .HasMaxLength(100) - .HasColumnType("nvarchar(100)"); - - b.Property("IdCharacter") - .HasColumnType("int"); - - b.Property("IdSource") - .HasColumnType("int"); - - b.Property("IdUsersPropose") - .HasColumnType("int"); - - b.Property("IsValid") - .HasColumnType("bit"); - - b.Property("Langage") - .HasColumnType("int"); - - b.Property("Likes") - .HasColumnType("int"); - - b.HasKey("Id"); - - b.HasIndex("IdCharacter"); - - b.HasIndex("IdSource"); - - b.HasIndex("IdUsersPropose"); - - b.ToTable("quotes"); - - b.HasData( - new - { - Id = 1, - Content = "Je n'y crois pas. Je n'y crois pas. Ce n'est pas possible", - IdCharacter = 1, - IdSource = 1, - IdUsersPropose = 1, - IsValid = true, - Langage = 1, - Likes = 11025 - }, - new - { - Id = 2, - Content = "There is always hope", - IdCharacter = 2, - IdSource = 2, - IdUsersPropose = 1, - IsValid = true, - Langage = 0, - Likes = 11025 - }, - new - { - Id = 3, - Content = "A red sun rises. Blood has been spilled this night.", - IdCharacter = 3, - IdSource = 2, - IdUsersPropose = 1, - IsValid = true, - Langage = 0, - Likes = 11025 - }, - new - { - Id = 4, - Content = "I wish the Ring had never come to me.I wish none of this had happened.", - IdCharacter = 4, - IdSource = 2, - IdUsersPropose = 1, - IsValid = true, - Langage = 0, - Likes = 11025 - }, - new - { - Id = 5, - Content = "Dobby is a free elf!", - IdCharacter = 5, - IdSource = 4, - IdUsersPropose = 1, - IsValid = true, - Langage = 0, - Likes = 11025 - }, - new - { - Id = 6, - Content = "Winter is comming", - IdCharacter = 6, - IdSource = 3, - IdUsersPropose = 1, - IsValid = true, - Langage = 0, - Likes = 11025 - }, - new - { - Id = 7, - Content = "Je suis la dernière Targaryen. Je suis la reine des dragons", - IdCharacter = 7, - IdSource = 3, - IdUsersPropose = 1, - IsValid = true, - Langage = 1, - Likes = 11025 - }, - new - { - Id = 8, - Content = "Je ne suis pas prêt à affronter ça. C'est trop pour moi.", - IdCharacter = 8, - IdSource = 5, - IdUsersPropose = 1, - IsValid = true, - Langage = 1, - Likes = 11025 - }, - new - { - Id = 9, - Content = "Aidez-moi, Obi-Wan Kenobi, vous êtes mon seul espoir.", - IdCharacter = 9, - IdSource = 5, - IdUsersPropose = 1, - IsValid = true, - Langage = 1, - Likes = 11025 - }, - new - { - Id = 10, - Content = "La quoi ?", - IdCharacter = 10, - IdSource = 4, - IdUsersPropose = 1, - IsValid = true, - Langage = 1, - Likes = 11025 - }); - }); - - modelBuilder.Entity("Entity.Source", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("int"); - - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); - - b.Property("Title") - .IsRequired() - .HasMaxLength(100) - .HasColumnType("nvarchar(100)"); - - b.Property("TypeSrc") - .HasColumnType("int"); - - b.Property("Year") - .HasColumnType("int"); - - b.HasKey("Id"); - - b.ToTable("sources"); - - b.HasData( - new - { - Id = 1, - Title = "Jurassic Park", - TypeSrc = 0, - Year = 1993 - }, - new - { - Id = 2, - Title = "Le Seigneur des anneaux : La Communauté de l'anneau", - TypeSrc = 0, - Year = 2001 - }, - new - { - Id = 3, - Title = "Game of throne", - TypeSrc = 1, - Year = 2011 - }, - new - { - Id = 4, - Title = "Harry Potter à l'école des sorcier", - TypeSrc = 0, - Year = 1997 - }, - new - { - Id = 5, - Title = "Star Wars, épisode IV : Un nouvel espoir", - TypeSrc = 0, - Year = 1977 - }); - }); - - modelBuilder.Entity("Entity.Users", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("int"); - - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); - - b.Property("Created") - .HasColumnType("date") - .HasColumnName("Created"); - - b.Property("Email") - .IsRequired() - .HasMaxLength(50) - .HasColumnType("nvarchar(50)"); - - b.Property("IdImage") - .HasColumnType("int"); - - b.Property("Password") - .IsRequired() - .HasMaxLength(200) - .HasColumnType("nvarchar(200)"); - - b.Property("UserName") - .IsRequired() - .HasMaxLength(50) - .HasColumnType("nvarchar(50)"); - - b.HasKey("Id"); - - b.HasIndex("IdImage"); - - b.ToTable("users"); - - b.HasData( - new - { - Id = 1, - Created = new DateTime(2025, 5, 12, 0, 0, 0, 0, DateTimeKind.Unspecified), - Email = "jhonDhoe@gmail.com", - IdImage = 1, - Password = "1234", - UserName = "Jhon-Dhoe" - }, - new - { - Id = 2, - Created = new DateTime(2025, 3, 19, 0, 0, 0, 0, DateTimeKind.Unspecified), - Email = "lucy_rose@outlook.com", - IdImage = 2, - Password = "abcd", - UserName = "Lucy-Rose" - }, - new - { - Id = 3, - Created = new DateTime(2024, 11, 2, 0, 0, 0, 0, DateTimeKind.Unspecified), - Email = "mark.taylor@yahoo.com", - IdImage = 3, - Password = "5678", - UserName = "Mark-Taylor" - }, - new - { - Id = 4, - Created = new DateTime(2025, 2, 28, 0, 0, 0, 0, DateTimeKind.Unspecified), - Email = "sophie.martin@gmail.com", - IdImage = 4, - Password = "4321", - UserName = "Sophie-Martin" - }, - new - { - Id = 5, - Created = new DateTime(2025, 1, 15, 0, 0, 0, 0, DateTimeKind.Unspecified), - Email = "nathan_doe@aol.com", - IdImage = 5, - Password = "8765", - UserName = "Nathan-Doe" - }, - new - { - Id = 6, - Created = new DateTime(2025, 4, 7, 0, 0, 0, 0, DateTimeKind.Unspecified), - Email = "ella.brown@icloud.com", - IdImage = 6, - Password = "2468", - UserName = "Ella-Brown" - }, - new - { - Id = 7, - Created = new DateTime(2024, 12, 25, 0, 0, 0, 0, DateTimeKind.Unspecified), - Email = "oliver_smith@gmail.com", - IdImage = 7, - Password = "1357", - UserName = "Oliver-Smith" - }, - new - { - Id = 8, - Created = new DateTime(2025, 3, 5, 0, 0, 0, 0, DateTimeKind.Unspecified), - Email = "mia.jones@outlook.com", - IdImage = 8, - Password = "1122", - UserName = "Mia-Jones" - }, - new - { - Id = 9, - Created = new DateTime(2025, 2, 22, 0, 0, 0, 0, DateTimeKind.Unspecified), - Email = "kevin_williams@aol.com", - IdImage = 9, - Password = "2233", - UserName = "Kevin-Williams" - }, - new - { - Id = 10, - Created = new DateTime(2025, 1, 3, 0, 0, 0, 0, DateTimeKind.Unspecified), - Email = "olivia.white@yahoo.com", - IdImage = 10, - Password = "3344", - UserName = "Olivia-White" - }); - }); - - modelBuilder.Entity("Entity.Character", b => - { - b.HasOne("Entity.Images", "Images") - .WithMany("Characters") - .HasForeignKey("IdImage") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.Navigation("Images"); - }); - - modelBuilder.Entity("Entity.Commentary", b => - { - b.HasOne("Entity.Quote", "Quote") - .WithMany("Commentarys") - .HasForeignKey("IdQuote") - .OnDelete(DeleteBehavior.ClientCascade) - .IsRequired(); - - b.HasOne("Entity.Users", "User") - .WithMany() - .HasForeignKey("IdUser") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.Navigation("Quote"); - - b.Navigation("User"); - }); - - modelBuilder.Entity("Entity.DailyQuote", b => - { - b.HasOne("Entity.Quote", "Quote") - .WithMany("DailyQuotes") - .HasForeignKey("IdQuote") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.Navigation("Quote"); - }); - - modelBuilder.Entity("Entity.Favorite", b => - { - b.HasOne("Entity.Quote", "Quote") - .WithMany() - .HasForeignKey("IdQuote") - .OnDelete(DeleteBehavior.ClientCascade) - .IsRequired(); - - b.HasOne("Entity.Users", "Users") - .WithMany() - .HasForeignKey("IdUsers") - .OnDelete(DeleteBehavior.ClientCascade) - .IsRequired(); - - b.Navigation("Quote"); - - b.Navigation("Users"); - }); - - modelBuilder.Entity("Entity.Quiz", b => - { - b.HasOne("Entity.Images", "Images") - .WithMany("Quizs") - .HasForeignKey("IdImage") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.Navigation("Images"); - }); - - modelBuilder.Entity("Entity.QuizQuestion", b => - { - b.HasOne("Entity.Question", null) - .WithMany() - .HasForeignKey("IdQuestion") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.HasOne("Entity.Quiz", null) - .WithMany() - .HasForeignKey("IdQuiz") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - }); - - modelBuilder.Entity("Entity.Quote", b => - { - b.HasOne("Entity.Character", "Character") - .WithMany("Quotes") - .HasForeignKey("IdCharacter") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.HasOne("Entity.Source", "Source") - .WithMany("Quotes") - .HasForeignKey("IdSource") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.HasOne("Entity.Users", "User") - .WithMany("Quotes") - .HasForeignKey("IdUsersPropose"); - - b.Navigation("Character"); - - b.Navigation("Source"); - - b.Navigation("User"); - }); - - modelBuilder.Entity("Entity.Users", b => - { - b.HasOne("Entity.Images", "Images") - .WithMany("Users") - .HasForeignKey("IdImage") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.Navigation("Images"); - }); - - modelBuilder.Entity("Entity.Character", b => - { - b.Navigation("Quotes"); - }); - - modelBuilder.Entity("Entity.Images", b => - { - b.Navigation("Characters"); - - b.Navigation("Quizs"); - - b.Navigation("Users"); - }); - - modelBuilder.Entity("Entity.Quote", b => - { - b.Navigation("Commentarys"); - - b.Navigation("DailyQuotes"); - }); - - modelBuilder.Entity("Entity.Source", b => - { - b.Navigation("Quotes"); - }); - - modelBuilder.Entity("Entity.Users", b => - { - b.Navigation("Quotes"); - }); -#pragma warning restore 612, 618 - } - } -} diff --git a/WF_EF_Api/StubbedContextLib/Migrations/20250318135625_migr1.Designer.cs b/WF_EF_Api/StubbedContextLib/Migrations/20250318135625_migr1.Designer.cs deleted file mode 100644 index 2ba04f3..0000000 --- a/WF_EF_Api/StubbedContextLib/Migrations/20250318135625_migr1.Designer.cs +++ /dev/null @@ -1,1065 +0,0 @@ -// -using System; -using Microsoft.EntityFrameworkCore; -using Microsoft.EntityFrameworkCore.Infrastructure; -using Microsoft.EntityFrameworkCore.Metadata; -using Microsoft.EntityFrameworkCore.Migrations; -using Microsoft.EntityFrameworkCore.Storage.ValueConversion; -using StubbedContextLib; - -#nullable disable - -namespace StubbedContextLib.Migrations -{ - [DbContext(typeof(StubWTFContext))] - [Migration("20250318135625_migr1")] - partial class migr1 - { - /// - protected override void BuildTargetModel(ModelBuilder modelBuilder) - { -#pragma warning disable 612, 618 - modelBuilder - .HasAnnotation("ProductVersion", "9.0.3") - .HasAnnotation("Relational:MaxIdentifierLength", 128); - - SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder); - - modelBuilder.Entity("Entity.Character", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("int"); - - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); - - b.Property("IdImage") - .HasColumnType("int"); - - b.Property("Name") - .IsRequired() - .HasMaxLength(50) - .HasColumnType("nvarchar(50)"); - - b.HasKey("Id"); - - b.HasIndex("IdImage"); - - b.ToTable("characters"); - - b.HasData( - new - { - Id = 1, - IdImage = 1, - Name = "Alan Grant" - }, - new - { - Id = 2, - IdImage = 2, - Name = "Aragorn" - }, - new - { - Id = 3, - IdImage = 3, - Name = "Legolas" - }, - new - { - Id = 4, - IdImage = 4, - Name = "Frodon" - }, - new - { - Id = 5, - IdImage = 5, - Name = "Dobby" - }, - new - { - Id = 6, - IdImage = 6, - Name = "Jon Snow" - }, - new - { - Id = 7, - IdImage = 7, - Name = "Daenerys Targaryen" - }, - new - { - Id = 8, - IdImage = 8, - Name = "Luke Skywalker" - }, - new - { - Id = 9, - IdImage = 9, - Name = "Princess Leia" - }, - new - { - Id = 10, - IdImage = 10, - Name = "Harry Potter" - }); - }); - - modelBuilder.Entity("Entity.Commentary", b => - { - b.Property("IdUser") - .HasColumnType("int"); - - b.Property("IdQuote") - .HasColumnType("int"); - - b.Property("Comment") - .IsRequired() - .HasMaxLength(100) - .HasColumnType("nvarchar(100)"); - - b.Property("DateCommentary") - .HasColumnType("date") - .HasColumnName("DateCommentary"); - - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("int"); - - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); - - b.HasKey("IdUser", "IdQuote"); - - b.HasIndex("IdQuote"); - - b.ToTable("comments"); - - b.HasData( - new - { - IdUser = 2, - IdQuote = 1, - Comment = "Ce film est le meilleur", - DateCommentary = new DateTime(2025, 2, 3, 0, 0, 0, 0, DateTimeKind.Unspecified), - Id = 1 - }, - new - { - IdUser = 3, - IdQuote = 1, - Comment = "Very good", - DateCommentary = new DateTime(2025, 3, 11, 0, 0, 0, 0, DateTimeKind.Unspecified), - Id = 2 - }); - }); - - modelBuilder.Entity("Entity.DailyQuote", b => - { - b.Property("IdQuote") - .HasColumnType("int"); - - b.HasKey("IdQuote"); - - b.ToTable("dailyquotes"); - - b.HasData( - new - { - IdQuote = 1 - }, - new - { - IdQuote = 5 - }); - }); - - modelBuilder.Entity("Entity.Favorite", b => - { - b.Property("IdQuote") - .HasColumnType("int"); - - b.Property("IdUsers") - .HasColumnType("int"); - - b.HasKey("IdQuote", "IdUsers"); - - b.HasIndex("IdUsers"); - - b.ToTable("favorites"); - - b.HasData( - new - { - IdQuote = 2, - IdUsers = 8 - }, - new - { - IdQuote = 5, - IdUsers = 3 - }, - new - { - IdQuote = 9, - IdUsers = 1 - }, - new - { - IdQuote = 4, - IdUsers = 10 - }, - new - { - IdQuote = 3, - IdUsers = 2 - }, - new - { - IdQuote = 6, - IdUsers = 7 - }, - new - { - IdQuote = 1, - IdUsers = 6 - }, - new - { - IdQuote = 8, - IdUsers = 9 - }, - new - { - IdQuote = 10, - IdUsers = 5 - }); - }); - - modelBuilder.Entity("Entity.Images", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("int"); - - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); - - b.Property("ImgPath") - .IsRequired() - .HasColumnType("nvarchar(max)"); - - b.HasKey("Id"); - - b.ToTable("images"); - - b.HasData( - new - { - Id = 1, - ImgPath = "https://th.bing.com/th/id/OIP.TJuWNCsibz8MVmhdNQEdMwHaE8?w=244&h=180&c=7&r=0&o=5&pid=1.7" - }, - new - { - Id = 2, - ImgPath = "https://th.bing.com/th/id/OIP.NgXRQ5-IknA6_qOPFhLWIwHaHK?w=165&h=180&c=7&r=0&o=5&pid=1.7" - }, - new - { - Id = 3, - ImgPath = "https://th.bing.com/th/id/OIP.XcJoJ6bC9sAMjol1pJn5UQHaLH?w=118&h=180&c=7&r=0&o=5&pid=1.7" - }, - new - { - Id = 4, - ImgPath = "https://th.bing.com/th/id/OIP.PPIESqZaNDa-qUcfSDXhdQHaGK?w=210&h=180&c=7&r=0&o=5&pid=1.7" - }, - new - { - Id = 5, - ImgPath = "https://th.bing.com/th/id/OIP.XBghSl2kfRNNtQoSxc901wHaHa?w=177&h=180&c=7&r=0&o=5&pid=1.7" - }, - new - { - Id = 6, - ImgPath = "https://th.bing.com/th/id/OIP.af1Aid64cqEKoIOBgCPxtQHaJO?w=145&h=182&c=7&r=0&o=5&pid=1.7" - }, - new - { - Id = 7, - ImgPath = "https://th.bing.com/th/id/OIP.ri5vSXr5lNTLt4DO6KQXyQHaI4?w=158&h=189&c=7&r=0&o=5&pid=1.7" - }, - new - { - Id = 8, - ImgPath = "https://th.bing.com/th/id/OIP.uPTRLR8uspCiafiunUqKfQHaMJ?w=115&h=180&c=7&r=0&o=5&pid=1.7" - }, - new - { - Id = 9, - ImgPath = "https://th.bing.com/th/id/OIP.hcJis4rKbyQtugsoFJU2ngHaM_?w=118&h=207&c=7&r=0&o=5&pid=1.7" - }, - new - { - Id = 10, - ImgPath = "https://th.bing.com/th/id/OIP.Py1_XfUrKJY_A6tYEmFS5wHaE8?w=280&h=187&c=7&r=0&o=5&pid=1.7" - }); - }); - - modelBuilder.Entity("Entity.Question", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("int"); - - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); - - b.Property("AnswerA") - .IsRequired() - .HasMaxLength(50) - .HasColumnType("nvarchar(50)"); - - b.Property("AnswerB") - .IsRequired() - .HasMaxLength(50) - .HasColumnType("nvarchar(50)"); - - b.Property("AnswerC") - .IsRequired() - .HasMaxLength(50) - .HasColumnType("nvarchar(50)"); - - b.Property("AnswerD") - .IsRequired() - .HasMaxLength(50) - .HasColumnType("nvarchar(50)"); - - b.Property("CorrectAnswer") - .IsRequired() - .HasMaxLength(1) - .HasColumnType("nvarchar(1)"); - - b.Property("Text") - .IsRequired() - .HasMaxLength(200) - .HasColumnType("nvarchar(200)"); - - b.HasKey("Id"); - - b.ToTable("question"); - - b.HasData( - new - { - Id = 1, - AnswerA = "Gimli", - AnswerB = "Aragorn", - AnswerC = "Frodon", - AnswerD = "Gandalf", - CorrectAnswer = "B", - Text = "Qui est le leader de la Communauté de l'Anneau ?" - }, - new - { - Id = 2, - AnswerA = "Serdaigle", - AnswerB = "Gryffondor", - AnswerC = "Serpentard", - AnswerD = "Poufsouffle", - CorrectAnswer = "B", - Text = "Dans quelle maison Harry Potter est-il ?" - }, - new - { - Id = 3, - AnswerA = "Saroumane", - AnswerB = "Sauron", - AnswerC = "Gollum", - AnswerD = "Gothmog", - CorrectAnswer = "B", - Text = "Qui est le Seigneur des Ténèbres dans la saga Le Seigneur des Anneaux ?" - }, - new - { - Id = 4, - AnswerA = "Han Solo", - AnswerB = "Princesse Leia", - AnswerC = "Chewbacca", - AnswerD = "R2-D2", - CorrectAnswer = "A", - Text = "Dans le film Star Wars : Episode IV, qui sauve Luke Skywalker de l'Étoile de la Mort ?" - }, - new - { - Id = 5, - AnswerA = "Reine Jadis", - AnswerB = "Aslan", - AnswerC = "Edmund", - AnswerD = "Lucy", - CorrectAnswer = "B", - Text = "Qui est le souverain de Narnia dans Le Lion, la Sorcière Blanche et l'Armoire Magique ?" - }, - new - { - Id = 6, - AnswerA = "Smaug", - AnswerB = "Falkor", - AnswerC = "Norbert", - AnswerD = "Shenron", - CorrectAnswer = "A", - Text = "Quel est le nom du dragon dans Le Hobbit ?" - }, - new - { - Id = 7, - AnswerA = "Bella Swan", - AnswerB = "Edward Cullen", - AnswerC = "Jacob Black", - AnswerD = "Victoria", - CorrectAnswer = "A", - Text = "Qui est la première personne à être mordue par un vampire dans Twilight ?" - }, - new - { - Id = 8, - AnswerA = "Obi-Wan Kenobi", - AnswerB = "Yoda", - AnswerC = "Han Solo", - AnswerD = "Luke Skywalker", - CorrectAnswer = "A", - Text = "Quel personnage dit Que la Force soit avec toi dans Star Wars ?" - }, - new - { - Id = 9, - AnswerA = "Dr. Ellie Sattler", - AnswerB = "Alan Grant", - AnswerC = "John Hammond", - AnswerD = "Dennis Nedry", - CorrectAnswer = "B", - Text = "Dans Jurassic Park, quel est le nom du paléontologue sur l'île ?" - }, - new - { - Id = 10, - AnswerA = "Cersei Lannister", - AnswerB = "Arya Stark", - AnswerC = "Daenerys Targaryen", - AnswerD = "Sansa Stark", - CorrectAnswer = "C", - Text = "Dans Game of Thrones, qui est surnommée la Mère des Dragons ?" - }); - }); - - modelBuilder.Entity("Entity.Quiz", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("int"); - - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); - - b.Property("IdImage") - .HasColumnType("int"); - - b.Property("NbQuestion") - .HasColumnType("int"); - - b.Property("Title") - .IsRequired() - .HasMaxLength(50) - .HasColumnType("nvarchar(50)"); - - b.HasKey("Id"); - - b.HasIndex("IdImage"); - - b.ToTable("quizzes"); - - b.HasData( - new - { - Id = 1, - IdImage = 1, - NbQuestion = 5, - Title = "Quiz 1" - }, - new - { - Id = 2, - IdImage = 2, - NbQuestion = 5, - Title = "Quiz 2" - }); - }); - - modelBuilder.Entity("Entity.QuizQuestion", b => - { - b.Property("IdQuestion") - .HasColumnType("int"); - - b.Property("IdQuiz") - .HasColumnType("int"); - - b.HasKey("IdQuestion", "IdQuiz"); - - b.HasIndex("IdQuiz"); - - b.ToTable("QuizQuestion"); - - b.HasData( - new - { - IdQuestion = 1, - IdQuiz = 1 - }, - new - { - IdQuestion = 2, - IdQuiz = 1 - }, - new - { - IdQuestion = 3, - IdQuiz = 1 - }, - new - { - IdQuestion = 4, - IdQuiz = 1 - }, - new - { - IdQuestion = 5, - IdQuiz = 1 - }, - new - { - IdQuestion = 6, - IdQuiz = 2 - }, - new - { - IdQuestion = 7, - IdQuiz = 2 - }, - new - { - IdQuestion = 8, - IdQuiz = 2 - }, - new - { - IdQuestion = 9, - IdQuiz = 2 - }, - new - { - IdQuestion = 10, - IdQuiz = 2 - }); - }); - - modelBuilder.Entity("Entity.Quote", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("int"); - - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); - - b.Property("Content") - .IsRequired() - .HasMaxLength(100) - .HasColumnType("nvarchar(100)"); - - b.Property("IdCharacter") - .HasColumnType("int"); - - b.Property("IdSource") - .HasColumnType("int"); - - b.Property("IdUsersPropose") - .HasColumnType("int"); - - b.Property("IsValid") - .HasColumnType("bit"); - - b.Property("Langage") - .HasColumnType("int"); - - b.Property("Likes") - .HasColumnType("int"); - - b.HasKey("Id"); - - b.HasIndex("IdCharacter"); - - b.HasIndex("IdSource"); - - b.HasIndex("IdUsersPropose"); - - b.ToTable("quotes"); - - b.HasData( - new - { - Id = 1, - Content = "Je n'y crois pas. Je n'y crois pas. Ce n'est pas possible", - IdCharacter = 1, - IdSource = 1, - IdUsersPropose = 1, - IsValid = true, - Langage = 1, - Likes = 11025 - }, - new - { - Id = 2, - Content = "There is always hope", - IdCharacter = 2, - IdSource = 2, - IdUsersPropose = 1, - IsValid = true, - Langage = 0, - Likes = 11025 - }, - new - { - Id = 3, - Content = "A red sun rises. Blood has been spilled this night.", - IdCharacter = 3, - IdSource = 2, - IdUsersPropose = 1, - IsValid = true, - Langage = 0, - Likes = 11025 - }, - new - { - Id = 4, - Content = "I wish the Ring had never come to me.I wish none of this had happened.", - IdCharacter = 4, - IdSource = 2, - IdUsersPropose = 1, - IsValid = true, - Langage = 0, - Likes = 11025 - }, - new - { - Id = 5, - Content = "Dobby is a free elf!", - IdCharacter = 5, - IdSource = 4, - IdUsersPropose = 1, - IsValid = true, - Langage = 0, - Likes = 11025 - }, - new - { - Id = 6, - Content = "Winter is comming", - IdCharacter = 6, - IdSource = 3, - IdUsersPropose = 1, - IsValid = true, - Langage = 0, - Likes = 11025 - }, - new - { - Id = 7, - Content = "Je suis la dernière Targaryen. Je suis la reine des dragons", - IdCharacter = 7, - IdSource = 3, - IdUsersPropose = 1, - IsValid = true, - Langage = 1, - Likes = 11025 - }, - new - { - Id = 8, - Content = "Je ne suis pas prêt à affronter ça. C'est trop pour moi.", - IdCharacter = 8, - IdSource = 5, - IdUsersPropose = 1, - IsValid = true, - Langage = 1, - Likes = 11025 - }, - new - { - Id = 9, - Content = "Aidez-moi, Obi-Wan Kenobi, vous êtes mon seul espoir.", - IdCharacter = 9, - IdSource = 5, - IdUsersPropose = 1, - IsValid = true, - Langage = 1, - Likes = 11025 - }, - new - { - Id = 10, - Content = "La quoi ?", - IdCharacter = 10, - IdSource = 4, - IdUsersPropose = 1, - IsValid = true, - Langage = 1, - Likes = 11025 - }); - }); - - modelBuilder.Entity("Entity.Source", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("int"); - - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); - - b.Property("Title") - .IsRequired() - .HasMaxLength(100) - .HasColumnType("nvarchar(100)"); - - b.Property("TypeSrc") - .HasColumnType("int"); - - b.Property("Year") - .HasColumnType("int"); - - b.HasKey("Id"); - - b.ToTable("sources"); - - b.HasData( - new - { - Id = 1, - Title = "Jurassic Park", - TypeSrc = 0, - Year = 1993 - }, - new - { - Id = 2, - Title = "Le Seigneur des anneaux : La Communauté de l'anneau", - TypeSrc = 0, - Year = 2001 - }, - new - { - Id = 3, - Title = "Game of throne", - TypeSrc = 1, - Year = 2011 - }, - new - { - Id = 4, - Title = "Harry Potter à l'école des sorcier", - TypeSrc = 0, - Year = 1997 - }, - new - { - Id = 5, - Title = "Star Wars, épisode IV : Un nouvel espoir", - TypeSrc = 0, - Year = 1977 - }); - }); - - modelBuilder.Entity("Entity.Users", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("int"); - - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); - - b.Property("Created") - .HasColumnType("date") - .HasColumnName("Created"); - - b.Property("Email") - .IsRequired() - .HasMaxLength(50) - .HasColumnType("nvarchar(50)"); - - b.Property("IdImage") - .HasColumnType("int"); - - b.Property("Password") - .IsRequired() - .HasMaxLength(200) - .HasColumnType("nvarchar(200)"); - - b.Property("UserName") - .IsRequired() - .HasMaxLength(50) - .HasColumnType("nvarchar(50)"); - - b.HasKey("Id"); - - b.HasIndex("IdImage"); - - b.ToTable("users"); - - b.HasData( - new - { - Id = 1, - Created = new DateTime(2025, 5, 12, 0, 0, 0, 0, DateTimeKind.Unspecified), - Email = "jhonDhoe@gmail.com", - IdImage = 1, - Password = "1234", - UserName = "Jhon-Dhoe" - }, - new - { - Id = 2, - Created = new DateTime(2025, 3, 19, 0, 0, 0, 0, DateTimeKind.Unspecified), - Email = "lucy_rose@outlook.com", - IdImage = 2, - Password = "abcd", - UserName = "Lucy-Rose" - }, - new - { - Id = 3, - Created = new DateTime(2024, 11, 2, 0, 0, 0, 0, DateTimeKind.Unspecified), - Email = "mark.taylor@yahoo.com", - IdImage = 3, - Password = "5678", - UserName = "Mark-Taylor" - }, - new - { - Id = 4, - Created = new DateTime(2025, 2, 28, 0, 0, 0, 0, DateTimeKind.Unspecified), - Email = "sophie.martin@gmail.com", - IdImage = 4, - Password = "4321", - UserName = "Sophie-Martin" - }, - new - { - Id = 5, - Created = new DateTime(2025, 1, 15, 0, 0, 0, 0, DateTimeKind.Unspecified), - Email = "nathan_doe@aol.com", - IdImage = 5, - Password = "8765", - UserName = "Nathan-Doe" - }, - new - { - Id = 6, - Created = new DateTime(2025, 4, 7, 0, 0, 0, 0, DateTimeKind.Unspecified), - Email = "ella.brown@icloud.com", - IdImage = 6, - Password = "2468", - UserName = "Ella-Brown" - }, - new - { - Id = 7, - Created = new DateTime(2024, 12, 25, 0, 0, 0, 0, DateTimeKind.Unspecified), - Email = "oliver_smith@gmail.com", - IdImage = 7, - Password = "1357", - UserName = "Oliver-Smith" - }, - new - { - Id = 8, - Created = new DateTime(2025, 3, 5, 0, 0, 0, 0, DateTimeKind.Unspecified), - Email = "mia.jones@outlook.com", - IdImage = 8, - Password = "1122", - UserName = "Mia-Jones" - }, - new - { - Id = 9, - Created = new DateTime(2025, 2, 22, 0, 0, 0, 0, DateTimeKind.Unspecified), - Email = "kevin_williams@aol.com", - IdImage = 9, - Password = "2233", - UserName = "Kevin-Williams" - }, - new - { - Id = 10, - Created = new DateTime(2025, 1, 3, 0, 0, 0, 0, DateTimeKind.Unspecified), - Email = "olivia.white@yahoo.com", - IdImage = 10, - Password = "3344", - UserName = "Olivia-White" - }); - }); - - modelBuilder.Entity("Entity.Character", b => - { - b.HasOne("Entity.Images", "Images") - .WithMany("Characters") - .HasForeignKey("IdImage") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.Navigation("Images"); - }); - - modelBuilder.Entity("Entity.Commentary", b => - { - b.HasOne("Entity.Quote", "Quote") - .WithMany("Commentarys") - .HasForeignKey("IdQuote") - .OnDelete(DeleteBehavior.ClientCascade) - .IsRequired(); - - b.HasOne("Entity.Users", "User") - .WithMany() - .HasForeignKey("IdUser") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.Navigation("Quote"); - - b.Navigation("User"); - }); - - modelBuilder.Entity("Entity.DailyQuote", b => - { - b.HasOne("Entity.Quote", "Quote") - .WithMany("DailyQuotes") - .HasForeignKey("IdQuote") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.Navigation("Quote"); - }); - - modelBuilder.Entity("Entity.Favorite", b => - { - b.HasOne("Entity.Quote", "Quote") - .WithMany() - .HasForeignKey("IdQuote") - .OnDelete(DeleteBehavior.ClientCascade) - .IsRequired(); - - b.HasOne("Entity.Users", "Users") - .WithMany() - .HasForeignKey("IdUsers") - .OnDelete(DeleteBehavior.ClientCascade) - .IsRequired(); - - b.Navigation("Quote"); - - b.Navigation("Users"); - }); - - modelBuilder.Entity("Entity.Quiz", b => - { - b.HasOne("Entity.Images", "Images") - .WithMany("Quizs") - .HasForeignKey("IdImage") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.Navigation("Images"); - }); - - modelBuilder.Entity("Entity.QuizQuestion", b => - { - b.HasOne("Entity.Question", null) - .WithMany() - .HasForeignKey("IdQuestion") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.HasOne("Entity.Quiz", null) - .WithMany() - .HasForeignKey("IdQuiz") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - }); - - modelBuilder.Entity("Entity.Quote", b => - { - b.HasOne("Entity.Character", "Character") - .WithMany("Quotes") - .HasForeignKey("IdCharacter") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.HasOne("Entity.Source", "Source") - .WithMany("Quotes") - .HasForeignKey("IdSource") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.HasOne("Entity.Users", "User") - .WithMany("Quotes") - .HasForeignKey("IdUsersPropose"); - - b.Navigation("Character"); - - b.Navigation("Source"); - - b.Navigation("User"); - }); - - modelBuilder.Entity("Entity.Users", b => - { - b.HasOne("Entity.Images", "Images") - .WithMany("Users") - .HasForeignKey("IdImage") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.Navigation("Images"); - }); - - modelBuilder.Entity("Entity.Character", b => - { - b.Navigation("Quotes"); - }); - - modelBuilder.Entity("Entity.Images", b => - { - b.Navigation("Characters"); - - b.Navigation("Quizs"); - - b.Navigation("Users"); - }); - - modelBuilder.Entity("Entity.Quote", b => - { - b.Navigation("Commentarys"); - - b.Navigation("DailyQuotes"); - }); - - modelBuilder.Entity("Entity.Source", b => - { - b.Navigation("Quotes"); - }); - - modelBuilder.Entity("Entity.Users", b => - { - b.Navigation("Quotes"); - }); -#pragma warning restore 612, 618 - } - } -} diff --git a/WF_EF_Api/StubbedContextLib/Migrations/20250318135625_migr1.cs b/WF_EF_Api/StubbedContextLib/Migrations/20250318135625_migr1.cs deleted file mode 100644 index 00b10fb..0000000 --- a/WF_EF_Api/StubbedContextLib/Migrations/20250318135625_migr1.cs +++ /dev/null @@ -1,22 +0,0 @@ -using Microsoft.EntityFrameworkCore.Migrations; - -#nullable disable - -namespace StubbedContextLib.Migrations -{ - /// - public partial class migr1 : Migration - { - /// - protected override void Up(MigrationBuilder migrationBuilder) - { - - } - - /// - protected override void Down(MigrationBuilder migrationBuilder) - { - - } - } -} diff --git a/WF_EF_Api/StubbedContextLib/Migrations/20250328102709_migr5.Designer.cs b/WF_EF_Api/StubbedContextLib/Migrations/20250328102709_migr5.Designer.cs deleted file mode 100644 index 7e637c8..0000000 --- a/WF_EF_Api/StubbedContextLib/Migrations/20250328102709_migr5.Designer.cs +++ /dev/null @@ -1,1107 +0,0 @@ -// -using System; -using Microsoft.EntityFrameworkCore; -using Microsoft.EntityFrameworkCore.Infrastructure; -using Microsoft.EntityFrameworkCore.Metadata; -using Microsoft.EntityFrameworkCore.Migrations; -using Microsoft.EntityFrameworkCore.Storage.ValueConversion; -using StubbedContextLib; - -#nullable disable - -namespace StubbedContextLib.Migrations -{ - [DbContext(typeof(StubWTFContext))] - [Migration("20250328102709_migr5")] - partial class migr5 - { - /// - protected override void BuildTargetModel(ModelBuilder modelBuilder) - { -#pragma warning disable 612, 618 - modelBuilder - .HasAnnotation("ProductVersion", "9.0.3") - .HasAnnotation("Relational:MaxIdentifierLength", 128); - - SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder); - - modelBuilder.Entity("Entity.Admin", b => - { - b.Property("IdUsers") - .ValueGeneratedOnAdd() - .HasColumnType("int"); - - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("IdUsers")); - - b.Property("UserId") - .HasColumnType("int"); - - b.HasKey("IdUsers"); - - b.HasIndex("UserId"); - - b.ToTable("admins"); - }); - - modelBuilder.Entity("Entity.Character", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("int"); - - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); - - b.Property("IdImage") - .HasColumnType("int"); - - b.Property("Name") - .IsRequired() - .HasMaxLength(50) - .HasColumnType("nvarchar(50)"); - - b.HasKey("Id"); - - b.HasIndex("IdImage"); - - b.ToTable("characters"); - - b.HasData( - new - { - Id = 1, - IdImage = 1, - Name = "Alan Grant" - }, - new - { - Id = 2, - IdImage = 2, - Name = "Aragorn" - }, - new - { - Id = 3, - IdImage = 3, - Name = "Legolas" - }, - new - { - Id = 4, - IdImage = 4, - Name = "Frodon" - }, - new - { - Id = 5, - IdImage = 5, - Name = "Dobby" - }, - new - { - Id = 6, - IdImage = 6, - Name = "Jon Snow" - }, - new - { - Id = 7, - IdImage = 7, - Name = "Daenerys Targaryen" - }, - new - { - Id = 8, - IdImage = 8, - Name = "Luke Skywalker" - }, - new - { - Id = 9, - IdImage = 9, - Name = "Princess Leia" - }, - new - { - Id = 10, - IdImage = 10, - Name = "Harry Potter" - }); - }); - - modelBuilder.Entity("Entity.Commentary", b => - { - b.Property("IdUser") - .HasColumnType("int"); - - b.Property("IdQuote") - .HasColumnType("int"); - - b.Property("Comment") - .IsRequired() - .HasMaxLength(100) - .HasColumnType("nvarchar(100)"); - - b.Property("DateCommentary") - .HasColumnType("date") - .HasColumnName("DateCommentary"); - - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("int"); - - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); - - b.HasKey("IdUser", "IdQuote"); - - b.HasIndex("IdQuote"); - - b.ToTable("comments"); - - b.HasData( - new - { - IdUser = 2, - IdQuote = 1, - Comment = "Ce film est le meilleur", - DateCommentary = new DateTime(2025, 2, 3, 0, 0, 0, 0, DateTimeKind.Unspecified), - Id = 1 - }, - new - { - IdUser = 3, - IdQuote = 1, - Comment = "Very good", - DateCommentary = new DateTime(2025, 3, 11, 0, 0, 0, 0, DateTimeKind.Unspecified), - Id = 2 - }); - }); - - modelBuilder.Entity("Entity.DailyQuote", b => - { - b.Property("IdQuote") - .HasColumnType("int"); - - b.HasKey("IdQuote"); - - b.ToTable("dailyquotes"); - - b.HasData( - new - { - IdQuote = 1 - }, - new - { - IdQuote = 5 - }); - }); - - modelBuilder.Entity("Entity.Favorite", b => - { - b.Property("IdQuote") - .HasColumnType("int"); - - b.Property("IdUsers") - .HasColumnType("int"); - - b.HasKey("IdQuote", "IdUsers"); - - b.HasIndex("IdUsers"); - - b.ToTable("favorites"); - - b.HasData( - new - { - IdQuote = 2, - IdUsers = 8 - }, - new - { - IdQuote = 5, - IdUsers = 3 - }, - new - { - IdQuote = 9, - IdUsers = 1 - }, - new - { - IdQuote = 4, - IdUsers = 10 - }, - new - { - IdQuote = 3, - IdUsers = 2 - }, - new - { - IdQuote = 6, - IdUsers = 7 - }, - new - { - IdQuote = 1, - IdUsers = 6 - }, - new - { - IdQuote = 8, - IdUsers = 9 - }, - new - { - IdQuote = 10, - IdUsers = 5 - }); - }); - - modelBuilder.Entity("Entity.Images", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("int"); - - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); - - b.Property("ImgPath") - .IsRequired() - .HasColumnType("nvarchar(max)"); - - b.HasKey("Id"); - - b.ToTable("images"); - - b.HasData( - new - { - Id = 1, - ImgPath = "https://th.bing.com/th/id/OIP.TJuWNCsibz8MVmhdNQEdMwHaE8?w=244&h=180&c=7&r=0&o=5&pid=1.7" - }, - new - { - Id = 2, - ImgPath = "https://th.bing.com/th/id/OIP.NgXRQ5-IknA6_qOPFhLWIwHaHK?w=165&h=180&c=7&r=0&o=5&pid=1.7" - }, - new - { - Id = 3, - ImgPath = "https://th.bing.com/th/id/OIP.XcJoJ6bC9sAMjol1pJn5UQHaLH?w=118&h=180&c=7&r=0&o=5&pid=1.7" - }, - new - { - Id = 4, - ImgPath = "https://th.bing.com/th/id/OIP.PPIESqZaNDa-qUcfSDXhdQHaGK?w=210&h=180&c=7&r=0&o=5&pid=1.7" - }, - new - { - Id = 5, - ImgPath = "https://th.bing.com/th/id/OIP.XBghSl2kfRNNtQoSxc901wHaHa?w=177&h=180&c=7&r=0&o=5&pid=1.7" - }, - new - { - Id = 6, - ImgPath = "https://th.bing.com/th/id/OIP.af1Aid64cqEKoIOBgCPxtQHaJO?w=145&h=182&c=7&r=0&o=5&pid=1.7" - }, - new - { - Id = 7, - ImgPath = "https://th.bing.com/th/id/OIP.ri5vSXr5lNTLt4DO6KQXyQHaI4?w=158&h=189&c=7&r=0&o=5&pid=1.7" - }, - new - { - Id = 8, - ImgPath = "https://th.bing.com/th/id/OIP.uPTRLR8uspCiafiunUqKfQHaMJ?w=115&h=180&c=7&r=0&o=5&pid=1.7" - }, - new - { - Id = 9, - ImgPath = "https://th.bing.com/th/id/OIP.hcJis4rKbyQtugsoFJU2ngHaM_?w=118&h=207&c=7&r=0&o=5&pid=1.7" - }, - new - { - Id = 10, - ImgPath = "https://th.bing.com/th/id/OIP.Py1_XfUrKJY_A6tYEmFS5wHaE8?w=280&h=187&c=7&r=0&o=5&pid=1.7" - }); - }); - - modelBuilder.Entity("Entity.Question", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("int"); - - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); - - b.Property("AnswerA") - .IsRequired() - .HasMaxLength(50) - .HasColumnType("nvarchar(50)"); - - b.Property("AnswerB") - .IsRequired() - .HasMaxLength(50) - .HasColumnType("nvarchar(50)"); - - b.Property("AnswerC") - .IsRequired() - .HasMaxLength(50) - .HasColumnType("nvarchar(50)"); - - b.Property("AnswerD") - .IsRequired() - .HasMaxLength(50) - .HasColumnType("nvarchar(50)"); - - b.Property("CorrectAnswer") - .IsRequired() - .HasMaxLength(1) - .HasColumnType("nvarchar(1)"); - - b.Property("IsValid") - .HasColumnType("bit"); - - b.Property("Text") - .IsRequired() - .HasMaxLength(200) - .HasColumnType("nvarchar(200)"); - - b.HasKey("Id"); - - b.ToTable("question"); - - b.HasData( - new - { - Id = 1, - AnswerA = "Gimli", - AnswerB = "Aragorn", - AnswerC = "Frodon", - AnswerD = "Gandalf", - CorrectAnswer = "B", - IsValid = true, - Text = "Qui est le leader de la Communauté de l'Anneau ?" - }, - new - { - Id = 2, - AnswerA = "Serdaigle", - AnswerB = "Gryffondor", - AnswerC = "Serpentard", - AnswerD = "Poufsouffle", - CorrectAnswer = "B", - IsValid = false, - Text = "Dans quelle maison Harry Potter est-il ?" - }, - new - { - Id = 3, - AnswerA = "Saroumane", - AnswerB = "Sauron", - AnswerC = "Gollum", - AnswerD = "Gothmog", - CorrectAnswer = "B", - IsValid = true, - Text = "Qui est le Seigneur des Ténèbres dans la saga Le Seigneur des Anneaux ?" - }, - new - { - Id = 4, - AnswerA = "Han Solo", - AnswerB = "Princesse Leia", - AnswerC = "Chewbacca", - AnswerD = "R2-D2", - CorrectAnswer = "A", - IsValid = true, - Text = "Dans le film Star Wars : Episode IV, qui sauve Luke Skywalker de l'Étoile de la Mort ?" - }, - new - { - Id = 5, - AnswerA = "Reine Jadis", - AnswerB = "Aslan", - AnswerC = "Edmund", - AnswerD = "Lucy", - CorrectAnswer = "B", - IsValid = true, - Text = "Qui est le souverain de Narnia dans Le Lion, la Sorcière Blanche et l'Armoire Magique ?" - }, - new - { - Id = 6, - AnswerA = "Smaug", - AnswerB = "Falkor", - AnswerC = "Norbert", - AnswerD = "Shenron", - CorrectAnswer = "A", - IsValid = true, - Text = "Quel est le nom du dragon dans Le Hobbit ?" - }, - new - { - Id = 7, - AnswerA = "Bella Swan", - AnswerB = "Edward Cullen", - AnswerC = "Jacob Black", - AnswerD = "Victoria", - CorrectAnswer = "A", - IsValid = true, - Text = "Qui est la première personne à être mordue par un vampire dans Twilight ?" - }, - new - { - Id = 8, - AnswerA = "Obi-Wan Kenobi", - AnswerB = "Yoda", - AnswerC = "Han Solo", - AnswerD = "Luke Skywalker", - CorrectAnswer = "A", - IsValid = true, - Text = "Quel personnage dit Que la Force soit avec toi dans Star Wars ?" - }, - new - { - Id = 9, - AnswerA = "Dr. Ellie Sattler", - AnswerB = "Alan Grant", - AnswerC = "John Hammond", - AnswerD = "Dennis Nedry", - CorrectAnswer = "B", - IsValid = true, - Text = "Dans Jurassic Park, quel est le nom du paléontologue sur l'île ?" - }, - new - { - Id = 10, - AnswerA = "Cersei Lannister", - AnswerB = "Arya Stark", - AnswerC = "Daenerys Targaryen", - AnswerD = "Sansa Stark", - CorrectAnswer = "C", - IsValid = true, - Text = "Dans Game of Thrones, qui est surnommée la Mère des Dragons ?" - }); - }); - - modelBuilder.Entity("Entity.Quiz", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("int"); - - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); - - b.Property("IdImage") - .HasColumnType("int"); - - b.Property("NbQuestion") - .HasColumnType("int"); - - b.Property("Title") - .IsRequired() - .HasMaxLength(50) - .HasColumnType("nvarchar(50)"); - - b.HasKey("Id"); - - b.HasIndex("IdImage"); - - b.ToTable("quizzes"); - - b.HasData( - new - { - Id = 1, - IdImage = 1, - NbQuestion = 5, - Title = "Quiz 1" - }, - new - { - Id = 2, - IdImage = 2, - NbQuestion = 5, - Title = "Quiz 2" - }); - }); - - modelBuilder.Entity("Entity.QuizQuestion", b => - { - b.Property("IdQuestion") - .HasColumnType("int"); - - b.Property("IdQuiz") - .HasColumnType("int"); - - b.HasKey("IdQuestion", "IdQuiz"); - - b.HasIndex("IdQuiz"); - - b.ToTable("QuizQuestion"); - - b.HasData( - new - { - IdQuestion = 1, - IdQuiz = 1 - }, - new - { - IdQuestion = 2, - IdQuiz = 1 - }, - new - { - IdQuestion = 3, - IdQuiz = 1 - }, - new - { - IdQuestion = 4, - IdQuiz = 1 - }, - new - { - IdQuestion = 5, - IdQuiz = 1 - }, - new - { - IdQuestion = 6, - IdQuiz = 2 - }, - new - { - IdQuestion = 7, - IdQuiz = 2 - }, - new - { - IdQuestion = 8, - IdQuiz = 2 - }, - new - { - IdQuestion = 9, - IdQuiz = 2 - }, - new - { - IdQuestion = 10, - IdQuiz = 2 - }); - }); - - modelBuilder.Entity("Entity.Quote", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("int"); - - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); - - b.Property("Content") - .IsRequired() - .HasMaxLength(100) - .HasColumnType("nvarchar(100)"); - - b.Property("IdCharacter") - .HasColumnType("int"); - - b.Property("IdSource") - .HasColumnType("int"); - - b.Property("IdUsersPropose") - .HasColumnType("int"); - - b.Property("IsValid") - .HasColumnType("bit"); - - b.Property("Langage") - .HasColumnType("int"); - - b.Property("Likes") - .HasColumnType("int"); - - b.HasKey("Id"); - - b.HasIndex("IdCharacter"); - - b.HasIndex("IdSource"); - - b.HasIndex("IdUsersPropose"); - - b.ToTable("quotes"); - - b.HasData( - new - { - Id = 1, - Content = "Je n'y crois pas. Je n'y crois pas. Ce n'est pas possible", - IdCharacter = 1, - IdSource = 1, - IdUsersPropose = 1, - IsValid = true, - Langage = 1, - Likes = 11025 - }, - new - { - Id = 2, - Content = "There is always hope", - IdCharacter = 2, - IdSource = 2, - IdUsersPropose = 1, - IsValid = true, - Langage = 0, - Likes = 11025 - }, - new - { - Id = 3, - Content = "A red sun rises. Blood has been spilled this night.", - IdCharacter = 3, - IdSource = 2, - IdUsersPropose = 1, - IsValid = true, - Langage = 0, - Likes = 11025 - }, - new - { - Id = 4, - Content = "I wish the Ring had never come to me.I wish none of this had happened.", - IdCharacter = 4, - IdSource = 2, - IdUsersPropose = 1, - IsValid = true, - Langage = 0, - Likes = 11025 - }, - new - { - Id = 5, - Content = "Dobby is a free elf!", - IdCharacter = 5, - IdSource = 4, - IdUsersPropose = 1, - IsValid = true, - Langage = 0, - Likes = 11025 - }, - new - { - Id = 6, - Content = "Winter is comming", - IdCharacter = 6, - IdSource = 3, - IdUsersPropose = 1, - IsValid = true, - Langage = 0, - Likes = 11025 - }, - new - { - Id = 7, - Content = "Je suis la dernière Targaryen. Je suis la reine des dragons", - IdCharacter = 7, - IdSource = 3, - IdUsersPropose = 1, - IsValid = true, - Langage = 1, - Likes = 11025 - }, - new - { - Id = 8, - Content = "Je ne suis pas prêt à affronter ça. C'est trop pour moi.", - IdCharacter = 8, - IdSource = 5, - IdUsersPropose = 1, - IsValid = true, - Langage = 1, - Likes = 11025 - }, - new - { - Id = 9, - Content = "Aidez-moi, Obi-Wan Kenobi, vous êtes mon seul espoir.", - IdCharacter = 9, - IdSource = 5, - IdUsersPropose = 1, - IsValid = true, - Langage = 1, - Likes = 11025 - }, - new - { - Id = 10, - Content = "La quoi ?", - IdCharacter = 10, - IdSource = 4, - IdUsersPropose = 1, - IsValid = true, - Langage = 1, - Likes = 11025 - }); - }); - - modelBuilder.Entity("Entity.Source", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("int"); - - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); - - b.Property("Title") - .IsRequired() - .HasMaxLength(100) - .HasColumnType("nvarchar(100)"); - - b.Property("TypeSrc") - .HasColumnType("int"); - - b.Property("Year") - .HasColumnType("int"); - - b.HasKey("Id"); - - b.ToTable("sources"); - - b.HasData( - new - { - Id = 1, - Title = "Jurassic Park", - TypeSrc = 0, - Year = 1993 - }, - new - { - Id = 2, - Title = "Le Seigneur des anneaux : La Communauté de l'anneau", - TypeSrc = 0, - Year = 2001 - }, - new - { - Id = 3, - Title = "Game of throne", - TypeSrc = 1, - Year = 2011 - }, - new - { - Id = 4, - Title = "Harry Potter à l'école des sorcier", - TypeSrc = 0, - Year = 1997 - }, - new - { - Id = 5, - Title = "Star Wars, épisode IV : Un nouvel espoir", - TypeSrc = 0, - Year = 1977 - }); - }); - - modelBuilder.Entity("Entity.Users", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("int"); - - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); - - b.Property("Created") - .HasColumnType("date") - .HasColumnName("Created"); - - b.Property("Email") - .IsRequired() - .HasMaxLength(50) - .HasColumnType("nvarchar(50)"); - - b.Property("IdImage") - .HasColumnType("int"); - - b.Property("Password") - .IsRequired() - .HasMaxLength(200) - .HasColumnType("nvarchar(200)"); - - b.Property("UserName") - .IsRequired() - .HasMaxLength(50) - .HasColumnType("nvarchar(50)"); - - b.HasKey("Id"); - - b.HasIndex("IdImage"); - - b.ToTable("users"); - - b.HasData( - new - { - Id = 1, - Created = new DateTime(2025, 5, 12, 0, 0, 0, 0, DateTimeKind.Unspecified), - Email = "jhonDhoe@gmail.com", - IdImage = 1, - Password = "1234", - UserName = "Jhon-Dhoe" - }, - new - { - Id = 2, - Created = new DateTime(2025, 3, 19, 0, 0, 0, 0, DateTimeKind.Unspecified), - Email = "lucy_rose@outlook.com", - IdImage = 2, - Password = "abcd", - UserName = "Lucy-Rose" - }, - new - { - Id = 3, - Created = new DateTime(2024, 11, 2, 0, 0, 0, 0, DateTimeKind.Unspecified), - Email = "mark.taylor@yahoo.com", - IdImage = 3, - Password = "5678", - UserName = "Mark-Taylor" - }, - new - { - Id = 4, - Created = new DateTime(2025, 2, 28, 0, 0, 0, 0, DateTimeKind.Unspecified), - Email = "sophie.martin@gmail.com", - IdImage = 4, - Password = "4321", - UserName = "Sophie-Martin" - }, - new - { - Id = 5, - Created = new DateTime(2025, 1, 15, 0, 0, 0, 0, DateTimeKind.Unspecified), - Email = "nathan_doe@aol.com", - IdImage = 5, - Password = "8765", - UserName = "Nathan-Doe" - }, - new - { - Id = 6, - Created = new DateTime(2025, 4, 7, 0, 0, 0, 0, DateTimeKind.Unspecified), - Email = "ella.brown@icloud.com", - IdImage = 6, - Password = "2468", - UserName = "Ella-Brown" - }, - new - { - Id = 7, - Created = new DateTime(2024, 12, 25, 0, 0, 0, 0, DateTimeKind.Unspecified), - Email = "oliver_smith@gmail.com", - IdImage = 7, - Password = "1357", - UserName = "Oliver-Smith" - }, - new - { - Id = 8, - Created = new DateTime(2025, 3, 5, 0, 0, 0, 0, DateTimeKind.Unspecified), - Email = "mia.jones@outlook.com", - IdImage = 8, - Password = "1122", - UserName = "Mia-Jones" - }, - new - { - Id = 9, - Created = new DateTime(2025, 2, 22, 0, 0, 0, 0, DateTimeKind.Unspecified), - Email = "kevin_williams@aol.com", - IdImage = 9, - Password = "2233", - UserName = "Kevin-Williams" - }, - new - { - Id = 10, - Created = new DateTime(2025, 1, 3, 0, 0, 0, 0, DateTimeKind.Unspecified), - Email = "olivia.white@yahoo.com", - IdImage = 10, - Password = "3344", - UserName = "Olivia-White" - }); - }); - - modelBuilder.Entity("Entity.Admin", b => - { - b.HasOne("Entity.Users", "User") - .WithMany() - .HasForeignKey("UserId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.Navigation("User"); - }); - - modelBuilder.Entity("Entity.Character", b => - { - b.HasOne("Entity.Images", "Images") - .WithMany("Characters") - .HasForeignKey("IdImage") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.Navigation("Images"); - }); - - modelBuilder.Entity("Entity.Commentary", b => - { - b.HasOne("Entity.Quote", "Quote") - .WithMany("Commentarys") - .HasForeignKey("IdQuote") - .OnDelete(DeleteBehavior.ClientCascade) - .IsRequired(); - - b.HasOne("Entity.Users", "User") - .WithMany() - .HasForeignKey("IdUser") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.Navigation("Quote"); - - b.Navigation("User"); - }); - - modelBuilder.Entity("Entity.DailyQuote", b => - { - b.HasOne("Entity.Quote", "Quote") - .WithMany("DailyQuotes") - .HasForeignKey("IdQuote") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.Navigation("Quote"); - }); - - modelBuilder.Entity("Entity.Favorite", b => - { - b.HasOne("Entity.Quote", "Quote") - .WithMany() - .HasForeignKey("IdQuote") - .OnDelete(DeleteBehavior.ClientCascade) - .IsRequired(); - - b.HasOne("Entity.Users", "Users") - .WithMany() - .HasForeignKey("IdUsers") - .OnDelete(DeleteBehavior.ClientCascade) - .IsRequired(); - - b.Navigation("Quote"); - - b.Navigation("Users"); - }); - - modelBuilder.Entity("Entity.Quiz", b => - { - b.HasOne("Entity.Images", "Images") - .WithMany("Quizs") - .HasForeignKey("IdImage") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.Navigation("Images"); - }); - - modelBuilder.Entity("Entity.QuizQuestion", b => - { - b.HasOne("Entity.Question", null) - .WithMany() - .HasForeignKey("IdQuestion") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.HasOne("Entity.Quiz", null) - .WithMany() - .HasForeignKey("IdQuiz") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - }); - - modelBuilder.Entity("Entity.Quote", b => - { - b.HasOne("Entity.Character", "Character") - .WithMany("Quotes") - .HasForeignKey("IdCharacter") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.HasOne("Entity.Source", "Source") - .WithMany("Quotes") - .HasForeignKey("IdSource") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.HasOne("Entity.Users", "User") - .WithMany("Quotes") - .HasForeignKey("IdUsersPropose"); - - b.Navigation("Character"); - - b.Navigation("Source"); - - b.Navigation("User"); - }); - - modelBuilder.Entity("Entity.Users", b => - { - b.HasOne("Entity.Images", "Images") - .WithMany("Users") - .HasForeignKey("IdImage") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.Navigation("Images"); - }); - - modelBuilder.Entity("Entity.Character", b => - { - b.Navigation("Quotes"); - }); - - modelBuilder.Entity("Entity.Images", b => - { - b.Navigation("Characters"); - - b.Navigation("Quizs"); - - b.Navigation("Users"); - }); - - modelBuilder.Entity("Entity.Quote", b => - { - b.Navigation("Commentarys"); - - b.Navigation("DailyQuotes"); - }); - - modelBuilder.Entity("Entity.Source", b => - { - b.Navigation("Quotes"); - }); - - modelBuilder.Entity("Entity.Users", b => - { - b.Navigation("Quotes"); - }); -#pragma warning restore 612, 618 - } - } -} diff --git a/WF_EF_Api/StubbedContextLib/Migrations/20250328102709_migr5.cs b/WF_EF_Api/StubbedContextLib/Migrations/20250328102709_migr5.cs deleted file mode 100644 index 28c1b1d..0000000 --- a/WF_EF_Api/StubbedContextLib/Migrations/20250328102709_migr5.cs +++ /dev/null @@ -1,126 +0,0 @@ -using Microsoft.EntityFrameworkCore.Migrations; - -#nullable disable - -namespace StubbedContextLib.Migrations -{ - /// - public partial class migr5 : Migration - { - /// - protected override void Up(MigrationBuilder migrationBuilder) - { - migrationBuilder.AddColumn( - name: "IsValid", - table: "question", - type: "bit", - nullable: false, - defaultValue: false); - - migrationBuilder.CreateTable( - name: "admins", - columns: table => new - { - IdUsers = table.Column(type: "int", nullable: false) - .Annotation("SqlServer:Identity", "1, 1"), - UserId = table.Column(type: "int", nullable: false) - }, - constraints: table => - { - table.PrimaryKey("PK_admins", x => x.IdUsers); - table.ForeignKey( - name: "FK_admins_users_UserId", - column: x => x.UserId, - principalTable: "users", - principalColumn: "Id", - onDelete: ReferentialAction.Cascade); - }); - - migrationBuilder.UpdateData( - table: "question", - keyColumn: "Id", - keyValue: 1, - column: "IsValid", - value: true); - - migrationBuilder.UpdateData( - table: "question", - keyColumn: "Id", - keyValue: 2, - column: "IsValid", - value: false); - - migrationBuilder.UpdateData( - table: "question", - keyColumn: "Id", - keyValue: 3, - column: "IsValid", - value: true); - - migrationBuilder.UpdateData( - table: "question", - keyColumn: "Id", - keyValue: 4, - column: "IsValid", - value: true); - - migrationBuilder.UpdateData( - table: "question", - keyColumn: "Id", - keyValue: 5, - column: "IsValid", - value: true); - - migrationBuilder.UpdateData( - table: "question", - keyColumn: "Id", - keyValue: 6, - column: "IsValid", - value: true); - - migrationBuilder.UpdateData( - table: "question", - keyColumn: "Id", - keyValue: 7, - column: "IsValid", - value: true); - - migrationBuilder.UpdateData( - table: "question", - keyColumn: "Id", - keyValue: 8, - column: "IsValid", - value: true); - - migrationBuilder.UpdateData( - table: "question", - keyColumn: "Id", - keyValue: 9, - column: "IsValid", - value: true); - - migrationBuilder.UpdateData( - table: "question", - keyColumn: "Id", - keyValue: 10, - column: "IsValid", - value: true); - - migrationBuilder.CreateIndex( - name: "IX_admins_UserId", - table: "admins", - column: "UserId"); - } - - /// - protected override void Down(MigrationBuilder migrationBuilder) - { - migrationBuilder.DropTable( - name: "admins"); - - migrationBuilder.DropColumn( - name: "IsValid", - table: "question"); - } - } -} diff --git a/WF_EF_Api/StubbedContextLib/Migrations/20250401141906_suprDailyQuote.cs b/WF_EF_Api/StubbedContextLib/Migrations/20250401141906_suprDailyQuote.cs deleted file mode 100644 index 1f3b252..0000000 --- a/WF_EF_Api/StubbedContextLib/Migrations/20250401141906_suprDailyQuote.cs +++ /dev/null @@ -1,61 +0,0 @@ -using Microsoft.EntityFrameworkCore.Migrations; - -#nullable disable - -namespace StubbedContextLib.Migrations -{ - /// - public partial class suprDailyQuote : Migration - { - /// - protected override void Up(MigrationBuilder migrationBuilder) - { - migrationBuilder.DropTable( - name: "dailyquotes"); - - migrationBuilder.UpdateData( - table: "quotes", - keyColumn: "Id", - keyValue: 10, - column: "IsValid", - value: false); - } - - /// - protected override void Down(MigrationBuilder migrationBuilder) - { - migrationBuilder.CreateTable( - name: "dailyquotes", - columns: table => new - { - IdQuote = table.Column(type: "int", nullable: false) - }, - constraints: table => - { - table.PrimaryKey("PK_dailyquotes", x => x.IdQuote); - table.ForeignKey( - name: "FK_dailyquotes_quotes_IdQuote", - column: x => x.IdQuote, - principalTable: "quotes", - principalColumn: "Id", - onDelete: ReferentialAction.Cascade); - }); - - migrationBuilder.InsertData( - table: "dailyquotes", - column: "IdQuote", - values: new object[] - { - 1, - 5 - }); - - migrationBuilder.UpdateData( - table: "quotes", - keyColumn: "Id", - keyValue: 10, - column: "IsValid", - value: true); - } - } -} diff --git a/WF_EF_Api/StubbedContextLib/Migrations/20250401143030_myFirstMigration.Designer.cs b/WF_EF_Api/StubbedContextLib/Migrations/20250401143030_myFirstMigration.Designer.cs deleted file mode 100644 index de2bfe4..0000000 --- a/WF_EF_Api/StubbedContextLib/Migrations/20250401143030_myFirstMigration.Designer.cs +++ /dev/null @@ -1,1107 +0,0 @@ -// -using System; -using Microsoft.EntityFrameworkCore; -using Microsoft.EntityFrameworkCore.Infrastructure; -using Microsoft.EntityFrameworkCore.Metadata; -using Microsoft.EntityFrameworkCore.Migrations; -using Microsoft.EntityFrameworkCore.Storage.ValueConversion; -using StubbedContextLib; - -#nullable disable - -namespace StubbedContextLib.Migrations -{ - [DbContext(typeof(StubWTFContext))] - [Migration("20250401143030_myFirstMigration")] - partial class myFirstMigration - { - /// - protected override void BuildTargetModel(ModelBuilder modelBuilder) - { -#pragma warning disable 612, 618 - modelBuilder - .HasAnnotation("ProductVersion", "9.0.3") - .HasAnnotation("Relational:MaxIdentifierLength", 128); - - SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder); - - modelBuilder.Entity("Entity.Admin", b => - { - b.Property("IdUsers") - .ValueGeneratedOnAdd() - .HasColumnType("int"); - - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("IdUsers")); - - b.Property("UserId") - .HasColumnType("int"); - - b.HasKey("IdUsers"); - - b.HasIndex("UserId"); - - b.ToTable("admins"); - }); - - modelBuilder.Entity("Entity.Character", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("int"); - - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); - - b.Property("IdImage") - .HasColumnType("int"); - - b.Property("Name") - .IsRequired() - .HasMaxLength(50) - .HasColumnType("nvarchar(50)"); - - b.HasKey("Id"); - - b.HasIndex("IdImage"); - - b.ToTable("characters"); - - b.HasData( - new - { - Id = 1, - IdImage = 1, - Name = "Alan Grant" - }, - new - { - Id = 2, - IdImage = 2, - Name = "Aragorn" - }, - new - { - Id = 3, - IdImage = 3, - Name = "Legolas" - }, - new - { - Id = 4, - IdImage = 4, - Name = "Frodon" - }, - new - { - Id = 5, - IdImage = 5, - Name = "Dobby" - }, - new - { - Id = 6, - IdImage = 6, - Name = "Jon Snow" - }, - new - { - Id = 7, - IdImage = 7, - Name = "Daenerys Targaryen" - }, - new - { - Id = 8, - IdImage = 8, - Name = "Luke Skywalker" - }, - new - { - Id = 9, - IdImage = 9, - Name = "Princess Leia" - }, - new - { - Id = 10, - IdImage = 10, - Name = "Harry Potter" - }); - }); - - modelBuilder.Entity("Entity.Commentary", b => - { - b.Property("IdUser") - .HasColumnType("int"); - - b.Property("IdQuote") - .HasColumnType("int"); - - b.Property("Comment") - .IsRequired() - .HasMaxLength(100) - .HasColumnType("nvarchar(100)"); - - b.Property("DateCommentary") - .HasColumnType("date") - .HasColumnName("DateCommentary"); - - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("int"); - - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); - - b.HasKey("IdUser", "IdQuote"); - - b.HasIndex("IdQuote"); - - b.ToTable("comments"); - - b.HasData( - new - { - IdUser = 2, - IdQuote = 1, - Comment = "Ce film est le meilleur", - DateCommentary = new DateTime(2025, 2, 3, 0, 0, 0, 0, DateTimeKind.Unspecified), - Id = 1 - }, - new - { - IdUser = 3, - IdQuote = 1, - Comment = "Very good", - DateCommentary = new DateTime(2025, 3, 11, 0, 0, 0, 0, DateTimeKind.Unspecified), - Id = 2 - }); - }); - - modelBuilder.Entity("Entity.DailyQuote", b => - { - b.Property("IdQuote") - .HasColumnType("int"); - - b.HasKey("IdQuote"); - - b.ToTable("dailyquotes"); - - b.HasData( - new - { - IdQuote = 1 - }, - new - { - IdQuote = 5 - }); - }); - - modelBuilder.Entity("Entity.Favorite", b => - { - b.Property("IdQuote") - .HasColumnType("int"); - - b.Property("IdUsers") - .HasColumnType("int"); - - b.HasKey("IdQuote", "IdUsers"); - - b.HasIndex("IdUsers"); - - b.ToTable("favorites"); - - b.HasData( - new - { - IdQuote = 2, - IdUsers = 8 - }, - new - { - IdQuote = 5, - IdUsers = 3 - }, - new - { - IdQuote = 9, - IdUsers = 1 - }, - new - { - IdQuote = 4, - IdUsers = 10 - }, - new - { - IdQuote = 3, - IdUsers = 2 - }, - new - { - IdQuote = 6, - IdUsers = 7 - }, - new - { - IdQuote = 1, - IdUsers = 6 - }, - new - { - IdQuote = 8, - IdUsers = 9 - }, - new - { - IdQuote = 10, - IdUsers = 5 - }); - }); - - modelBuilder.Entity("Entity.Images", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("int"); - - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); - - b.Property("ImgPath") - .IsRequired() - .HasColumnType("nvarchar(max)"); - - b.HasKey("Id"); - - b.ToTable("images"); - - b.HasData( - new - { - Id = 1, - ImgPath = "https://th.bing.com/th/id/OIP.TJuWNCsibz8MVmhdNQEdMwHaE8?w=244&h=180&c=7&r=0&o=5&pid=1.7" - }, - new - { - Id = 2, - ImgPath = "https://th.bing.com/th/id/OIP.NgXRQ5-IknA6_qOPFhLWIwHaHK?w=165&h=180&c=7&r=0&o=5&pid=1.7" - }, - new - { - Id = 3, - ImgPath = "https://th.bing.com/th/id/OIP.XcJoJ6bC9sAMjol1pJn5UQHaLH?w=118&h=180&c=7&r=0&o=5&pid=1.7" - }, - new - { - Id = 4, - ImgPath = "https://th.bing.com/th/id/OIP.PPIESqZaNDa-qUcfSDXhdQHaGK?w=210&h=180&c=7&r=0&o=5&pid=1.7" - }, - new - { - Id = 5, - ImgPath = "https://th.bing.com/th/id/OIP.XBghSl2kfRNNtQoSxc901wHaHa?w=177&h=180&c=7&r=0&o=5&pid=1.7" - }, - new - { - Id = 6, - ImgPath = "https://th.bing.com/th/id/OIP.af1Aid64cqEKoIOBgCPxtQHaJO?w=145&h=182&c=7&r=0&o=5&pid=1.7" - }, - new - { - Id = 7, - ImgPath = "https://th.bing.com/th/id/OIP.ri5vSXr5lNTLt4DO6KQXyQHaI4?w=158&h=189&c=7&r=0&o=5&pid=1.7" - }, - new - { - Id = 8, - ImgPath = "https://th.bing.com/th/id/OIP.uPTRLR8uspCiafiunUqKfQHaMJ?w=115&h=180&c=7&r=0&o=5&pid=1.7" - }, - new - { - Id = 9, - ImgPath = "https://th.bing.com/th/id/OIP.hcJis4rKbyQtugsoFJU2ngHaM_?w=118&h=207&c=7&r=0&o=5&pid=1.7" - }, - new - { - Id = 10, - ImgPath = "https://th.bing.com/th/id/OIP.Py1_XfUrKJY_A6tYEmFS5wHaE8?w=280&h=187&c=7&r=0&o=5&pid=1.7" - }); - }); - - modelBuilder.Entity("Entity.Question", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("int"); - - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); - - b.Property("AnswerA") - .IsRequired() - .HasMaxLength(50) - .HasColumnType("nvarchar(50)"); - - b.Property("AnswerB") - .IsRequired() - .HasMaxLength(50) - .HasColumnType("nvarchar(50)"); - - b.Property("AnswerC") - .IsRequired() - .HasMaxLength(50) - .HasColumnType("nvarchar(50)"); - - b.Property("AnswerD") - .IsRequired() - .HasMaxLength(50) - .HasColumnType("nvarchar(50)"); - - b.Property("CorrectAnswer") - .IsRequired() - .HasMaxLength(1) - .HasColumnType("nvarchar(1)"); - - b.Property("IsValid") - .HasColumnType("bit"); - - b.Property("Text") - .IsRequired() - .HasMaxLength(200) - .HasColumnType("nvarchar(200)"); - - b.HasKey("Id"); - - b.ToTable("question"); - - b.HasData( - new - { - Id = 1, - AnswerA = "Gimli", - AnswerB = "Aragorn", - AnswerC = "Frodon", - AnswerD = "Gandalf", - CorrectAnswer = "B", - IsValid = true, - Text = "Qui est le leader de la Communauté de l'Anneau ?" - }, - new - { - Id = 2, - AnswerA = "Serdaigle", - AnswerB = "Gryffondor", - AnswerC = "Serpentard", - AnswerD = "Poufsouffle", - CorrectAnswer = "B", - IsValid = false, - Text = "Dans quelle maison Harry Potter est-il ?" - }, - new - { - Id = 3, - AnswerA = "Saroumane", - AnswerB = "Sauron", - AnswerC = "Gollum", - AnswerD = "Gothmog", - CorrectAnswer = "B", - IsValid = true, - Text = "Qui est le Seigneur des Ténèbres dans la saga Le Seigneur des Anneaux ?" - }, - new - { - Id = 4, - AnswerA = "Han Solo", - AnswerB = "Princesse Leia", - AnswerC = "Chewbacca", - AnswerD = "R2-D2", - CorrectAnswer = "A", - IsValid = true, - Text = "Dans le film Star Wars : Episode IV, qui sauve Luke Skywalker de l'Étoile de la Mort ?" - }, - new - { - Id = 5, - AnswerA = "Reine Jadis", - AnswerB = "Aslan", - AnswerC = "Edmund", - AnswerD = "Lucy", - CorrectAnswer = "B", - IsValid = true, - Text = "Qui est le souverain de Narnia dans Le Lion, la Sorcière Blanche et l'Armoire Magique ?" - }, - new - { - Id = 6, - AnswerA = "Smaug", - AnswerB = "Falkor", - AnswerC = "Norbert", - AnswerD = "Shenron", - CorrectAnswer = "A", - IsValid = true, - Text = "Quel est le nom du dragon dans Le Hobbit ?" - }, - new - { - Id = 7, - AnswerA = "Bella Swan", - AnswerB = "Edward Cullen", - AnswerC = "Jacob Black", - AnswerD = "Victoria", - CorrectAnswer = "A", - IsValid = true, - Text = "Qui est la première personne à être mordue par un vampire dans Twilight ?" - }, - new - { - Id = 8, - AnswerA = "Obi-Wan Kenobi", - AnswerB = "Yoda", - AnswerC = "Han Solo", - AnswerD = "Luke Skywalker", - CorrectAnswer = "A", - IsValid = true, - Text = "Quel personnage dit Que la Force soit avec toi dans Star Wars ?" - }, - new - { - Id = 9, - AnswerA = "Dr. Ellie Sattler", - AnswerB = "Alan Grant", - AnswerC = "John Hammond", - AnswerD = "Dennis Nedry", - CorrectAnswer = "B", - IsValid = true, - Text = "Dans Jurassic Park, quel est le nom du paléontologue sur l'île ?" - }, - new - { - Id = 10, - AnswerA = "Cersei Lannister", - AnswerB = "Arya Stark", - AnswerC = "Daenerys Targaryen", - AnswerD = "Sansa Stark", - CorrectAnswer = "C", - IsValid = true, - Text = "Dans Game of Thrones, qui est surnommée la Mère des Dragons ?" - }); - }); - - modelBuilder.Entity("Entity.Quiz", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("int"); - - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); - - b.Property("IdImage") - .HasColumnType("int"); - - b.Property("NbQuestion") - .HasColumnType("int"); - - b.Property("Title") - .IsRequired() - .HasMaxLength(50) - .HasColumnType("nvarchar(50)"); - - b.HasKey("Id"); - - b.HasIndex("IdImage"); - - b.ToTable("quizzes"); - - b.HasData( - new - { - Id = 1, - IdImage = 1, - NbQuestion = 5, - Title = "Quiz 1" - }, - new - { - Id = 2, - IdImage = 2, - NbQuestion = 5, - Title = "Quiz 2" - }); - }); - - modelBuilder.Entity("Entity.QuizQuestion", b => - { - b.Property("IdQuestion") - .HasColumnType("int"); - - b.Property("IdQuiz") - .HasColumnType("int"); - - b.HasKey("IdQuestion", "IdQuiz"); - - b.HasIndex("IdQuiz"); - - b.ToTable("QuizQuestion"); - - b.HasData( - new - { - IdQuestion = 1, - IdQuiz = 1 - }, - new - { - IdQuestion = 2, - IdQuiz = 1 - }, - new - { - IdQuestion = 3, - IdQuiz = 1 - }, - new - { - IdQuestion = 4, - IdQuiz = 1 - }, - new - { - IdQuestion = 5, - IdQuiz = 1 - }, - new - { - IdQuestion = 6, - IdQuiz = 2 - }, - new - { - IdQuestion = 7, - IdQuiz = 2 - }, - new - { - IdQuestion = 8, - IdQuiz = 2 - }, - new - { - IdQuestion = 9, - IdQuiz = 2 - }, - new - { - IdQuestion = 10, - IdQuiz = 2 - }); - }); - - modelBuilder.Entity("Entity.Quote", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("int"); - - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); - - b.Property("Content") - .IsRequired() - .HasMaxLength(100) - .HasColumnType("nvarchar(100)"); - - b.Property("IdCharacter") - .HasColumnType("int"); - - b.Property("IdSource") - .HasColumnType("int"); - - b.Property("IdUsersPropose") - .HasColumnType("int"); - - b.Property("IsValid") - .HasColumnType("bit"); - - b.Property("Langage") - .HasColumnType("int"); - - b.Property("Likes") - .HasColumnType("int"); - - b.HasKey("Id"); - - b.HasIndex("IdCharacter"); - - b.HasIndex("IdSource"); - - b.HasIndex("IdUsersPropose"); - - b.ToTable("quotes"); - - b.HasData( - new - { - Id = 1, - Content = "Je n'y crois pas. Je n'y crois pas. Ce n'est pas possible", - IdCharacter = 1, - IdSource = 1, - IdUsersPropose = 1, - IsValid = true, - Langage = 1, - Likes = 11025 - }, - new - { - Id = 2, - Content = "There is always hope", - IdCharacter = 2, - IdSource = 2, - IdUsersPropose = 1, - IsValid = true, - Langage = 0, - Likes = 11025 - }, - new - { - Id = 3, - Content = "A red sun rises. Blood has been spilled this night.", - IdCharacter = 3, - IdSource = 2, - IdUsersPropose = 1, - IsValid = true, - Langage = 0, - Likes = 11025 - }, - new - { - Id = 4, - Content = "I wish the Ring had never come to me.I wish none of this had happened.", - IdCharacter = 4, - IdSource = 2, - IdUsersPropose = 1, - IsValid = true, - Langage = 0, - Likes = 11025 - }, - new - { - Id = 5, - Content = "Dobby is a free elf!", - IdCharacter = 5, - IdSource = 4, - IdUsersPropose = 1, - IsValid = true, - Langage = 0, - Likes = 11025 - }, - new - { - Id = 6, - Content = "Winter is comming", - IdCharacter = 6, - IdSource = 3, - IdUsersPropose = 1, - IsValid = true, - Langage = 0, - Likes = 11025 - }, - new - { - Id = 7, - Content = "Je suis la dernière Targaryen. Je suis la reine des dragons", - IdCharacter = 7, - IdSource = 3, - IdUsersPropose = 1, - IsValid = true, - Langage = 1, - Likes = 11025 - }, - new - { - Id = 8, - Content = "Je ne suis pas prêt à affronter ça. C'est trop pour moi.", - IdCharacter = 8, - IdSource = 5, - IdUsersPropose = 1, - IsValid = true, - Langage = 1, - Likes = 11025 - }, - new - { - Id = 9, - Content = "Aidez-moi, Obi-Wan Kenobi, vous êtes mon seul espoir.", - IdCharacter = 9, - IdSource = 5, - IdUsersPropose = 1, - IsValid = true, - Langage = 1, - Likes = 11025 - }, - new - { - Id = 10, - Content = "La quoi ?", - IdCharacter = 10, - IdSource = 4, - IdUsersPropose = 1, - IsValid = false, - Langage = 1, - Likes = 11025 - }); - }); - - modelBuilder.Entity("Entity.Source", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("int"); - - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); - - b.Property("Title") - .IsRequired() - .HasMaxLength(100) - .HasColumnType("nvarchar(100)"); - - b.Property("TypeSrc") - .HasColumnType("int"); - - b.Property("Year") - .HasColumnType("int"); - - b.HasKey("Id"); - - b.ToTable("sources"); - - b.HasData( - new - { - Id = 1, - Title = "Jurassic Park", - TypeSrc = 0, - Year = 1993 - }, - new - { - Id = 2, - Title = "Le Seigneur des anneaux : La Communauté de l'anneau", - TypeSrc = 0, - Year = 2001 - }, - new - { - Id = 3, - Title = "Game of throne", - TypeSrc = 1, - Year = 2011 - }, - new - { - Id = 4, - Title = "Harry Potter à l'école des sorcier", - TypeSrc = 0, - Year = 1997 - }, - new - { - Id = 5, - Title = "Star Wars, épisode IV : Un nouvel espoir", - TypeSrc = 0, - Year = 1977 - }); - }); - - modelBuilder.Entity("Entity.Users", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("int"); - - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); - - b.Property("Created") - .HasColumnType("date") - .HasColumnName("Created"); - - b.Property("Email") - .IsRequired() - .HasMaxLength(50) - .HasColumnType("nvarchar(50)"); - - b.Property("IdImage") - .HasColumnType("int"); - - b.Property("Password") - .IsRequired() - .HasMaxLength(200) - .HasColumnType("nvarchar(200)"); - - b.Property("UserName") - .IsRequired() - .HasMaxLength(50) - .HasColumnType("nvarchar(50)"); - - b.HasKey("Id"); - - b.HasIndex("IdImage"); - - b.ToTable("users"); - - b.HasData( - new - { - Id = 1, - Created = new DateTime(2025, 5, 12, 0, 0, 0, 0, DateTimeKind.Unspecified), - Email = "jhonDhoe@gmail.com", - IdImage = 1, - Password = "1234", - UserName = "Jhon-Dhoe" - }, - new - { - Id = 2, - Created = new DateTime(2025, 3, 19, 0, 0, 0, 0, DateTimeKind.Unspecified), - Email = "lucy_rose@outlook.com", - IdImage = 2, - Password = "abcd", - UserName = "Lucy-Rose" - }, - new - { - Id = 3, - Created = new DateTime(2024, 11, 2, 0, 0, 0, 0, DateTimeKind.Unspecified), - Email = "mark.taylor@yahoo.com", - IdImage = 3, - Password = "5678", - UserName = "Mark-Taylor" - }, - new - { - Id = 4, - Created = new DateTime(2025, 2, 28, 0, 0, 0, 0, DateTimeKind.Unspecified), - Email = "sophie.martin@gmail.com", - IdImage = 4, - Password = "4321", - UserName = "Sophie-Martin" - }, - new - { - Id = 5, - Created = new DateTime(2025, 1, 15, 0, 0, 0, 0, DateTimeKind.Unspecified), - Email = "nathan_doe@aol.com", - IdImage = 5, - Password = "8765", - UserName = "Nathan-Doe" - }, - new - { - Id = 6, - Created = new DateTime(2025, 4, 7, 0, 0, 0, 0, DateTimeKind.Unspecified), - Email = "ella.brown@icloud.com", - IdImage = 6, - Password = "2468", - UserName = "Ella-Brown" - }, - new - { - Id = 7, - Created = new DateTime(2024, 12, 25, 0, 0, 0, 0, DateTimeKind.Unspecified), - Email = "oliver_smith@gmail.com", - IdImage = 7, - Password = "1357", - UserName = "Oliver-Smith" - }, - new - { - Id = 8, - Created = new DateTime(2025, 3, 5, 0, 0, 0, 0, DateTimeKind.Unspecified), - Email = "mia.jones@outlook.com", - IdImage = 8, - Password = "1122", - UserName = "Mia-Jones" - }, - new - { - Id = 9, - Created = new DateTime(2025, 2, 22, 0, 0, 0, 0, DateTimeKind.Unspecified), - Email = "kevin_williams@aol.com", - IdImage = 9, - Password = "2233", - UserName = "Kevin-Williams" - }, - new - { - Id = 10, - Created = new DateTime(2025, 1, 3, 0, 0, 0, 0, DateTimeKind.Unspecified), - Email = "olivia.white@yahoo.com", - IdImage = 10, - Password = "3344", - UserName = "Olivia-White" - }); - }); - - modelBuilder.Entity("Entity.Admin", b => - { - b.HasOne("Entity.Users", "User") - .WithMany() - .HasForeignKey("UserId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.Navigation("User"); - }); - - modelBuilder.Entity("Entity.Character", b => - { - b.HasOne("Entity.Images", "Images") - .WithMany("Characters") - .HasForeignKey("IdImage") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.Navigation("Images"); - }); - - modelBuilder.Entity("Entity.Commentary", b => - { - b.HasOne("Entity.Quote", "Quote") - .WithMany("Commentarys") - .HasForeignKey("IdQuote") - .OnDelete(DeleteBehavior.ClientCascade) - .IsRequired(); - - b.HasOne("Entity.Users", "User") - .WithMany() - .HasForeignKey("IdUser") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.Navigation("Quote"); - - b.Navigation("User"); - }); - - modelBuilder.Entity("Entity.DailyQuote", b => - { - b.HasOne("Entity.Quote", "Quote") - .WithMany("DailyQuotes") - .HasForeignKey("IdQuote") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.Navigation("Quote"); - }); - - modelBuilder.Entity("Entity.Favorite", b => - { - b.HasOne("Entity.Quote", "Quote") - .WithMany() - .HasForeignKey("IdQuote") - .OnDelete(DeleteBehavior.ClientCascade) - .IsRequired(); - - b.HasOne("Entity.Users", "Users") - .WithMany() - .HasForeignKey("IdUsers") - .OnDelete(DeleteBehavior.ClientCascade) - .IsRequired(); - - b.Navigation("Quote"); - - b.Navigation("Users"); - }); - - modelBuilder.Entity("Entity.Quiz", b => - { - b.HasOne("Entity.Images", "Images") - .WithMany("Quizs") - .HasForeignKey("IdImage") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.Navigation("Images"); - }); - - modelBuilder.Entity("Entity.QuizQuestion", b => - { - b.HasOne("Entity.Question", null) - .WithMany() - .HasForeignKey("IdQuestion") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.HasOne("Entity.Quiz", null) - .WithMany() - .HasForeignKey("IdQuiz") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - }); - - modelBuilder.Entity("Entity.Quote", b => - { - b.HasOne("Entity.Character", "Character") - .WithMany("Quotes") - .HasForeignKey("IdCharacter") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.HasOne("Entity.Source", "Source") - .WithMany("Quotes") - .HasForeignKey("IdSource") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.HasOne("Entity.Users", "User") - .WithMany("Quotes") - .HasForeignKey("IdUsersPropose"); - - b.Navigation("Character"); - - b.Navigation("Source"); - - b.Navigation("User"); - }); - - modelBuilder.Entity("Entity.Users", b => - { - b.HasOne("Entity.Images", "Images") - .WithMany("Users") - .HasForeignKey("IdImage") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.Navigation("Images"); - }); - - modelBuilder.Entity("Entity.Character", b => - { - b.Navigation("Quotes"); - }); - - modelBuilder.Entity("Entity.Images", b => - { - b.Navigation("Characters"); - - b.Navigation("Quizs"); - - b.Navigation("Users"); - }); - - modelBuilder.Entity("Entity.Quote", b => - { - b.Navigation("Commentarys"); - - b.Navigation("DailyQuotes"); - }); - - modelBuilder.Entity("Entity.Source", b => - { - b.Navigation("Quotes"); - }); - - modelBuilder.Entity("Entity.Users", b => - { - b.Navigation("Quotes"); - }); -#pragma warning restore 612, 618 - } - } -} diff --git a/WF_EF_Api/StubbedContextLib/Migrations/20250401143030_myFirstMigration.cs b/WF_EF_Api/StubbedContextLib/Migrations/20250401143030_myFirstMigration.cs deleted file mode 100644 index 78898b5..0000000 --- a/WF_EF_Api/StubbedContextLib/Migrations/20250401143030_myFirstMigration.cs +++ /dev/null @@ -1,32 +0,0 @@ -using Microsoft.EntityFrameworkCore.Migrations; - -#nullable disable - -namespace StubbedContextLib.Migrations -{ - /// - public partial class myFirstMigration : Migration - { - /// - protected override void Up(MigrationBuilder migrationBuilder) - { - migrationBuilder.UpdateData( - table: "quotes", - keyColumn: "Id", - keyValue: 10, - column: "IsValid", - value: false); - } - - /// - protected override void Down(MigrationBuilder migrationBuilder) - { - migrationBuilder.UpdateData( - table: "quotes", - keyColumn: "Id", - keyValue: 10, - column: "IsValid", - value: true); - } - } -} diff --git a/WF_EF_Api/StubbedContextLib/Migrations/20250402084447_migration2-04.Designer.cs b/WF_EF_Api/StubbedContextLib/Migrations/20250402084447_migration2-04.Designer.cs deleted file mode 100644 index 1ecdc86..0000000 --- a/WF_EF_Api/StubbedContextLib/Migrations/20250402084447_migration2-04.Designer.cs +++ /dev/null @@ -1,1074 +0,0 @@ -// -using System; -using Microsoft.EntityFrameworkCore; -using Microsoft.EntityFrameworkCore.Infrastructure; -using Microsoft.EntityFrameworkCore.Metadata; -using Microsoft.EntityFrameworkCore.Migrations; -using Microsoft.EntityFrameworkCore.Storage.ValueConversion; -using StubbedContextLib; - -#nullable disable - -namespace StubbedContextLib.Migrations -{ - [DbContext(typeof(StubWTFContext))] - [Migration("20250402084447_migration2-04")] - partial class migration204 - { - /// - protected override void BuildTargetModel(ModelBuilder modelBuilder) - { -#pragma warning disable 612, 618 - modelBuilder - .HasAnnotation("ProductVersion", "9.0.3") - .HasAnnotation("Relational:MaxIdentifierLength", 128); - - SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder); - - modelBuilder.Entity("Entity.Admin", b => - { - b.Property("IdUsers") - .ValueGeneratedOnAdd() - .HasColumnType("int"); - - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("IdUsers")); - - b.Property("UserId") - .HasColumnType("int"); - - b.HasKey("IdUsers"); - - b.HasIndex("UserId"); - - b.ToTable("admins"); - }); - - modelBuilder.Entity("Entity.Character", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("int"); - - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); - - b.Property("IdImage") - .HasColumnType("int"); - - b.Property("Name") - .IsRequired() - .HasMaxLength(50) - .HasColumnType("nvarchar(50)"); - - b.HasKey("Id"); - - b.HasIndex("IdImage"); - - b.ToTable("characters"); - - b.HasData( - new - { - Id = 1, - IdImage = 1, - Name = "Alan Grant" - }, - new - { - Id = 2, - IdImage = 2, - Name = "Aragorn" - }, - new - { - Id = 3, - IdImage = 3, - Name = "Legolas" - }, - new - { - Id = 4, - IdImage = 4, - Name = "Frodon" - }, - new - { - Id = 5, - IdImage = 5, - Name = "Dobby" - }, - new - { - Id = 6, - IdImage = 6, - Name = "Jon Snow" - }, - new - { - Id = 7, - IdImage = 7, - Name = "Daenerys Targaryen" - }, - new - { - Id = 8, - IdImage = 8, - Name = "Luke Skywalker" - }, - new - { - Id = 9, - IdImage = 9, - Name = "Princess Leia" - }, - new - { - Id = 10, - IdImage = 10, - Name = "Harry Potter" - }); - }); - - modelBuilder.Entity("Entity.Commentary", b => - { - b.Property("IdUser") - .HasColumnType("int"); - - b.Property("IdQuote") - .HasColumnType("int"); - - b.Property("Comment") - .IsRequired() - .HasMaxLength(100) - .HasColumnType("nvarchar(100)"); - - b.Property("DateCommentary") - .HasColumnType("date") - .HasColumnName("DateCommentary"); - - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("int"); - - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); - - b.HasKey("IdUser", "IdQuote"); - - b.HasIndex("IdQuote"); - - b.ToTable("comments"); - - b.HasData( - new - { - IdUser = 2, - IdQuote = 1, - Comment = "Ce film est le meilleur", - DateCommentary = new DateTime(2025, 2, 3, 0, 0, 0, 0, DateTimeKind.Unspecified), - Id = 1 - }, - new - { - IdUser = 3, - IdQuote = 1, - Comment = "Very good", - DateCommentary = new DateTime(2025, 3, 11, 0, 0, 0, 0, DateTimeKind.Unspecified), - Id = 2 - }); - }); - - modelBuilder.Entity("Entity.Favorite", b => - { - b.Property("IdQuote") - .HasColumnType("int"); - - b.Property("IdUsers") - .HasColumnType("int"); - - b.HasKey("IdQuote", "IdUsers"); - - b.HasIndex("IdUsers"); - - b.ToTable("favorites"); - - b.HasData( - new - { - IdQuote = 2, - IdUsers = 8 - }, - new - { - IdQuote = 5, - IdUsers = 3 - }, - new - { - IdQuote = 9, - IdUsers = 1 - }, - new - { - IdQuote = 4, - IdUsers = 10 - }, - new - { - IdQuote = 3, - IdUsers = 2 - }, - new - { - IdQuote = 6, - IdUsers = 7 - }, - new - { - IdQuote = 1, - IdUsers = 6 - }, - new - { - IdQuote = 8, - IdUsers = 9 - }, - new - { - IdQuote = 10, - IdUsers = 5 - }); - }); - - modelBuilder.Entity("Entity.Images", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("int"); - - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); - - b.Property("ImgPath") - .IsRequired() - .HasColumnType("nvarchar(max)"); - - b.HasKey("Id"); - - b.ToTable("images"); - - b.HasData( - new - { - Id = 1, - ImgPath = "https://th.bing.com/th/id/OIP.TJuWNCsibz8MVmhdNQEdMwHaE8?w=244&h=180&c=7&r=0&o=5&pid=1.7" - }, - new - { - Id = 2, - ImgPath = "https://th.bing.com/th/id/OIP.NgXRQ5-IknA6_qOPFhLWIwHaHK?w=165&h=180&c=7&r=0&o=5&pid=1.7" - }, - new - { - Id = 3, - ImgPath = "https://th.bing.com/th/id/OIP.XcJoJ6bC9sAMjol1pJn5UQHaLH?w=118&h=180&c=7&r=0&o=5&pid=1.7" - }, - new - { - Id = 4, - ImgPath = "https://th.bing.com/th/id/OIP.PPIESqZaNDa-qUcfSDXhdQHaGK?w=210&h=180&c=7&r=0&o=5&pid=1.7" - }, - new - { - Id = 5, - ImgPath = "https://th.bing.com/th/id/OIP.XBghSl2kfRNNtQoSxc901wHaHa?w=177&h=180&c=7&r=0&o=5&pid=1.7" - }, - new - { - Id = 6, - ImgPath = "https://th.bing.com/th/id/OIP.af1Aid64cqEKoIOBgCPxtQHaJO?w=145&h=182&c=7&r=0&o=5&pid=1.7" - }, - new - { - Id = 7, - ImgPath = "https://th.bing.com/th/id/OIP.ri5vSXr5lNTLt4DO6KQXyQHaI4?w=158&h=189&c=7&r=0&o=5&pid=1.7" - }, - new - { - Id = 8, - ImgPath = "https://th.bing.com/th/id/OIP.uPTRLR8uspCiafiunUqKfQHaMJ?w=115&h=180&c=7&r=0&o=5&pid=1.7" - }, - new - { - Id = 9, - ImgPath = "https://th.bing.com/th/id/OIP.hcJis4rKbyQtugsoFJU2ngHaM_?w=118&h=207&c=7&r=0&o=5&pid=1.7" - }, - new - { - Id = 10, - ImgPath = "https://th.bing.com/th/id/OIP.Py1_XfUrKJY_A6tYEmFS5wHaE8?w=280&h=187&c=7&r=0&o=5&pid=1.7" - }); - }); - - modelBuilder.Entity("Entity.Question", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("int"); - - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); - - b.Property("AnswerA") - .IsRequired() - .HasMaxLength(50) - .HasColumnType("nvarchar(50)"); - - b.Property("AnswerB") - .IsRequired() - .HasMaxLength(50) - .HasColumnType("nvarchar(50)"); - - b.Property("AnswerC") - .IsRequired() - .HasMaxLength(50) - .HasColumnType("nvarchar(50)"); - - b.Property("AnswerD") - .IsRequired() - .HasMaxLength(50) - .HasColumnType("nvarchar(50)"); - - b.Property("CorrectAnswer") - .IsRequired() - .HasMaxLength(1) - .HasColumnType("nvarchar(1)"); - - b.Property("IsValid") - .HasColumnType("bit"); - - b.Property("Text") - .IsRequired() - .HasMaxLength(200) - .HasColumnType("nvarchar(200)"); - - b.HasKey("Id"); - - b.ToTable("question"); - - b.HasData( - new - { - Id = 1, - AnswerA = "Gimli", - AnswerB = "Aragorn", - AnswerC = "Frodon", - AnswerD = "Gandalf", - CorrectAnswer = "B", - IsValid = true, - Text = "Qui est le leader de la Communauté de l'Anneau ?" - }, - new - { - Id = 2, - AnswerA = "Serdaigle", - AnswerB = "Gryffondor", - AnswerC = "Serpentard", - AnswerD = "Poufsouffle", - CorrectAnswer = "B", - IsValid = false, - Text = "Dans quelle maison Harry Potter est-il ?" - }, - new - { - Id = 3, - AnswerA = "Saroumane", - AnswerB = "Sauron", - AnswerC = "Gollum", - AnswerD = "Gothmog", - CorrectAnswer = "B", - IsValid = true, - Text = "Qui est le Seigneur des Ténèbres dans la saga Le Seigneur des Anneaux ?" - }, - new - { - Id = 4, - AnswerA = "Han Solo", - AnswerB = "Princesse Leia", - AnswerC = "Chewbacca", - AnswerD = "R2-D2", - CorrectAnswer = "A", - IsValid = true, - Text = "Dans le film Star Wars : Episode IV, qui sauve Luke Skywalker de l'Étoile de la Mort ?" - }, - new - { - Id = 5, - AnswerA = "Reine Jadis", - AnswerB = "Aslan", - AnswerC = "Edmund", - AnswerD = "Lucy", - CorrectAnswer = "B", - IsValid = true, - Text = "Qui est le souverain de Narnia dans Le Lion, la Sorcière Blanche et l'Armoire Magique ?" - }, - new - { - Id = 6, - AnswerA = "Smaug", - AnswerB = "Falkor", - AnswerC = "Norbert", - AnswerD = "Shenron", - CorrectAnswer = "A", - IsValid = true, - Text = "Quel est le nom du dragon dans Le Hobbit ?" - }, - new - { - Id = 7, - AnswerA = "Bella Swan", - AnswerB = "Edward Cullen", - AnswerC = "Jacob Black", - AnswerD = "Victoria", - CorrectAnswer = "A", - IsValid = true, - Text = "Qui est la première personne à être mordue par un vampire dans Twilight ?" - }, - new - { - Id = 8, - AnswerA = "Obi-Wan Kenobi", - AnswerB = "Yoda", - AnswerC = "Han Solo", - AnswerD = "Luke Skywalker", - CorrectAnswer = "A", - IsValid = true, - Text = "Quel personnage dit Que la Force soit avec toi dans Star Wars ?" - }, - new - { - Id = 9, - AnswerA = "Dr. Ellie Sattler", - AnswerB = "Alan Grant", - AnswerC = "John Hammond", - AnswerD = "Dennis Nedry", - CorrectAnswer = "B", - IsValid = true, - Text = "Dans Jurassic Park, quel est le nom du paléontologue sur l'île ?" - }, - new - { - Id = 10, - AnswerA = "Cersei Lannister", - AnswerB = "Arya Stark", - AnswerC = "Daenerys Targaryen", - AnswerD = "Sansa Stark", - CorrectAnswer = "C", - IsValid = true, - Text = "Dans Game of Thrones, qui est surnommée la Mère des Dragons ?" - }); - }); - - modelBuilder.Entity("Entity.Quiz", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("int"); - - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); - - b.Property("IdImage") - .HasColumnType("int"); - - b.Property("NbQuestion") - .HasColumnType("int"); - - b.Property("Title") - .IsRequired() - .HasMaxLength(50) - .HasColumnType("nvarchar(50)"); - - b.HasKey("Id"); - - b.HasIndex("IdImage"); - - b.ToTable("quizzes"); - - b.HasData( - new - { - Id = 1, - IdImage = 1, - NbQuestion = 5, - Title = "Quiz 1" - }, - new - { - Id = 2, - IdImage = 2, - NbQuestion = 5, - Title = "Quiz 2" - }); - }); - - modelBuilder.Entity("Entity.QuizQuestion", b => - { - b.Property("IdQuestion") - .HasColumnType("int"); - - b.Property("IdQuiz") - .HasColumnType("int"); - - b.HasKey("IdQuestion", "IdQuiz"); - - b.HasIndex("IdQuiz"); - - b.ToTable("QuizQuestion"); - - b.HasData( - new - { - IdQuestion = 1, - IdQuiz = 1 - }, - new - { - IdQuestion = 2, - IdQuiz = 1 - }, - new - { - IdQuestion = 3, - IdQuiz = 1 - }, - new - { - IdQuestion = 4, - IdQuiz = 1 - }, - new - { - IdQuestion = 5, - IdQuiz = 1 - }, - new - { - IdQuestion = 6, - IdQuiz = 2 - }, - new - { - IdQuestion = 7, - IdQuiz = 2 - }, - new - { - IdQuestion = 8, - IdQuiz = 2 - }, - new - { - IdQuestion = 9, - IdQuiz = 2 - }, - new - { - IdQuestion = 10, - IdQuiz = 2 - }); - }); - - modelBuilder.Entity("Entity.Quote", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("int"); - - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); - - b.Property("Content") - .IsRequired() - .HasMaxLength(100) - .HasColumnType("nvarchar(100)"); - - b.Property("IdCharacter") - .HasColumnType("int"); - - b.Property("IdSource") - .HasColumnType("int"); - - b.Property("IdUsersPropose") - .HasColumnType("int"); - - b.Property("IsValid") - .HasColumnType("bit"); - - b.Property("Langage") - .HasColumnType("int"); - - b.Property("Likes") - .HasColumnType("int"); - - b.HasKey("Id"); - - b.HasIndex("IdCharacter"); - - b.HasIndex("IdSource"); - - b.HasIndex("IdUsersPropose"); - - b.ToTable("quotes"); - - b.HasData( - new - { - Id = 1, - Content = "Je n'y crois pas. Je n'y crois pas. Ce n'est pas possible", - IdCharacter = 1, - IdSource = 1, - IdUsersPropose = 1, - IsValid = true, - Langage = 1, - Likes = 11025 - }, - new - { - Id = 2, - Content = "There is always hope", - IdCharacter = 2, - IdSource = 2, - IdUsersPropose = 1, - IsValid = true, - Langage = 0, - Likes = 11025 - }, - new - { - Id = 3, - Content = "A red sun rises. Blood has been spilled this night.", - IdCharacter = 3, - IdSource = 2, - IdUsersPropose = 1, - IsValid = true, - Langage = 0, - Likes = 11025 - }, - new - { - Id = 4, - Content = "I wish the Ring had never come to me.I wish none of this had happened.", - IdCharacter = 4, - IdSource = 2, - IdUsersPropose = 1, - IsValid = true, - Langage = 0, - Likes = 11025 - }, - new - { - Id = 5, - Content = "Dobby is a free elf!", - IdCharacter = 5, - IdSource = 4, - IdUsersPropose = 1, - IsValid = true, - Langage = 0, - Likes = 11025 - }, - new - { - Id = 6, - Content = "Winter is comming", - IdCharacter = 6, - IdSource = 3, - IdUsersPropose = 1, - IsValid = true, - Langage = 0, - Likes = 11025 - }, - new - { - Id = 7, - Content = "Je suis la dernière Targaryen. Je suis la reine des dragons", - IdCharacter = 7, - IdSource = 3, - IdUsersPropose = 1, - IsValid = true, - Langage = 1, - Likes = 11025 - }, - new - { - Id = 8, - Content = "Je ne suis pas prêt à affronter ça. C'est trop pour moi.", - IdCharacter = 8, - IdSource = 5, - IdUsersPropose = 1, - IsValid = true, - Langage = 1, - Likes = 11025 - }, - new - { - Id = 9, - Content = "Aidez-moi, Obi-Wan Kenobi, vous êtes mon seul espoir.", - IdCharacter = 9, - IdSource = 5, - IdUsersPropose = 1, - IsValid = true, - Langage = 1, - Likes = 11025 - }, - new - { - Id = 10, - Content = "La quoi ?", - IdCharacter = 10, - IdSource = 4, - IdUsersPropose = 1, - IsValid = false, - Langage = 1, - Likes = 11025 - }); - }); - - modelBuilder.Entity("Entity.Source", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("int"); - - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); - - b.Property("Title") - .IsRequired() - .HasMaxLength(100) - .HasColumnType("nvarchar(100)"); - - b.Property("TypeSrc") - .HasColumnType("int"); - - b.Property("Year") - .HasColumnType("int"); - - b.HasKey("Id"); - - b.ToTable("sources"); - - b.HasData( - new - { - Id = 1, - Title = "Jurassic Park", - TypeSrc = 0, - Year = 1993 - }, - new - { - Id = 2, - Title = "Le Seigneur des anneaux : La Communauté de l'anneau", - TypeSrc = 0, - Year = 2001 - }, - new - { - Id = 3, - Title = "Game of throne", - TypeSrc = 1, - Year = 2011 - }, - new - { - Id = 4, - Title = "Harry Potter à l'école des sorcier", - TypeSrc = 0, - Year = 1997 - }, - new - { - Id = 5, - Title = "Star Wars, épisode IV : Un nouvel espoir", - TypeSrc = 0, - Year = 1977 - }); - }); - - modelBuilder.Entity("Entity.Users", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("int"); - - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); - - b.Property("Created") - .HasColumnType("date") - .HasColumnName("Created"); - - b.Property("Email") - .IsRequired() - .HasMaxLength(50) - .HasColumnType("nvarchar(50)"); - - b.Property("IdImage") - .HasColumnType("int"); - - b.Property("Password") - .IsRequired() - .HasMaxLength(200) - .HasColumnType("nvarchar(200)"); - - b.Property("UserName") - .IsRequired() - .HasMaxLength(50) - .HasColumnType("nvarchar(50)"); - - b.HasKey("Id"); - - b.HasIndex("IdImage"); - - b.ToTable("users"); - - b.HasData( - new - { - Id = 1, - Created = new DateTime(2025, 5, 12, 0, 0, 0, 0, DateTimeKind.Unspecified), - Email = "jhonDhoe@gmail.com", - IdImage = 1, - Password = "1234", - UserName = "Jhon-Dhoe" - }, - new - { - Id = 2, - Created = new DateTime(2025, 3, 19, 0, 0, 0, 0, DateTimeKind.Unspecified), - Email = "lucy_rose@outlook.com", - IdImage = 2, - Password = "abcd", - UserName = "Lucy-Rose" - }, - new - { - Id = 3, - Created = new DateTime(2024, 11, 2, 0, 0, 0, 0, DateTimeKind.Unspecified), - Email = "mark.taylor@yahoo.com", - IdImage = 3, - Password = "5678", - UserName = "Mark-Taylor" - }, - new - { - Id = 4, - Created = new DateTime(2025, 2, 28, 0, 0, 0, 0, DateTimeKind.Unspecified), - Email = "sophie.martin@gmail.com", - IdImage = 4, - Password = "4321", - UserName = "Sophie-Martin" - }, - new - { - Id = 5, - Created = new DateTime(2025, 1, 15, 0, 0, 0, 0, DateTimeKind.Unspecified), - Email = "nathan_doe@aol.com", - IdImage = 5, - Password = "8765", - UserName = "Nathan-Doe" - }, - new - { - Id = 6, - Created = new DateTime(2025, 4, 7, 0, 0, 0, 0, DateTimeKind.Unspecified), - Email = "ella.brown@icloud.com", - IdImage = 6, - Password = "2468", - UserName = "Ella-Brown" - }, - new - { - Id = 7, - Created = new DateTime(2024, 12, 25, 0, 0, 0, 0, DateTimeKind.Unspecified), - Email = "oliver_smith@gmail.com", - IdImage = 7, - Password = "1357", - UserName = "Oliver-Smith" - }, - new - { - Id = 8, - Created = new DateTime(2025, 3, 5, 0, 0, 0, 0, DateTimeKind.Unspecified), - Email = "mia.jones@outlook.com", - IdImage = 8, - Password = "1122", - UserName = "Mia-Jones" - }, - new - { - Id = 9, - Created = new DateTime(2025, 2, 22, 0, 0, 0, 0, DateTimeKind.Unspecified), - Email = "kevin_williams@aol.com", - IdImage = 9, - Password = "2233", - UserName = "Kevin-Williams" - }, - new - { - Id = 10, - Created = new DateTime(2025, 1, 3, 0, 0, 0, 0, DateTimeKind.Unspecified), - Email = "olivia.white@yahoo.com", - IdImage = 10, - Password = "3344", - UserName = "Olivia-White" - }); - }); - - modelBuilder.Entity("Entity.Admin", b => - { - b.HasOne("Entity.Users", "User") - .WithMany() - .HasForeignKey("UserId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.Navigation("User"); - }); - - modelBuilder.Entity("Entity.Character", b => - { - b.HasOne("Entity.Images", "Images") - .WithMany("Characters") - .HasForeignKey("IdImage") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.Navigation("Images"); - }); - - modelBuilder.Entity("Entity.Commentary", b => - { - b.HasOne("Entity.Quote", "Quote") - .WithMany("Commentarys") - .HasForeignKey("IdQuote") - .OnDelete(DeleteBehavior.ClientCascade) - .IsRequired(); - - b.HasOne("Entity.Users", "User") - .WithMany() - .HasForeignKey("IdUser") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.Navigation("Quote"); - - b.Navigation("User"); - }); - - modelBuilder.Entity("Entity.Favorite", b => - { - b.HasOne("Entity.Quote", "Quote") - .WithMany() - .HasForeignKey("IdQuote") - .OnDelete(DeleteBehavior.ClientCascade) - .IsRequired(); - - b.HasOne("Entity.Users", "Users") - .WithMany() - .HasForeignKey("IdUsers") - .OnDelete(DeleteBehavior.ClientCascade) - .IsRequired(); - - b.Navigation("Quote"); - - b.Navigation("Users"); - }); - - modelBuilder.Entity("Entity.Quiz", b => - { - b.HasOne("Entity.Images", "Images") - .WithMany("Quizs") - .HasForeignKey("IdImage") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.Navigation("Images"); - }); - - modelBuilder.Entity("Entity.QuizQuestion", b => - { - b.HasOne("Entity.Question", null) - .WithMany() - .HasForeignKey("IdQuestion") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.HasOne("Entity.Quiz", null) - .WithMany() - .HasForeignKey("IdQuiz") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - }); - - modelBuilder.Entity("Entity.Quote", b => - { - b.HasOne("Entity.Character", "Character") - .WithMany("Quotes") - .HasForeignKey("IdCharacter") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.HasOne("Entity.Source", "Source") - .WithMany("Quotes") - .HasForeignKey("IdSource") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.HasOne("Entity.Users", "User") - .WithMany("Quotes") - .HasForeignKey("IdUsersPropose"); - - b.Navigation("Character"); - - b.Navigation("Source"); - - b.Navigation("User"); - }); - - modelBuilder.Entity("Entity.Users", b => - { - b.HasOne("Entity.Images", "Images") - .WithMany("Users") - .HasForeignKey("IdImage") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.Navigation("Images"); - }); - - modelBuilder.Entity("Entity.Character", b => - { - b.Navigation("Quotes"); - }); - - modelBuilder.Entity("Entity.Images", b => - { - b.Navigation("Characters"); - - b.Navigation("Quizs"); - - b.Navigation("Users"); - }); - - modelBuilder.Entity("Entity.Quote", b => - { - b.Navigation("Commentarys"); - }); - - modelBuilder.Entity("Entity.Source", b => - { - b.Navigation("Quotes"); - }); - - modelBuilder.Entity("Entity.Users", b => - { - b.Navigation("Quotes"); - }); -#pragma warning restore 612, 618 - } - } -} diff --git a/WF_EF_Api/StubbedContextLib/Migrations/20250402084447_migration2-04.cs b/WF_EF_Api/StubbedContextLib/Migrations/20250402084447_migration2-04.cs deleted file mode 100644 index 4f1a548..0000000 --- a/WF_EF_Api/StubbedContextLib/Migrations/20250402084447_migration2-04.cs +++ /dev/null @@ -1,22 +0,0 @@ -using Microsoft.EntityFrameworkCore.Migrations; - -#nullable disable - -namespace StubbedContextLib.Migrations -{ - /// - public partial class migration204 : Migration - { - /// - protected override void Up(MigrationBuilder migrationBuilder) - { - - } - - /// - protected override void Down(MigrationBuilder migrationBuilder) - { - - } - } -} diff --git a/WF_EF_Api/StubbedContextLib/Migrations/20250402105029_migration1.cs b/WF_EF_Api/StubbedContextLib/Migrations/20250402105029_migration1.cs deleted file mode 100644 index 8e69aba..0000000 --- a/WF_EF_Api/StubbedContextLib/Migrations/20250402105029_migration1.cs +++ /dev/null @@ -1,22 +0,0 @@ -using Microsoft.EntityFrameworkCore.Migrations; - -#nullable disable - -namespace StubbedContextLib.Migrations -{ - /// - public partial class migration1 : Migration - { - /// - protected override void Up(MigrationBuilder migrationBuilder) - { - - } - - /// - protected override void Down(MigrationBuilder migrationBuilder) - { - - } - } -} diff --git a/WF_EF_Api/StubbedContextLib/Migrations/20250402105029_migration1.Designer.cs b/WF_EF_Api/StubbedContextLib/Migrations/20250402113707_pm_api.Designer.cs similarity index 97% rename from WF_EF_Api/StubbedContextLib/Migrations/20250402105029_migration1.Designer.cs rename to WF_EF_Api/StubbedContextLib/Migrations/20250402113707_pm_api.Designer.cs index ca444d0..c1cc023 100644 --- a/WF_EF_Api/StubbedContextLib/Migrations/20250402105029_migration1.Designer.cs +++ b/WF_EF_Api/StubbedContextLib/Migrations/20250402113707_pm_api.Designer.cs @@ -12,8 +12,8 @@ using StubbedContextLib; namespace StubbedContextLib.Migrations { [DbContext(typeof(StubWTFContext))] - [Migration("20250402105029_migration1")] - partial class migration1 + [Migration("20250402113707_pm_api")] + partial class pm_api { /// protected override void BuildTargetModel(ModelBuilder modelBuilder) diff --git a/WF_EF_Api/StubbedContextLib/Migrations/20250317163102_migrationTest1.cs b/WF_EF_Api/StubbedContextLib/Migrations/20250402113707_pm_api.cs similarity index 90% rename from WF_EF_Api/StubbedContextLib/Migrations/20250317163102_migrationTest1.cs rename to WF_EF_Api/StubbedContextLib/Migrations/20250402113707_pm_api.cs index 437370b..f9dd7c8 100644 --- a/WF_EF_Api/StubbedContextLib/Migrations/20250317163102_migrationTest1.cs +++ b/WF_EF_Api/StubbedContextLib/Migrations/20250402113707_pm_api.cs @@ -8,7 +8,7 @@ using Microsoft.EntityFrameworkCore.Migrations; namespace StubbedContextLib.Migrations { /// - public partial class migrationTest1 : Migration + public partial class pm_api : Migration { /// protected override void Up(MigrationBuilder migrationBuilder) @@ -37,7 +37,8 @@ namespace StubbedContextLib.Migrations AnswerB = table.Column(type: "nvarchar(50)", maxLength: 50, nullable: false), AnswerC = table.Column(type: "nvarchar(50)", maxLength: 50, nullable: false), AnswerD = table.Column(type: "nvarchar(50)", maxLength: 50, nullable: false), - CorrectAnswer = table.Column(type: "nvarchar(1)", maxLength: 1, nullable: false) + CorrectAnswer = table.Column(type: "nvarchar(1)", maxLength: 1, nullable: false), + IsValid = table.Column(type: "bit", nullable: false) }, constraints: table => { @@ -147,6 +148,25 @@ namespace StubbedContextLib.Migrations onDelete: ReferentialAction.Cascade); }); + migrationBuilder.CreateTable( + name: "admins", + columns: table => new + { + IdUsers = table.Column(type: "int", nullable: false) + .Annotation("SqlServer:Identity", "1, 1"), + UserId = table.Column(type: "int", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_admins", x => x.IdUsers); + table.ForeignKey( + name: "FK_admins_users_UserId", + column: x => x.UserId, + principalTable: "users", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + }); + migrationBuilder.CreateTable( name: "quotes", columns: table => new @@ -210,23 +230,6 @@ namespace StubbedContextLib.Migrations onDelete: ReferentialAction.Cascade); }); - migrationBuilder.CreateTable( - name: "dailyquotes", - columns: table => new - { - IdQuote = table.Column(type: "int", nullable: false) - }, - constraints: table => - { - table.PrimaryKey("PK_dailyquotes", x => x.IdQuote); - table.ForeignKey( - name: "FK_dailyquotes_quotes_IdQuote", - column: x => x.IdQuote, - principalTable: "quotes", - principalColumn: "Id", - onDelete: ReferentialAction.Cascade); - }); - migrationBuilder.CreateTable( name: "favorites", columns: table => new @@ -268,19 +271,19 @@ namespace StubbedContextLib.Migrations migrationBuilder.InsertData( table: "question", - columns: new[] { "Id", "AnswerA", "AnswerB", "AnswerC", "AnswerD", "CorrectAnswer", "Text" }, + columns: new[] { "Id", "AnswerA", "AnswerB", "AnswerC", "AnswerD", "CorrectAnswer", "IsValid", "Text" }, values: new object[,] { - { 1, "Gimli", "Aragorn", "Frodon", "Gandalf", "B", "Qui est le leader de la Communauté de l'Anneau ?" }, - { 2, "Serdaigle", "Gryffondor", "Serpentard", "Poufsouffle", "B", "Dans quelle maison Harry Potter est-il ?" }, - { 3, "Saroumane", "Sauron", "Gollum", "Gothmog", "B", "Qui est le Seigneur des Ténèbres dans la saga Le Seigneur des Anneaux ?" }, - { 4, "Han Solo", "Princesse Leia", "Chewbacca", "R2-D2", "A", "Dans le film Star Wars : Episode IV, qui sauve Luke Skywalker de l'Étoile de la Mort ?" }, - { 5, "Reine Jadis", "Aslan", "Edmund", "Lucy", "B", "Qui est le souverain de Narnia dans Le Lion, la Sorcière Blanche et l'Armoire Magique ?" }, - { 6, "Smaug", "Falkor", "Norbert", "Shenron", "A", "Quel est le nom du dragon dans Le Hobbit ?" }, - { 7, "Bella Swan", "Edward Cullen", "Jacob Black", "Victoria", "A", "Qui est la première personne à être mordue par un vampire dans Twilight ?" }, - { 8, "Obi-Wan Kenobi", "Yoda", "Han Solo", "Luke Skywalker", "A", "Quel personnage dit Que la Force soit avec toi dans Star Wars ?" }, - { 9, "Dr. Ellie Sattler", "Alan Grant", "John Hammond", "Dennis Nedry", "B", "Dans Jurassic Park, quel est le nom du paléontologue sur l'île ?" }, - { 10, "Cersei Lannister", "Arya Stark", "Daenerys Targaryen", "Sansa Stark", "C", "Dans Game of Thrones, qui est surnommée la Mère des Dragons ?" } + { 1, "Gimli", "Aragorn", "Frodon", "Gandalf", "B", true, "Qui est le leader de la Communauté de l'Anneau ?" }, + { 2, "Serdaigle", "Gryffondor", "Serpentard", "Poufsouffle", "B", false, "Dans quelle maison Harry Potter est-il ?" }, + { 3, "Saroumane", "Sauron", "Gollum", "Gothmog", "B", true, "Qui est le Seigneur des Ténèbres dans la saga Le Seigneur des Anneaux ?" }, + { 4, "Han Solo", "Princesse Leia", "Chewbacca", "R2-D2", "A", true, "Dans le film Star Wars : Episode IV, qui sauve Luke Skywalker de l'Étoile de la Mort ?" }, + { 5, "Reine Jadis", "Aslan", "Edmund", "Lucy", "B", true, "Qui est le souverain de Narnia dans Le Lion, la Sorcière Blanche et l'Armoire Magique ?" }, + { 6, "Smaug", "Falkor", "Norbert", "Shenron", "A", true, "Quel est le nom du dragon dans Le Hobbit ?" }, + { 7, "Bella Swan", "Edward Cullen", "Jacob Black", "Victoria", "A", true, "Qui est la première personne à être mordue par un vampire dans Twilight ?" }, + { 8, "Obi-Wan Kenobi", "Yoda", "Han Solo", "Luke Skywalker", "A", true, "Quel personnage dit Que la Force soit avec toi dans Star Wars ?" }, + { 9, "Dr. Ellie Sattler", "Alan Grant", "John Hammond", "Dennis Nedry", "B", true, "Dans Jurassic Park, quel est le nom du paléontologue sur l'île ?" }, + { 10, "Cersei Lannister", "Arya Stark", "Daenerys Targaryen", "Sansa Stark", "C", true, "Dans Game of Thrones, qui est surnommée la Mère des Dragons ?" } }); migrationBuilder.InsertData( @@ -369,7 +372,7 @@ namespace StubbedContextLib.Migrations { 7, "Je suis la dernière Targaryen. Je suis la reine des dragons", 7, 3, 1, true, 1, 11025 }, { 8, "Je ne suis pas prêt à affronter ça. C'est trop pour moi.", 8, 5, 1, true, 1, 11025 }, { 9, "Aidez-moi, Obi-Wan Kenobi, vous êtes mon seul espoir.", 9, 5, 1, true, 1, 11025 }, - { 10, "La quoi ?", 10, 4, 1, true, 1, 11025 } + { 10, "La quoi ?", 10, 4, 1, false, 1, 11025 } }); migrationBuilder.InsertData( @@ -381,15 +384,6 @@ namespace StubbedContextLib.Migrations { 1, 3, "Very good", new DateTime(2025, 3, 11, 0, 0, 0, 0, DateTimeKind.Unspecified), 2 } }); - migrationBuilder.InsertData( - table: "dailyquotes", - column: "IdQuote", - values: new object[] - { - 1, - 5 - }); - migrationBuilder.InsertData( table: "favorites", columns: new[] { "IdQuote", "IdUsers" }, @@ -406,6 +400,11 @@ namespace StubbedContextLib.Migrations { 10, 5 } }); + migrationBuilder.CreateIndex( + name: "IX_admins_UserId", + table: "admins", + column: "UserId"); + migrationBuilder.CreateIndex( name: "IX_characters_IdImage", table: "characters", @@ -456,10 +455,10 @@ namespace StubbedContextLib.Migrations protected override void Down(MigrationBuilder migrationBuilder) { migrationBuilder.DropTable( - name: "comments"); + name: "admins"); migrationBuilder.DropTable( - name: "dailyquotes"); + name: "comments"); migrationBuilder.DropTable( name: "favorites"); diff --git a/WF_EF_Api/StubbedContextLib/Migrations/20250401141906_suprDailyQuote.Designer.cs b/WF_EF_Api/StubbedContextLib/Migrations/20250402134601_pm_apiV2.Designer.cs similarity index 96% rename from WF_EF_Api/StubbedContextLib/Migrations/20250401141906_suprDailyQuote.Designer.cs rename to WF_EF_Api/StubbedContextLib/Migrations/20250402134601_pm_apiV2.Designer.cs index 89c0f87..efad120 100644 --- a/WF_EF_Api/StubbedContextLib/Migrations/20250401141906_suprDailyQuote.Designer.cs +++ b/WF_EF_Api/StubbedContextLib/Migrations/20250402134601_pm_apiV2.Designer.cs @@ -12,8 +12,8 @@ using StubbedContextLib; namespace StubbedContextLib.Migrations { [DbContext(typeof(StubWTFContext))] - [Migration("20250401141906_suprDailyQuote")] - partial class suprDailyQuote + [Migration("20250402134601_pm_apiV2")] + partial class pm_apiV2 { /// protected override void BuildTargetModel(ModelBuilder modelBuilder) @@ -130,11 +130,11 @@ namespace StubbedContextLib.Migrations modelBuilder.Entity("Entity.Commentary", b => { - b.Property("IdUser") + b.Property("Id") + .ValueGeneratedOnAdd() .HasColumnType("int"); - b.Property("IdQuote") - .HasColumnType("int"); + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); b.Property("Comment") .IsRequired() @@ -145,34 +145,36 @@ namespace StubbedContextLib.Migrations .HasColumnType("date") .HasColumnName("DateCommentary"); - b.Property("Id") - .ValueGeneratedOnAdd() + b.Property("IdQuote") .HasColumnType("int"); - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + b.Property("IdUser") + .HasColumnType("int"); - b.HasKey("IdUser", "IdQuote"); + b.HasKey("Id"); b.HasIndex("IdQuote"); + b.HasIndex("IdUser"); + b.ToTable("comments"); b.HasData( new { - IdUser = 2, - IdQuote = 1, + Id = 1, Comment = "Ce film est le meilleur", DateCommentary = new DateTime(2025, 2, 3, 0, 0, 0, 0, DateTimeKind.Unspecified), - Id = 1 + IdQuote = 1, + IdUser = 2 }, new { - IdUser = 3, - IdQuote = 1, + Id = 2, Comment = "Very good", DateCommentary = new DateTime(2025, 3, 11, 0, 0, 0, 0, DateTimeKind.Unspecified), - Id = 2 + IdQuote = 1, + IdUser = 3 }); }); diff --git a/WF_EF_Api/StubbedContextLib/Migrations/20250402134601_pm_apiV2.cs b/WF_EF_Api/StubbedContextLib/Migrations/20250402134601_pm_apiV2.cs new file mode 100644 index 0000000..ec12b89 --- /dev/null +++ b/WF_EF_Api/StubbedContextLib/Migrations/20250402134601_pm_apiV2.cs @@ -0,0 +1,86 @@ +using System; +using Microsoft.EntityFrameworkCore.Migrations; + +#nullable disable + +#pragma warning disable CA1814 // Prefer jagged arrays over multidimensional + +namespace StubbedContextLib.Migrations +{ + /// + public partial class pm_apiV2 : Migration + { + /// + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropPrimaryKey( + name: "PK_comments", + table: "comments"); + + migrationBuilder.DeleteData( + table: "comments", + keyColumns: new[] { "IdQuote", "IdUser" }, + keyValues: new object[] { 1, 2 }); + + migrationBuilder.DeleteData( + table: "comments", + keyColumns: new[] { "IdQuote", "IdUser" }, + keyValues: new object[] { 1, 3 }); + + migrationBuilder.AddPrimaryKey( + name: "PK_comments", + table: "comments", + column: "Id"); + + migrationBuilder.InsertData( + table: "comments", + columns: new[] { "Id", "Comment", "DateCommentary", "IdQuote", "IdUser" }, + values: new object[,] + { + { 1, "Ce film est le meilleur", new DateTime(2025, 2, 3, 0, 0, 0, 0, DateTimeKind.Unspecified), 1, 2 }, + { 2, "Very good", new DateTime(2025, 3, 11, 0, 0, 0, 0, DateTimeKind.Unspecified), 1, 3 } + }); + + migrationBuilder.CreateIndex( + name: "IX_comments_IdUser", + table: "comments", + column: "IdUser"); + } + + /// + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropPrimaryKey( + name: "PK_comments", + table: "comments"); + + migrationBuilder.DropIndex( + name: "IX_comments_IdUser", + table: "comments"); + + migrationBuilder.DeleteData( + table: "comments", + keyColumn: "Id", + keyValue: 1); + + migrationBuilder.DeleteData( + table: "comments", + keyColumn: "Id", + keyValue: 2); + + migrationBuilder.AddPrimaryKey( + name: "PK_comments", + table: "comments", + columns: new[] { "IdUser", "IdQuote" }); + + migrationBuilder.InsertData( + table: "comments", + columns: new[] { "IdQuote", "IdUser", "Comment", "DateCommentary", "Id" }, + values: new object[,] + { + { 1, 2, "Ce film est le meilleur", new DateTime(2025, 2, 3, 0, 0, 0, 0, DateTimeKind.Unspecified), 1 }, + { 1, 3, "Very good", new DateTime(2025, 3, 11, 0, 0, 0, 0, DateTimeKind.Unspecified), 2 } + }); + } + } +} diff --git a/WF_EF_Api/StubbedContextLib/Migrations/StubWTFContextModelSnapshot.cs b/WF_EF_Api/StubbedContextLib/Migrations/StubWTFContextModelSnapshot.cs index 37b2e66..08ef8a9 100644 --- a/WF_EF_Api/StubbedContextLib/Migrations/StubWTFContextModelSnapshot.cs +++ b/WF_EF_Api/StubbedContextLib/Migrations/StubWTFContextModelSnapshot.cs @@ -127,11 +127,11 @@ namespace StubbedContextLib.Migrations modelBuilder.Entity("Entity.Commentary", b => { - b.Property("IdUser") + b.Property("Id") + .ValueGeneratedOnAdd() .HasColumnType("int"); - b.Property("IdQuote") - .HasColumnType("int"); + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); b.Property("Comment") .IsRequired() @@ -142,34 +142,36 @@ namespace StubbedContextLib.Migrations .HasColumnType("date") .HasColumnName("DateCommentary"); - b.Property("Id") - .ValueGeneratedOnAdd() + b.Property("IdQuote") .HasColumnType("int"); - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + b.Property("IdUser") + .HasColumnType("int"); - b.HasKey("IdUser", "IdQuote"); + b.HasKey("Id"); b.HasIndex("IdQuote"); + b.HasIndex("IdUser"); + b.ToTable("comments"); b.HasData( new { - IdUser = 2, - IdQuote = 1, + Id = 1, Comment = "Ce film est le meilleur", DateCommentary = new DateTime(2025, 2, 3, 0, 0, 0, 0, DateTimeKind.Unspecified), - Id = 1 + IdQuote = 1, + IdUser = 2 }, new { - IdUser = 3, - IdQuote = 1, + Id = 2, Comment = "Very good", DateCommentary = new DateTime(2025, 3, 11, 0, 0, 0, 0, DateTimeKind.Unspecified), - Id = 2 + IdQuote = 1, + IdUser = 3 }); }); diff --git a/WF_EF_Api/StubbedContextLib/StubbedContextLib.csproj b/WF_EF_Api/StubbedContextLib/StubbedContextLib.csproj index 9a838f3..4ae6e1b 100644 --- a/WF_EF_Api/StubbedContextLib/StubbedContextLib.csproj +++ b/WF_EF_Api/StubbedContextLib/StubbedContextLib.csproj @@ -18,4 +18,8 @@ + + + + diff --git a/WF_EF_Api/WfApi/Controllers/CommentariesController.cs b/WF_EF_Api/WfApi/Controllers/CommentariesController.cs index cdeb881..7fd26bc 100644 --- a/WF_EF_Api/WfApi/Controllers/CommentariesController.cs +++ b/WF_EF_Api/WfApi/Controllers/CommentariesController.cs @@ -57,15 +57,17 @@ namespace WfApi.Controllers return BadRequest(new { message = "Comment data is required." }); } - var existingCommentary = _commentary.GetCommentaryById(newCommentary.Id).Result; - if (existingCommentary != null) + try { + var existingCommentary = await _commentary.GetCommentaryById(newCommentary.Id); return Conflict(new { message = "A comment with this ID already exists." }); } + catch (KeyNotFoundException e) + { + await _commentary.AddComment(newCommentary, idQuote); - await _commentary.AddComment(newCommentary, idQuote); - - return CreatedAtAction(nameof(GetCommentary), new { id = newCommentary.Id }, newCommentary); + return CreatedAtAction(nameof(GetCommentary), new { id = newCommentary.Id }, newCommentary); + } } catch (Exception) { @@ -89,7 +91,7 @@ namespace WfApi.Controllers return NotFound(new { message = "Commentary not found." }); } - _commentary.RemoveCommentary(existingCommentary.Id); + await _commentary.RemoveCommentary(existingCommentary.Id); return Ok(new { message = $"Commentary {id} deleted successfully." }); } diff --git a/WF_EF_Api/WfApi/Controllers/QuotesController.cs b/WF_EF_Api/WfApi/Controllers/QuotesController.cs index 1eda2f1..d64b1ef 100644 --- a/WF_EF_Api/WfApi/Controllers/QuotesController.cs +++ b/WF_EF_Api/WfApi/Controllers/QuotesController.cs @@ -33,13 +33,9 @@ namespace WfApi.Controllers try { var result = await _quote.GetQuoteById(id); - if (result == null) - { - throw new KeyNotFoundException($"Error : No quotes found with the ID: {id}."); - } if (result!=null) { - return await Task.FromResult(Ok(result)); + return Ok(result); } else { diff --git a/WF_EF_Api/WfApi/Controllers/SourceController.cs b/WF_EF_Api/WfApi/Controllers/SourceController.cs new file mode 100644 index 0000000..2f78d7c --- /dev/null +++ b/WF_EF_Api/WfApi/Controllers/SourceController.cs @@ -0,0 +1,84 @@ +using System.Net; +using DTO; +using Microsoft.AspNetCore.Mvc; +using Shared; + +// For more information on enabling Web API for empty projects, visit https://go.microsoft.com/fwlink/?LinkID=397860 + +namespace WfApi.Controllers +{ + [Route("api/v1/source")] + [ApiController] + public class SourceController : ControllerBase + { + private readonly ISourceService _source; + + private readonly ILogger _logger; + public SourceController(ISourceService sourceService, ILogger logger) + { + _source = sourceService; + _logger = logger; + + } + + [HttpGet("{id}")] // Indiquer que l'id est dans l'URL + [ProducesResponseType(StatusCodes.Status200OK)] + [ProducesResponseType(StatusCodes.Status204NoContent)] + [ProducesResponseType(StatusCodes.Status500InternalServerError)] + public async Task GetSource(int id) + { + try + { + var source = await _source.GetSourceById(id); + if(source != null) + { + return Ok(source); + } + else + { + return NoContent(); + } + } + catch(Exception e) + { + return StatusCode((int)HttpStatusCode.InternalServerError, new { message = "Internal Server Error (" + e + ")" }); + } + } + + [HttpGet("all")] + [ProducesResponseType(StatusCodes.Status200OK)] + [ProducesResponseType(StatusCodes.Status204NoContent)] + [ProducesResponseType(StatusCodes.Status500InternalServerError)] + public async Task GetAllSource(int index = 0, int count = 10) + { + + } + + [HttpPost] + [ProducesResponseType(StatusCodes.Status200OK)] + [ProducesResponseType(StatusCodes.Status204NoContent)] + [ProducesResponseType(StatusCodes.Status500InternalServerError)] + public async Task CreateSource([FromBody] SourceDTO newSource) + { + + } + + [HttpPut()] + [ProducesResponseType(StatusCodes.Status200OK)] + [ProducesResponseType(StatusCodes.Status204NoContent)] + [ProducesResponseType(StatusCodes.Status500InternalServerError)] + public async Task UpdateSource([FromQuery] int id, [FromBody] SourceDTO updatedSource) + { + + } + + [HttpDelete("delete")] + [ProducesResponseType(StatusCodes.Status200OK)] + [ProducesResponseType(StatusCodes.Status204NoContent)] + [ProducesResponseType(StatusCodes.Status500InternalServerError)] + public async Task DeleteSource([FromQuery] int idSource) + { + + } + } +} From 831a65f244f7abf41d9781f4a96c655ef55aca12 Mon Sep 17 00:00:00 2001 From: kekentin Date: Wed, 2 Apr 2025 16:17:59 +0200 Subject: [PATCH 58/65] correction erreur favorite --- WF_EF_Api/Contextlib/DbFavoriteManager.cs | 13 +++++++- WF_EF_Api/ServicesApi/FavoriteService.cs | 19 +++++++++-- .../WfApi/Controllers/FavoriteControleur.cs | 32 +++++++++++++------ WF_EF_Api/WfApi/Program.cs | 1 + 4 files changed, 51 insertions(+), 14 deletions(-) diff --git a/WF_EF_Api/Contextlib/DbFavoriteManager.cs b/WF_EF_Api/Contextlib/DbFavoriteManager.cs index 314da25..27e1b90 100644 --- a/WF_EF_Api/Contextlib/DbFavoriteManager.cs +++ b/WF_EF_Api/Contextlib/DbFavoriteManager.cs @@ -8,7 +8,7 @@ using System.Threading.Tasks; namespace Contextlib { - public class DbFavoriteManager : IFavoriteService + public class DbFavoriteManager : IFavoriteService { private WTFContext _context; @@ -22,6 +22,7 @@ namespace Contextlib throw new NotImplementedException(); } + public async Task RemoveAllFavoriteForQuote(int quoteId) { throw new NotImplementedException(); @@ -36,5 +37,15 @@ namespace Contextlib { throw new NotImplementedException(); } + + public Task GetFavorite(int userId, int idQuote) + { + throw new NotImplementedException(); + } + + public Task> GetFavoriteByIdUser(int userId, int index, int count) + { + throw new NotImplementedException(); + } } } diff --git a/WF_EF_Api/ServicesApi/FavoriteService.cs b/WF_EF_Api/ServicesApi/FavoriteService.cs index d3b3802..a2a0030 100644 --- a/WF_EF_Api/ServicesApi/FavoriteService.cs +++ b/WF_EF_Api/ServicesApi/FavoriteService.cs @@ -8,15 +8,16 @@ using Entity; using Shared; using Dto2Entities; using static System.Net.Mime.MediaTypeNames; +using static System.Runtime.InteropServices.JavaScript.JSType; namespace ServicesApi { - public class FavoriteService : IFavoriteService + public class FavoriteService : IFavoriteService { - private IFavoriteService favoriteService; + private IFavoriteService favoriteService; - public FavoriteService(IFavoriteService favorite) + public FavoriteService(IFavoriteService favorite) { favoriteService = favorite; } @@ -41,5 +42,17 @@ namespace ServicesApi { await favoriteService.RemoveFavorite(quoteid, userId); } + + public async Task GetFavorite(int userId, int idQuote) + { + return (await favoriteService.GetFavorite(userId,idQuote) ).ToDto(); + } + + public async Task> GetFavoriteByIdUser(int userId, int index, int count) + { + var fav = (await favoriteService.GetFavoriteByIdUser(userId, index, count)).items; + return new PaginationResult(fav.Count(), 0, 10, fav.ToDto()); + + } } } diff --git a/WF_EF_Api/WfApi/Controllers/FavoriteControleur.cs b/WF_EF_Api/WfApi/Controllers/FavoriteControleur.cs index 2529717..7ef8a7c 100644 --- a/WF_EF_Api/WfApi/Controllers/FavoriteControleur.cs +++ b/WF_EF_Api/WfApi/Controllers/FavoriteControleur.cs @@ -85,7 +85,7 @@ namespace WfApi.Controllers var existingFavorite = await _favorite.GetFavorite(idUser, idQuote); if (existingFavorite == null) { - return NotFound(new { message = "Commentary not found." }); + return NotFound(new { message = "Favorite not found." }); } await _favorite.RemoveFavorite(idUser, idQuote); @@ -97,24 +97,36 @@ namespace WfApi.Controllers return StatusCode((int)HttpStatusCode.InternalServerError, new { message = "Internal server error." }); } } - [HttpDelete] // /api/v1/commentary?id=51 + [HttpDelete("alluser")] // /api/v1/commentary?id=51 [ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status404NotFound)] [ProducesResponseType(StatusCodes.Status500InternalServerError)] - public async Task DeleteFavorite([FromQuery] int idUser, [FromQuery] int idQuote) + public async Task DeleteAllFavoriteForUser([FromQuery] int idUser) { try { - var existingFavorite = await _favorite.GetFavorite(idUser, idQuote); - if (existingFavorite == null) - { - return NotFound(new { message = "Commentary not found." }); - } + await _favorite.RemoveAllFavoriteForUser(idUser); - await _favorite.RemoveFavorite(idUser, idQuote); + return Ok(new { message = $"Favorite from user {idUser} deleted successfully." }); + } + catch (Exception) + { + return StatusCode((int)HttpStatusCode.InternalServerError, new { message = "Internal server error." }); + } + } + [HttpDelete("allquote")] // /api/v1/commentary?id=51 + [ProducesResponseType(StatusCodes.Status200OK)] + [ProducesResponseType(StatusCodes.Status404NotFound)] + [ProducesResponseType(StatusCodes.Status500InternalServerError)] + public async Task DeleteAllFavoriteForQuote([FromQuery] int idQuote) + { + try + { - return Ok(new { message = $"Favorite from user {idUser} and quote {idQuote} deleted successfully." }); + await _favorite.RemoveAllFavoriteForQuote(idQuote); + + return Ok(new { message = $"Favorite from quote {idQuote} deleted successfully." }); } catch (Exception) { diff --git a/WF_EF_Api/WfApi/Program.cs b/WF_EF_Api/WfApi/Program.cs index 6d308be..24338f1 100644 --- a/WF_EF_Api/WfApi/Program.cs +++ b/WF_EF_Api/WfApi/Program.cs @@ -12,6 +12,7 @@ var builder = WebApplication.CreateBuilder(args); builder.Services.AddScoped, UserService>(); builder.Services.AddScoped, QuoteService>(); +builder.Services.AddScoped, FavoriteService>(); builder.Services.AddScoped, CommentaryService>(); builder.Services.AddScoped, CharacterService>(); builder.Services.AddScoped, ImageService>(); From 0cacb3a3ed146052be4403dfdf2e572962517756 Mon Sep 17 00:00:00 2001 From: Leni BEAULATON Date: Wed, 2 Apr 2025 17:19:19 +0200 Subject: [PATCH 59/65] =?UTF-8?q?Mise=20=C3=A0=20jour=20de=20'.drone.yml'?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .drone.yml | 162 ++++++++++++++++++++++++++--------------------------- 1 file changed, 81 insertions(+), 81 deletions(-) diff --git a/.drone.yml b/.drone.yml index ed13d1e..668adb6 100644 --- a/.drone.yml +++ b/.drone.yml @@ -1,82 +1,82 @@ -kind: pipeline -type: docker -name: CI_ApiPm - -trigger: - event: - - push - branch: - exclude: - - master - -steps: - - name: retore & build - image: mcr.microsoft.com/dotnet/sdk:8.0 - commands: - - dotnet build --configuration Release - depend_on: [clone] - - - name: test - image: mcr.microsoft.com/dotnet/sdk:8.0 - commands: - - dotnet test - depends_on: [retore & build] - - - name: publish - image: mcr.microsoft.com/dotnet/sdk:8.0 - commands: - - dotnet publish -c Release -o out - depends_on: [retore & build, test] - ---- - -kind: pipeline -type: docker -name: CI_ApiPm_Master - -trigger: - event: - - push - branch: - - master - -volumes: - - name: doc - temp: {} - - -steps: - - name: retore & build - image: mcr.microsoft.com/dotnet/sdk:8.0 - commands: - - dotnet build --configuration Release - depend_on: [clone] - - - name: test - image: mcr.microsoft.com/dotnet/sdk:8.0 - commands: - - dotnet test - depends_on: [retore & build] - - - name: generate doc - image: mcr.microsoft.com/dotnet/sdk:8.0 - volumes: - - name: doc - path: /doc - commands: - - dotnet new tool-manifest - - dotnet tool install NSwag.ConsoleCore - - dotnet restore - - cd WF_EF_Api/WfApi - - dotnet nswag aspnetcore2openapi /output:/doc/swagger.json - depends_on: [clone, retore & build] - - #- name: code-inspection - # image: hub.codefirst.iut.uca.fr/marc.chevaldonne:codefirs-dronsonarplugin-dotnet8 - # secret: [SECRET_SONAR_LOGIN] - # A FINIR - - name: publish - image: mcr.microsoft.com/dotnet/sdk:8.0 - commands: - - dotnet publish -c Release -o out +kind: pipeline +type: docker +name: CI_ApiPm + +trigger: + event: + - push + branch: + exclude: + - master + +steps: + - name: retore & build + image: mcr.microsoft.com/dotnet/sdk:8.0 + commands: + - dotnet build WF_EF_Api/WF_EF_Api.sln --configuration Release + depend_on: [clone] + + - name: test + image: mcr.microsoft.com/dotnet/sdk:8.0 + commands: + - dotnet test + depends_on: [retore & build] + + - name: publish + image: mcr.microsoft.com/dotnet/sdk:8.0 + commands: + - dotnet publish -c Release -o out + depends_on: [retore & build, test] + +--- + +kind: pipeline +type: docker +name: CI_ApiPm_Master + +trigger: + event: + - push + branch: + - master + +volumes: + - name: doc + temp: {} + + +steps: + - name: retore & build + image: mcr.microsoft.com/dotnet/sdk:8.0 + commands: + - dotnet build --configuration Release + depend_on: [clone] + + - name: test + image: mcr.microsoft.com/dotnet/sdk:8.0 + commands: + - dotnet test + depends_on: [retore & build] + + - name: generate doc + image: mcr.microsoft.com/dotnet/sdk:8.0 + volumes: + - name: doc + path: /doc + commands: + - dotnet new tool-manifest + - dotnet tool install NSwag.ConsoleCore + - dotnet restore + - cd WF_EF_Api/WfApi + - dotnet nswag aspnetcore2openapi /output:/doc/swagger.json + depends_on: [clone, retore & build] + + #- name: code-inspection + # image: hub.codefirst.iut.uca.fr/marc.chevaldonne:codefirs-dronsonarplugin-dotnet8 + # secret: [SECRET_SONAR_LOGIN] + # A FINIR + - name: publish + image: mcr.microsoft.com/dotnet/sdk:8.0 + commands: + - dotnet publish -c Release -o out depends_on: [retore & build, test] \ No newline at end of file From 18e311da9f501a729da3e288d61b2e9e9ceb6e38 Mon Sep 17 00:00:00 2001 From: Leni BEAULATON Date: Wed, 2 Apr 2025 17:22:17 +0200 Subject: [PATCH 60/65] drone2 --- .drone.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.drone.yml b/.drone.yml index 668adb6..530d776 100644 --- a/.drone.yml +++ b/.drone.yml @@ -19,7 +19,7 @@ steps: - name: test image: mcr.microsoft.com/dotnet/sdk:8.0 commands: - - dotnet test + - dotnet test WF_EF_Api/XUnitTest/XUnitTest.csproj depends_on: [retore & build] - name: publish From 3da9d718e7aceeb3c289f667a277d15e9ab4e26a Mon Sep 17 00:00:00 2001 From: Kevin MONDEJAR Date: Wed, 2 Apr 2025 17:24:40 +0200 Subject: [PATCH 61/65] Fin route Source --- WF_EF_Api/Contextlib/DbSourceManager.cs | 7 ++ WF_EF_Api/ServicesApi/SourceService.cs | 8 ++- WF_EF_Api/Shared/ISourceService.cs | 2 + .../WfApi/Controllers/SourceController.cs | 65 +++++++++++++++---- WF_EF_Api/WfApi/Program.cs | 1 + 5 files changed, 71 insertions(+), 12 deletions(-) diff --git a/WF_EF_Api/Contextlib/DbSourceManager.cs b/WF_EF_Api/Contextlib/DbSourceManager.cs index 6f470f7..e2ed299 100644 --- a/WF_EF_Api/Contextlib/DbSourceManager.cs +++ b/WF_EF_Api/Contextlib/DbSourceManager.cs @@ -5,6 +5,7 @@ using System.Text; using System.Threading.Tasks; using Entity; using Shared; +using static System.Runtime.InteropServices.JavaScript.JSType; namespace Contextlib { @@ -40,6 +41,12 @@ namespace Contextlib throw new NotImplementedException(); } + public async Task> GetSomesSource(int page, int count) + { + var srcLst = _repo.GetItems(page, count, []).ToList(); + return new PaginationResult(srcLst.Count, 0, srcLst.Count, srcLst); + } + public async Task> GetSourceByDate(int date) { diff --git a/WF_EF_Api/ServicesApi/SourceService.cs b/WF_EF_Api/ServicesApi/SourceService.cs index 217c2ad..acefbcc 100644 --- a/WF_EF_Api/ServicesApi/SourceService.cs +++ b/WF_EF_Api/ServicesApi/SourceService.cs @@ -36,6 +36,12 @@ namespace ServicesApi return await srcService.GetLastSourceId(); } + public async Task> GetSomesSource(int page, int count) + { + var sources = (await srcService.GetSomesSource(page, count)).items; + return new PaginationResult(sources.Count(), page, count, sources.ToDto()); + } + public async Task> GetSourceByDate(int date) { var sources = (await srcService.GetSourceByDate(date)).items; @@ -44,7 +50,7 @@ namespace ServicesApi public async Task GetSourceById(int id) { - return srcService.GetSourceById(id).Result.ToDto(); + return (await srcService.GetSourceById(id)).ToDto(); } public async Task GetSourceByTitle(string title) diff --git a/WF_EF_Api/Shared/ISourceService.cs b/WF_EF_Api/Shared/ISourceService.cs index 9657db7..73fd2c6 100644 --- a/WF_EF_Api/Shared/ISourceService.cs +++ b/WF_EF_Api/Shared/ISourceService.cs @@ -42,5 +42,7 @@ namespace Shared // Retrieves the unique identifier of the last added source. Task GetLastSourceId(); + + Task> GetSomesSource(int page, int count); } } diff --git a/WF_EF_Api/WfApi/Controllers/SourceController.cs b/WF_EF_Api/WfApi/Controllers/SourceController.cs index 770a55f..744a737 100644 --- a/WF_EF_Api/WfApi/Controllers/SourceController.cs +++ b/WF_EF_Api/WfApi/Controllers/SourceController.cs @@ -1,5 +1,6 @@ using System.Net; using DTO; +using Entity; using Microsoft.AspNetCore.Mvc; using Shared; @@ -43,22 +44,59 @@ namespace WfApi.Controllers } } - /*[HttpGet("all")] + [HttpGet("all")] [ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status204NoContent)] [ProducesResponseType(StatusCodes.Status500InternalServerError)] public async Task GetAllSource(int index = 0, int count = 10) { + try + { + var result = await _source.GetSomesSource(index, count); + if (result != null) + { + return await Task.FromResult(Ok(result)); + } + else + { + return NoContent(); + } + } + catch (Exception e) + { + return StatusCode((int)HttpStatusCode.InternalServerError, new { message = "Internal Server Error (" + e + ")" }); + } } [HttpPost] [ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status204NoContent)] [ProducesResponseType(StatusCodes.Status500InternalServerError)] + [ProducesResponseType(StatusCodes.Status400BadRequest)] public async Task CreateSource([FromBody] SourceDTO newSource) { - + try + { + if(newSource == null) + { + return BadRequest(new { message = "Source data is required." }); + } + try + { + var existingSource = await _source.GetSourceById(newSource.Id); + return Conflict(new { message = "A source with this ID already exists." }); + } + catch(KeyNotFoundException e) + { + await _source.AddSource(newSource); + return CreatedAtAction(nameof(GetAllSource), new { id = newSource.Id }, newSource); + } + } + catch (Exception e) + { + return StatusCode((int)HttpStatusCode.InternalServerError, new { message = "Internal Server Error (" + e + ")" }); + } } [HttpPut()] @@ -67,16 +105,21 @@ namespace WfApi.Controllers [ProducesResponseType(StatusCodes.Status500InternalServerError)] public async Task UpdateSource([FromQuery] int id, [FromBody] SourceDTO updatedSource) { + try + { + if (updatedSource == null) + { + return BadRequest(new { message = "new source data is required." }); + } - } - - [HttpDelete("delete")] - [ProducesResponseType(StatusCodes.Status200OK)] - [ProducesResponseType(StatusCodes.Status204NoContent)] - [ProducesResponseType(StatusCodes.Status500InternalServerError)] - public async Task DeleteSource([FromQuery] int idSource) - { + var result = _source.UpdateSource(id, updatedSource); - }*/ + return Ok(result); + } + catch (Exception e) + { + return StatusCode((int)HttpStatusCode.InternalServerError, new { message = "Internal Server Error (" + e + ")" }); + } + } } } diff --git a/WF_EF_Api/WfApi/Program.cs b/WF_EF_Api/WfApi/Program.cs index 24338f1..71bbd5b 100644 --- a/WF_EF_Api/WfApi/Program.cs +++ b/WF_EF_Api/WfApi/Program.cs @@ -26,6 +26,7 @@ builder.Services.AddScoped(); builder.Services.AddScoped, DbUsersManager>(); builder.Services.AddScoped, DbQuoteManager>(); +builder.Services.AddScoped, DbFavoriteManager>(); builder.Services.AddScoped, DbCommentaryManager>(); builder.Services.AddScoped, DbCharacterManager>(); builder.Services.AddScoped, DbImagesManager>(); From d872246561dad2a55f6a629360eba911c7a1a771 Mon Sep 17 00:00:00 2001 From: Leni BEAULATON Date: Wed, 2 Apr 2025 17:26:45 +0200 Subject: [PATCH 62/65] DroneTest --- WF_EF_Api/XUnitTest/ApiUnitTest.cs | 492 ++++++++++++++--------------- 1 file changed, 246 insertions(+), 246 deletions(-) diff --git a/WF_EF_Api/XUnitTest/ApiUnitTest.cs b/WF_EF_Api/XUnitTest/ApiUnitTest.cs index 7591909..8692e14 100644 --- a/WF_EF_Api/XUnitTest/ApiUnitTest.cs +++ b/WF_EF_Api/XUnitTest/ApiUnitTest.cs @@ -11,272 +11,272 @@ namespace XUnitTest { public class UnitTest1 { - private readonly Mock> _mockUserService; - private readonly Mock> _mockLogger; - private readonly UsersController _userController; - - public UnitTest1() - { - // Initialisation des mocks - _mockUserService = new Mock>(); - _mockLogger = new Mock>(); - _userController = new UsersController(_mockUserService.Object, _mockLogger.Object); - } - - - - [Fact] - public async Task Get_ReturnsOk_WhenUserExists() - { - // Arrange - var userId = 1; - var userDTO = new UserDTO - { - Id = userId, - Pseudo = "test", - Email = "test@unitaire.fr", - ImageProfil = "http://test", - Password = "1234" - }; - - _mockUserService.Setup(service => service.GetUserById(userId)).ReturnsAsync(userDTO); - - // Act - var result = await _userController.Get(userId); - - // Assert - Assert.IsType(result); - } - - - - - [Fact] - public async Task GetAllUsers_ReturnsOk() - { - // Arrange - var userDTO = new UserDTO - { - Id = 1, - Pseudo = "test", - Email = "test@unitaire.fr", - ImageProfil = "http://test", - Password = "1234" - }; - var userDTO2 = new UserDTO - { - Id = 2, - Pseudo = "test", - Email = "test@unitaire.fr", - ImageProfil = "http://test", - Password = "1234" - }; - - _mockUserService.Setup(service => service.GetUserById(1)).ReturnsAsync(userDTO); - _mockUserService.Setup(service => service.GetUserById(2)).ReturnsAsync(userDTO); - - // Act - var result = await _userController.GetAllUsers(); - - // Assert - Assert.IsType(result); - } - - - - [Fact] - public async Task GetHashPassword_ReturnsOk_WhenPasswordHashIsFound() - { - // Arrange - var username = "testUser"; - var expectedHash = "hashedPassword"; - - var taskResult = Task.FromResult(expectedHash); - _mockUserService.Setup(service => service.GetHashPassword(username)).Returns(taskResult); - - // Act - var result = await _userController.GetHashPassword(username); - - // Assert - Assert.IsType(result); - } - - [Fact] - public async Task GetUserByUsername_ReturnsOk_WhenPasswordHashIsFound() - { - // Arrange - var username = "testUser"; - var userDTO = new UserDTO - { - Id = 1, - Pseudo = "testUser", - Email = "test@unitaire.fr", - ImageProfil = "http://test", - Password = "1234" - }; - - var taskResult = Task.FromResult(userDTO); - _mockUserService.Setup(service => service.GetUserByUsername(username)).Returns(taskResult); - - // Act - var result = await _userController.GetUserByUsername(username); - - // Assert - Assert.IsType(result); - } - - [Fact] - public async Task GetUserByEmail_ReturnsOk_WhenUserExists() - { - // Arrange - var email = "test@unitaire.fr"; - var userDTO = new UserDTO - { - Id = 1, - Pseudo = "testUser", - Email = email, - ImageProfil = "http://test", - Password = "1234" - }; + //private readonly Mock> _mockUserService; + //private readonly Mock> _mockLogger; + //private readonly UsersController _userController; + + //public UnitTest1() + //{ + // // Initialisation des mocks + // _mockUserService = new Mock>(); + // _mockLogger = new Mock>(); + // _userController = new UsersController(_mockUserService.Object, _mockLogger.Object); + //} + + + + //[Fact] + //public async Task Get_ReturnsOk_WhenUserExists() + //{ + // // Arrange + // var userId = 1; + // var userDTO = new UserDTO + // { + // Id = userId, + // Pseudo = "test", + // Email = "test@unitaire.fr", + // ImageProfil = "http://test", + // Password = "1234" + // }; + + // _mockUserService.Setup(service => service.GetUserById(userId)).ReturnsAsync(userDTO); + + // // Act + // var result = await _userController.Get(userId); + + // // Assert + // Assert.IsType(result); + //} + + + + + //[Fact] + //public async Task GetAllUsers_ReturnsOk() + //{ + // // Arrange + // var userDTO = new UserDTO + // { + // Id = 1, + // Pseudo = "test", + // Email = "test@unitaire.fr", + // ImageProfil = "http://test", + // Password = "1234" + // }; + // var userDTO2 = new UserDTO + // { + // Id = 2, + // Pseudo = "test", + // Email = "test@unitaire.fr", + // ImageProfil = "http://test", + // Password = "1234" + // }; + + // _mockUserService.Setup(service => service.GetUserById(1)).ReturnsAsync(userDTO); + // _mockUserService.Setup(service => service.GetUserById(2)).ReturnsAsync(userDTO); + + // // Act + // var result = await _userController.GetAllUsers(); + + // // Assert + // Assert.IsType(result); + //} + + + + //[Fact] + //public async Task GetHashPassword_ReturnsOk_WhenPasswordHashIsFound() + //{ + // // Arrange + // var username = "testUser"; + // var expectedHash = "hashedPassword"; + + // var taskResult = Task.FromResult(expectedHash); + // _mockUserService.Setup(service => service.GetHashPassword(username)).Returns(taskResult); + + // // Act + // var result = await _userController.GetHashPassword(username); + + // // Assert + // Assert.IsType(result); + //} + + //[Fact] + //public async Task GetUserByUsername_ReturnsOk_WhenPasswordHashIsFound() + //{ + // // Arrange + // var username = "testUser"; + // var userDTO = new UserDTO + // { + // Id = 1, + // Pseudo = "testUser", + // Email = "test@unitaire.fr", + // ImageProfil = "http://test", + // Password = "1234" + // }; + + // var taskResult = Task.FromResult(userDTO); + // _mockUserService.Setup(service => service.GetUserByUsername(username)).Returns(taskResult); + + // // Act + // var result = await _userController.GetUserByUsername(username); + + // // Assert + // Assert.IsType(result); + //} + + //[Fact] + //public async Task GetUserByEmail_ReturnsOk_WhenUserExists() + //{ + // // Arrange + // var email = "test@unitaire.fr"; + // var userDTO = new UserDTO + // { + // Id = 1, + // Pseudo = "testUser", + // Email = email, + // ImageProfil = "http://test", + // Password = "1234" + // }; - var taskResult = Task.FromResult(userDTO); - _mockUserService.Setup(service => service.GetUserByEmail(email)).Returns(taskResult); + // var taskResult = Task.FromResult(userDTO); + // _mockUserService.Setup(service => service.GetUserByEmail(email)).Returns(taskResult); - // Act - var result = await _userController.GetUserByEmail(email); + // // Act + // var result = await _userController.GetUserByEmail(email); - // Assert - Assert.IsType(result); - } + // // Assert + // Assert.IsType(result); + //} - [Fact] - public async Task GetCountUser_ReturnsOk_WhenCountIsSuccessful() - { - // Arrange - var expectedCount = 5; - var taskResult = Task.FromResult(expectedCount); + //[Fact] + //public async Task GetCountUser_ReturnsOk_WhenCountIsSuccessful() + //{ + // // Arrange + // var expectedCount = 5; + // var taskResult = Task.FromResult(expectedCount); - _mockUserService.Setup(service => service.CountUser()).Returns(taskResult); + // _mockUserService.Setup(service => service.CountUser()).Returns(taskResult); - // Act - var result = await _userController.GetCountUser(); + // // Act + // var result = await _userController.GetCountUser(); - // Assert - Assert.IsType(result); - } + // // Assert + // Assert.IsType(result); + //} - [Fact] - public async Task GetExistUsername_ReturnsOk_WhenUserExists() - { - // Arrange - var username = "testUser"; - var taskResult = Task.FromResult(true); + //[Fact] + //public async Task GetExistUsername_ReturnsOk_WhenUserExists() + //{ + // // Arrange + // var username = "testUser"; + // var taskResult = Task.FromResult(true); - _mockUserService.Setup(service => service.ExistUsername(username)).Returns(taskResult); + // _mockUserService.Setup(service => service.ExistUsername(username)).Returns(taskResult); - // Act - var result = await _userController.GetExistUsername(username); + // // Act + // var result = await _userController.GetExistUsername(username); - // Assert - Assert.IsType(result); + // // Assert + // Assert.IsType(result); - } + //} - [Fact] - public async Task GetExistEmail_ReturnsOk_WhenEmailExists() - { - // Arrange - var email = "test@unitaire.fr"; - var taskResult = Task.FromResult(true); + //[Fact] + //public async Task GetExistEmail_ReturnsOk_WhenEmailExists() + //{ + // // Arrange + // var email = "test@unitaire.fr"; + // var taskResult = Task.FromResult(true); - _mockUserService.Setup(service => service.ExistEmail(email)).Returns(taskResult); + // _mockUserService.Setup(service => service.ExistEmail(email)).Returns(taskResult); - // Act - var result = await _userController.GetExistEmail(email); + // // Act + // var result = await _userController.GetExistEmail(email); - // Assert - Assert.IsType(result); + // // Assert + // Assert.IsType(result); - } - [Fact] - public async Task UpdateUser_ReturnsOk_WhenUserDataIsValid() - { - // Arrange - var id = 1; - var updatedUser = new UserDTO - { - Id = id, - Pseudo = "UpdatedUser", - Email = "updated@unitaire.fr", - ImageProfil = "http://updatedImage.com", - Password = "newPassword123" - }; - - var taskResult = Task.FromResult(updatedUser); - - _mockUserService.Setup(service => service.UpdateUser(id, updatedUser)).Returns(taskResult); - - // Act - var result = await _userController.UpdateUser(id, updatedUser); - - // Assert - var okResult = Assert.IsType(result); - - Assert.IsType(result); - } - [Fact] - public async Task CreateUser_ReturnsCreatedAtAction_WhenUserIsValid() - { - // Arrange - var newUser = new UserDTO - { - Id = 2, - Pseudo = "NewUser", - Email = "newuser@unitaire.fr", - ImageProfil = "http://newuserimage.com", - Password = "newPassword123" - }; - - _mockUserService.Setup(service => service.GetUserById(newUser.Id)).ReturnsAsync((UserDTO)null); - - _mockUserService.Setup(service => service.AddUser(newUser)).Verifiable(); - - // Act - var result = await _userController.CreateUser(newUser); - - // Assert - var createdResult = Assert.IsType(result); - Assert.Equal(newUser.Id, createdResult.RouteValues["id"]); - } - - - [Fact] - public async Task DeletePlayer_ReturnsOk_WhenPlayerExists() - { - // Arrange - var id = 1; - var existingPlayer = new UserDTO - { - Id = id, - Pseudo = "ExistingUser", - Email = "existing@unitaire.fr", - ImageProfil = "http://existingimage.com", - Password = "existingPassword123" - }; - - _mockUserService.Setup(service => service.GetUserById(id)).ReturnsAsync(existingPlayer); - - _mockUserService.Setup(service => service.RemoveUser(existingPlayer.Id)).Verifiable(); - - // Act - var result = await _userController.DeletePlayer(id); - - // Assert - Assert.IsType(result); + //} + //[Fact] + //public async Task UpdateUser_ReturnsOk_WhenUserDataIsValid() + //{ + // // Arrange + // var id = 1; + // var updatedUser = new UserDTO + // { + // Id = id, + // Pseudo = "UpdatedUser", + // Email = "updated@unitaire.fr", + // ImageProfil = "http://updatedImage.com", + // Password = "newPassword123" + // }; + + // var taskResult = Task.FromResult(updatedUser); + + // _mockUserService.Setup(service => service.UpdateUser(id, updatedUser)).Returns(taskResult); + + // // Act + // var result = await _userController.UpdateUser(id, updatedUser); + + // // Assert + // var okResult = Assert.IsType(result); + + // Assert.IsType(result); + //} + //[Fact] + //public async Task CreateUser_ReturnsCreatedAtAction_WhenUserIsValid() + //{ + // // Arrange + // var newUser = new UserDTO + // { + // Id = 2, + // Pseudo = "NewUser", + // Email = "newuser@unitaire.fr", + // ImageProfil = "http://newuserimage.com", + // Password = "newPassword123" + // }; + + // _mockUserService.Setup(service => service.GetUserById(newUser.Id)).ReturnsAsync((UserDTO)null); + + // _mockUserService.Setup(service => service.AddUser(newUser)).Verifiable(); + + // // Act + // var result = await _userController.CreateUser(newUser); + + // // Assert + // var createdResult = Assert.IsType(result); + // Assert.Equal(newUser.Id, createdResult.RouteValues["id"]); + //} + + + //[Fact] + //public async Task DeletePlayer_ReturnsOk_WhenPlayerExists() + //{ + // // Arrange + // var id = 1; + // var existingPlayer = new UserDTO + // { + // Id = id, + // Pseudo = "ExistingUser", + // Email = "existing@unitaire.fr", + // ImageProfil = "http://existingimage.com", + // Password = "existingPassword123" + // }; + + // _mockUserService.Setup(service => service.GetUserById(id)).ReturnsAsync(existingPlayer); + + // _mockUserService.Setup(service => service.RemoveUser(existingPlayer.Id)).Verifiable(); + + // // Act + // var result = await _userController.DeletePlayer(id); + + // // Assert + // Assert.IsType(result); - } + //} } From cfe199a64db1d32eaf0231c1a91f8c3f3ab7b41e Mon Sep 17 00:00:00 2001 From: Leni BEAULATON Date: Wed, 2 Apr 2025 17:28:54 +0200 Subject: [PATCH 63/65] =?UTF-8?q?Mise=20=C3=A0=20jour=20de=20'.drone.yml'?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Drone3 --- .drone.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.drone.yml b/.drone.yml index 530d776..894663d 100644 --- a/.drone.yml +++ b/.drone.yml @@ -25,7 +25,7 @@ steps: - name: publish image: mcr.microsoft.com/dotnet/sdk:8.0 commands: - - dotnet publish -c Release -o out + - dotnet publish WF_EF_Api/WfApi/WfApi.csproj -c Release -o out depends_on: [retore & build, test] --- From eb0af16e6a0a6123cf153a369441744ac93f7ee7 Mon Sep 17 00:00:00 2001 From: kekentin Date: Wed, 2 Apr 2025 17:35:16 +0200 Subject: [PATCH 64/65] Route Favorite Remove A finir (supr favorite de la liste dans Quote et User) --- WF_EF_Api/Contextlib/DbFavoriteManager.cs | 85 +++++++++++++++++-- WF_EF_Api/Dto2Entities/Extention.cs | 24 +++++- WF_EF_Api/ServicesApi/FavoriteService.cs | 2 +- ...iteControleur.cs => FavoriteController.cs} | 33 +++++-- WF_EF_Api/WfApi/Program.cs | 1 + 5 files changed, 128 insertions(+), 17 deletions(-) rename WF_EF_Api/WfApi/Controllers/{FavoriteControleur.cs => FavoriteController.cs} (79%) diff --git a/WF_EF_Api/Contextlib/DbFavoriteManager.cs b/WF_EF_Api/Contextlib/DbFavoriteManager.cs index 27e1b90..1b84dd2 100644 --- a/WF_EF_Api/Contextlib/DbFavoriteManager.cs +++ b/WF_EF_Api/Contextlib/DbFavoriteManager.cs @@ -1,4 +1,6 @@ using Entity; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Metadata.Internal; using Shared; using System; using System.Collections.Generic; @@ -11,41 +13,108 @@ namespace Contextlib public class DbFavoriteManager : IFavoriteService { private WTFContext _context; + private GenericRepository _repo; public DbFavoriteManager(WTFContext context) { _context = context ?? throw new ArgumentNullException(nameof(context), "Database context cannot be null."); + _repo = new GenericRepository(context); } public async Task AddFavorite(int quoteid, int userId) { - throw new NotImplementedException(); + var quote = await _context.quotes // collection des commentaires est chargée + .Include(q => q.Favorite) + .FirstOrDefaultAsync(q => q.Id == quoteid); + + if (quote == null) + { + throw new ArgumentException("Quote not exist", nameof(quoteid)); + } + var user = await _context.users // collection des commentaires est chargée + .Include(u => u.Favorite) + .FirstOrDefaultAsync(q => q.Id == userId); + if (user == null) + { + throw new ArgumentException("User not exist", nameof(userId)); + } + + var fav = new Favorite + { + // Lien entre le favorite et la citation + Quote = quote, + IdQuote = quoteid, + // Lien entre le favorite et le user + Users = user, + IdUsers = userId, + }; + + if (fav != null) + { + // Ajout favorite à la collection des favorites de la citation + quote.Favorite.Add(user); + + // Ajout favorite à la collection des favorites de la citation + user.Favorite.Add(quote); + } + _context.Add(fav); + await _context.SaveChangesAsync(); } public async Task RemoveAllFavoriteForQuote(int quoteId) { - throw new NotImplementedException(); + var fav = await _context.quotes.Where(item => item.Id==quoteId) + .Include(q => q.Source).Include(q => q.Character).ThenInclude(c => c.Images).Include(q => q.Favorite) + .ToListAsync(); + + if (fav == null) throw new KeyNotFoundException(); + + foreach (var item in fav) + { + _repo.Delete(item); + } + + await _context.SaveChangesAsync(); } public async Task RemoveAllFavoriteForUser(int userId) { - throw new NotImplementedException(); + var fav = (await this.GetFavoriteByIdUser(userId,0,_repo.Count())).items; + + if (fav == null) throw new KeyNotFoundException(); + + foreach (var item in fav) + { + _repo.Delete(item); + } + + await _context.SaveChangesAsync(); } public async Task RemoveFavorite(int quoteid, int userId) { - throw new NotImplementedException(); + var fav = await this.GetFavorite(userId, quoteid); + + if (fav == null) throw new KeyNotFoundException(); + _repo.Delete(fav); + + await _context.SaveChangesAsync(); } - public Task GetFavorite(int userId, int idQuote) + public async Task GetFavorite(int userId, int idQuote) { - throw new NotImplementedException(); + return await _context.quotes.Where( item => item.Id == idQuote && item.Favorite.Any(u => u.Id == userId) ) + .Include(q => q.Source).Include(q => q.Character).ThenInclude(c => c.Images).Include(q=>q.Favorite) + .FirstOrDefaultAsync(); } - public Task> GetFavoriteByIdUser(int userId, int index, int count) + public async Task> GetFavoriteByIdUser(int userId, int index, int count) { - throw new NotImplementedException(); + List fav = await _context.quotes.Where(item => item.Favorite.Any(u => u.Id == userId)) + .Include(q => q.Source).Include(q => q.Character).ThenInclude(c => c.Images).Include(q => q.Favorite) + .Skip(index * count).Take(count).ToListAsync(); + return new PaginationResult(fav.Count,index,count,fav); } } } diff --git a/WF_EF_Api/Dto2Entities/Extention.cs b/WF_EF_Api/Dto2Entities/Extention.cs index 1687d94..a453875 100644 --- a/WF_EF_Api/Dto2Entities/Extention.cs +++ b/WF_EF_Api/Dto2Entities/Extention.cs @@ -15,6 +15,7 @@ namespace Dto2Entities public static CharacterDTO ToDto(this Character item) { + if (item == null) return null; CharacterDTO character = new CharacterDTO(); character.Id = item.Id; character.Name = item.Name; @@ -34,6 +35,7 @@ namespace Dto2Entities public static CommentaryDTO ToDto(this Commentary item) { + if (item == null) return null; CommentaryDTO commentary = new CommentaryDTO(); commentary.Id = item.Id; commentary.Date = item.DateCommentary; @@ -56,6 +58,7 @@ namespace Dto2Entities // Surement a refaire car Faoirite Entity modifier sur branche EF public static FavoriteDTO ToDto(this Favorite item) { + if (item == null) return null; FavoriteDTO favorite = new FavoriteDTO(); favorite.IdUser = item.IdUsers; favorite.IdQuote = item.IdQuote; @@ -74,6 +77,7 @@ namespace Dto2Entities public static ImageDTO ToDto(this Images item) { + if (item == null) return null; ImageDTO image = new ImageDTO(); image.IdImage = item.Id; image.ImagePath = item.ImgPath; @@ -92,6 +96,7 @@ namespace Dto2Entities public static QuestionDTO ToDto(this Question item) { + if (item == null) return null; QuestionDTO question = new QuestionDTO(); question.Id = item.Id; question.Question = item.Text; @@ -115,6 +120,7 @@ namespace Dto2Entities public static QuizDTO ToDto(this Quiz item) { + if (item == null) return null; QuizDTO quiz = new QuizDTO(); quiz.Id = item.Id; quiz.NbQuestion = item.NbQuestion; @@ -134,8 +140,9 @@ namespace Dto2Entities } // Surement a refaire car QuizQuestion Entity modifier sur branche EF - public static QuizQuestionDTO ToDto(this QuizQuestion item) - { + public static QuizQuestionDTO ToDto(this QuizQuestion item) + { + if (item == null) return null; QuizQuestionDTO quizQuestion = new QuizQuestionDTO(); quizQuestion.IdQuiz = item.IdQuiz; quizQuestion.IdQuestion = item.IdQuestion; @@ -154,6 +161,7 @@ namespace Dto2Entities public static QuoteDTO ToDto(this Quote item) { + if (item == null) return null; QuoteDTO quote = new QuoteDTO(); quote.Id = item.Id; quote.Content = item.Content; @@ -180,6 +188,7 @@ namespace Dto2Entities public static SourceDTO ToDto(this Source item) { + if (item == null) return null; SourceDTO source = new SourceDTO(); source.Id = item.Id; source.Date = item.Year; @@ -200,6 +209,7 @@ namespace Dto2Entities public static UserDTO ToDto(this Users item) { + if (item == null) return null; UserDTO user = new UserDTO(); user.Id = item.Id; user.Pseudo = item.UserName; @@ -247,6 +257,7 @@ namespace Dto2Entities public static Character ToEntity(this CharacterDTO item) { + if (item == null) return null; Character character = new Character(); character.Id = item.Id; character.Name = item.Name; @@ -266,6 +277,7 @@ namespace Dto2Entities public static Commentary ToEntity(this CommentaryDTO item) { + if (item == null) return null; Commentary commentary = new Commentary(); commentary.Id = item.Id; commentary.DateCommentary = item.Date; @@ -288,6 +300,7 @@ namespace Dto2Entities // Surement a refaire car Faoirite Entity modifier sur branche EF public static Favorite ToEntity(this FavoriteDTO item) { + if (item == null) return null; Favorite favorite = new Favorite(); favorite.IdUsers = item.IdUser; favorite.IdQuote = item.IdQuote; @@ -306,6 +319,7 @@ namespace Dto2Entities public static Images ToEntity(this ImageDTO item) { + if (item == null) return null; Images image = new Images(); image.Id = item.IdImage; image.ImgPath = item.ImagePath; @@ -324,6 +338,7 @@ namespace Dto2Entities public static Question ToEntity(this QuestionDTO item) { + if (item == null) return null; Question question = new Question(); question.Id = item.Id; question.Text = item.Question; @@ -346,6 +361,7 @@ namespace Dto2Entities public static Quiz ToEntity(this QuizDTO item) { + if (item == null) return null; Quiz quiz = new Quiz(); quiz.Id = item.Id; quiz.NbQuestion = item.NbQuestion; @@ -367,6 +383,7 @@ namespace Dto2Entities // Surement a refaire car QuizQuestion Entity modifier sur branche EF public static QuizQuestion ToEntity(this QuizQuestionDTO item) { + if (item == null) return null; QuizQuestion quizQuestion = new QuizQuestion(); quizQuestion.IdQuiz = item.IdQuiz; quizQuestion.IdQuestion = item.IdQuestion; @@ -385,6 +402,7 @@ namespace Dto2Entities public static Quote ToEntity(this QuoteDTO item) { + if (item == null) return null; Quote quote = new Quote(); quote.Id = item.Id; quote.Content = item.Content; @@ -414,6 +432,7 @@ namespace Dto2Entities public static Source ToEntity(this SourceDTO item) { + if (item == null) return null; Source source = new Source(); source.Id = item.Id; source.Year = item.Date; @@ -434,6 +453,7 @@ namespace Dto2Entities public static Users ToEntity(this UserDTO item) { + if (item == null) return null; Users user = new Users(); user.Id = item.Id; user.UserName = item.Pseudo; diff --git a/WF_EF_Api/ServicesApi/FavoriteService.cs b/WF_EF_Api/ServicesApi/FavoriteService.cs index a2a0030..b68d082 100644 --- a/WF_EF_Api/ServicesApi/FavoriteService.cs +++ b/WF_EF_Api/ServicesApi/FavoriteService.cs @@ -43,7 +43,7 @@ namespace ServicesApi await favoriteService.RemoveFavorite(quoteid, userId); } - public async Task GetFavorite(int userId, int idQuote) + public async Task GetFavorite(int userId, int idQuote) { return (await favoriteService.GetFavorite(userId,idQuote) ).ToDto(); } diff --git a/WF_EF_Api/WfApi/Controllers/FavoriteControleur.cs b/WF_EF_Api/WfApi/Controllers/FavoriteController.cs similarity index 79% rename from WF_EF_Api/WfApi/Controllers/FavoriteControleur.cs rename to WF_EF_Api/WfApi/Controllers/FavoriteController.cs index 7ef8a7c..20ca251 100644 --- a/WF_EF_Api/WfApi/Controllers/FavoriteControleur.cs +++ b/WF_EF_Api/WfApi/Controllers/FavoriteController.cs @@ -9,12 +9,12 @@ namespace WfApi.Controllers { [ApiController] [Route("api/v1/favorite")] //Version API - public class FavoriteControleur : ControllerBase + public class FavoriteController : ControllerBase { private readonly IFavoriteService _favorite; - private readonly ILogger _logger; - public FavoriteControleur(IFavoriteService favoriteService, ILogger logger) + private readonly ILogger _logger; + public FavoriteController(IFavoriteService favoriteService, ILogger logger) { _favorite = favoriteService; _logger = logger; @@ -22,12 +22,33 @@ namespace WfApi.Controllers - [HttpGet("{id}")] // Indiquer que l'id est dans l'URL - public async Task GetFavoriteByIdUser(int id, int index = 0, int count = 10) + [HttpGet("{idUser}")] // Indiquer que l'id est dans l'URL + public async Task GetFavoriteByIdUser(int idUser, int index = 0, int count = 10) { try { - var result = await _favorite.GetFavoriteByIdUser(id, index, count); + var result = await _favorite.GetFavoriteByIdUser(idUser, index, count); + + if (result != null) + { + return await Task.FromResult(Ok(result)); + } + else + { + return NoContent(); + } + } + catch (Exception) + { + return StatusCode((int)HttpStatusCode.InternalServerError, new { message = "Internal Server Error" }); + } + } + [HttpGet()] // Indiquer que l'id est dans l'URL + public async Task GetFavoriteByIdUser(int idUser , int idQuote) + { + try + { + var result = await _favorite.GetFavorite(idUser, idQuote); if (result != null) { diff --git a/WF_EF_Api/WfApi/Program.cs b/WF_EF_Api/WfApi/Program.cs index 24338f1..71bbd5b 100644 --- a/WF_EF_Api/WfApi/Program.cs +++ b/WF_EF_Api/WfApi/Program.cs @@ -26,6 +26,7 @@ builder.Services.AddScoped(); builder.Services.AddScoped, DbUsersManager>(); builder.Services.AddScoped, DbQuoteManager>(); +builder.Services.AddScoped, DbFavoriteManager>(); builder.Services.AddScoped, DbCommentaryManager>(); builder.Services.AddScoped, DbCharacterManager>(); builder.Services.AddScoped, DbImagesManager>(); From ed678b67ebdf9ab20df2b065159f0ea4ca6a967d Mon Sep 17 00:00:00 2001 From: kekentin Date: Wed, 2 Apr 2025 17:46:20 +0200 Subject: [PATCH 65/65] Finition route favorite --- WF_EF_Api/Contextlib/DbFavoriteManager.cs | 25 ++++++++++------------- 1 file changed, 11 insertions(+), 14 deletions(-) diff --git a/WF_EF_Api/Contextlib/DbFavoriteManager.cs b/WF_EF_Api/Contextlib/DbFavoriteManager.cs index 1b84dd2..0fbdd59 100644 --- a/WF_EF_Api/Contextlib/DbFavoriteManager.cs +++ b/WF_EF_Api/Contextlib/DbFavoriteManager.cs @@ -27,17 +27,15 @@ namespace Contextlib .Include(q => q.Favorite) .FirstOrDefaultAsync(q => q.Id == quoteid); - if (quote == null) - { - throw new ArgumentException("Quote not exist", nameof(quoteid)); - } var user = await _context.users // collection des commentaires est chargée .Include(u => u.Favorite) .FirstOrDefaultAsync(q => q.Id == userId); - if (user == null) + + if (quote == null && user == null) { - throw new ArgumentException("User not exist", nameof(userId)); + throw new ArgumentException("Quote or User not exist", nameof(quoteid)); } + var fav = new Favorite { @@ -64,15 +62,13 @@ namespace Contextlib public async Task RemoveAllFavoriteForQuote(int quoteId) { - var fav = await _context.quotes.Where(item => item.Id==quoteId) - .Include(q => q.Source).Include(q => q.Character).ThenInclude(c => c.Images).Include(q => q.Favorite) - .ToListAsync(); + var fav = _context.favorites.Where(item => item.IdQuote == quoteId).ToList(); if (fav == null) throw new KeyNotFoundException(); foreach (var item in fav) { - _repo.Delete(item); + _context.favorites.Remove(item); } await _context.SaveChangesAsync(); @@ -80,13 +76,13 @@ namespace Contextlib public async Task RemoveAllFavoriteForUser(int userId) { - var fav = (await this.GetFavoriteByIdUser(userId,0,_repo.Count())).items; + var fav = _context.favorites.Where(item => item.IdUsers == userId).ToList(); if (fav == null) throw new KeyNotFoundException(); foreach (var item in fav) { - _repo.Delete(item); + _context.favorites.Remove(item); } await _context.SaveChangesAsync(); @@ -94,10 +90,11 @@ namespace Contextlib public async Task RemoveFavorite(int quoteid, int userId) { - var fav = await this.GetFavorite(userId, quoteid); + var fav = await _context.favorites.Where(item=>item.IdQuote==quoteid && item.IdUsers==userId).FirstAsync(); if (fav == null) throw new KeyNotFoundException(); - _repo.Delete(fav); + + _context.favorites.Remove(fav); await _context.SaveChangesAsync(); }