Compare commits
9 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 0beb5f3446 | |||
| 2b4b2b50df | |||
| 0cc0eeb439 | |||
| 6908112755 | |||
| a554693e9c | |||
| fc736e8525 | |||
| 604dd77fed | |||
| df0756ff50 | |||
| 0a001e15e3 |
@@ -7,5 +7,7 @@ public class CreateContactDto
|
|||||||
public string? PhoneNumber { get; set; }
|
public string? PhoneNumber { get; set; }
|
||||||
public string? Email { get; set; }
|
public string? Email { get; set; }
|
||||||
public string? Address { get; set; }
|
public string? Address { get; set; }
|
||||||
|
public string? City { get; set; }
|
||||||
public string? Role { get; set; }
|
public string? Role { get; set; }
|
||||||
|
public int? CustomerId { get; set; }
|
||||||
}
|
}
|
||||||
@@ -8,5 +8,7 @@ public class UpdateContactDto
|
|||||||
public string? PhoneNumber { get; set; }
|
public string? PhoneNumber { get; set; }
|
||||||
public string? Email { get; set; }
|
public string? Email { get; set; }
|
||||||
public string? Address { get; set; }
|
public string? Address { get; set; }
|
||||||
|
public string? City { get; set; }
|
||||||
public string? Role { get; set; }
|
public string? Role { get; set; }
|
||||||
|
public int? CustomerTypeId { get; set; }
|
||||||
}
|
}
|
||||||
@@ -8,5 +8,7 @@ public class GetContactDto
|
|||||||
public string? PhoneNumber { get; set; }
|
public string? PhoneNumber { get; set; }
|
||||||
public string? Email { get; set; }
|
public string? Email { get; set; }
|
||||||
public string? Address { get; set; }
|
public string? Address { get; set; }
|
||||||
|
public string? City { get; set; }
|
||||||
public string? Role { get; set; }
|
public string? Role { get; set; }
|
||||||
|
public int? CustomerId { get; set; }
|
||||||
}
|
}
|
||||||
7
PyroFetes/DTO/Customer/Request/CreateCustomerDto.cs
Normal file
7
PyroFetes/DTO/Customer/Request/CreateCustomerDto.cs
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
namespace PyroFetes.DTO.Customer.Request;
|
||||||
|
|
||||||
|
public class CreateCustomerDto
|
||||||
|
{
|
||||||
|
public string? Note { get; set; }
|
||||||
|
public int CustomerTypeId { get; set; }
|
||||||
|
}
|
||||||
6
PyroFetes/DTO/Customer/Request/GetCustomerRequest.cs
Normal file
6
PyroFetes/DTO/Customer/Request/GetCustomerRequest.cs
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
namespace PyroFetes.DTO.Customer.Request;
|
||||||
|
|
||||||
|
public class GetCustomerRequest
|
||||||
|
{
|
||||||
|
public int Id { get; set; }
|
||||||
|
}
|
||||||
7
PyroFetes/DTO/Customer/Request/UpdateCustomerDto.cs
Normal file
7
PyroFetes/DTO/Customer/Request/UpdateCustomerDto.cs
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
namespace PyroFetes.DTO.Customer.Request;
|
||||||
|
|
||||||
|
public class UpdateCustomerDto
|
||||||
|
{
|
||||||
|
public int Id { get; set; }
|
||||||
|
public string? Note { get; set; }
|
||||||
|
}
|
||||||
9
PyroFetes/DTO/Customer/Response/GetCustomerDto.cs
Normal file
9
PyroFetes/DTO/Customer/Response/GetCustomerDto.cs
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
namespace PyroFetes.DTO.Customer.Response;
|
||||||
|
|
||||||
|
public class GetCustomerDto
|
||||||
|
{
|
||||||
|
public int Id { get; set; }
|
||||||
|
public string? Note { get; set; }
|
||||||
|
|
||||||
|
public int CustomerTypeId { get; set; }
|
||||||
|
}
|
||||||
@@ -0,0 +1,6 @@
|
|||||||
|
namespace PyroFetes.DTO.CustomerType.Request;
|
||||||
|
|
||||||
|
public class CreateCustomerTypeDto
|
||||||
|
{
|
||||||
|
public string? Label { get; set; }
|
||||||
|
}
|
||||||
@@ -0,0 +1,6 @@
|
|||||||
|
namespace PyroFetes.DTO.CustomerType.Request;
|
||||||
|
|
||||||
|
public class GetCustomerTypeRequest
|
||||||
|
{
|
||||||
|
public int Id { get; set; }
|
||||||
|
}
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
namespace PyroFetes.DTO.CustomerType.Request;
|
||||||
|
|
||||||
|
public class UpdateCustomerTypeDto
|
||||||
|
{
|
||||||
|
public int Id { get; set; }
|
||||||
|
public string? Label { get; set; }
|
||||||
|
}
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
namespace PyroFetes.DTO.CustomerType.Response;
|
||||||
|
|
||||||
|
public class GetCustomerTypeDto
|
||||||
|
{
|
||||||
|
public int Id { get; set; }
|
||||||
|
public string? Label { get; set; }
|
||||||
|
}
|
||||||
6
PyroFetes/DTO/Provider/Request/CreateProviderDto.cs
Normal file
6
PyroFetes/DTO/Provider/Request/CreateProviderDto.cs
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
namespace PyroFetes.DTO.Provider.Request;
|
||||||
|
|
||||||
|
public class CreateProviderDto
|
||||||
|
{
|
||||||
|
public decimal Price { get; set; }
|
||||||
|
}
|
||||||
6
PyroFetes/DTO/Provider/Request/GetProviderRequest.cs
Normal file
6
PyroFetes/DTO/Provider/Request/GetProviderRequest.cs
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
namespace PyroFetes.DTO.Provider.Request;
|
||||||
|
|
||||||
|
public class GetProviderRequest
|
||||||
|
{
|
||||||
|
public int Id { get; set; }
|
||||||
|
}
|
||||||
7
PyroFetes/DTO/Provider/Request/UpdateProviderDto.cs
Normal file
7
PyroFetes/DTO/Provider/Request/UpdateProviderDto.cs
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
namespace PyroFetes.DTO.Provider.Request;
|
||||||
|
|
||||||
|
public class UpdateProviderDto
|
||||||
|
{
|
||||||
|
public int Id { get; set; }
|
||||||
|
public decimal Price { get; set; }
|
||||||
|
}
|
||||||
7
PyroFetes/DTO/Provider/Response/GetProviderDto.cs
Normal file
7
PyroFetes/DTO/Provider/Response/GetProviderDto.cs
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
namespace PyroFetes.DTO.Provider.Response;
|
||||||
|
|
||||||
|
public class GetProviderDto
|
||||||
|
{
|
||||||
|
public int Id { get; set; }
|
||||||
|
public decimal Price { get; set; }
|
||||||
|
}
|
||||||
@@ -0,0 +1,6 @@
|
|||||||
|
namespace PyroFetes.DTO.ProviderType.Request;
|
||||||
|
|
||||||
|
public class CreateProviderTypeDto
|
||||||
|
{
|
||||||
|
public string? Label { get; set; }
|
||||||
|
}
|
||||||
@@ -0,0 +1,6 @@
|
|||||||
|
namespace PyroFetes.DTO.ProviderType.Request;
|
||||||
|
|
||||||
|
public class GetProviderTypeRequest
|
||||||
|
{
|
||||||
|
public int Id { get; set; }
|
||||||
|
}
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
namespace PyroFetes.DTO.ProviderType.Request;
|
||||||
|
|
||||||
|
public class UpdateProviderTypeDto
|
||||||
|
{
|
||||||
|
public int Id { get; set; }
|
||||||
|
public string? Label { get; set; }
|
||||||
|
}
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
namespace PyroFetes.DTO.ProviderType.Response;
|
||||||
|
|
||||||
|
public class GetProviderTypeDto
|
||||||
|
{
|
||||||
|
public int Id { get; set; }
|
||||||
|
public string? Label { get; set; }
|
||||||
|
}
|
||||||
@@ -8,7 +8,7 @@ public class CreateAvailabilityEndpoint(PyroFetesDbContext pyroFetesDbContext) :
|
|||||||
{
|
{
|
||||||
public override void Configure()
|
public override void Configure()
|
||||||
{
|
{
|
||||||
Post("/api/availabilities");
|
Post("/availabilities");
|
||||||
AllowAnonymous();
|
AllowAnonymous();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ public class DeleteAvailabilityEndpoint(PyroFetesDbContext pyroFetesDbContext) :
|
|||||||
{
|
{
|
||||||
public override void Configure()
|
public override void Configure()
|
||||||
{
|
{
|
||||||
Delete ("/api/availabilities/{@Id}", x => new { x.Id });
|
Delete ("/availabilities/{@Id}", x => new { x.Id });
|
||||||
AllowAnonymous();
|
AllowAnonymous();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ public class GetAllAvailabilityxuest(PyroFetesDbContext pyroFetesDbContext) : En
|
|||||||
{
|
{
|
||||||
public override void Configure()
|
public override void Configure()
|
||||||
{
|
{
|
||||||
Get ("/api/availabilities");
|
Get ("/availabilities");
|
||||||
AllowAnonymous();
|
AllowAnonymous();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ public class GetAvailabilityEndpoint(PyroFetesDbContext pyroFetesDbContext) : En
|
|||||||
{
|
{
|
||||||
public override void Configure()
|
public override void Configure()
|
||||||
{
|
{
|
||||||
Get ("/api/availabilities/{@Id}", x => new { x.Id });
|
Get ("/availabilities/{@Id}", x => new { x.Id });
|
||||||
AllowAnonymous();
|
AllowAnonymous();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ public class UpdateAvailabilityEndpoint(PyroFetesDbContext pyroFetesDbContext) :
|
|||||||
{
|
{
|
||||||
public override void Configure()
|
public override void Configure()
|
||||||
{
|
{
|
||||||
Put ("/api/availabilities/{@Id}", x => new { x.Id });
|
Put ("/availabilities/{@Id}", x => new { x.Id });
|
||||||
AllowAnonymous();
|
AllowAnonymous();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ public class CreateCommunicationEndpoint(PyroFetesDbContext pyroFetesDbContext)
|
|||||||
{
|
{
|
||||||
public override void Configure()
|
public override void Configure()
|
||||||
{
|
{
|
||||||
Post("/api/communications");
|
Post("/communications");
|
||||||
AllowAnonymous();
|
AllowAnonymous();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -5,11 +5,11 @@ using PyroFetes.DTO.Communication.Response;
|
|||||||
|
|
||||||
namespace PyroFetes.Endpoints.Communication;
|
namespace PyroFetes.Endpoints.Communication;
|
||||||
|
|
||||||
public class DeleteCommunicationEndpoint(PyroFetesDbContext pyroFetesDbContext) : Endpoint <GetCommunicationDto, GetCommunicationEndpoint>
|
public class DeleteCommunicationEndpoint(PyroFetesDbContext pyroFetesDbContext) : Endpoint <GetCommunicationDto, GetAllCommunicationsEndpoint>
|
||||||
{
|
{
|
||||||
public override void Configure()
|
public override void Configure()
|
||||||
{
|
{
|
||||||
Delete ("/api/availabilities/{@Id}", x => new { x.Id });
|
Delete ("/communications/{@Id}", x => new { x.Id });
|
||||||
AllowAnonymous();
|
AllowAnonymous();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,27 @@
|
|||||||
|
using FastEndpoints;
|
||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
using PyroFetes.DTO.Communication.Response;
|
||||||
|
|
||||||
|
namespace PyroFetes.Endpoints.Communication;
|
||||||
|
|
||||||
|
public class GetAllCommunicationsEndpoint(PyroFetesDbContext pyroFetesDbContext) : EndpointWithoutRequest<List<GetCommunicationDto>>
|
||||||
|
{
|
||||||
|
public override void Configure()
|
||||||
|
{
|
||||||
|
Get ("/communications");
|
||||||
|
AllowAnonymous();
|
||||||
|
}
|
||||||
|
|
||||||
|
public override async Task HandleAsync(CancellationToken ct)
|
||||||
|
{
|
||||||
|
List<GetCommunicationDto> communications = await pyroFetesDbContext.Communications.Select(x => new GetCommunicationDto()
|
||||||
|
{
|
||||||
|
Id = x.Id,
|
||||||
|
Calling = x.Calling,
|
||||||
|
Email = x.Email,
|
||||||
|
Meeting = x.Meeting,
|
||||||
|
}).ToListAsync(ct);
|
||||||
|
|
||||||
|
await Send.OkAsync(communications, ct);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,28 +1,36 @@
|
|||||||
using FastEndpoints;
|
using FastEndpoints;
|
||||||
using Microsoft.EntityFrameworkCore;
|
using Microsoft.EntityFrameworkCore;
|
||||||
using PyroFetes.DTO.Availability.Response;
|
using PyroFetes.DTO.Communication.Request;
|
||||||
using PyroFetes.DTO.Communication.Response;
|
using PyroFetes.DTO.Communication.Response;
|
||||||
|
|
||||||
namespace PyroFetes.Endpoints.Communication;
|
namespace PyroFetes.Endpoints.Communication;
|
||||||
|
|
||||||
public class GetCommunicationEndpoint(PyroFetesDbContext pyroFetesDbContext) : EndpointWithoutRequest<List<GetCommunicationDto>>
|
public class GetCommunicationEndpoint(PyroFetesDbContext pyroFetesDbContext) : Endpoint <GetCommunicationRequest, GetCommunicationDto>
|
||||||
{
|
{
|
||||||
public override void Configure()
|
public override void Configure()
|
||||||
{
|
{
|
||||||
Get ("/api/availabilities");
|
Get ("/communications/{@Id}", x => new { x.Id });
|
||||||
AllowAnonymous();
|
AllowAnonymous();
|
||||||
}
|
}
|
||||||
|
|
||||||
public override async Task HandleAsync(CancellationToken ct)
|
public override async Task HandleAsync(GetCommunicationRequest database, CancellationToken ct)
|
||||||
{
|
{
|
||||||
List<GetCommunicationDto> communications = await pyroFetesDbContext.Communications.Select(x => new GetCommunicationDto()
|
Models.Communication? databaseCommunications = await pyroFetesDbContext.Communications.SingleOrDefaultAsync(x => x.Id == database.Id, cancellationToken: ct);
|
||||||
{
|
|
||||||
Id = x.Id,
|
|
||||||
Calling = x.Calling,
|
|
||||||
Email = x.Email,
|
|
||||||
Meeting = x.Meeting,
|
|
||||||
}).ToListAsync(ct);
|
|
||||||
|
|
||||||
await Send.OkAsync(communications, ct);
|
if (databaseCommunications == null)
|
||||||
|
{
|
||||||
|
await Send.NotFoundAsync(ct);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
GetCommunicationDto dto = new()
|
||||||
|
{
|
||||||
|
Id = databaseCommunications.Id,
|
||||||
|
Calling = databaseCommunications.Calling,
|
||||||
|
Email = databaseCommunications.Email,
|
||||||
|
Meeting = databaseCommunications.Meeting
|
||||||
|
};
|
||||||
|
|
||||||
|
await Send.OkAsync(dto, ct);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,43 @@
|
|||||||
|
using FastEndpoints;
|
||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
using PyroFetes.DTO.Communication.Request;
|
||||||
|
using PyroFetes.DTO.Communication.Response;
|
||||||
|
|
||||||
|
namespace PyroFetes.Endpoints.Communication;
|
||||||
|
|
||||||
|
public class UpdateCommunicationEndpoint(PyroFetesDbContext pyroFetesDbContext) : Endpoint <UpdateCommunicationDto, GetCommunicationDto>
|
||||||
|
{
|
||||||
|
public override void Configure()
|
||||||
|
{
|
||||||
|
Put ("/communications/{@Id}", x => new { x.Id });
|
||||||
|
AllowAnonymous();
|
||||||
|
}
|
||||||
|
|
||||||
|
public override async Task HandleAsync(UpdateCommunicationDto req, CancellationToken ct)
|
||||||
|
{
|
||||||
|
Models.Communication? databaseCommunication = await pyroFetesDbContext.Communications.SingleOrDefaultAsync(x => x.Id == req.Id, cancellationToken: ct);
|
||||||
|
|
||||||
|
if (databaseCommunication == null)
|
||||||
|
{
|
||||||
|
await Send.NotFoundAsync(ct);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
databaseCommunication.Calling = req.Calling;
|
||||||
|
databaseCommunication.Email = req.Email;
|
||||||
|
databaseCommunication.Meeting = req.Meeting;
|
||||||
|
}
|
||||||
|
await pyroFetesDbContext.SaveChangesAsync(ct);
|
||||||
|
|
||||||
|
GetCommunicationDto dto = new()
|
||||||
|
{
|
||||||
|
Id = databaseCommunication.Id,
|
||||||
|
Calling = req.Calling,
|
||||||
|
Email = req.Email,
|
||||||
|
Meeting = req.Meeting,
|
||||||
|
};
|
||||||
|
|
||||||
|
await Send.OkAsync(dto, ct);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,4 +1,5 @@
|
|||||||
using FastEndpoints;
|
using FastEndpoints;
|
||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
using PyroFetes.DTO.Contact.Request;
|
using PyroFetes.DTO.Contact.Request;
|
||||||
using PyroFetes.DTO.Contact.Response;
|
using PyroFetes.DTO.Contact.Response;
|
||||||
|
|
||||||
@@ -8,13 +9,22 @@ public class CreateContactEndpoint(PyroFetesDbContext pyroFetesDbContext) : Endp
|
|||||||
{
|
{
|
||||||
public override void Configure()
|
public override void Configure()
|
||||||
{
|
{
|
||||||
Post("/api/contacts");
|
Post("/contacts");
|
||||||
AllowAnonymous();
|
AllowAnonymous();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public override async Task HandleAsync(CreateContactDto req, CancellationToken ct)
|
public override async Task HandleAsync(CreateContactDto req, CancellationToken ct)
|
||||||
{
|
{
|
||||||
|
Models.Customer? databaseCustomer = await pyroFetesDbContext.Customers.SingleOrDefaultAsync(x => x.Id == req.CustomerId, cancellationToken: ct);
|
||||||
|
|
||||||
|
if (databaseCustomer == null)
|
||||||
|
{
|
||||||
|
await Send.NotFoundAsync(ct);
|
||||||
|
Console.WriteLine("Customer not found");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
Models.Contact contact = new()
|
Models.Contact contact = new()
|
||||||
{
|
{
|
||||||
LastName = req.LastName,
|
LastName = req.LastName,
|
||||||
@@ -22,7 +32,9 @@ public class CreateContactEndpoint(PyroFetesDbContext pyroFetesDbContext) : Endp
|
|||||||
PhoneNumber = req.PhoneNumber,
|
PhoneNumber = req.PhoneNumber,
|
||||||
Email = req.Email,
|
Email = req.Email,
|
||||||
Address = req.Address,
|
Address = req.Address,
|
||||||
|
City = req.City,
|
||||||
Role = req.Role,
|
Role = req.Role,
|
||||||
|
CustomerId = databaseCustomer.Id,
|
||||||
};
|
};
|
||||||
pyroFetesDbContext.Add(contact);
|
pyroFetesDbContext.Add(contact);
|
||||||
await pyroFetesDbContext.SaveChangesAsync(ct);
|
await pyroFetesDbContext.SaveChangesAsync(ct);
|
||||||
@@ -34,7 +46,9 @@ public class CreateContactEndpoint(PyroFetesDbContext pyroFetesDbContext) : Endp
|
|||||||
PhoneNumber = contact.PhoneNumber,
|
PhoneNumber = contact.PhoneNumber,
|
||||||
Email = contact.Email,
|
Email = contact.Email,
|
||||||
Address = contact.Address,
|
Address = contact.Address,
|
||||||
|
City = contact.City,
|
||||||
Role = contact.Role,
|
Role = contact.Role,
|
||||||
|
CustomerId = contact.CustomerId,
|
||||||
};
|
};
|
||||||
|
|
||||||
await Send.OkAsync(response, ct);
|
await Send.OkAsync(response, ct);
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ public class DeleteContactEndpoint(PyroFetesDbContext pyroFetesDbContext) : Endp
|
|||||||
{
|
{
|
||||||
public override void Configure()
|
public override void Configure()
|
||||||
{
|
{
|
||||||
Delete ("/api/Contacts/{@Id}", x => new { x.Id });
|
Delete ("/contacts/{@Id}", x => new { x.Id });
|
||||||
AllowAnonymous();
|
AllowAnonymous();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ public class GetAllContactxuest(PyroFetesDbContext pyroFetesDbContext) : Endpoin
|
|||||||
{
|
{
|
||||||
public override void Configure()
|
public override void Configure()
|
||||||
{
|
{
|
||||||
Get ("/api/contacts");
|
Get ("/contacts");
|
||||||
AllowAnonymous();
|
AllowAnonymous();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ public class GetContactEndpoint(PyroFetesDbContext pyroFetesDbContext) : Endpoin
|
|||||||
{
|
{
|
||||||
public override void Configure()
|
public override void Configure()
|
||||||
{
|
{
|
||||||
Get ("/api/contacts/{@Id}", x => new { x.Id });
|
Get ("/contacts/{@Id}", x => new { x.Id });
|
||||||
AllowAnonymous();
|
AllowAnonymous();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ public class UpdateContactRequest(PyroFetesDbContext pyroFetesDbContext) : Endpo
|
|||||||
{
|
{
|
||||||
public override void Configure()
|
public override void Configure()
|
||||||
{
|
{
|
||||||
Put ("/api/contacts/{@Id}", x => new { x.Id });
|
Put ("/contacts/{@Id}", x => new { x.Id });
|
||||||
AllowAnonymous();
|
AllowAnonymous();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
47
PyroFetes/Endpoints/Customer/CreateCustomerEndpoint.cs
Normal file
47
PyroFetes/Endpoints/Customer/CreateCustomerEndpoint.cs
Normal file
@@ -0,0 +1,47 @@
|
|||||||
|
using FastEndpoints;
|
||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
using PyroFetes.DTO.Customer.Request;
|
||||||
|
using PyroFetes.DTO.Customer.Response;
|
||||||
|
|
||||||
|
namespace PyroFetes.Endpoints.Customer;
|
||||||
|
|
||||||
|
public class CreateCustomerEndpoint(PyroFetesDbContext pyroFetesDbContext) : Endpoint<CreateCustomerDto, GetCustomerDto>
|
||||||
|
{
|
||||||
|
public override void Configure()
|
||||||
|
{
|
||||||
|
Post("/customers");
|
||||||
|
AllowAnonymous();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public override async Task HandleAsync(CreateCustomerDto req, CancellationToken ct)
|
||||||
|
{
|
||||||
|
Models.CustomerType? databaseCustomerType = await pyroFetesDbContext.CustomerTypes.SingleOrDefaultAsync(x => x.Id == req.CustomerTypeId, cancellationToken: ct);
|
||||||
|
|
||||||
|
if (databaseCustomerType == null)
|
||||||
|
{
|
||||||
|
await Send.NotFoundAsync(ct);
|
||||||
|
Console.WriteLine("Customer Type not found");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
Models.Customer customer = new()
|
||||||
|
{
|
||||||
|
Note = req.Note,
|
||||||
|
CustomerTypeId = databaseCustomerType.Id,
|
||||||
|
|
||||||
|
};
|
||||||
|
pyroFetesDbContext.Add(customer);
|
||||||
|
await pyroFetesDbContext.SaveChangesAsync(ct);
|
||||||
|
|
||||||
|
GetCustomerDto response = new GetCustomerDto()
|
||||||
|
{
|
||||||
|
Id = customer.Id,
|
||||||
|
Note = customer.Note,
|
||||||
|
CustomerTypeId = customer.CustomerTypeId
|
||||||
|
};
|
||||||
|
|
||||||
|
await Send.OkAsync(response, ct);
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
30
PyroFetes/Endpoints/Customer/DeleteCustomerEndpoint.cs
Normal file
30
PyroFetes/Endpoints/Customer/DeleteCustomerEndpoint.cs
Normal file
@@ -0,0 +1,30 @@
|
|||||||
|
using FastEndpoints;
|
||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
using PyroFetes.DTO.Customer.Request;
|
||||||
|
using PyroFetes.DTO.Customer.Response;
|
||||||
|
|
||||||
|
namespace PyroFetes.Endpoints.Customer;
|
||||||
|
|
||||||
|
public class DeleteCustomerEndpoint(PyroFetesDbContext pyroFetesDbContext) : Endpoint <GetCustomerRequest, GetCustomerDto>
|
||||||
|
{
|
||||||
|
public override void Configure()
|
||||||
|
{
|
||||||
|
Delete ("/customers/{@Id}", x => new { x.Id });
|
||||||
|
AllowAnonymous();
|
||||||
|
}
|
||||||
|
|
||||||
|
public override async Task HandleAsync(GetCustomerRequest req, CancellationToken ct)
|
||||||
|
{
|
||||||
|
Models.Customer? databaseCustomer = await pyroFetesDbContext.Customers.SingleOrDefaultAsync(x => x.Id == req.Id, cancellationToken: ct);
|
||||||
|
|
||||||
|
if (databaseCustomer == null)
|
||||||
|
{
|
||||||
|
await Send.NotFoundAsync(ct);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
pyroFetesDbContext.Customers.Remove(databaseCustomer);
|
||||||
|
await pyroFetesDbContext.SaveChangesAsync(ct);
|
||||||
|
|
||||||
|
await Send.NoContentAsync(ct);
|
||||||
|
}
|
||||||
|
}
|
||||||
25
PyroFetes/Endpoints/Customer/GetAllCustomerEndpoint.cs
Normal file
25
PyroFetes/Endpoints/Customer/GetAllCustomerEndpoint.cs
Normal file
@@ -0,0 +1,25 @@
|
|||||||
|
using FastEndpoints;
|
||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
using PyroFetes.DTO.Customer.Response;
|
||||||
|
|
||||||
|
namespace PyroFetes.Endpoints.Customer;
|
||||||
|
|
||||||
|
public class GetAllCustomerEndpoint(PyroFetesDbContext pyroFetesDbContext) : EndpointWithoutRequest<List<GetCustomerDto>>
|
||||||
|
{
|
||||||
|
public override void Configure()
|
||||||
|
{
|
||||||
|
Get ("/customers");
|
||||||
|
AllowAnonymous();
|
||||||
|
}
|
||||||
|
|
||||||
|
public override async Task HandleAsync(CancellationToken ct)
|
||||||
|
{
|
||||||
|
List<GetCustomerDto> customer= await pyroFetesDbContext.Customers.Select(x => new GetCustomerDto()
|
||||||
|
{
|
||||||
|
Id = x.Id,
|
||||||
|
Note = x.Note,
|
||||||
|
}).ToListAsync(ct);
|
||||||
|
|
||||||
|
await Send.OkAsync(customer, ct);
|
||||||
|
}
|
||||||
|
}
|
||||||
34
PyroFetes/Endpoints/Customer/GetCustomerEndpoint.cs
Normal file
34
PyroFetes/Endpoints/Customer/GetCustomerEndpoint.cs
Normal file
@@ -0,0 +1,34 @@
|
|||||||
|
using FastEndpoints;
|
||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
using PyroFetes.DTO.Customer.Request;
|
||||||
|
using PyroFetes.DTO.Customer.Response;
|
||||||
|
|
||||||
|
namespace PyroFetes.Endpoints.Customer;
|
||||||
|
|
||||||
|
public class GetCustomerEndpoint(PyroFetesDbContext pyroFetesDbContext) : Endpoint <GetCustomerRequest, GetCustomerDto>
|
||||||
|
{
|
||||||
|
public override void Configure()
|
||||||
|
{
|
||||||
|
Get ("/customers/{@Id}", x => new { x.Id });
|
||||||
|
AllowAnonymous();
|
||||||
|
}
|
||||||
|
|
||||||
|
public override async Task HandleAsync(GetCustomerRequest req, CancellationToken ct)
|
||||||
|
{
|
||||||
|
Models.Customer? databaseCustomer = await pyroFetesDbContext.Customers.SingleOrDefaultAsync(x => x.Id == req.Id, cancellationToken: ct);
|
||||||
|
|
||||||
|
if (databaseCustomer == null)
|
||||||
|
{
|
||||||
|
await Send.NotFoundAsync(ct);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
GetCustomerDto dto = new()
|
||||||
|
{
|
||||||
|
Id = databaseCustomer.Id,
|
||||||
|
Note = databaseCustomer.Note,
|
||||||
|
};
|
||||||
|
|
||||||
|
await Send.OkAsync(dto, ct);
|
||||||
|
}
|
||||||
|
}
|
||||||
38
PyroFetes/Endpoints/Customer/UpdateCustomerEndpoint.cs
Normal file
38
PyroFetes/Endpoints/Customer/UpdateCustomerEndpoint.cs
Normal file
@@ -0,0 +1,38 @@
|
|||||||
|
using FastEndpoints;
|
||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
using PyroFetes.DTO.Customer.Request;
|
||||||
|
using PyroFetes.DTO.Customer.Response;
|
||||||
|
|
||||||
|
namespace PyroFetes.Endpoints.Customer;
|
||||||
|
|
||||||
|
public class UpdateCustomer(PyroFetesDbContext pyroFetesDbContext) : Endpoint <UpdateCustomerDto, GetCustomerDto>
|
||||||
|
{
|
||||||
|
public override void Configure()
|
||||||
|
{
|
||||||
|
Put ("/customers/{@Id}", x => new { x.Id });
|
||||||
|
AllowAnonymous();
|
||||||
|
}
|
||||||
|
|
||||||
|
public override async Task HandleAsync(UpdateCustomerDto req, CancellationToken ct)
|
||||||
|
{
|
||||||
|
Models.Customer? databaseCustomer = await pyroFetesDbContext.Customers.SingleOrDefaultAsync(x => x.Id == req.Id, cancellationToken: ct);
|
||||||
|
|
||||||
|
if (databaseCustomer == null)
|
||||||
|
{
|
||||||
|
await Send.NotFoundAsync(ct);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
databaseCustomer.Note = req.Note;
|
||||||
|
}
|
||||||
|
await pyroFetesDbContext.SaveChangesAsync(ct);
|
||||||
|
|
||||||
|
GetCustomerDto dto = new()
|
||||||
|
{
|
||||||
|
Id = databaseCustomer.Id,
|
||||||
|
};
|
||||||
|
|
||||||
|
await Send.OkAsync(dto, ct);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,34 @@
|
|||||||
|
using FastEndpoints;
|
||||||
|
using PyroFetes.DTO.CustomerType.Response;
|
||||||
|
using PyroFetes.DTO.CustomerType.Request;
|
||||||
|
|
||||||
|
namespace PyroFetes.Endpoints.CustomerType;
|
||||||
|
|
||||||
|
public class CreateCustomerTypeEndpoint(PyroFetesDbContext pyroFetesDbContext) : Endpoint<CreateCustomerTypeDto, GetCustomerTypeDto>
|
||||||
|
{
|
||||||
|
public override void Configure()
|
||||||
|
{
|
||||||
|
Post("/customertypes");
|
||||||
|
AllowAnonymous();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public override async Task HandleAsync(CreateCustomerTypeDto req, CancellationToken ct)
|
||||||
|
{
|
||||||
|
var customerType = new Models.CustomerType
|
||||||
|
{
|
||||||
|
Label = req.Label
|
||||||
|
};
|
||||||
|
pyroFetesDbContext.Add(customerType);
|
||||||
|
await pyroFetesDbContext.SaveChangesAsync(ct);
|
||||||
|
|
||||||
|
GetCustomerTypeDto response = new GetCustomerTypeDto()
|
||||||
|
{
|
||||||
|
Id = customerType.Id,
|
||||||
|
Label = customerType.Label
|
||||||
|
};
|
||||||
|
|
||||||
|
await Send.OkAsync(response, ct);
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,30 @@
|
|||||||
|
using FastEndpoints;
|
||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
using PyroFetes.DTO.CustomerType.Request;
|
||||||
|
using PyroFetes.DTO.CustomerType.Response;
|
||||||
|
|
||||||
|
namespace PyroFetes.Endpoints.CustomerType;
|
||||||
|
|
||||||
|
public class DeleteCustomerTypeEndpoint(PyroFetesDbContext pyroFetesDbContext) : Endpoint <GetCustomerTypeRequest, GetCustomerTypeDto>
|
||||||
|
{
|
||||||
|
public override void Configure()
|
||||||
|
{
|
||||||
|
Delete ("/customertypes/{@Id}", x => new { x.Id });
|
||||||
|
AllowAnonymous();
|
||||||
|
}
|
||||||
|
|
||||||
|
public override async Task HandleAsync(GetCustomerTypeRequest req, CancellationToken ct)
|
||||||
|
{
|
||||||
|
Models.CustomerType? databaseCustomerType = await pyroFetesDbContext.CustomerTypes.SingleOrDefaultAsync(x => x.Id == req.Id, cancellationToken: ct);
|
||||||
|
|
||||||
|
if (databaseCustomerType == null)
|
||||||
|
{
|
||||||
|
await Send.NotFoundAsync(ct);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
pyroFetesDbContext.CustomerTypes.Remove(databaseCustomerType);
|
||||||
|
await pyroFetesDbContext.SaveChangesAsync(ct);
|
||||||
|
|
||||||
|
await Send.NoContentAsync(ct);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,25 @@
|
|||||||
|
using FastEndpoints;
|
||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
using PyroFetes.DTO.CustomerType.Response;
|
||||||
|
|
||||||
|
namespace PyroFetes.Endpoints.CustomerType;
|
||||||
|
|
||||||
|
public class GetAllCustomerTypeEndpoint(PyroFetesDbContext pyroFetesDbContext) : EndpointWithoutRequest<List<GetCustomerTypeDto>>
|
||||||
|
{
|
||||||
|
public override void Configure()
|
||||||
|
{
|
||||||
|
Get ("/customertypes");
|
||||||
|
AllowAnonymous();
|
||||||
|
}
|
||||||
|
|
||||||
|
public override async Task HandleAsync(CancellationToken ct)
|
||||||
|
{
|
||||||
|
List<GetCustomerTypeDto> customerType= await pyroFetesDbContext.CustomerTypes.Select(x => new GetCustomerTypeDto()
|
||||||
|
{
|
||||||
|
Id = x.Id,
|
||||||
|
Label = x.Label,
|
||||||
|
}).ToListAsync(ct);
|
||||||
|
|
||||||
|
await Send.OkAsync(customerType, ct);
|
||||||
|
}
|
||||||
|
}
|
||||||
34
PyroFetes/Endpoints/CustomerType/GetCustomerTypeEndpoint.cs
Normal file
34
PyroFetes/Endpoints/CustomerType/GetCustomerTypeEndpoint.cs
Normal file
@@ -0,0 +1,34 @@
|
|||||||
|
using FastEndpoints;
|
||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
using PyroFetes.DTO.CustomerType.Request;
|
||||||
|
using PyroFetes.DTO.CustomerType.Response;
|
||||||
|
|
||||||
|
namespace PyroFetes.Endpoints.CustomerType;
|
||||||
|
|
||||||
|
public class GetCustomerTypeEndpoint(PyroFetesDbContext pyroFetesDbContext) : Endpoint <GetCustomerTypeRequest, GetCustomerTypeDto>
|
||||||
|
{
|
||||||
|
public override void Configure()
|
||||||
|
{
|
||||||
|
Get ("/customertypes/{@Id}", x => new { x.Id });
|
||||||
|
AllowAnonymous();
|
||||||
|
}
|
||||||
|
|
||||||
|
public override async Task HandleAsync(GetCustomerTypeRequest req, CancellationToken ct)
|
||||||
|
{
|
||||||
|
Models.CustomerType? databaseCustomerType = await pyroFetesDbContext.CustomerTypes.SingleOrDefaultAsync(x => x.Id == req.Id, cancellationToken: ct);
|
||||||
|
|
||||||
|
if (databaseCustomerType == null)
|
||||||
|
{
|
||||||
|
await Send.NotFoundAsync(ct);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
GetCustomerTypeDto dto = new()
|
||||||
|
{
|
||||||
|
Id = databaseCustomerType.Id,
|
||||||
|
Label = databaseCustomerType.Label,
|
||||||
|
};
|
||||||
|
|
||||||
|
await Send.OkAsync(dto, ct);
|
||||||
|
}
|
||||||
|
}
|
||||||
38
PyroFetes/Endpoints/CustomerType/UpdateCustomerEndpoint.cs
Normal file
38
PyroFetes/Endpoints/CustomerType/UpdateCustomerEndpoint.cs
Normal file
@@ -0,0 +1,38 @@
|
|||||||
|
using FastEndpoints;
|
||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
using PyroFetes.DTO.CustomerType.Request;
|
||||||
|
using PyroFetes.DTO.CustomerType.Response;
|
||||||
|
|
||||||
|
namespace PyroFetes.Endpoints.CustomerType;
|
||||||
|
|
||||||
|
public class UpdateCustomerType(PyroFetesDbContext pyroFetesDbContext) : Endpoint <UpdateCustomerTypeDto, GetCustomerTypeDto>
|
||||||
|
{
|
||||||
|
public override void Configure()
|
||||||
|
{
|
||||||
|
Put ("/customertypes/{@Id}", x => new { x.Id });
|
||||||
|
AllowAnonymous();
|
||||||
|
}
|
||||||
|
|
||||||
|
public override async Task HandleAsync(UpdateCustomerTypeDto req, CancellationToken ct)
|
||||||
|
{
|
||||||
|
Models.CustomerType? databaseCustomerType = await pyroFetesDbContext.CustomerTypes.SingleOrDefaultAsync(x => x.Id == req.Id, cancellationToken: ct);
|
||||||
|
|
||||||
|
if (databaseCustomerType == null)
|
||||||
|
{
|
||||||
|
await Send.NotFoundAsync(ct);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
databaseCustomerType.Label = req.Label;
|
||||||
|
}
|
||||||
|
await pyroFetesDbContext.SaveChangesAsync(ct);
|
||||||
|
|
||||||
|
GetCustomerTypeDto dto = new()
|
||||||
|
{
|
||||||
|
Id = databaseCustomerType.Id,
|
||||||
|
};
|
||||||
|
|
||||||
|
await Send.OkAsync(dto, ct);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -9,7 +9,7 @@ public class CreateExperienceLevelEndpoint(PyroFetesDbContext pyroFetesDbContext
|
|||||||
{
|
{
|
||||||
public override void Configure()
|
public override void Configure()
|
||||||
{
|
{
|
||||||
Post("/api/ExperienceLevels");
|
Post("/experiencelevels");
|
||||||
AllowAnonymous();
|
AllowAnonymous();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ public class DeleteExerienceLevelEndpoint(PyroFetesDbContext pyroFetesDbContext)
|
|||||||
{
|
{
|
||||||
public override void Configure()
|
public override void Configure()
|
||||||
{
|
{
|
||||||
Delete ("/api/ExperienceLevels/{@Id}", x => new { x.Id });
|
Delete ("/experiencelevels/{@Id}", x => new { x.Id });
|
||||||
AllowAnonymous();
|
AllowAnonymous();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ public class GetAllExperienceLevelsEndpoint(PyroFetesDbContext pyroFetesDbContex
|
|||||||
{
|
{
|
||||||
public override void Configure()
|
public override void Configure()
|
||||||
{
|
{
|
||||||
Get ("/api/experienceLevels");
|
Get ("/experiencelevels");
|
||||||
AllowAnonymous();
|
AllowAnonymous();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ public class GetExperienceLevelEndpoint(PyroFetesDbContext pyroFetesDbContext) :
|
|||||||
{
|
{
|
||||||
public override void Configure()
|
public override void Configure()
|
||||||
{
|
{
|
||||||
Get ("/api/experienceLevels/{@Id}", x => new { x.Id });
|
Get ("/experiencelevels/{@Id}", x => new { x.Id });
|
||||||
AllowAnonymous();
|
AllowAnonymous();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ public class UpdateExperienceLevelEndpoint(PyroFetesDbContext pyroFetesDbContext
|
|||||||
{
|
{
|
||||||
public override void Configure()
|
public override void Configure()
|
||||||
{
|
{
|
||||||
Put ("/api/ExperienceLevels/{@Id}", x => new { x.Id });
|
Put ("/experiencelevels/{@Id}", x => new { x.Id });
|
||||||
AllowAnonymous();
|
AllowAnonymous();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ public class CreateHistoryOfApprovalEndpoint(PyroFetesDbContext pyroFetesDbConte
|
|||||||
{
|
{
|
||||||
public override void Configure()
|
public override void Configure()
|
||||||
{
|
{
|
||||||
Post("/api/HistoryOfApprovals");
|
Post("/historyofapprovals");
|
||||||
AllowAnonymous();
|
AllowAnonymous();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ public class DeleteHistoryOfApprovalEndpoint(PyroFetesDbContext pyroFetesDbConte
|
|||||||
{
|
{
|
||||||
public override void Configure()
|
public override void Configure()
|
||||||
{
|
{
|
||||||
Delete ("/api/HistoryOfApprovals/{@Id}", x => new { x.Id });
|
Delete ("/historyofapprovals/{@Id}", x => new { x.Id });
|
||||||
AllowAnonymous();
|
AllowAnonymous();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ public class GetAllHistoryOfApprovalEndpoint(PyroFetesDbContext pyroFetesDbConte
|
|||||||
{
|
{
|
||||||
public override void Configure()
|
public override void Configure()
|
||||||
{
|
{
|
||||||
Get ("/api/HistoryOfApprovals");
|
Get ("/historyofapprovals");
|
||||||
AllowAnonymous();
|
AllowAnonymous();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ public class GetHistoryOfApprovalEndpoint(PyroFetesDbContext pyroFetesDbContext)
|
|||||||
{
|
{
|
||||||
public override void Configure()
|
public override void Configure()
|
||||||
{
|
{
|
||||||
Get ("/api/HistoryOfApprovals/{@Id}", x => new { x.Id });
|
Get ("/historyofapprovals/{@Id}", x => new { x.Id });
|
||||||
AllowAnonymous();
|
AllowAnonymous();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ public class UpdateHistoryOfApprovalEndpoint(PyroFetesDbContext pyroFetesDbConte
|
|||||||
{
|
{
|
||||||
public override void Configure()
|
public override void Configure()
|
||||||
{
|
{
|
||||||
Put ("/api/HistoryOfApprovals/{@Id}", x => new { x.Id });
|
Put ("/historyofapprovals/{@Id}", x => new { x.Id });
|
||||||
AllowAnonymous();
|
AllowAnonymous();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
34
PyroFetes/Endpoints/Provider/CreateProviderEndpoint.cs
Normal file
34
PyroFetes/Endpoints/Provider/CreateProviderEndpoint.cs
Normal file
@@ -0,0 +1,34 @@
|
|||||||
|
using FastEndpoints;
|
||||||
|
using PyroFetes.DTO.Provider.Request;
|
||||||
|
using PyroFetes.DTO.Provider.Response;
|
||||||
|
|
||||||
|
namespace PyroFetes.Endpoints.Provider;
|
||||||
|
|
||||||
|
public class CreateProviderEndpoint(PyroFetesDbContext pyroFetesDbContext) : Endpoint<CreateProviderDto, GetProviderDto>
|
||||||
|
{
|
||||||
|
public override void Configure()
|
||||||
|
{
|
||||||
|
Post("/providers");
|
||||||
|
AllowAnonymous();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public override async Task HandleAsync(CreateProviderDto req, CancellationToken ct)
|
||||||
|
{
|
||||||
|
var provider = new Models.ServiceProvider()
|
||||||
|
{
|
||||||
|
Price = req.Price
|
||||||
|
};
|
||||||
|
pyroFetesDbContext.Add(provider);
|
||||||
|
await pyroFetesDbContext.SaveChangesAsync(ct);
|
||||||
|
|
||||||
|
GetProviderDto response = new GetProviderDto()
|
||||||
|
{
|
||||||
|
Id = provider.Id,
|
||||||
|
Price = provider.Price
|
||||||
|
};
|
||||||
|
|
||||||
|
await Send.OkAsync(response, ct);
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
30
PyroFetes/Endpoints/Provider/DeleteProviderEndpoint.cs
Normal file
30
PyroFetes/Endpoints/Provider/DeleteProviderEndpoint.cs
Normal file
@@ -0,0 +1,30 @@
|
|||||||
|
using FastEndpoints;
|
||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
using PyroFetes.DTO.Provider.Request;
|
||||||
|
using PyroFetes.DTO.Provider.Response;
|
||||||
|
|
||||||
|
namespace PyroFetes.Endpoints.Provider;
|
||||||
|
|
||||||
|
public class DeleteProviderEndpoint(PyroFetesDbContext pyroFetesDbContext) : Endpoint <GetProviderRequest, GetProviderDto>
|
||||||
|
{
|
||||||
|
public override void Configure()
|
||||||
|
{
|
||||||
|
Delete ("/providers/{@Id}", x => new { x.Id });
|
||||||
|
AllowAnonymous();
|
||||||
|
}
|
||||||
|
|
||||||
|
public override async Task HandleAsync(GetProviderRequest req, CancellationToken ct)
|
||||||
|
{
|
||||||
|
Models.ServiceProvider? databaseProvider = await pyroFetesDbContext.Providers.SingleOrDefaultAsync(x => x.Id == req.Id, cancellationToken: ct);
|
||||||
|
|
||||||
|
if (databaseProvider == null)
|
||||||
|
{
|
||||||
|
await Send.NotFoundAsync(ct);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
pyroFetesDbContext.Providers.Remove(databaseProvider);
|
||||||
|
await pyroFetesDbContext.SaveChangesAsync(ct);
|
||||||
|
|
||||||
|
await Send.NoContentAsync(ct);
|
||||||
|
}
|
||||||
|
}
|
||||||
25
PyroFetes/Endpoints/Provider/GetAllProvidersEndpoint.cs
Normal file
25
PyroFetes/Endpoints/Provider/GetAllProvidersEndpoint.cs
Normal file
@@ -0,0 +1,25 @@
|
|||||||
|
using FastEndpoints;
|
||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
using PyroFetes.DTO.Provider.Response;
|
||||||
|
|
||||||
|
namespace PyroFetes.Endpoints.Provider;
|
||||||
|
|
||||||
|
public class GetAllProvidersEndpoint(PyroFetesDbContext pyroFetesDbContext) : EndpointWithoutRequest<List<GetProviderDto>>
|
||||||
|
{
|
||||||
|
public override void Configure()
|
||||||
|
{
|
||||||
|
Get ("/providers");
|
||||||
|
AllowAnonymous();
|
||||||
|
}
|
||||||
|
|
||||||
|
public override async Task HandleAsync(CancellationToken ct)
|
||||||
|
{
|
||||||
|
List<GetProviderDto> customer= await pyroFetesDbContext.Providers.Select(x => new GetProviderDto()
|
||||||
|
{
|
||||||
|
Id = x.Id,
|
||||||
|
Price = x.Price,
|
||||||
|
}).ToListAsync(ct);
|
||||||
|
|
||||||
|
await Send.OkAsync(customer, ct);
|
||||||
|
}
|
||||||
|
}
|
||||||
34
PyroFetes/Endpoints/Provider/GetProviderEndpoint.cs
Normal file
34
PyroFetes/Endpoints/Provider/GetProviderEndpoint.cs
Normal file
@@ -0,0 +1,34 @@
|
|||||||
|
using FastEndpoints;
|
||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
using PyroFetes.DTO.Provider.Request;
|
||||||
|
using PyroFetes.DTO.Provider.Response;
|
||||||
|
|
||||||
|
namespace PyroFetes.Endpoints.Provider;
|
||||||
|
|
||||||
|
public class GetProviderEndpoint(PyroFetesDbContext pyroFetesDbContext) : Endpoint <GetProviderRequest, GetProviderDto>
|
||||||
|
{
|
||||||
|
public override void Configure()
|
||||||
|
{
|
||||||
|
Get ("/providers/{@Id}", x => new { x.Id });
|
||||||
|
AllowAnonymous();
|
||||||
|
}
|
||||||
|
|
||||||
|
public override async Task HandleAsync(GetProviderRequest req, CancellationToken ct)
|
||||||
|
{
|
||||||
|
Models.ServiceProvider? databaseProvider = await pyroFetesDbContext.Providers.SingleOrDefaultAsync(x => x.Id == req.Id, cancellationToken: ct);
|
||||||
|
|
||||||
|
if (databaseProvider == null)
|
||||||
|
{
|
||||||
|
await Send.NotFoundAsync(ct);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
GetProviderDto dto = new()
|
||||||
|
{
|
||||||
|
Id = databaseProvider.Id,
|
||||||
|
Price = databaseProvider.Price,
|
||||||
|
};
|
||||||
|
|
||||||
|
await Send.OkAsync(dto, ct);
|
||||||
|
}
|
||||||
|
}
|
||||||
38
PyroFetes/Endpoints/Provider/UpdateProviderEndpoint.cs
Normal file
38
PyroFetes/Endpoints/Provider/UpdateProviderEndpoint.cs
Normal file
@@ -0,0 +1,38 @@
|
|||||||
|
using FastEndpoints;
|
||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
using PyroFetes.DTO.Provider.Request;
|
||||||
|
using PyroFetes.DTO.Provider.Response;
|
||||||
|
|
||||||
|
namespace PyroFetes.Endpoints.Provider;
|
||||||
|
|
||||||
|
public class UpdateProviderEndpoint(PyroFetesDbContext pyroFetesDbContext) : Endpoint <UpdateProviderDto, GetProviderDto>
|
||||||
|
{
|
||||||
|
public override void Configure()
|
||||||
|
{
|
||||||
|
Put ("/providers/{@Id}", x => new { x.Id });
|
||||||
|
AllowAnonymous();
|
||||||
|
}
|
||||||
|
|
||||||
|
public override async Task HandleAsync(UpdateProviderDto req, CancellationToken ct)
|
||||||
|
{
|
||||||
|
Models.ServiceProvider? databaseProvider = await pyroFetesDbContext.Providers.SingleOrDefaultAsync(x => x.Id == req.Id, cancellationToken: ct);
|
||||||
|
|
||||||
|
if (databaseProvider == null)
|
||||||
|
{
|
||||||
|
await Send.NotFoundAsync(ct);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
databaseProvider.Price = req.Price;
|
||||||
|
}
|
||||||
|
await pyroFetesDbContext.SaveChangesAsync(ct);
|
||||||
|
|
||||||
|
GetProviderDto dto = new()
|
||||||
|
{
|
||||||
|
Id = databaseProvider.Id,
|
||||||
|
};
|
||||||
|
|
||||||
|
await Send.OkAsync(dto, ct);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,34 @@
|
|||||||
|
using FastEndpoints;
|
||||||
|
using PyroFetes.DTO.ProviderType.Request;
|
||||||
|
using PyroFetes.DTO.ProviderType.Response;
|
||||||
|
|
||||||
|
namespace PyroFetes.Endpoints.ProviderType;
|
||||||
|
|
||||||
|
public class CreateProviderTypeEndpoint(PyroFetesDbContext pyroFetesDbContext) : Endpoint<CreateProviderTypeDto, GetProviderTypeDto>
|
||||||
|
{
|
||||||
|
public override void Configure()
|
||||||
|
{
|
||||||
|
Post("/providertypes");
|
||||||
|
AllowAnonymous();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public override async Task HandleAsync(CreateProviderTypeDto req, CancellationToken ct)
|
||||||
|
{
|
||||||
|
var providerType = new Models.ProviderType
|
||||||
|
{
|
||||||
|
Label = req.Label
|
||||||
|
};
|
||||||
|
pyroFetesDbContext.Add(providerType);
|
||||||
|
await pyroFetesDbContext.SaveChangesAsync(ct);
|
||||||
|
|
||||||
|
GetProviderTypeDto response = new GetProviderTypeDto()
|
||||||
|
{
|
||||||
|
Id = providerType.Id,
|
||||||
|
Label = providerType.Label
|
||||||
|
};
|
||||||
|
|
||||||
|
await Send.OkAsync(response, ct);
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,30 @@
|
|||||||
|
using FastEndpoints;
|
||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
using PyroFetes.DTO.ProviderType.Request;
|
||||||
|
using PyroFetes.DTO.ProviderType.Response;
|
||||||
|
|
||||||
|
namespace PyroFetes.Endpoints.ProviderType;
|
||||||
|
|
||||||
|
public class DeleteProviderTypeEndpoint(PyroFetesDbContext pyroFetesDbContext) : Endpoint <GetProviderTypeRequest, GetProviderTypeDto>
|
||||||
|
{
|
||||||
|
public override void Configure()
|
||||||
|
{
|
||||||
|
Delete ("/providertypes/{@Id}", x => new { x.Id });
|
||||||
|
AllowAnonymous();
|
||||||
|
}
|
||||||
|
|
||||||
|
public override async Task HandleAsync(GetProviderTypeRequest req, CancellationToken ct)
|
||||||
|
{
|
||||||
|
Models.ProviderType? databaseProviderType = await pyroFetesDbContext.ProviderTypes.SingleOrDefaultAsync(x => x.Id == req.Id, cancellationToken: ct);
|
||||||
|
|
||||||
|
if (databaseProviderType == null)
|
||||||
|
{
|
||||||
|
await Send.NotFoundAsync(ct);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
pyroFetesDbContext.ProviderTypes.Remove(databaseProviderType);
|
||||||
|
await pyroFetesDbContext.SaveChangesAsync(ct);
|
||||||
|
|
||||||
|
await Send.NoContentAsync(ct);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,25 @@
|
|||||||
|
using FastEndpoints;
|
||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
using PyroFetes.DTO.ProviderType.Response;
|
||||||
|
|
||||||
|
namespace PyroFetes.Endpoints.ProviderType;
|
||||||
|
|
||||||
|
public class GetAllProviderTypesEndpoint(PyroFetesDbContext pyroFetesDbContext) : EndpointWithoutRequest<List<GetProviderTypeDto>>
|
||||||
|
{
|
||||||
|
public override void Configure()
|
||||||
|
{
|
||||||
|
Get ("/providertype");
|
||||||
|
AllowAnonymous();
|
||||||
|
}
|
||||||
|
|
||||||
|
public override async Task HandleAsync(CancellationToken ct)
|
||||||
|
{
|
||||||
|
List<GetProviderTypeDto> providerType= await pyroFetesDbContext.ProviderTypes.Select(x => new GetProviderTypeDto()
|
||||||
|
{
|
||||||
|
Id = x.Id,
|
||||||
|
Label = x.Label,
|
||||||
|
}).ToListAsync(ct);
|
||||||
|
|
||||||
|
await Send.OkAsync(providerType, ct);
|
||||||
|
}
|
||||||
|
}
|
||||||
34
PyroFetes/Endpoints/ProviderType/GetProviderTypeEndpoint.cs
Normal file
34
PyroFetes/Endpoints/ProviderType/GetProviderTypeEndpoint.cs
Normal file
@@ -0,0 +1,34 @@
|
|||||||
|
using FastEndpoints;
|
||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
using PyroFetes.DTO.ProviderType.Request;
|
||||||
|
using PyroFetes.DTO.ProviderType.Response;
|
||||||
|
|
||||||
|
namespace PyroFetes.Endpoints.ProviderType;
|
||||||
|
|
||||||
|
public class GetProviderTypeEndpoint(PyroFetesDbContext pyroFetesDbContext) : Endpoint <GetProviderTypeRequest, GetProviderTypeDto>
|
||||||
|
{
|
||||||
|
public override void Configure()
|
||||||
|
{
|
||||||
|
Get ("/providertypes/{@Id}", x => new { x.Id });
|
||||||
|
AllowAnonymous();
|
||||||
|
}
|
||||||
|
|
||||||
|
public override async Task HandleAsync(GetProviderTypeRequest req, CancellationToken ct)
|
||||||
|
{
|
||||||
|
Models.ProviderType? databaseProviderType = await pyroFetesDbContext.ProviderTypes.SingleOrDefaultAsync(x => x.Id == req.Id, cancellationToken: ct);
|
||||||
|
|
||||||
|
if (databaseProviderType == null)
|
||||||
|
{
|
||||||
|
await Send.NotFoundAsync(ct);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
GetProviderTypeDto dto = new()
|
||||||
|
{
|
||||||
|
Id = databaseProviderType.Id,
|
||||||
|
Label = databaseProviderType.Label,
|
||||||
|
};
|
||||||
|
|
||||||
|
await Send.OkAsync(dto, ct);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,38 @@
|
|||||||
|
using FastEndpoints;
|
||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
using PyroFetes.DTO.ProviderType.Request;
|
||||||
|
using PyroFetes.DTO.ProviderType.Response;
|
||||||
|
|
||||||
|
namespace PyroFetes.Endpoints.ProviderType;
|
||||||
|
|
||||||
|
public class UpdateProviderTypeEndpoint(PyroFetesDbContext pyroFetesDbContext) : Endpoint <UpdateProviderTypeDto, GetProviderTypeDto>
|
||||||
|
{
|
||||||
|
public override void Configure()
|
||||||
|
{
|
||||||
|
Put ("/providertypes/{@Id}", x => new { x.Id });
|
||||||
|
AllowAnonymous();
|
||||||
|
}
|
||||||
|
|
||||||
|
public override async Task HandleAsync(UpdateProviderTypeDto req, CancellationToken ct)
|
||||||
|
{
|
||||||
|
Models.ProviderType? databaseProviderType = await pyroFetesDbContext.ProviderTypes.SingleOrDefaultAsync(x => x.Id == req.Id, cancellationToken: ct);
|
||||||
|
|
||||||
|
if (databaseProviderType == null)
|
||||||
|
{
|
||||||
|
await Send.NotFoundAsync(ct);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
databaseProviderType.Label = req.Label;
|
||||||
|
}
|
||||||
|
await pyroFetesDbContext.SaveChangesAsync(ct);
|
||||||
|
|
||||||
|
GetProviderTypeDto dto = new()
|
||||||
|
{
|
||||||
|
Id = databaseProviderType.Id,
|
||||||
|
};
|
||||||
|
|
||||||
|
await Send.OkAsync(dto, ct);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -8,7 +8,7 @@ public class CreateStaffEndpoint(PyroFetesDbContext pyroFetesDbContext) : Endpoi
|
|||||||
{
|
{
|
||||||
public override void Configure()
|
public override void Configure()
|
||||||
{
|
{
|
||||||
Post("/api/availabilities");
|
Post("/staffs");
|
||||||
AllowAnonymous();
|
AllowAnonymous();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ public class DeleteStaffEndpoint(PyroFetesDbContext pyroFetesDbContext) : Endpoi
|
|||||||
{
|
{
|
||||||
public override void Configure()
|
public override void Configure()
|
||||||
{
|
{
|
||||||
Delete ("/api/staff/{@Id}", x => new { x.Id });
|
Delete ("/staffs/{@Id}", x => new { x.Id });
|
||||||
AllowAnonymous();
|
AllowAnonymous();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ public class GetAllStaffsEndpoint(PyroFetesDbContext pyroFetesDbContext) : Endpo
|
|||||||
{
|
{
|
||||||
public override void Configure()
|
public override void Configure()
|
||||||
{
|
{
|
||||||
Get ("/api/availabilities");
|
Get ("/staffs");
|
||||||
AllowAnonymous();
|
AllowAnonymous();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ public class GetStaffEndpoint(PyroFetesDbContext pyroFetesDbContext) : Endpoint
|
|||||||
{
|
{
|
||||||
public override void Configure()
|
public override void Configure()
|
||||||
{
|
{
|
||||||
Get ("/api/Staffs/{@Id}", x => new { x.Id });
|
Get ("/staffs/{@Id}", x => new { x.Id });
|
||||||
AllowAnonymous();
|
AllowAnonymous();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ public class UpdateStaffRequest(PyroFetesDbContext pyroFetesDbContext) : Endpoin
|
|||||||
{
|
{
|
||||||
public override void Configure()
|
public override void Configure()
|
||||||
{
|
{
|
||||||
Put ("/api/Staffs/{@Id}", x => new { x.Id });
|
Put ("/staffs/{@Id}", x => new { x.Id });
|
||||||
AllowAnonymous();
|
AllowAnonymous();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
14
PyroFetes/Models/ContactCustomer.cs
Normal file
14
PyroFetes/Models/ContactCustomer.cs
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
using System.ComponentModel.DataAnnotations;
|
||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
|
||||||
|
namespace PyroFetes.Models;
|
||||||
|
|
||||||
|
[PrimaryKey(nameof(ContactId), nameof(CustomerId))]
|
||||||
|
public class ContactCustomer
|
||||||
|
{
|
||||||
|
[Required] public int ContactId { get; set; }
|
||||||
|
[Required] public int CustomerId { get; set; }
|
||||||
|
|
||||||
|
public Contact? Contact { get; set; }
|
||||||
|
public Customer? Customer { get; set; }
|
||||||
|
}
|
||||||
@@ -1,19 +1,43 @@
|
|||||||
var builder = WebApplication.CreateBuilder(args);
|
using PyroFetes;
|
||||||
|
using FastEndpoints;
|
||||||
|
using FastEndpoints.Swagger;
|
||||||
|
using FastEndpoints.Security;
|
||||||
|
|
||||||
// Add services to the container.
|
WebApplicationBuilder builder = WebApplication.CreateBuilder(args);
|
||||||
// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
|
|
||||||
builder.Services.AddEndpointsApiExplorer();
|
|
||||||
builder.Services.AddSwaggerGen();
|
|
||||||
|
|
||||||
var app = builder.Build();
|
// On ajoute ici FastEndpoints, un framework REPR et Swagger aux services disponibles dans le projet
|
||||||
|
builder.Services
|
||||||
|
.AddAuthenticationJwtBearer(s => s.SigningKey = "zewsxrdctfvgybuhbgyvftrcdtfvgbyuhn")
|
||||||
|
.AddAuthorization()
|
||||||
|
.AddFastEndpoints().SwaggerDocument(options => { options.ShortSchemaNames = true;});
|
||||||
|
|
||||||
// Configure the HTTP request pipeline.
|
// On ajoute ici la configuration de la base de données
|
||||||
if (app.Environment.IsDevelopment())
|
builder.Services.AddDbContext<PyroFetesDbContext>();
|
||||||
{
|
|
||||||
app.UseSwagger();
|
//On ajoute le CORS au code
|
||||||
app.UseSwaggerUI();
|
builder.Services.AddCors(options =>
|
||||||
}
|
{ options.AddDefaultPolicy(policyBuilder =>
|
||||||
|
{
|
||||||
|
policyBuilder
|
||||||
|
.WithOrigins("http://localhost:5298")
|
||||||
|
.WithMethods("GET", "POST", "PUT", "PATCH", "DELETE")
|
||||||
|
.AllowAnyHeader();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
// On construit l'application en lui donnant vie
|
||||||
|
WebApplication app = builder.Build();
|
||||||
|
app.UseAuthentication()
|
||||||
|
.UseAuthorization()
|
||||||
|
.UseFastEndpoints(options =>
|
||||||
|
{
|
||||||
|
options.Endpoints.RoutePrefix = "API";
|
||||||
|
options.Endpoints.ShortNames = true;
|
||||||
|
}
|
||||||
|
).UseSwaggerGen();
|
||||||
|
|
||||||
app.UseHttpsRedirection();
|
app.UseHttpsRedirection();
|
||||||
|
|
||||||
|
app.UseCors();
|
||||||
|
|
||||||
app.Run();
|
app.Run();
|
||||||
@@ -7,7 +7,9 @@
|
|||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
<PackageReference Include="BCrypt.Net-Next" Version="4.0.3" />
|
||||||
<PackageReference Include="FastEndpoints" Version="7.0.1" />
|
<PackageReference Include="FastEndpoints" Version="7.0.1" />
|
||||||
|
<PackageReference Include="FastEndpoints.Security" Version="7.0.1" />
|
||||||
<PackageReference Include="FastEndpoints.Swagger" Version="7.0.1" />
|
<PackageReference Include="FastEndpoints.Swagger" Version="7.0.1" />
|
||||||
<PackageReference Include="Microsoft.AspNetCore.OpenApi" Version="8.0.19"/>
|
<PackageReference Include="Microsoft.AspNetCore.OpenApi" Version="8.0.19"/>
|
||||||
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="8.0.20" />
|
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="8.0.20" />
|
||||||
|
|||||||
Reference in New Issue
Block a user