Add time record API endpoint and supporting infrastructure
Introduced a new TimeController with a POST endpoint to insert and retrieve the latest time record. Added ITimeRepository, TimeRepository, and TimeRecord entity. Implemented MediatR command and handler for time insertion. Updated ApplicationDbContext and DI configuration to support the new feature.
This commit is contained in:
21
DbFirst.Application/Time/Commands/InsertTimeHandler.cs
Normal file
21
DbFirst.Application/Time/Commands/InsertTimeHandler.cs
Normal file
@@ -0,0 +1,21 @@
|
||||
using DbFirst.Application.Repositories;
|
||||
using DbFirst.Domain.Entities;
|
||||
using MediatR;
|
||||
|
||||
namespace DbFirst.Application.Time.Commands;
|
||||
|
||||
public class InsertTimeHandler : IRequestHandler<InsertTimeCommand, TimeRecord?>
|
||||
{
|
||||
private readonly ITimeRepository _repository;
|
||||
|
||||
public InsertTimeHandler(ITimeRepository repository)
|
||||
{
|
||||
_repository = repository;
|
||||
}
|
||||
|
||||
public async Task<TimeRecord?> Handle(InsertTimeCommand request, CancellationToken cancellationToken)
|
||||
{
|
||||
await _repository.InsertAsync(cancellationToken);
|
||||
return await _repository.GetLastAsync(cancellationToken);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user