First Commit 09/10

# Conflicts:
#	PyroFetes/PyroFetes.csproj
This commit is contained in:
2025-10-09 17:12:17 +02:00
parent 0e19ef1ab7
commit 4e64112a31
49 changed files with 908 additions and 0 deletions

View File

@@ -0,0 +1,38 @@
using FastEndpoints;
using PyroFetes.DTO.Availability.Request;
using PyroFetes.DTO.Availability.Response;
namespace PyroFetes.Endpoints.Availability;
public class CreateAvailabilityEndpoint(PyroFetesDbContext pyroFetesDbContext) : Endpoint<CreateAvailabilityDto, GetAvailabilityDto>
{
public override void Configure()
{
Post("/api/availabilities");
AllowAnonymous();
}
public override async Task HandleAsync(CreateAvailabilityDto req, CancellationToken ct)
{
Models.Availability availability = new()
{
AvailabilityDate = req.AvailabilityDate,
DeliveryDate = req.DeliveryDate,
ExpirationDate = req.ExpirationDate,
RenewallDate = req.RenewalDate,
};
pyroFetesDbContext.Add(availability);
await pyroFetesDbContext.SaveChangesAsync(ct);
GetAvailabilityDto response = new()
{
AvailabilityDate = availability.AvailabilityDate,
DeliveryDate = availability.DeliveryDate,
ExpirationDate = availability.ExpirationDate,
RenewalDate = availability.RenewallDate
};
await Send.OkAsync(response, ct);
}
}

View File

@@ -0,0 +1,30 @@
using FastEndpoints;
using Microsoft.EntityFrameworkCore;
using PyroFetes.DTO.Availability.Request;
using PyroFetes.DTO.Availability.Response;
namespace PyroFetes.Endpoints.Availability;
public class DeleteAvailabilityEndpoint(PyroFetesDbContext pyroFetesDbContext) : Endpoint <GetAvailabilityRequest, GetAvailabilityDto>
{
public override void Configure()
{
Delete ("/api/availabilities/{@Id}", x => new { x.Id });
AllowAnonymous();
}
public override async Task HandleAsync(GetAvailabilityRequest req, CancellationToken ct)
{
Models.Availability? databaseAvailability = await pyroFetesDbContext.Availabilities.SingleOrDefaultAsync(x => x.Id == req.Id, cancellationToken: ct);
if (databaseAvailability == null)
{
await Send.NotFoundAsync(ct);
return;
}
pyroFetesDbContext.Availabilities.Remove(databaseAvailability);
await pyroFetesDbContext.SaveChangesAsync(ct);
await Send.NoContentAsync(ct);
}
}

View File

@@ -0,0 +1,28 @@
using FastEndpoints;
using Microsoft.EntityFrameworkCore;
using PyroFetes.DTO.Availability.Response;
namespace PyroFetes.Endpoints.Availability;
public class GetAllAvailabilityxuest(PyroFetesDbContext pyroFetesDbContext) : EndpointWithoutRequest<List<GetAvailabilityDto>>
{
public override void Configure()
{
Get ("/api/availabilities");
AllowAnonymous();
}
public override async Task HandleAsync(CancellationToken ct)
{
List<GetAvailabilityDto> availabilities = await pyroFetesDbContext.Availabilities.Select(x => new GetAvailabilityDto()
{
Id = x.Id,
AvailabilityDate = x.AvailabilityDate,
DeliveryDate = x.DeliveryDate,
ExpirationDate = x.ExpirationDate,
RenewalDate = x.RenewallDate
}).ToListAsync(ct);
await Send.OkAsync(availabilities, ct);
}
}

View File

@@ -0,0 +1,37 @@
using FastEndpoints;
using Microsoft.EntityFrameworkCore;
using PyroFetes.DTO.Availability.Request;
using PyroFetes.DTO.Availability.Response;
namespace PyroFetes.Endpoints.Availability;
public class GetAvailabilityEndpoint(PyroFetesDbContext pyroFetesDbContext) : Endpoint <GetAvailabilityRequest, GetAvailabilityDto>
{
public override void Configure()
{
Get ("/api/availabilities/{@Id}", x => new { x.Id });
AllowAnonymous();
}
public override async Task HandleAsync(GetAvailabilityRequest database, CancellationToken ct)
{
Models.Availability? databaseAvailability = await pyroFetesDbContext.Availabilities.SingleOrDefaultAsync(x => x.Id == database.Id, cancellationToken: ct);
if (databaseAvailability == null)
{
await Send.NotFoundAsync(ct);
return;
}
GetAvailabilityDto dto = new()
{
Id = databaseAvailability.Id,
AvailabilityDate = databaseAvailability.AvailabilityDate,
DeliveryDate = databaseAvailability.DeliveryDate,
ExpirationDate = databaseAvailability.ExpirationDate,
RenewalDate = databaseAvailability.RenewallDate
};
await Send.OkAsync(dto, ct);
}
}

