using DigitalOps.Authority.Services; using DigitalOps.CQRS.Services.TimeEntry; using DigitalOps.CQRS.Services.TimeEntry.Options; using DigitalOps.Dal; using DigitalOps.Dal.Validators; using FluentValidation; using OpenHarbor.CQRS.Abstractions; namespace DigitalOps.CQRS.Commands.TimeEntry; public class AddTimeEntryCommand { public long ProjectId { get; set; } public long? ForUser { get; set; } public required string Description { get; set; } public DateTime StartAt { get; set; } public DateTime? EndAt { get; set; } public TimeOnly? Offset { get; set; } } public class AddTimeEntryCommandHandler(TimeEntryService timeEntryService) : ICommandHandler { public async Task HandleAsync(AddTimeEntryCommand command, CancellationToken cancellationToken = new CancellationToken()) { await timeEntryService.AddTimeEntryAsync(new AddTimeEntryOptions { ProjectId = command.ProjectId, ForUser = command.ForUser, Description = command.Description, StartAt = command.StartAt, EndAt = command.EndAt, Offset = command.Offset, }, cancellationToken); } } public class AddTimeEntryCommandValidator : AbstractValidator { public AddTimeEntryCommandValidator(MainDbContext dbContext, UserIdentityService userIdentityService) { RuleFor(command => command.ProjectId) .NotEmpty() .SetValidator(new DbEntityExistValidator(dbContext)); } }