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,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,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,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,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,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,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; }
|
||||
}
|
Binary file not shown.
@ -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,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,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,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…
Reference in new issue