View File

@@ -0,0 +1,45 @@
using FastEndpoints;
using Microsoft.EntityFrameworkCore;
using PyroFetes.DTO.Availability.Request;
using PyroFetes.DTO.Availability.Response;
namespace PyroFetes.Endpoints.Availability;
public class UpdateAvailabilityEndpoint(PyroFetesDbContext pyroFetesDbContext) : Endpoint <UpdateAvailabilityDto, GetAvailabilityDto>
{
public override void Configure()
{
Put ("/api/availabilities/{@Id}", x => new { x.Id });
AllowAnonymous();
}
public override async Task HandleAsync(UpdateAvailabilityDto req, CancellationToken ct)
{
Models.Availability? databaseAvailability = await pyroFetesDbContext.Availabilities.SingleOrDefaultAsync(x => x.Id == req.Id, cancellationToken: ct);
if (databaseAvailability == null)
{
await Send.NotFoundAsync(ct);
return;
}
else
{
databaseAvailability.AvailabilityDate = req.AvailabilityDate;
databaseAvailability.DeliveryDate = req.DeliveryDate;
databaseAvailability.ExpirationDate = req.ExpirationDate;
databaseAvailability.RenewallDate = req.RenewalDate;
}
await pyroFetesDbContext.SaveChangesAsync(ct);
GetAvailabilityDto dto = new()
{
Id = databaseAvailability.Id,
AvailabilityDate = req.AvailabilityDate,
DeliveryDate = req.DeliveryDate,
ExpirationDate = req.ExpirationDate,
RenewalDate = req.RenewalDate,
};
await Send.OkAsync(dto, ct);
}
}

View File

@@ -0,0 +1,42 @@
using FastEndpoints;
using PyroFetes.DTO.Contact.Request;
using PyroFetes.DTO.Contact.Response;
namespace PyroFetes.Endpoints.Contact;
public class CreateContactEndpoint(PyroFetesDbContext pyroFetesDbContext) : Endpoint<CreateContactDto, GetContactDto>
{
public override void Configure()
{
Post("/api/contacts");
AllowAnonymous();
}
public override async Task HandleAsync(CreateContactDto req, CancellationToken ct)
{
Models.Contact contact = new()
{
LastName = req.LastName,
FirstName = req.FirstName,
PhoneNumber = req.PhoneNumber,
Email = req.Email,
Address = req.Address,
Role = req.Role,
};
pyroFetesDbContext.Add(contact);
await pyroFetesDbContext.SaveChangesAsync(ct);
GetContactDto response = new()
{
LastName = contact.LastName,
FirstName = contact.FirstName,
PhoneNumber = contact.PhoneNumber,
Email = contact.Email,
Address = contact.Address,
Role = contact.Role,
};
await Send.OkAsync(response, ct);
}
}

View File

@@ -0,0 +1,30 @@
using FastEndpoints;
using Microsoft.EntityFrameworkCore;
using PyroFetes.DTO.Contact.Request;
using PyroFetes.DTO.Contact.Response;
namespace PyroFetes.Endpoints.Contact;
public class DeleteContactEndpoint(PyroFetesDbContext pyroFetesDbContext) : Endpoint <GetContactRequest, GetContactDto>
{
public override void Configure()
{
Delete ("/api/Contacts/{@Id}", x => new { x.Id });
AllowAnonymous();
}
public override async Task HandleAsync(GetContactRequest req, CancellationToken ct)
{
Models.Contact? databaseContact = await pyroFetesDbContext.Contacts.SingleOrDefaultAsync(x => x.Id == req.Id, cancellationToken: ct);
if (databaseContact == null)
{
await Send.NotFoundAsync(ct);
return;
}
pyroFetesDbContext.Contacts.Remove(databaseContact);
await pyroFetesDbContext.SaveChangesAsync(ct);
await Send.NoContentAsync(ct);
}
}

View File

