diff --git a/PyroFetes/DTO/Communication/Request/CreateCommunicationDto.cs b/PyroFetes/DTO/Communication/Request/CreateCommunicationDto.cs index cb8bbc2..47fa206 100644 --- a/PyroFetes/DTO/Communication/Request/CreateCommunicationDto.cs +++ b/PyroFetes/DTO/Communication/Request/CreateCommunicationDto.cs @@ -2,5 +2,7 @@ namespace PyroFetes.DTO.Communication.Request; public class CreateCommunicationDto { - + public string? Calling { get; set; } + public string? Email { get; set; } + public string? Meeting { get; set; } } \ No newline at end of file diff --git a/PyroFetes/DTO/Communication/Request/GetCommunicationRequest.cs b/PyroFetes/DTO/Communication/Request/GetCommunicationRequest.cs index 185f4d1..bcea23c 100644 --- a/PyroFetes/DTO/Communication/Request/GetCommunicationRequest.cs +++ b/PyroFetes/DTO/Communication/Request/GetCommunicationRequest.cs @@ -2,5 +2,5 @@ namespace PyroFetes.DTO.Communication.Request; public class GetCommunicationRequest { - + public int Id { get; set; } } \ No newline at end of file diff --git a/PyroFetes/DTO/Communication/Request/UpdateCommunicationDto.cs b/PyroFetes/DTO/Communication/Request/UpdateCommunicationDto.cs index 8cb9fcf..071832f 100644 --- a/PyroFetes/DTO/Communication/Request/UpdateCommunicationDto.cs +++ b/PyroFetes/DTO/Communication/Request/UpdateCommunicationDto.cs @@ -2,5 +2,8 @@ namespace PyroFetes.DTO.Communication.Request; public class UpdateCommunicationDto { - + public int Id { get; set; } + public string? Calling { get; set; } + public string? Email { get; set; } + public string? Meeting { get; set; } } \ No newline at end of file diff --git a/PyroFetes/DTO/Communication/Response/GetCommunicationDto.cs b/PyroFetes/DTO/Communication/Response/GetCommunicationDto.cs index de0f97d..ea0432d 100644 --- a/PyroFetes/DTO/Communication/Response/GetCommunicationDto.cs +++ b/PyroFetes/DTO/Communication/Response/GetCommunicationDto.cs @@ -1,7 +1,8 @@ namespace PyroFetes.DTO.Communication.Response; -public class GetCommunicationRequest +public class GetCommunicationDto { + public int Id { get; set; } public string? Calling { get; set; } public string? Email { get; set; } public string? Meeting { get; set; } diff --git a/PyroFetes/DTO/ExperienceLevel/Request/GetExperienceLevelRequest.cs b/PyroFetes/DTO/ExperienceLevel/Request/GetExperienceLevelDTO.cs similarity index 68% rename from PyroFetes/DTO/ExperienceLevel/Request/GetExperienceLevelRequest.cs rename to PyroFetes/DTO/ExperienceLevel/Request/GetExperienceLevelDTO.cs index a9991e5..c64b436 100644 --- a/PyroFetes/DTO/ExperienceLevel/Request/GetExperienceLevelRequest.cs +++ b/PyroFetes/DTO/ExperienceLevel/Request/GetExperienceLevelDTO.cs @@ -1,6 +1,6 @@ namespace PyroFetes.DTO.ExperienceLevel.Request; -public class GetExperienceLevelRequest +public class GetExperienceLevelDTO { public int Id { get; set; } } \ No newline at end of file diff --git a/PyroFetes/Endpoints/Communication/CreateCommunicationEndpoint.cs b/PyroFetes/Endpoints/Communication/CreateCommunicationEndpoint.cs new file mode 100644 index 0000000..3429d20 --- /dev/null +++ b/PyroFetes/Endpoints/Communication/CreateCommunicationEndpoint.cs @@ -0,0 +1,36 @@ +using FastEndpoints; +using PyroFetes.DTO.Communication.Request; +using PyroFetes.DTO.Communication.Response; + +namespace PyroFetes.Endpoints.Communication; + +public class CreateCommunicationEndpoint(PyroFetesDbContext pyroFetesDbContext) : Endpoint +{ + public override void Configure() + { + Post("/api/communications"); + AllowAnonymous(); + } + + + public override async Task HandleAsync(CreateCommunicationDto req, CancellationToken ct) + { + Models.Communication communication = new() + { + Calling = req.Calling, + Email = req.Email, + Meeting = req.Meeting + }; + pyroFetesDbContext.Add(communication); + await pyroFetesDbContext.SaveChangesAsync(ct); + + GetCommunicationDto response = new() + { + Calling = req.Calling, + Email = req.Email, + Meeting = req.Meeting + }; + + await Send.OkAsync(response, ct); + } +} \ No newline at end of file diff --git a/PyroFetes/Endpoints/Communication/DeleteCommunicationEndpoint.cs b/PyroFetes/Endpoints/Communication/DeleteCommunicationEndpoint.cs new file mode 100644 index 0000000..b707b4b --- /dev/null +++ b/PyroFetes/Endpoints/Communication/DeleteCommunicationEndpoint.cs @@ -0,0 +1,30 @@ +using FastEndpoints; +using Microsoft.EntityFrameworkCore; +using PyroFetes.DTO.Availability.Request; +using PyroFetes.DTO.Communication.Response; + +namespace PyroFetes.Endpoints.Communication; + +public class DeleteCommunicationEndpoint(PyroFetesDbContext pyroFetesDbContext) : Endpoint +{ + public override void Configure() + { + Delete ("/api/availabilities/{@Id}", x => new { x.Id }); + AllowAnonymous(); + } + + public 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); + } +} \ No newline at end of file diff --git a/PyroFetes/Endpoints/Communication/GetCommunicationEndpoint.cs b/PyroFetes/Endpoints/Communication/GetCommunicationEndpoint.cs new file mode 100644 index 0000000..cb58367 --- /dev/null +++ b/PyroFetes/Endpoints/Communication/GetCommunicationEndpoint.cs @@ -0,0 +1,28 @@ +using FastEndpoints; +using Microsoft.EntityFrameworkCore; +using PyroFetes.DTO.Availability.Response; +using PyroFetes.DTO.Communication.Response; + +namespace PyroFetes.Endpoints.Communication; + +public class GetCommunicationEndpoint(PyroFetesDbContext pyroFetesDbContext) : EndpointWithoutRequest> +{ + public override void Configure() + { + Get ("/api/availabilities"); + AllowAnonymous(); + } + + public override async Task HandleAsync(CancellationToken ct) + { + List 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); + } +} diff --git a/PyroFetes/Endpoints/ExperienceLevel/DeleteExerienceLevelEndpoint.cs b/PyroFetes/Endpoints/ExperienceLevel/DeleteExerienceLevelEndpoint.cs index 5b5792d..2fc0a96 100644 --- a/PyroFetes/Endpoints/ExperienceLevel/DeleteExerienceLevelEndpoint.cs +++ b/PyroFetes/Endpoints/ExperienceLevel/DeleteExerienceLevelEndpoint.cs @@ -5,7 +5,7 @@ using FastEndpoints; namespace PyroFetes.Endpoints.ExperienceLevel; -public class DeleteExerienceLevelEndpoint(PyroFetesDbContext pyroFetesDbContext) : Endpoint +public class DeleteExerienceLevelEndpoint(PyroFetesDbContext pyroFetesDbContext) : Endpoint { public override void Configure() { @@ -13,7 +13,7 @@ public class DeleteExerienceLevelEndpoint(PyroFetesDbContext pyroFetesDbContext) AllowAnonymous(); } - public override async Task HandleAsync(GetExperienceLevelRequest req, CancellationToken ct) + public override async Task HandleAsync(GetExperienceLevelDTO req, CancellationToken ct) { Models.ExperienceLevel? databaseExperienceLevel = await pyroFetesDbContext.ExperienceLevels.SingleOrDefaultAsync(x => x.Id == req.Id, cancellationToken: ct); diff --git a/PyroFetes/Endpoints/ExperienceLevel/GetExperienceLevelEndpoint.cs b/PyroFetes/Endpoints/ExperienceLevel/GetExperienceLevelEndpoint.cs index 3ba32ce..9236f07 100644 --- a/PyroFetes/Endpoints/ExperienceLevel/GetExperienceLevelEndpoint.cs +++ b/PyroFetes/Endpoints/ExperienceLevel/GetExperienceLevelEndpoint.cs @@ -5,7 +5,7 @@ using FastEndpoints; namespace PyroFetes.Endpoints.ExperienceLevel; -public class GetExperienceLevelEndpoint(PyroFetesDbContext pyroFetesDbContext) : Endpoint +public class GetExperienceLevelEndpoint(PyroFetesDbContext pyroFetesDbContext) : Endpoint { public override void Configure() { @@ -13,7 +13,7 @@ public class GetExperienceLevelEndpoint(PyroFetesDbContext pyroFetesDbContext) : AllowAnonymous(); } - public override async Task HandleAsync(GetExperienceLevelRequest req, CancellationToken ct) + public override async Task HandleAsync(GetExperienceLevelDTO req, CancellationToken ct) { Models.ExperienceLevel? databaseExperienceLevel = await pyroFetesDbContext.ExperienceLevels.SingleOrDefaultAsync(x => x.Id == req.Id, cancellationToken: ct);