initial commit

This commit is contained in:
2026-07-21 14:08:10 +07:00
commit f7cf118326
533 changed files with 41762 additions and 0 deletions
@@ -0,0 +1,73 @@
using Indotalent.ConfigBackEnd.Exceptions;
using Indotalent.ConfigBackEnd.Extensions;
using Indotalent.Infrastructure.Database;
using MediatR;
using Microsoft.EntityFrameworkCore;
namespace Indotalent.Features.Payroll.Deduction.Cqrs;
public class CreateDeductionRequest
{
public string? Code { get; set; }
public string? Name { get; set; }
public string? Description { get; set; }
public string? Category { get; set; }
public bool PreTax { get; set; }
public string? CalculationMethod { get; set; }
public string? Status { get; set; } = "Active";
}
public class CreateDeductionResponse
{
public string? Id { get; set; }
public string? Code { get; set; }
}
public record CreateDeductionCommand(CreateDeductionRequest Data) : IRequest<CreateDeductionResponse>;
public class CreateDeductionHandler : IRequestHandler<CreateDeductionCommand, CreateDeductionResponse>
{
private readonly AppDbContext _context;
public CreateDeductionHandler(AppDbContext context) => _context = context;
public async Task<CreateDeductionResponse> Handle(CreateDeductionCommand request, CancellationToken cancellationToken)
{
var isExists = await _context.Deduction
.AnyAsync(x => x.Code == request.Data.Code, cancellationToken);
if (isExists)
{
throw new AlreadyExistsException("Deduction Component", request.Data.Code ?? string.Empty);
}
var entityName = nameof(Data.Entities.Deduction);
var autoNo = await _context.GenerateAutoNumberAsync(
entityName: entityName,
prefixTemplate: $"{entityName.ToShortNameConsonant(3)}/{{Year}}/",
ct: cancellationToken
);
var entity = new Data.Entities.Deduction
{
AutoNumber = autoNo,
Code = request.Data.Code,
Name = request.Data.Name,
Description = request.Data.Description,
Category = request.Data.Category,
PreTax = request.Data.PreTax,
CalculationMethod = request.Data.CalculationMethod,
Status = request.Data.Status
};
_context.Deduction.Add(entity);
await _context.SaveChangesAsync(cancellationToken);
return new CreateDeductionResponse
{
Id = entity.Id,
Code = entity.Code
};
}
}
@@ -0,0 +1,30 @@
using FluentValidation;
using Indotalent.Shared.Consts;
namespace Indotalent.Features.Payroll.Deduction.Cqrs;
public class CreateDeductionValidator : AbstractValidator<CreateDeductionRequest>
{
public CreateDeductionValidator()
{
RuleFor(x => x.Code)
.NotEmpty().WithMessage("Code is required")
.MaximumLength(GlobalConsts.StringLengthShort);
RuleFor(x => x.Name)
.NotEmpty().WithMessage("Name is required")
.MaximumLength(GlobalConsts.StringLengthShort);
RuleFor(x => x.Category)
.NotEmpty().WithMessage("Category is required")
.MaximumLength(GlobalConsts.StringLengthShort);
RuleFor(x => x.CalculationMethod)
.NotEmpty().WithMessage("Calculation Method is required")
.MaximumLength(GlobalConsts.StringLengthShort);
RuleFor(x => x.Status)
.NotEmpty().WithMessage("Status is required")
.MaximumLength(GlobalConsts.StringLengthShort);
}
}
@@ -0,0 +1,27 @@
using Indotalent.Infrastructure.Database;
using MediatR;
using Microsoft.EntityFrameworkCore;
namespace Indotalent.Features.Payroll.Deduction.Cqrs;
public record DeleteDeductionByIdRequest(string Id);
public record DeleteDeductionByIdCommand(DeleteDeductionByIdRequest Data) : IRequest<bool>;
public class DeleteDeductionByIdHandler : IRequestHandler<DeleteDeductionByIdCommand, bool>
{
private readonly AppDbContext _context;
public DeleteDeductionByIdHandler(AppDbContext context) => _context = context;
public async Task<bool> Handle(DeleteDeductionByIdCommand request, CancellationToken cancellationToken)
{
var entity = await _context.Deduction
.FirstOrDefaultAsync(x => x.Id == request.Data.Id, cancellationToken);
if (entity == null) return false;
_context.Deduction.Remove(entity);
return await _context.SaveChangesAsync(cancellationToken) > 0;
}
}
@@ -0,0 +1,53 @@
using Indotalent.Infrastructure.Database;
using MediatR;
using Microsoft.EntityFrameworkCore;
namespace Indotalent.Features.Payroll.Deduction.Cqrs;
public class GetDeductionByIdResponse
{
public string? Id { get; set; }
public string? Code { get; set; }
public string? Name { get; set; }
public string? Description { get; set; }
public string? Category { get; set; }
public bool PreTax { get; set; }
public string? CalculationMethod { get; set; }
public string? Status { get; set; }
public DateTimeOffset? CreatedAt { get; set; }
public string? CreatedBy { get; set; }
public DateTimeOffset? UpdatedAt { get; set; }
public string? UpdatedBy { get; set; }
}
public record GetDeductionByIdQuery(string Id) : IRequest<GetDeductionByIdResponse?>;
public class GetDeductionByIdHandler : IRequestHandler<GetDeductionByIdQuery, GetDeductionByIdResponse?>
{
private readonly AppDbContext _context;
public GetDeductionByIdHandler(AppDbContext context) => _context = context;
public async Task<GetDeductionByIdResponse?> Handle(GetDeductionByIdQuery request, CancellationToken cancellationToken)
{
return await _context.Deduction
.AsNoTracking()
.Where(x => x.Id == request.Id)
.Select(x => new GetDeductionByIdResponse
{
Id = x.Id,
Code = x.Code,
Name = x.Name,
Description = x.Description,
Category = x.Category,
PreTax = x.PreTax,
CalculationMethod = x.CalculationMethod,
Status = x.Status,
CreatedAt = x.CreatedAt,
CreatedBy = x.CreatedBy,
UpdatedAt = x.UpdatedAt,
UpdatedBy = x.UpdatedBy
})
.FirstOrDefaultAsync(cancellationToken);
}
}
@@ -0,0 +1,45 @@
using Indotalent.Infrastructure.Database;
using MediatR;
using Microsoft.EntityFrameworkCore;
namespace Indotalent.Features.Payroll.Deduction.Cqrs;
public class GetDeductionListResponse
{
public string? Id { get; set; }
public string? Code { get; set; }
public string? Name { get; set; }
public string? Category { get; set; }
public bool PreTax { get; set; }
public string? CalculationMethod { get; set; }
public string? Status { get; set; }
public DateTimeOffset? CreatedAt { get; set; }
}
public record GetDeductionListQuery() : IRequest<List<GetDeductionListResponse>>;
public class GetDeductionListHandler : IRequestHandler<GetDeductionListQuery, List<GetDeductionListResponse>>
{
private readonly AppDbContext _context;
public GetDeductionListHandler(AppDbContext context) => _context = context;
public async Task<List<GetDeductionListResponse>> Handle(GetDeductionListQuery request, CancellationToken cancellationToken)
{
return await _context.Deduction
.AsNoTracking()
.OrderBy(x => x.Code)
.Select(x => new GetDeductionListResponse
{
Id = x.Id,
Code = x.Code,
Name = x.Name,
Category = x.Category,
PreTax = x.PreTax,
CalculationMethod = x.CalculationMethod,
Status = x.Status,
CreatedAt = x.CreatedAt
})
.ToListAsync(cancellationToken);
}
}
@@ -0,0 +1,72 @@
using Indotalent.ConfigBackEnd.Exceptions;
using Indotalent.Infrastructure.Database;
using MediatR;
using Microsoft.EntityFrameworkCore;
namespace Indotalent.Features.Payroll.Deduction.Cqrs;
public class UpdateDeductionRequest
{
public string? Id { get; set; }
public string? Code { get; set; }
public string? Name { get; set; }
public string? Description { get; set; }
public string? Category { get; set; }
public bool PreTax { get; set; }
public string? CalculationMethod { get; set; }
public string? Status { get; set; }
public DateTimeOffset? CreatedAt { get; set; }
public string? CreatedBy { get; set; }
public DateTimeOffset? UpdatedAt { get; set; }
public string? UpdatedBy { get; set; }
}
public class UpdateDeductionResponse
{
public string? Id { get; set; }
public bool Success { get; set; }
}
public record UpdateDeductionCommand(UpdateDeductionRequest Data) : IRequest<UpdateDeductionResponse>;
public class UpdateDeductionHandler : IRequestHandler<UpdateDeductionCommand, UpdateDeductionResponse>
{
private readonly AppDbContext _context;
public UpdateDeductionHandler(AppDbContext context) => _context = context;
public async Task<UpdateDeductionResponse> Handle(UpdateDeductionCommand request, CancellationToken cancellationToken)
{
var isExists = await _context.Deduction
.AnyAsync(x => x.Code == request.Data.Code && x.Id != request.Data.Id, cancellationToken);
if (isExists)
{
throw new AlreadyExistsException("Deduction Component", request.Data.Code ?? string.Empty);
}
var entity = await _context.Deduction
.FirstOrDefaultAsync(x => x.Id == request.Data.Id, cancellationToken);
if (entity == null)
{
return new UpdateDeductionResponse { Id = request.Data.Id, Success = false };
}
entity.Code = request.Data.Code;
entity.Name = request.Data.Name;
entity.Description = request.Data.Description;
entity.Category = request.Data.Category;
entity.PreTax = request.Data.PreTax;
entity.CalculationMethod = request.Data.CalculationMethod;
entity.Status = request.Data.Status;
await _context.SaveChangesAsync(cancellationToken);
return new UpdateDeductionResponse
{
Id = entity.Id,
Success = true
};
}
}
@@ -0,0 +1,33 @@
using FluentValidation;
using Indotalent.Shared.Consts;
namespace Indotalent.Features.Payroll.Deduction.Cqrs;
public class UpdateDeductionValidator : AbstractValidator<UpdateDeductionRequest>
{
public UpdateDeductionValidator()
{
RuleFor(x => x.Id)
.NotEmpty().WithMessage("ID is required for update");
RuleFor(x => x.Code)
.NotEmpty().WithMessage("Code is required")
.MaximumLength(GlobalConsts.StringLengthShort);
RuleFor(x => x.Name)
.NotEmpty().WithMessage("Name is required")
.MaximumLength(GlobalConsts.StringLengthShort);
RuleFor(x => x.Category)
.NotEmpty().WithMessage("Category is required")
.MaximumLength(GlobalConsts.StringLengthShort);
RuleFor(x => x.CalculationMethod)
.NotEmpty().WithMessage("Calculation Method is required")
.MaximumLength(GlobalConsts.StringLengthShort);
RuleFor(x => x.Status)
.NotEmpty().WithMessage("Status is required")
.MaximumLength(GlobalConsts.StringLengthShort);
}
}