@@ -0,0 +1,30 @@
using FastEndpoints;
using Microsoft.EntityFrameworkCore;
using PyroFetes.DTO.Contact.Response;
namespace PyroFetes.Endpoints.Contact;
public class GetAllContactxuest(PyroFetesDbContext pyroFetesDbContext) : EndpointWithoutRequest<List<GetContactDto>>
{
public override void Configure()
{
Get ("/api/contacts");
AllowAnonymous();
}
public override async Task HandleAsync(CancellationToken ct)
{
List<GetContactDto> contacts = await pyroFetesDbContext.Contacts.Select(x => new GetContactDto()
{
Id = x.Id,
LastName = x.LastName,
FirstName = x.FirstName,
PhoneNumber = x.PhoneNumber,
Email = x.Email,
Address = x.Address,
Role = x.Role,
}).ToListAsync(ct);
await Send.OkAsync(contacts, ct);
}
}

View File

@@ -0,0 +1,39 @@
using FastEndpoints;
using Microsoft.EntityFrameworkCore;
using PyroFetes.DTO.Contact.Request;
using PyroFetes.DTO.Contact.Response;
namespace PyroFetes.Endpoints.Contact;
public class GetContactEndpoint(PyroFetesDbContext pyroFetesDbContext) : Endpoint <GetContactRequest, GetContactDto>
{
public override void Configure()
{
Get ("/api/contacts/{@Id}", x => new { x.Id });
AllowAnonymous();
}
public override async Task HandleAsync(GetContactRequest database, CancellationToken ct)
{
Models.Contact? databaseContact = await pyroFetesDbContext.Contacts.SingleOrDefaultAsync(x => x.Id == database.Id, cancellationToken: ct);
if (databaseContact == null)
{
await Send.NotFoundAsync(ct);
return;
}
GetContactDto dto = new()
{
Id = databaseContact.Id,
LastName = databaseContact.LastName,
FirstName = databaseContact.FirstName,
PhoneNumber = databaseContact.PhoneNumber,
Email = databaseContact.Email,
Address = databaseContact.Address,
Role = databaseContact.Role,
};
await Send.OkAsync(dto, ct);
}
}

View File

@@ -0,0 +1,49 @@
using FastEndpoints;
using Microsoft.EntityFrameworkCore;
using PyroFetes.DTO.Contact.Request;
using PyroFetes.DTO.Contact.Response;
namespace PyroFetes.Endpoints.Contact;
public class UpdateContactRequest(PyroFetesDbContext pyroFetesDbContext) : Endpoint <UpdateContactDto, GetContactDto>
{
public override void Configure()
{
Put ("/api/contacts/{@Id}", x => new { x.Id });
AllowAnonymous();
}
public override async Task HandleAsync(UpdateContactDto req, CancellationToken ct)
{
Models.Contact? databaseContact = await pyroFetesDbContext.Contacts.SingleOrDefaultAsync(x => x.Id == req.Id, cancellationToken: ct);
if (databaseContact == null)
{
await Send.NotFoundAsync(ct);
return;
}
else
{
databaseContact.LastName = req.LastName;
databaseContact.FirstName = req.FirstName;
databaseContact.PhoneNumber = req.PhoneNumber;
databaseContact.Email = req.Email;
databaseContact.Address = req.Address;
databaseContact.Role = req.Role;
}
await pyroFetesDbContext.SaveChangesAsync(ct);
GetContactDto dto = new()
{
Id = databaseContact.Id,
LastName = req.LastName,
FirstName = req.FirstName,
PhoneNumber = req.PhoneNumber,
Email = req.Email,
Address = req.Address,
Role = req.Role,
};
await Send.OkAsync(dto, ct);
}
}

View File

@@ -0,0 +1,34 @@
using FastEndpoints;
using PyroFetes.DTO.ExperienceLevel.Response;
using PyroFetes.DTO.ExperienceLevel.Request;
namespace PyroFetes.Endpoints.ExperienceLevel;
public class CreateExperienceLevelEndpoint(PyroFetesDbContext pyroFetesDbContext) : Endpoint<CreateExperienceLevelDto, GetExperienceLevelDto>
{
public override void Configure()
{
Post("/api/ExperienceLevels");
AllowAnonymous();
}
public override async Task HandleAsync(CreateExperienceLevelDto req, CancellationToken ct)
{
Models.ExperienceLevel experienceLevel = new()
{
Label = req.Label
};
pyroFetesDbContext.Add(experienceLevel);
await pyroFetesDbContext.SaveChangesAsync(ct);
GetExperienceLevelDto response = new()
{
Id = experienceLevel.Id,
Label = experienceLevel.Label,
};
await Send.OkAsync(response, ct);
}
}

