add TaskSectionTimeRequest to programmanager
This commit is contained in:
@@ -0,0 +1,43 @@
|
||||
using GozareshgirProgramManager.Application._Common.Interfaces;
|
||||
using GozareshgirProgramManager.Application._Common.Models;
|
||||
using GozareshgirProgramManager.Domain._Common;
|
||||
using GozareshgirProgramManager.Domain.ProjectAgg.Entities;
|
||||
using GozareshgirProgramManager.Domain.ProjectAgg.Enums;
|
||||
using GozareshgirProgramManager.Domain.ProjectAgg.Repositories;
|
||||
|
||||
namespace GozareshgirProgramManager.Application.Modules.TaskSectionTimeRequests.Commands.CreateTimeRequest;
|
||||
|
||||
public record CreateTimeRequestCommand(int Hours, int Minutes, string Description,
|
||||
TaskSectionTimeRequestType RequestType,Guid TaskSectionId) : IBaseCommand;
|
||||
|
||||
public class CreateTimeRequestCommandHandler : IBaseCommandHandler<CreateTimeRequestCommand>
|
||||
{
|
||||
private readonly IAuthHelper _authHelper;
|
||||
private readonly ITaskSectionTimeRequestRepository _timeRequestRepository;
|
||||
private readonly IUnitOfWork _unitOfWork;
|
||||
|
||||
public CreateTimeRequestCommandHandler
|
||||
(ITaskSectionTimeRequestRepository timeRequestRepository, IAuthHelper authHelper, IUnitOfWork unitOfWork)
|
||||
{
|
||||
_timeRequestRepository = timeRequestRepository;
|
||||
_authHelper = authHelper;
|
||||
_unitOfWork = unitOfWork;
|
||||
}
|
||||
|
||||
public async Task<OperationResult> Handle(CreateTimeRequestCommand request, CancellationToken cancellationToken)
|
||||
{
|
||||
var currentUser = _authHelper.GetCurrentUserId();
|
||||
if (!currentUser.HasValue)
|
||||
{
|
||||
return OperationResult.Unauthorized();
|
||||
}
|
||||
|
||||
var requestTimeSpan = TimeSpan.FromHours(request.Hours) + TimeSpan.FromMinutes(request.Minutes);
|
||||
|
||||
var entity = new TaskSectionTimeRequest(currentUser.Value, request.Description, requestTimeSpan,
|
||||
TaskSectionTimeRequestType.RejectedTime,);
|
||||
await _timeRequestRepository.CreateAsync(entity);
|
||||
await _unitOfWork.SaveChangesAsync(cancellationToken);
|
||||
return OperationResult.Success();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
using FluentValidation;
|
||||
|
||||
namespace GozareshgirProgramManager.Application.Modules.TaskSectionTimeRequests.Commands.CreateTimeRequest;
|
||||
|
||||
public class CreateTimeRequestValidator : AbstractValidator<CreateTimeRequestCommand>
|
||||
{
|
||||
public CreateTimeRequestValidator()
|
||||
{
|
||||
RuleFor(c => c.Hours)
|
||||
.InclusiveBetween(0, 100).WithMessage("ساعت درخواست شده باید کمتر از 100 ساعت باشد");
|
||||
|
||||
RuleFor(c => c.Minutes)
|
||||
.InclusiveBetween(0, 60)
|
||||
.WithMessage("دقیقه وارد شده باید بین 0 تا 60 باشد");
|
||||
|
||||
RuleFor(x => x.RequestType)
|
||||
.IsInEnum()
|
||||
.NotNull();
|
||||
}
|
||||
}
|
||||
@@ -31,7 +31,7 @@ public class OperationResult
|
||||
|
||||
// Helper methods for specific error types
|
||||
public static OperationResult NotFound(string errorMessage) => new(false, errorMessage, errorType: ErrorType.NotFound);
|
||||
public static OperationResult Unauthorized(string errorMessage) => new(false, errorMessage, errorType: ErrorType.Unauthorized);
|
||||
public static OperationResult Unauthorized(string errorMessage="احراز هویت شما منقضی شده است. لطفا دوباره وارد شوید") => new(false, errorMessage, errorType: ErrorType.Unauthorized);
|
||||
public static OperationResult ValidationError(string errorMessage) => new(false, errorMessage, errorType: ErrorType.Validation);
|
||||
public static OperationResult ValidationError(List<string> errors) => new(false, errors: errors, errorType: ErrorType.Validation);
|
||||
public static OperationResult InternalServerError(string errorMessage) => new(false, errorMessage, errorType: ErrorType.InternalServerError);
|
||||
|
||||
@@ -0,0 +1,27 @@
|
||||
using GozareshgirProgramManager.Domain._Common;
|
||||
using GozareshgirProgramManager.Domain.ProjectAgg.Enums;
|
||||
|
||||
namespace GozareshgirProgramManager.Domain.ProjectAgg.Entities;
|
||||
|
||||
public class TaskSectionTimeRequest:EntityBase<Guid>
|
||||
{
|
||||
public TaskSectionTimeRequest(long userId, string description,
|
||||
TimeSpan requestedTime, TaskSectionTimeRequestType requestType,
|
||||
Guid taskSectionId)
|
||||
{
|
||||
UserId = userId;
|
||||
Description = description;
|
||||
RequestedTime = requestedTime;
|
||||
RequestType = requestType;
|
||||
TaskSectionId = taskSectionId;
|
||||
}
|
||||
|
||||
public TaskSection TaskSection { get; set; }
|
||||
public Guid TaskSectionId { get; set; }
|
||||
public long UserId { get; private set; }
|
||||
public string Description { get; private set; }
|
||||
public TimeSpan RequestedTime { get; private set; }
|
||||
public TaskSectionTimeRequestType RequestType { get; private set; }
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
namespace GozareshgirProgramManager.Domain.ProjectAgg.Enums;
|
||||
|
||||
public enum TaskSectionTimeRequestType
|
||||
{
|
||||
InitialTime,
|
||||
AdditionalTime,
|
||||
RejectedTime,
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
using GozareshgirProgramManager.Domain._Common;
|
||||
using GozareshgirProgramManager.Domain.ProjectAgg.Entities;
|
||||
|
||||
namespace GozareshgirProgramManager.Domain.ProjectAgg.Repositories;
|
||||
|
||||
public interface ITaskSectionTimeRequestRepository:IRepository<Guid,TaskSectionTimeRequest>
|
||||
{
|
||||
|
||||
}
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
public class UnAuthorizedException:Exception
|
||||
{
|
||||
public UnAuthorizedException(string message) : base(message)
|
||||
public UnAuthorizedException(string message="احراز هویت شما منقضی شده است. لطفا دوباره وارد شوید") : base(message)
|
||||
{
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
using GozareshgirProgramManager.Application._Common.Models;
|
||||
using GozareshgirProgramManager.Application.Modules.TaskSectionTimeRequests.Commands.CreateTimeRequest;
|
||||
using GozareshgirProgramManager.Domain.ProjectAgg.Enums;
|
||||
using MediatR;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using ServiceHost.BaseControllers;
|
||||
|
||||
namespace ServiceHost.Areas.Admin.Controllers.ProgramManager;
|
||||
|
||||
public class TimeRequestController:ProgramManagerBaseController
|
||||
{
|
||||
private readonly IMediator _mediator;
|
||||
|
||||
public TimeRequestController(IMediator mediator)
|
||||
{
|
||||
_mediator = mediator;
|
||||
}
|
||||
|
||||
[HttpPost("Rejected")]
|
||||
public async Task<ActionResult<OperationResult>> CreateRejectedTimeRequest(CreateRejectedTimeRequest request)
|
||||
{
|
||||
var command = new CreateTimeRequestCommand(request.Hours, request.Minutes, request.Description,
|
||||
TaskSectionTimeRequestType.RejectedTime);
|
||||
var res = await _mediator.Send(command);
|
||||
return res;
|
||||
}
|
||||
|
||||
[HttpPost("Initial")]
|
||||
public async Task<ActionResult<OperationResult>> CreateInitialTimeRequest(CreateRejectedTimeRequest request)
|
||||
{
|
||||
var command = new CreateTimeRequestCommand(request.Hours, request.Minutes, request.Description,
|
||||
TaskSectionTimeRequestType.InitialTime);
|
||||
var res = await _mediator.Send(command);
|
||||
return res;
|
||||
}
|
||||
|
||||
[HttpPost("Additional")]
|
||||
public async Task<ActionResult<OperationResult>> CreateAdditionalTimeRequest(CreateRejectedTimeRequest request)
|
||||
{
|
||||
var command = new CreateTimeRequestCommand(request.Hours, request.Minutes, request.Description,
|
||||
TaskSectionTimeRequestType.AdditionalTime);
|
||||
var res = await _mediator.Send(command);
|
||||
return res;
|
||||
}
|
||||
}
|
||||
|
||||
public record CreateRejectedTimeRequest(int Hours, int Minutes, string Description);
|
||||
Reference in New Issue
Block a user