finalisation des endpoints

This commit is contained in:
2025-11-13 15:11:12 +01:00
parent 55f92ad761
commit 5c12a45ae6
41 changed files with 79 additions and 258 deletions

View File

@@ -1,4 +1,4 @@
namespace PF3.DTO.Show.Request;
namespace PyroFetes.DTO.Show.Request;
public class CreateShowDto
{

View File

@@ -1,4 +1,4 @@
namespace PF3.DTO.Show.Request;
namespace PyroFetes.DTO.Show.Request;
public class IdShowDto
{

View File

@@ -1,4 +1,4 @@
namespace PF3.DTO.Show.Request;
namespace PyroFetes.DTO.Show.Request;
public class UpdateShowDto
{

View File

@@ -1,4 +1,4 @@
namespace PF3.DTO.Show.Response;
namespace PyroFetes.DTO.Show.Response;
public class ReadShowDto
{

View File

@@ -1,4 +1,4 @@
namespace PF3.DTO.SoundCategory.Request;
namespace PyroFetes.DTO.Sound.Request;
public class CreateSoundDto
{

View File

@@ -1,4 +1,4 @@
namespace PF3.DTO.SoundCategory.Request;
namespace PyroFetes.DTO.Sound.Request;
public class IdSoundto
{

View File

@@ -1,4 +1,4 @@
namespace PF3.DTO.SoundCategory.Request;
namespace PyroFetes.DTO.Sound.Request;
public class UpdateSoundDto
{

View File

@@ -1,4 +1,4 @@
namespace PF3.DTO.SoundCategory.Response;
namespace PyroFetes.DTO.Sound.Response;
public class ReadSoundDto
{

View File

@@ -1,4 +1,4 @@
namespace PF3.DTO.SoundCategory.Request;
namespace PyroFetes.DTO.SoundCategory.Request;
public class CreateSoundCategoryDto
{

View File

@@ -1,4 +1,4 @@
namespace PF3.DTO.SoundCategory.Request;
namespace PyroFetes.DTO.SoundCategory.Request;
public class IdSoundCategoryDto
{

View File

@@ -1,4 +1,4 @@
namespace PF3.DTO.SoundCategory.Request;
namespace PyroFetes.DTO.SoundCategory.Request;
public class UpdateSoundCategoryDto
{

View File

@@ -1,4 +1,4 @@
namespace PF3.DTO.SoundCategory.Response;
namespace PyroFetes.DTO.SoundCategory.Response;
public class ReadSoundCategoryDto
{

View File

@@ -1,4 +1,4 @@
namespace PF3.DTO.SoundTimecode.Request;
namespace PyroFetes.DTO.SoundTimecode.Request;
public class CreateSoundTimecodeDto
{

View File

@@ -1,4 +1,4 @@
namespace PF3.DTO.SoundTimecode.Request;
namespace PyroFetes.DTO.SoundTimecode.Request;
public class IdSoundTimecodeDto
{

View File

@@ -1,4 +1,4 @@
namespace PF3.DTO.SoundTimecode.Request;
namespace PyroFetes.DTO.SoundTimecode.Request;
public class UpdateSoundTimecodeDto
{

View File

@@ -1,4 +1,4 @@
namespace PF3.DTO.SoundTimecode.Response;
namespace PyroFetes.DTO.SoundTimecode.Response;
public class ReadSoundTimecodeDto
{

View File

@@ -1,4 +1,4 @@
namespace PF3.DTO.Staff.Request;
namespace PyroFetes.DTO.Staff.Request;
public class CreateStaffDto
{

View File

@@ -1,4 +1,4 @@
namespace PF3.DTO.Staff.Request;
namespace PyroFetes.DTO.Staff.Request;
public class IdStaffDto
{

View File

@@ -1,4 +1,4 @@
namespace PF3.DTO.Staff.Request;
namespace PyroFetes.DTO.Staff.Request;
public class UpdateStaffDto
{

View File

@@ -1,4 +1,4 @@
namespace PF3.DTO.Staff.Response;
namespace PyroFetes.DTO.Staff.Response;
public class ReadStaffDto
{

View File

@@ -1,10 +1,10 @@
namespace PF3.DTO.Truck.Request;
namespace PyroFetes.DTO.Truck.Request;
public class CreateTruckDto
{
public string? Type { get; set; }
public string? MaxExplosiveCapacity { get; set; }
public double? MaxExplosiveCapacity { get; set; }
public string? Sizes { get; set; }
public string? Statut { get; set; }
public string? Status { get; set; }
public int? ShowId { get; set; }
}

View File

@@ -1,4 +1,4 @@
namespace PF3.DTO.Truck.Request;
namespace PyroFetes.DTO.Truck.Request;
public class IdTruckDto
{

View File

@@ -1,4 +1,4 @@
namespace PF3.DTO.Truck.Request;
namespace PyroFetes.DTO.Truck.Request;
public class UpdateTruckDto
{

View File

@@ -1,10 +1,10 @@
namespace PF3.DTO.Truck.Response;
namespace PyroFetes.DTO.Truck.Response;
public class ReadTruckDto
{
public int? Id { get; set; }
public string? Type { get; set; }
public string? MaxExplosiveCapacity { get; set; }
public double? MaxExplosiveCapacity { get; set; }
public string? Sizes { get; set; }
public string? Statut { get; set; }
public int? ShowId { get; set; }

View File

@@ -1,11 +1,10 @@
using FastEndpoints;
using PF3.DTO.SoundCategory.Request;
using PF3.DTO.SoundCategory.Response;
using PF3.Models;
using PyroFetes.DTO.SoundCategory.Request;
using PyroFetes.DTO.SoundCategory.Response;
namespace PF3.Endpoints.SoundCategory;
namespace PyroFetes.Endpoints.SoundCategory;
public class CreateSoundCategoryEndpoint(PF3DbContext pf3DbContext) : Endpoint<CreateSoundCategoryDto, ReadSoundCategoryDto>
public class CreateSoundCategoryEndpoint(PyroFetesDbContext pyroFetesDbContext) : Endpoint<CreateSoundCategoryDto, ReadSoundCategoryDto>
{
public override void Configure()
{
@@ -15,13 +14,13 @@ public class CreateSoundCategoryEndpoint(PF3DbContext pf3DbContext) : Endpoint<C
public override async Task HandleAsync(CreateSoundCategoryDto req, CancellationToken ct)
{
var soundCategory = new Models.SoundCategory
var soundCategory = new PyroFetes.Models.SoundCategory
{
Name = req.Name,
};
pf3DbContext.SoundsCategorys.Add(soundCategory);
await pf3DbContext.SaveChangesAsync(ct);
pyroFetesDbContext.SoundCategories.Add(soundCategory);
await pyroFetesDbContext.SaveChangesAsync(ct);
var result = new ReadSoundCategoryDto
{

View File

@@ -1,10 +1,10 @@
using FastEndpoints;
using Microsoft.EntityFrameworkCore;
using PF3.DTO.SoundCategory.Request;
using PyroFetes.DTO.SoundCategory.Request;
namespace PF3.Endpoints.SoundCategory;
namespace PyroFetes.Endpoints.SoundCategory;
public class DeleteSoundCategoryEndpoint(PF3DbContext pf3DbContext) : Endpoint<IdSoundCategoryDto>
public class DeleteSoundCategoryEndpoint(PyroFetesDbContext pf3DbContext) : Endpoint<IdSoundCategoryDto>
{
public override void Configure()
{
@@ -14,14 +14,14 @@ public class DeleteSoundCategoryEndpoint(PF3DbContext pf3DbContext) : Endpoint<I
public override async Task HandleAsync(IdSoundCategoryDto req, CancellationToken ct)
{
var soundCategory = await pf3DbContext.SoundsCategorys.FirstOrDefaultAsync(st => st.Id == req.Id, ct);
var soundCategory = await pf3DbContext.SoundCategories.FirstOrDefaultAsync(st => st.Id == req.Id, ct);
if (soundCategory is null)
{
await Send.NotFoundAsync(ct);
return;
}
pf3DbContext.SoundsCategorys.Remove(soundCategory);
pf3DbContext.SoundCategories.Remove(soundCategory);
await pf3DbContext.SaveChangesAsync(ct);
await Send.OkAsync(ct);

View File

@@ -1,10 +1,10 @@
using FastEndpoints;
using Microsoft.EntityFrameworkCore;
using PF3.DTO.SoundCategory.Response;
using PyroFetes.DTO.SoundCategory.Response;
namespace PF3.Endpoints.SoundCategory;
namespace PyroFetes.Endpoints.SoundCategory;
public class GetAllSoundCategorysEndpoint(PF3DbContext pf3DbContext) : EndpointWithoutRequest<List<ReadSoundCategoryDto>>
public class GetAllSoundCategorysEndpoint(PyroFetesDbContext pf3DbContext) : EndpointWithoutRequest<List<ReadSoundCategoryDto>>
{
public override void Configure()
{
@@ -14,7 +14,7 @@ public class GetAllSoundCategorysEndpoint(PF3DbContext pf3DbContext) : EndpointW
public override async Task HandleAsync(CancellationToken ct)
{
var soundCategorys = await pf3DbContext.SoundsCategorys.ToListAsync(ct);
var soundCategorys = await pf3DbContext.SoundCategories.ToListAsync(ct);
var result = soundCategorys.Select(sC => new ReadSoundCategoryDto
{

View File

@@ -1,11 +1,11 @@
using FastEndpoints;
using Microsoft.EntityFrameworkCore;
using PF3.DTO.SoundCategory.Request;
using PF3.DTO.SoundCategory.Response;
using PyroFetes.DTO.SoundCategory.Request;
using PyroFetes.DTO.SoundCategory.Response;
namespace PF3.Endpoints.SoundCategory;
namespace PyroFetes.Endpoints.SoundCategory;
public class GetSoundCategoryEndpoint(PF3DbContext pf3DbContext) : Endpoint<IdSoundCategoryDto, ReadSoundCategoryDto>
public class GetSoundCategoryEndpoint(PyroFetesDbContext pf3DbContext) : Endpoint<IdSoundCategoryDto, ReadSoundCategoryDto>
{
public override void Configure()
{
@@ -15,7 +15,7 @@ public class GetSoundCategoryEndpoint(PF3DbContext pf3DbContext) : Endpoint<IdSo
public override async Task HandleAsync(IdSoundCategoryDto req, CancellationToken ct)
{
var soundCategory = await pf3DbContext.SoundsCategorys
var soundCategory = await pf3DbContext.SoundCategories
.Where(sc => sc.Id == req.Id)
.Select(sc => new ReadSoundCategoryDto
{

View File

@@ -1,11 +1,11 @@
using FastEndpoints;
using Microsoft.EntityFrameworkCore;
using PF3.DTO.SoundCategory.Request;
using PF3.DTO.SoundCategory.Response;
using PyroFetes.DTO.SoundCategory.Request;
using PyroFetes.DTO.SoundCategory.Response;
namespace PF3.Endpoints.SoundCategory;
namespace PyroFetes.Endpoints.SoundCategory;
public class UpdateSoundCategoryEndpoint(PF3DbContext pf3DbContext) : Endpoint<UpdateSoundCategoryDto, ReadSoundCategoryDto>
public class UpdateSoundCategoryEndpoint(PyroFetesDbContext pf3DbContext) : Endpoint<UpdateSoundCategoryDto, ReadSoundCategoryDto>
{
public override void Configure()
{
@@ -15,7 +15,7 @@ public class UpdateSoundCategoryEndpoint(PF3DbContext pf3DbContext) : Endpoint<U
public override async Task HandleAsync(UpdateSoundCategoryDto req, CancellationToken ct)
{
var soundCategory = await pf3DbContext.SoundsCategorys.FirstOrDefaultAsync(st => st.Id == req.Id, ct);
var soundCategory = await pf3DbContext.SoundCategories.FirstOrDefaultAsync(st => st.Id == req.Id, ct);
if (soundCategory is null)
{
await Send.NotFoundAsync(ct);

View File

@@ -1,10 +1,10 @@
using FastEndpoints;
using PF3.DTO.Staff.Request;
using PF3.DTO.Staff.Response;
using PyroFetes.DTO.Staff.Request;
using PyroFetes.DTO.Staff.Response;
namespace PF3.Endpoints.Staff;
namespace PyroFetes.Endpoints.Staff;
public class CreateStaffEndpoint(PF3DbContext pf3DbContext):Endpoint<CreateStaffDto, ReadStaffDto>
public class CreateStaffEndpoint(PyroFetesDbContext pf3DbContext):Endpoint<CreateStaffDto, ReadStaffDto>
{
public override void Configure()
{
@@ -14,7 +14,7 @@ public class CreateStaffEndpoint(PF3DbContext pf3DbContext):Endpoint<CreateStaff
public override async Task HandleAsync(CreateStaffDto req, CancellationToken ct)
{
var staff = new Models.Staff
var staff = new PyroFetes.Models.Staff
{
FirstName = req.FirstName,
LastName = req.LastName,

View File

@@ -1,10 +1,10 @@
using FastEndpoints;
using Microsoft.EntityFrameworkCore;
using PF3.DTO.Staff.Request;
using PyroFetes.DTO.Staff.Request;
namespace PF3.Endpoints.Staff;
namespace PyroFetes.Endpoints.Staff;
public class DeleteStaffEndpoint(PF3DbContext pf3DbContext) : Endpoint<IdStaffDto>
public class DeleteStaffEndpoint(PyroFetesDbContext pf3DbContext) : Endpoint<IdStaffDto>
{
public override void Configure()
{

View File

@@ -1,10 +1,10 @@
using FastEndpoints;
using Microsoft.EntityFrameworkCore;
using PF3.DTO.Staff.Response;
using PyroFetes.DTO.Staff.Response;
namespace PF3.Endpoints.Staff;
namespace PyroFetes.Endpoints.Staff;
public class GetAllStaffEndpoint(PF3DbContext pf3DbContext) : EndpointWithoutRequest<List<ReadStaffDto>>
public class GetAllStaffEndpoint(PyroFetesDbContext pf3DbContext) : EndpointWithoutRequest<List<ReadStaffDto>>
{
public override void Configure()
{

View File

@@ -1,11 +1,11 @@
using FastEndpoints;
using Microsoft.EntityFrameworkCore;
using PF3.DTO.Staff.Request;
using PF3.DTO.Staff.Response;
using PyroFetes.DTO.Staff.Request;
using PyroFetes.DTO.Staff.Response;
namespace PF3.Endpoints.Staff;
namespace PyroFetes.Endpoints.Staff;
public class GetStaffEndpoint(PF3DbContext pf3DbContext) : Endpoint<IdStaffDto, ReadStaffDto>
public class GetStaffEndpoint(PyroFetesDbContext pf3DbContext) : Endpoint<IdStaffDto, ReadStaffDto>
{
public override void Configure()
{

View File

@@ -1,11 +1,11 @@
using FastEndpoints;
using Microsoft.EntityFrameworkCore;
using PF3.DTO.Staff.Request;
using PF3.DTO.Staff.Response;
using PyroFetes.DTO.Staff.Request;
using PyroFetes.DTO.Staff.Response;
namespace PF3.Endpoints.Staff;
namespace PyroFetes.Endpoints.Staff;
public class UpdateStaffEndpoint(PF3DbContext pf3DbContext) : Endpoint<UpdateStaffDto, ReadStaffDto>
public class UpdateStaffEndpoint(PyroFetesDbContext pf3DbContext) : Endpoint<UpdateStaffDto, ReadStaffDto>
{
public override void Configure()
{

View File

@@ -1,41 +0,0 @@
using FastEndpoints;
using PF3.DTO.Truck.Request;
using PF3.DTO.Truck.Response;
using PyroFetes;
namespace PF3.Endpoints.Truck;
public class CreateTruckEndpoint(PF3DbContext pf3DbContext):Endpoint<CreateTruckDto, ReadTruckDto>
{
public override void Configure()
{
Post("/api/truck");
AllowAnonymous();
}
public override async Task HandleAsync(CreateTruckDto req, CancellationToken ct)
{
var truck = new Models.Truck
{
Type = req.Type,
MaxExplosiveCapacity = req.MaxExplosiveCapacity,
Sizes = req.Sizes,
Statut = req.Statut
};
pf3DbContext.Trucks.Add(truck);
await pf3DbContext.SaveChangesAsync(ct);
var result = new ReadTruckDto()
{
Id = truck.Id,
Type = truck.Type,
MaxExplosiveCapacity = truck.MaxExplosiveCapacity,
Sizes = truck.Sizes,
Statut = truck.Statut
};
await Send.OkAsync(result, ct);
}
}

View File

@@ -1,24 +0,0 @@
using PF3.DTO.Truck.Request;
using FastEndpoints;
using Microsoft.EntityFrameworkCore;
using PF3;
namespace ApiLibrary.Endpoints.Truck;
public class DeleteTruckEndpoint(PF3DbContext pf3DbContext) : Endpoint<IdTruckDto>
{
public override void Configure()
{
Delete("/api/trucks/{@Id}", x => new { x.Id });
}
public override async Task HandleAsync(IdTruckDto req, CancellationToken ct)
{
var truck = await pf3DbContext.Trucks.FirstOrDefaultAsync(a => a.Id == req.Id, ct);
pf3DbContext.Trucks.Remove(truck);
await pf3DbContext.SaveChangesAsync(ct);
await Send.OkAsync(ct);
}
}

View File

@@ -1,33 +0,0 @@
using PF3.DTO.Truck.Response;
using FastEndpoints;
using Microsoft.EntityFrameworkCore;
using PF3;
namespace PF3.Endpoints.Truck;
public class GetAllTrucksEndpoint(PF3DbContext pf3DbContext) : EndpointWithoutRequest<List<ReadTruckDto>>
{
public override void Configure()
{
Get("/api/trucks");
}
public override async Task HandleAsync(CancellationToken ct)
{
var trucks = await pf3DbContext.Trucks.ToListAsync(ct);
var result = trucks
.Select(truck => new ReadTruckDto
{
Id = truck.Id,
Type = truck.Type,
MaxExplosiveCapacity = truck.MaxExplosiveCapacity,
Sizes = truck.Sizes,
Statut = truck.Statut,
ShowId = truck.ShowId
})
.ToList();
await Send.OkAsync(result, ct);
}
}

View File

@@ -1,39 +0,0 @@
using PF3.DTO.Truck.Request;
using PF3.DTO.Truck.Response;
using FastEndpoints;
using Microsoft.EntityFrameworkCore;
using PF3;
namespace PF3.Endpoints.Truck;
public class GetTruckEndpoint(PF3DbContext pf3DbContext) : Endpoint<IdTruckDto, ReadTruckDto>
{
public override void Configure()
{
Get("/api/trucks/{@Id}");
}
public override async Task HandleAsync(IdTruckDto req, CancellationToken ct)
{
var truck = await pf3DbContext.Trucks
.Where(t => t.Id == req.Id)
.Select(t => new ReadTruckDto
{
Id = t.Id,
Type = t.Type,
MaxExplosiveCapacity = t.MaxExplosiveCapacity,
Sizes = t.Sizes,
Statut = t.Statut,
ShowId = t.ShowId
})
.FirstOrDefaultAsync(ct);
if (truck is null)
{
await Send.NotFoundAsync(ct);
return;
}
await Send.OkAsync(truck, ct);
}
}

View File

@@ -1,48 +0,0 @@
using PF3.DTO.Truck.Request;
using PF3.DTO.Truck.Response;
using FastEndpoints;
using Microsoft.EntityFrameworkCore;
using PF3;
namespace PF3.Endpoints.Truck;
public class UpdateTruckEndpoint(PF3DbContext pf3DbContext) : Endpoint<UpdateTruckDto, ReadTruckDto>
{
public override void Configure()
{
Put("/api/trucks/{id}");
}
public override async Task HandleAsync(UpdateTruckDto req, CancellationToken ct)
{
var id = Route<int>("id");
var truck = await pf3DbContext.Trucks.FirstOrDefaultAsync(t => t.Id == id, ct);
if (truck is null)
{
await Send.NotFoundAsync(ct);
return;
}
truck.Type = req.Type;
truck.MaxExplosiveCapacity = req.MaxExplosiveCapacity;
truck.Sizes = req.Sizes;
truck.Statut = req.Statut;
truck.ShowId = req.ShowId;
await pf3DbContext.SaveChangesAsync(ct);
var result = new ReadTruckDto
{
Id = truck.Id,
Type = truck.Type,
MaxExplosiveCapacity = truck.MaxExplosiveCapacity,
Sizes = truck.Sizes,
Statut = truck.Statut,
ShowId = truck.ShowId
};
await Send.OkAsync(result, ct);
}
}

View File

@@ -7,6 +7,8 @@
</PropertyGroup>
<ItemGroup>
<PackageReference Include="FastEndpoints" Version="7.1.1" />
<PackageReference Include="FastEndpoints.Swagger" Version="7.1.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">
@@ -21,6 +23,7 @@
<Folder Include="Endpoints\Show\" />
<Folder Include="Endpoints\SoundTimecode\" />
<Folder Include="Endpoints\Sound\" />
<Folder Include="Endpoints\Truck\" />
</ItemGroup>
</Project>

View File

@@ -37,6 +37,10 @@ public class PyroFetesDbContext : DbContext
public DbSet<QuotationProduct> QuotationProducts { get; set; }
public DbSet<Setting> Settings { get; set; }
public DbSet<Show> Shows { get; set; }
// AJOUTE CETTE LIGNE ICI ⬇️
public DbSet<ShowTruck> ShowTrucks { get; set; }
public DbSet<Sound> Sounds { get; set; }
public DbSet<SoundCategory> SoundCategories { get; set; }
public DbSet<SoundTimecode> SoundTimecodes { get; set; }