From 6b12620a7cf45e5a433f7f53b8a2d7579531a443 Mon Sep 17 00:00:00 2001 From: Eduardo Rezende Date: Sat, 6 Sep 2025 17:40:43 -0300 Subject: [PATCH 01/30] =?UTF-8?q?=E2=9C=A8feat:=20Add=20new=20JsonConverte?= =?UTF-8?q?r?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Adding TrimmingJsonConverter to secure API and database --- OneBus.API/Converters/TrimmingJsonConverter.cs | 18 ++++++++++++++++++ OneBus.API/Program.cs | 18 ++++++++++-------- 2 files changed, 28 insertions(+), 8 deletions(-) create mode 100644 OneBus.API/Converters/TrimmingJsonConverter.cs diff --git a/OneBus.API/Converters/TrimmingJsonConverter.cs b/OneBus.API/Converters/TrimmingJsonConverter.cs new file mode 100644 index 0000000..74ead0a --- /dev/null +++ b/OneBus.API/Converters/TrimmingJsonConverter.cs @@ -0,0 +1,18 @@ +using System.Text.Json; +using System.Text.Json.Serialization; + +namespace OneBus.API.Converters +{ + public class TrimmingJsonConverter : JsonConverter + { + public override string Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) + { + return reader.GetString()?.Trim()!; + } + + public override void Write(Utf8JsonWriter writer, string value, JsonSerializerOptions options) + { + writer.WriteStringValue(value); + } + } +} diff --git a/OneBus.API/Program.cs b/OneBus.API/Program.cs index cf7298e..e82c35b 100644 --- a/OneBus.API/Program.cs +++ b/OneBus.API/Program.cs @@ -1,14 +1,15 @@ -using System.Text; -using OneBus.Infra.Ioc; +using Microsoft.AspNetCore.Authentication.JwtBearer; +using Microsoft.AspNetCore.Http.Json; +using Microsoft.EntityFrameworkCore; +using Microsoft.IdentityModel.Tokens; +using Microsoft.OpenApi.Models; +using OneBus.API.Converters; using OneBus.API.Handlers; using OneBus.Domain.Settings; -using Microsoft.OpenApi.Models; using OneBus.Infra.Data.DbContexts; -using Microsoft.EntityFrameworkCore; +using OneBus.Infra.Ioc; +using System.Text; using System.Text.Json.Serialization; -using Microsoft.AspNetCore.Http.Json; -using Microsoft.IdentityModel.Tokens; -using Microsoft.AspNetCore.Authentication.JwtBearer; var builder = WebApplication.CreateBuilder(args); @@ -16,7 +17,8 @@ builder.Services .AddControllers() - .AddJsonOptions(c => c.JsonSerializerOptions.Converters.Add(new JsonStringEnumConverter())); + .AddJsonOptions(c => c.JsonSerializerOptions.Converters.Add(new JsonStringEnumConverter())) + .AddJsonOptions(c => c.JsonSerializerOptions.Converters.Add(new TrimmingJsonConverter())); // Configuring json visualization for Enums builder.Services.Configure(options => From fabe05e397be6d089a2040a1a6ed971e239c19b9 Mon Sep 17 00:00:00 2001 From: Eduardo Rezende Date: Sat, 6 Sep 2025 17:41:19 -0300 Subject: [PATCH 02/30] =?UTF-8?q?=F0=9F=93=A6build:=20Update=20nuget=20pac?= =?UTF-8?q?kages?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Updating OneBus packages --- OneBus.API/OneBus.API.csproj | 8 ++++---- OneBus.Test/OneBus.Test.csproj | 1 + 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/OneBus.API/OneBus.API.csproj b/OneBus.API/OneBus.API.csproj index cda3555..699bf51 100644 --- a/OneBus.API/OneBus.API.csproj +++ b/OneBus.API/OneBus.API.csproj @@ -18,10 +18,10 @@ runtime; build; native; contentfiles; analyzers; buildtransitive - - - - + + + + diff --git a/OneBus.Test/OneBus.Test.csproj b/OneBus.Test/OneBus.Test.csproj index 5f947dd..ed2efb5 100644 --- a/OneBus.Test/OneBus.Test.csproj +++ b/OneBus.Test/OneBus.Test.csproj @@ -13,6 +13,7 @@ runtime; build; native; contentfiles; analyzers; buildtransitive + all From 1c5ae45e8e6269f0cc57b2498cc06ccb1f68bc89 Mon Sep 17 00:00:00 2001 From: Eduardo Rezende Date: Sat, 6 Sep 2025 17:42:26 -0300 Subject: [PATCH 03/30] =?UTF-8?q?=E2=99=BB=EF=B8=8Frefactor:=20Update=20Em?= =?UTF-8?q?ployees=20DTOS?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Adding new DTOs for Enums and updating Create, Read and Update DTOs with fields --- .../DTOs/Employee/CreateEmployeeDTO.cs | 37 +++++++++++++++ .../DTOs/Employee/ReadBloodTypeDTO.cs | 14 ++++++ .../DTOs/Employee/ReadCnhCategoryDTO.cs | 14 ++++++ .../DTOs/Employee/ReadEmployeeDTO.cs | 45 +++++++++++++++++++ .../DTOs/Employee/ReadRoleDTO.cs | 14 ++++++ .../DTOs/Employee/ReadStatusDTO.cs | 14 ++++++ .../DTOs/Employee/UpdateEmployeeDTO.cs | 37 +++++++++++++++ 7 files changed, 175 insertions(+) create mode 100644 OneBus.Application/DTOs/Employee/ReadBloodTypeDTO.cs create mode 100644 OneBus.Application/DTOs/Employee/ReadCnhCategoryDTO.cs create mode 100644 OneBus.Application/DTOs/Employee/ReadRoleDTO.cs create mode 100644 OneBus.Application/DTOs/Employee/ReadStatusDTO.cs diff --git a/OneBus.Application/DTOs/Employee/CreateEmployeeDTO.cs b/OneBus.Application/DTOs/Employee/CreateEmployeeDTO.cs index 94cebd9..5d2e64d 100644 --- a/OneBus.Application/DTOs/Employee/CreateEmployeeDTO.cs +++ b/OneBus.Application/DTOs/Employee/CreateEmployeeDTO.cs @@ -2,5 +2,42 @@ { public class CreateEmployeeDTO : BaseCreateDTO { + public CreateEmployeeDTO() + { + Name = string.Empty; + Rg = string.Empty; + Cpf = string.Empty; + Code = string.Empty; + Email = string.Empty; + Phone = string.Empty; + } + + public string Name { get; set; } + + public string Rg { get; set; } + + public string Cpf { get; set; } + + public byte? BloodType { get; set; } + + public string Code { get; set; } + + public byte Role { get; set; } + + public string Email { get; set; } + + public string Phone { get; set; } + + public DateOnly HiringDate { get; set; } + + public string? CnhNumber { get; set; } + + public byte? CnhCategory { get; set; } + + public DateOnly? CnhExpiration { get; set; } + + public byte Status { get; set; } + + public byte[]? Image { get; set; } } } diff --git a/OneBus.Application/DTOs/Employee/ReadBloodTypeDTO.cs b/OneBus.Application/DTOs/Employee/ReadBloodTypeDTO.cs new file mode 100644 index 0000000..aa31519 --- /dev/null +++ b/OneBus.Application/DTOs/Employee/ReadBloodTypeDTO.cs @@ -0,0 +1,14 @@ +namespace OneBus.Application.DTOs.Employee +{ + public class ReadBloodTypeDTO + { + public ReadBloodTypeDTO() + { + Name = string.Empty; + } + + public byte Value { get; set; } + + public string Name { get; set; } + } +} diff --git a/OneBus.Application/DTOs/Employee/ReadCnhCategoryDTO.cs b/OneBus.Application/DTOs/Employee/ReadCnhCategoryDTO.cs new file mode 100644 index 0000000..66dabee --- /dev/null +++ b/OneBus.Application/DTOs/Employee/ReadCnhCategoryDTO.cs @@ -0,0 +1,14 @@ +namespace OneBus.Application.DTOs.Employee +{ + public class ReadCnhCategoryDTO + { + public ReadCnhCategoryDTO() + { + Name = string.Empty; + } + + public byte Value { get; set; } + + public string Name { get; set; } + } +} diff --git a/OneBus.Application/DTOs/Employee/ReadEmployeeDTO.cs b/OneBus.Application/DTOs/Employee/ReadEmployeeDTO.cs index 50af690..b9d5124 100644 --- a/OneBus.Application/DTOs/Employee/ReadEmployeeDTO.cs +++ b/OneBus.Application/DTOs/Employee/ReadEmployeeDTO.cs @@ -2,5 +2,50 @@ { public class ReadEmployeeDTO : BaseReadDTO { + public ReadEmployeeDTO() + { + Name = string.Empty; + Rg = string.Empty; + Cpf = string.Empty; + Code = string.Empty; + Email = string.Empty; + Phone = string.Empty; + } + + public string Name { get; set; } + + public string Rg { get; set; } + + public string Cpf { get; set; } + + public byte? BloodType { get; set; } + + public string? BloodTypeName { get; set; } + + public string Code { get; set; } + + public byte Role { get; set; } + + public string? RoleName { get; set; } + + public string Email { get; set; } + + public string Phone { get; set; } + + public DateOnly HiringDate { get; set; } + + public string? CnhNumber { get; set; } + + public byte? CnhCategory { get; set; } + + public string? CnhCategoryName { get; set; } + + public DateOnly? CnhExpiration { get; set; } + + public byte Status { get; set; } + + public string? StatusName { get; set; } + + public byte[]? Image { get; set; } } } diff --git a/OneBus.Application/DTOs/Employee/ReadRoleDTO.cs b/OneBus.Application/DTOs/Employee/ReadRoleDTO.cs new file mode 100644 index 0000000..616b044 --- /dev/null +++ b/OneBus.Application/DTOs/Employee/ReadRoleDTO.cs @@ -0,0 +1,14 @@ +namespace OneBus.Application.DTOs.Employee +{ + public class ReadRoleDTO + { + public ReadRoleDTO() + { + Name = string.Empty; + } + + public byte Value { get; set; } + + public string Name { get; set; } + } +} diff --git a/OneBus.Application/DTOs/Employee/ReadStatusDTO.cs b/OneBus.Application/DTOs/Employee/ReadStatusDTO.cs new file mode 100644 index 0000000..6712450 --- /dev/null +++ b/OneBus.Application/DTOs/Employee/ReadStatusDTO.cs @@ -0,0 +1,14 @@ +namespace OneBus.Application.DTOs.Employee +{ + public class ReadStatusDTO + { + public ReadStatusDTO() + { + Name = string.Empty; + } + + public byte Value { get; set; } + + public string Name { get; set; } + } +} diff --git a/OneBus.Application/DTOs/Employee/UpdateEmployeeDTO.cs b/OneBus.Application/DTOs/Employee/UpdateEmployeeDTO.cs index 5edf62d..f7ffd31 100644 --- a/OneBus.Application/DTOs/Employee/UpdateEmployeeDTO.cs +++ b/OneBus.Application/DTOs/Employee/UpdateEmployeeDTO.cs @@ -2,5 +2,42 @@ { public class UpdateEmployeeDTO : BaseUpdateDTO { + public UpdateEmployeeDTO() + { + Name = string.Empty; + Rg = string.Empty; + Cpf = string.Empty; + Code = string.Empty; + Email = string.Empty; + Phone = string.Empty; + } + + public string Name { get; set; } + + public string Rg { get; set; } + + public string Cpf { get; set; } + + public byte? BloodType { get; set; } + + public string Code { get; set; } + + public byte Role { get; set; } + + public string Email { get; set; } + + public string Phone { get; set; } + + public DateOnly HiringDate { get; set; } + + public string? CnhNumber { get; set; } + + public byte? CnhCategory { get; set; } + + public DateOnly? CnhExpiration { get; set; } + + public byte Status { get; set; } + + public byte[]? Image { get; set; } } } From 2ae7368e5fdd50df831639b13b66c5c8cbaab41c Mon Sep 17 00:00:00 2001 From: Eduardo Rezende Date: Sat, 6 Sep 2025 17:43:02 -0300 Subject: [PATCH 04/30] =?UTF-8?q?=E2=9C=A8feat:=20Add=20EnumUtils?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Adding class for smart enum methods --- OneBus.Application/Utils/EnumUtils.cs | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 OneBus.Application/Utils/EnumUtils.cs diff --git a/OneBus.Application/Utils/EnumUtils.cs b/OneBus.Application/Utils/EnumUtils.cs new file mode 100644 index 0000000..a697bae --- /dev/null +++ b/OneBus.Application/Utils/EnumUtils.cs @@ -0,0 +1,27 @@ +using System.Reflection; +using System.Text.Json.Serialization; + +namespace OneBus.Application.Utils +{ + public static class EnumUtils + { + public static string? GetName(object? value) + where TEnum : Enum + { + if (value is null) + return null; + + return Enum.GetName(typeof(TEnum), value); + } + + public static string GetDisplayName(this Enum value) + { + var type = value.GetType(); + var memberInfo = type.GetMember(value.ToString()); + var attribute = memberInfo[0] + .GetCustomAttribute(); + + return attribute?.Name ?? value.ToString(); + } + } +} From 20e03be9447d9f066484b2f350b1c94d76a18c05 Mon Sep 17 00:00:00 2001 From: Eduardo Rezende Date: Sat, 6 Sep 2025 17:43:20 -0300 Subject: [PATCH 05/30] =?UTF-8?q?=E2=9C=A8feat:=20Add=20ValidationUtils?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Adding class for smart validation methods --- OneBus.Application/Utils/ValidationUtils.cs | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 OneBus.Application/Utils/ValidationUtils.cs diff --git a/OneBus.Application/Utils/ValidationUtils.cs b/OneBus.Application/Utils/ValidationUtils.cs new file mode 100644 index 0000000..1213843 --- /dev/null +++ b/OneBus.Application/Utils/ValidationUtils.cs @@ -0,0 +1,20 @@ +namespace OneBus.Application.Utils +{ + public static class ValidationUtils + { + public static bool IsValidEnumValue(byte? value) + where TEnum : Enum + { + if (!value.HasValue) + return true; + + return Enum.IsDefined(typeof(TEnum), value); + } + + public static bool IsValidEnumValue(byte value) + where TEnum : Enum + { + return Enum.IsDefined(typeof(TEnum), value); + } + } +} From 5e135af08986fdc409fd0b710b7c638112d7876f Mon Sep 17 00:00:00 2001 From: Eduardo Rezende Date: Sat, 6 Sep 2025 17:43:49 -0300 Subject: [PATCH 06/30] =?UTF-8?q?=E2=99=BB=EF=B8=8Frefactor:=20Update=20Er?= =?UTF-8?q?rorUtils?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Adding AlreadyExists method --- OneBus.Domain/Commons/ErrorUtils.cs | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/OneBus.Domain/Commons/ErrorUtils.cs b/OneBus.Domain/Commons/ErrorUtils.cs index 33f44fa..49c3d48 100644 --- a/OneBus.Domain/Commons/ErrorUtils.cs +++ b/OneBus.Domain/Commons/ErrorUtils.cs @@ -2,6 +2,15 @@ { public static class ErrorUtils { + /// + /// {Campo} já existe. + /// + /// + public static Error AlreadyExists(string field) + { + return new Error($"{field} já existe.", field); + } + /// /// Registro não encontrado. /// From 9dea4277eed37dad524886d645e3ccdbab522835 Mon Sep 17 00:00:00 2001 From: Eduardo Rezende Date: Sat, 6 Sep 2025 17:45:09 -0300 Subject: [PATCH 07/30] =?UTF-8?q?=E2=99=BB=EF=B8=8Frefactor:=20Update=20Em?= =?UTF-8?q?ployee=20Enums?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Adding JsonStringEnumMemberName into values --- OneBus.Domain/Enums/Employee/EmployeeStatus.cs | 5 ++++- OneBus.Domain/Enums/Employee/Role.cs | 5 ++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/OneBus.Domain/Enums/Employee/EmployeeStatus.cs b/OneBus.Domain/Enums/Employee/EmployeeStatus.cs index c765e45..11fd8c8 100644 --- a/OneBus.Domain/Enums/Employee/EmployeeStatus.cs +++ b/OneBus.Domain/Enums/Employee/EmployeeStatus.cs @@ -1,4 +1,6 @@ -namespace OneBus.Domain.Enums.Employee +using System.Text.Json.Serialization; + +namespace OneBus.Domain.Enums.Employee { public enum EmployeeStatus : byte { @@ -8,6 +10,7 @@ public enum EmployeeStatus : byte Desligado, Folga, Ausente, + [JsonStringEnumMemberName("Em Processo de Contratação")] Processo_Contratação } } diff --git a/OneBus.Domain/Enums/Employee/Role.cs b/OneBus.Domain/Enums/Employee/Role.cs index 76fc228..6b32314 100644 --- a/OneBus.Domain/Enums/Employee/Role.cs +++ b/OneBus.Domain/Enums/Employee/Role.cs @@ -1,4 +1,6 @@ -namespace OneBus.Domain.Enums.Employee +using System.Text.Json.Serialization; + +namespace OneBus.Domain.Enums.Employee { public enum Role : byte { @@ -6,6 +8,7 @@ public enum Role : byte Supervisor, Cobrador, Motorista, + [JsonStringEnumMemberName("Motorista e Cobrador")] Motorista_Cobrador } } From efe1d235a6cc6dc5fd9f2ac4575b4e8975ae526d Mon Sep 17 00:00:00 2001 From: Eduardo Rezende Date: Sat, 6 Sep 2025 17:45:31 -0300 Subject: [PATCH 08/30] =?UTF-8?q?=E2=9C=A8feat:=20Add=20EmployeeFilter?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Adding filter class for Employee --- OneBus.Domain/Filters/EmployeeFilter.cs | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 OneBus.Domain/Filters/EmployeeFilter.cs diff --git a/OneBus.Domain/Filters/EmployeeFilter.cs b/OneBus.Domain/Filters/EmployeeFilter.cs new file mode 100644 index 0000000..acdd92e --- /dev/null +++ b/OneBus.Domain/Filters/EmployeeFilter.cs @@ -0,0 +1,17 @@ +namespace OneBus.Domain.Filters +{ + public class EmployeeFilter : BaseFilter + { + public byte? Status { get; set; } + + public byte? CnhCategory { get; set; } + + public byte? Role { get; set; } + + public byte? BloodType { get; set; } + + //public DateOnly? HiringDate { get; set; } + + //public DateOnly? CnhExpiration { get; set; } + } +} From 96b4c1b940b55aab735367992b45bd5f16d161ac Mon Sep 17 00:00:00 2001 From: Eduardo Rezende Date: Sat, 6 Sep 2025 17:46:07 -0300 Subject: [PATCH 09/30] =?UTF-8?q?=E2=99=BB=EF=B8=8Frefactor:=20Update=20Em?= =?UTF-8?q?ployeeRepository?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Updating class with filter references and logic --- .../Repositories/IEmployeeRepository.cs | 2 +- .../Repositories/EmployeeRepository.cs | 21 ++++++++++++++++++- 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/OneBus.Domain/Interfaces/Repositories/IEmployeeRepository.cs b/OneBus.Domain/Interfaces/Repositories/IEmployeeRepository.cs index 5864517..eaeab75 100644 --- a/OneBus.Domain/Interfaces/Repositories/IEmployeeRepository.cs +++ b/OneBus.Domain/Interfaces/Repositories/IEmployeeRepository.cs @@ -3,7 +3,7 @@ namespace OneBus.Domain.Interfaces.Repositories { - public interface IEmployeeRepository : IBaseRepository + public interface IEmployeeRepository : IBaseRepository { } } diff --git a/OneBus.Infra.Data/Repositories/EmployeeRepository.cs b/OneBus.Infra.Data/Repositories/EmployeeRepository.cs index bb22d32..9185981 100644 --- a/OneBus.Infra.Data/Repositories/EmployeeRepository.cs +++ b/OneBus.Infra.Data/Repositories/EmployeeRepository.cs @@ -2,13 +2,32 @@ using OneBus.Domain.Filters; using OneBus.Domain.Interfaces.Repositories; using OneBus.Infra.Data.DbContexts; +using System.Linq.Expressions; namespace OneBus.Infra.Data.Repositories { - public class EmployeeRepository : BaseRepository, IEmployeeRepository + public class EmployeeRepository : BaseRepository, IEmployeeRepository { public EmployeeRepository(OneBusDbContext dbContext) : base(dbContext) { } + + protected override Expression> ApplyFilter(EmployeeFilter filter) + { + var value = filter.Value?.ToLower(); + + return c => + (filter.BloodType == null || c.BloodType == filter.BloodType) && + (filter.Status == null || c.Status == filter.Status) && + (filter.Role == null || c.Role == filter.Role) && + (filter.CnhCategory == null || c.CnhCategory == filter.CnhCategory) && + (string.IsNullOrWhiteSpace(value) || + ((c.Name.ToLower().Contains(value) || + c.Code.ToLower().Contains(value) || + c.Rg.ToLower().Contains(value) || + c.Cpf.ToLower().Contains(value) || + c.Phone.ToLower().Contains(value) || + c.CnhNumber!.ToLower().Contains(value)) && value != string.Empty)); + } } } From ef88067dbae67a5fd7d390e76df4eed96cd7cd83 Mon Sep 17 00:00:00 2001 From: Eduardo Rezende Date: Sat, 6 Sep 2025 17:47:22 -0300 Subject: [PATCH 10/30] =?UTF-8?q?=E2=99=BB=EF=B8=8Frefactor:=20Update=20Em?= =?UTF-8?q?ployeeService?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Adding methods to get enum values and filling UpdateFields method --- .../Interfaces/Services/IEmployeeService.cs | 12 +- .../Services/EmployeeService.cs | 118 +++++++++++++++++- 2 files changed, 123 insertions(+), 7 deletions(-) diff --git a/OneBus.Application/Interfaces/Services/IEmployeeService.cs b/OneBus.Application/Interfaces/Services/IEmployeeService.cs index 6336baa..f4e0a28 100644 --- a/OneBus.Application/Interfaces/Services/IEmployeeService.cs +++ b/OneBus.Application/Interfaces/Services/IEmployeeService.cs @@ -1,11 +1,19 @@ using OneBus.Application.DTOs.Employee; +using OneBus.Domain.Commons.Result; using OneBus.Domain.Entities; using OneBus.Domain.Filters; namespace OneBus.Application.Interfaces.Services { - public interface IEmployeeService : - IBaseService + public interface IEmployeeService : + IBaseService { + Result> GetBloodTypes(); + + Result> GetCnhCategories(); + + Result> GetRoles(); + + Result> GetStatus(); } } diff --git a/OneBus.Application/Services/EmployeeService.cs b/OneBus.Application/Services/EmployeeService.cs index 0d34fe1..b6268d6 100644 --- a/OneBus.Application/Services/EmployeeService.cs +++ b/OneBus.Application/Services/EmployeeService.cs @@ -1,26 +1,134 @@ using FluentValidation; using OneBus.Application.DTOs.Employee; using OneBus.Application.Interfaces.Services; +using OneBus.Application.Utils; +using OneBus.Domain.Commons; +using OneBus.Domain.Commons.Result; using OneBus.Domain.Entities; +using OneBus.Domain.Enums.Employee; using OneBus.Domain.Filters; using OneBus.Domain.Interfaces.Repositories; namespace OneBus.Application.Services { - public class EmployeeService : BaseService, + public class EmployeeService : BaseService, IEmployeeService { public EmployeeService( - IBaseRepository baseRepository, - IValidator createValidator, - IValidator updateValidator) + IBaseRepository baseRepository, + IValidator createValidator, + IValidator updateValidator) : base(baseRepository, createValidator, updateValidator) { } + public override async Task>> GetPaginedAsync(EmployeeFilter filter, CancellationToken cancellationToken = default) + { + var result = await base.GetPaginedAsync(filter, cancellationToken); + + if (!result.Sucess) + return result; + + foreach (var employee in result.Value!.Items) + { + employee.BloodTypeName = EnumUtils.GetName(employee.BloodType); + employee.RoleName = EnumUtils.GetName(employee.Role); + employee.CnhCategoryName = EnumUtils.GetName(employee.CnhCategory); + employee.StatusName = EnumUtils.GetName(employee.Status); + } + + return result; + } + + public override async Task> GetByIdAsync(long id, CancellationToken cancellationToken = default) + { + var result = await base.GetByIdAsync(id, cancellationToken); + + if (!result.Sucess) + return result; + + var employee = result.Value!; + + employee.BloodTypeName = EnumUtils.GetName(employee.BloodType); + employee.RoleName = EnumUtils.GetName(employee.Role); + employee.CnhCategoryName = EnumUtils.GetName(employee.CnhCategory); + employee.StatusName = EnumUtils.GetName(employee.Status); + + return result; + } + + public Result> GetStatus() + { + var values = Enum.GetValues(); + + List status = []; + + foreach (var value in values) + { + status.Add(new ReadStatusDTO { Value = (byte)value, Name = value.GetDisplayName() }); + } + + return SuccessResult>.Create(status); + } + + public Result> GetCnhCategories() + { + var values = Enum.GetValues(); + + List cnhCategories = []; + + foreach (var value in values) + { + cnhCategories.Add(new ReadCnhCategoryDTO { Value = (byte)value, Name = value.GetDisplayName() }); + } + + return SuccessResult>.Create(cnhCategories); + } + + public Result> GetRoles() + { + var values = Enum.GetValues(); + + List roles = []; + + foreach (var value in values) + { + roles.Add(new ReadRoleDTO { Value = (byte)value, Name = value.GetDisplayName() }); + } + + return SuccessResult>.Create(roles); + } + + public Result> GetBloodTypes() + { + var values = Enum.GetValues(); + + List bloodTypes = []; + + foreach (var value in values) + { + bloodTypes.Add(new ReadBloodTypeDTO { Value = (byte)value, Name = value.GetDisplayName() }); + } + + return SuccessResult>.Create(bloodTypes); + } + protected override void UpdateFields(Employee entity, UpdateEmployeeDTO updateDTO) { - throw new NotImplementedException(); + entity.Name = updateDTO.Name; + entity.Rg = updateDTO.Rg; + entity.Cpf = updateDTO.Cpf; + entity.BloodType = updateDTO.BloodType; + entity.Code = updateDTO.Code; + entity.Role = updateDTO.Role; + entity.Email = updateDTO.Email; + entity.Phone = updateDTO.Phone; + entity.HiringDate = updateDTO.HiringDate; + entity.CnhNumber = updateDTO.CnhNumber; + entity.CnhCategory = updateDTO.CnhCategory; + entity.CnhExpiration = updateDTO.CnhExpiration; + entity.Status = updateDTO.Status; + entity.Image = updateDTO.Image; } } } From 943a03513e1ce32c6dcda5740cccd22eae012061 Mon Sep 17 00:00:00 2001 From: Eduardo Rezende Date: Sat, 6 Sep 2025 17:47:54 -0300 Subject: [PATCH 11/30] =?UTF-8?q?=E2=99=BB=EF=B8=8Frefactor:=20Update=20Em?= =?UTF-8?q?ployee=20Validators?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Adding validation for Create and Update Employee DTOs --- .../Employee/CreateEmployeeDTOValidator.cs | 80 ++++++++++++++++++ .../Employee/UpdateEmployeeDTOValidator.cs | 81 +++++++++++++++++++ 2 files changed, 161 insertions(+) diff --git a/OneBus.Application/Validators/Employee/CreateEmployeeDTOValidator.cs b/OneBus.Application/Validators/Employee/CreateEmployeeDTOValidator.cs index 557f699..6e5c81a 100644 --- a/OneBus.Application/Validators/Employee/CreateEmployeeDTOValidator.cs +++ b/OneBus.Application/Validators/Employee/CreateEmployeeDTOValidator.cs @@ -1,9 +1,89 @@ using FluentValidation; using OneBus.Application.DTOs.Employee; +using OneBus.Application.Utils; +using OneBus.Domain.Commons; +using OneBus.Domain.Enums.Employee; +using OneBus.Domain.Interfaces.Repositories; namespace OneBus.Application.Validators.Employee { public class CreateEmployeeDTOValidator : AbstractValidator { + private readonly IEmployeeRepository _employeeRepository; + + public CreateEmployeeDTOValidator(IEmployeeRepository employeeRepository) + { + _employeeRepository = employeeRepository; + + RuleFor(c => c.Name).NotEmpty().OverridePropertyName("Nome"); + RuleFor(c => c.Rg).NotEmpty(); + + RuleFor(c => c.Cpf).NotEmpty() + .MustAsync(async (cpf, ct) => !await CpfAlreadyExistsAsync(cpf, ct)) + .WithMessage(ErrorUtils.AlreadyExists("Cpf").Message); + + RuleFor(c => c.BloodType).Must(ValidationUtils.IsValidEnumValue) + .OverridePropertyName("Tipo Sanguíneo"); + + RuleFor(c => c.Code).NotEmpty() + .MustAsync(async (code, ct) => !await CodeAlreadyExistsAsync(code, ct)) + .OverridePropertyName("Matrícula") + .WithMessage(ErrorUtils.AlreadyExists("Matrícula").Message); + + RuleFor(c => c.Role).Must(ValidationUtils.IsValidEnumValue) + .OverridePropertyName("Cargo"); + + RuleFor(c => c.Email).NotEmpty().EmailAddress() + .MustAsync(async (email, ct) => !await EmailAlreadyExistsAsync(email, ct)) + .WithMessage(ErrorUtils.AlreadyExists("Email").Message); + + RuleFor(c => c.Phone).NotEmpty() + .MustAsync(async (phone, ct) => !await PhoneAlreadyExistsAsync(phone, ct)) + .OverridePropertyName("Telefone") + .WithMessage(ErrorUtils.AlreadyExists("Telefone").Message); + + RuleFor(c => c.CnhNumber) + .MustAsync(async (cnhNumber, ct) => !await CnhNumberAlreadyExistsAsync(cnhNumber, ct)) + .OverridePropertyName("Número da CNH") + .WithMessage(ErrorUtils.AlreadyExists("Número da CNH").Message); + + RuleFor(c => c.CnhCategory).Must(ValidationUtils.IsValidEnumValue) + .OverridePropertyName("Categoria da CNH"); + + RuleFor(c => c.Status).Must(ValidationUtils.IsValidEnumValue); + } + + private async Task CpfAlreadyExistsAsync(string cpf, CancellationToken cancellationToken = default) + { + return await _employeeRepository.AnyAsync(c => c.Cpf.ToLower().Equals(cpf), + cancellationToken: cancellationToken); + } + + private async Task CodeAlreadyExistsAsync(string code, CancellationToken cancellationToken = default) + { + return await _employeeRepository.AnyAsync(c => c.Code.ToLower().Equals(code), + cancellationToken: cancellationToken); + } + + private async Task EmailAlreadyExistsAsync(string email, CancellationToken cancellationToken = default) + { + return await _employeeRepository.AnyAsync(c => c.Email.ToLower().Equals(email), + cancellationToken: cancellationToken); + } + + private async Task PhoneAlreadyExistsAsync(string phone, CancellationToken cancellationToken = default) + { + return await _employeeRepository.AnyAsync(c => c.Phone.ToLower().Equals(phone), + cancellationToken: cancellationToken); + } + + private async Task CnhNumberAlreadyExistsAsync(string? cnhNumber, CancellationToken cancellationToken = default) + { + if (string.IsNullOrWhiteSpace(cnhNumber)) + return false; + + return await _employeeRepository.AnyAsync(c => c.CnhNumber!.ToLower().Equals(cnhNumber), + cancellationToken: cancellationToken); + } } } diff --git a/OneBus.Application/Validators/Employee/UpdateEmployeeDTOValidator.cs b/OneBus.Application/Validators/Employee/UpdateEmployeeDTOValidator.cs index 402ef22..cb4910e 100644 --- a/OneBus.Application/Validators/Employee/UpdateEmployeeDTOValidator.cs +++ b/OneBus.Application/Validators/Employee/UpdateEmployeeDTOValidator.cs @@ -1,9 +1,90 @@ using FluentValidation; using OneBus.Application.DTOs.Employee; +using OneBus.Application.Utils; +using OneBus.Domain.Commons; +using OneBus.Domain.Enums.Employee; +using OneBus.Domain.Interfaces.Repositories; namespace OneBus.Application.Validators.Employee { public class UpdateEmployeeDTOValidator : AbstractValidator { + private readonly IEmployeeRepository _employeeRepository; + + public UpdateEmployeeDTOValidator(IEmployeeRepository employeeRepository) + { + _employeeRepository = employeeRepository; + + RuleFor(c => c.Id).GreaterThan(0); + RuleFor(c => c.Name).NotEmpty().OverridePropertyName("Nome"); + RuleFor(c => c.Rg).NotEmpty(); + + RuleFor(c => c.Cpf).NotEmpty() + .MustAsync(async (employee, cpf, ct) => !await CpfAlreadyExistsAsync(employee.Id, cpf, ct)) + .WithMessage(ErrorUtils.AlreadyExists("Cpf").Message); + + RuleFor(c => c.BloodType).Must(ValidationUtils.IsValidEnumValue) + .OverridePropertyName("Tipo Sanguíneo"); + + RuleFor(c => c.Code).NotEmpty() + .MustAsync(async (employee, code, ct) => !await CodeAlreadyExistsAsync(employee.Id, code, ct)) + .OverridePropertyName("Matrícula") + .WithMessage(ErrorUtils.AlreadyExists("Matrícula").Message); + + RuleFor(c => c.Role).Must(ValidationUtils.IsValidEnumValue) + .OverridePropertyName("Cargo"); + + RuleFor(c => c.Email).NotEmpty().EmailAddress() + .MustAsync(async (employee, email, ct) => !await EmailAlreadyExistsAsync(employee.Id, email, ct)) + .WithMessage(ErrorUtils.AlreadyExists("Email").Message); + + RuleFor(c => c.Phone).NotEmpty() + .MustAsync(async (employee, phone, ct) => !await PhoneAlreadyExistsAsync(employee.Id, phone, ct)) + .OverridePropertyName("Telefone") + .WithMessage(ErrorUtils.AlreadyExists("Telefone").Message); + + RuleFor(c => c.CnhNumber) + .MustAsync(async (employee, cnhNumber, ct) => !await CnhNumberAlreadyExistsAsync(employee.Id, cnhNumber, ct)) + .OverridePropertyName("Número da CNH") + .WithMessage(ErrorUtils.AlreadyExists("Número da CNH").Message); + + RuleFor(c => c.CnhCategory).Must(ValidationUtils.IsValidEnumValue) + .OverridePropertyName("Categoria da CNH"); + + RuleFor(c => c.Status).Must(ValidationUtils.IsValidEnumValue); + } + + private async Task CpfAlreadyExistsAsync(long id, string cpf, CancellationToken cancellationToken = default) + { + return await _employeeRepository.AnyAsync(c => c.Cpf.ToLower().Equals(cpf) && c.Id != id, + cancellationToken: cancellationToken); + } + + private async Task CodeAlreadyExistsAsync(long id, string code, CancellationToken cancellationToken = default) + { + return await _employeeRepository.AnyAsync(c => c.Code.ToLower().Equals(code) && c.Id != id, + cancellationToken: cancellationToken); + } + + private async Task EmailAlreadyExistsAsync(long id, string email, CancellationToken cancellationToken = default) + { + return await _employeeRepository.AnyAsync(c => c.Email.ToLower().Equals(email) && c.Id != id, + cancellationToken: cancellationToken); + } + + private async Task PhoneAlreadyExistsAsync(long id, string phone, CancellationToken cancellationToken = default) + { + return await _employeeRepository.AnyAsync(c => c.Phone.ToLower().Equals(phone) && c.Id != id, + cancellationToken: cancellationToken); + } + + private async Task CnhNumberAlreadyExistsAsync(long id, string? cnhNumber, CancellationToken cancellationToken = default) + { + if (string.IsNullOrWhiteSpace(cnhNumber)) + return false; + + return await _employeeRepository.AnyAsync(c => c.CnhNumber!.ToLower().Equals(cnhNumber) && c.Id != id, + cancellationToken: cancellationToken); + } } } From 5725fd10b1e6ac53915ff02f5ca354a04b098e90 Mon Sep 17 00:00:00 2001 From: Eduardo Rezende Date: Sat, 6 Sep 2025 17:48:59 -0300 Subject: [PATCH 12/30] =?UTF-8?q?=E2=99=BB=EF=B8=8Frefactor:=20Update=20Em?= =?UTF-8?q?ployeeController?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Adding GET endpoints for enums values like status and blood types --- OneBus.API/Controllers/EmployeeController.cs | 63 +++++++++++++++++++- OneBus.API/Controllers/UserController.cs | 2 +- 2 files changed, 62 insertions(+), 3 deletions(-) diff --git a/OneBus.API/Controllers/EmployeeController.cs b/OneBus.API/Controllers/EmployeeController.cs index af85c9a..af5433f 100644 --- a/OneBus.API/Controllers/EmployeeController.cs +++ b/OneBus.API/Controllers/EmployeeController.cs @@ -10,7 +10,6 @@ namespace OneBus.API.Controllers { - [NonController] [Route("api/v1/employees")] [ApiController] [Produces("application/json")] @@ -102,7 +101,7 @@ public async Task DeleteAsync([FromRoute] long id, CancellationTo /// Funcionários paginados e filtrados com sucesso [HttpGet] [ProducesResponseType(typeof(SuccessResult>), StatusCodes.Status200OK)] - public async Task GetPaginedAsync([FromQuery] BaseFilter filter, CancellationToken cancellationToken = default) + public async Task GetPaginedAsync([FromQuery] EmployeeFilter filter, CancellationToken cancellationToken = default) { return (await _employeeService.GetPaginedAsync(filter, cancellationToken)).ToActionResult(); } @@ -125,5 +124,65 @@ public async Task GetByIdAsync([FromRoute] long id, CancellationT { return (await _employeeService.GetByIdAsync(id, cancellationToken)).ToActionResult(); } + + /// + /// Listar status + /// + /// + /// GET de status + /// + /// Status disponíveis + /// Status retornados com sucesso + [HttpGet("status")] + [ProducesResponseType(typeof(SuccessResult>), StatusCodes.Status200OK)] + public IActionResult GetStatus() + { + return _employeeService.GetStatus().ToActionResult(); + } + + /// + /// Listar categorias de cnh + /// + /// + /// GET de categorias de cnh + /// + /// Categorias de cnh disponíveis + /// Categorias de cnh retornados com sucesso + [HttpGet("cnhCategories")] + [ProducesResponseType(typeof(SuccessResult>), StatusCodes.Status200OK)] + public IActionResult GetCnhCategories() + { + return _employeeService.GetCnhCategories().ToActionResult(); + } + + /// + /// Listar cargos + /// + /// + /// GET de cargos + /// + /// Cargos disponíveis + /// Cargos retornados com sucesso + [HttpGet("roles")] + [ProducesResponseType(typeof(SuccessResult>), StatusCodes.Status200OK)] + public IActionResult GetRoles() + { + return _employeeService.GetRoles().ToActionResult(); + } + + /// + /// Listar tipos sanguíneos + /// + /// + /// GET de tipos sanguíneos + /// + /// Tipos sanguíneos disponíveis + /// Tipos sanguíneos retornados com sucesso + [HttpGet("bloodTypes")] + [ProducesResponseType(typeof(SuccessResult>), StatusCodes.Status200OK)] + public IActionResult GetBloodTypes() + { + return _employeeService.GetBloodTypes().ToActionResult(); + } } } diff --git a/OneBus.API/Controllers/UserController.cs b/OneBus.API/Controllers/UserController.cs index cbbb7f0..7ca6bae 100644 --- a/OneBus.API/Controllers/UserController.cs +++ b/OneBus.API/Controllers/UserController.cs @@ -27,7 +27,7 @@ public UserController(IUserService userService) /// Efetuar login /// /// - /// Example: + /// Exemplo: /// /// POST /logins /// { From 0206af85fb01dea6156d0c2efa49ee708d8fc4c9 Mon Sep 17 00:00:00 2001 From: Eduardo Rezende Date: Sat, 20 Sep 2025 15:04:39 -0300 Subject: [PATCH 13/30] =?UTF-8?q?=F0=9F=93=A6build:=20Update=20nuget=20pac?= =?UTF-8?q?kages?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Updating projects packages --- OneBus.API/OneBus.API.csproj | 6 +++--- OneBus.Application/OneBus.Application.csproj | 2 +- OneBus.Infra.Data/OneBus.Infra.Data.csproj | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/OneBus.API/OneBus.API.csproj b/OneBus.API/OneBus.API.csproj index 699bf51..56da312 100644 --- a/OneBus.API/OneBus.API.csproj +++ b/OneBus.API/OneBus.API.csproj @@ -11,9 +11,9 @@ - - - + + + all runtime; build; native; contentfiles; analyzers; buildtransitive diff --git a/OneBus.Application/OneBus.Application.csproj b/OneBus.Application/OneBus.Application.csproj index f44ee7b..eee47b5 100644 --- a/OneBus.Application/OneBus.Application.csproj +++ b/OneBus.Application/OneBus.Application.csproj @@ -10,7 +10,7 @@ - + diff --git a/OneBus.Infra.Data/OneBus.Infra.Data.csproj b/OneBus.Infra.Data/OneBus.Infra.Data.csproj index 00869b2..aecb86e 100644 --- a/OneBus.Infra.Data/OneBus.Infra.Data.csproj +++ b/OneBus.Infra.Data/OneBus.Infra.Data.csproj @@ -7,11 +7,11 @@ - + all runtime; build; native; contentfiles; analyzers; buildtransitive - + all runtime; build; native; contentfiles; analyzers; buildtransitive From 55c6169798d583352b7ab94bf130b69ffd56b9a7 Mon Sep 17 00:00:00 2001 From: Eduardo Rezende Date: Sat, 20 Sep 2025 16:46:21 -0300 Subject: [PATCH 14/30] =?UTF-8?q?=E2=9C=A8feat:=20Add=20Messages.resx?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Adding resource file to handle key value message for the UI --- OneBus.Domain/OneBus.Domain.csproj | 16 ++ OneBus.Domain/Resources/Messages.Designer.cs | 171 +++++++++++++++++++ OneBus.Domain/Resources/Messages.resx | 156 +++++++++++++++++ 3 files changed, 343 insertions(+) create mode 100644 OneBus.Domain/Resources/Messages.Designer.cs create mode 100644 OneBus.Domain/Resources/Messages.resx diff --git a/OneBus.Domain/OneBus.Domain.csproj b/OneBus.Domain/OneBus.Domain.csproj index 125f4c9..526283f 100644 --- a/OneBus.Domain/OneBus.Domain.csproj +++ b/OneBus.Domain/OneBus.Domain.csproj @@ -4,6 +4,22 @@ net9.0 enable enable + Resources + + + True + True + Messages.resx + + + + + + ResXFileCodeGenerator + Messages.Designer.cs + + + diff --git a/OneBus.Domain/Resources/Messages.Designer.cs b/OneBus.Domain/Resources/Messages.Designer.cs new file mode 100644 index 0000000..8ae2b7b --- /dev/null +++ b/OneBus.Domain/Resources/Messages.Designer.cs @@ -0,0 +1,171 @@ +//------------------------------------------------------------------------------ +// +// O código foi gerado por uma ferramenta. +// Versão de Tempo de Execução:4.0.30319.42000 +// +// As alterações ao arquivo poderão causar comportamento incorreto e serão perdidas se +// o código for gerado novamente. +// +//------------------------------------------------------------------------------ + +namespace OneBus.Domain.Resources { + using System; + + + /// + /// Uma classe de recurso de tipo de alta segurança, para pesquisar cadeias de caracteres localizadas etc. + /// + // Essa classe foi gerada automaticamente pela classe StronglyTypedResourceBuilder + // através de uma ferramenta como ResGen ou Visual Studio. + // Para adicionar ou remover um associado, edite o arquivo .ResX e execute ResGen novamente + // com a opção /str, ou recrie o projeto do VS. + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "17.0.0.0")] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] + internal class Messages { + + private static global::System.Resources.ResourceManager resourceMan; + + private static global::System.Globalization.CultureInfo resourceCulture; + + [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] + internal Messages() { + } + + /// + /// Retorna a instância de ResourceManager armazenada em cache usada por essa classe. + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + internal static global::System.Resources.ResourceManager ResourceManager { + get { + if (object.ReferenceEquals(resourceMan, null)) { + global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("OneBus.Domain.Resources.Messages", typeof(Messages).Assembly); + resourceMan = temp; + } + return resourceMan; + } + } + + /// + /// Substitui a propriedade CurrentUICulture do thread atual para todas as + /// pesquisas de recursos que usam essa classe de recurso de tipo de alta segurança. + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + internal static global::System.Globalization.CultureInfo Culture { + get { + return resourceCulture; + } + set { + resourceCulture = value; + } + } + + /// + /// Consulta uma cadeia de caracteres localizada semelhante a A-. + /// + internal static string A_Negative { + get { + return ResourceManager.GetString("A_Negative", resourceCulture); + } + } + + /// + /// Consulta uma cadeia de caracteres localizada semelhante a A+. + /// + internal static string A_Positive { + get { + return ResourceManager.GetString("A_Positive", resourceCulture); + } + } + + /// + /// Consulta uma cadeia de caracteres localizada semelhante a AB-. + /// + internal static string AB_Negative { + get { + return ResourceManager.GetString("AB_Negative", resourceCulture); + } + } + + /// + /// Consulta uma cadeia de caracteres localizada semelhante a AB+. + /// + internal static string AB_Positive { + get { + return ResourceManager.GetString("AB_Positive", resourceCulture); + } + } + + /// + /// Consulta uma cadeia de caracteres localizada semelhante a B-. + /// + internal static string B_Negative { + get { + return ResourceManager.GetString("B_Negative", resourceCulture); + } + } + + /// + /// Consulta uma cadeia de caracteres localizada semelhante a B+. + /// + internal static string B_Positive { + get { + return ResourceManager.GetString("B_Positive", resourceCulture); + } + } + + /// + /// Consulta uma cadeia de caracteres localizada semelhante a Dias Úteis. + /// + internal static string Dias_Úteis { + get { + return ResourceManager.GetString("Dias_Úteis", resourceCulture); + } + } + + /// + /// Consulta uma cadeia de caracteres localizada semelhante a Domingos e Feriados. + /// + internal static string Domingos_Feriados { + get { + return ResourceManager.GetString("Domingos_Feriados", resourceCulture); + } + } + + /// + /// Consulta uma cadeia de caracteres localizada semelhante a Motorista e Cobrador. + /// + internal static string Motorista_Cobrador { + get { + return ResourceManager.GetString("Motorista_Cobrador", resourceCulture); + } + } + + /// + /// Consulta uma cadeia de caracteres localizada semelhante a O-. + /// + internal static string O_Negative { + get { + return ResourceManager.GetString("O_Negative", resourceCulture); + } + } + + /// + /// Consulta uma cadeia de caracteres localizada semelhante a O+. + /// + internal static string O_Positive { + get { + return ResourceManager.GetString("O_Positive", resourceCulture); + } + } + + /// + /// Consulta uma cadeia de caracteres localizada semelhante a Em Processo de Contratação. + /// + internal static string Processo_Contratação { + get { + return ResourceManager.GetString("Processo_Contratação", resourceCulture); + } + } + } +} diff --git a/OneBus.Domain/Resources/Messages.resx b/OneBus.Domain/Resources/Messages.resx new file mode 100644 index 0000000..9b21cad --- /dev/null +++ b/OneBus.Domain/Resources/Messages.resx @@ -0,0 +1,156 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + AB- + + + AB+ + + + A- + + + A+ + + + B- + + + B+ + + + Dias Úteis + + + Domingos e Feriados + + + Motorista e Cobrador + + + O- + + + O+ + + + Em Processo de Contratação + + \ No newline at end of file From e7771afb030abd3fb9d1bf0ad23b1d7354202f3a Mon Sep 17 00:00:00 2001 From: Eduardo Rezende Date: Sat, 20 Sep 2025 16:46:56 -0300 Subject: [PATCH 15/30] =?UTF-8?q?=E2=9C=A8feat:=20Add=20ResourceMgr?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Adding wrapper class for Resource Manager --- OneBus.Domain/Commons/ResourceMgr.cs | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 OneBus.Domain/Commons/ResourceMgr.cs diff --git a/OneBus.Domain/Commons/ResourceMgr.cs b/OneBus.Domain/Commons/ResourceMgr.cs new file mode 100644 index 0000000..709fd01 --- /dev/null +++ b/OneBus.Domain/Commons/ResourceMgr.cs @@ -0,0 +1,28 @@ +using System.Globalization; +using System.Reflection; +using System.Resources; + +namespace OneBus.Domain.Commons +{ + public static class ResourceMgr + { + public static string GetString( + string? name, + bool returnEmptyWhenNotFound = false, + bool returnKeyWhenNotFound = false) + { + if (string.IsNullOrWhiteSpace(name)) + return string.Empty; + + ResourceManager resourceManager = new("OneBus.Domain.Resources.Messages", Assembly.GetExecutingAssembly()); + Thread.CurrentThread.CurrentUICulture = CultureInfo.GetCultureInfo("pt-BR"); + string? result = resourceManager.GetString(name); + + if (!string.IsNullOrWhiteSpace(result)) + return result; + + return returnEmptyWhenNotFound ? string.Empty : + returnKeyWhenNotFound ? name : $"[[{name}]]"; + } + } +} From aecd9184d22ad08fbdfbb74ae5d606e158e458c2 Mon Sep 17 00:00:00 2001 From: Eduardo Rezende Date: Sat, 20 Sep 2025 16:50:35 -0300 Subject: [PATCH 16/30] =?UTF-8?q?=E2=99=BB=EF=B8=8Frefactor:=20Update=20Db?= =?UTF-8?q?QueryOptions?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Updating constructor field orders --- OneBus.Domain/Commons/DbQueryOptions.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/OneBus.Domain/Commons/DbQueryOptions.cs b/OneBus.Domain/Commons/DbQueryOptions.cs index c54e036..afcede9 100644 --- a/OneBus.Domain/Commons/DbQueryOptions.cs +++ b/OneBus.Domain/Commons/DbQueryOptions.cs @@ -12,7 +12,7 @@ private DbQueryOptions(bool ignoreQueryFilter, params string[]? includes) public string[]? Includes { get; } - public static DbQueryOptions Create(bool ignoreQueryFilter = false, params string[]? includes) + public static DbQueryOptions Create(string[]? includes = null, bool ignoreQueryFilter = false) { return new DbQueryOptions(ignoreQueryFilter, includes); } From f1c4864ad13f828f9c72221ff61092dc43809625 Mon Sep 17 00:00:00 2001 From: Eduardo Rezende Date: Sat, 20 Sep 2025 16:51:19 -0300 Subject: [PATCH 17/30] =?UTF-8?q?=E2=99=BB=EF=B8=8Frefactor:=20Update=20En?= =?UTF-8?q?ums=20values?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Updating enums values --- OneBus.Domain/Enums/DayType.cs | 3 +-- OneBus.Domain/Enums/Employee/BloodType.cs | 12 ++++++++---- OneBus.Domain/Enums/Employee/EmployeeStatus.cs | 5 +---- OneBus.Domain/Enums/Employee/Role.cs | 5 +---- 4 files changed, 11 insertions(+), 14 deletions(-) diff --git a/OneBus.Domain/Enums/DayType.cs b/OneBus.Domain/Enums/DayType.cs index a50e9da..5e550cd 100644 --- a/OneBus.Domain/Enums/DayType.cs +++ b/OneBus.Domain/Enums/DayType.cs @@ -4,7 +4,6 @@ public enum DayType : byte { Dias_Úteis, Sábados, - Domingos, - Feriados + Domingos_Feriados, } } diff --git a/OneBus.Domain/Enums/Employee/BloodType.cs b/OneBus.Domain/Enums/Employee/BloodType.cs index fde1364..6cb335c 100644 --- a/OneBus.Domain/Enums/Employee/BloodType.cs +++ b/OneBus.Domain/Enums/Employee/BloodType.cs @@ -2,9 +2,13 @@ { public enum BloodType : byte { - A, - B, - AB, - O + A_Positive, + A_Negative, + B_Positive, + B_Negative, + AB_Positive, + AB_Negative, + O_Positive, + O_Negative } } diff --git a/OneBus.Domain/Enums/Employee/EmployeeStatus.cs b/OneBus.Domain/Enums/Employee/EmployeeStatus.cs index 11fd8c8..c765e45 100644 --- a/OneBus.Domain/Enums/Employee/EmployeeStatus.cs +++ b/OneBus.Domain/Enums/Employee/EmployeeStatus.cs @@ -1,6 +1,4 @@ -using System.Text.Json.Serialization; - -namespace OneBus.Domain.Enums.Employee +namespace OneBus.Domain.Enums.Employee { public enum EmployeeStatus : byte { @@ -10,7 +8,6 @@ public enum EmployeeStatus : byte Desligado, Folga, Ausente, - [JsonStringEnumMemberName("Em Processo de Contratação")] Processo_Contratação } } diff --git a/OneBus.Domain/Enums/Employee/Role.cs b/OneBus.Domain/Enums/Employee/Role.cs index 6b32314..76fc228 100644 --- a/OneBus.Domain/Enums/Employee/Role.cs +++ b/OneBus.Domain/Enums/Employee/Role.cs @@ -1,6 +1,4 @@ -using System.Text.Json.Serialization; - -namespace OneBus.Domain.Enums.Employee +namespace OneBus.Domain.Enums.Employee { public enum Role : byte { @@ -8,7 +6,6 @@ public enum Role : byte Supervisor, Cobrador, Motorista, - [JsonStringEnumMemberName("Motorista e Cobrador")] Motorista_Cobrador } } From 4b5edda4586dbad435ddc1049d493ac83eb67a61 Mon Sep 17 00:00:00 2001 From: Eduardo Rezende Date: Sat, 20 Sep 2025 16:52:04 -0300 Subject: [PATCH 18/30] =?UTF-8?q?=E2=9C=A8feat:=20Add=20LocalizationExtens?= =?UTF-8?q?ions?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Adding extension to easily localize values --- OneBus.Domain/Extensions/LocalizationExtensions.cs | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 OneBus.Domain/Extensions/LocalizationExtensions.cs diff --git a/OneBus.Domain/Extensions/LocalizationExtensions.cs b/OneBus.Domain/Extensions/LocalizationExtensions.cs new file mode 100644 index 0000000..4cc8b57 --- /dev/null +++ b/OneBus.Domain/Extensions/LocalizationExtensions.cs @@ -0,0 +1,12 @@ +using OneBus.Domain.Commons; + +namespace OneBus.Domain.Extensions +{ + public static class LocalizationExtensions + { + public static string Localize(this string? value) + { + return ResourceMgr.GetString(value, returnKeyWhenNotFound: true); + } + } +} From c64fd8dd81b934fae4e426d8467a5dca13c43424 Mon Sep 17 00:00:00 2001 From: Eduardo Rezende Date: Sat, 20 Sep 2025 16:52:54 -0300 Subject: [PATCH 19/30] =?UTF-8?q?=E2=9C=A8feat:=20Add=20EmployeeFilter?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Adding filter class for EmployeeWorkDay --- OneBus.Domain/Filters/EmployeeFilter.cs | 6 ------ OneBus.Domain/Filters/EmployeeWorkDayFilter.cs | 7 +++++++ 2 files changed, 7 insertions(+), 6 deletions(-) create mode 100644 OneBus.Domain/Filters/EmployeeWorkDayFilter.cs diff --git a/OneBus.Domain/Filters/EmployeeFilter.cs b/OneBus.Domain/Filters/EmployeeFilter.cs index acdd92e..406a95c 100644 --- a/OneBus.Domain/Filters/EmployeeFilter.cs +++ b/OneBus.Domain/Filters/EmployeeFilter.cs @@ -4,14 +4,8 @@ public class EmployeeFilter : BaseFilter { public byte? Status { get; set; } - public byte? CnhCategory { get; set; } - public byte? Role { get; set; } public byte? BloodType { get; set; } - - //public DateOnly? HiringDate { get; set; } - - //public DateOnly? CnhExpiration { get; set; } } } diff --git a/OneBus.Domain/Filters/EmployeeWorkDayFilter.cs b/OneBus.Domain/Filters/EmployeeWorkDayFilter.cs new file mode 100644 index 0000000..d0f19ba --- /dev/null +++ b/OneBus.Domain/Filters/EmployeeWorkDayFilter.cs @@ -0,0 +1,7 @@ +namespace OneBus.Domain.Filters +{ + public class EmployeeWorkDayFilter : BaseFilter + { + public byte? DayType { get; set; } + } +} From 5b2457a317a89e81fff718d964f755ae957305ee Mon Sep 17 00:00:00 2001 From: Eduardo Rezende Date: Sat, 20 Sep 2025 16:54:36 -0300 Subject: [PATCH 20/30] =?UTF-8?q?=E2=9C=A8feat:=20Add=20EmployeeWorkday=20?= =?UTF-8?q?Repository?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Adding repository class for EmployeeWorkday --- .../Repositories/IEmployeeWorkdayRepository.cs | 2 +- .../Repositories/EmployeeRepository.cs | 1 - .../Repositories/EmployeeWorkdayRepository.cs | 18 +++++++++++++++++- 3 files changed, 18 insertions(+), 3 deletions(-) diff --git a/OneBus.Domain/Interfaces/Repositories/IEmployeeWorkdayRepository.cs b/OneBus.Domain/Interfaces/Repositories/IEmployeeWorkdayRepository.cs index bb52d6f..3cf5101 100644 --- a/OneBus.Domain/Interfaces/Repositories/IEmployeeWorkdayRepository.cs +++ b/OneBus.Domain/Interfaces/Repositories/IEmployeeWorkdayRepository.cs @@ -3,7 +3,7 @@ namespace OneBus.Domain.Interfaces.Repositories { - public interface IEmployeeWorkdayRepository : IBaseRepository + public interface IEmployeeWorkdayRepository : IBaseRepository { } } diff --git a/OneBus.Infra.Data/Repositories/EmployeeRepository.cs b/OneBus.Infra.Data/Repositories/EmployeeRepository.cs index 9185981..ae396fb 100644 --- a/OneBus.Infra.Data/Repositories/EmployeeRepository.cs +++ b/OneBus.Infra.Data/Repositories/EmployeeRepository.cs @@ -20,7 +20,6 @@ protected override Expression> ApplyFilter(EmployeeFilter f (filter.BloodType == null || c.BloodType == filter.BloodType) && (filter.Status == null || c.Status == filter.Status) && (filter.Role == null || c.Role == filter.Role) && - (filter.CnhCategory == null || c.CnhCategory == filter.CnhCategory) && (string.IsNullOrWhiteSpace(value) || ((c.Name.ToLower().Contains(value) || c.Code.ToLower().Contains(value) || diff --git a/OneBus.Infra.Data/Repositories/EmployeeWorkdayRepository.cs b/OneBus.Infra.Data/Repositories/EmployeeWorkdayRepository.cs index 8aa1d28..f80b6d5 100644 --- a/OneBus.Infra.Data/Repositories/EmployeeWorkdayRepository.cs +++ b/OneBus.Infra.Data/Repositories/EmployeeWorkdayRepository.cs @@ -2,13 +2,29 @@ using OneBus.Domain.Filters; using OneBus.Domain.Interfaces.Repositories; using OneBus.Infra.Data.DbContexts; +using System.Linq.Expressions; namespace OneBus.Infra.Data.Repositories { - public class EmployeeWorkdayRepository : BaseRepository, IEmployeeWorkdayRepository + public class EmployeeWorkdayRepository : BaseRepository, IEmployeeWorkdayRepository { public EmployeeWorkdayRepository(OneBusDbContext dbContext) : base(dbContext) { } + + protected override Expression> ApplyFilter(EmployeeWorkDayFilter filter) + { + var value = filter.Value?.ToLower(); + + return c => + (filter.DayType == null || c.DayType == filter.DayType) && + (string.IsNullOrWhiteSpace(value) || + ((c.Employee!.Name.ToLower().Contains(value) || + c.Employee!.Code.ToLower().Contains(value) || + c.Employee!.Rg.ToLower().Contains(value) || + c.Employee!.Cpf.ToLower().Contains(value) || + c.Employee!.Phone.ToLower().Contains(value) || + c.Employee!.CnhNumber!.ToLower().Contains(value)) && value != string.Empty)); + } } } From c592c57f398a67bb3267fdb5fb20da07664b5f8f Mon Sep 17 00:00:00 2001 From: Eduardo Rezende Date: Sat, 20 Sep 2025 16:55:21 -0300 Subject: [PATCH 21/30] =?UTF-8?q?=E2=99=BB=EF=B8=8Frefactor:=20Update=20De?= =?UTF-8?q?pendencyInjection?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Adding default culture for validation messages --- OneBus.Infra.Ioc/DependencyInjection.cs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/OneBus.Infra.Ioc/DependencyInjection.cs b/OneBus.Infra.Ioc/DependencyInjection.cs index 23b2327..d5d36fd 100644 --- a/OneBus.Infra.Ioc/DependencyInjection.cs +++ b/OneBus.Infra.Ioc/DependencyInjection.cs @@ -4,6 +4,7 @@ using OneBus.Application.Services; using OneBus.Domain.Interfaces.Repositories; using OneBus.Infra.Data.Repositories; +using System.Globalization; namespace OneBus.Infra.Ioc { @@ -11,6 +12,7 @@ public static class DependencyInjection { public static IServiceCollection AddInfrastructure(this IServiceCollection services) { + ValidatorOptions.Global.LanguageManager.Culture = new CultureInfo("pt-BR"); services.AddValidatorsFromAssembly(typeof(IBaseReadOnlyService<,,>).Assembly); services.Scan(scan => scan From 4911770a6aaebed2646946ee0939848ba7bbf4d5 Mon Sep 17 00:00:00 2001 From: Eduardo Rezende Date: Sat, 20 Sep 2025 16:56:36 -0300 Subject: [PATCH 22/30] =?UTF-8?q?=E2=99=BB=EF=B8=8Frefactor:=20Update=20Em?= =?UTF-8?q?ployee=20DTOs?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Removing CnhCategory fields --- .../DTOs/Employee/CreateEmployeeDTO.cs | 2 -- .../DTOs/Employee/ReadCnhCategoryDTO.cs | 14 -------------- .../DTOs/Employee/ReadEmployeeDTO.cs | 4 ---- .../DTOs/Employee/UpdateEmployeeDTO.cs | 2 -- 4 files changed, 22 deletions(-) delete mode 100644 OneBus.Application/DTOs/Employee/ReadCnhCategoryDTO.cs diff --git a/OneBus.Application/DTOs/Employee/CreateEmployeeDTO.cs b/OneBus.Application/DTOs/Employee/CreateEmployeeDTO.cs index 5d2e64d..6e99d15 100644 --- a/OneBus.Application/DTOs/Employee/CreateEmployeeDTO.cs +++ b/OneBus.Application/DTOs/Employee/CreateEmployeeDTO.cs @@ -32,8 +32,6 @@ public CreateEmployeeDTO() public string? CnhNumber { get; set; } - public byte? CnhCategory { get; set; } - public DateOnly? CnhExpiration { get; set; } public byte Status { get; set; } diff --git a/OneBus.Application/DTOs/Employee/ReadCnhCategoryDTO.cs b/OneBus.Application/DTOs/Employee/ReadCnhCategoryDTO.cs deleted file mode 100644 index 66dabee..0000000 --- a/OneBus.Application/DTOs/Employee/ReadCnhCategoryDTO.cs +++ /dev/null @@ -1,14 +0,0 @@ -namespace OneBus.Application.DTOs.Employee -{ - public class ReadCnhCategoryDTO - { - public ReadCnhCategoryDTO() - { - Name = string.Empty; - } - - public byte Value { get; set; } - - public string Name { get; set; } - } -} diff --git a/OneBus.Application/DTOs/Employee/ReadEmployeeDTO.cs b/OneBus.Application/DTOs/Employee/ReadEmployeeDTO.cs index b9d5124..331f3d2 100644 --- a/OneBus.Application/DTOs/Employee/ReadEmployeeDTO.cs +++ b/OneBus.Application/DTOs/Employee/ReadEmployeeDTO.cs @@ -36,10 +36,6 @@ public ReadEmployeeDTO() public string? CnhNumber { get; set; } - public byte? CnhCategory { get; set; } - - public string? CnhCategoryName { get; set; } - public DateOnly? CnhExpiration { get; set; } public byte Status { get; set; } diff --git a/OneBus.Application/DTOs/Employee/UpdateEmployeeDTO.cs b/OneBus.Application/DTOs/Employee/UpdateEmployeeDTO.cs index f7ffd31..7ed7a61 100644 --- a/OneBus.Application/DTOs/Employee/UpdateEmployeeDTO.cs +++ b/OneBus.Application/DTOs/Employee/UpdateEmployeeDTO.cs @@ -32,8 +32,6 @@ public UpdateEmployeeDTO() public string? CnhNumber { get; set; } - public byte? CnhCategory { get; set; } - public DateOnly? CnhExpiration { get; set; } public byte Status { get; set; } From a430416d263ba2b89f07e4f2b430ce9f3b8bf759 Mon Sep 17 00:00:00 2001 From: Eduardo Rezende Date: Sat, 20 Sep 2025 16:57:23 -0300 Subject: [PATCH 23/30] =?UTF-8?q?=E2=99=BB=EF=B8=8Frefactor:=20Update=20Em?= =?UTF-8?q?ployeeWorkday=20DTOs?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Adding values to DTOs --- .../EmployeeWorkday/CreateEmployeeWorkdayDTO.cs | 7 +++++++ .../DTOs/EmployeeWorkday/ReadDayTypeDTO.cs | 14 ++++++++++++++ .../EmployeeWorkday/ReadEmployeeWorkdayDTO.cs | 15 +++++++++++++++ .../EmployeeWorkday/UpdateEmployeeWorkdayDTO.cs | 3 +++ 4 files changed, 39 insertions(+) create mode 100644 OneBus.Application/DTOs/EmployeeWorkday/ReadDayTypeDTO.cs diff --git a/OneBus.Application/DTOs/EmployeeWorkday/CreateEmployeeWorkdayDTO.cs b/OneBus.Application/DTOs/EmployeeWorkday/CreateEmployeeWorkdayDTO.cs index 448df95..f38309f 100644 --- a/OneBus.Application/DTOs/EmployeeWorkday/CreateEmployeeWorkdayDTO.cs +++ b/OneBus.Application/DTOs/EmployeeWorkday/CreateEmployeeWorkdayDTO.cs @@ -2,5 +2,12 @@ { public class CreateEmployeeWorkdayDTO : BaseCreateDTO { + public long EmployeeId { get; set; } + + public TimeOnly StartTime { get; set; } + + public TimeOnly EndTime { get; set; } + + public byte DayType { get; set; } } } diff --git a/OneBus.Application/DTOs/EmployeeWorkday/ReadDayTypeDTO.cs b/OneBus.Application/DTOs/EmployeeWorkday/ReadDayTypeDTO.cs new file mode 100644 index 0000000..a8672c2 --- /dev/null +++ b/OneBus.Application/DTOs/EmployeeWorkday/ReadDayTypeDTO.cs @@ -0,0 +1,14 @@ +namespace OneBus.Application.DTOs.EmployeeWorkday +{ + public class ReadDayTypeDTO + { + public ReadDayTypeDTO() + { + Name = string.Empty; + } + + public byte Value { get; set; } + + public string Name { get; set; } + } +} diff --git a/OneBus.Application/DTOs/EmployeeWorkday/ReadEmployeeWorkdayDTO.cs b/OneBus.Application/DTOs/EmployeeWorkday/ReadEmployeeWorkdayDTO.cs index 5432271..701d2bb 100644 --- a/OneBus.Application/DTOs/EmployeeWorkday/ReadEmployeeWorkdayDTO.cs +++ b/OneBus.Application/DTOs/EmployeeWorkday/ReadEmployeeWorkdayDTO.cs @@ -2,5 +2,20 @@ { public class ReadEmployeeWorkdayDTO : BaseReadDTO { + public long EmployeeId { get; set; } + + public string? EmployeeName { get; set; } + + public string? EmployeeCpf { get; set; } + + public string? EmployeeCode { get; set; } + + public TimeOnly StartTime { get; set; } + + public TimeOnly EndTime { get; set; } + + public byte DayType { get; set; } + + public string? DayTypeName { get; set; } } } diff --git a/OneBus.Application/DTOs/EmployeeWorkday/UpdateEmployeeWorkdayDTO.cs b/OneBus.Application/DTOs/EmployeeWorkday/UpdateEmployeeWorkdayDTO.cs index 03ca0ef..278f72e 100644 --- a/OneBus.Application/DTOs/EmployeeWorkday/UpdateEmployeeWorkdayDTO.cs +++ b/OneBus.Application/DTOs/EmployeeWorkday/UpdateEmployeeWorkdayDTO.cs @@ -2,5 +2,8 @@ { public class UpdateEmployeeWorkdayDTO : BaseUpdateDTO { + public TimeOnly StartTime { get; set; } + + public TimeOnly EndTime { get; set; } } } From 3b09d40935cc36077c0df27cd98d6739ea46178d Mon Sep 17 00:00:00 2001 From: Eduardo Rezende Date: Sat, 20 Sep 2025 16:58:43 -0300 Subject: [PATCH 24/30] =?UTF-8?q?=E2=99=BB=EF=B8=8Frefactor:=20Update=20Ba?= =?UTF-8?q?seReadOnly=20Service?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Adding DbQueryOptions optional parameter to get methods --- .../Interfaces/Services/IBaseReadOnlyService.cs | 2 ++ OneBus.Application/Services/BaseReadOnlyService.cs | 8 +++++--- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/OneBus.Application/Interfaces/Services/IBaseReadOnlyService.cs b/OneBus.Application/Interfaces/Services/IBaseReadOnlyService.cs index 5e18a65..65570dc 100644 --- a/OneBus.Application/Interfaces/Services/IBaseReadOnlyService.cs +++ b/OneBus.Application/Interfaces/Services/IBaseReadOnlyService.cs @@ -13,10 +13,12 @@ public interface IBaseReadOnlyService { Task>> GetPaginedAsync( TFilter filter, + DbQueryOptions? dbQueryOptions = null, CancellationToken cancellationToken = default); Task> GetByIdAsync( long id, + DbQueryOptions? dbQueryOptions = null, CancellationToken cancellationToken = default); } } diff --git a/OneBus.Application/Services/BaseReadOnlyService.cs b/OneBus.Application/Services/BaseReadOnlyService.cs index 9640501..1578ca6 100644 --- a/OneBus.Application/Services/BaseReadOnlyService.cs +++ b/OneBus.Application/Services/BaseReadOnlyService.cs @@ -23,9 +23,10 @@ protected BaseReadOnlyService(IBaseReadOnlyRepository baseRead public virtual async Task>> GetPaginedAsync( TFilter filter, + DbQueryOptions? dbQueryOptions = null, CancellationToken cancellationToken = default) { - long totalItems = await _baseReadOnlyRepository.LongCountAsync(filter, dbQueryOptions: null, cancellationToken); + long totalItems = await _baseReadOnlyRepository.LongCountAsync(filter, dbQueryOptions, cancellationToken); if (totalItems < 1) { @@ -33,7 +34,7 @@ public virtual async Task>> GetPaginedAsync( .Create(new Pagination(items: [], totalItems, filter.CurrentPage, filter.PageSize)); } - IEnumerable entities = await _baseReadOnlyRepository.GetPaginedAsync(filter, dbQueryOptions: null, cancellationToken); + IEnumerable entities = await _baseReadOnlyRepository.GetPaginedAsync(filter, dbQueryOptions, cancellationToken); IEnumerable entitiesDTO = entities.Adapt>(); @@ -43,9 +44,10 @@ public virtual async Task>> GetPaginedAsync( public virtual async Task> GetByIdAsync( long id, + DbQueryOptions? dbQueryOptions = null, CancellationToken cancellationToken = default) { - TEntity? entity = await _baseReadOnlyRepository.GetOneAsync(c => c.Id == id, dbQueryOptions: null, cancellationToken); + TEntity? entity = await _baseReadOnlyRepository.GetOneAsync(c => c.Id == id, dbQueryOptions, cancellationToken); if (entity is null) return NotFoundResult.Create(ErrorUtils.EntityNotFound()); From 48bd656f9dba56a92fa4edf06c61b7e809eb7529 Mon Sep 17 00:00:00 2001 From: Eduardo Rezende Date: Sat, 20 Sep 2025 16:59:55 -0300 Subject: [PATCH 25/30] =?UTF-8?q?=E2=99=BB=EF=B8=8Frefactor:=20Update=20Em?= =?UTF-8?q?ployee=20Service?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Removing CnhCategory references and improving enum values reading --- .../Interfaces/Services/IEmployeeService.cs | 4 +- .../Services/EmployeeService.cs | 54 ++++++++----------- 2 files changed, 22 insertions(+), 36 deletions(-) diff --git a/OneBus.Application/Interfaces/Services/IEmployeeService.cs b/OneBus.Application/Interfaces/Services/IEmployeeService.cs index f4e0a28..d924a80 100644 --- a/OneBus.Application/Interfaces/Services/IEmployeeService.cs +++ b/OneBus.Application/Interfaces/Services/IEmployeeService.cs @@ -9,9 +9,7 @@ public interface IEmployeeService : IBaseService { Result> GetBloodTypes(); - - Result> GetCnhCategories(); - + Result> GetRoles(); Result> GetStatus(); diff --git a/OneBus.Application/Services/EmployeeService.cs b/OneBus.Application/Services/EmployeeService.cs index b6268d6..8114cd2 100644 --- a/OneBus.Application/Services/EmployeeService.cs +++ b/OneBus.Application/Services/EmployeeService.cs @@ -1,11 +1,11 @@ using FluentValidation; using OneBus.Application.DTOs.Employee; using OneBus.Application.Interfaces.Services; -using OneBus.Application.Utils; using OneBus.Domain.Commons; using OneBus.Domain.Commons.Result; using OneBus.Domain.Entities; using OneBus.Domain.Enums.Employee; +using OneBus.Domain.Extensions; using OneBus.Domain.Filters; using OneBus.Domain.Interfaces.Repositories; @@ -22,37 +22,41 @@ public EmployeeService( { } - public override async Task>> GetPaginedAsync(EmployeeFilter filter, CancellationToken cancellationToken = default) + public override async Task>> GetPaginedAsync( + EmployeeFilter filter, + DbQueryOptions? dbQueryOptions = null, + CancellationToken cancellationToken = default) { - var result = await base.GetPaginedAsync(filter, cancellationToken); + var result = await base.GetPaginedAsync(filter, cancellationToken: cancellationToken); if (!result.Sucess) return result; foreach (var employee in result.Value!.Items) { - employee.BloodTypeName = EnumUtils.GetName(employee.BloodType); - employee.RoleName = EnumUtils.GetName(employee.Role); - employee.CnhCategoryName = EnumUtils.GetName(employee.CnhCategory); - employee.StatusName = EnumUtils.GetName(employee.Status); + employee.BloodTypeName = ((BloodType?)employee.BloodType)?.ToString()?.Localize(); + employee.RoleName = ((Role)employee.Role).ToString().Localize(); + employee.StatusName = ((EmployeeStatus)employee.Status).ToString().Localize(); } return result; } - public override async Task> GetByIdAsync(long id, CancellationToken cancellationToken = default) + public override async Task> GetByIdAsync( + long id, + DbQueryOptions? dbQueryOptions = null, + CancellationToken cancellationToken = default) { - var result = await base.GetByIdAsync(id, cancellationToken); + var result = await base.GetByIdAsync(id, cancellationToken: cancellationToken); if (!result.Sucess) return result; var employee = result.Value!; - employee.BloodTypeName = EnumUtils.GetName(employee.BloodType); - employee.RoleName = EnumUtils.GetName(employee.Role); - employee.CnhCategoryName = EnumUtils.GetName(employee.CnhCategory); - employee.StatusName = EnumUtils.GetName(employee.Status); + employee.BloodTypeName = ((BloodType?)employee.BloodType)?.ToString()?.Localize(); + employee.RoleName = ((Role)employee.Role).ToString().Localize(); + employee.StatusName = ((EmployeeStatus)employee.Status).ToString().Localize(); return result; } @@ -65,26 +69,11 @@ public Result> GetStatus() foreach (var value in values) { - status.Add(new ReadStatusDTO { Value = (byte)value, Name = value.GetDisplayName() }); + status.Add(new ReadStatusDTO { Value = (byte)value, Name = value.ToString().Localize() }); } return SuccessResult>.Create(status); - } - - public Result> GetCnhCategories() - { - var values = Enum.GetValues(); - - List cnhCategories = []; - - foreach (var value in values) - { - cnhCategories.Add(new ReadCnhCategoryDTO { Value = (byte)value, Name = value.GetDisplayName() }); - } - - return SuccessResult>.Create(cnhCategories); - } - + } public Result> GetRoles() { var values = Enum.GetValues(); @@ -93,7 +82,7 @@ public Result> GetRoles() foreach (var value in values) { - roles.Add(new ReadRoleDTO { Value = (byte)value, Name = value.GetDisplayName() }); + roles.Add(new ReadRoleDTO { Value = (byte)value, Name = value.ToString().Localize() }); } return SuccessResult>.Create(roles); @@ -107,7 +96,7 @@ public Result> GetBloodTypes() foreach (var value in values) { - bloodTypes.Add(new ReadBloodTypeDTO { Value = (byte)value, Name = value.GetDisplayName() }); + bloodTypes.Add(new ReadBloodTypeDTO { Value = (byte)value, Name = value.ToString().Localize() }); } return SuccessResult>.Create(bloodTypes); @@ -125,7 +114,6 @@ protected override void UpdateFields(Employee entity, UpdateEmployeeDTO updateDT entity.Phone = updateDTO.Phone; entity.HiringDate = updateDTO.HiringDate; entity.CnhNumber = updateDTO.CnhNumber; - entity.CnhCategory = updateDTO.CnhCategory; entity.CnhExpiration = updateDTO.CnhExpiration; entity.Status = updateDTO.Status; entity.Image = updateDTO.Image; From 852a397119751e5ee416d36468172f00df369c45 Mon Sep 17 00:00:00 2001 From: Eduardo Rezende Date: Sat, 20 Sep 2025 17:01:40 -0300 Subject: [PATCH 26/30] =?UTF-8?q?=E2=9C=A8feat:=20Add=20EmployeeWorkday=20?= =?UTF-8?q?Service?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Adding service class for EmployeeWorkday --- .../Services/IEmployeeWorkdayService.cs | 6 +- .../Services/EmployeeWorkdayService.cs | 65 +++++++++++++++++-- 2 files changed, 64 insertions(+), 7 deletions(-) diff --git a/OneBus.Application/Interfaces/Services/IEmployeeWorkdayService.cs b/OneBus.Application/Interfaces/Services/IEmployeeWorkdayService.cs index ea07590..8f127f5 100644 --- a/OneBus.Application/Interfaces/Services/IEmployeeWorkdayService.cs +++ b/OneBus.Application/Interfaces/Services/IEmployeeWorkdayService.cs @@ -1,11 +1,13 @@ using OneBus.Application.DTOs.EmployeeWorkday; +using OneBus.Domain.Commons.Result; using OneBus.Domain.Entities; using OneBus.Domain.Filters; namespace OneBus.Application.Interfaces.Services { - public interface IEmployeeWorkdayService : - IBaseService + public interface IEmployeeWorkdayService : + IBaseService { + Result> GetDaysTypes(); } } diff --git a/OneBus.Application/Services/EmployeeWorkdayService.cs b/OneBus.Application/Services/EmployeeWorkdayService.cs index 49c304f..2ac7d26 100644 --- a/OneBus.Application/Services/EmployeeWorkdayService.cs +++ b/OneBus.Application/Services/EmployeeWorkdayService.cs @@ -1,26 +1,81 @@ using FluentValidation; using OneBus.Application.DTOs.EmployeeWorkday; using OneBus.Application.Interfaces.Services; +using OneBus.Domain.Commons; +using OneBus.Domain.Commons.Result; using OneBus.Domain.Entities; +using OneBus.Domain.Enums; +using OneBus.Domain.Extensions; using OneBus.Domain.Filters; using OneBus.Domain.Interfaces.Repositories; namespace OneBus.Application.Services { - public class EmployeeWorkdayService : BaseService, + public class EmployeeWorkdayService : BaseService, IEmployeeWorkdayService { public EmployeeWorkdayService( - IBaseRepository baseRepository, - IValidator createValidator, - IValidator updateValidator) + IBaseRepository baseRepository, + IValidator createValidator, + IValidator updateValidator) : base(baseRepository, createValidator, updateValidator) { } + public override async Task>> GetPaginedAsync( + EmployeeWorkDayFilter filter, + DbQueryOptions? dbQueryOptions = null, + CancellationToken cancellationToken = default) + { + var result = await base.GetPaginedAsync(filter, dbQueryOptions, cancellationToken); + + if (!result.Sucess) + return result; + + var employeesWorkdays = result.Value!.Items; + + foreach (var employeeWorkday in employeesWorkdays) + { + employeeWorkday.DayTypeName = ((DayType)employeeWorkday.DayType).ToString().Localize(); + } + + return result; + } + + public override async Task> GetByIdAsync( + long id, + DbQueryOptions? dbQueryOptions = null, + CancellationToken cancellationToken = default) + { + var result = await base.GetByIdAsync(id, dbQueryOptions, cancellationToken); + + if (!result.Sucess) + return result; + + var employeeWorkday = result.Value!; + + employeeWorkday.DayTypeName = ((DayType)employeeWorkday.DayType).ToString().Localize(); + return result; + } + + public Result> GetDaysTypes() + { + var values = Enum.GetValues(); + + List daysTypes = []; + + foreach (var value in values) + { + daysTypes.Add(new ReadDayTypeDTO { Value = (byte)value, Name = value.ToString().Localize() }); + } + + return SuccessResult>.Create(daysTypes); + } + protected override void UpdateFields(EmployeeWorkday entity, UpdateEmployeeWorkdayDTO updateDTO) { - throw new NotImplementedException(); + entity.StartTime = updateDTO.StartTime; + entity.EndTime = updateDTO.EndTime; } } } From 9368e0e2b120eb9d074b48ebd064c618cb343ae7 Mon Sep 17 00:00:00 2001 From: Eduardo Rezende Date: Sat, 20 Sep 2025 17:02:36 -0300 Subject: [PATCH 27/30] =?UTF-8?q?=F0=9F=A7=B9cleanup:=20Remove=20EnumUtils?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Removing class because it's not necessary --- OneBus.Application/Utils/EnumUtils.cs | 27 --------------------- OneBus.Domain/Enums/Employee/CnhCategory.cs | 11 --------- 2 files changed, 38 deletions(-) delete mode 100644 OneBus.Application/Utils/EnumUtils.cs delete mode 100644 OneBus.Domain/Enums/Employee/CnhCategory.cs diff --git a/OneBus.Application/Utils/EnumUtils.cs b/OneBus.Application/Utils/EnumUtils.cs deleted file mode 100644 index a697bae..0000000 --- a/OneBus.Application/Utils/EnumUtils.cs +++ /dev/null @@ -1,27 +0,0 @@ -using System.Reflection; -using System.Text.Json.Serialization; - -namespace OneBus.Application.Utils -{ - public static class EnumUtils - { - public static string? GetName(object? value) - where TEnum : Enum - { - if (value is null) - return null; - - return Enum.GetName(typeof(TEnum), value); - } - - public static string GetDisplayName(this Enum value) - { - var type = value.GetType(); - var memberInfo = type.GetMember(value.ToString()); - var attribute = memberInfo[0] - .GetCustomAttribute(); - - return attribute?.Name ?? value.ToString(); - } - } -} diff --git a/OneBus.Domain/Enums/Employee/CnhCategory.cs b/OneBus.Domain/Enums/Employee/CnhCategory.cs deleted file mode 100644 index 9d0727d..0000000 --- a/OneBus.Domain/Enums/Employee/CnhCategory.cs +++ /dev/null @@ -1,11 +0,0 @@ -namespace OneBus.Domain.Enums.Employee -{ - public enum CnhCategory : byte - { - A, - B, - C, - D, - E - } -} From 0aaed468cc2858271aab73a80707c3eb1fdb7f28 Mon Sep 17 00:00:00 2001 From: Eduardo Rezende Date: Sat, 20 Sep 2025 17:03:01 -0300 Subject: [PATCH 28/30] =?UTF-8?q?=E2=99=BB=EF=B8=8Frefactor:=20Update=20Em?= =?UTF-8?q?ployee=20Validators?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Removing CnhCategory references --- .../Validators/Employee/CreateEmployeeDTOValidator.cs | 5 +---- .../Validators/Employee/UpdateEmployeeDTOValidator.cs | 5 +---- 2 files changed, 2 insertions(+), 8 deletions(-) diff --git a/OneBus.Application/Validators/Employee/CreateEmployeeDTOValidator.cs b/OneBus.Application/Validators/Employee/CreateEmployeeDTOValidator.cs index 6e5c81a..4edee42 100644 --- a/OneBus.Application/Validators/Employee/CreateEmployeeDTOValidator.cs +++ b/OneBus.Application/Validators/Employee/CreateEmployeeDTOValidator.cs @@ -46,10 +46,7 @@ public CreateEmployeeDTOValidator(IEmployeeRepository employeeRepository) .MustAsync(async (cnhNumber, ct) => !await CnhNumberAlreadyExistsAsync(cnhNumber, ct)) .OverridePropertyName("Número da CNH") .WithMessage(ErrorUtils.AlreadyExists("Número da CNH").Message); - - RuleFor(c => c.CnhCategory).Must(ValidationUtils.IsValidEnumValue) - .OverridePropertyName("Categoria da CNH"); - + RuleFor(c => c.Status).Must(ValidationUtils.IsValidEnumValue); } diff --git a/OneBus.Application/Validators/Employee/UpdateEmployeeDTOValidator.cs b/OneBus.Application/Validators/Employee/UpdateEmployeeDTOValidator.cs index cb4910e..9762db7 100644 --- a/OneBus.Application/Validators/Employee/UpdateEmployeeDTOValidator.cs +++ b/OneBus.Application/Validators/Employee/UpdateEmployeeDTOValidator.cs @@ -47,10 +47,7 @@ public UpdateEmployeeDTOValidator(IEmployeeRepository employeeRepository) .MustAsync(async (employee, cnhNumber, ct) => !await CnhNumberAlreadyExistsAsync(employee.Id, cnhNumber, ct)) .OverridePropertyName("Número da CNH") .WithMessage(ErrorUtils.AlreadyExists("Número da CNH").Message); - - RuleFor(c => c.CnhCategory).Must(ValidationUtils.IsValidEnumValue) - .OverridePropertyName("Categoria da CNH"); - + RuleFor(c => c.Status).Must(ValidationUtils.IsValidEnumValue); } From 0df9a8e7a2939f907f7ed15fd6e0023e1acdaed5 Mon Sep 17 00:00:00 2001 From: Eduardo Rezende Date: Sat, 20 Sep 2025 17:04:00 -0300 Subject: [PATCH 29/30] =?UTF-8?q?=E2=9C=A8feat:=20Update=20EmployeeWorkday?= =?UTF-8?q?=20Validators?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Adding validation class for Create and Update DTOs --- .../CreateEmployeeWorkdayDTOValidator.cs | 33 +++++++++++++++++++ .../UpdateEmployeeWorkdayDTOValidator.cs | 9 ++++- 2 files changed, 41 insertions(+), 1 deletion(-) diff --git a/OneBus.Application/Validators/EmployeeWorkday/CreateEmployeeWorkdayDTOValidator.cs b/OneBus.Application/Validators/EmployeeWorkday/CreateEmployeeWorkdayDTOValidator.cs index cab2958..2c90fab 100644 --- a/OneBus.Application/Validators/EmployeeWorkday/CreateEmployeeWorkdayDTOValidator.cs +++ b/OneBus.Application/Validators/EmployeeWorkday/CreateEmployeeWorkdayDTOValidator.cs @@ -1,9 +1,42 @@ using FluentValidation; using OneBus.Application.DTOs.EmployeeWorkday; +using OneBus.Application.Utils; +using OneBus.Domain.Commons; +using OneBus.Domain.Enums; +using OneBus.Domain.Interfaces.Repositories; namespace OneBus.Application.Validators.EmployeeWorkday { public class CreateEmployeeWorkdayDTOValidator : AbstractValidator { + private readonly IEmployeeRepository _employeeRepository; + + const string EmployeeIdPropertyName = "Id do Funcionário"; + + public CreateEmployeeWorkdayDTOValidator(IEmployeeRepository employeeRepository) + { + _employeeRepository = employeeRepository; + + RuleFor(c => c.EmployeeId).GreaterThan(0) + .OverridePropertyName(EmployeeIdPropertyName); + + RuleFor(c => c.EmployeeId) + .MustAsync(ExistsAsync) + .WithMessage(ErrorUtils.EntityNotFound(EmployeeIdPropertyName).Message) + .OverridePropertyName(EmployeeIdPropertyName); + + RuleFor(c => c.DayType).Must(ValidationUtils.IsValidEnumValue) + .OverridePropertyName("Dia da Semana"); + + RuleFor(c => c.EndTime) + .Must((dto, endTime) => endTime > dto.StartTime) + .WithMessage("Horário inválido") + .OverridePropertyName("Horário de Saída"); + } + + private async Task ExistsAsync(long employeeId, CancellationToken ct = default) + { + return await _employeeRepository.AnyAsync(c => c.Id == employeeId, cancellationToken: ct); + } } } diff --git a/OneBus.Application/Validators/EmployeeWorkday/UpdateEmployeeWorkdayDTOValidator.cs b/OneBus.Application/Validators/EmployeeWorkday/UpdateEmployeeWorkdayDTOValidator.cs index adc8100..95effef 100644 --- a/OneBus.Application/Validators/EmployeeWorkday/UpdateEmployeeWorkdayDTOValidator.cs +++ b/OneBus.Application/Validators/EmployeeWorkday/UpdateEmployeeWorkdayDTOValidator.cs @@ -4,6 +4,13 @@ namespace OneBus.Application.Validators.EmployeeWorkday { public class UpdateEmployeeWorkdayDTOValidator : AbstractValidator - { + { + public UpdateEmployeeWorkdayDTOValidator() + { + RuleFor(c => c.EndTime) + .Must((dto, endTime) => endTime > dto.StartTime) + .WithMessage("Horário inválido") + .OverridePropertyName("Horário de Saída"); + } } } From ee2965ea704120101b5aa1ab1381c5984594e8b5 Mon Sep 17 00:00:00 2001 From: Eduardo Rezende Date: Sat, 20 Sep 2025 17:05:53 -0300 Subject: [PATCH 30/30] =?UTF-8?q?=E2=99=BB=EF=B8=8Frefactor:=20Update=20Co?= =?UTF-8?q?ntrollers?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Adjusting get methods parameters and adding EmployeeWorkday controller endpoints --- OneBus.API/Controllers/EmployeeController.cs | 19 ++------------ .../Controllers/EmployeeWorkdayController.cs | 26 ++++++++++++++++--- OneBus.API/Controllers/LineController.cs | 4 +-- OneBus.API/Controllers/LineTimeController.cs | 4 +-- .../Controllers/MaintenanceController.cs | 4 +-- OneBus.API/Controllers/VehicleController.cs | 6 ++--- .../Controllers/VehicleOperationController.cs | 4 +-- 7 files changed, 35 insertions(+), 32 deletions(-) diff --git a/OneBus.API/Controllers/EmployeeController.cs b/OneBus.API/Controllers/EmployeeController.cs index af5433f..af4d0b2 100644 --- a/OneBus.API/Controllers/EmployeeController.cs +++ b/OneBus.API/Controllers/EmployeeController.cs @@ -103,7 +103,7 @@ public async Task DeleteAsync([FromRoute] long id, CancellationTo [ProducesResponseType(typeof(SuccessResult>), StatusCodes.Status200OK)] public async Task GetPaginedAsync([FromQuery] EmployeeFilter filter, CancellationToken cancellationToken = default) { - return (await _employeeService.GetPaginedAsync(filter, cancellationToken)).ToActionResult(); + return (await _employeeService.GetPaginedAsync(filter, cancellationToken: cancellationToken)).ToActionResult(); } /// @@ -122,7 +122,7 @@ public async Task GetPaginedAsync([FromQuery] EmployeeFilter filt [ProducesResponseType(typeof(NotFoundResult), StatusCodes.Status404NotFound)] public async Task GetByIdAsync([FromRoute] long id, CancellationToken cancellationToken = default) { - return (await _employeeService.GetByIdAsync(id, cancellationToken)).ToActionResult(); + return (await _employeeService.GetByIdAsync(id, cancellationToken: cancellationToken)).ToActionResult(); } /// @@ -140,21 +140,6 @@ public IActionResult GetStatus() return _employeeService.GetStatus().ToActionResult(); } - /// - /// Listar categorias de cnh - /// - /// - /// GET de categorias de cnh - /// - /// Categorias de cnh disponíveis - /// Categorias de cnh retornados com sucesso - [HttpGet("cnhCategories")] - [ProducesResponseType(typeof(SuccessResult>), StatusCodes.Status200OK)] - public IActionResult GetCnhCategories() - { - return _employeeService.GetCnhCategories().ToActionResult(); - } - /// /// Listar cargos /// diff --git a/OneBus.API/Controllers/EmployeeWorkdayController.cs b/OneBus.API/Controllers/EmployeeWorkdayController.cs index 7b53a05..b089312 100644 --- a/OneBus.API/Controllers/EmployeeWorkdayController.cs +++ b/OneBus.API/Controllers/EmployeeWorkdayController.cs @@ -10,7 +10,6 @@ namespace OneBus.API.Controllers { - [NonController] [Route("api/v1/employeesWorkdays")] [ApiController] [Produces("application/json")] @@ -102,9 +101,11 @@ public async Task DeleteAsync([FromRoute] long id, CancellationTo /// Horários dos Funcionários paginados e filtrados com sucesso [HttpGet] [ProducesResponseType(typeof(SuccessResult>), StatusCodes.Status200OK)] - public async Task GetPaginedAsync([FromQuery] BaseFilter filter, CancellationToken cancellationToken = default) + public async Task GetPaginedAsync([FromQuery] EmployeeWorkDayFilter filter, CancellationToken cancellationToken = default) { - return (await _employeeWorkdayService.GetPaginedAsync(filter, cancellationToken)).ToActionResult(); + return (await _employeeWorkdayService.GetPaginedAsync(filter, + DbQueryOptions.Create(["Employee"]), + cancellationToken)).ToActionResult(); } /// @@ -123,7 +124,24 @@ public async Task GetPaginedAsync([FromQuery] BaseFilter filter, [ProducesResponseType(typeof(NotFoundResult), StatusCodes.Status404NotFound)] public async Task GetByIdAsync([FromRoute] long id, CancellationToken cancellationToken = default) { - return (await _employeeWorkdayService.GetByIdAsync(id, cancellationToken)).ToActionResult(); + return (await _employeeWorkdayService.GetByIdAsync(id, + DbQueryOptions.Create(["Employee"]), + cancellationToken)).ToActionResult(); + } + + /// + /// Listar tipos de dias + /// + /// + /// GET de tipos de dias + /// + /// Tipos de Dias disponíveis + /// Status retornados com sucesso + [HttpGet("daysTypes")] + [ProducesResponseType(typeof(SuccessResult>), StatusCodes.Status200OK)] + public IActionResult GetDaysTypes() + { + return _employeeWorkdayService.GetDaysTypes().ToActionResult(); } } } diff --git a/OneBus.API/Controllers/LineController.cs b/OneBus.API/Controllers/LineController.cs index 23bbf12..029d3ea 100644 --- a/OneBus.API/Controllers/LineController.cs +++ b/OneBus.API/Controllers/LineController.cs @@ -104,7 +104,7 @@ public async Task DeleteAsync([FromRoute] long id, CancellationTo [ProducesResponseType(typeof(SuccessResult>), StatusCodes.Status200OK)] public async Task GetPaginedAsync([FromQuery] BaseFilter filter, CancellationToken cancellationToken = default) { - return (await _lineService.GetPaginedAsync(filter, cancellationToken)).ToActionResult(); + return (await _lineService.GetPaginedAsync(filter, cancellationToken: cancellationToken)).ToActionResult(); } /// @@ -123,7 +123,7 @@ public async Task GetPaginedAsync([FromQuery] BaseFilter filter, [ProducesResponseType(typeof(NotFoundResult), StatusCodes.Status404NotFound)] public async Task GetByIdAsync([FromRoute] long id, CancellationToken cancellationToken = default) { - return (await _lineService.GetByIdAsync(id, cancellationToken)).ToActionResult(); + return (await _lineService.GetByIdAsync(id, cancellationToken: cancellationToken)).ToActionResult(); } } } diff --git a/OneBus.API/Controllers/LineTimeController.cs b/OneBus.API/Controllers/LineTimeController.cs index 86227f3..40e174c 100644 --- a/OneBus.API/Controllers/LineTimeController.cs +++ b/OneBus.API/Controllers/LineTimeController.cs @@ -104,7 +104,7 @@ public async Task DeleteAsync([FromRoute] long id, CancellationTo [ProducesResponseType(typeof(SuccessResult>), StatusCodes.Status200OK)] public async Task GetPaginedAsync([FromQuery] BaseFilter filter, CancellationToken cancellationToken = default) { - return (await _lineTimeService.GetPaginedAsync(filter, cancellationToken)).ToActionResult(); + return (await _lineTimeService.GetPaginedAsync(filter, cancellationToken: cancellationToken)).ToActionResult(); } /// @@ -123,7 +123,7 @@ public async Task GetPaginedAsync([FromQuery] BaseFilter filter, [ProducesResponseType(typeof(NotFoundResult), StatusCodes.Status404NotFound)] public async Task GetByIdAsync([FromRoute] long id, CancellationToken cancellationToken = default) { - return (await _lineTimeService.GetByIdAsync(id, cancellationToken)).ToActionResult(); + return (await _lineTimeService.GetByIdAsync(id, cancellationToken: cancellationToken)).ToActionResult(); } } } diff --git a/OneBus.API/Controllers/MaintenanceController.cs b/OneBus.API/Controllers/MaintenanceController.cs index a399008..f7dcb88 100644 --- a/OneBus.API/Controllers/MaintenanceController.cs +++ b/OneBus.API/Controllers/MaintenanceController.cs @@ -104,7 +104,7 @@ public async Task DeleteAsync([FromRoute] long id, CancellationTo [ProducesResponseType(typeof(SuccessResult>), StatusCodes.Status200OK)] public async Task GetPaginedAsync([FromQuery] BaseFilter filter, CancellationToken cancellationToken = default) { - return (await _maintenanceService.GetPaginedAsync(filter, cancellationToken)).ToActionResult(); + return (await _maintenanceService.GetPaginedAsync(filter, cancellationToken: cancellationToken)).ToActionResult(); } /// @@ -123,7 +123,7 @@ public async Task GetPaginedAsync([FromQuery] BaseFilter filter, [ProducesResponseType(typeof(NotFoundResult), StatusCodes.Status404NotFound)] public async Task GetByIdAsync([FromRoute] long id, CancellationToken cancellationToken = default) { - return (await _maintenanceService.GetByIdAsync(id, cancellationToken)).ToActionResult(); + return (await _maintenanceService.GetByIdAsync(id, cancellationToken: cancellationToken)).ToActionResult(); } } } diff --git a/OneBus.API/Controllers/VehicleController.cs b/OneBus.API/Controllers/VehicleController.cs index d914b3a..7185c78 100644 --- a/OneBus.API/Controllers/VehicleController.cs +++ b/OneBus.API/Controllers/VehicleController.cs @@ -41,7 +41,7 @@ public VehicleController(IVehicleService vehicleService) [ProducesResponseType(typeof(InvalidResult), StatusCodes.Status422UnprocessableEntity)] public async Task CreateAsync([FromBody] CreateVehicleDTO createDTO, CancellationToken cancellationToken = default) { - return (await _vehicleService.CreateAsync(createDTO, cancellationToken)).ToActionResult(); + return (await _vehicleService.CreateAsync(createDTO, cancellationToken: cancellationToken)).ToActionResult(); } /// @@ -104,7 +104,7 @@ public async Task DeleteAsync([FromRoute] long id, CancellationTo [ProducesResponseType(typeof(SuccessResult>), StatusCodes.Status200OK)] public async Task GetPaginedAsync([FromQuery] BaseFilter filter, CancellationToken cancellationToken = default) { - return (await _vehicleService.GetPaginedAsync(filter, cancellationToken)).ToActionResult(); + return (await _vehicleService.GetPaginedAsync(filter, cancellationToken: cancellationToken)).ToActionResult(); } /// @@ -123,7 +123,7 @@ public async Task GetPaginedAsync([FromQuery] BaseFilter filter, [ProducesResponseType(typeof(NotFoundResult), StatusCodes.Status404NotFound)] public async Task GetByIdAsync([FromRoute] long id, CancellationToken cancellationToken = default) { - return (await _vehicleService.GetByIdAsync(id, cancellationToken)).ToActionResult(); + return (await _vehicleService.GetByIdAsync(id, cancellationToken: cancellationToken)).ToActionResult(); } } } diff --git a/OneBus.API/Controllers/VehicleOperationController.cs b/OneBus.API/Controllers/VehicleOperationController.cs index 91bcf79..aa611cb 100644 --- a/OneBus.API/Controllers/VehicleOperationController.cs +++ b/OneBus.API/Controllers/VehicleOperationController.cs @@ -104,7 +104,7 @@ public async Task DeleteAsync([FromRoute] long id, CancellationTo [ProducesResponseType(typeof(SuccessResult>), StatusCodes.Status200OK)] public async Task GetPaginedAsync([FromQuery] BaseFilter filter, CancellationToken cancellationToken = default) { - return (await _vehicleOperationService.GetPaginedAsync(filter, cancellationToken)).ToActionResult(); + return (await _vehicleOperationService.GetPaginedAsync(filter, cancellationToken: cancellationToken)).ToActionResult(); } /// @@ -123,7 +123,7 @@ public async Task GetPaginedAsync([FromQuery] BaseFilter filter, [ProducesResponseType(typeof(NotFoundResult), StatusCodes.Status404NotFound)] public async Task GetByIdAsync([FromRoute] long id, CancellationToken cancellationToken = default) { - return (await _vehicleOperationService.GetByIdAsync(id, cancellationToken)).ToActionResult(); + return (await _vehicleOperationService.GetByIdAsync(id, cancellationToken: cancellationToken)).ToActionResult(); } } }