Fusion API + EF + MAPPing + Ser 🚧

testTony
Tony Fages 1 year ago
parent ff24423c0f
commit 36da6f99c1

@ -0,0 +1,13 @@
# Default ignored files
/shelf/
/workspace.xml
# Rider ignored files
/.idea.Verax_API_EF.iml
/contentModel.xml
/projectSettingsUpdater.xml
/modules.xml
# Editor-based HTTP Client requests
/httpRequests/
# Datasource local storage ignored files
/dataSources/
/dataSources.local.xml

@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="UserContentModel">
<attachedFolders />
<explicitIncludes />
<explicitExcludes />
</component>
</project>

@ -0,0 +1,15 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<RootNamespace>DbDataManager</RootNamespace>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\API_Services\API_Services.csproj" />
<ProjectReference Include="..\Web_API\Web_API.csproj" />
</ItemGroup>
</Project>

@ -0,0 +1,94 @@
using API_Services;
using DbContextLib;
using Web_API.Mapper;
using Web_API.Model;
namespace DbDataManager;
public class DbDataManager : IArticleService, IFormulaireService, IUserService
{
private readonly LibraryContext _context;
private Mapper map = new Mapper();
public DbDataManager(LibraryContext context)
{
_context = context;
}
public Task<ArticleDTO> CreateArticle(ArticleDTO a)
{
throw new NotImplementedException();
}
public Task<ArticleDTO?> DeleteArticle(long id)
{
throw new NotImplementedException();
}
public Task<bool> UpdateArticle(long id, ArticleDTO a)
{
throw new NotImplementedException();
}
public Task<ArticleDTO> GetArticleById(int id)
{
var article = _context.ArticleSet.Find(id);
return Task.FromResult(map.ArtEntityToDTO(article));
}
public Task<List<ArticleDTO>> GetAllArticles()
{
var articles = _context.ArticleSet.ToList();
return Task.FromResult(map.ArtEntityToDTO(articles));
}
public Task<List<FormulaireDTO>> GetAllForm()
{
throw new NotImplementedException();
}
public Task<FormulaireDTO?> GetById(long id)
{
throw new NotImplementedException();
}
public Task<FormulaireDTO> CreateForm(Formulaire formulaire)
{
throw new NotImplementedException();
}
public Task<bool> DeleteForm(long id)
{
throw new NotImplementedException();
}
public Task<bool> UpdateForm(long id, Formulaire formulaire)
{
throw new NotImplementedException();
}
public Task<bool> Create(User user)
{
throw new NotImplementedException();
}
public Task<bool> Update(User user)
{
throw new NotImplementedException();
}
public Task<bool> Delete(string pseudo)
{
throw new NotImplementedException();
}
public Task<User> GetByPseudo(string pseudo)
{
throw new NotImplementedException();
}
public Task<List<UserDTO>> GetAll()
{
throw new NotImplementedException();
}
}

@ -0,0 +1,14 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\API_Model\API_Model.csproj" />
<ProjectReference Include="..\Model\Model.csproj" />
</ItemGroup>
</Project>

@ -0,0 +1,27 @@
using Model;
using Web_API.Model;
namespace API_Mapping;
public static class ArticleMapper
{
public static ArticleDTO ToDTO(this Article a) => new()
{
Id = a.Id,
Title = a.Title,
Description = a.Description,
DatePublished = a.DatePublished,
LectureTime = a.LectureTime,
Author = a.Author
};
public static Article ToModel(this ArticleDTO a) => new()
{
Id = a.Id,
Title = a.Title,
Description = a.Description,
DatePublished = a.DatePublished,
LectureTime = a.LectureTime,
Author = a.Author
};
}

@ -0,0 +1,25 @@
using Model;
using Web_API.Model;
namespace API_Mapping;
public static class FormulaireMapping
{
public static FormulaireDTO ToDTO(this Formulaire f) => new()
{
Id = f.Id,
Theme = f.Theme,
Date = f.Date,
Lien = f.Lien,
Pseudo = f.Pseudo
};
public static Formulaire ToModel(this FormulaireDTO f) => new()
{
Id = f.Id,
Theme = f.Theme,
Date = f.Date,
Lien = f.Lien,
Pseudo = f.Pseudo
};
}

@ -0,0 +1,27 @@
using Model;
using Web_API.Model;
namespace API_Mapping;
public static class UserMapping
{
public static UserDTO ToDTO(this User u) => new()
{
Pseudo = u.Pseudo,
Mdp = u.Mdp,
Nom = u.Nom,
Prenom = u.Prenom,
Mail = u.Mail,
Role = u.Role
};
public static User ToModel(this UserDTO u) => new()
{
Pseudo = u.Pseudo,
Mdp = u.Mdp,
Nom = u.Nom,
Prenom = u.Prenom,
Mail = u.Mail,
Role = u.Role
};
}

@ -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,12 @@
namespace Web_API.Model;
public class ArticleDTO
{
public long Id { get; set; }
public string Title { get; set; } = string.Empty;
public string Description { get; set; } = string.Empty;
public string DatePublished { get; set; } = string.Empty;
public int LectureTime { get; set; }
public string Author { get; set; } = string.Empty;
}

@ -0,0 +1,12 @@
namespace Web_API.Model;
public class FormulaireDTO
{
public long Id;
public string Theme { get; set; }
public DateTime Date { get; set; }
public string Lien { get; set; }
public string Pseudo { get; set; }
}

@ -0,0 +1,11 @@
namespace Web_API.Model;
public class UserDTO
{
public string Pseudo { get; set; }
public string Mdp { get; set; }
public string Nom { get; set; }
public string Prenom { get; set; }
public string Mail { get; set; }
public string Role { get; set; }
}

@ -0,0 +1,13 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\Web_API\Web_API.csproj" />
</ItemGroup>
</Project>

