ExperienceLevel Finished (API) 09/10
This commit is contained in:
@@ -17,6 +17,8 @@ public class GetAllExperienceLevelsEndpoint(PyroFetesDbContext pyroFetesDbContex
|
|||||||
List<GetExperienceLevelDto> experienceLevels= await pyroFetesDbContext.ExperienceLevels.Select(x => new GetExperienceLevelDto()
|
List<GetExperienceLevelDto> experienceLevels= await pyroFetesDbContext.ExperienceLevels.Select(x => new GetExperienceLevelDto()
|
||||||
{
|
{
|
||||||
Id = x.Id,
|
Id = x.Id,
|
||||||
|
Label = x.Label,
|
||||||
|
|
||||||
}).ToListAsync(ct);
|
}).ToListAsync(ct);
|
||||||
|
|
||||||
await Send.OkAsync(experienceLevels, ct);
|
await Send.OkAsync(experienceLevels, ct);
|
||||||
|
@@ -1,6 +1,34 @@
|
|||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
using PyroFetes.DTO.ExperienceLevel.Request;
|
||||||
|
using PyroFetes.DTO.ExperienceLevel.Response;
|
||||||
|
using FastEndpoints;
|
||||||
|
|
||||||
namespace PyroFetes.Endpoints.ExperienceLevel;
|
namespace PyroFetes.Endpoints.ExperienceLevel;
|
||||||
|
|
||||||
public class GetExperienceLevelEndpoint
|
public class GetExperienceLevelEndpoint(PyroFetesDbContext pyroFetesDbContext) : Endpoint <GetExperienceLevelRequest, GetExperienceLevelDto>
|
||||||
{
|
{
|
||||||
|
public override void Configure()
|
||||||
|
{
|
||||||
|
Get ("/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;
|
||||||
|
}
|
||||||
|
|
||||||
|
GetExperienceLevelDto dto = new()
|
||||||
|
{
|
||||||
|
Id = databaseExperienceLevel.Id,
|
||||||
|
Label = databaseExperienceLevel.Label,
|
||||||
|
};
|
||||||
|
|
||||||
|
await Send.OkAsync(dto, ct);
|
||||||
|
}
|
||||||
}
|
}
|
@@ -1,6 +1,39 @@
|
|||||||
|
using FastEndpoints;
|
||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
using PyroFetes.DTO.ExperienceLevel.Request;
|
||||||
|
using PyroFetes.DTO.ExperienceLevel.Response;
|
||||||
|
|
||||||
namespace PyroFetes.Endpoints.ExperienceLevel;
|
namespace PyroFetes.Endpoints.ExperienceLevel;
|
||||||
|
|
||||||
public class UpdateExperienceLevelEndpoint
|
public class UpdateExperienceLevelEndpoint(PyroFetesDbContext pyroFetesDbContext) : Endpoint <UpdateExperienceLevelDto, GetExperienceLevelDto>
|
||||||
{
|
{
|
||||||
|
public override void Configure()
|
||||||
|
{
|
||||||
|
Put ("/api/ExperienceLevels/{@Id}", x => new { x.Id });
|
||||||
|
AllowAnonymous();
|
||||||
|
}
|
||||||
|
|
||||||
|
public override async Task HandleAsync(UpdateExperienceLevelDto 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;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
databaseExperienceLevel.Label = req.Label;
|
||||||
|
}
|
||||||
|
await pyroFetesDbContext.SaveChangesAsync(ct);
|
||||||
|
|
||||||
|
GetExperienceLevelDto dto = new()
|
||||||
|
{
|
||||||
|
Id = databaseExperienceLevel.Id,
|
||||||
|
Label = req.Label,
|
||||||
|
};
|
||||||
|
|
||||||
|
await Send.OkAsync(dto, ct);
|
||||||
|
}
|
||||||
}
|
}
|
Reference in New Issue
Block a user