First Commit 09/10
# Conflicts: # PyroFetes/PyroFetes.csproj
This commit is contained in:
@@ -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);
|
||||
|
||||
}
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
namespace PyroFetes.Endpoints.ExperienceLevel;
|
||||
|
||||
public class GetExperienceLevelEndpoint
|
||||
{
|
||||
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
namespace PyroFetes.Endpoints.ExperienceLevel;
|
||||
|
||||
public class UpdateExperienceLevelEndpoint
|
||||
{
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user