Création des différents projets nécessaires pour l'API et la gestion de EntityFramework. Installation des nugets nécessaire (utilisation de pgsql pour EF). Création des entités + début de la création des classes métier, des DTO, des Mapper et des Service de données

pull/26/head
Johnny RATTON 1 year ago
parent bd8bddeec5
commit c681a72c84

@ -0,0 +1,14 @@
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
<InvariantGlobalization>true</InvariantGlobalization>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.4.0" />
</ItemGroup>
</Project>

@ -0,0 +1,6 @@
@API_HostAddress = http://localhost:5015
GET {{API_HostAddress}}/weatherforecast/
Accept: application/json
###

@ -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();

@ -0,0 +1,41 @@
{
"$schema": "http://json.schemastore.org/launchsettings.json",
"iisSettings": {
"windowsAuthentication": false,
"anonymousAuthentication": true,
"iisExpress": {
"applicationUrl": "http://localhost:64538",
"sslPort": 44356
}
},
"profiles": {
"http": {
"commandName": "Project",
"dotnetRunMessages": true,
"launchBrowser": true,
"launchUrl": "swagger",
"applicationUrl": "http://localhost:5015",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
},
"https": {
"commandName": "Project",
"dotnetRunMessages": true,
"launchBrowser": true,
"launchUrl": "swagger",
"applicationUrl": "https://localhost:7259;http://localhost:5015",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
},
"IIS Express": {
"commandName": "IISExpress",
"launchBrowser": true,
"launchUrl": "swagger",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
}
}
}

@ -0,0 +1,8 @@
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.AspNetCore": "Warning"
}
}
}

@ -0,0 +1,9 @@
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.AspNetCore": "Warning"
}
},
"AllowedHosts": "*"
}

@ -0,0 +1,25 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.8.34408.163
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "API", "API\API.csproj", "{65F4AE69-E1CA-4B87-BDF0-946A37351BD1}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{65F4AE69-E1CA-4B87-BDF0-946A37351BD1}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{65F4AE69-E1CA-4B87-BDF0-946A37351BD1}.Debug|Any CPU.Build.0 = Debug|Any CPU
{65F4AE69-E1CA-4B87-BDF0-946A37351BD1}.Release|Any CPU.ActiveCfg = Release|Any CPU
{65F4AE69-E1CA-4B87-BDF0-946A37351BD1}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {B1212232-F848-49A7-B5F9-0E66FD538A6F}
EndGlobalSection
EndGlobal

@ -0,0 +1,9 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
</Project>

@ -0,0 +1,22 @@
using Microsoft.EntityFrameworkCore;
namespace DbContextLib
{
public class UserDbContext : DbContext
{
public UserDbContext(DbContextOptions<UserDbContext> options) : base(options) { }
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
if (!optionsBuilder.IsConfigured)
{
optionsBuilder.UseNpgsql("Host=localhost;Database=SQLuedo;Username=admin;Password=password");
}
base.OnConfiguring(optionsBuilder);
}
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
base.OnModelCreating(modelBuilder);
}
}
}

@ -0,0 +1,9 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
</Project>

@ -0,0 +1,22 @@
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Entities.SQLudeoDB
{
public class BlackListEntity
{
[Key]
public string Email { get; set; }
public DateOnly ExpirationDate { get; set; }
public BlackListEntity() { }
public BlackListEntity(string email, DateOnly expirationDate)
{
Email = email;
ExpirationDate = expirationDate;
}
}
}

@ -0,0 +1,23 @@
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 Entities
{
internal class ContentLessonEntity
{
[Key, Column(Order = 0)]
[ForeignKey(nameof(Lesson))]
public int LessonId { get; set; }
public LessonEntity Lesson { get; set; }
[Key, Column(Order = 1)]
[ForeignKey(nameof(Paragraph))]
public int LessonPartId { get; set; }
public ParagraphEntity Paragraph { get; set; }
}
}

@ -0,0 +1,29 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Entities
{
public class InquiryEntity
{
public int Id { get; set; }
public string Title { get; set; }
public string Description { get; set; }
public bool IsUser { get; set; }
public InquiryTableEntity Database { get; set; }
public SolutionEntity InquiryTable { get; set; }
public InquiryEntity() { }
public InquiryEntity(int id, string title, string description, bool isUser, InquiryTableEntity database, SolutionEntity inquiryTable)
{
Id = id;
Title = title;
Description = description;
IsUser = isUser;
Database = database;
InquiryTable = inquiryTable;
}
}
}

