initial commit

This commit is contained in:
2026-07-21 13:52:43 +07:00
commit f0e6f38940
881 changed files with 66309 additions and 0 deletions
@@ -0,0 +1,54 @@
using Indotalent.ConfigBackEnd.Exceptions;
using Indotalent.ConfigBackEnd.Extensions;
using Indotalent.Infrastructure.Database;
using MediatR;
using Microsoft.EntityFrameworkCore;
namespace Indotalent.Features.Thirdparty.PatientGroup.Cqrs;
public class CreatePatientGroupRequest
{
public string? Name { get; set; }
public string? Description { get; set; }
}
public class CreatePatientGroupResponse
{
public string? Id { get; set; }
public string? Name { get; set; }
}
public record CreatePatientGroupCommand(CreatePatientGroupRequest Data) : IRequest<CreatePatientGroupResponse>;
public class CreatePatientGroupHandler : IRequestHandler<CreatePatientGroupCommand, CreatePatientGroupResponse>
{
private readonly AppDbContext _context;
public CreatePatientGroupHandler(AppDbContext context) => _context = context;
public async Task<CreatePatientGroupResponse> Handle(CreatePatientGroupCommand request, CancellationToken cancellationToken)
{
var isExists = await _context.PatientGroup
.AnyAsync(x => x.Name == request.Data.Name, cancellationToken);
if (isExists)
{
throw new AlreadyExistsException("Patient Group", request.Data.Name ?? string.Empty);
}
var entity = new Data.Entities.PatientGroup
{
Name = request.Data.Name,
Description = request.Data.Description
};
_context.PatientGroup.Add(entity);
await _context.SaveChangesAsync(cancellationToken);
return new CreatePatientGroupResponse
{
Id = entity.Id,
Name = entity.Name
};
}
}
@@ -0,0 +1,17 @@
using FluentValidation;
using Indotalent.Shared.Consts;
namespace Indotalent.Features.Thirdparty.PatientGroup.Cqrs;
public class CreatePatientGroupValidator : AbstractValidator<CreatePatientGroupRequest>
{
public CreatePatientGroupValidator()
{
RuleFor(x => x.Name)
.NotEmpty().WithMessage("Group Name is required")
.MaximumLength(GlobalConsts.StringLengthShort);
RuleFor(x => x.Description)
.MaximumLength(GlobalConsts.StringLengthMedium);
}
}
@@ -0,0 +1,27 @@
using Indotalent.Infrastructure.Database;
using MediatR;
using Microsoft.EntityFrameworkCore;
namespace Indotalent.Features.Thirdparty.PatientGroup.Cqrs;
public record DeletePatientGroupByIdRequest(string Id);
public record DeletePatientGroupByIdCommand(DeletePatientGroupByIdRequest Data) : IRequest<bool>;
public class DeletePatientGroupByIdHandler : IRequestHandler<DeletePatientGroupByIdCommand, bool>
{
private readonly AppDbContext _context;
public DeletePatientGroupByIdHandler(AppDbContext context) => _context = context;
public async Task<bool> Handle(DeletePatientGroupByIdCommand request, CancellationToken cancellationToken)
{
var entity = await _context.PatientGroup
.FirstOrDefaultAsync(x => x.Id == request.Data.Id, cancellationToken);
if (entity == null) return false;
_context.PatientGroup.Remove(entity);
return await _context.SaveChangesAsync(cancellationToken) > 0;
}
}
@@ -0,0 +1,43 @@
using Indotalent.Infrastructure.Database;
using MediatR;
using Microsoft.EntityFrameworkCore;
namespace Indotalent.Features.Thirdparty.PatientGroup.Cqrs;
public class GetPatientGroupByIdResponse
{
public string? Id { get; set; }
public string? Name { get; set; }
public string? Description { get; set; }
public DateTimeOffset? CreatedAt { get; set; }
public string? CreatedBy { get; set; }
public DateTimeOffset? UpdatedAt { get; set; }
public string? UpdatedBy { get; set; }
}
public record GetPatientGroupByIdQuery(string Id) : IRequest<GetPatientGroupByIdResponse?>;
public class GetPatientGroupByIdHandler : IRequestHandler<GetPatientGroupByIdQuery, GetPatientGroupByIdResponse?>
{
private readonly AppDbContext _context;
public GetPatientGroupByIdHandler(AppDbContext context) => _context = context;
public async Task<GetPatientGroupByIdResponse?> Handle(GetPatientGroupByIdQuery request, CancellationToken cancellationToken)
{
return await _context.PatientGroup
.AsNoTracking()
.Where(x => x.Id == request.Id)
.Select(x => new GetPatientGroupByIdResponse
{
Id = x.Id,
Name = x.Name,
Description = x.Description,
CreatedAt = x.CreatedAt,
CreatedBy = x.CreatedBy,
UpdatedAt = x.UpdatedAt,
UpdatedBy = x.UpdatedBy,
})
.FirstOrDefaultAsync(cancellationToken);
}
}
@@ -0,0 +1,43 @@
using Indotalent.Infrastructure.Database;
using MediatR;
using Microsoft.EntityFrameworkCore;
namespace Indotalent.Features.Thirdparty.PatientGroup.Cqrs;
public class GetPatientGroupListResponse
{
public string? Id { get; set; }
public string? Name { get; set; }
public string? Description { get; set; }
public DateTimeOffset? CreatedAt { get; set; }
public string? CreatedBy { get; set; }
public DateTimeOffset? UpdatedAt { get; set; }
public string? UpdatedBy { get; set; }
}
public record GetPatientGroupListQuery() : IRequest<List<GetPatientGroupListResponse>>;
public class GetPatientGroupListHandler : IRequestHandler<GetPatientGroupListQuery, List<GetPatientGroupListResponse>>
{
private readonly AppDbContext _context;
public GetPatientGroupListHandler(AppDbContext context) => _context = context;
public async Task<List<GetPatientGroupListResponse>> Handle(GetPatientGroupListQuery request, CancellationToken cancellationToken)
{
return await _context.PatientGroup
.AsNoTracking()
.OrderBy(x => x.Name)
.Select(x => new GetPatientGroupListResponse
{
Id = x.Id,
Name = x.Name,
Description = x.Description,
CreatedAt = x.CreatedAt,
CreatedBy = x.CreatedBy,
UpdatedAt = x.UpdatedAt,
UpdatedBy = x.UpdatedBy,
})
.ToListAsync(cancellationToken);
}
}
@@ -0,0 +1,61 @@
using Indotalent.ConfigBackEnd.Exceptions;
using Indotalent.Infrastructure.Database;
using MediatR;
using Microsoft.EntityFrameworkCore;
namespace Indotalent.Features.Thirdparty.PatientGroup.Cqrs;
public class UpdatePatientGroupRequest
{
public string? Id { get; set; }
public string? Name { get; set; }
public string? Description { get; set; }
public DateTimeOffset? CreatedAt { get; set; }
public string? CreatedBy { get; set; }
public DateTimeOffset? UpdatedAt { get; set; }
public string? UpdatedBy { get; set; }
}
public class UpdatePatientGroupResponse
{
public string? Id { get; set; }
public bool Success { get; set; }
}
public record UpdatePatientGroupCommand(UpdatePatientGroupRequest Data) : IRequest<UpdatePatientGroupResponse>;
public class UpdatePatientGroupHandler : IRequestHandler<UpdatePatientGroupCommand, UpdatePatientGroupResponse>
{
private readonly AppDbContext _context;
public UpdatePatientGroupHandler(AppDbContext context) => _context = context;
public async Task<UpdatePatientGroupResponse> Handle(UpdatePatientGroupCommand request, CancellationToken cancellationToken)
{
var isExists = await _context.PatientGroup
.AnyAsync(x => x.Name == request.Data.Name && x.Id != request.Data.Id, cancellationToken);
if (isExists)
{
throw new AlreadyExistsException("Patient Group", request.Data.Name ?? string.Empty);
}
var entity = await _context.PatientGroup
.FirstOrDefaultAsync(x => x.Id == request.Data.Id, cancellationToken);
if (entity == null)
{
return new UpdatePatientGroupResponse { Id = request.Data.Id, Success = false };
}
entity.Name = request.Data.Name;
entity.Description = request.Data.Description;
await _context.SaveChangesAsync(cancellationToken);
return new UpdatePatientGroupResponse
{
Id = entity.Id,
Success = true
};
}
}
@@ -0,0 +1,20 @@
using FluentValidation;
using Indotalent.Shared.Consts;
namespace Indotalent.Features.Thirdparty.PatientGroup.Cqrs;
public class UpdatePatientGroupValidator : AbstractValidator<UpdatePatientGroupRequest>
{
public UpdatePatientGroupValidator()
{
RuleFor(x => x.Id)
.NotEmpty().WithMessage("ID is required for update");
RuleFor(x => x.Name)
.NotEmpty().WithMessage("Group Name is required")
.MaximumLength(GlobalConsts.StringLengthShort);
RuleFor(x => x.Description)
.MaximumLength(GlobalConsts.StringLengthMedium);
}
}