@ -0,0 +1,19 @@
using Entities;
using Web_API.Model;
namespace API_Services
{
public interface IArticleService
{
Task<ArticleDTO> CreateArticle(ArticleDTO a);
Task<ArticleDTO?> DeleteArticle(long id);
Task<bool> UpdateArticle(long id, ArticleDTO a);
Task<ArticleDTO> GetArticleById(int id);
Task<List<ArticleDTO>> GetAllArticles();
}
}

@ -0,0 +1,18 @@
using Web_API.Model;
namespace API_Services;
public interface IFormulaireService
{
Task<List<FormulaireDTO>> GetAllForm();
Task<FormulaireDTO?> GetById(long id);
Task<FormulaireDTO> CreateForm(Formulaire formulaire);
Task<bool> DeleteForm(long id);
Task<bool> UpdateForm(long id, Formulaire formulaire);
}

@ -0,0 +1,20 @@
using Web_API.Model;
namespace API_Services
{
public interface IUserService
{
Task<bool> Create(User user);
Task<bool> Update(User user);
Task<bool> Delete(string pseudo);
Task<User> GetByPseudo(string pseudo);
Task<List<UserDTO>> GetAll();
}
}

@ -0,0 +1,23 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="8.0.2" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="8.0.2" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite.Core" Version="8.0.2" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="8.0.2">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Entities\Entities.csproj" />
</ItemGroup>
</Project>

@ -0,0 +1,36 @@
using Entities;
using Microsoft.EntityFrameworkCore;
namespace DbContextLib;
public class LibraryContext : DbContext
{
public LibraryContext()
: base()
{ }
public LibraryContext(DbContextOptions<LibraryContext> options)
: base(options)
{ }
public DbSet<ArticleEntity> ArticleSet { get; set; }
public DbSet<UserEntity> UserSet { get; set; }
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
if (!optionsBuilder.IsConfigured)
{
optionsBuilder.UseSqlite($"Data Source=Entity_FrameWork.Article.db");
}
}
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
base.OnModelCreating(modelBuilder);
modelBuilder.Entity<ArticleEntity>()
.HasMany(a => a.Users)
.WithMany(a => a.Articles)
.UsingEntity<ArticleUserEntity>();
}
}

@ -0,0 +1,14 @@
namespace Entities;
public class ArticleEntity
{
public long Id { get; set; }
public string Title { get; set; } = string.Empty;
public string Description { get; set; } = string.Empty;
public string DatePublished { get; set; } = string.Empty;
public int LectureTime { get; set; }
public string Author { get; set; } = string.Empty;
public ICollection<UserEntity> Users { get; } = new List<UserEntity>();
}

@ -0,0 +1,7 @@
namespace Entities;
public class ArticleUserEntity
{
public long UserEntityId { get; set; }
public long ArticleEntityId { get; set; }
}

@ -0,0 +1,19 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="8.0.2" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="8.0.2" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite.Core" Version="8.0.2" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="8.0.2">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
</ItemGroup>
</Project>

@ -0,0 +1,16 @@
namespace Entities;
public class FormEntity
{
public long Id { get; set; }
public string Theme { get; set; } = string.Empty;
public string DatePublication { get; set; } = string.Empty;
public string Link { get; set; } = string.Empty;
public string Pseudo { get; set; } = string.Empty;
public long UserEntityId { get; set; }
public UserEntity User { get; set; } = null;
}

@ -0,0 +1,21 @@
namespace Entities;
public class UserEntity
{
public long Id { get; set; }
public string Pseudo { get; set; } = string.Empty;
public string Mdp { get; set; } = string.Empty;
public string Nom { get; set; } = string.Empty;
public string Prenom { get; set; } = string.Empty;
public string Mail { get; set; } = string.Empty;
public string Role { get; set; } = string.Empty;
public ICollection<ArticleEntity> Articles { get; set; } = new List<ArticleEntity>();
public ICollection<FormEntity> Forms { get; set; } = new List<FormEntity>();
}

@ -0,0 +1,11 @@
namespace Model;
public class Article
{
public long Id { get; set; }
public string Title { get; set; } = string.Empty;
public string Description { get; set; } = string.Empty;
public string DatePublished { get; set; } = string.Empty;
public int LectureTime { get; set; }
public string Author { get; set; } = string.Empty;
}

@ -0,0 +1,10 @@
namespace Model;
public class Formulaire
{
public long Id;
public string Theme { get; set; }
public DateTime Date { get; set; }
public string Lien { get; set; }
public string Pseudo { get; set; }
}

@ -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,11 @@
namespace Model;
public class User
{
public string Pseudo { get; set; }
public string Mdp { get; set; }
public string Nom { get; set; }
public string Prenom { get; set; }
public string Mail { get; set; }
public string Role { get; set; }
}

@ -0,0 +1,89 @@
using DbContextLib;
using Entities;
using Microsoft.EntityFrameworkCore;
namespace StubbedContextLib;
public class StubbedContext : LibraryContext
{
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
base.OnModelCreating(modelBuilder);
modelBuilder.Entity<ArticleEntity>().HasData(
new ArticleEntity
{
Id = 1,
Title = "Breaking News Elisabeth 2 Died",
Description = "The queen of England died today at the age of 95",
DatePublished = "2022-02-06",
LectureTime = 2,
Author = "Tom Smith"
},
new ArticleEntity
{
Id = 2,
Title = "The new iPhone 15",
Description = "The new iPhone 15 is out and it's the best phone ever",
DatePublished = "2022-02-06",
LectureTime = 3,
Author = "Tom Smith"
},
new ArticleEntity
{
Id = 3,
Title = "M&M's new recipe",
Description = "M&M's new recipe is out and it's the best chocolate ever",
DatePublished = "2022-02-06",
LectureTime = 1,
Author = "M&M's Red"
}
);
modelBuilder.Entity<UserEntity>().HasData(
new UserEntity
{
Id = 1, Nom = "Fages", Prenom = "Tony", Pseudo = "TonyF", Mail = "tony@gmail.com", Mdp = "1234", Role = "Admin"
},
new UserEntity
{
Id = 2, Nom = "Smith", Prenom = "Tom", Pseudo = "TomS", Mail = "tom@mail.com", Mdp = "1234",
Role = "User"
},
new UserEntity
{
Id = 3, Nom = "M&M's", Prenom = "Red", Pseudo = "RedM", Mail = "M&M#mail.com", Mdp = "1234", Role = "Modérator"
}
);
modelBuilder.Entity<ArticleUserEntity>().HasData(
new ArticleUserEntity
{
ArticleEntityId = 1,
UserEntityId = 1
},
new ArticleUserEntity
{
ArticleEntityId = 2,
UserEntityId = 2
},
new ArticleUserEntity
{
ArticleEntityId = 3,
UserEntityId = 3
},
new ArticleUserEntity
{
ArticleEntityId = 3,
UserEntityId = 1
},
new ArticleUserEntity
{
ArticleEntityId = 2,
UserEntityId = 3
}
);
}
}

