Creating all entities and dbcontext
This commit is contained in:
5
.gitignore
vendored
Normal file
5
.gitignore
vendored
Normal file
@@ -0,0 +1,5 @@
|
||||
bin/
|
||||
obj/
|
||||
/packages/
|
||||
riderModule.iml
|
||||
/_ReSharper.Caches/
|
13
.idea/.idea.BlogPlatform/.idea/.gitignore
generated
vendored
Normal file
13
.idea/.idea.BlogPlatform/.idea/.gitignore
generated
vendored
Normal file
@@ -0,0 +1,13 @@
|
||||
# Default ignored files
|
||||
/shelf/
|
||||
/workspace.xml
|
||||
# Rider ignored files
|
||||
/modules.xml
|
||||
/.idea.BlogPlatform.iml
|
||||
/contentModel.xml
|
||||
/projectSettingsUpdater.xml
|
||||
# Editor-based HTTP Client requests
|
||||
/httpRequests/
|
||||
# Datasource local storage ignored files
|
||||
/dataSources/
|
||||
/dataSources.local.xml
|
8
.idea/.idea.BlogPlatform/.idea/indexLayout.xml
generated
Normal file
8
.idea/.idea.BlogPlatform/.idea/indexLayout.xml
generated
Normal file
@@ -0,0 +1,8 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="UserContentModel">
|
||||
<attachedFolders />
|
||||
<explicitIncludes />
|
||||
<explicitExcludes />
|
||||
</component>
|
||||
</project>
|
6
.idea/.idea.BlogPlatform/.idea/vcs.xml
generated
Normal file
6
.idea/.idea.BlogPlatform/.idea/vcs.xml
generated
Normal file
@@ -0,0 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="VcsDirectoryMappings">
|
||||
<mapping directory="$PROJECT_DIR$" vcs="Git" />
|
||||
</component>
|
||||
</project>
|
16
BlogPlatform.sln
Normal file
16
BlogPlatform.sln
Normal file
@@ -0,0 +1,16 @@
|
||||
|
||||
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BlogPlatform", "BlogPlatform\BlogPlatform.csproj", "{B132EF03-5CDA-4FD0-AB1B-3F12F064478C}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Any CPU = Debug|Any CPU
|
||||
Release|Any CPU = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||
{B132EF03-5CDA-4FD0-AB1B-3F12F064478C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{B132EF03-5CDA-4FD0-AB1B-3F12F064478C}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{B132EF03-5CDA-4FD0-AB1B-3F12F064478C}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{B132EF03-5CDA-4FD0-AB1B-3F12F064478C}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
EndGlobal
|
24
BlogPlatform/BlogPlatform.csproj
Normal file
24
BlogPlatform/BlogPlatform.csproj
Normal file
@@ -0,0 +1,24 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk.Web">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net8.0</TargetFramework>
|
||||
<Nullable>enable</Nullable>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="FastEndpoints" Version="7.0.1" />
|
||||
<PackageReference Include="FastEndpoints.Security" Version="7.0.1" />
|
||||
<PackageReference Include="FastEndpoints.Swagger" Version="7.0.1" />
|
||||
<PackageReference Include="Microsoft.AspNetCore.OpenApi" Version="8.0.19"/>
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="8.0.20" />
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="8.0.20">
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
</PackageReference>
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="8.0.20" />
|
||||
<PackageReference Include="PasswordGenerator" Version="2.1.0" />
|
||||
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.6.2"/>
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
6
BlogPlatform/BlogPlatform.http
Normal file
6
BlogPlatform/BlogPlatform.http
Normal file
@@ -0,0 +1,6 @@
|
||||
@BlogPlatform_HostAddress = http://localhost:5040
|
||||
|
||||
GET {{BlogPlatform_HostAddress}}/weatherforecast/
|
||||
Accept: application/json
|
||||
|
||||
###
|
30
BlogPlatform/BlogPlatformDbContext.cs
Normal file
30
BlogPlatform/BlogPlatformDbContext.cs
Normal file
@@ -0,0 +1,30 @@
|
||||
using BlogPlatform.Models;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace BlogPlatform;
|
||||
|
||||
public class BlogPlatformDbContext : DbContext
|
||||
{
|
||||
// Tables représentées par les entités
|
||||
public DbSet<Comment> Comments { get; set; } // Table des Commentaires
|
||||
public DbSet<Post> Posts { get; set; } // Table des publications
|
||||
public DbSet<User> Users { get; set; } // Table des utilisateurs
|
||||
|
||||
// Configuration de la connexion à la base de données
|
||||
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
|
||||
{
|
||||
string connectionString =
|
||||
"Server=romaric-thibault.fr;" + // Serveur SQL
|
||||
"Database=mathys_BlogPlatform;" + // Nom de la base
|
||||
"User Id=mathys;" + // Utilisateur
|
||||
"Password=Onto9-Cage-Afflicted;" + // Mot de passe
|
||||
"TrustServerCertificate=true;"; // Accepte certificat auto-signé
|
||||
|
||||
optionsBuilder.UseSqlServer(connectionString);
|
||||
}
|
||||
|
||||
// Personnalisation du modèle (non utilisée ici)
|
||||
protected override void OnModelCreating(ModelBuilder modelBuilder)
|
||||
{
|
||||
}
|
||||
}
|
16
BlogPlatform/Models/Comment.cs
Normal file
16
BlogPlatform/Models/Comment.cs
Normal file
@@ -0,0 +1,16 @@
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
|
||||
namespace BlogPlatform.Models;
|
||||
|
||||
public class Comment
|
||||
{
|
||||
[Key] public int Id { get; set; }
|
||||
[Required, Length(1, 500)] public string? Content { get; set; }
|
||||
[Required] public DateOnly CreatedAt { get; set; }
|
||||
|
||||
public Post? Post { get; set; }
|
||||
[Required] public int PostId { get; set; }
|
||||
|
||||
public User? User { get; set; }
|
||||
[Required] public int UserId { get; set; }
|
||||
}
|
17
BlogPlatform/Models/Post.cs
Normal file
17
BlogPlatform/Models/Post.cs
Normal file
@@ -0,0 +1,17 @@
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
|
||||
namespace BlogPlatform.Models;
|
||||
|
||||
public class Post
|
||||
{
|
||||
[Key] public int Id { get; set; }
|
||||
[Required, Length(1, 200)] public string? Title { get; set; }
|
||||
[Required] public string? Content { get; set; }
|
||||
[Required] public int Likes { get; set; }
|
||||
[Required] public DateOnly CreatedAt { get; set; }
|
||||
|
||||
public User? User { get; set; }
|
||||
[Required] public int UserId { get; set; }
|
||||
|
||||
public List<Comment>? Comments { get; set; }
|
||||
}
|
16
BlogPlatform/Models/User.cs
Normal file
16
BlogPlatform/Models/User.cs
Normal file
@@ -0,0 +1,16 @@
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
|
||||
namespace BlogPlatform.Models;
|
||||
|
||||
public class User
|
||||
{
|
||||
[Key] public int Id { get; set; }
|
||||
[Required, Length(3, 20)] public string? Username { get; set; }
|
||||
[Required, Length(3, 50)] public string? Email { get; set; }
|
||||
[Required, Length(60, 60)] public string? Password { get; set; }
|
||||
[Required, Length(24, 24)] public string? Salt { get; set; }
|
||||
[Required] public DateOnly CreatedAt { get; set; }
|
||||
|
||||
public List<Comment>? Comments { get; set; }
|
||||
public List<Post>? Posts { get; set; }
|
||||
}
|
27
BlogPlatform/Program.cs
Normal file
27
BlogPlatform/Program.cs
Normal file
@@ -0,0 +1,27 @@
|
||||
using BlogPlatform;
|
||||
using FastEndpoints;
|
||||
using FastEndpoints.Swagger;
|
||||
using FastEndpoints.Security;
|
||||
|
||||
WebApplicationBuilder builder = WebApplication.CreateBuilder(args);
|
||||
|
||||
// On ajoute ici FastEndpoints, un framework REPR et Swagger aux services disponibles dans le projet
|
||||
builder.Services
|
||||
.AddAuthenticationJwtBearer(s => s.SigningKey = "ThisIsASuperSecretJwtKeyThatIsAtLeast32CharsLong")
|
||||
.AddAuthorization()
|
||||
.AddFastEndpoints()
|
||||
.SwaggerDocument();
|
||||
|
||||
// On ajoute ici la configuration de la base de données
|
||||
builder.Services.AddDbContext<BlogPlatformDbContext>();
|
||||
|
||||
// On construit l'application en lui donnant vie
|
||||
WebApplication app = builder.Build();
|
||||
app.UseAuthentication()
|
||||
.UseAuthorization()
|
||||
.UseFastEndpoints()
|
||||
.UseSwaggerGen();
|
||||
|
||||
app.UseHttpsRedirection();
|
||||
|
||||
app.Run();
|
41
BlogPlatform/Properties/launchSettings.json
Normal file
41
BlogPlatform/Properties/launchSettings.json
Normal file
@@ -0,0 +1,41 @@
|
||||
{
|
||||
"$schema": "http://json.schemastore.org/launchsettings.json",
|
||||
"iisSettings": {
|
||||
"windowsAuthentication": false,
|
||||
"anonymousAuthentication": true,
|
||||
"iisExpress": {
|
||||
"applicationUrl": "http://localhost:60181",
|
||||
"sslPort": 44311
|
||||
}
|
||||
},
|
||||
"profiles": {
|
||||
"http": {
|
||||
"commandName": "Project",
|
||||
"dotnetRunMessages": true,
|
||||
"launchBrowser": true,
|
||||
"launchUrl": "swagger",
|
||||
"applicationUrl": "http://localhost:5040",
|
||||
"environmentVariables": {
|
||||
"ASPNETCORE_ENVIRONMENT": "Development"
|
||||
}
|
||||
},
|
||||
"https": {
|
||||
"commandName": "Project",
|
||||
"dotnetRunMessages": true,
|
||||
"launchBrowser": true,
|
||||
"launchUrl": "swagger",
|
||||
"applicationUrl": "https://localhost:7275;http://localhost:5040",
|
||||
"environmentVariables": {
|
||||
"ASPNETCORE_ENVIRONMENT": "Development"
|
||||
}
|
||||
},
|
||||
"IIS Express": {
|
||||
"commandName": "IISExpress",
|
||||
"launchBrowser": true,
|
||||
"launchUrl": "swagger",
|
||||
"environmentVariables": {
|
||||
"ASPNETCORE_ENVIRONMENT": "Development"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
8
BlogPlatform/appsettings.Development.json
Normal file
8
BlogPlatform/appsettings.Development.json
Normal file
@@ -0,0 +1,8 @@
|
||||
{
|
||||
"Logging": {
|
||||
"LogLevel": {
|
||||
"Default": "Information",
|
||||
"Microsoft.AspNetCore": "Warning"
|
||||
}
|
||||
}
|
||||
}
|
9
BlogPlatform/appsettings.json
Normal file
9
BlogPlatform/appsettings.json
Normal file
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"Logging": {
|
||||
"LogLevel": {
|
||||
"Default": "Information",
|
||||
"Microsoft.AspNetCore": "Warning"
|
||||
}
|
||||
},
|
||||
"AllowedHosts": "*"
|
||||
}
|
Reference in New Issue
Block a user