@ -0,0 +1,32 @@
using System.ComponentModel.DataAnnotations.Schema;
using System.ComponentModel.DataAnnotations;
namespace Entities
{
public class InquiryTableEntity
{
[Key]
[ForeignKey(nameof(Owner))]
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
[Required]
public int OwnerId { get; set; }
public InquiryEntity Owner { get; set; }
public string DatabaseName { get; set; }
public string ConnectionInfo { get; set; }
public InquiryTableEntity() { }
public InquiryTableEntity(int inquiryId, string databaseName, string connectionInfo)
{
OwnerId = inquiryId;
DatabaseName = databaseName;
ConnectionInfo = connectionInfo;
}
public InquiryTableEntity(InquiryEntity owner, string databaseName, string connectionInfo)
{
Owner = owner;
DatabaseName = databaseName;
ConnectionInfo = connectionInfo;
}
}
}

@ -0,0 +1,32 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Entities
{
public class LessonEntity
{
public int Id { get; set; }
public string Titla { get; set; }
public string LastPublisher { get; set; }
public DateOnly LastEdit { get; set; }
public LessonEntity() { }
public LessonEntity(int id, string titla, string lastPublisher, DateOnly lastEdit)
{
Id = id;
Titla = titla;
LastPublisher = lastPublisher;
LastEdit = lastEdit;
}
public LessonEntity(string titla, string lastPublisher, DateOnly lastEdit)
{
Titla = titla;
LastPublisher = lastPublisher;
LastEdit = lastEdit;
}
}
}

@ -0,0 +1,43 @@
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations.Schema;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Entities.SQLudeoDB
{
public class NotepadEntity
{
public int Id { get; set; }
[ForeignKey(nameof(User))]
public int UserId { get; set; }
public UserEntity User { get; set; }
[ForeignKey(nameof(Inquiry))]
public int InquiryId { get; set; }
public InquiryEntity Inquiry { get; set; }
public string Notes { get; set; }
public NotepadEntity() { }
public NotepadEntity(int id, int userId, UserEntity user, int inquiryId, InquiryEntity inquiry, string notes)
{
Id = id;
UserId = userId;
User = user;
InquiryId = inquiryId;
Inquiry = inquiry;
Notes = notes;
}
public NotepadEntity(int userId, UserEntity user, int inquiryId, InquiryEntity inquiry, string notes)
{
UserId = userId;
User = user;
InquiryId = inquiryId;
Inquiry = inquiry;
Notes = notes;
}
}
}

@ -0,0 +1,32 @@
namespace Entities
{
public class ParagraphEntity
{
public int Id { get; set; }
public string Title { get; set; }
public string Content { get; set; }
public string Info { get; set; }
public string Query { get; set; }
public string Comment { get; set; }
public ParagraphEntity() { }
public ParagraphEntity(int id, string title, string content, string info, string query, string comment)
{
Id = id;
Title = title;
Content = content;
Info = info;
Query = query;
Comment = comment;
}
public ParagraphEntity(string title, string content, string info, string query, string comment)
{
Title = title;
Content = content;
Info = info;
Query = query;
Comment = comment;
}
}
}

@ -0,0 +1,41 @@
using System.ComponentModel.DataAnnotations.Schema;
using System.ComponentModel.DataAnnotations;
using System.Security.Cryptography.X509Certificates;
namespace Entities
{
public class SolutionEntity
{
[Key]
[ForeignKey(nameof(Owner))]
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
[Required]
public int OwnerId { get; set; }
public InquiryEntity Owner { get; set; }
public string MurdererFirstName { get; set; }
public string MurdererLastName { get; set; }
public string MurderPlace { get; set; }
public string MurderWeapon { get; set; }
public string Explanation { get; set; }
public SolutionEntity() { }
public SolutionEntity(int ownerId, InquiryEntity owner, string murdererFirstName, string murdererLastName, string murderPlace, string murderWeapon, string explanation)
{
OwnerId = ownerId;
Owner = owner;
MurdererFirstName = murdererFirstName;
MurdererLastName = murdererLastName;
MurderPlace = murderPlace;
MurderWeapon = murderWeapon;
Explanation = explanation;
}
public SolutionEntity(InquiryEntity owner, string murdererFirstName, string murdererLastName, string murderPlace, string murderWeapon, string explanation)
{
Owner = owner;
MurdererFirstName = murdererFirstName;
MurdererLastName = murdererLastName;
MurderPlace = murderPlace;
MurderWeapon = murderWeapon;
Explanation = explanation;
}
}
}

