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,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);
}
}