From b8d6d6cecff9a3a83961fed0c91a56fb18c5da6e Mon Sep 17 00:00:00 2001 From: "damien.nortier" Date: Mon, 19 Feb 2024 08:29:34 +0100 Subject: [PATCH] =?UTF-8?q?feat=20+=20doc=20:=20cr=C3=A9ation=20de=20proje?= =?UTF-8?q?t=20et=20ajout=20de=20la=20classe=20Answer=20(AnswerEntity,=20A?= =?UTF-8?q?nswerDTO)=20+=20documentation=20de=20cette=20classe?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- WebApi/DTOs/AnswerDto.cs | 25 +++++++++ WebApi/DTOs/DTOs.csproj | 9 +++ .../DbConnectionLibrairie.csproj | 22 ++++++++ WebApi/DbConnectionLibrairie/MyDbContext.cs | 17 ++++++ WebApi/Entities/AnswerEntity.cs | 14 +++++ WebApi/Entities/Entities.csproj | 9 +++ WebApi/ManagerInterfaces/IAnswerManager.cs | 7 +++ .../ManagerInterfaces.csproj | 9 +++ WebApi/Model/Answer.cs | 53 ++++++++++++++++++ WebApi/Model/Model.csproj | 9 +++ WebApi/WebApi.sln | 55 +++++++++++++++++++ .../Controllers/WeatherForecastController.cs | 33 +++++++++++ WebApi/WebApplication/Program.cs | 25 +++++++++ .../Properties/launchSettings.json | 41 ++++++++++++++ WebApi/WebApplication/WeatherForecast.cs | 13 +++++ WebApi/WebApplication/WebApplication.csproj | 13 +++++ WebApi/WebApplication/WebApplication.http | 6 ++ .../appsettings.Development.json | 8 +++ WebApi/WebApplication/appsettings.json | 9 +++ WebApi/routes.txt | 30 ++++++++++ 20 files changed, 407 insertions(+) create mode 100644 WebApi/DTOs/AnswerDto.cs create mode 100644 WebApi/DTOs/DTOs.csproj create mode 100644 WebApi/DbConnectionLibrairie/DbConnectionLibrairie.csproj create mode 100644 WebApi/DbConnectionLibrairie/MyDbContext.cs create mode 100644 WebApi/Entities/AnswerEntity.cs create mode 100644 WebApi/Entities/Entities.csproj create mode 100644 WebApi/ManagerInterfaces/IAnswerManager.cs create mode 100644 WebApi/ManagerInterfaces/ManagerInterfaces.csproj create mode 100644 WebApi/Model/Answer.cs create mode 100644 WebApi/Model/Model.csproj create mode 100644 WebApi/WebApi.sln create mode 100644 WebApi/WebApplication/Controllers/WeatherForecastController.cs create mode 100644 WebApi/WebApplication/Program.cs create mode 100644 WebApi/WebApplication/Properties/launchSettings.json create mode 100644 WebApi/WebApplication/WeatherForecast.cs create mode 100644 WebApi/WebApplication/WebApplication.csproj create mode 100644 WebApi/WebApplication/WebApplication.http create mode 100644 WebApi/WebApplication/appsettings.Development.json create mode 100644 WebApi/WebApplication/appsettings.json create mode 100644 WebApi/routes.txt diff --git a/WebApi/DTOs/AnswerDto.cs b/WebApi/DTOs/AnswerDto.cs new file mode 100644 index 0000000..78e9a00 --- /dev/null +++ b/WebApi/DTOs/AnswerDto.cs @@ -0,0 +1,25 @@ +namespace DTOs +{ + /// + /// define a DTO of an answer for a Question with Mutiple Choice + /// properties : + /// Id : identifier in the database + /// Content : content of the answer + /// + public class AnswerDto + { + public long Id { get; set; } + public string Content { get; set; } = null!; + + /// + /// constructor of an answer + /// + /// the id of an answer + /// the content of an answer + public AnswerDto(long id, string content) + { + Id = id; + Content = content; + } + } +} diff --git a/WebApi/DTOs/DTOs.csproj b/WebApi/DTOs/DTOs.csproj new file mode 100644 index 0000000..fa71b7a --- /dev/null +++ b/WebApi/DTOs/DTOs.csproj @@ -0,0 +1,9 @@ + + + + net8.0 + enable + enable + + + diff --git a/WebApi/DbConnectionLibrairie/DbConnectionLibrairie.csproj b/WebApi/DbConnectionLibrairie/DbConnectionLibrairie.csproj new file mode 100644 index 0000000..ad7adea --- /dev/null +++ b/WebApi/DbConnectionLibrairie/DbConnectionLibrairie.csproj @@ -0,0 +1,22 @@ + + + + net8.0 + enable + enable + + + + + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + + + + + + + diff --git a/WebApi/DbConnectionLibrairie/MyDbContext.cs b/WebApi/DbConnectionLibrairie/MyDbContext.cs new file mode 100644 index 0000000..81a5a21 --- /dev/null +++ b/WebApi/DbConnectionLibrairie/MyDbContext.cs @@ -0,0 +1,17 @@ +using Microsoft.EntityFrameworkCore; +using Microsoft.Extensions.Options; + +namespace DbConnectionLibrairie +{ + public class MyDbContext : DbContext + { + + protected override void OnConfiguring(DbContextOptionsBuilder options) + { + if (!options.IsConfigured) + { + options.UseSqlite(@"Data source = database.db"); + } + } + } +} diff --git a/WebApi/Entities/AnswerEntity.cs b/WebApi/Entities/AnswerEntity.cs new file mode 100644 index 0000000..81f44e5 --- /dev/null +++ b/WebApi/Entities/AnswerEntity.cs @@ -0,0 +1,14 @@ +namespace Entities +{ + public class AnswerEntity + { + /// + /// define an entity of an answer for a Question with Mutiple Choice + /// properties : + /// Id : identifier in the database + /// Content : content of the answer + /// + long Id { get; set; } + string Content { get; set; } = null!; + } +} diff --git a/WebApi/Entities/Entities.csproj b/WebApi/Entities/Entities.csproj new file mode 100644 index 0000000..fa71b7a --- /dev/null +++ b/WebApi/Entities/Entities.csproj @@ -0,0 +1,9 @@ + + + + net8.0 + enable + enable + + + diff --git a/WebApi/ManagerInterfaces/IAnswerManager.cs b/WebApi/ManagerInterfaces/IAnswerManager.cs new file mode 100644 index 0000000..0f9610f --- /dev/null +++ b/WebApi/ManagerInterfaces/IAnswerManager.cs @@ -0,0 +1,7 @@ +namespace ManagerInterfaces +{ + public interface IAnswerManager + { + public T getAnswers(int nb, int count); + } +} diff --git a/WebApi/ManagerInterfaces/ManagerInterfaces.csproj b/WebApi/ManagerInterfaces/ManagerInterfaces.csproj new file mode 100644 index 0000000..fa71b7a --- /dev/null +++ b/WebApi/ManagerInterfaces/ManagerInterfaces.csproj @@ -0,0 +1,9 @@ + + + + net8.0 + enable + enable + + + diff --git a/WebApi/Model/Answer.cs b/WebApi/Model/Answer.cs new file mode 100644 index 0000000..5dd1554 --- /dev/null +++ b/WebApi/Model/Answer.cs @@ -0,0 +1,53 @@ +namespace Model +{ + /// + /// define an answer for a Question with Mutiple Choice + /// variable : + /// id : identifier in the database + /// content : content of the answer + /// + public class Answer + { + private long id; + private string? content; + /// + /// property for id manipulations + /// + public long Id + { + get + { + return id; + } + private set + { + id = value < -1 ? -1 : value; + } + } + /// + /// property for content manipulations + /// + public string Content + { + get + { + return content == null ? "" : content; + } + set + { + content = value == "" ? null : value; + } + } + + /// + /// constructor of an answer + /// + /// the content of an answer + /// the id of an answer + private Answer(string content, long id = -1) + { + Id = id; + Content = content; + } + } +} diff --git a/WebApi/Model/Model.csproj b/WebApi/Model/Model.csproj new file mode 100644 index 0000000..fa71b7a --- /dev/null +++ b/WebApi/Model/Model.csproj @@ -0,0 +1,9 @@ + + + + net8.0 + enable + enable + + + diff --git a/WebApi/WebApi.sln b/WebApi/WebApi.sln new file mode 100644 index 0000000..9c0923d --- /dev/null +++ b/WebApi/WebApi.sln @@ -0,0 +1,55 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 17 +VisualStudioVersion = 17.9.34607.119 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WebApplication", "WebApplication\WebApplication.csproj", "{9F05B995-3079-4905-A9B1-7B3E8621ECC1}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Entities", "Entities\Entities.csproj", "{19A1AA55-0FDF-427F-97EA-157E816C93CE}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DbConnectionLibrairie", "DbConnectionLibrairie\DbConnectionLibrairie.csproj", "{8224E470-B008-4738-88FD-7DEDCAA4AE44}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ManagerInterfaces", "ManagerInterfaces\ManagerInterfaces.csproj", "{35D8DDF1-93B1-4064-9205-BB745D300BCC}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DTOs", "DTOs\DTOs.csproj", "{F911181D-6194-4CA9-A302-7A055652E5FA}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Model", "Model\Model.csproj", "{1C517096-268C-478C-BB98-5ACB8DD0692A}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {9F05B995-3079-4905-A9B1-7B3E8621ECC1}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {9F05B995-3079-4905-A9B1-7B3E8621ECC1}.Debug|Any CPU.Build.0 = Debug|Any CPU + {9F05B995-3079-4905-A9B1-7B3E8621ECC1}.Release|Any CPU.ActiveCfg = Release|Any CPU + {9F05B995-3079-4905-A9B1-7B3E8621ECC1}.Release|Any CPU.Build.0 = Release|Any CPU + {19A1AA55-0FDF-427F-97EA-157E816C93CE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {19A1AA55-0FDF-427F-97EA-157E816C93CE}.Debug|Any CPU.Build.0 = Debug|Any CPU + {19A1AA55-0FDF-427F-97EA-157E816C93CE}.Release|Any CPU.ActiveCfg = Release|Any CPU + {19A1AA55-0FDF-427F-97EA-157E816C93CE}.Release|Any CPU.Build.0 = Release|Any CPU + {8224E470-B008-4738-88FD-7DEDCAA4AE44}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {8224E470-B008-4738-88FD-7DEDCAA4AE44}.Debug|Any CPU.Build.0 = Debug|Any CPU + {8224E470-B008-4738-88FD-7DEDCAA4AE44}.Release|Any CPU.ActiveCfg = Release|Any CPU + {8224E470-B008-4738-88FD-7DEDCAA4AE44}.Release|Any CPU.Build.0 = Release|Any CPU + {35D8DDF1-93B1-4064-9205-BB745D300BCC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {35D8DDF1-93B1-4064-9205-BB745D300BCC}.Debug|Any CPU.Build.0 = Debug|Any CPU + {35D8DDF1-93B1-4064-9205-BB745D300BCC}.Release|Any CPU.ActiveCfg = Release|Any CPU + {35D8DDF1-93B1-4064-9205-BB745D300BCC}.Release|Any CPU.Build.0 = Release|Any CPU + {F911181D-6194-4CA9-A302-7A055652E5FA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {F911181D-6194-4CA9-A302-7A055652E5FA}.Debug|Any CPU.Build.0 = Debug|Any CPU + {F911181D-6194-4CA9-A302-7A055652E5FA}.Release|Any CPU.ActiveCfg = Release|Any CPU + {F911181D-6194-4CA9-A302-7A055652E5FA}.Release|Any CPU.Build.0 = Release|Any CPU + {1C517096-268C-478C-BB98-5ACB8DD0692A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {1C517096-268C-478C-BB98-5ACB8DD0692A}.Debug|Any CPU.Build.0 = Debug|Any CPU + {1C517096-268C-478C-BB98-5ACB8DD0692A}.Release|Any CPU.ActiveCfg = Release|Any CPU + {1C517096-268C-478C-BB98-5ACB8DD0692A}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {30D8C710-2DC7-401D-AC62-AB63591468C8} + EndGlobalSection +EndGlobal diff --git a/WebApi/WebApplication/Controllers/WeatherForecastController.cs b/WebApi/WebApplication/Controllers/WeatherForecastController.cs new file mode 100644 index 0000000..6377a80 --- /dev/null +++ b/WebApi/WebApplication/Controllers/WeatherForecastController.cs @@ -0,0 +1,33 @@ +using Microsoft.AspNetCore.Mvc; + +namespace WebApplication.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/WebApi/WebApplication/Program.cs b/WebApi/WebApplication/Program.cs new file mode 100644 index 0000000..48863a6 --- /dev/null +++ b/WebApi/WebApplication/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/WebApi/WebApplication/Properties/launchSettings.json b/WebApi/WebApplication/Properties/launchSettings.json new file mode 100644 index 0000000..9fd4ce5 --- /dev/null +++ b/WebApi/WebApplication/Properties/launchSettings.json @@ -0,0 +1,41 @@ +{ + "$schema": "http://json.schemastore.org/launchsettings.json", + "iisSettings": { + "windowsAuthentication": false, + "anonymousAuthentication": true, + "iisExpress": { + "applicationUrl": "http://localhost:62623", + "sslPort": 44358 + } + }, + "profiles": { + "http": { + "commandName": "Project", + "dotnetRunMessages": true, + "launchBrowser": true, + "launchUrl": "swagger", + "applicationUrl": "http://localhost:5228", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + } + }, + "https": { + "commandName": "Project", + "dotnetRunMessages": true, + "launchBrowser": true, + "launchUrl": "swagger", + "applicationUrl": "https://localhost:7256;http://localhost:5228", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + } + }, + "IIS Express": { + "commandName": "IISExpress", + "launchBrowser": true, + "launchUrl": "swagger", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + } + } + } +} diff --git a/WebApi/WebApplication/WeatherForecast.cs b/WebApi/WebApplication/WeatherForecast.cs new file mode 100644 index 0000000..bfdf165 --- /dev/null +++ b/WebApi/WebApplication/WeatherForecast.cs @@ -0,0 +1,13 @@ +namespace WebApplication +{ + 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/WebApi/WebApplication/WebApplication.csproj b/WebApi/WebApplication/WebApplication.csproj new file mode 100644 index 0000000..9daa180 --- /dev/null +++ b/WebApi/WebApplication/WebApplication.csproj @@ -0,0 +1,13 @@ + + + + net8.0 + enable + enable + + + + + + + diff --git a/WebApi/WebApplication/WebApplication.http b/WebApi/WebApplication/WebApplication.http new file mode 100644 index 0000000..9c6f7be --- /dev/null +++ b/WebApi/WebApplication/WebApplication.http @@ -0,0 +1,6 @@ +@WebApplication_HostAddress = http://localhost:5228 + +GET {{WebApplication_HostAddress}}/weatherforecast/ +Accept: application/json + +### diff --git a/WebApi/WebApplication/appsettings.Development.json b/WebApi/WebApplication/appsettings.Development.json new file mode 100644 index 0000000..0c208ae --- /dev/null +++ b/WebApi/WebApplication/appsettings.Development.json @@ -0,0 +1,8 @@ +{ + "Logging": { + "LogLevel": { + "Default": "Information", + "Microsoft.AspNetCore": "Warning" + } + } +} diff --git a/WebApi/WebApplication/appsettings.json b/WebApi/WebApplication/appsettings.json new file mode 100644 index 0000000..10f68b8 --- /dev/null +++ b/WebApi/WebApplication/appsettings.json @@ -0,0 +1,9 @@ +{ + "Logging": { + "LogLevel": { + "Default": "Information", + "Microsoft.AspNetCore": "Warning" + } + }, + "AllowedHosts": "*" +} diff --git a/WebApi/routes.txt b/WebApi/routes.txt new file mode 100644 index 0000000..2511dbf --- /dev/null +++ b/WebApi/routes.txt @@ -0,0 +1,30 @@ +./Blazor/Blazor/Pages/Admins/AddAdministrator.razor.cs: string apiUri = API.API_URL + "add/administrator/" + API.TOKEN + ./Blazor/Blazor/Pages/Admins/Administrators.razor.cs: var response = await Http.GetFromJsonAsync(API.API_URL + "all/administrators/" + API.TOKEN + "/" + page) + ./Blazor/Blazor/Pages/Admins/Administrators.razor.cs: string apiUri = API.API_URL +"delete/administrator/" + id + "/" + API.TOKEN + ./Blazor/Blazor/Pages/Admins/EditAdministrator.razor.cs: string apiUri = API.API_URL + "update/administrator/" + administratorModel.Id + "/" + API.TOKEN + ./Blazor/Blazor/Pages/Chapters/AddChapter.razor.cs: string apiUri = API.API_URL + "add/chapter/" + API.TOKEN + ./Blazor/Blazor/Pages/Chapters/Chapters.razor.cs: string apiUri = API.API_URL+"delete/chapter/" + id + "/" + API.TOKEN + ./Blazor/Blazor/Pages/Chapters/Chapters.razor.cs: var response = await Http.GetFromJsonAsync(API.API_URL + "all/chapters/" + API.TOKEN + "/" + page) + ./Blazor/Blazor/Pages/Chapters/EditChapter.razor.cs: string apiUri = API.API_URL+"update/chapter/" + chapterModel.Id + "/" + API.TOKEN + ./Blazor/Blazor/Pages/Players/AddPlayer.razor.cs: string apiUri = API.API_URL + "add/player/" + API.TOKEN + ./Blazor/Blazor/Pages/Players/EditPlayer.razor.cs: string apiUri = API.API_URL+"update/player/" + playerModel.Id + "/" + API.TOKEN + ./Blazor/Blazor/Pages/Players/Players.razor.cs: string apiUri = API.API_URL+"delete/player/" + id + "/" + API.TOKEN + ./Blazor/Blazor/Pages/Players/Players.razor.cs: var response = await Http.GetFromJsonAsync(API.API_URL + "all/players/" + API.TOKEN + "/" + page) + ./Blazor/Blazor/Pages/Questions/AddQuestion.razor.cs: var response = Http.GetFromJsonAsync(API.API_URL + "all/chapters/" + API.TOKEN + "/1").Result + ./Blazor/Blazor/Pages/Questions/AddQuestion.razor.cs: string apiUri = API.API_URL + "add/question/" + API.TOKEN + ./Blazor/Blazor/Pages/Questions/DisplayQuestions.razor.cs: var response = Http.GetFromJsonAsync(API.API_URL + "questions/" + QuestionId + "/" + API.TOKEN).Result + ./Blazor/Blazor/Pages/Questions/EditQuestion.razor.cs: var response = Http.GetFromJsonAsync(API.API_URL + "all/chapters/" + API.TOKEN + "/1").Result + ./Blazor/Blazor/Pages/Questions/EditQuestion.razor.cs: var resp = Http.GetFromJsonAsync(API.API_URL + "questions/" + Id + "/" + API.TOKEN).Result + ./Blazor/Blazor/Pages/Questions/EditQuestion.razor.cs: string apiUri = API.API_URL+"/update/question/" + question.Id + "/" + API.TOKEN + ./Blazor/Blazor/Pages/Questions/Questions.razor.cs: string apiUri = API.API_URL+"delete/question/" + id + "/" + API.TOKEN + ./Blazor/Blazor/Pages/Questions/Questions.razor.cs: var response = await Http.GetFromJsonAsync(API.API_URL + "all/questions/" + API.TOKEN + "/" + page) + ./Blazor/Blazor/Pages/Questions/Questions.razor.cs: HttpResponseMessage response = await Http.GetAsync(API.API_URL+"questionsExport/"+API.TOKEN) + ./Blazor/Blazor/Pages/Questions/Questions.razor.cs: string apiUri = API.API_URL+"chapters/name/"+field[1] + "/" + API.TOKEN + ./Blazor/Blazor/Pages/Questions/Questions.razor.cs: apiUri = API.API_URL+"add/question/"+API.TOKEN + ./Blazor/Blazor/Services/DataLocalService.cs: var currentData = _http.GetFromJsonAsync>(API.API_URL + "chapters/" + id + "/" + API.TOKEN).Result + ./Blazor/Blazor/Services/DataLocalService.cs: var currentData = _http.GetFromJsonAsync>(API.API_URL + "administrators/" + id + "/" + API.TOKEN).Result + ./Blazor/Blazor/Services/DataLocalService.cs: var currentData = _http.GetFromJsonAsync>(API.API_URL + "questions/"+API.TOKEN).Result + ./Blazor/Blazor/Services/DataLocalService.cs: var currentData = await _http.GetFromJsonAsync>(API.API_URL + "questions/" + API.TOKEN) + ./Blazor/Blazor/Services/DataLocalService.cs: var currentData = _http.GetFromJsonAsync>(API.API_URL + "players/" + id + "/" + API.TOKEN).Result + ./Blazor/Blazor/Services/DataLocalService.cs: var answer = _http.GetFromJsonAsync(API.API_URL + "answer/" + id + "/" + API.TOKEN).Result + \ No newline at end of file