@ -0,0 +1,38 @@
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 Entities.SQLudeoDB
{
public class SuccessEntity
{
[Key, Column(Order = 0), ForeignKey(nameof(User))]
public int UserId { get; set; }
public UserEntity User { get; set; }
[Key, Column(Order = 1), ForeignKey(nameof(Inquiry))]
public int InquiryId { get; set; }
public InquiryEntity Inquiry { get; set; }
public bool IsFinished { get; set; }
public SuccessEntity() { }
public SuccessEntity(int userId, int inquiryId, bool isFinished)
{
UserId = userId;
InquiryId = inquiryId;
IsFinished = isFinished;
}
public SuccessEntity(UserEntity user, InquiryEntity inquiry, bool isFinished)
{
User = user;
Inquiry = inquiry;
IsFinished = isFinished;
}
}
}

@ -0,0 +1,30 @@
namespace EntityFramework
{
public class UserEntity
{
public int Id { get; set; }
public string Username { get; set; }
public string Password { get; set; }
public string Email { get; set; }
public bool IsAdmin { get; set; }
public UserEntity() { }
public UserEntity(int id, string username, string password, string email, bool isAdmin)
{
Id = id;
Username = username;
Password = password;
Email = email;
IsAdmin = isAdmin;
}
public UserEntity(string username, string password, string email, bool isAdmin)
{
Username = username;
Password = password;
Email = email;
IsAdmin = isAdmin;
}
}
}

@ -0,0 +1,12 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Model.Business
{
public class Inquiry
{
}
}

@ -0,0 +1,7 @@
namespace Model.Business
{
public class UserDTO
{
}
}

@ -0,0 +1,12 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Model.DTO
{
public class InquiryDTO
{
}
}

@ -0,0 +1,12 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Model.DTO
{
public class UserDTO
{
}
}

@ -0,0 +1,16 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Model.Mappers
{
public interface IMapper
{
public Object FromEntityToModel();
public Object FromModelToDTO();
public Object FromDTOToModel();
public Object FromModelToEntity();
}
}

@ -0,0 +1,31 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Model.Mappers
{
public class InquiryMapper : IMapper
{
public object FromDTOToModel()
{
throw new NotImplementedException();
}
public object FromEntityToModel()
{
throw new NotImplementedException();
}
public object FromModelToDTO()
{
throw new NotImplementedException();
}
public object FromModelToEntity()
{
throw new NotImplementedException();
}
}
}

@ -0,0 +1,31 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Model.Mappers
{
public class UserMapper : IMapper
{
public object FromDTOToModel()
{
throw new NotImplementedException();
}
public object FromEntityToModel()
{
throw new NotImplementedException();
}
public object FromModelToDTO()
{
throw new NotImplementedException();
}
public object FromModelToEntity()
{
throw new NotImplementedException();
}
}
}

@ -0,0 +1,9 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
</Project>

@ -0,0 +1,13 @@
using Model.DTO;
namespace Services
{
public interface IDataService
{
public IEnumerable<UserDTO> GetUsers(int page, int number);
public UserDTO GetUserById(int id);
public UserDTO GetUserByUsername(string username);
public IEnumerable<InquiryDTO> GetInquiries();
}
}

@ -0,0 +1,9 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
</Project>

@ -0,0 +1,25 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<IsPackable>false</IsPackable>
<IsTestProject>true</IsTestProject>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.6.0" />
<PackageReference Include="xunit" Version="2.4.2" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.5">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="coverlet.collector" Version="6.0.0">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
</ItemGroup>
</Project>

@ -0,0 +1,11 @@
namespace TestAPI
{
public class UnitTest1
{
[Fact]
public void Test1()
{
}
}
}

@ -0,0 +1 @@
global using Xunit;

@ -0,0 +1,25 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<IsPackable>false</IsPackable>
<IsTestProject>true</IsTestProject>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.6.0" />
<PackageReference Include="xunit" Version="2.4.2" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.5">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="coverlet.collector" Version="6.0.0">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
</ItemGroup>
</Project>

@ -0,0 +1,11 @@
namespace TestEF
{
public class UnitTest1
{
[Fact]
public void Test1()
{
}
}
}
Loading…
Cancel
Save