From bd12ff05067858359dec01d02de89bd022617a62 Mon Sep 17 00:00:00 2001 From: mahan Date: Mon, 19 Jan 2026 15:19:58 +0330 Subject: [PATCH] add TaskSectionTimeRequest to programmanager --- .../CreateTimeRequestCommand.cs | 43 +++++++++++++++++ .../CreateTimeRequestValidator.cs | 20 ++++++++ .../_Common/Models/OperationResult.cs | 2 +- .../Entities/TaskSectionTimeRequest.cs | 27 +++++++++++ .../Enums/TaskSectionTimeRequestType.cs | 8 ++++ .../ITaskSectionTimeRequestRepository.cs | 9 ++++ .../Exceptions/UnAuthorizedException.cs | 2 +- .../ProgramManager/TimeRequestController.cs | 47 +++++++++++++++++++ 8 files changed, 156 insertions(+), 2 deletions(-) create mode 100644 ProgramManager/src/Application/GozareshgirProgramManager.Application/Modules/TaskSectionTimeRequests/Commands/CreateTimeRequest/CreateTimeRequestCommand.cs create mode 100644 ProgramManager/src/Application/GozareshgirProgramManager.Application/Modules/TaskSectionTimeRequests/Commands/CreateTimeRequest/CreateTimeRequestValidator.cs create mode 100644 ProgramManager/src/Domain/GozareshgirProgramManager.Domain/ProjectAgg/Entities/TaskSectionTimeRequest.cs create mode 100644 ProgramManager/src/Domain/GozareshgirProgramManager.Domain/ProjectAgg/Enums/TaskSectionTimeRequestType.cs create mode 100644 ProgramManager/src/Domain/GozareshgirProgramManager.Domain/ProjectAgg/Repositories/ITaskSectionTimeRequestRepository.cs create mode 100644 ServiceHost/Areas/Admin/Controllers/ProgramManager/TimeRequestController.cs diff --git a/ProgramManager/src/Application/GozareshgirProgramManager.Application/Modules/TaskSectionTimeRequests/Commands/CreateTimeRequest/CreateTimeRequestCommand.cs b/ProgramManager/src/Application/GozareshgirProgramManager.Application/Modules/TaskSectionTimeRequests/Commands/CreateTimeRequest/CreateTimeRequestCommand.cs new file mode 100644 index 00000000..794a1442 --- /dev/null +++ b/ProgramManager/src/Application/GozareshgirProgramManager.Application/Modules/TaskSectionTimeRequests/Commands/CreateTimeRequest/CreateTimeRequestCommand.cs @@ -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 +{ + 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 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(); + } +} \ No newline at end of file diff --git a/ProgramManager/src/Application/GozareshgirProgramManager.Application/Modules/TaskSectionTimeRequests/Commands/CreateTimeRequest/CreateTimeRequestValidator.cs b/ProgramManager/src/Application/GozareshgirProgramManager.Application/Modules/TaskSectionTimeRequests/Commands/CreateTimeRequest/CreateTimeRequestValidator.cs new file mode 100644 index 00000000..03d65b77 --- /dev/null +++ b/ProgramManager/src/Application/GozareshgirProgramManager.Application/Modules/TaskSectionTimeRequests/Commands/CreateTimeRequest/CreateTimeRequestValidator.cs @@ -0,0 +1,20 @@ +using FluentValidation; + +namespace GozareshgirProgramManager.Application.Modules.TaskSectionTimeRequests.Commands.CreateTimeRequest; + +public class CreateTimeRequestValidator : AbstractValidator +{ + 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(); + } +} \ No newline at end of file diff --git a/ProgramManager/src/Application/GozareshgirProgramManager.Application/_Common/Models/OperationResult.cs b/ProgramManager/src/Application/GozareshgirProgramManager.Application/_Common/Models/OperationResult.cs index 324e9895..e92e0df6 100644 --- a/ProgramManager/src/Application/GozareshgirProgramManager.Application/_Common/Models/OperationResult.cs +++ b/ProgramManager/src/Application/GozareshgirProgramManager.Application/_Common/Models/OperationResult.cs @@ -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 errors) => new(false, errors: errors, errorType: ErrorType.Validation); public static OperationResult InternalServerError(string errorMessage) => new(false, errorMessage, errorType: ErrorType.InternalServerError); diff --git a/ProgramManager/src/Domain/GozareshgirProgramManager.Domain/ProjectAgg/Entities/TaskSectionTimeRequest.cs b/ProgramManager/src/Domain/GozareshgirProgramManager.Domain/ProjectAgg/Entities/TaskSectionTimeRequest.cs new file mode 100644 index 00000000..7ea28037 --- /dev/null +++ b/ProgramManager/src/Domain/GozareshgirProgramManager.Domain/ProjectAgg/Entities/TaskSectionTimeRequest.cs @@ -0,0 +1,27 @@ +using GozareshgirProgramManager.Domain._Common; +using GozareshgirProgramManager.Domain.ProjectAgg.Enums; + +namespace GozareshgirProgramManager.Domain.ProjectAgg.Entities; + +public class TaskSectionTimeRequest:EntityBase +{ + 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; } + + +} \ No newline at end of file diff --git a/ProgramManager/src/Domain/GozareshgirProgramManager.Domain/ProjectAgg/Enums/TaskSectionTimeRequestType.cs b/ProgramManager/src/Domain/GozareshgirProgramManager.Domain/ProjectAgg/Enums/TaskSectionTimeRequestType.cs new file mode 100644 index 00000000..9c8007f7 --- /dev/null +++ b/ProgramManager/src/Domain/GozareshgirProgramManager.Domain/ProjectAgg/Enums/TaskSectionTimeRequestType.cs @@ -0,0 +1,8 @@ +namespace GozareshgirProgramManager.Domain.ProjectAgg.Enums; + +public enum TaskSectionTimeRequestType +{ + InitialTime, + AdditionalTime, + RejectedTime, +} \ No newline at end of file diff --git a/ProgramManager/src/Domain/GozareshgirProgramManager.Domain/ProjectAgg/Repositories/ITaskSectionTimeRequestRepository.cs b/ProgramManager/src/Domain/GozareshgirProgramManager.Domain/ProjectAgg/Repositories/ITaskSectionTimeRequestRepository.cs new file mode 100644 index 00000000..9247bb9e --- /dev/null +++ b/ProgramManager/src/Domain/GozareshgirProgramManager.Domain/ProjectAgg/Repositories/ITaskSectionTimeRequestRepository.cs @@ -0,0 +1,9 @@ +using GozareshgirProgramManager.Domain._Common; +using GozareshgirProgramManager.Domain.ProjectAgg.Entities; + +namespace GozareshgirProgramManager.Domain.ProjectAgg.Repositories; + +public interface ITaskSectionTimeRequestRepository:IRepository +{ + +} \ No newline at end of file diff --git a/ProgramManager/src/Domain/GozareshgirProgramManager.Domain/_Common/Exceptions/UnAuthorizedException.cs b/ProgramManager/src/Domain/GozareshgirProgramManager.Domain/_Common/Exceptions/UnAuthorizedException.cs index 67f0befb..f470b20c 100644 --- a/ProgramManager/src/Domain/GozareshgirProgramManager.Domain/_Common/Exceptions/UnAuthorizedException.cs +++ b/ProgramManager/src/Domain/GozareshgirProgramManager.Domain/_Common/Exceptions/UnAuthorizedException.cs @@ -2,7 +2,7 @@ public class UnAuthorizedException:Exception { - public UnAuthorizedException(string message) : base(message) + public UnAuthorizedException(string message="احراز هویت شما منقضی شده است. لطفا دوباره وارد شوید") : base(message) { } } \ No newline at end of file diff --git a/ServiceHost/Areas/Admin/Controllers/ProgramManager/TimeRequestController.cs b/ServiceHost/Areas/Admin/Controllers/ProgramManager/TimeRequestController.cs new file mode 100644 index 00000000..3e577b13 --- /dev/null +++ b/ServiceHost/Areas/Admin/Controllers/ProgramManager/TimeRequestController.cs @@ -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> 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> 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> 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); \ No newline at end of file