View File

@@ -0,0 +1,30 @@
using Microsoft.EntityFrameworkCore;
using PyroFetes.DTO.ExperienceLevel.Request;
using PyroFetes.DTO.ExperienceLevel.Response;
using FastEndpoints;
namespace PyroFetes.Endpoints.ExperienceLevel;
public class DeleteExerienceLevelEndpoint(PyroFetesDbContext pyroFetesDbContext) : Endpoint <GetExperienceLevelRequest, GetExperienceLevelDto>
{
public override void Configure()
{
Delete ("/api/ExperienceLevels/{@Id}", x => new { x.Id });
AllowAnonymous();
}
public override async Task HandleAsync(GetExperienceLevelRequest req, CancellationToken ct)
{
Models.ExperienceLevel? databaseExperienceLevel = await pyroFetesDbContext.ExperienceLevels.SingleOrDefaultAsync(x => x.Id == req.Id, cancellationToken: ct);
if (databaseExperienceLevel == null)
{
await Send.NotFoundAsync(ct);
return;
}
pyroFetesDbContext.ExperienceLevels.Remove(databaseExperienceLevel);
await pyroFetesDbContext.SaveChangesAsync(ct);
await Send.NoContentAsync(ct);
}
}

View File

@@ -0,0 +1,24 @@
using Microsoft.EntityFrameworkCore;
using PyroFetes.DTO.ExperienceLevel.Response;
namespace PyroFetes.Endpoints.ExperienceLevel;
using FastEndpoints;
public class GetAllExperienceLevelsEndpoint(PyroFetesDbContext pyroFetesDbContext) : EndpointWithoutRequest<List<GetExperienceLevelDto>>
{
public override void Configure()
{
Get ("/api/experienceLevels");
AllowAnonymous();
}
public override async Task HandleAsync(CancellationToken ct)
{
List<GetExperienceLevelDto> experienceLevels= await pyroFetesDbContext.ExperienceLevels.Select(x => new GetExperienceLevelDto()
{
Id = x.Id,
}).ToListAsync(ct);
await Send.OkAsync(experienceLevels, ct);
}
}

View File

@@ -0,0 +1,6 @@
namespace PyroFetes.Endpoints.ExperienceLevel;
public class GetExperienceLevelEndpoint
{
}

View File

@@ -0,0 +1,6 @@
namespace PyroFetes.Endpoints.ExperienceLevel;
public class UpdateExperienceLevelEndpoint
{
}

View File

@@ -0,0 +1,36 @@
using FastEndpoints;
using PyroFetes.DTO.HistoryOfApproval.Request;
using PyroFetes.DTO.HistoryOfApproval.Response;
namespace PyroFetes.Endpoints.HistoryOfApproval;
public class CreateHistoryOfApprovalEndpoint(PyroFetesDbContext pyroFetesDbContext) : Endpoint<CreateHistoryOfApprovalDto, GetHistoryOfApprovalDto>
{
public override void Configure()
{
Post("/api/HistoryOfApprovals");
AllowAnonymous();
}
public override async Task HandleAsync(CreateHistoryOfApprovalDto req, CancellationToken ct)
{
Models.HistoryOfApproval historyOfApproval = new()
{
DeliveryDate = req.DeliveryDate,
ExpirationDate = req.ExpirationDate
};
pyroFetesDbContext.Add(historyOfApproval);
await pyroFetesDbContext.SaveChangesAsync(ct);
GetHistoryOfApprovalDto response = new()
{
Id = historyOfApproval.Id,
DeliveryDate = historyOfApproval.DeliveryDate,
ExpirationDate = historyOfApproval.ExpirationDate
};
await Send.OkAsync(response, ct);
}
}

View File

@@ -0,0 +1,30 @@
using FastEndpoints;
using Microsoft.EntityFrameworkCore;
using PyroFetes.DTO.HistoryOfApproval.Request;
using PyroFetes.DTO.HistoryOfApproval.Response;
namespace PyroFetes.Endpoints.HistoryOfApproval;
public class DeleteHistoryOfApprovalEndpoint(PyroFetesDbContext pyroFetesDbContext) : Endpoint <GetHistoryOfApprovalRequest, GetHistoryOfApprovalDto>
{
public override void Configure()
{
Delete ("/api/HistoryOfApprovals/{@Id}", x => new { x.Id });
AllowAnonymous();
}
public override async Task HandleAsync(GetHistoryOfApprovalRequest req, CancellationToken ct)
{
Models.HistoryOfApproval? databaseHistoryOfApproval = await pyroFetesDbContext.HistoryOfApprovals.SingleOrDefaultAsync(x => x.Id == req.Id, cancellationToken: ct);
if (databaseHistoryOfApproval == null)
{
await Send.NotFoundAsync(ct);
return;
}
pyroFetesDbContext.HistoryOfApprovals.Remove(databaseHistoryOfApproval);
await pyroFetesDbContext.SaveChangesAsync(ct);
await Send.NoContentAsync(ct);
}
}