@ -0,0 +1,255 @@
// <auto-generated />
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Migrations;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
using StubbedContextLib;
#nullable disable
namespace StubbedContextLib.Migrations
{
[DbContext(typeof(StubbedContext))]
[Migration("20240305073325_mrg1")]
partial class mrg1
{
/// <inheritdoc />
protected override void BuildTargetModel(ModelBuilder modelBuilder)
{
#pragma warning disable 612, 618
modelBuilder.HasAnnotation("ProductVersion", "8.0.2");
modelBuilder.Entity("Entities.ArticleEntity", b =>
{
b.Property<long>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("INTEGER");
b.Property<string>("Author")
.IsRequired()
.HasColumnType("TEXT");
b.Property<string>("DatePublished")
.IsRequired()
.HasColumnType("TEXT");
b.Property<string>("Description")
.IsRequired()
.HasColumnType("TEXT");
b.Property<int>("LectureTime")
.HasColumnType("INTEGER");
b.Property<string>("Title")
.IsRequired()
.HasColumnType("TEXT");
b.HasKey("Id");
b.ToTable("ArticleSet");
b.HasData(
new
{
Id = 1L,
Author = "Tom Smith",
DatePublished = "2022-02-06",
Description = "The queen of England died today at the age of 95",
LectureTime = 2,
Title = "Breaking News Elisabeth 2 Died"
},
new
{
Id = 2L,
Author = "Tom Smith",
DatePublished = "2022-02-06",
Description = "The new iPhone 15 is out and it's the best phone ever",
LectureTime = 3,
Title = "The new iPhone 15"
},
new
{
Id = 3L,
Author = "M&M's Red",
DatePublished = "2022-02-06",
Description = "M&M's new recipe is out and it's the best chocolate ever",
LectureTime = 1,
Title = "M&M's new recipe"
});
});
modelBuilder.Entity("Entities.ArticleUserEntity", b =>
{
b.Property<long>("ArticleEntityId")
.HasColumnType("INTEGER");
b.Property<long>("UserEntityId")
.HasColumnType("INTEGER");
b.HasKey("ArticleEntityId", "UserEntityId");
b.HasIndex("UserEntityId");
b.ToTable("ArticleUserEntity");
b.HasData(
new
{
ArticleEntityId = 1L,
UserEntityId = 1L
},
new
{
ArticleEntityId = 2L,
UserEntityId = 2L
},
new
{
ArticleEntityId = 3L,
UserEntityId = 3L
},
new
{
ArticleEntityId = 3L,
UserEntityId = 1L
},
new
{
ArticleEntityId = 2L,
UserEntityId = 3L
});
});
modelBuilder.Entity("Entities.FormEntity", b =>
{
b.Property<long>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("INTEGER");
b.Property<string>("DatePublication")
.IsRequired()
.HasColumnType("TEXT");
b.Property<string>("Link")
.IsRequired()
.HasColumnType("TEXT");
b.Property<string>("Pseudo")
.IsRequired()
.HasColumnType("TEXT");
b.Property<string>("Theme")
.IsRequired()
.HasColumnType("TEXT");
b.Property<long>("UserEntityId")
.HasColumnType("INTEGER");
b.HasKey("Id");
b.HasIndex("UserEntityId");
b.ToTable("FormEntity");
});
modelBuilder.Entity("Entities.UserEntity", b =>
{
b.Property<long>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("INTEGER");
b.Property<string>("Mail")
.IsRequired()
.HasColumnType("TEXT");
b.Property<string>("Mdp")
.IsRequired()
.HasColumnType("TEXT");
b.Property<string>("Nom")
.IsRequired()
.HasColumnType("TEXT");
b.Property<string>("Prenom")
.IsRequired()
.HasColumnType("TEXT");
b.Property<string>("Pseudo")
.IsRequired()
.HasColumnType("TEXT");
b.Property<string>("Role")
.IsRequired()
.HasColumnType("TEXT");
b.HasKey("Id");
b.ToTable("UserSet");
b.HasData(
new
{
Id = 1L,
Mail = "tony@gmail.com",
Mdp = "1234",
Nom = "Fages",
Prenom = "Tony",
Pseudo = "TonyF",
Role = "Admin"
},
new
{
Id = 2L,
Mail = "tom@mail.com",
Mdp = "1234",
Nom = "Smith",
Prenom = "Tom",
Pseudo = "TomS",
Role = "User"
},
new
{
Id = 3L,
Mail = "M&M#mail.com",
Mdp = "1234",
Nom = "M&M's",
Prenom = "Red",
Pseudo = "RedM",
Role = "Modérator"
});
});
modelBuilder.Entity("Entities.ArticleUserEntity", b =>
{
b.HasOne("Entities.ArticleEntity", null)
.WithMany()
.HasForeignKey("ArticleEntityId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("Entities.UserEntity", null)
.WithMany()
.HasForeignKey("UserEntityId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
});
modelBuilder.Entity("Entities.FormEntity", b =>
{
b.HasOne("Entities.UserEntity", "User")
.WithMany("Forms")
.HasForeignKey("UserEntityId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("User");
});
modelBuilder.Entity("Entities.UserEntity", b =>
{
b.Navigation("Forms");
});
#pragma warning restore 612, 618
}
}
}

@ -0,0 +1,156 @@
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
#pragma warning disable CA1814 // Prefer jagged arrays over multidimensional
namespace StubbedContextLib.Migrations
{
/// <inheritdoc />
public partial class mrg1 : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.CreateTable(
name: "ArticleSet",
columns: table => new
{
Id = table.Column<long>(type: "INTEGER", nullable: false)
.Annotation("Sqlite:Autoincrement", true),
Title = table.Column<string>(type: "TEXT", nullable: false),
Description = table.Column<string>(type: "TEXT", nullable: false),
DatePublished = table.Column<string>(type: "TEXT", nullable: false),
LectureTime = table.Column<int>(type: "INTEGER", nullable: false),
Author = table.Column<string>(type: "TEXT", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_ArticleSet", x => x.Id);
});
migrationBuilder.CreateTable(
name: "UserSet",
columns: table => new
{
Id = table.Column<long>(type: "INTEGER", nullable: false)
.Annotation("Sqlite:Autoincrement", true),
Pseudo = table.Column<string>(type: "TEXT", nullable: false),
Mdp = table.Column<string>(type: "TEXT", nullable: false),
Nom = table.Column<string>(type: "TEXT", nullable: false),
Prenom = table.Column<string>(type: "TEXT", nullable: false),
Mail = table.Column<string>(type: "TEXT", nullable: false),
Role = table.Column<string>(type: "TEXT", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_UserSet", x => x.Id);
});
migrationBuilder.CreateTable(
name: "ArticleUserEntity",
columns: table => new
{
UserEntityId = table.Column<long>(type: "INTEGER", nullable: false),
ArticleEntityId = table.Column<long>(type: "INTEGER", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_ArticleUserEntity", x => new { x.ArticleEntityId, x.UserEntityId });
table.ForeignKey(
name: "FK_ArticleUserEntity_ArticleSet_ArticleEntityId",
column: x => x.ArticleEntityId,
principalTable: "ArticleSet",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
table.ForeignKey(
name: "FK_ArticleUserEntity_UserSet_UserEntityId",
column: x => x.UserEntityId,
principalTable: "UserSet",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateTable(
name: "FormEntity",
columns: table => new
{
Id = table.Column<long>(type: "INTEGER", nullable: false)
.Annotation("Sqlite:Autoincrement", true),
Theme = table.Column<string>(type: "TEXT", nullable: false),
DatePublication = table.Column<string>(type: "TEXT", nullable: false),
Link = table.Column<string>(type: "TEXT", nullable: false),
Pseudo = table.Column<string>(type: "TEXT", nullable: false),
UserEntityId = table.Column<long>(type: "INTEGER", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_FormEntity", x => x.Id);
table.ForeignKey(
name: "FK_FormEntity_UserSet_UserEntityId",
column: x => x.UserEntityId,
principalTable: "UserSet",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.InsertData(
table: "ArticleSet",
columns: new[] { "Id", "Author", "DatePublished", "Description", "LectureTime", "Title" },
values: new object[,]
{
{ 1L, "Tom Smith", "2022-02-06", "The queen of England died today at the age of 95", 2, "Breaking News Elisabeth 2 Died" },
{ 2L, "Tom Smith", "2022-02-06", "The new iPhone 15 is out and it's the best phone ever", 3, "The new iPhone 15" },
{ 3L, "M&M's Red", "2022-02-06", "M&M's new recipe is out and it's the best chocolate ever", 1, "M&M's new recipe" }
});
migrationBuilder.InsertData(
table: "UserSet",
columns: new[] { "Id", "Mail", "Mdp", "Nom", "Prenom", "Pseudo", "Role" },
values: new object[,]
{
{ 1L, "tony@gmail.com", "1234", "Fages", "Tony", "TonyF", "Admin" },
{ 2L, "tom@mail.com", "1234", "Smith", "Tom", "TomS", "User" },
{ 3L, "M&M#mail.com", "1234", "M&M's", "Red", "RedM", "Modérator" }
});
migrationBuilder.InsertData(
table: "ArticleUserEntity",
columns: new[] { "ArticleEntityId", "UserEntityId" },
values: new object[,]
{
{ 1L, 1L },
{ 2L, 2L },
{ 2L, 3L },
{ 3L, 1L },
{ 3L, 3L }
});
migrationBuilder.CreateIndex(
name: "IX_ArticleUserEntity_UserEntityId",
table: "ArticleUserEntity",
column: "UserEntityId");
migrationBuilder.CreateIndex(
name: "IX_FormEntity_UserEntityId",
table: "FormEntity",
column: "UserEntityId");
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropTable(
name: "ArticleUserEntity");
migrationBuilder.DropTable(
name: "FormEntity");
migrationBuilder.DropTable(
name: "ArticleSet");
migrationBuilder.DropTable(
name: "UserSet");
}
}
}

@ -0,0 +1,252 @@
// <auto-generated />
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
using StubbedContextLib;
#nullable disable
namespace StubbedContextLib.Migrations
{
[DbContext(typeof(StubbedContext))]
partial class StubbedContextModelSnapshot : ModelSnapshot
{
protected override void BuildModel(ModelBuilder modelBuilder)
{
#pragma warning disable 612, 618
modelBuilder.HasAnnotation("ProductVersion", "8.0.2");
modelBuilder.Entity("Entities.ArticleEntity", b =>
{
b.Property<long>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("INTEGER");
b.Property<string>("Author")
.IsRequired()
.HasColumnType("TEXT");
b.Property<string>("DatePublished")
.IsRequired()
.HasColumnType("TEXT");
b.Property<string>("Description")
.IsRequired()
.HasColumnType("TEXT");
b.Property<int>("LectureTime")
.HasColumnType("INTEGER");
b.Property<string>("Title")
.IsRequired()
.HasColumnType("TEXT");
b.HasKey("Id");
b.ToTable("ArticleSet");
b.HasData(
new
{
Id = 1L,
Author = "Tom Smith",
DatePublished = "2022-02-06",
Description = "The queen of England died today at the age of 95",
LectureTime = 2,
Title = "Breaking News Elisabeth 2 Died"
},
new
{
Id = 2L,
Author = "Tom Smith",
DatePublished = "2022-02-06",
Description = "The new iPhone 15 is out and it's the best phone ever",
LectureTime = 3,
Title = "The new iPhone 15"
},
new
{
Id = 3L,
Author = "M&M's Red",
DatePublished = "2022-02-06",
Description = "M&M's new recipe is out and it's the best chocolate ever",
LectureTime = 1,
Title = "M&M's new recipe"
});
});
modelBuilder.Entity("Entities.ArticleUserEntity", b =>
{
b.Property<long>("ArticleEntityId")
.HasColumnType("INTEGER");
b.Property<long>("UserEntityId")
.HasColumnType("INTEGER");
b.HasKey("ArticleEntityId", "UserEntityId");
b.HasIndex("UserEntityId");
b.ToTable("ArticleUserEntity");
b.HasData(
new
{
ArticleEntityId = 1L,
UserEntityId = 1L
},
new
{
ArticleEntityId = 2L,
UserEntityId = 2L
},
new
{
ArticleEntityId = 3L,
UserEntityId = 3L
},
new
{
ArticleEntityId = 3L,
UserEntityId = 1L
},
new
{
ArticleEntityId = 2L,
UserEntityId = 3L
});
});
modelBuilder.Entity("Entities.FormEntity", b =>
{
b.Property<long>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("INTEGER");
b.Property<string>("DatePublication")
.IsRequired()
.HasColumnType("TEXT");
b.Property<string>("Link")
.IsRequired()
.HasColumnType("TEXT");
b.Property<string>("Pseudo")
.IsRequired()
.HasColumnType("TEXT");
b.Property<string>("Theme")
.IsRequired()
.HasColumnType("TEXT");
b.Property<long>("UserEntityId")
.HasColumnType("INTEGER");
b.HasKey("Id");
b.HasIndex("UserEntityId");
b.ToTable("FormEntity");
});
modelBuilder.Entity("Entities.UserEntity", b =>
{
b.Property<long>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("INTEGER");
b.Property<string>("Mail")
.IsRequired()
.HasColumnType("TEXT");
b.Property<string>("Mdp")
.IsRequired()
.HasColumnType("TEXT");
b.Property<string>("Nom")
.IsRequired()
.HasColumnType("TEXT");
b.Property<string>("Prenom")
.IsRequired()
.HasColumnType("TEXT");
b.Property<string>("Pseudo")
.IsRequired()
.HasColumnType("TEXT");
b.Property<string>("Role")
.IsRequired()
.HasColumnType("TEXT");
b.HasKey("Id");
b.ToTable("UserSet");
b.HasData(
new
{
Id = 1L,
Mail = "tony@gmail.com",
Mdp = "1234",
Nom = "Fages",
Prenom = "Tony",
Pseudo = "TonyF",
Role = "Admin"
},
new
{
Id = 2L,
Mail = "tom@mail.com",
Mdp = "1234",
Nom = "Smith",
Prenom = "Tom",
Pseudo = "TomS",
Role = "User"
},
new
{
Id = 3L,
Mail = "M&M#mail.com",
Mdp = "1234",
Nom = "M&M's",
Prenom = "Red",
Pseudo = "RedM",
Role = "Modérator"
});
});
modelBuilder.Entity("Entities.ArticleUserEntity", b =>
{
b.HasOne("Entities.ArticleEntity", null)
.WithMany()
.HasForeignKey("ArticleEntityId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("Entities.UserEntity", null)
.WithMany()
.HasForeignKey("UserEntityId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
});
modelBuilder.Entity("Entities.FormEntity", b =>
{
b.HasOne("Entities.UserEntity", "User")
.WithMany("Forms")
.HasForeignKey("UserEntityId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("User");
});
modelBuilder.Entity("Entities.UserEntity", b =>
{
b.Navigation("Forms");
});
#pragma warning restore 612, 618
}
}
}

@ -0,0 +1,23 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\DbContextLib\DbContextLib.csproj" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="8.0.2" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="8.0.2" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite.Core" Version="8.0.2" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="8.0.2">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
</ItemGroup>
</Project>

@ -0,0 +1,83 @@
// See https://aka.ms/new-console-template for more information
using DbContextLib;
using Entities;
addArticle();
listArticle();
// Allows to list all the articles from the db
void listArticle()
{
using (var context = new LibraryContext())
{
var articles = context.ArticleSet;
foreach (var article in articles)
{
Console.WriteLine($"{article.Author} - {article.Title} - {article.Description} - {article.DatePublished} - {article.LectureTime}");
}
}
}
// Allows to list all the articles from the db by author
void listArticleByAuthor()
{
using (var context = new LibraryContext())
{
var articles = context.ArticleSet.Where(a => a.Author.Equals("Tony Fages"));
foreach (var article in articles)
{
Console.WriteLine($"{article.Author} - {article.Title} - {article.Description} - {article.DatePublished} - {article.LectureTime}");
}
}
}
// Allows to add an article to the db
void addArticle()
{
using (var context = new LibraryContext())
{
var article = new ArticleEntity
{
Title = "Louis is not sick anymore",
Description = "Louis is not sick anymore, he is now healthy and happy",
DatePublished = "16-02-2024",
LectureTime = 1,
Author = "Tony Fages"
};
context.ArticleSet.Add(article);
context.SaveChanges();
}
}
// Allows to modify an article from the db
void modifyArticle()
{
using (var context = new LibraryContext())
{
var article = context.ArticleSet.Where(a => a.Author.Equals("Tom Smith"));
foreach (var articles in article)
{
articles.Title = "Demain des l'aube";
context.SaveChanges();
}
}
}
// Allows to delete an article from the db
void deleteArticle()
{
using (var context = new LibraryContext())
{
var article = context.ArticleSet.Where(a => a.Author.Equals("M&M's Red"));
foreach (var articles in article)
{
context.ArticleSet.Remove(articles);
context.SaveChanges();
}
}
}

@ -0,0 +1,26 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<StartWorkingDirectory>$(MSBuildProjectDirectory)</StartWorkingDirectory>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="8.0.2" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="8.0.2" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite.Core" Version="8.0.2" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="8.0.2">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\DbContextLib\DbContextLib.csproj" />
<ProjectReference Include="..\StubbedContextLib\StubbedContextLib.csproj" />
</ItemGroup>
</Project>

@ -0,0 +1,35 @@
using System.Reflection;
using System.Runtime.InteropServices;
// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("TestsUnitaires")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("TestsUnitaires")]
[assembly: AssemblyCopyright("Copyright © 2024")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)]
// The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly: Guid("FF8AFA55-12FE-4856-A0A1-21344D366E12")]
// Version information for an assembly consists of the following four values:
//
// Major Version
// Minor Version
// Build Number
// Revision
//
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]

@ -0,0 +1,14 @@
using System;
using Xunit;
namespace TestsUnitaires
{
public class Tests
{
[Fact]
public void Test1()
{
Assert.True(true);
}
}
}

@ -0,0 +1,66 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props"
Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')"/>
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{FF8AFA55-12FE-4856-A0A1-21344D366E12}</ProjectGuid>
<ProjectTypeGuids>{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>TestsUnitaires</RootNamespace>
<AssemblyName>TestsUnitaires</AssemblyName>
<TargetFrameworkVersion>v4.8</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="System"/>
<Reference Include="System.Core"/>
<Reference Include="System.Data"/>
<Reference Include="System.Xml"/>
<Reference Include="xunit.abstractions, Version=2.0.0.0, Culture=neutral, PublicKeyToken=8d05b1bb7a6fdb6c">
<HintPath>..\packages\xunit.abstractions.2.0.0\lib\net35\xunit.abstractions.dll</HintPath>
</Reference>
<Reference Include="xunit.assert, Version=2.1.0.3179, Culture=neutral, PublicKeyToken=8d05b1bb7a6fdb6c">
<HintPath>..\packages\xunit.assert.2.1.0\lib\dotnet\xunit.assert.dll</HintPath>
</Reference>
<Reference Include="xunit.core, Version=2.1.0.3179, Culture=neutral, PublicKeyToken=8d05b1bb7a6fdb6c">
<HintPath>..\packages\xunit.extensibility.core.2.1.0\lib\dotnet\xunit.core.dll</HintPath>
</Reference>
<Reference Include="xunit.execution.desktop, Version=2.1.0.3179, Culture=neutral, PublicKeyToken=8d05b1bb7a6fdb6c">
<HintPath>..\packages\xunit.extensibility.execution.2.1.0\lib\net45\xunit.execution.desktop.dll</HintPath>
</Reference>
</ItemGroup>
<ItemGroup>
<Compile Include="Tests.cs"/>
<Compile Include="Properties\AssemblyInfo.cs"/>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets"/>
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>
-->
</Project>

@ -0,0 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="xunit" version="2.1.0" targetFramework="net45" />
<package id="xunit.abstractions" version="2.0.0" targetFramework="net45" />
<package id="xunit.assert" version="2.1.0" targetFramework="net45" />
<package id="xunit.core" version="2.1.0" targetFramework="net45" />
<package id="xunit.extensibility.core" version="2.1.0" targetFramework="net45" />
<package id="xunit.extensibility.execution" version="2.1.0" targetFramework="net45" />
</packages>

@ -0,0 +1,70 @@

Microsoft Visual Studio Solution File, Format Version 12.00
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Test_Console_EF", "Test_Console_EF\Test_Console_EF.csproj", "{E27E2617-28A1-4675-B12B-89430582C05E}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Entities", "Entities\Entities.csproj", "{40BD34D7-3F07-410A-BC04-2A5B09E758C0}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DbContextLib", "DbContextLib\DbContextLib.csproj", "{F94BEE1F-302F-4654-8D85-AD41E0BACD03}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "StubbedContextLib", "StubbedContextLib\StubbedContextLib.csproj", "{F1B4BCE5-8DE7-4EFB-8BC1-D7E04EA75302}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Web_API", "Web_API\Web_API.csproj", "{852E0658-1A97-482A-84F3-0EF08E34D7B1}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "API_DbDataManager", "API_DbDataManager\API_DbDataManager.csproj", "{FBA0CF18-7488-4088-A7C5-5D2071D19CCB}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "API_Services", "API_Services\API_Services.csproj", "{4FB7D286-B583-44BC-BB79-4AE3058AFEDE}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "API_Model", "API_Model\API_Model.csproj", "{F09B566E-8D25-4D70-B9F0-99E6969D4D1F}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "API_Mapping", "API_Mapping\API_Mapping.csproj", "{BECFAD2C-E442-4300-8121-5AE6610B92DF}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Model", "Model\Model.csproj", "{96FDB5DE-6707-4856-94CD-EFAF0C7CEB4B}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{E27E2617-28A1-4675-B12B-89430582C05E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{E27E2617-28A1-4675-B12B-89430582C05E}.Debug|Any CPU.Build.0 = Debug|Any CPU
{E27E2617-28A1-4675-B12B-89430582C05E}.Release|Any CPU.ActiveCfg = Release|Any CPU
{E27E2617-28A1-4675-B12B-89430582C05E}.Release|Any CPU.Build.0 = Release|Any CPU
{40BD34D7-3F07-410A-BC04-2A5B09E758C0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{40BD34D7-3F07-410A-BC04-2A5B09E758C0}.Debug|Any CPU.Build.0 = Debug|Any CPU
{40BD34D7-3F07-410A-BC04-2A5B09E758C0}.Release|Any CPU.ActiveCfg = Release|Any CPU
{40BD34D7-3F07-410A-BC04-2A5B09E758C0}.Release|Any CPU.Build.0 = Release|Any CPU
{F94BEE1F-302F-4654-8D85-AD41E0BACD03}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{F94BEE1F-302F-4654-8D85-AD41E0BACD03}.Debug|Any CPU.Build.0 = Debug|Any CPU
{F94BEE1F-302F-4654-8D85-AD41E0BACD03}.Release|Any CPU.ActiveCfg = Release|Any CPU
{F94BEE1F-302F-4654-8D85-AD41E0BACD03}.Release|Any CPU.Build.0 = Release|Any CPU
{F1B4BCE5-8DE7-4EFB-8BC1-D7E04EA75302}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{F1B4BCE5-8DE7-4EFB-8BC1-D7E04EA75302}.Debug|Any CPU.Build.0 = Debug|Any CPU
{F1B4BCE5-8DE7-4EFB-8BC1-D7E04EA75302}.Release|Any CPU.ActiveCfg = Release|Any CPU
{F1B4BCE5-8DE7-4EFB-8BC1-D7E04EA75302}.Release|Any CPU.Build.0 = Release|Any CPU
{852E0658-1A97-482A-84F3-0EF08E34D7B1}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{852E0658-1A97-482A-84F3-0EF08E34D7B1}.Debug|Any CPU.Build.0 = Debug|Any CPU
{852E0658-1A97-482A-84F3-0EF08E34D7B1}.Release|Any CPU.ActiveCfg = Release|Any CPU
{852E0658-1A97-482A-84F3-0EF08E34D7B1}.Release|Any CPU.Build.0 = Release|Any CPU
{FBA0CF18-7488-4088-A7C5-5D2071D19CCB}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{FBA0CF18-7488-4088-A7C5-5D2071D19CCB}.Debug|Any CPU.Build.0 = Debug|Any CPU
{FBA0CF18-7488-4088-A7C5-5D2071D19CCB}.Release|Any CPU.ActiveCfg = Release|Any CPU
{FBA0CF18-7488-4088-A7C5-5D2071D19CCB}.Release|Any CPU.Build.0 = Release|Any CPU
{4FB7D286-B583-44BC-BB79-4AE3058AFEDE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{4FB7D286-B583-44BC-BB79-4AE3058AFEDE}.Debug|Any CPU.Build.0 = Debug|Any CPU
{4FB7D286-B583-44BC-BB79-4AE3058AFEDE}.Release|Any CPU.ActiveCfg = Release|Any CPU
{4FB7D286-B583-44BC-BB79-4AE3058AFEDE}.Release|Any CPU.Build.0 = Release|Any CPU
{F09B566E-8D25-4D70-B9F0-99E6969D4D1F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{F09B566E-8D25-4D70-B9F0-99E6969D4D1F}.Debug|Any CPU.Build.0 = Debug|Any CPU
{F09B566E-8D25-4D70-B9F0-99E6969D4D1F}.Release|Any CPU.ActiveCfg = Release|Any CPU
{F09B566E-8D25-4D70-B9F0-99E6969D4D1F}.Release|Any CPU.Build.0 = Release|Any CPU
{BECFAD2C-E442-4300-8121-5AE6610B92DF}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{BECFAD2C-E442-4300-8121-5AE6610B92DF}.Debug|Any CPU.Build.0 = Debug|Any CPU
{BECFAD2C-E442-4300-8121-5AE6610B92DF}.Release|Any CPU.ActiveCfg = Release|Any CPU
{BECFAD2C-E442-4300-8121-5AE6610B92DF}.Release|Any CPU.Build.0 = Release|Any CPU
{96FDB5DE-6707-4856-94CD-EFAF0C7CEB4B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{96FDB5DE-6707-4856-94CD-EFAF0C7CEB4B}.Debug|Any CPU.Build.0 = Debug|Any CPU
{96FDB5DE-6707-4856-94CD-EFAF0C7CEB4B}.Release|Any CPU.ActiveCfg = Release|Any CPU
{96FDB5DE-6707-4856-94CD-EFAF0C7CEB4B}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
EndGlobal

@ -0,0 +1,3 @@
 // See https://aka.ms/new-console-template for more information
Console.WriteLine("Hello, World!");

@ -0,0 +1,20 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="8.0.2" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="8.0.2" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite.Core" Version="8.0.2" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="8.0.2">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
</ItemGroup>
</Project>

@ -0,0 +1,68 @@
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Web_API.Model;
using API_Services;
namespace Web_API.Controllers
{
[Route("api/[controller]")]
[ApiController]
public class ArticleController : ControllerBase
{
private readonly IArticleService _as;
private Mapper.Mapper map = new Mapper.Mapper();
public ArticleController(IArticleService articleService)
{
this._as = articleService;
}
[HttpGet("Articles")]
public async Task<IActionResult> GetAllArticle()
{
return Ok(await _as.GetAllArticles());
}
[HttpGet("{id}")]
public async Task<IActionResult> GetArticle(int id)
{
var article = await _as.GetById(id);
if (article == null)
{
return NotFound();
}
return Ok(article);
}
[HttpPost]
public async Task<ActionResult<Article>> PostArticle(ArticleDTO article)
{
var newArticle = await _as.Create(article);
if (newArticle == null) return BadRequest();
var newArticleEnt = map.ArtDTOToEntity(article);
return CreatedAtAction(nameof(GetArticle), new { id = newArticle.Id}, newArticleEnt);
}
[HttpPut("{id}")]
public async Task<ActionResult<Article>> PutArticle(long id , [FromBody]ArticleDTO article)
{
var check = await _as.Update(id,article);
if (!check) return NotFound();
var articleEnt = map.ArtDTOToEntity(article);
return articleEnt;
}
[HttpDelete("{id}")]
public async Task<ActionResult<Article>> DeleteArticle(long id)
{
var articleDeleted = await _as.Delete(id);
if (articleDeleted == null)return NotFound();
articleDeleted = map.ArtEntityToDTO(articleDeleted);
return Ok(articleDeleted);
}
}
}

@ -0,0 +1,27 @@
using Microsoft.AspNetCore.Mvc;
using Web_API.Model;
using API_Services;
namespace Web_API.Controllers
{
[Route("api/[controller]")]
[ApiController]
public class FormulaireController : ControllerBase
{
private readonly IFormulaireService _form;
private Mapper.Mapper map = new Mapper.Mapper();
public FormulaireController(IFormulaireService iform)
{
this._form = iform;
}
[HttpGet]
public async Task<List<Formulaire>> GetAllForm()
{
var AllForms = await _form.GetAllForm();
return AllForms;
}
}
}

@ -0,0 +1,76 @@
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Web_API.Model;
using API_Services;
namespace Web_API.Controllers
{
[Route("api/[controller]")]
[ApiController]
public class UserController : ControllerBase
{
private readonly ILogger<User>? logger;
private readonly IUserService _us;
public UserController(IUserService us)
{
this._us = us;
}
[HttpGet]
public async Task<IActionResult> GetAll()
{
return Ok(await _us.GetAll());
}
// GET : users/id
[HttpGet("{pseudo}", Name = "GetUserByPseudo")]
public async Task<IActionResult> GetUser(string pseudo)
{
var user = _us.GetByPseudo(pseudo);
if (user == null)
{
return NotFound();
}
return Ok(user);
}
[HttpPost]
public async Task<ActionResult<User>> PostUser(User user)
{
var check = await _us.Create(user);
if (!check)
{
return BadRequest();
}
return CreatedAtAction(nameof(GetUser), new { Pseudo = user.Pseudo}, user);
}
[HttpDelete]
public async Task<IActionResult> DeleteUser(string pseudo)
{
var check = await _us.Delete(pseudo);
if (!check)
{
return NotFound();
}
return Ok(pseudo);
}
[HttpPut]
public async Task<IActionResult> UpdateUser(User user)
{
var check = await _us.Update(user);
if (!check)
{
return NotFound();
}
return Ok(user);
}
}
}

@ -0,0 +1,82 @@
using Entities;
using Web_API.Model;
namespace Web_API.Mapper;
public class Mapper
{
public ArticleDTO ArtEntityToDTO(ArticleEntity a)
{
return new ArticleDTO
{
Id = a.Id,
Author = a.Author,
Title = a.Title,
Description = a.Description,
LectureTime = a.LectureTime,
DatePublished = a.DatePublished
};
}
public ArticleEntity ArtDTOToEntity(ArticleDTO a)
{
return new ArticleEntity()
{
Id = a.Id,
Author = a.Author,
Title = a.Title,
Description = a.Description,
LectureTime = a.LectureTime,
DatePublished = a.DatePublished
};
}
public FormulaireDTO FormEntityToDTO(FormEntity f)
{
return new FormulaireDTO
{
Theme = f.Theme,
Date = f.DatePublication,
Lien = f.Lien,
Pseudo = f.Pseudo
};
}
public Formulaire FormDTOToEntity(FormulaireDTO f)
{
return new Formulaire
{
Theme = f.Theme,
Date = f.Date,
Lien = f.Lien,
Pseudo = f.Pseudo
};
}
public UserDTO UserEntityToDTO(User u)
{
return new UserDTO
{
Pseudo = u.Pseudo,
Mail = u.Mail,
Prenom = u.Prenom,
Nom = u.Nom,
Role = u.Role,
Mdp = u.Mdp
};
}
public User UserDTOToEntity(UserDTO u)
{
return new User
{
Pseudo = u.Pseudo,
Mail = u.Mail,
Prenom = u.Prenom,
Nom = u.Nom,
Role = u.Role,
Mdp = u.Mdp
};
}
}

@ -0,0 +1,44 @@
var builder = WebApplication.CreateBuilder(args);
// Add services to the container.
// 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();
var summaries = new[]
{
"Freezing", "Bracing", "Chilly", "Cool", "Mild", "Warm", "Balmy", "Hot", "Sweltering", "Scorching"
};
app.MapGet("/weatherforecast", () =>
{
var forecast = Enumerable.Range(1, 5).Select(index =>
new WeatherForecast
(
DateOnly.FromDateTime(DateTime.Now.AddDays(index)),
Random.Shared.Next(-20, 55),
summaries[Random.Shared.Next(summaries.Length)]
))
.ToArray();
return forecast;
})
.WithName("GetWeatherForecast")
.WithOpenApi();
app.Run();
record WeatherForecast(DateOnly Date, int TemperatureC, string? Summary)
{
public int TemperatureF => 32 + (int)(TemperatureC / 0.5556);
}

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

@ -0,0 +1,21 @@
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Identity.EntityFrameworkCore" Version="8.0.2" />
<PackageReference Include="Microsoft.AspNetCore.OpenApi" Version="8.0.2" />
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="8.0.2" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.5.0" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\API_Model\API_Model.csproj" />
<ProjectReference Include="..\DbContextLib\DbContextLib.csproj" />
</ItemGroup>
</Project>

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

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

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