46 lines
1.1 KiB
C#
46 lines
1.1 KiB
C#
using Tasker.Web.Data;
|
|
using Task = System.Threading.Tasks.Task;
|
|
|
|
namespace Tasker.Web.Endpoints;
|
|
|
|
[PublicAPI]
|
|
public record AddTaskRequest(
|
|
Guid Id,
|
|
string Name,
|
|
string? Description,
|
|
DateTimeOffset? DueDate);
|
|
|
|
[PublicAPI]
|
|
public class AddTaskEndpoint(
|
|
ProjectingDbContext dbContext)
|
|
: Endpoint<AddTaskRequest>
|
|
{
|
|
public override void Configure()
|
|
{
|
|
Post("/tasks");
|
|
Options(o => o.WithTags("Projecting"));
|
|
AllowAnonymous();
|
|
}
|
|
|
|
public override async Task HandleAsync(
|
|
AddTaskRequest req,
|
|
CancellationToken ct)
|
|
{
|
|
var task = await dbContext.Tasks.AddAsync(
|
|
new Data.Task
|
|
{
|
|
Id = req.Id,
|
|
Name = req.Name,
|
|
Description = req.Description,
|
|
DueDate = req.DueDate
|
|
},
|
|
cancellationToken: ct);
|
|
|
|
await dbContext.SaveChangesAsync(ct);
|
|
|
|
await SendCreatedAtAsync<GetTaskEndpoint>(
|
|
task.Entity.Id,
|
|
task.Entity,
|
|
cancellation: ct);
|
|
}
|
|
} |