View File

@@ -0,0 +1,26 @@
using FastEndpoints;
using Microsoft.EntityFrameworkCore;
using PyroFetes.DTO.HistoryOfApproval.Response;
namespace PyroFetes.Endpoints.HistoryOfApproval;
public class GetAllHistoryOfApprovalEndpoint(PyroFetesDbContext pyroFetesDbContext) : EndpointWithoutRequest<List<GetHistoryOfApprovalDto>>
{
public override void Configure()
{
Get ("/api/HistoryOfApprovals");
AllowAnonymous();
}
public override async Task HandleAsync(CancellationToken ct)
{
List<GetHistoryOfApprovalDto> historyOfApprovals= await pyroFetesDbContext.HistoryOfApprovals.Select(x => new GetHistoryOfApprovalDto()
{
Id = x.Id,
DeliveryDate = x.DeliveryDate,
ExpirationDate = x.ExpirationDate,
}).ToListAsync(ct);
await Send.OkAsync(historyOfApprovals, ct);
}
}

View File

@@ -0,0 +1,35 @@
using FastEndpoints;
using Microsoft.EntityFrameworkCore;
using PyroFetes.DTO.HistoryOfApproval.Request;
using PyroFetes.DTO.HistoryOfApproval.Response;
namespace PyroFetes.Endpoints.HistoryOfApproval;
public class GetHistoryOfApprovalEndpoint(PyroFetesDbContext pyroFetesDbContext) : Endpoint <GetHistoryOfApprovalRequest, GetHistoryOfApprovalDto>
{
public override void Configure()
{
Get ("/api/HistoryOfApprovals/{@Id}", x => new { x.Id });
AllowAnonymous();
}
public override async Task HandleAsync(GetHistoryOfApprovalRequest req, CancellationToken ct)
{
Models.HistoryOfApproval? databaseHistoryOfApproval = await pyroFetesDbContext.HistoryOfApprovals.SingleOrDefaultAsync(x => x.Id == req.Id, cancellationToken: ct);
if (databaseHistoryOfApproval == null)
{
await Send.NotFoundAsync(ct);
return;
}
GetHistoryOfApprovalDto dto = new()
{
Id = databaseHistoryOfApproval.Id,
DeliveryDate = databaseHistoryOfApproval.DeliveryDate,
ExpirationDate = databaseHistoryOfApproval.ExpirationDate
};
await Send.OkAsync(dto, ct);
}
}

View File

@@ -0,0 +1,41 @@
using FastEndpoints;
using Microsoft.EntityFrameworkCore;
using PyroFetes.DTO.HistoryOfApproval.Request;
using PyroFetes.DTO.HistoryOfApproval.Response;
namespace PyroFetes.Endpoints.HistoryOfApproval;
public class UpdateHistoryOfApprovalEndpoint(PyroFetesDbContext pyroFetesDbContext) : Endpoint <UpdateHistoryOfApprovalDto, GetHistoryOfApprovalDto>
{
public override void Configure()
{
Put ("/api/HistoryOfApprovals/{@Id}", x => new { x.Id });
AllowAnonymous();
}
public override async Task HandleAsync(UpdateHistoryOfApprovalDto req, CancellationToken ct)
{
Models.HistoryOfApproval? databaseHistoryOfApproval = await pyroFetesDbContext.HistoryOfApprovals.SingleOrDefaultAsync(x => x.Id == req.Id, cancellationToken: ct);
if (databaseHistoryOfApproval == null)
{
await Send.NotFoundAsync(ct);
return;
}
else
{
databaseHistoryOfApproval.DeliveryDate = req.DeliveryDate;
databaseHistoryOfApproval.ExpirationDate = req.ExpirationDate;
}
await pyroFetesDbContext.SaveChangesAsync(ct);
GetHistoryOfApprovalDto dto = new()
{
Id = databaseHistoryOfApproval.Id,
DeliveryDate = req.DeliveryDate,
ExpirationDate = req.ExpirationDate
};
await Send.OkAsync(dto, ct);
}
}