Staff DTO / Request Finished 09/10
This commit is contained in:
@@ -3,5 +3,5 @@ namespace PyroFetes.DTO.Staff.Request;
|
||||
public class CreateStaffDto
|
||||
{
|
||||
public string? F4T2NumberApproval { get; set; }
|
||||
public string? F4T2ExpirationDate { get; set; }
|
||||
public DateOnly F4T2ExpirationDate { get; set; }
|
||||
}
|
@@ -2,5 +2,5 @@ namespace PyroFetes.DTO.Staff.Request;
|
||||
|
||||
public class GetStaffRequest
|
||||
{
|
||||
public string? Label { get; set; }
|
||||
public int Id { get; set; }
|
||||
}
|
@@ -4,5 +4,5 @@ public class UpdateStaffDto
|
||||
{
|
||||
public int Id { get; set; }
|
||||
public string? F4T2NumberApproval { get; set; }
|
||||
public string? F4T2ExpirationDate { get; set; }
|
||||
public DateOnly F4T2ExpirationDate { get; set; }
|
||||
}
|
@@ -3,4 +3,6 @@ namespace PyroFetes.DTO.Staff.Response;
|
||||
public class GetStaffDto
|
||||
{
|
||||
public int Id { get; set; }
|
||||
public string? F4T2NumberApproval { get; set; }
|
||||
public DateOnly F4T2ExpirationDate { get; set; }
|
||||
}
|
34
PyroFetes/Endpoints/Staff/CreateStaffEndpoint.cs
Normal file
34
PyroFetes/Endpoints/Staff/CreateStaffEndpoint.cs
Normal file
@@ -0,0 +1,34 @@
|
||||
using FastEndpoints;
|
||||
using PyroFetes.DTO.Staff.Request;
|
||||
using PyroFetes.DTO.Staff.Response;
|
||||
|
||||
namespace PyroFetes.Endpoints.Staff;
|
||||
|
||||
public class CreateStaffEndpoint(PyroFetesDbContext pyroFetesDbContext) : Endpoint<CreateStaffDto, GetStaffDto>
|
||||
{
|
||||
public override void Configure()
|
||||
{
|
||||
Post("/api/availabilities");
|
||||
AllowAnonymous();
|
||||
}
|
||||
|
||||
|
||||
public override async Task HandleAsync(CreateStaffDto req, CancellationToken ct)
|
||||
{
|
||||
Models.Staff staff = new()
|
||||
{
|
||||
F4T2NumberApproval = req.F4T2NumberApproval,
|
||||
F4T2ExpirationDate = req.F4T2ExpirationDate,
|
||||
};
|
||||
pyroFetesDbContext.Add(staff);
|
||||
await pyroFetesDbContext.SaveChangesAsync(ct);
|
||||
|
||||
GetStaffDto response = new()
|
||||
{
|
||||
F4T2NumberApproval = staff.F4T2NumberApproval,
|
||||
F4T2ExpirationDate = staff.F4T2ExpirationDate,
|
||||
};
|
||||
|
||||
await Send.OkAsync(response, ct);
|
||||
}
|
||||
}
|
30
PyroFetes/Endpoints/Staff/DeleteStaffEndpoint.cs
Normal file
30
PyroFetes/Endpoints/Staff/DeleteStaffEndpoint.cs
Normal file
@@ -0,0 +1,30 @@
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using PyroFetes.DTO.Staff.Request;
|
||||
using PyroFetes.DTO.Staff.Response;
|
||||
using FastEndpoints;
|
||||
|
||||
namespace PyroFetes.Endpoints.Staff;
|
||||
|
||||
public class DeleteStaffEndpoint(PyroFetesDbContext pyroFetesDbContext) : Endpoint <GetStaffRequest, GetStaffDto>
|
||||
{
|
||||
public override void Configure()
|
||||
{
|
||||
Delete ("/api/staff/{@Id}", x => new { x.Id });
|
||||
AllowAnonymous();
|
||||
}
|
||||
|
||||
public override async Task HandleAsync(GetStaffRequest req, CancellationToken ct)
|
||||
{
|
||||
Models.Staff? databaseStaff = await pyroFetesDbContext.Staffs.SingleOrDefaultAsync(x => x.Id == req.Id, cancellationToken: ct);
|
||||
|
||||
if (databaseStaff == null)
|
||||
{
|
||||
await Send.NotFoundAsync(ct);
|
||||
return;
|
||||
}
|
||||
pyroFetesDbContext.Staffs.Remove(databaseStaff);
|
||||
await pyroFetesDbContext.SaveChangesAsync(ct);
|
||||
|
||||
await Send.NoContentAsync(ct);
|
||||
}
|
||||
}
|
27
PyroFetes/Endpoints/Staff/GetAllStaffsEndpoint.cs
Normal file
27
PyroFetes/Endpoints/Staff/GetAllStaffsEndpoint.cs
Normal file
@@ -0,0 +1,27 @@
|
||||
using FastEndpoints;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using PyroFetes.DTO.Staff.Response;
|
||||
|
||||
namespace PyroFetes.Endpoints.Staff;
|
||||
|
||||
public class GetAllStaffsEndpoint(PyroFetesDbContext pyroFetesDbContext) : EndpointWithoutRequest<List<GetStaffDto>>
|
||||
{
|
||||
public override void Configure()
|
||||
{
|
||||
Get ("/api/availabilities");
|
||||
AllowAnonymous();
|
||||
}
|
||||
|
||||
public override async Task HandleAsync(CancellationToken ct)
|
||||
{
|
||||
List<GetStaffDto> staff = await pyroFetesDbContext.Staffs.Select(x => new GetStaffDto()
|
||||
{
|
||||
Id = x.Id,
|
||||
F4T2NumberApproval = x.F4T2NumberApproval,
|
||||
F4T2ExpirationDate = x.F4T2ExpirationDate,
|
||||
|
||||
}).ToListAsync(ct);
|
||||
|
||||
await Send.OkAsync(staff, ct);
|
||||
}
|
||||
}
|
35
PyroFetes/Endpoints/Staff/GetStaffEndpoint.cs
Normal file
35
PyroFetes/Endpoints/Staff/GetStaffEndpoint.cs
Normal file
@@ -0,0 +1,35 @@
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using PyroFetes.DTO.Staff.Request;
|
||||
using PyroFetes.DTO.Staff.Response;
|
||||
using FastEndpoints;
|
||||
|
||||
namespace PyroFetes.Endpoints.Staff;
|
||||
|
||||
public class GetStaffEndpoint(PyroFetesDbContext pyroFetesDbContext) : Endpoint <GetStaffRequest, GetStaffDto>
|
||||
{
|
||||
public override void Configure()
|
||||
{
|
||||
Get ("/api/Staffs/{@Id}", x => new { x.Id });
|
||||
AllowAnonymous();
|
||||
}
|
||||
|
||||
public override async Task HandleAsync(GetStaffRequest database, CancellationToken ct)
|
||||
{
|
||||
Models.Staff? databaseStaff = await pyroFetesDbContext.Staffs.SingleOrDefaultAsync(x => x.Id == database.Id, cancellationToken: ct);
|
||||
|
||||
if (databaseStaff == null)
|
||||
{
|
||||
await Send.NotFoundAsync(ct);
|
||||
return;
|
||||
}
|
||||
|
||||
GetStaffDto dto = new()
|
||||
{
|
||||
Id = databaseStaff.Id,
|
||||
F4T2NumberApproval = databaseStaff.F4T2NumberApproval,
|
||||
F4T2ExpirationDate = databaseStaff.F4T2ExpirationDate,
|
||||
};
|
||||
|
||||
await Send.OkAsync(dto, ct);
|
||||
}
|
||||
}
|
41
PyroFetes/Endpoints/Staff/UpdateStaffRequest.cs
Normal file
41
PyroFetes/Endpoints/Staff/UpdateStaffRequest.cs
Normal file
@@ -0,0 +1,41 @@
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using PyroFetes.DTO.Staff.Request;
|
||||
using PyroFetes.DTO.Staff.Response;
|
||||
using FastEndpoints;
|
||||
|
||||
namespace PyroFetes.Endpoints.Staff;
|
||||
|
||||
public class UpdateStaffRequest(PyroFetesDbContext pyroFetesDbContext) : Endpoint <UpdateStaffDto, GetStaffDto>
|
||||
{
|
||||
public override void Configure()
|
||||
{
|
||||
Put ("/api/Staffs/{@Id}", x => new { x.Id });
|
||||
AllowAnonymous();
|
||||
}
|
||||
|
||||
public override async Task HandleAsync(UpdateStaffDto req, CancellationToken ct)
|
||||
{
|
||||
Models.Staff? databaseStaff = await pyroFetesDbContext.Staffs.SingleOrDefaultAsync(x => x.Id == req.Id, cancellationToken: ct);
|
||||
|
||||
if (databaseStaff == null)
|
||||
{
|
||||
await Send.NotFoundAsync(ct);
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
databaseStaff.F4T2NumberApproval = req.F4T2NumberApproval;
|
||||
databaseStaff.F4T2ExpirationDate = req.F4T2ExpirationDate;
|
||||
}
|
||||
await pyroFetesDbContext.SaveChangesAsync(ct);
|
||||
|
||||
GetStaffDto dto = new()
|
||||
{
|
||||
Id = databaseStaff.Id,
|
||||
F4T2NumberApproval = req.F4T2NumberApproval,
|
||||
F4T2ExpirationDate = req.F4T2ExpirationDate,
|
||||
};
|
||||
|
||||
await Send.OkAsync(dto, ct);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user