From 1513d5f7b46eb5eae20f944c0b02ab933b85968e Mon Sep 17 00:00:00 2001 From: Eduardo Rezende Date: Sat, 4 Oct 2025 20:00:37 -0300 Subject: [PATCH 01/99] =?UTF-8?q?=F0=9F=A7=B9cleanup:=20Remove=20all=20Bus?= =?UTF-8?q?=20references?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Removing all Bus and BusOperation references --- OneBus.Application/DTOs/Bus/CreateBusDTO.cs | 6 ---- OneBus.Application/DTOs/Bus/ReadBusDTO.cs | 6 ---- OneBus.Application/DTOs/Bus/UpdateBusDTO.cs | 6 ---- .../BusOperation/CreateBusOperationDTO.cs | 6 ---- .../DTOs/BusOperation/ReadBusOperationDTO.cs | 6 ---- .../BusOperation/UpdateBusOperationDTO.cs | 6 ---- .../Services/IBusOperationService.cs | 11 ------- .../Interfaces/Services/IBusService.cs | 10 ------ .../Services/BusOperationService.cs | 26 --------------- OneBus.Application/Services/BusService.cs | 25 -------------- .../Validators/Bus/CreateBusDTOValidator.cs | 9 ----- .../Validators/Bus/UpdateBusDTOValidator.cs | 9 ----- .../CreateBusOperationDTOValidator.cs | 9 ----- .../UpdateBusOperationDTOValidator.cs | 9 ----- OneBus.Domain/Entities/Bus.cs | 33 ------------------- OneBus.Domain/Entities/BusOperation.cs | 19 ----------- .../Repositories/IBusOperationRepository.cs | 9 ----- .../Interfaces/Repositories/IBusRepository.cs | 9 ----- OneBus.Infra.Data/Mappings/BusMapping.cs | 21 ------------ .../Mappings/BusOperationMapping.cs | 28 ---------------- .../Repositories/BusOperationRepository.cs | 14 -------- .../Repositories/BusRepository.cs | 14 -------- 22 files changed, 291 deletions(-) delete mode 100644 OneBus.Application/DTOs/Bus/CreateBusDTO.cs delete mode 100644 OneBus.Application/DTOs/Bus/ReadBusDTO.cs delete mode 100644 OneBus.Application/DTOs/Bus/UpdateBusDTO.cs delete mode 100644 OneBus.Application/DTOs/BusOperation/CreateBusOperationDTO.cs delete mode 100644 OneBus.Application/DTOs/BusOperation/ReadBusOperationDTO.cs delete mode 100644 OneBus.Application/DTOs/BusOperation/UpdateBusOperationDTO.cs delete mode 100644 OneBus.Application/Interfaces/Services/IBusOperationService.cs delete mode 100644 OneBus.Application/Interfaces/Services/IBusService.cs delete mode 100644 OneBus.Application/Services/BusOperationService.cs delete mode 100644 OneBus.Application/Services/BusService.cs delete mode 100644 OneBus.Application/Validators/Bus/CreateBusDTOValidator.cs delete mode 100644 OneBus.Application/Validators/Bus/UpdateBusDTOValidator.cs delete mode 100644 OneBus.Application/Validators/BusOperation/CreateBusOperationDTOValidator.cs delete mode 100644 OneBus.Application/Validators/BusOperation/UpdateBusOperationDTOValidator.cs delete mode 100644 OneBus.Domain/Entities/Bus.cs delete mode 100644 OneBus.Domain/Entities/BusOperation.cs delete mode 100644 OneBus.Domain/Interfaces/Repositories/IBusOperationRepository.cs delete mode 100644 OneBus.Domain/Interfaces/Repositories/IBusRepository.cs delete mode 100644 OneBus.Infra.Data/Mappings/BusMapping.cs delete mode 100644 OneBus.Infra.Data/Mappings/BusOperationMapping.cs delete mode 100644 OneBus.Infra.Data/Repositories/BusOperationRepository.cs delete mode 100644 OneBus.Infra.Data/Repositories/BusRepository.cs diff --git a/OneBus.Application/DTOs/Bus/CreateBusDTO.cs b/OneBus.Application/DTOs/Bus/CreateBusDTO.cs deleted file mode 100644 index 9f4ffb3..0000000 --- a/OneBus.Application/DTOs/Bus/CreateBusDTO.cs +++ /dev/null @@ -1,6 +0,0 @@ -namespace OneBus.Application.DTOs.Bus -{ - public class CreateBusDTO : BaseCreateDTO - { - } -} diff --git a/OneBus.Application/DTOs/Bus/ReadBusDTO.cs b/OneBus.Application/DTOs/Bus/ReadBusDTO.cs deleted file mode 100644 index af8018a..0000000 --- a/OneBus.Application/DTOs/Bus/ReadBusDTO.cs +++ /dev/null @@ -1,6 +0,0 @@ -namespace OneBus.Application.DTOs.Bus -{ - public class ReadBusDTO : BaseReadDTO - { - } -} diff --git a/OneBus.Application/DTOs/Bus/UpdateBusDTO.cs b/OneBus.Application/DTOs/Bus/UpdateBusDTO.cs deleted file mode 100644 index 23595d0..0000000 --- a/OneBus.Application/DTOs/Bus/UpdateBusDTO.cs +++ /dev/null @@ -1,6 +0,0 @@ -namespace OneBus.Application.DTOs.Bus -{ - public class UpdateBusDTO : BaseUpdateDTO - { - } -} diff --git a/OneBus.Application/DTOs/BusOperation/CreateBusOperationDTO.cs b/OneBus.Application/DTOs/BusOperation/CreateBusOperationDTO.cs deleted file mode 100644 index c6fedf5..0000000 --- a/OneBus.Application/DTOs/BusOperation/CreateBusOperationDTO.cs +++ /dev/null @@ -1,6 +0,0 @@ -namespace OneBus.Application.DTOs.BusOperation -{ - public class CreateBusOperationDTO : BaseCreateDTO - { - } -} diff --git a/OneBus.Application/DTOs/BusOperation/ReadBusOperationDTO.cs b/OneBus.Application/DTOs/BusOperation/ReadBusOperationDTO.cs deleted file mode 100644 index f0c04fa..0000000 --- a/OneBus.Application/DTOs/BusOperation/ReadBusOperationDTO.cs +++ /dev/null @@ -1,6 +0,0 @@ -namespace OneBus.Application.DTOs.BusOperation -{ - public class ReadBusOperationDTO : BaseReadDTO - { - } -} diff --git a/OneBus.Application/DTOs/BusOperation/UpdateBusOperationDTO.cs b/OneBus.Application/DTOs/BusOperation/UpdateBusOperationDTO.cs deleted file mode 100644 index 143c07d..0000000 --- a/OneBus.Application/DTOs/BusOperation/UpdateBusOperationDTO.cs +++ /dev/null @@ -1,6 +0,0 @@ -namespace OneBus.Application.DTOs.BusOperation -{ - public class UpdateBusOperationDTO : BaseUpdateDTO - { - } -} diff --git a/OneBus.Application/Interfaces/Services/IBusOperationService.cs b/OneBus.Application/Interfaces/Services/IBusOperationService.cs deleted file mode 100644 index f301efd..0000000 --- a/OneBus.Application/Interfaces/Services/IBusOperationService.cs +++ /dev/null @@ -1,11 +0,0 @@ -using OneBus.Application.DTOs.BusOperation; -using OneBus.Domain.Entities; -using OneBus.Domain.Filters; - -namespace OneBus.Application.Interfaces.Services -{ - public interface IBusOperationService : - IBaseService - { - } -} diff --git a/OneBus.Application/Interfaces/Services/IBusService.cs b/OneBus.Application/Interfaces/Services/IBusService.cs deleted file mode 100644 index 60c1962..0000000 --- a/OneBus.Application/Interfaces/Services/IBusService.cs +++ /dev/null @@ -1,10 +0,0 @@ -using OneBus.Application.DTOs.Bus; -using OneBus.Domain.Entities; -using OneBus.Domain.Filters; - -namespace OneBus.Application.Interfaces.Services -{ - public interface IBusService : IBaseService - { - } -} diff --git a/OneBus.Application/Services/BusOperationService.cs b/OneBus.Application/Services/BusOperationService.cs deleted file mode 100644 index ba7ab6b..0000000 --- a/OneBus.Application/Services/BusOperationService.cs +++ /dev/null @@ -1,26 +0,0 @@ -using FluentValidation; -using OneBus.Application.DTOs.BusOperation; -using OneBus.Application.Interfaces.Services; -using OneBus.Domain.Entities; -using OneBus.Domain.Filters; -using OneBus.Domain.Interfaces.Repositories; - -namespace OneBus.Application.Services -{ - public class BusOperationService : BaseService, - IBusOperationService - { - public BusOperationService( - IBaseRepository baseRepository, - IValidator createValidator, - IValidator updateValidator) - : base(baseRepository, createValidator, updateValidator) - { - } - - protected override void UpdateFields(BusOperation entity, UpdateBusOperationDTO updateDTO) - { - throw new NotImplementedException(); - } - } -} diff --git a/OneBus.Application/Services/BusService.cs b/OneBus.Application/Services/BusService.cs deleted file mode 100644 index 5b17c8d..0000000 --- a/OneBus.Application/Services/BusService.cs +++ /dev/null @@ -1,25 +0,0 @@ -using FluentValidation; -using OneBus.Application.DTOs.Bus; -using OneBus.Application.Interfaces.Services; -using OneBus.Domain.Entities; -using OneBus.Domain.Filters; -using OneBus.Domain.Interfaces.Repositories; - -namespace OneBus.Application.Services -{ - public class BusService : BaseService, IBusService - { - public BusService( - IBaseRepository baseRepository, - IValidator createValidator, - IValidator updateValidator) - : base(baseRepository, createValidator, updateValidator) - { - } - - protected override void UpdateFields(Bus entity, UpdateBusDTO updateDTO) - { - throw new NotImplementedException(); - } - } -} diff --git a/OneBus.Application/Validators/Bus/CreateBusDTOValidator.cs b/OneBus.Application/Validators/Bus/CreateBusDTOValidator.cs deleted file mode 100644 index 2aa60f9..0000000 --- a/OneBus.Application/Validators/Bus/CreateBusDTOValidator.cs +++ /dev/null @@ -1,9 +0,0 @@ -using FluentValidation; -using OneBus.Application.DTOs.Bus; - -namespace OneBus.Application.Validators.Bus -{ - public class CreateBusDTOValidator : AbstractValidator - { - } -} diff --git a/OneBus.Application/Validators/Bus/UpdateBusDTOValidator.cs b/OneBus.Application/Validators/Bus/UpdateBusDTOValidator.cs deleted file mode 100644 index 2ff8eea..0000000 --- a/OneBus.Application/Validators/Bus/UpdateBusDTOValidator.cs +++ /dev/null @@ -1,9 +0,0 @@ -using FluentValidation; -using OneBus.Application.DTOs.Bus; - -namespace OneBus.Application.Validators.Bus -{ - public class UpdateBusDTOValidator : AbstractValidator - { - } -} diff --git a/OneBus.Application/Validators/BusOperation/CreateBusOperationDTOValidator.cs b/OneBus.Application/Validators/BusOperation/CreateBusOperationDTOValidator.cs deleted file mode 100644 index 71a1d13..0000000 --- a/OneBus.Application/Validators/BusOperation/CreateBusOperationDTOValidator.cs +++ /dev/null @@ -1,9 +0,0 @@ -using FluentValidation; -using OneBus.Application.DTOs.BusOperation; - -namespace OneBus.Application.Validators.BusOperation -{ - public class CreateBusOperationDTOValidator : AbstractValidator - { - } -} diff --git a/OneBus.Application/Validators/BusOperation/UpdateBusOperationDTOValidator.cs b/OneBus.Application/Validators/BusOperation/UpdateBusOperationDTOValidator.cs deleted file mode 100644 index 44448c4..0000000 --- a/OneBus.Application/Validators/BusOperation/UpdateBusOperationDTOValidator.cs +++ /dev/null @@ -1,9 +0,0 @@ -using FluentValidation; -using OneBus.Application.DTOs.BusOperation; - -namespace OneBus.Application.Validators.BusOperation -{ - public class UpdateBusOperationDTOValidator : AbstractValidator - { - } -} diff --git a/OneBus.Domain/Entities/Bus.cs b/OneBus.Domain/Entities/Bus.cs deleted file mode 100644 index b81933f..0000000 --- a/OneBus.Domain/Entities/Bus.cs +++ /dev/null @@ -1,33 +0,0 @@ -namespace OneBus.Domain.Entities -{ - public class Bus : BaseEntity - { - public Bus() - { - ChassisBrand = string.Empty; - ChassisModel = string.Empty; - } - - public long VehicleId { get; set; } - - public byte ServiceType { get; set; } - - public string ChassisBrand { get; set; } - - public string ChassisModel { get; set; } - - public ushort ChassisYear { get; set; } - - public bool HasLowFloor { get; set; } - - public bool HasLeftDoors { get; set; } - - public DateOnly InsuranceExpiration { get; set; } - - public DateOnly FumigateExpiration { get; set; } - - public Vehicle? Vehicle { get; set; } - - public ICollection? BusOperations { get; set; } - } -} diff --git a/OneBus.Domain/Entities/BusOperation.cs b/OneBus.Domain/Entities/BusOperation.cs deleted file mode 100644 index 2485f6b..0000000 --- a/OneBus.Domain/Entities/BusOperation.cs +++ /dev/null @@ -1,19 +0,0 @@ -namespace OneBus.Domain.Entities -{ - public class BusOperation : BaseEntity - { - public long LineTimeId { get; set; } - - public long EmployeeWorkDayId { get; set; } - - public long BusId { get; set; } - - public DateOnly Date { get; set; } - - public LineTime? LineTime { get; set; } - - public EmployeeWorkday? EmployeeWorkday { get; set; } - - public Bus? Bus { get; set; } - } -} diff --git a/OneBus.Domain/Interfaces/Repositories/IBusOperationRepository.cs b/OneBus.Domain/Interfaces/Repositories/IBusOperationRepository.cs deleted file mode 100644 index 5206104..0000000 --- a/OneBus.Domain/Interfaces/Repositories/IBusOperationRepository.cs +++ /dev/null @@ -1,9 +0,0 @@ -using OneBus.Domain.Entities; -using OneBus.Domain.Filters; - -namespace OneBus.Domain.Interfaces.Repositories -{ - public interface IBusOperationRepository : IBaseRepository - { - } -} diff --git a/OneBus.Domain/Interfaces/Repositories/IBusRepository.cs b/OneBus.Domain/Interfaces/Repositories/IBusRepository.cs deleted file mode 100644 index 5d1a491..0000000 --- a/OneBus.Domain/Interfaces/Repositories/IBusRepository.cs +++ /dev/null @@ -1,9 +0,0 @@ -using OneBus.Domain.Entities; -using OneBus.Domain.Filters; - -namespace OneBus.Domain.Interfaces.Repositories -{ - public interface IBusRepository : IBaseRepository - { - } -} diff --git a/OneBus.Infra.Data/Mappings/BusMapping.cs b/OneBus.Infra.Data/Mappings/BusMapping.cs deleted file mode 100644 index 41e1f21..0000000 --- a/OneBus.Infra.Data/Mappings/BusMapping.cs +++ /dev/null @@ -1,21 +0,0 @@ -using Microsoft.EntityFrameworkCore.Metadata.Builders; -using OneBus.Domain.Entities; - -namespace OneBus.Infra.Data.Mappings -{ - public class BusMapping : BaseEntityMapping - { - public override void Configure(EntityTypeBuilder builder) - { - base.Configure(builder); - - builder.Property(c => c.ChassisBrand).HasMaxLength(50); - builder.Property(c => c.ChassisModel).HasMaxLength(50); - - builder - .HasOne(c => c.Vehicle) - .WithMany(c => c.Buses) - .HasForeignKey(c => c.VehicleId); - } - } -} diff --git a/OneBus.Infra.Data/Mappings/BusOperationMapping.cs b/OneBus.Infra.Data/Mappings/BusOperationMapping.cs deleted file mode 100644 index c797a93..0000000 --- a/OneBus.Infra.Data/Mappings/BusOperationMapping.cs +++ /dev/null @@ -1,28 +0,0 @@ -using Microsoft.EntityFrameworkCore.Metadata.Builders; -using OneBus.Domain.Entities; - -namespace OneBus.Infra.Data.Mappings -{ - public class BusOperationMapping : BaseEntityMapping - { - public override void Configure(EntityTypeBuilder builder) - { - base.Configure(builder); - - builder - .HasOne(c => c.LineTime) - .WithMany(c => c.BusOperations) - .HasForeignKey(c => c.LineTimeId); - - builder - .HasOne(c => c.Bus) - .WithMany(c => c.BusOperations) - .HasForeignKey(c => c.BusId); - - builder - .HasOne(c => c.EmployeeWorkday) - .WithMany(c => c.BusOperations) - .HasForeignKey(c => c.EmployeeWorkDayId); - } - } -} diff --git a/OneBus.Infra.Data/Repositories/BusOperationRepository.cs b/OneBus.Infra.Data/Repositories/BusOperationRepository.cs deleted file mode 100644 index 7513bdf..0000000 --- a/OneBus.Infra.Data/Repositories/BusOperationRepository.cs +++ /dev/null @@ -1,14 +0,0 @@ -using OneBus.Domain.Entities; -using OneBus.Domain.Filters; -using OneBus.Domain.Interfaces.Repositories; -using OneBus.Infra.Data.DbContexts; - -namespace OneBus.Infra.Data.Repositories -{ - public class BusOperationRepository : BaseRepository, IBusOperationRepository - { - public BusOperationRepository(OneBusDbContext dbContext) : base(dbContext) - { - } - } -} diff --git a/OneBus.Infra.Data/Repositories/BusRepository.cs b/OneBus.Infra.Data/Repositories/BusRepository.cs deleted file mode 100644 index 197b351..0000000 --- a/OneBus.Infra.Data/Repositories/BusRepository.cs +++ /dev/null @@ -1,14 +0,0 @@ -using OneBus.Domain.Entities; -using OneBus.Domain.Filters; -using OneBus.Domain.Interfaces.Repositories; -using OneBus.Infra.Data.DbContexts; - -namespace OneBus.Infra.Data.Repositories -{ - public class BusRepository : BaseRepository, IBusRepository - { - public BusRepository(OneBusDbContext dbContext) : base(dbContext) - { - } - } -} From 274ef1e129254a77132d865aa588abc38c548603 Mon Sep 17 00:00:00 2001 From: Eduardo Rezende Date: Sat, 4 Oct 2025 20:01:11 -0300 Subject: [PATCH 02/99] =?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 | 8 ++++---- OneBus.Infra.Data/OneBus.Infra.Data.csproj | 2 +- OneBus.Test/OneBus.Test.csproj | 4 ++-- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/OneBus.API/OneBus.API.csproj b/OneBus.API/OneBus.API.csproj index 56da312..a5f1f82 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.Infra.Data/OneBus.Infra.Data.csproj b/OneBus.Infra.Data/OneBus.Infra.Data.csproj index aecb86e..f78bd31 100644 --- a/OneBus.Infra.Data/OneBus.Infra.Data.csproj +++ b/OneBus.Infra.Data/OneBus.Infra.Data.csproj @@ -16,7 +16,7 @@ runtime; build; native; contentfiles; analyzers; buildtransitive - + diff --git a/OneBus.Test/OneBus.Test.csproj b/OneBus.Test/OneBus.Test.csproj index ed2efb5..59315f7 100644 --- a/OneBus.Test/OneBus.Test.csproj +++ b/OneBus.Test/OneBus.Test.csproj @@ -12,10 +12,10 @@ all runtime; build; native; contentfiles; analyzers; buildtransitive - + - + all runtime; build; native; contentfiles; analyzers; buildtransitive From 120932cfe138629cfe95430d57c879b670bc4fb7 Mon Sep 17 00:00:00 2001 From: Eduardo Rezende Date: Sat, 4 Oct 2025 20:02:26 -0300 Subject: [PATCH 03/99] =?UTF-8?q?=E2=99=BB=EF=B8=8Frefactor:=20Update=20En?= =?UTF-8?q?tities?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Updating Vehicle and VehicleOperation fields --- OneBus.Domain/Entities/EmployeeWorkday.cs | 4 +--- OneBus.Domain/Entities/LineTime.cs | 2 +- OneBus.Domain/Entities/Vehicle.cs | 16 +++++++++++++++- OneBus.Domain/Entities/VehicleOperation.cs | 4 ++++ 4 files changed, 21 insertions(+), 5 deletions(-) diff --git a/OneBus.Domain/Entities/EmployeeWorkday.cs b/OneBus.Domain/Entities/EmployeeWorkday.cs index 9edde3f..f2fbd37 100644 --- a/OneBus.Domain/Entities/EmployeeWorkday.cs +++ b/OneBus.Domain/Entities/EmployeeWorkday.cs @@ -12,8 +12,6 @@ public class EmployeeWorkday : BaseEntity public Employee? Employee { get; set; } - public ICollection? VehicleOperations { get; set; } - - public ICollection? BusOperations { get; set; } + public ICollection? VehicleOperations { get; set; } } } diff --git a/OneBus.Domain/Entities/LineTime.cs b/OneBus.Domain/Entities/LineTime.cs index d3c4b07..f2baab9 100644 --- a/OneBus.Domain/Entities/LineTime.cs +++ b/OneBus.Domain/Entities/LineTime.cs @@ -12,6 +12,6 @@ public class LineTime : BaseEntity public Line? Line { get; set; } - public ICollection? BusOperations { get; set; } + public ICollection? VehicleOperations { get; set; } } } diff --git a/OneBus.Domain/Entities/Vehicle.cs b/OneBus.Domain/Entities/Vehicle.cs index 0a01f1b..4d929cb 100644 --- a/OneBus.Domain/Entities/Vehicle.cs +++ b/OneBus.Domain/Entities/Vehicle.cs @@ -55,7 +55,21 @@ public Vehicle() public byte[]? Image { get; set; } - public ICollection? Buses { get; set; } + public byte? BusServiceType { get; set; } + + public string? BusChassisBrand { get; set; } + + public string? BusChassisModel { get; set; } + + public short? BusChassisYear { get; set; } + + public bool? BusHasLowFloor { get; set; } + + public bool? BusHasLeftDoors { get; set; } + + public DateOnly? BusInsuranceExpiration { get; set; } + + public DateOnly? BusFumigateExpiration { get; set; } public ICollection? Maintenances { get; set; } diff --git a/OneBus.Domain/Entities/VehicleOperation.cs b/OneBus.Domain/Entities/VehicleOperation.cs index 877318f..fd1a149 100644 --- a/OneBus.Domain/Entities/VehicleOperation.cs +++ b/OneBus.Domain/Entities/VehicleOperation.cs @@ -2,6 +2,8 @@ { public class VehicleOperation : BaseEntity { + public long? LineTimeId { get; set; } + public long EmployeeWorkdayId { get; set; } public long VehicleId { get; set; } @@ -11,5 +13,7 @@ public class VehicleOperation : BaseEntity public EmployeeWorkday? EmployeeWorkday { get; set; } public Vehicle? Vehicle { get; set; } + + public LineTime? LineTime { get; set; } } } From 0601e7f4dde0648eef18958b5d7aea19e8098157 Mon Sep 17 00:00:00 2001 From: Eduardo Rezende Date: Sat, 4 Oct 2025 20:02:52 -0300 Subject: [PATCH 04/99] =?UTF-8?q?=E2=99=BB=EF=B8=8Frefactor:=20Update=20En?= =?UTF-8?q?tities=20Mapping?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Updating Vehicle and VehicleOperation tables mappings --- OneBus.Infra.Data/Mappings/VehicleMapping.cs | 3 +++ OneBus.Infra.Data/Mappings/VehicleOperationMapping.cs | 5 +++++ 2 files changed, 8 insertions(+) diff --git a/OneBus.Infra.Data/Mappings/VehicleMapping.cs b/OneBus.Infra.Data/Mappings/VehicleMapping.cs index 814a9b7..204e643 100644 --- a/OneBus.Infra.Data/Mappings/VehicleMapping.cs +++ b/OneBus.Infra.Data/Mappings/VehicleMapping.cs @@ -19,6 +19,9 @@ public override void Configure(EntityTypeBuilder builder) builder.Property(c => c.NumberChassis).HasMaxLength(20); builder.Property(c => c.BodyworkNumber).HasMaxLength(20); + builder.Property(c => c.BusChassisBrand).HasMaxLength(50); + builder.Property(c => c.BusChassisModel).HasMaxLength(50); + builder.HasIndex(c => c.Plate); builder.HasIndex(c => c.Prefix); builder.HasIndex(c => c.Renavam); diff --git a/OneBus.Infra.Data/Mappings/VehicleOperationMapping.cs b/OneBus.Infra.Data/Mappings/VehicleOperationMapping.cs index 1d594ac..a6453ac 100644 --- a/OneBus.Infra.Data/Mappings/VehicleOperationMapping.cs +++ b/OneBus.Infra.Data/Mappings/VehicleOperationMapping.cs @@ -9,6 +9,11 @@ public override void Configure(EntityTypeBuilder builder) { base.Configure(builder); + builder + .HasOne(c => c.LineTime) + .WithMany(c => c.VehicleOperations) + .HasForeignKey(c => c.LineTimeId); + builder .HasOne(c => c.Vehicle) .WithMany(c => c.VehicleOperations) From 8ac25dba42ba24631ad3e24ef467f1edc6dfa47d Mon Sep 17 00:00:00 2001 From: Eduardo Rezende Date: Sat, 4 Oct 2025 20:03:25 -0300 Subject: [PATCH 05/99] =?UTF-8?q?=E2=9C=A8feat:=20Add=20Migration?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Updating Vehicle and VehicleOperation tables --- ...251004225605_RemovingBusTables.Designer.cs | 596 ++++++++++++++++++ .../20251004225605_RemovingBusTables.cs | 226 +++++++ .../OneBusDbContextModelSnapshot.cs | 182 ++---- 3 files changed, 864 insertions(+), 140 deletions(-) create mode 100644 OneBus.Infra.Data/Migrations/20251004225605_RemovingBusTables.Designer.cs create mode 100644 OneBus.Infra.Data/Migrations/20251004225605_RemovingBusTables.cs diff --git a/OneBus.Infra.Data/Migrations/20251004225605_RemovingBusTables.Designer.cs b/OneBus.Infra.Data/Migrations/20251004225605_RemovingBusTables.Designer.cs new file mode 100644 index 0000000..39976eb --- /dev/null +++ b/OneBus.Infra.Data/Migrations/20251004225605_RemovingBusTables.Designer.cs @@ -0,0 +1,596 @@ +// +using System; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; +using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; +using OneBus.Infra.Data.DbContexts; + +#nullable disable + +namespace OneBus.Infra.Data.Migrations +{ + [DbContext(typeof(OneBusDbContext))] + [Migration("20251004225605_RemovingBusTables")] + partial class RemovingBusTables + { + /// + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("ProductVersion", "9.0.9") + .HasAnnotation("Relational:MaxIdentifierLength", 63); + + NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder); + + modelBuilder.Entity("OneBus.Domain.Entities.Employee", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("bigint"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("BloodType") + .HasColumnType("smallint"); + + b.Property("CnhCategory") + .HasColumnType("smallint"); + + b.Property("CnhExpiration") + .HasColumnType("date"); + + b.Property("CnhNumber") + .HasMaxLength(20) + .IsUnicode(false) + .HasColumnType("character varying(20)"); + + b.Property("Code") + .IsRequired() + .HasMaxLength(30) + .IsUnicode(false) + .HasColumnType("character varying(30)"); + + b.Property("Cpf") + .IsRequired() + .HasMaxLength(20) + .IsUnicode(false) + .HasColumnType("character varying(20)"); + + b.Property("CreatedAt") + .HasColumnType("timestamp with time zone"); + + b.Property("Email") + .IsRequired() + .HasMaxLength(80) + .IsUnicode(false) + .HasColumnType("character varying(80)"); + + b.Property("HiringDate") + .HasColumnType("date"); + + b.Property("Image") + .HasColumnType("bytea"); + + b.Property("IsDeleted") + .HasColumnType("boolean"); + + b.Property("Name") + .IsRequired() + .HasMaxLength(80) + .IsUnicode(false) + .HasColumnType("character varying(80)"); + + b.Property("Phone") + .IsRequired() + .HasMaxLength(20) + .IsUnicode(false) + .HasColumnType("character varying(20)"); + + b.Property("Rg") + .IsRequired() + .HasMaxLength(20) + .IsUnicode(false) + .HasColumnType("character varying(20)"); + + b.Property("Role") + .HasColumnType("smallint"); + + b.Property("Status") + .HasColumnType("smallint"); + + b.HasKey("Id"); + + b.HasIndex("CnhNumber"); + + b.HasIndex("Code"); + + b.HasIndex("Cpf"); + + b.ToTable("Employee"); + }); + + modelBuilder.Entity("OneBus.Domain.Entities.EmployeeWorkday", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("bigint"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("CreatedAt") + .HasColumnType("timestamp with time zone"); + + b.Property("DayType") + .HasColumnType("smallint"); + + b.Property("EmployeeId") + .HasColumnType("bigint"); + + b.Property("EndTime") + .HasColumnType("time without time zone"); + + b.Property("IsDeleted") + .HasColumnType("boolean"); + + b.Property("StartTime") + .HasColumnType("time without time zone"); + + b.HasKey("Id"); + + b.HasIndex("EmployeeId"); + + b.ToTable("EmployeeWorkday"); + }); + + modelBuilder.Entity("OneBus.Domain.Entities.Line", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("bigint"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("CreatedAt") + .HasColumnType("timestamp with time zone"); + + b.Property("IsDeleted") + .HasColumnType("boolean"); + + b.Property("MaxNumberBuses") + .HasColumnType("smallint"); + + b.Property("Mileage") + .HasPrecision(19, 4) + .HasColumnType("numeric(19,4)"); + + b.Property("MinNumberBuses") + .HasColumnType("smallint"); + + b.Property("Name") + .IsRequired() + .HasMaxLength(80) + .IsUnicode(false) + .HasColumnType("character varying(80)"); + + b.Property("Number") + .IsRequired() + .HasMaxLength(20) + .IsUnicode(false) + .HasColumnType("character varying(20)"); + + b.Property("TravelTime") + .HasColumnType("time without time zone"); + + b.Property("Type") + .HasColumnType("smallint"); + + b.HasKey("Id"); + + b.ToTable("Line"); + }); + + modelBuilder.Entity("OneBus.Domain.Entities.LineTime", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("bigint"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("CreatedAt") + .HasColumnType("timestamp with time zone"); + + b.Property("DayType") + .HasColumnType("smallint"); + + b.Property("EndTime") + .HasColumnType("time without time zone"); + + b.Property("IsDeleted") + .HasColumnType("boolean"); + + b.Property("LineId") + .HasColumnType("bigint"); + + b.Property("StartTime") + .HasColumnType("time without time zone"); + + b.HasKey("Id"); + + b.HasIndex("LineId"); + + b.ToTable("LineTime"); + }); + + modelBuilder.Entity("OneBus.Domain.Entities.Maintenance", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("bigint"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("Cost") + .HasPrecision(19, 4) + .HasColumnType("numeric(19,4)"); + + b.Property("CreatedAt") + .HasColumnType("timestamp with time zone"); + + b.Property("Description") + .IsRequired() + .HasMaxLength(150) + .IsUnicode(false) + .HasColumnType("character varying(150)"); + + b.Property("EndDate") + .HasColumnType("date"); + + b.Property("IsDeleted") + .HasColumnType("boolean"); + + b.Property("Sector") + .HasColumnType("smallint"); + + b.Property("StartDate") + .HasColumnType("date"); + + b.Property("SurveyExpiration") + .HasColumnType("date"); + + b.Property("VehicleId") + .HasColumnType("bigint"); + + b.HasKey("Id"); + + b.HasIndex("VehicleId"); + + b.ToTable("Maintenance"); + }); + + modelBuilder.Entity("OneBus.Domain.Entities.User", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("bigint"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("CreatedAt") + .HasColumnType("timestamp with time zone"); + + b.Property("Email") + .IsRequired() + .HasMaxLength(80) + .IsUnicode(false) + .HasColumnType("character varying(80)"); + + b.Property("IsDeleted") + .HasColumnType("boolean"); + + b.Property("Name") + .IsRequired() + .HasMaxLength(80) + .IsUnicode(false) + .HasColumnType("character varying(80)"); + + b.Property("Password") + .IsRequired() + .HasMaxLength(50) + .IsUnicode(false) + .HasColumnType("character varying(50)"); + + b.Property("Salt") + .IsRequired() + .HasMaxLength(32) + .IsUnicode(false) + .HasColumnType("character varying(32)"); + + b.HasKey("Id"); + + b.ToTable("User"); + + b.HasData( + new + { + Id = 1L, + CreatedAt = new DateTime(2025, 8, 25, 0, 0, 0, 0, DateTimeKind.Utc), + Email = "onebus@admin", + IsDeleted = false, + Name = "Administrador", + Password = "YRT66Z4XEJ2SSNaJVDIXQW7uvC8LSvOxDU1sH/Sr/ic=", + Salt = "c37b6028194d489192aac9391801594a" + }); + }); + + modelBuilder.Entity("OneBus.Domain.Entities.Vehicle", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("bigint"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("AcquisitionDate") + .HasColumnType("date"); + + b.Property("AxesNumber") + .HasColumnType("smallint"); + + b.Property("BodyworkNumber") + .HasMaxLength(20) + .IsUnicode(false) + .HasColumnType("character varying(20)"); + + b.Property("Brand") + .IsRequired() + .HasMaxLength(50) + .IsUnicode(false) + .HasColumnType("character varying(50)"); + + b.Property("BusChassisBrand") + .HasMaxLength(50) + .IsUnicode(false) + .HasColumnType("character varying(50)"); + + b.Property("BusChassisModel") + .HasMaxLength(50) + .IsUnicode(false) + .HasColumnType("character varying(50)"); + + b.Property("BusChassisYear") + .HasColumnType("smallint"); + + b.Property("BusFumigateExpiration") + .HasColumnType("date"); + + b.Property("BusHasLeftDoors") + .HasColumnType("boolean"); + + b.Property("BusHasLowFloor") + .HasColumnType("boolean"); + + b.Property("BusInsuranceExpiration") + .HasColumnType("date"); + + b.Property("BusServiceType") + .HasColumnType("smallint"); + + b.Property("Color") + .HasMaxLength(20) + .IsUnicode(false) + .HasColumnType("character varying(20)"); + + b.Property("CreatedAt") + .HasColumnType("timestamp with time zone"); + + b.Property("EngineNumber") + .HasMaxLength(20) + .IsUnicode(false) + .HasColumnType("character varying(20)"); + + b.Property("FuelType") + .HasColumnType("smallint"); + + b.Property("HasAccessibility") + .HasColumnType("boolean"); + + b.Property("Image") + .HasColumnType("bytea"); + + b.Property("IpvaExpiration") + .HasColumnType("date"); + + b.Property("IsDeleted") + .HasColumnType("boolean"); + + b.Property("LicensingExpiration") + .HasColumnType("date"); + + b.Property("Model") + .IsRequired() + .HasMaxLength(50) + .IsUnicode(false) + .HasColumnType("character varying(50)"); + + b.Property("NumberChassis") + .HasMaxLength(20) + .IsUnicode(false) + .HasColumnType("character varying(20)"); + + b.Property("NumberDoors") + .HasColumnType("smallint"); + + b.Property("NumberSeats") + .HasColumnType("smallint"); + + b.Property("Plate") + .IsRequired() + .HasMaxLength(20) + .IsUnicode(false) + .HasColumnType("character varying(20)"); + + b.Property("Prefix") + .IsRequired() + .HasMaxLength(30) + .IsUnicode(false) + .HasColumnType("character varying(30)"); + + b.Property("Renavam") + .IsRequired() + .HasMaxLength(20) + .IsUnicode(false) + .HasColumnType("character varying(20)"); + + b.Property("Status") + .HasColumnType("smallint"); + + b.Property("TransmissionType") + .HasColumnType("smallint"); + + b.Property("Type") + .HasColumnType("smallint"); + + b.Property("Year") + .HasColumnType("integer"); + + b.HasKey("Id"); + + b.HasIndex("Plate"); + + b.HasIndex("Prefix"); + + b.HasIndex("Renavam"); + + b.ToTable("Vehicle"); + }); + + modelBuilder.Entity("OneBus.Domain.Entities.VehicleOperation", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("bigint"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("CreatedAt") + .HasColumnType("timestamp with time zone"); + + b.Property("Date") + .HasColumnType("date"); + + b.Property("EmployeeWorkdayId") + .HasColumnType("bigint"); + + b.Property("IsDeleted") + .HasColumnType("boolean"); + + b.Property("LineTimeId") + .HasColumnType("bigint"); + + b.Property("VehicleId") + .HasColumnType("bigint"); + + b.HasKey("Id"); + + b.HasIndex("EmployeeWorkdayId"); + + b.HasIndex("LineTimeId"); + + b.HasIndex("VehicleId"); + + b.ToTable("VehicleOperation"); + }); + + modelBuilder.Entity("OneBus.Domain.Entities.EmployeeWorkday", b => + { + b.HasOne("OneBus.Domain.Entities.Employee", "Employee") + .WithMany("EmployeeWorkdays") + .HasForeignKey("EmployeeId") + .OnDelete(DeleteBehavior.Restrict) + .IsRequired(); + + b.Navigation("Employee"); + }); + + modelBuilder.Entity("OneBus.Domain.Entities.LineTime", b => + { + b.HasOne("OneBus.Domain.Entities.Line", "Line") + .WithMany("LineTimes") + .HasForeignKey("LineId") + .OnDelete(DeleteBehavior.Restrict) + .IsRequired(); + + b.Navigation("Line"); + }); + + modelBuilder.Entity("OneBus.Domain.Entities.Maintenance", b => + { + b.HasOne("OneBus.Domain.Entities.Vehicle", "Vehicle") + .WithMany("Maintenances") + .HasForeignKey("VehicleId") + .OnDelete(DeleteBehavior.Restrict) + .IsRequired(); + + b.Navigation("Vehicle"); + }); + + modelBuilder.Entity("OneBus.Domain.Entities.VehicleOperation", b => + { + b.HasOne("OneBus.Domain.Entities.EmployeeWorkday", "EmployeeWorkday") + .WithMany("VehicleOperations") + .HasForeignKey("EmployeeWorkdayId") + .OnDelete(DeleteBehavior.Restrict) + .IsRequired(); + + b.HasOne("OneBus.Domain.Entities.LineTime", "LineTime") + .WithMany("VehicleOperations") + .HasForeignKey("LineTimeId") + .OnDelete(DeleteBehavior.Restrict); + + b.HasOne("OneBus.Domain.Entities.Vehicle", "Vehicle") + .WithMany("VehicleOperations") + .HasForeignKey("VehicleId") + .OnDelete(DeleteBehavior.Restrict) + .IsRequired(); + + b.Navigation("EmployeeWorkday"); + + b.Navigation("LineTime"); + + b.Navigation("Vehicle"); + }); + + modelBuilder.Entity("OneBus.Domain.Entities.Employee", b => + { + b.Navigation("EmployeeWorkdays"); + }); + + modelBuilder.Entity("OneBus.Domain.Entities.EmployeeWorkday", b => + { + b.Navigation("VehicleOperations"); + }); + + modelBuilder.Entity("OneBus.Domain.Entities.Line", b => + { + b.Navigation("LineTimes"); + }); + + modelBuilder.Entity("OneBus.Domain.Entities.LineTime", b => + { + b.Navigation("VehicleOperations"); + }); + + modelBuilder.Entity("OneBus.Domain.Entities.Vehicle", b => + { + b.Navigation("Maintenances"); + + b.Navigation("VehicleOperations"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/OneBus.Infra.Data/Migrations/20251004225605_RemovingBusTables.cs b/OneBus.Infra.Data/Migrations/20251004225605_RemovingBusTables.cs new file mode 100644 index 0000000..583a930 --- /dev/null +++ b/OneBus.Infra.Data/Migrations/20251004225605_RemovingBusTables.cs @@ -0,0 +1,226 @@ +using System; +using Microsoft.EntityFrameworkCore.Migrations; +using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; + +#nullable disable + +namespace OneBus.Infra.Data.Migrations +{ + /// + public partial class RemovingBusTables : Migration + { + /// + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropTable( + name: "BusOperation"); + + migrationBuilder.DropTable( + name: "Bus"); + + migrationBuilder.AddColumn( + name: "LineTimeId", + table: "VehicleOperation", + type: "bigint", + nullable: true); + + migrationBuilder.AddColumn( + name: "BusChassisBrand", + table: "Vehicle", + type: "character varying(50)", + unicode: false, + maxLength: 50, + nullable: true); + + migrationBuilder.AddColumn( + name: "BusChassisModel", + table: "Vehicle", + type: "character varying(50)", + unicode: false, + maxLength: 50, + nullable: true); + + migrationBuilder.AddColumn( + name: "BusChassisYear", + table: "Vehicle", + type: "smallint", + nullable: true); + + migrationBuilder.AddColumn( + name: "BusFumigateExpiration", + table: "Vehicle", + type: "date", + nullable: true); + + migrationBuilder.AddColumn( + name: "BusHasLeftDoors", + table: "Vehicle", + type: "boolean", + nullable: true); + + migrationBuilder.AddColumn( + name: "BusHasLowFloor", + table: "Vehicle", + type: "boolean", + nullable: true); + + migrationBuilder.AddColumn( + name: "BusInsuranceExpiration", + table: "Vehicle", + type: "date", + nullable: true); + + migrationBuilder.AddColumn( + name: "BusServiceType", + table: "Vehicle", + type: "smallint", + nullable: true); + + migrationBuilder.CreateIndex( + name: "IX_VehicleOperation_LineTimeId", + table: "VehicleOperation", + column: "LineTimeId"); + + migrationBuilder.AddForeignKey( + name: "FK_VehicleOperation_LineTime_LineTimeId", + table: "VehicleOperation", + column: "LineTimeId", + principalTable: "LineTime", + principalColumn: "Id", + onDelete: ReferentialAction.Restrict); + } + + /// + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropForeignKey( + name: "FK_VehicleOperation_LineTime_LineTimeId", + table: "VehicleOperation"); + + migrationBuilder.DropIndex( + name: "IX_VehicleOperation_LineTimeId", + table: "VehicleOperation"); + + migrationBuilder.DropColumn( + name: "LineTimeId", + table: "VehicleOperation"); + + migrationBuilder.DropColumn( + name: "BusChassisBrand", + table: "Vehicle"); + + migrationBuilder.DropColumn( + name: "BusChassisModel", + table: "Vehicle"); + + migrationBuilder.DropColumn( + name: "BusChassisYear", + table: "Vehicle"); + + migrationBuilder.DropColumn( + name: "BusFumigateExpiration", + table: "Vehicle"); + + migrationBuilder.DropColumn( + name: "BusHasLeftDoors", + table: "Vehicle"); + + migrationBuilder.DropColumn( + name: "BusHasLowFloor", + table: "Vehicle"); + + migrationBuilder.DropColumn( + name: "BusInsuranceExpiration", + table: "Vehicle"); + + migrationBuilder.DropColumn( + name: "BusServiceType", + table: "Vehicle"); + + migrationBuilder.CreateTable( + name: "Bus", + columns: table => new + { + Id = table.Column(type: "bigint", nullable: false) + .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), + VehicleId = table.Column(type: "bigint", nullable: false), + ChassisBrand = table.Column(type: "character varying(50)", unicode: false, maxLength: 50, nullable: false), + ChassisModel = table.Column(type: "character varying(50)", unicode: false, maxLength: 50, nullable: false), + ChassisYear = table.Column(type: "integer", nullable: false), + CreatedAt = table.Column(type: "timestamp with time zone", nullable: false), + FumigateExpiration = table.Column(type: "date", nullable: false), + HasLeftDoors = table.Column(type: "boolean", nullable: false), + HasLowFloor = table.Column(type: "boolean", nullable: false), + InsuranceExpiration = table.Column(type: "date", nullable: false), + IsDeleted = table.Column(type: "boolean", nullable: false), + ServiceType = table.Column(type: "smallint", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Bus", x => x.Id); + table.ForeignKey( + name: "FK_Bus_Vehicle_VehicleId", + column: x => x.VehicleId, + principalTable: "Vehicle", + principalColumn: "Id", + onDelete: ReferentialAction.Restrict); + }); + + migrationBuilder.CreateTable( + name: "BusOperation", + columns: table => new + { + Id = table.Column(type: "bigint", nullable: false) + .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), + BusId = table.Column(type: "bigint", nullable: false), + EmployeeWorkDayId = table.Column(type: "bigint", nullable: false), + LineTimeId = table.Column(type: "bigint", nullable: false), + CreatedAt = table.Column(type: "timestamp with time zone", nullable: false), + Date = table.Column(type: "date", nullable: false), + IsDeleted = table.Column(type: "boolean", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_BusOperation", x => x.Id); + table.ForeignKey( + name: "FK_BusOperation_Bus_BusId", + column: x => x.BusId, + principalTable: "Bus", + principalColumn: "Id", + onDelete: ReferentialAction.Restrict); + table.ForeignKey( + name: "FK_BusOperation_EmployeeWorkday_EmployeeWorkDayId", + column: x => x.EmployeeWorkDayId, + principalTable: "EmployeeWorkday", + principalColumn: "Id", + onDelete: ReferentialAction.Restrict); + table.ForeignKey( + name: "FK_BusOperation_LineTime_LineTimeId", + column: x => x.LineTimeId, + principalTable: "LineTime", + principalColumn: "Id", + onDelete: ReferentialAction.Restrict); + }); + + migrationBuilder.CreateIndex( + name: "IX_Bus_VehicleId", + table: "Bus", + column: "VehicleId"); + + migrationBuilder.CreateIndex( + name: "IX_BusOperation_BusId", + table: "BusOperation", + column: "BusId"); + + migrationBuilder.CreateIndex( + name: "IX_BusOperation_EmployeeWorkDayId", + table: "BusOperation", + column: "EmployeeWorkDayId"); + + migrationBuilder.CreateIndex( + name: "IX_BusOperation_LineTimeId", + table: "BusOperation", + column: "LineTimeId"); + } + } +} diff --git a/OneBus.Infra.Data/Migrations/OneBusDbContextModelSnapshot.cs b/OneBus.Infra.Data/Migrations/OneBusDbContextModelSnapshot.cs index 657adab..5d46760 100644 --- a/OneBus.Infra.Data/Migrations/OneBusDbContextModelSnapshot.cs +++ b/OneBus.Infra.Data/Migrations/OneBusDbContextModelSnapshot.cs @@ -17,102 +17,11 @@ protected override void BuildModel(ModelBuilder modelBuilder) { #pragma warning disable 612, 618 modelBuilder - .HasAnnotation("ProductVersion", "9.0.8") + .HasAnnotation("ProductVersion", "9.0.9") .HasAnnotation("Relational:MaxIdentifierLength", 63); NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder); - modelBuilder.Entity("OneBus.Domain.Entities.Bus", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("bigint"); - - NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); - - b.Property("ChassisBrand") - .IsRequired() - .HasMaxLength(50) - .IsUnicode(false) - .HasColumnType("character varying(50)"); - - b.Property("ChassisModel") - .IsRequired() - .HasMaxLength(50) - .IsUnicode(false) - .HasColumnType("character varying(50)"); - - b.Property("ChassisYear") - .HasColumnType("integer"); - - b.Property("CreatedAt") - .HasColumnType("timestamp with time zone"); - - b.Property("FumigateExpiration") - .HasColumnType("date"); - - b.Property("HasLeftDoors") - .HasColumnType("boolean"); - - b.Property("HasLowFloor") - .HasColumnType("boolean"); - - b.Property("InsuranceExpiration") - .HasColumnType("date"); - - b.Property("IsDeleted") - .HasColumnType("boolean"); - - b.Property("ServiceType") - .HasColumnType("smallint"); - - b.Property("VehicleId") - .HasColumnType("bigint"); - - b.HasKey("Id"); - - b.HasIndex("VehicleId"); - - b.ToTable("Bus"); - }); - - modelBuilder.Entity("OneBus.Domain.Entities.BusOperation", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("bigint"); - - NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); - - b.Property("BusId") - .HasColumnType("bigint"); - - b.Property("CreatedAt") - .HasColumnType("timestamp with time zone"); - - b.Property("Date") - .HasColumnType("date"); - - b.Property("EmployeeWorkDayId") - .HasColumnType("bigint"); - - b.Property("IsDeleted") - .HasColumnType("boolean"); - - b.Property("LineTimeId") - .HasColumnType("bigint"); - - b.HasKey("Id"); - - b.HasIndex("BusId"); - - b.HasIndex("EmployeeWorkDayId"); - - b.HasIndex("LineTimeId"); - - b.ToTable("BusOperation"); - }); - modelBuilder.Entity("OneBus.Domain.Entities.Employee", b => { b.Property("Id") @@ -439,6 +348,34 @@ protected override void BuildModel(ModelBuilder modelBuilder) .IsUnicode(false) .HasColumnType("character varying(50)"); + b.Property("BusChassisBrand") + .HasMaxLength(50) + .IsUnicode(false) + .HasColumnType("character varying(50)"); + + b.Property("BusChassisModel") + .HasMaxLength(50) + .IsUnicode(false) + .HasColumnType("character varying(50)"); + + b.Property("BusChassisYear") + .HasColumnType("smallint"); + + b.Property("BusFumigateExpiration") + .HasColumnType("date"); + + b.Property("BusHasLeftDoors") + .HasColumnType("boolean"); + + b.Property("BusHasLowFloor") + .HasColumnType("boolean"); + + b.Property("BusInsuranceExpiration") + .HasColumnType("date"); + + b.Property("BusServiceType") + .HasColumnType("smallint"); + b.Property("Color") .HasMaxLength(20) .IsUnicode(false) @@ -548,6 +485,9 @@ protected override void BuildModel(ModelBuilder modelBuilder) b.Property("IsDeleted") .HasColumnType("boolean"); + b.Property("LineTimeId") + .HasColumnType("bigint"); + b.Property("VehicleId") .HasColumnType("bigint"); @@ -555,49 +495,13 @@ protected override void BuildModel(ModelBuilder modelBuilder) b.HasIndex("EmployeeWorkdayId"); + b.HasIndex("LineTimeId"); + b.HasIndex("VehicleId"); b.ToTable("VehicleOperation"); }); - modelBuilder.Entity("OneBus.Domain.Entities.Bus", b => - { - b.HasOne("OneBus.Domain.Entities.Vehicle", "Vehicle") - .WithMany("Buses") - .HasForeignKey("VehicleId") - .OnDelete(DeleteBehavior.Restrict) - .IsRequired(); - - b.Navigation("Vehicle"); - }); - - modelBuilder.Entity("OneBus.Domain.Entities.BusOperation", b => - { - b.HasOne("OneBus.Domain.Entities.Bus", "Bus") - .WithMany("BusOperations") - .HasForeignKey("BusId") - .OnDelete(DeleteBehavior.Restrict) - .IsRequired(); - - b.HasOne("OneBus.Domain.Entities.EmployeeWorkday", "EmployeeWorkday") - .WithMany("BusOperations") - .HasForeignKey("EmployeeWorkDayId") - .OnDelete(DeleteBehavior.Restrict) - .IsRequired(); - - b.HasOne("OneBus.Domain.Entities.LineTime", "LineTime") - .WithMany("BusOperations") - .HasForeignKey("LineTimeId") - .OnDelete(DeleteBehavior.Restrict) - .IsRequired(); - - b.Navigation("Bus"); - - b.Navigation("EmployeeWorkday"); - - b.Navigation("LineTime"); - }); - modelBuilder.Entity("OneBus.Domain.Entities.EmployeeWorkday", b => { b.HasOne("OneBus.Domain.Entities.Employee", "Employee") @@ -639,6 +543,11 @@ protected override void BuildModel(ModelBuilder modelBuilder) .OnDelete(DeleteBehavior.Restrict) .IsRequired(); + b.HasOne("OneBus.Domain.Entities.LineTime", "LineTime") + .WithMany("VehicleOperations") + .HasForeignKey("LineTimeId") + .OnDelete(DeleteBehavior.Restrict); + b.HasOne("OneBus.Domain.Entities.Vehicle", "Vehicle") .WithMany("VehicleOperations") .HasForeignKey("VehicleId") @@ -647,12 +556,9 @@ protected override void BuildModel(ModelBuilder modelBuilder) b.Navigation("EmployeeWorkday"); - b.Navigation("Vehicle"); - }); + b.Navigation("LineTime"); - modelBuilder.Entity("OneBus.Domain.Entities.Bus", b => - { - b.Navigation("BusOperations"); + b.Navigation("Vehicle"); }); modelBuilder.Entity("OneBus.Domain.Entities.Employee", b => @@ -662,8 +568,6 @@ protected override void BuildModel(ModelBuilder modelBuilder) modelBuilder.Entity("OneBus.Domain.Entities.EmployeeWorkday", b => { - b.Navigation("BusOperations"); - b.Navigation("VehicleOperations"); }); @@ -674,13 +578,11 @@ protected override void BuildModel(ModelBuilder modelBuilder) modelBuilder.Entity("OneBus.Domain.Entities.LineTime", b => { - b.Navigation("BusOperations"); + b.Navigation("VehicleOperations"); }); modelBuilder.Entity("OneBus.Domain.Entities.Vehicle", b => { - b.Navigation("Buses"); - b.Navigation("Maintenances"); b.Navigation("VehicleOperations"); From c4c119866570c5ebfb9f4279d678e058e9cec202 Mon Sep 17 00:00:00 2001 From: Eduardo Rezende Date: Sat, 4 Oct 2025 20:13:36 -0300 Subject: [PATCH 06/99] =?UTF-8?q?=E2=99=BB=EF=B8=8Frefactor:=20Update=20ve?= =?UTF-8?q?hicle=20DTOs?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Adding fields into DTOs classes --- .../DTOs/Vehicle/CreateVehicleDTO.cs | 68 +++++++++++++++++++ .../DTOs/Vehicle/ReadVehicleDTO.cs | 66 ++++++++++++++++++ .../DTOs/Vehicle/UpdateVehicleDTO.cs | 66 ++++++++++++++++++ 3 files changed, 200 insertions(+) diff --git a/OneBus.Application/DTOs/Vehicle/CreateVehicleDTO.cs b/OneBus.Application/DTOs/Vehicle/CreateVehicleDTO.cs index 731fa48..06caf73 100644 --- a/OneBus.Application/DTOs/Vehicle/CreateVehicleDTO.cs +++ b/OneBus.Application/DTOs/Vehicle/CreateVehicleDTO.cs @@ -2,5 +2,73 @@ { public class CreateVehicleDTO : BaseCreateDTO { + public CreateVehicleDTO() + { + Prefix = string.Empty; + Brand = string.Empty; + Model = string.Empty; + Plate = string.Empty; + Renavam = string.Empty; + } + + public byte Type { get; set; } + + public string Prefix { get; set; } + + public byte NumberDoors { get; set; } + + public byte NumberSeats { get; set; } + + public bool HasAccessibility { get; set; } + + public byte FuelType { get; set; } + + public string Brand { get; set; } + + public string Model { get; set; } + + public ushort Year { get; set; } + + public string Plate { get; set; } + + public string? Color { get; set; } + + public string? BodyworkNumber { get; set; } + + public string? NumberChassis { get; set; } + + public string? EngineNumber { get; set; } + + public byte AxesNumber { get; set; } + + public DateOnly IpvaExpiration { get; set; } + + public DateOnly LicensingExpiration { get; set; } + + public string Renavam { get; set; } + + public byte TransmissionType { get; set; } + + public DateOnly AcquisitionDate { get; set; } + + public byte Status { get; set; } + + public byte[]? Image { get; set; } + + public byte? BusServiceType { get; set; } + + public string? BusChassisBrand { get; set; } + + public string? BusChassisModel { get; set; } + + public short? BusChassisYear { get; set; } + + public bool? BusHasLowFloor { get; set; } + + public bool? BusHasLeftDoors { get; set; } + + public DateOnly? BusInsuranceExpiration { get; set; } + + public DateOnly? BusFumigateExpiration { get; set; } } } diff --git a/OneBus.Application/DTOs/Vehicle/ReadVehicleDTO.cs b/OneBus.Application/DTOs/Vehicle/ReadVehicleDTO.cs index e1d240b..d23fa4f 100644 --- a/OneBus.Application/DTOs/Vehicle/ReadVehicleDTO.cs +++ b/OneBus.Application/DTOs/Vehicle/ReadVehicleDTO.cs @@ -2,5 +2,71 @@ { public class ReadVehicleDTO : BaseReadDTO { + public ReadVehicleDTO() + { + Prefix = string.Empty; + Brand = string.Empty; + Model = string.Empty; + Plate = string.Empty; + Renavam = string.Empty; + } + + public string Prefix { get; set; } + + public byte NumberDoors { get; set; } + + public byte NumberSeats { get; set; } + + public bool HasAccessibility { get; set; } + + public byte FuelType { get; set; } + + public string Brand { get; set; } + + public string Model { get; set; } + + public ushort Year { get; set; } + + public string Plate { get; set; } + + public string? Color { get; set; } + + public string? BodyworkNumber { get; set; } + + public string? NumberChassis { get; set; } + + public string? EngineNumber { get; set; } + + public byte AxesNumber { get; set; } + + public DateOnly IpvaExpiration { get; set; } + + public DateOnly LicensingExpiration { get; set; } + + public string Renavam { get; set; } + + public byte TransmissionType { get; set; } + + public DateOnly AcquisitionDate { get; set; } + + public byte Status { get; set; } + + public byte[]? Image { get; set; } + + public byte? BusServiceType { get; set; } + + public string? BusChassisBrand { get; set; } + + public string? BusChassisModel { get; set; } + + public short? BusChassisYear { get; set; } + + public bool? BusHasLowFloor { get; set; } + + public bool? BusHasLeftDoors { get; set; } + + public DateOnly? BusInsuranceExpiration { get; set; } + + public DateOnly? BusFumigateExpiration { get; set; } } } diff --git a/OneBus.Application/DTOs/Vehicle/UpdateVehicleDTO.cs b/OneBus.Application/DTOs/Vehicle/UpdateVehicleDTO.cs index e0fa962..664f799 100644 --- a/OneBus.Application/DTOs/Vehicle/UpdateVehicleDTO.cs +++ b/OneBus.Application/DTOs/Vehicle/UpdateVehicleDTO.cs @@ -2,5 +2,71 @@ { public class UpdateVehicleDTO : BaseUpdateDTO { + public UpdateVehicleDTO() + { + Prefix = string.Empty; + Brand = string.Empty; + Model = string.Empty; + Plate = string.Empty; + Renavam = string.Empty; + } + + public string Prefix { get; set; } + + public byte NumberDoors { get; set; } + + public byte NumberSeats { get; set; } + + public bool HasAccessibility { get; set; } + + public byte FuelType { get; set; } + + public string Brand { get; set; } + + public string Model { get; set; } + + public ushort Year { get; set; } + + public string Plate { get; set; } + + public string? Color { get; set; } + + public string? BodyworkNumber { get; set; } + + public string? NumberChassis { get; set; } + + public string? EngineNumber { get; set; } + + public byte AxesNumber { get; set; } + + public DateOnly IpvaExpiration { get; set; } + + public DateOnly LicensingExpiration { get; set; } + + public string Renavam { get; set; } + + public byte TransmissionType { get; set; } + + public DateOnly AcquisitionDate { get; set; } + + public byte Status { get; set; } + + public byte[]? Image { get; set; } + + public byte? BusServiceType { get; set; } + + public string? BusChassisBrand { get; set; } + + public string? BusChassisModel { get; set; } + + public short? BusChassisYear { get; set; } + + public bool? BusHasLowFloor { get; set; } + + public bool? BusHasLeftDoors { get; set; } + + public DateOnly? BusInsuranceExpiration { get; set; } + + public DateOnly? BusFumigateExpiration { get; set; } } } From 4f7b924ea90fa6bef72875f649b79cca13a7e9d6 Mon Sep 17 00:00:00 2001 From: Eduardo Rezende Date: Sat, 4 Oct 2025 20:13:54 -0300 Subject: [PATCH 07/99] =?UTF-8?q?=E2=99=BB=EF=B8=8Frefactor:=20Update=20Ve?= =?UTF-8?q?hicle=20Service?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Adding UpdateFields method --- OneBus.Application/Services/VehicleService.cs | 30 ++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/OneBus.Application/Services/VehicleService.cs b/OneBus.Application/Services/VehicleService.cs index bf793c1..2901cb0 100644 --- a/OneBus.Application/Services/VehicleService.cs +++ b/OneBus.Application/Services/VehicleService.cs @@ -20,7 +20,35 @@ public VehicleService( protected override void UpdateFields(Vehicle entity, UpdateVehicleDTO updateDTO) { - throw new NotImplementedException(); + entity.Year = updateDTO.Year; + entity.Brand = updateDTO.Brand; + entity.Model = updateDTO.Model; + entity.Plate = updateDTO.Plate; + entity.Color = updateDTO.Color; + entity.Image = updateDTO.Image; + entity.Prefix = updateDTO.Prefix; + entity.Status = updateDTO.Status; + entity.Renavam = updateDTO.Renavam; + entity.FuelType = updateDTO.FuelType; + entity.AxesNumber = updateDTO.AxesNumber; + entity.NumberDoors = updateDTO.NumberDoors; + entity.NumberSeats = updateDTO.NumberSeats; + entity.EngineNumber = updateDTO.EngineNumber; + entity.NumberChassis = updateDTO.NumberChassis; + entity.BusChassisYear = updateDTO.BusChassisYear; + entity.BusServiceType = updateDTO.BusServiceType; + entity.BusHasLowFloor = updateDTO.BusHasLowFloor; + entity.IpvaExpiration = updateDTO.IpvaExpiration; + entity.BodyworkNumber = updateDTO.BodyworkNumber; + entity.BusChassisBrand = updateDTO.BusChassisBrand; + entity.BusChassisModel = updateDTO.BusChassisModel; + entity.AcquisitionDate = updateDTO.AcquisitionDate; + entity.BusHasLeftDoors = updateDTO.BusHasLeftDoors; + entity.HasAccessibility = updateDTO.HasAccessibility; + entity.TransmissionType = updateDTO.TransmissionType; + entity.LicensingExpiration = updateDTO.LicensingExpiration; + entity.BusFumigateExpiration = updateDTO.BusFumigateExpiration; + entity.BusInsuranceExpiration = updateDTO.BusInsuranceExpiration; } } } From 1ebd153b976b608660446a8c8c7de6a5f20c14d5 Mon Sep 17 00:00:00 2001 From: Eduardo Rezende Date: Sat, 4 Oct 2025 21:16:59 -0300 Subject: [PATCH 08/99] =?UTF-8?q?=E2=99=BB=EF=B8=8Frefactor:=20Update=20Ve?= =?UTF-8?q?hicle=20Enums?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Updating enums values --- .../Enums/Vehicle/BusChassisBrands.cs | 20 ++++++++++ .../BusServiceType.cs} | 4 +- OneBus.Domain/Enums/Vehicle/Color.cs | 22 +++++++++++ OneBus.Domain/Enums/Vehicle/FuelType.cs | 12 +++--- OneBus.Domain/Enums/Vehicle/VehicleBrands.cs | 37 +++++++++++++++++++ OneBus.Domain/Enums/Vehicle/VehicleStatus.cs | 8 ++-- OneBus.Domain/Enums/Vehicle/VehicleType.cs | 13 ++++--- 7 files changed, 98 insertions(+), 18 deletions(-) create mode 100644 OneBus.Domain/Enums/Vehicle/BusChassisBrands.cs rename OneBus.Domain/Enums/{Bus/ServiceType.cs => Vehicle/BusServiceType.cs} (50%) create mode 100644 OneBus.Domain/Enums/Vehicle/Color.cs create mode 100644 OneBus.Domain/Enums/Vehicle/VehicleBrands.cs diff --git a/OneBus.Domain/Enums/Vehicle/BusChassisBrands.cs b/OneBus.Domain/Enums/Vehicle/BusChassisBrands.cs new file mode 100644 index 0000000..6f7a365 --- /dev/null +++ b/OneBus.Domain/Enums/Vehicle/BusChassisBrands.cs @@ -0,0 +1,20 @@ +namespace OneBus.Domain.Enums.Vehicle +{ + public enum BusChassisBrands : byte + { + Mercedes_Benz, + Scania, + Volkswagen, + Volvo, + Volare, + Agrale, + Iveco, + BYD, + Higer, + Tecnobus, + Cummins, + Eletra, + Ankai, + Outros + } +} diff --git a/OneBus.Domain/Enums/Bus/ServiceType.cs b/OneBus.Domain/Enums/Vehicle/BusServiceType.cs similarity index 50% rename from OneBus.Domain/Enums/Bus/ServiceType.cs rename to OneBus.Domain/Enums/Vehicle/BusServiceType.cs index fbbfe05..aa01621 100644 --- a/OneBus.Domain/Enums/Bus/ServiceType.cs +++ b/OneBus.Domain/Enums/Vehicle/BusServiceType.cs @@ -1,6 +1,6 @@ -namespace OneBus.Domain.Enums.Bus +namespace OneBus.Domain.Enums.Vehicle { - public enum ServiceType : byte + public enum BusServiceType : byte { Municipal, Intermunicipal, diff --git a/OneBus.Domain/Enums/Vehicle/Color.cs b/OneBus.Domain/Enums/Vehicle/Color.cs new file mode 100644 index 0000000..5278999 --- /dev/null +++ b/OneBus.Domain/Enums/Vehicle/Color.cs @@ -0,0 +1,22 @@ +namespace OneBus.Domain.Enums.Vehicle +{ + public enum Color : byte + { + Amarelo, + Azul, + Bege, + Branco, + Cinza, + Dourado, + Grená, + Laranja, + Marrom, + Prata, + Preto, + Rosa, + Roxo, + Verde, + Vermelho, + Outros + } +} diff --git a/OneBus.Domain/Enums/Vehicle/FuelType.cs b/OneBus.Domain/Enums/Vehicle/FuelType.cs index 1ba6073..d78b7b0 100644 --- a/OneBus.Domain/Enums/Vehicle/FuelType.cs +++ b/OneBus.Domain/Enums/Vehicle/FuelType.cs @@ -2,11 +2,11 @@ { public enum FuelType : byte { - Diesel, - Gás, - Elétrico, - Híbrido, - Gasolina, - Etanol, + Gasolina, + Etanol, + Diesel, + Gas_Natural, + Eletrico, + Outros } } diff --git a/OneBus.Domain/Enums/Vehicle/VehicleBrands.cs b/OneBus.Domain/Enums/Vehicle/VehicleBrands.cs new file mode 100644 index 0000000..afd49b4 --- /dev/null +++ b/OneBus.Domain/Enums/Vehicle/VehicleBrands.cs @@ -0,0 +1,37 @@ +namespace OneBus.Domain.Enums.Vehicle +{ + public enum VehicleBrands : byte + { + Fiat, + Chevrolet, + Toyota, + Hyundai, + Renault, + Jeep, + Honda, + Citroen, + Ford, + Caio, + Marcopolo, + Comil, + Busccar, + Neobus, + Bepobus, + Mascarello, + Irizar, + Ciferal, + Volare, + Scania, + Tecnobus, + Mercedes_Benz, + Maxibus, + Ibrava, + AMD, + BYD, + Higer, + Ankai, + Neostar, + Nielson, + Outros + } +} diff --git a/OneBus.Domain/Enums/Vehicle/VehicleStatus.cs b/OneBus.Domain/Enums/Vehicle/VehicleStatus.cs index 92f372c..002c3a7 100644 --- a/OneBus.Domain/Enums/Vehicle/VehicleStatus.cs +++ b/OneBus.Domain/Enums/Vehicle/VehicleStatus.cs @@ -2,10 +2,10 @@ { public enum VehicleStatus : byte { - Disponível, - Operação, - Manutenção, + Desativado, + Em_Manutenção, Reservado, - Fora_Operação + Em_Operação, + Disponível } } diff --git a/OneBus.Domain/Enums/Vehicle/VehicleType.cs b/OneBus.Domain/Enums/Vehicle/VehicleType.cs index 04edce5..8628809 100644 --- a/OneBus.Domain/Enums/Vehicle/VehicleType.cs +++ b/OneBus.Domain/Enums/Vehicle/VehicleType.cs @@ -1,11 +1,12 @@ namespace OneBus.Domain.Enums.Vehicle { public enum VehicleType : byte - { - Caminhão_Guincho, - Ônibus, - Micro_Ônibus, - Carro, - Van + { + Onibus, + Micro_Onibus, + Onibus_Articulado, + Van, + Caminhão, + Carro } } From 29499f4ed881244b24d9056019161e012fc2be49 Mon Sep 17 00:00:00 2001 From: Eduardo Rezende Date: Sat, 4 Oct 2025 21:17:21 -0300 Subject: [PATCH 09/99] =?UTF-8?q?=E2=99=BB=EF=B8=8Frefactor:=20Update=20Ve?= =?UTF-8?q?hicle=20entity?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Updating fields types --- OneBus.Domain/Entities/Vehicle.cs | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/OneBus.Domain/Entities/Vehicle.cs b/OneBus.Domain/Entities/Vehicle.cs index 4d929cb..3573fd7 100644 --- a/OneBus.Domain/Entities/Vehicle.cs +++ b/OneBus.Domain/Entities/Vehicle.cs @@ -5,7 +5,6 @@ public class Vehicle : BaseEntity public Vehicle() { Prefix = string.Empty; - Brand = string.Empty; Model = string.Empty; Plate = string.Empty; Renavam = string.Empty; @@ -23,7 +22,7 @@ public Vehicle() public byte FuelType { get; set; } - public string Brand { get; set; } + public byte Brand { get; set; } public string Model { get; set; } @@ -31,7 +30,7 @@ public Vehicle() public string Plate { get; set; } - public string? Color { get; set; } + public byte? Color { get; set; } public string? BodyworkNumber { get; set; } @@ -57,7 +56,7 @@ public Vehicle() public byte? BusServiceType { get; set; } - public string? BusChassisBrand { get; set; } + public byte? BusChassisBrand { get; set; } public string? BusChassisModel { get; set; } From f1fdf695421b88330ae841e0ae27784b80124938 Mon Sep 17 00:00:00 2001 From: Eduardo Rezende Date: Sat, 4 Oct 2025 21:18:08 -0300 Subject: [PATCH 10/99] =?UTF-8?q?=E2=99=BB=EF=B8=8Frefactor:=20Update=20Ve?= =?UTF-8?q?hicle=20DTOs?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Adding enums DTOs and updating fields --- .../DTOs/Vehicle/CreateVehicleDTO.cs | 9 +++------ OneBus.Application/DTOs/Vehicle/ReadBrandDTO.cs | 14 ++++++++++++++ .../DTOs/Vehicle/ReadBusChassisBrandDTO.cs | 14 ++++++++++++++ .../DTOs/Vehicle/ReadBusServiceTypeDTO.cs | 14 ++++++++++++++ OneBus.Application/DTOs/Vehicle/ReadColorDTO.cs | 14 ++++++++++++++ OneBus.Application/DTOs/Vehicle/ReadFuelTypeDTO.cs | 14 ++++++++++++++ OneBus.Application/DTOs/Vehicle/ReadStatusDTO.cs | 14 ++++++++++++++ .../DTOs/Vehicle/ReadTransmissionTypeDTO.cs | 14 ++++++++++++++ OneBus.Application/DTOs/Vehicle/ReadTypeDTO.cs | 14 ++++++++++++++ OneBus.Application/DTOs/Vehicle/ReadVehicleDTO.cs | 9 +++++---- .../DTOs/Vehicle/UpdateVehicleDTO.cs | 7 +++---- 11 files changed, 123 insertions(+), 14 deletions(-) create mode 100644 OneBus.Application/DTOs/Vehicle/ReadBrandDTO.cs create mode 100644 OneBus.Application/DTOs/Vehicle/ReadBusChassisBrandDTO.cs create mode 100644 OneBus.Application/DTOs/Vehicle/ReadBusServiceTypeDTO.cs create mode 100644 OneBus.Application/DTOs/Vehicle/ReadColorDTO.cs create mode 100644 OneBus.Application/DTOs/Vehicle/ReadFuelTypeDTO.cs create mode 100644 OneBus.Application/DTOs/Vehicle/ReadStatusDTO.cs create mode 100644 OneBus.Application/DTOs/Vehicle/ReadTransmissionTypeDTO.cs create mode 100644 OneBus.Application/DTOs/Vehicle/ReadTypeDTO.cs diff --git a/OneBus.Application/DTOs/Vehicle/CreateVehicleDTO.cs b/OneBus.Application/DTOs/Vehicle/CreateVehicleDTO.cs index 06caf73..14c7646 100644 --- a/OneBus.Application/DTOs/Vehicle/CreateVehicleDTO.cs +++ b/OneBus.Application/DTOs/Vehicle/CreateVehicleDTO.cs @@ -5,14 +5,11 @@ public class CreateVehicleDTO : BaseCreateDTO public CreateVehicleDTO() { Prefix = string.Empty; - Brand = string.Empty; Model = string.Empty; Plate = string.Empty; Renavam = string.Empty; } - public byte Type { get; set; } - public string Prefix { get; set; } public byte NumberDoors { get; set; } @@ -23,7 +20,7 @@ public CreateVehicleDTO() public byte FuelType { get; set; } - public string Brand { get; set; } + public byte Brand { get; set; } public string Model { get; set; } @@ -31,7 +28,7 @@ public CreateVehicleDTO() public string Plate { get; set; } - public string? Color { get; set; } + public byte? Color { get; set; } public string? BodyworkNumber { get; set; } @@ -57,7 +54,7 @@ public CreateVehicleDTO() public byte? BusServiceType { get; set; } - public string? BusChassisBrand { get; set; } + public byte? BusChassisBrand { get; set; } public string? BusChassisModel { get; set; } diff --git a/OneBus.Application/DTOs/Vehicle/ReadBrandDTO.cs b/OneBus.Application/DTOs/Vehicle/ReadBrandDTO.cs new file mode 100644 index 0000000..a4dd81b --- /dev/null +++ b/OneBus.Application/DTOs/Vehicle/ReadBrandDTO.cs @@ -0,0 +1,14 @@ +namespace OneBus.Application.DTOs.Vehicle +{ + public class ReadBrandDTO + { + public ReadBrandDTO() + { + Name = string.Empty; + } + + public byte Value { get; set; } + + public string Name { get; set; } + } +} diff --git a/OneBus.Application/DTOs/Vehicle/ReadBusChassisBrandDTO.cs b/OneBus.Application/DTOs/Vehicle/ReadBusChassisBrandDTO.cs new file mode 100644 index 0000000..d309975 --- /dev/null +++ b/OneBus.Application/DTOs/Vehicle/ReadBusChassisBrandDTO.cs @@ -0,0 +1,14 @@ +namespace OneBus.Application.DTOs.Vehicle +{ + public class ReadBusChassisBrandDTO + { + public ReadBusChassisBrandDTO() + { + Name = string.Empty; + } + + public byte Value { get; set; } + + public string Name { get; set; } + } +} diff --git a/OneBus.Application/DTOs/Vehicle/ReadBusServiceTypeDTO.cs b/OneBus.Application/DTOs/Vehicle/ReadBusServiceTypeDTO.cs new file mode 100644 index 0000000..30401a1 --- /dev/null +++ b/OneBus.Application/DTOs/Vehicle/ReadBusServiceTypeDTO.cs @@ -0,0 +1,14 @@ +namespace OneBus.Application.DTOs.Vehicle +{ + public class ReadBusServiceTypeDTO + { + public ReadBusServiceTypeDTO() + { + Name = string.Empty; + } + + public byte Value { get; set; } + + public string Name { get; set; } + } +} diff --git a/OneBus.Application/DTOs/Vehicle/ReadColorDTO.cs b/OneBus.Application/DTOs/Vehicle/ReadColorDTO.cs new file mode 100644 index 0000000..9ac01eb --- /dev/null +++ b/OneBus.Application/DTOs/Vehicle/ReadColorDTO.cs @@ -0,0 +1,14 @@ +namespace OneBus.Application.DTOs.Vehicle +{ + public class ReadColorDTO + { + public ReadColorDTO() + { + Name = string.Empty; + } + + public byte Value { get; set; } + + public string Name { get; set; } + } +} diff --git a/OneBus.Application/DTOs/Vehicle/ReadFuelTypeDTO.cs b/OneBus.Application/DTOs/Vehicle/ReadFuelTypeDTO.cs new file mode 100644 index 0000000..337b0d8 --- /dev/null +++ b/OneBus.Application/DTOs/Vehicle/ReadFuelTypeDTO.cs @@ -0,0 +1,14 @@ +namespace OneBus.Application.DTOs.Vehicle +{ + public class ReadFuelTypeDTO + { + public ReadFuelTypeDTO() + { + Name = string.Empty; + } + + public byte Value { get; set; } + + public string Name { get; set; } + } +} diff --git a/OneBus.Application/DTOs/Vehicle/ReadStatusDTO.cs b/OneBus.Application/DTOs/Vehicle/ReadStatusDTO.cs new file mode 100644 index 0000000..26c9dd7 --- /dev/null +++ b/OneBus.Application/DTOs/Vehicle/ReadStatusDTO.cs @@ -0,0 +1,14 @@ +namespace OneBus.Application.DTOs.Vehicle +{ + public class ReadStatusDTO + { + public ReadStatusDTO() + { + Name = string.Empty; + } + + public byte Value { get; set; } + + public string Name { get; set; } + } +} diff --git a/OneBus.Application/DTOs/Vehicle/ReadTransmissionTypeDTO.cs b/OneBus.Application/DTOs/Vehicle/ReadTransmissionTypeDTO.cs new file mode 100644 index 0000000..81d7e25 --- /dev/null +++ b/OneBus.Application/DTOs/Vehicle/ReadTransmissionTypeDTO.cs @@ -0,0 +1,14 @@ +namespace OneBus.Application.DTOs.Vehicle +{ + public class ReadTransmissionTypeDTO + { + public ReadTransmissionTypeDTO() + { + Name = string.Empty; + } + + public byte Value { get; set; } + + public string Name { get; set; } + } +} diff --git a/OneBus.Application/DTOs/Vehicle/ReadTypeDTO.cs b/OneBus.Application/DTOs/Vehicle/ReadTypeDTO.cs new file mode 100644 index 0000000..f4a904f --- /dev/null +++ b/OneBus.Application/DTOs/Vehicle/ReadTypeDTO.cs @@ -0,0 +1,14 @@ +namespace OneBus.Application.DTOs.Vehicle +{ + public class ReadTypeDTO + { + public ReadTypeDTO() + { + Name = string.Empty; + } + + public byte Value { get; set; } + + public string Name { get; set; } + } +} diff --git a/OneBus.Application/DTOs/Vehicle/ReadVehicleDTO.cs b/OneBus.Application/DTOs/Vehicle/ReadVehicleDTO.cs index d23fa4f..c99e462 100644 --- a/OneBus.Application/DTOs/Vehicle/ReadVehicleDTO.cs +++ b/OneBus.Application/DTOs/Vehicle/ReadVehicleDTO.cs @@ -5,12 +5,13 @@ public class ReadVehicleDTO : BaseReadDTO public ReadVehicleDTO() { Prefix = string.Empty; - Brand = string.Empty; Model = string.Empty; Plate = string.Empty; Renavam = string.Empty; } + public byte Type { get; set; } + public string Prefix { get; set; } public byte NumberDoors { get; set; } @@ -21,7 +22,7 @@ public ReadVehicleDTO() public byte FuelType { get; set; } - public string Brand { get; set; } + public byte Brand { get; set; } public string Model { get; set; } @@ -29,7 +30,7 @@ public ReadVehicleDTO() public string Plate { get; set; } - public string? Color { get; set; } + public byte? Color { get; set; } public string? BodyworkNumber { get; set; } @@ -55,7 +56,7 @@ public ReadVehicleDTO() public byte? BusServiceType { get; set; } - public string? BusChassisBrand { get; set; } + public byte? BusChassisBrand { get; set; } public string? BusChassisModel { get; set; } diff --git a/OneBus.Application/DTOs/Vehicle/UpdateVehicleDTO.cs b/OneBus.Application/DTOs/Vehicle/UpdateVehicleDTO.cs index 664f799..7825963 100644 --- a/OneBus.Application/DTOs/Vehicle/UpdateVehicleDTO.cs +++ b/OneBus.Application/DTOs/Vehicle/UpdateVehicleDTO.cs @@ -5,7 +5,6 @@ public class UpdateVehicleDTO : BaseUpdateDTO public UpdateVehicleDTO() { Prefix = string.Empty; - Brand = string.Empty; Model = string.Empty; Plate = string.Empty; Renavam = string.Empty; @@ -21,7 +20,7 @@ public UpdateVehicleDTO() public byte FuelType { get; set; } - public string Brand { get; set; } + public byte Brand { get; set; } public string Model { get; set; } @@ -29,7 +28,7 @@ public UpdateVehicleDTO() public string Plate { get; set; } - public string? Color { get; set; } + public byte? Color { get; set; } public string? BodyworkNumber { get; set; } @@ -55,7 +54,7 @@ public UpdateVehicleDTO() public byte? BusServiceType { get; set; } - public string? BusChassisBrand { get; set; } + public byte? BusChassisBrand { get; set; } public string? BusChassisModel { get; set; } From 5512d8e632e0bf0564ee517941324520e0ae98b2 Mon Sep 17 00:00:00 2001 From: Eduardo Rezende Date: Sat, 4 Oct 2025 21:18:40 -0300 Subject: [PATCH 11/99] =?UTF-8?q?=E2=9C=A8feat:=20Add=20Migration?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Updating Vehicle Table fields types --- OneBus.Infra.Data/Mappings/VehicleMapping.cs | 3 - ...1005001325_UpdateVehicleFields.Designer.cs | 589 ++++++++++++++++++ .../20251005001325_UpdateVehicleFields.cs | 77 +++ .../OneBusDbContextModelSnapshot.cs | 19 +- 4 files changed, 672 insertions(+), 16 deletions(-) create mode 100644 OneBus.Infra.Data/Migrations/20251005001325_UpdateVehicleFields.Designer.cs create mode 100644 OneBus.Infra.Data/Migrations/20251005001325_UpdateVehicleFields.cs diff --git a/OneBus.Infra.Data/Mappings/VehicleMapping.cs b/OneBus.Infra.Data/Mappings/VehicleMapping.cs index 204e643..007b5cf 100644 --- a/OneBus.Infra.Data/Mappings/VehicleMapping.cs +++ b/OneBus.Infra.Data/Mappings/VehicleMapping.cs @@ -10,8 +10,6 @@ public override void Configure(EntityTypeBuilder builder) base.Configure(builder); builder.Property(c => c.Renavam).HasMaxLength(20); - builder.Property(c => c.Color).HasMaxLength(20); - builder.Property(c => c.Brand).HasMaxLength(50); builder.Property(c => c.Plate).HasMaxLength(20); builder.Property(c => c.Model).HasMaxLength(50); builder.Property(c => c.Prefix).HasMaxLength(30); @@ -19,7 +17,6 @@ public override void Configure(EntityTypeBuilder builder) builder.Property(c => c.NumberChassis).HasMaxLength(20); builder.Property(c => c.BodyworkNumber).HasMaxLength(20); - builder.Property(c => c.BusChassisBrand).HasMaxLength(50); builder.Property(c => c.BusChassisModel).HasMaxLength(50); builder.HasIndex(c => c.Plate); diff --git a/OneBus.Infra.Data/Migrations/20251005001325_UpdateVehicleFields.Designer.cs b/OneBus.Infra.Data/Migrations/20251005001325_UpdateVehicleFields.Designer.cs new file mode 100644 index 0000000..057b7d4 --- /dev/null +++ b/OneBus.Infra.Data/Migrations/20251005001325_UpdateVehicleFields.Designer.cs @@ -0,0 +1,589 @@ +// +using System; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; +using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; +using OneBus.Infra.Data.DbContexts; + +#nullable disable + +namespace OneBus.Infra.Data.Migrations +{ + [DbContext(typeof(OneBusDbContext))] + [Migration("20251005001325_UpdateVehicleFields")] + partial class UpdateVehicleFields + { + /// + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("ProductVersion", "9.0.9") + .HasAnnotation("Relational:MaxIdentifierLength", 63); + + NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder); + + modelBuilder.Entity("OneBus.Domain.Entities.Employee", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("bigint"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("BloodType") + .HasColumnType("smallint"); + + b.Property("CnhCategory") + .HasColumnType("smallint"); + + b.Property("CnhExpiration") + .HasColumnType("date"); + + b.Property("CnhNumber") + .HasMaxLength(20) + .IsUnicode(false) + .HasColumnType("character varying(20)"); + + b.Property("Code") + .IsRequired() + .HasMaxLength(30) + .IsUnicode(false) + .HasColumnType("character varying(30)"); + + b.Property("Cpf") + .IsRequired() + .HasMaxLength(20) + .IsUnicode(false) + .HasColumnType("character varying(20)"); + + b.Property("CreatedAt") + .HasColumnType("timestamp with time zone"); + + b.Property("Email") + .IsRequired() + .HasMaxLength(80) + .IsUnicode(false) + .HasColumnType("character varying(80)"); + + b.Property("HiringDate") + .HasColumnType("date"); + + b.Property("Image") + .HasColumnType("bytea"); + + b.Property("IsDeleted") + .HasColumnType("boolean"); + + b.Property("Name") + .IsRequired() + .HasMaxLength(80) + .IsUnicode(false) + .HasColumnType("character varying(80)"); + + b.Property("Phone") + .IsRequired() + .HasMaxLength(20) + .IsUnicode(false) + .HasColumnType("character varying(20)"); + + b.Property("Rg") + .IsRequired() + .HasMaxLength(20) + .IsUnicode(false) + .HasColumnType("character varying(20)"); + + b.Property("Role") + .HasColumnType("smallint"); + + b.Property("Status") + .HasColumnType("smallint"); + + b.HasKey("Id"); + + b.HasIndex("CnhNumber"); + + b.HasIndex("Code"); + + b.HasIndex("Cpf"); + + b.ToTable("Employee"); + }); + + modelBuilder.Entity("OneBus.Domain.Entities.EmployeeWorkday", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("bigint"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("CreatedAt") + .HasColumnType("timestamp with time zone"); + + b.Property("DayType") + .HasColumnType("smallint"); + + b.Property("EmployeeId") + .HasColumnType("bigint"); + + b.Property("EndTime") + .HasColumnType("time without time zone"); + + b.Property("IsDeleted") + .HasColumnType("boolean"); + + b.Property("StartTime") + .HasColumnType("time without time zone"); + + b.HasKey("Id"); + + b.HasIndex("EmployeeId"); + + b.ToTable("EmployeeWorkday"); + }); + + modelBuilder.Entity("OneBus.Domain.Entities.Line", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("bigint"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("CreatedAt") + .HasColumnType("timestamp with time zone"); + + b.Property("IsDeleted") + .HasColumnType("boolean"); + + b.Property("MaxNumberBuses") + .HasColumnType("smallint"); + + b.Property("Mileage") + .HasPrecision(19, 4) + .HasColumnType("numeric(19,4)"); + + b.Property("MinNumberBuses") + .HasColumnType("smallint"); + + b.Property("Name") + .IsRequired() + .HasMaxLength(80) + .IsUnicode(false) + .HasColumnType("character varying(80)"); + + b.Property("Number") + .IsRequired() + .HasMaxLength(20) + .IsUnicode(false) + .HasColumnType("character varying(20)"); + + b.Property("TravelTime") + .HasColumnType("time without time zone"); + + b.Property("Type") + .HasColumnType("smallint"); + + b.HasKey("Id"); + + b.ToTable("Line"); + }); + + modelBuilder.Entity("OneBus.Domain.Entities.LineTime", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("bigint"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("CreatedAt") + .HasColumnType("timestamp with time zone"); + + b.Property("DayType") + .HasColumnType("smallint"); + + b.Property("EndTime") + .HasColumnType("time without time zone"); + + b.Property("IsDeleted") + .HasColumnType("boolean"); + + b.Property("LineId") + .HasColumnType("bigint"); + + b.Property("StartTime") + .HasColumnType("time without time zone"); + + b.HasKey("Id"); + + b.HasIndex("LineId"); + + b.ToTable("LineTime"); + }); + + modelBuilder.Entity("OneBus.Domain.Entities.Maintenance", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("bigint"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("Cost") + .HasPrecision(19, 4) + .HasColumnType("numeric(19,4)"); + + b.Property("CreatedAt") + .HasColumnType("timestamp with time zone"); + + b.Property("Description") + .IsRequired() + .HasMaxLength(150) + .IsUnicode(false) + .HasColumnType("character varying(150)"); + + b.Property("EndDate") + .HasColumnType("date"); + + b.Property("IsDeleted") + .HasColumnType("boolean"); + + b.Property("Sector") + .HasColumnType("smallint"); + + b.Property("StartDate") + .HasColumnType("date"); + + b.Property("SurveyExpiration") + .HasColumnType("date"); + + b.Property("VehicleId") + .HasColumnType("bigint"); + + b.HasKey("Id"); + + b.HasIndex("VehicleId"); + + b.ToTable("Maintenance"); + }); + + modelBuilder.Entity("OneBus.Domain.Entities.User", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("bigint"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("CreatedAt") + .HasColumnType("timestamp with time zone"); + + b.Property("Email") + .IsRequired() + .HasMaxLength(80) + .IsUnicode(false) + .HasColumnType("character varying(80)"); + + b.Property("IsDeleted") + .HasColumnType("boolean"); + + b.Property("Name") + .IsRequired() + .HasMaxLength(80) + .IsUnicode(false) + .HasColumnType("character varying(80)"); + + b.Property("Password") + .IsRequired() + .HasMaxLength(50) + .IsUnicode(false) + .HasColumnType("character varying(50)"); + + b.Property("Salt") + .IsRequired() + .HasMaxLength(32) + .IsUnicode(false) + .HasColumnType("character varying(32)"); + + b.HasKey("Id"); + + b.ToTable("User"); + + b.HasData( + new + { + Id = 1L, + CreatedAt = new DateTime(2025, 8, 25, 0, 0, 0, 0, DateTimeKind.Utc), + Email = "onebus@admin", + IsDeleted = false, + Name = "Administrador", + Password = "YRT66Z4XEJ2SSNaJVDIXQW7uvC8LSvOxDU1sH/Sr/ic=", + Salt = "c37b6028194d489192aac9391801594a" + }); + }); + + modelBuilder.Entity("OneBus.Domain.Entities.Vehicle", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("bigint"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("AcquisitionDate") + .HasColumnType("date"); + + b.Property("AxesNumber") + .HasColumnType("smallint"); + + b.Property("BodyworkNumber") + .HasMaxLength(20) + .IsUnicode(false) + .HasColumnType("character varying(20)"); + + b.Property("Brand") + .HasColumnType("smallint"); + + b.Property("BusChassisBrand") + .HasColumnType("smallint"); + + b.Property("BusChassisModel") + .HasMaxLength(50) + .IsUnicode(false) + .HasColumnType("character varying(50)"); + + b.Property("BusChassisYear") + .HasColumnType("smallint"); + + b.Property("BusFumigateExpiration") + .HasColumnType("date"); + + b.Property("BusHasLeftDoors") + .HasColumnType("boolean"); + + b.Property("BusHasLowFloor") + .HasColumnType("boolean"); + + b.Property("BusInsuranceExpiration") + .HasColumnType("date"); + + b.Property("BusServiceType") + .HasColumnType("smallint"); + + b.Property("Color") + .HasColumnType("smallint"); + + b.Property("CreatedAt") + .HasColumnType("timestamp with time zone"); + + b.Property("EngineNumber") + .HasMaxLength(20) + .IsUnicode(false) + .HasColumnType("character varying(20)"); + + b.Property("FuelType") + .HasColumnType("smallint"); + + b.Property("HasAccessibility") + .HasColumnType("boolean"); + + b.Property("Image") + .HasColumnType("bytea"); + + b.Property("IpvaExpiration") + .HasColumnType("date"); + + b.Property("IsDeleted") + .HasColumnType("boolean"); + + b.Property("LicensingExpiration") + .HasColumnType("date"); + + b.Property("Model") + .IsRequired() + .HasMaxLength(50) + .IsUnicode(false) + .HasColumnType("character varying(50)"); + + b.Property("NumberChassis") + .HasMaxLength(20) + .IsUnicode(false) + .HasColumnType("character varying(20)"); + + b.Property("NumberDoors") + .HasColumnType("smallint"); + + b.Property("NumberSeats") + .HasColumnType("smallint"); + + b.Property("Plate") + .IsRequired() + .HasMaxLength(20) + .IsUnicode(false) + .HasColumnType("character varying(20)"); + + b.Property("Prefix") + .IsRequired() + .HasMaxLength(30) + .IsUnicode(false) + .HasColumnType("character varying(30)"); + + b.Property("Renavam") + .IsRequired() + .HasMaxLength(20) + .IsUnicode(false) + .HasColumnType("character varying(20)"); + + b.Property("Status") + .HasColumnType("smallint"); + + b.Property("TransmissionType") + .HasColumnType("smallint"); + + b.Property("Type") + .HasColumnType("smallint"); + + b.Property("Year") + .HasColumnType("integer"); + + b.HasKey("Id"); + + b.HasIndex("Plate"); + + b.HasIndex("Prefix"); + + b.HasIndex("Renavam"); + + b.ToTable("Vehicle"); + }); + + modelBuilder.Entity("OneBus.Domain.Entities.VehicleOperation", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("bigint"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("CreatedAt") + .HasColumnType("timestamp with time zone"); + + b.Property("Date") + .HasColumnType("date"); + + b.Property("EmployeeWorkdayId") + .HasColumnType("bigint"); + + b.Property("IsDeleted") + .HasColumnType("boolean"); + + b.Property("LineTimeId") + .HasColumnType("bigint"); + + b.Property("VehicleId") + .HasColumnType("bigint"); + + b.HasKey("Id"); + + b.HasIndex("EmployeeWorkdayId"); + + b.HasIndex("LineTimeId"); + + b.HasIndex("VehicleId"); + + b.ToTable("VehicleOperation"); + }); + + modelBuilder.Entity("OneBus.Domain.Entities.EmployeeWorkday", b => + { + b.HasOne("OneBus.Domain.Entities.Employee", "Employee") + .WithMany("EmployeeWorkdays") + .HasForeignKey("EmployeeId") + .OnDelete(DeleteBehavior.Restrict) + .IsRequired(); + + b.Navigation("Employee"); + }); + + modelBuilder.Entity("OneBus.Domain.Entities.LineTime", b => + { + b.HasOne("OneBus.Domain.Entities.Line", "Line") + .WithMany("LineTimes") + .HasForeignKey("LineId") + .OnDelete(DeleteBehavior.Restrict) + .IsRequired(); + + b.Navigation("Line"); + }); + + modelBuilder.Entity("OneBus.Domain.Entities.Maintenance", b => + { + b.HasOne("OneBus.Domain.Entities.Vehicle", "Vehicle") + .WithMany("Maintenances") + .HasForeignKey("VehicleId") + .OnDelete(DeleteBehavior.Restrict) + .IsRequired(); + + b.Navigation("Vehicle"); + }); + + modelBuilder.Entity("OneBus.Domain.Entities.VehicleOperation", b => + { + b.HasOne("OneBus.Domain.Entities.EmployeeWorkday", "EmployeeWorkday") + .WithMany("VehicleOperations") + .HasForeignKey("EmployeeWorkdayId") + .OnDelete(DeleteBehavior.Restrict) + .IsRequired(); + + b.HasOne("OneBus.Domain.Entities.LineTime", "LineTime") + .WithMany("VehicleOperations") + .HasForeignKey("LineTimeId") + .OnDelete(DeleteBehavior.Restrict); + + b.HasOne("OneBus.Domain.Entities.Vehicle", "Vehicle") + .WithMany("VehicleOperations") + .HasForeignKey("VehicleId") + .OnDelete(DeleteBehavior.Restrict) + .IsRequired(); + + b.Navigation("EmployeeWorkday"); + + b.Navigation("LineTime"); + + b.Navigation("Vehicle"); + }); + + modelBuilder.Entity("OneBus.Domain.Entities.Employee", b => + { + b.Navigation("EmployeeWorkdays"); + }); + + modelBuilder.Entity("OneBus.Domain.Entities.EmployeeWorkday", b => + { + b.Navigation("VehicleOperations"); + }); + + modelBuilder.Entity("OneBus.Domain.Entities.Line", b => + { + b.Navigation("LineTimes"); + }); + + modelBuilder.Entity("OneBus.Domain.Entities.LineTime", b => + { + b.Navigation("VehicleOperations"); + }); + + modelBuilder.Entity("OneBus.Domain.Entities.Vehicle", b => + { + b.Navigation("Maintenances"); + + b.Navigation("VehicleOperations"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/OneBus.Infra.Data/Migrations/20251005001325_UpdateVehicleFields.cs b/OneBus.Infra.Data/Migrations/20251005001325_UpdateVehicleFields.cs new file mode 100644 index 0000000..458b72f --- /dev/null +++ b/OneBus.Infra.Data/Migrations/20251005001325_UpdateVehicleFields.cs @@ -0,0 +1,77 @@ +using Microsoft.EntityFrameworkCore.Migrations; + +#nullable disable + +namespace OneBus.Infra.Data.Migrations +{ + /// + public partial class UpdateVehicleFields : Migration + { + /// + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropColumn( + name: "Color", + table: "Vehicle"); + + migrationBuilder.AddColumn( + name: "Color", + table: "Vehicle", + nullable: true); + + migrationBuilder.DropColumn( + name: "BusChassisBrand", + table: "Vehicle"); + + migrationBuilder.AddColumn( + name: "BusChassisBrand", + table: "Vehicle", + nullable: true); + + migrationBuilder.DropColumn( + name: "Brand", + table: "Vehicle"); + + migrationBuilder.AddColumn( + name: "Brand", + table: "Vehicle", + nullable: false); + } + + /// + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.AlterColumn( + name: "Color", + table: "Vehicle", + type: "character varying(20)", + unicode: false, + maxLength: 20, + nullable: true, + oldClrType: typeof(byte), + oldType: "smallint", + oldNullable: true); + + migrationBuilder.AlterColumn( + name: "BusChassisBrand", + table: "Vehicle", + type: "character varying(50)", + unicode: false, + maxLength: 50, + nullable: true, + oldClrType: typeof(byte), + oldType: "smallint", + oldNullable: true); + + migrationBuilder.AlterColumn( + name: "Brand", + table: "Vehicle", + type: "character varying(50)", + unicode: false, + maxLength: 50, + nullable: false, + oldClrType: typeof(byte), + oldType: "smallint"); + } + } +} diff --git a/OneBus.Infra.Data/Migrations/OneBusDbContextModelSnapshot.cs b/OneBus.Infra.Data/Migrations/OneBusDbContextModelSnapshot.cs index 5d46760..541d643 100644 --- a/OneBus.Infra.Data/Migrations/OneBusDbContextModelSnapshot.cs +++ b/OneBus.Infra.Data/Migrations/OneBusDbContextModelSnapshot.cs @@ -342,16 +342,11 @@ protected override void BuildModel(ModelBuilder modelBuilder) .IsUnicode(false) .HasColumnType("character varying(20)"); - b.Property("Brand") - .IsRequired() - .HasMaxLength(50) - .IsUnicode(false) - .HasColumnType("character varying(50)"); + b.Property("Brand") + .HasColumnType("smallint"); - b.Property("BusChassisBrand") - .HasMaxLength(50) - .IsUnicode(false) - .HasColumnType("character varying(50)"); + b.Property("BusChassisBrand") + .HasColumnType("smallint"); b.Property("BusChassisModel") .HasMaxLength(50) @@ -376,10 +371,8 @@ protected override void BuildModel(ModelBuilder modelBuilder) b.Property("BusServiceType") .HasColumnType("smallint"); - b.Property("Color") - .HasMaxLength(20) - .IsUnicode(false) - .HasColumnType("character varying(20)"); + b.Property("Color") + .HasColumnType("smallint"); b.Property("CreatedAt") .HasColumnType("timestamp with time zone"); From e98f9b12e85ebb3090d1131a55908731ef8207b7 Mon Sep 17 00:00:00 2001 From: Eduardo Rezende Date: Sat, 4 Oct 2025 21:19:04 -0300 Subject: [PATCH 12/99] =?UTF-8?q?=E2=99=BB=EF=B8=8Frefactor:=20Update=20Ve?= =?UTF-8?q?hicle=20Service?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Adding Get enums values methods --- .../Interfaces/Services/IVehicleService.cs | 16 +++ OneBus.Application/Services/VehicleService.cs | 121 +++++++++++++++++- 2 files changed, 134 insertions(+), 3 deletions(-) diff --git a/OneBus.Application/Interfaces/Services/IVehicleService.cs b/OneBus.Application/Interfaces/Services/IVehicleService.cs index ac0f422..bd74d0a 100644 --- a/OneBus.Application/Interfaces/Services/IVehicleService.cs +++ b/OneBus.Application/Interfaces/Services/IVehicleService.cs @@ -1,4 +1,5 @@ using OneBus.Application.DTOs.Vehicle; +using OneBus.Domain.Commons.Result; using OneBus.Domain.Entities; using OneBus.Domain.Filters; @@ -7,5 +8,20 @@ namespace OneBus.Application.Interfaces.Services public interface IVehicleService : IBaseService { + Result> GetBrands(); + + Result> GetBusChassisBrands(); + + Result> GetBusServiceTypes(); + + Result> GetColors(); + + Result> GetFuelTypes(); + + Result> GetStatus(); + + Result> GetTransmissionTypes(); + + Result> GetVehicleTypes(); } } diff --git a/OneBus.Application/Services/VehicleService.cs b/OneBus.Application/Services/VehicleService.cs index 2901cb0..7aa2385 100644 --- a/OneBus.Application/Services/VehicleService.cs +++ b/OneBus.Application/Services/VehicleService.cs @@ -1,7 +1,10 @@ using FluentValidation; using OneBus.Application.DTOs.Vehicle; using OneBus.Application.Interfaces.Services; +using OneBus.Domain.Commons.Result; using OneBus.Domain.Entities; +using OneBus.Domain.Enums.Vehicle; +using OneBus.Domain.Extensions; using OneBus.Domain.Filters; using OneBus.Domain.Interfaces.Repositories; @@ -11,13 +14,125 @@ public class VehicleService : BaseService baseRepository, - IValidator createValidator, - IValidator updateValidator) + IBaseRepository baseRepository, + IValidator createValidator, + IValidator updateValidator) : base(baseRepository, createValidator, updateValidator) { } + public Result> GetStatus() + { + var values = Enum.GetValues(); + + List status = []; + + foreach (var value in values) + { + status.Add(new ReadStatusDTO { Value = (byte)value, Name = value.ToString().Localize() }); + } + + return SuccessResult>.Create(status); + } + + public Result> GetBrands() + { + var values = Enum.GetValues(); + + List status = []; + + foreach (var value in values) + { + status.Add(new ReadBrandDTO { Value = (byte)value, Name = value.ToString().Localize() }); + } + + return SuccessResult>.Create(status); + } + + public Result> GetBusChassisBrands() + { + var values = Enum.GetValues(); + + List status = []; + + foreach (var value in values) + { + status.Add(new ReadBusChassisBrandDTO { Value = (byte)value, Name = value.ToString().Localize() }); + } + + return SuccessResult>.Create(status); + } + + public Result> GetBusServiceTypes() + { + var values = Enum.GetValues(); + + List status = []; + + foreach (var value in values) + { + status.Add(new ReadBusServiceTypeDTO { Value = (byte)value, Name = value.ToString().Localize() }); + } + + return SuccessResult>.Create(status); + } + + public Result> GetColors() + { + var values = Enum.GetValues(); + + List status = []; + + foreach (var value in values) + { + status.Add(new ReadColorDTO { Value = (byte)value, Name = value.ToString().Localize() }); + } + + return SuccessResult>.Create(status); + } + + public Result> GetFuelTypes() + { + var values = Enum.GetValues(); + + List status = []; + + foreach (var value in values) + { + status.Add(new ReadFuelTypeDTO { Value = (byte)value, Name = value.ToString().Localize() }); + } + + return SuccessResult>.Create(status); + } + + public Result> GetTransmissionTypes() + { + var values = Enum.GetValues(); + + List status = []; + + foreach (var value in values) + { + status.Add(new ReadTransmissionTypeDTO { Value = (byte)value, Name = value.ToString().Localize() }); + } + + return SuccessResult>.Create(status); + } + + public Result> GetVehicleTypes() + { + var values = Enum.GetValues(); + + List status = []; + + foreach (var value in values) + { + status.Add(new ReadTypeDTO { Value = (byte)value, Name = value.ToString().Localize() }); + } + + return SuccessResult>.Create(status); + } + protected override void UpdateFields(Vehicle entity, UpdateVehicleDTO updateDTO) { entity.Year = updateDTO.Year; From 6972bfdf2753382cdd41af70fca06044eb4fea2a Mon Sep 17 00:00:00 2001 From: Eduardo Rezende Date: Sat, 4 Oct 2025 21:19:24 -0300 Subject: [PATCH 13/99] =?UTF-8?q?=E2=99=BB=EF=B8=8Frefactor:=20Update=20Ve?= =?UTF-8?q?hicle=20Controller?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Adding Get enums values endpoints --- OneBus.API/Controllers/VehicleController.cs | 120 ++++++++++++++++++++ 1 file changed, 120 insertions(+) diff --git a/OneBus.API/Controllers/VehicleController.cs b/OneBus.API/Controllers/VehicleController.cs index 7185c78..6abcbfd 100644 --- a/OneBus.API/Controllers/VehicleController.cs +++ b/OneBus.API/Controllers/VehicleController.cs @@ -125,5 +125,125 @@ public async Task GetByIdAsync([FromRoute] long id, CancellationT { return (await _vehicleService.GetByIdAsync(id, cancellationToken: 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 _vehicleService.GetStatus().ToActionResult(); + } + + /// + /// Listar marcas + /// + /// + /// GET de marcas + /// + /// Marcas disponíveis + /// Marcas retornadas com sucesso + [HttpGet("brands")] + [ProducesResponseType(typeof(SuccessResult>), StatusCodes.Status200OK)] + public IActionResult GetBrands() + { + return _vehicleService.GetBrands().ToActionResult(); + } + + /// + /// Listar marcas de chassis + /// + /// + /// GET de marcas de chassis + /// + /// Marcas de chassis disponíveis + /// Marcas de chassis retornadas com sucesso + [HttpGet("chassisBrands")] + [ProducesResponseType(typeof(SuccessResult>), StatusCodes.Status200OK)] + public IActionResult GetBusChassisBrands() + { + return _vehicleService.GetBusChassisBrands().ToActionResult(); + } + + /// + /// Listar tipos de serviço + /// + /// + /// GET de tipos de serviço + /// + /// Tipos de serviço disponíveis + /// Tipos de serviço retornados com sucesso + [HttpGet("serviceTypes")] + [ProducesResponseType(typeof(SuccessResult>), StatusCodes.Status200OK)] + public IActionResult GetBusServiceTypes() + { + return _vehicleService.GetBusServiceTypes().ToActionResult(); + } + + /// + /// Listar cores + /// + /// + /// GET de cores + /// + /// Cores disponíveis + /// Cores retornadas com sucesso + [HttpGet("colors")] + [ProducesResponseType(typeof(SuccessResult>), StatusCodes.Status200OK)] + public IActionResult GetColors() + { + return _vehicleService.GetColors().ToActionResult(); + } + + /// + /// Listar tipos de combustíveis + /// + /// + /// GET de tipos de combustíveis + /// + /// Tipos de combustíveis disponíveis + /// Tipos de combustíveis retornados com sucesso + [HttpGet("fuelTypes")] + [ProducesResponseType(typeof(SuccessResult>), StatusCodes.Status200OK)] + public IActionResult GetFuelTypes() + { + return _vehicleService.GetFuelTypes().ToActionResult(); + } + + /// + /// Listar tipos de transmissão + /// + /// + /// GET de tipos de transmissão + /// + /// Tipos de transmissão disponíveis + /// Tipos de transmissão retornados com sucesso + [HttpGet("transmissionTypes")] + [ProducesResponseType(typeof(SuccessResult>), StatusCodes.Status200OK)] + public IActionResult GetTransmissionTypes() + { + return _vehicleService.GetTransmissionTypes().ToActionResult(); + } + + /// + /// Listar tipos de veículo + /// + /// + /// GET de tipos de veículo + /// + /// Tipos de veículo disponíveis + /// Tipos de veículo retornados com sucesso + [HttpGet("types")] + [ProducesResponseType(typeof(SuccessResult>), StatusCodes.Status200OK)] + public IActionResult GetVehicleTypes() + { + return _vehicleService.GetVehicleTypes().ToActionResult(); + } } } From 4c98eb875e776f5bec2b1f334a0f0e6f06a3221a Mon Sep 17 00:00:00 2001 From: Eduardo Rezende Date: Sat, 4 Oct 2025 21:25:24 -0300 Subject: [PATCH 14/99] =?UTF-8?q?=E2=99=BB=EF=B8=8Frefactor:=20Update=20St?= =?UTF-8?q?atus=20DTOs?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Updating Status DTOs classes names because swagger generation --- .../Employee/{ReadStatusDTO.cs => ReadEmployeeStatusDTO.cs} | 4 ++-- .../Vehicle/{ReadStatusDTO.cs => ReadVehicleStatusDTO.cs} | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) rename OneBus.Application/DTOs/Employee/{ReadStatusDTO.cs => ReadEmployeeStatusDTO.cs} (71%) rename OneBus.Application/DTOs/Vehicle/{ReadStatusDTO.cs => ReadVehicleStatusDTO.cs} (72%) diff --git a/OneBus.Application/DTOs/Employee/ReadStatusDTO.cs b/OneBus.Application/DTOs/Employee/ReadEmployeeStatusDTO.cs similarity index 71% rename from OneBus.Application/DTOs/Employee/ReadStatusDTO.cs rename to OneBus.Application/DTOs/Employee/ReadEmployeeStatusDTO.cs index 6712450..0609d62 100644 --- a/OneBus.Application/DTOs/Employee/ReadStatusDTO.cs +++ b/OneBus.Application/DTOs/Employee/ReadEmployeeStatusDTO.cs @@ -1,8 +1,8 @@ namespace OneBus.Application.DTOs.Employee { - public class ReadStatusDTO + public class ReadEmployeeStatusDTO { - public ReadStatusDTO() + public ReadEmployeeStatusDTO() { Name = string.Empty; } diff --git a/OneBus.Application/DTOs/Vehicle/ReadStatusDTO.cs b/OneBus.Application/DTOs/Vehicle/ReadVehicleStatusDTO.cs similarity index 72% rename from OneBus.Application/DTOs/Vehicle/ReadStatusDTO.cs rename to OneBus.Application/DTOs/Vehicle/ReadVehicleStatusDTO.cs index 26c9dd7..02b6262 100644 --- a/OneBus.Application/DTOs/Vehicle/ReadStatusDTO.cs +++ b/OneBus.Application/DTOs/Vehicle/ReadVehicleStatusDTO.cs @@ -1,8 +1,8 @@ namespace OneBus.Application.DTOs.Vehicle { - public class ReadStatusDTO + public class ReadVehicleStatusDTO { - public ReadStatusDTO() + public ReadVehicleStatusDTO() { Name = string.Empty; } From d0545981b6431fd929318a6e13fc66f8017b15ba Mon Sep 17 00:00:00 2001 From: Eduardo Rezende Date: Sat, 4 Oct 2025 21:26:00 -0300 Subject: [PATCH 15/99] =?UTF-8?q?=E2=99=BB=EF=B8=8Frefactor:=20Update=20Se?= =?UTF-8?q?rvices?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Updating Status DTOs classes names references --- .../Interfaces/Services/IEmployeeService.cs | 2 +- OneBus.Application/Interfaces/Services/IVehicleService.cs | 2 +- OneBus.Application/Services/EmployeeService.cs | 8 ++++---- OneBus.Application/Services/VehicleService.cs | 8 ++++---- 4 files changed, 10 insertions(+), 10 deletions(-) diff --git a/OneBus.Application/Interfaces/Services/IEmployeeService.cs b/OneBus.Application/Interfaces/Services/IEmployeeService.cs index d924a80..b529797 100644 --- a/OneBus.Application/Interfaces/Services/IEmployeeService.cs +++ b/OneBus.Application/Interfaces/Services/IEmployeeService.cs @@ -12,6 +12,6 @@ public interface IEmployeeService : Result> GetRoles(); - Result> GetStatus(); + Result> GetStatus(); } } diff --git a/OneBus.Application/Interfaces/Services/IVehicleService.cs b/OneBus.Application/Interfaces/Services/IVehicleService.cs index bd74d0a..e992de7 100644 --- a/OneBus.Application/Interfaces/Services/IVehicleService.cs +++ b/OneBus.Application/Interfaces/Services/IVehicleService.cs @@ -18,7 +18,7 @@ public interface IVehicleService : Result> GetFuelTypes(); - Result> GetStatus(); + Result> GetStatus(); Result> GetTransmissionTypes(); diff --git a/OneBus.Application/Services/EmployeeService.cs b/OneBus.Application/Services/EmployeeService.cs index 8114cd2..8059bb8 100644 --- a/OneBus.Application/Services/EmployeeService.cs +++ b/OneBus.Application/Services/EmployeeService.cs @@ -61,18 +61,18 @@ public override async Task> GetByIdAsync( return result; } - public Result> GetStatus() + public Result> GetStatus() { var values = Enum.GetValues(); - List status = []; + List status = []; foreach (var value in values) { - status.Add(new ReadStatusDTO { Value = (byte)value, Name = value.ToString().Localize() }); + status.Add(new ReadEmployeeStatusDTO { Value = (byte)value, Name = value.ToString().Localize() }); } - return SuccessResult>.Create(status); + return SuccessResult>.Create(status); } public Result> GetRoles() { diff --git a/OneBus.Application/Services/VehicleService.cs b/OneBus.Application/Services/VehicleService.cs index 7aa2385..9983923 100644 --- a/OneBus.Application/Services/VehicleService.cs +++ b/OneBus.Application/Services/VehicleService.cs @@ -21,18 +21,18 @@ public VehicleService( { } - public Result> GetStatus() + public Result> GetStatus() { var values = Enum.GetValues(); - List status = []; + List status = []; foreach (var value in values) { - status.Add(new ReadStatusDTO { Value = (byte)value, Name = value.ToString().Localize() }); + status.Add(new ReadVehicleStatusDTO { Value = (byte)value, Name = value.ToString().Localize() }); } - return SuccessResult>.Create(status); + return SuccessResult>.Create(status); } public Result> GetBrands() From ad98f9f289f9cd22ba0b469f6ca3f633da47ae8d Mon Sep 17 00:00:00 2001 From: Eduardo Rezende Date: Sat, 4 Oct 2025 21:27:13 -0300 Subject: [PATCH 16/99] =?UTF-8?q?=F0=9F=93=9Adocs:=20Update=20User=20Contr?= =?UTF-8?q?oller?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Updating login endpoint documentation --- OneBus.API/Controllers/UserController.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/OneBus.API/Controllers/UserController.cs b/OneBus.API/Controllers/UserController.cs index 7ca6bae..1ecfd24 100644 --- a/OneBus.API/Controllers/UserController.cs +++ b/OneBus.API/Controllers/UserController.cs @@ -31,8 +31,8 @@ public UserController(IUserService userService) /// /// POST /logins /// { - /// "email": "helloworld@gmail.com", - /// "password": "dasdfsf35346353tsd" + /// "email": "onebus@admin", + /// "password": "onebus@2025" /// } /// /// From 2bd199f7cddc8a2a25e6b550e4673a64165aeb76 Mon Sep 17 00:00:00 2001 From: Eduardo Rezende Date: Sat, 4 Oct 2025 21:27:53 -0300 Subject: [PATCH 17/99] =?UTF-8?q?=E2=99=BB=EF=B8=8Frefactor:=20Update=20Ve?= =?UTF-8?q?hicle=20Controller?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Removing NonController attribute --- OneBus.API/Controllers/EmployeeController.cs | 2 +- OneBus.API/Controllers/VehicleController.cs | 3 +-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/OneBus.API/Controllers/EmployeeController.cs b/OneBus.API/Controllers/EmployeeController.cs index af4d0b2..52b16a3 100644 --- a/OneBus.API/Controllers/EmployeeController.cs +++ b/OneBus.API/Controllers/EmployeeController.cs @@ -134,7 +134,7 @@ public async Task GetByIdAsync([FromRoute] long id, CancellationT /// Status disponíveis /// Status retornados com sucesso [HttpGet("status")] - [ProducesResponseType(typeof(SuccessResult>), StatusCodes.Status200OK)] + [ProducesResponseType(typeof(SuccessResult>), StatusCodes.Status200OK)] public IActionResult GetStatus() { return _employeeService.GetStatus().ToActionResult(); diff --git a/OneBus.API/Controllers/VehicleController.cs b/OneBus.API/Controllers/VehicleController.cs index 6abcbfd..8320ff7 100644 --- a/OneBus.API/Controllers/VehicleController.cs +++ b/OneBus.API/Controllers/VehicleController.cs @@ -10,7 +10,6 @@ namespace OneBus.API.Controllers { - [NonController] [Route("api/v1/vehicles")] [ApiController] [Produces("application/json")] @@ -135,7 +134,7 @@ public async Task GetByIdAsync([FromRoute] long id, CancellationT /// Status disponíveis /// Status retornados com sucesso [HttpGet("status")] - [ProducesResponseType(typeof(SuccessResult>), StatusCodes.Status200OK)] + [ProducesResponseType(typeof(SuccessResult>), StatusCodes.Status200OK)] public IActionResult GetStatus() { return _vehicleService.GetStatus().ToActionResult(); From db820fea25cea8a671e0633679e234d6b6bbaecd Mon Sep 17 00:00:00 2001 From: Eduardo Rezende Date: Sat, 4 Oct 2025 21:38:00 -0300 Subject: [PATCH 18/99] =?UTF-8?q?=E2=9C=A8feat:=20Add=20Localization=20to?= =?UTF-8?q?=20Vehicle=20data?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Adding Localization feature to Vehicle data --- OneBus.Domain/Enums/Vehicle/FuelType.cs | 2 +- OneBus.Domain/Enums/Vehicle/VehicleType.cs | 6 +-- OneBus.Domain/Resources/Messages.Designer.cs | 54 ++++++++++++++++++++ OneBus.Domain/Resources/Messages.resx | 18 +++++++ 4 files changed, 76 insertions(+), 4 deletions(-) diff --git a/OneBus.Domain/Enums/Vehicle/FuelType.cs b/OneBus.Domain/Enums/Vehicle/FuelType.cs index d78b7b0..08e70ce 100644 --- a/OneBus.Domain/Enums/Vehicle/FuelType.cs +++ b/OneBus.Domain/Enums/Vehicle/FuelType.cs @@ -6,7 +6,7 @@ public enum FuelType : byte Etanol, Diesel, Gas_Natural, - Eletrico, + Elétrico, Outros } } diff --git a/OneBus.Domain/Enums/Vehicle/VehicleType.cs b/OneBus.Domain/Enums/Vehicle/VehicleType.cs index 8628809..ea4f4c8 100644 --- a/OneBus.Domain/Enums/Vehicle/VehicleType.cs +++ b/OneBus.Domain/Enums/Vehicle/VehicleType.cs @@ -2,9 +2,9 @@ { public enum VehicleType : byte { - Onibus, - Micro_Onibus, - Onibus_Articulado, + Ônibus, + Micro_Ônibus, + Ônibus_Articulado, Van, Caminhão, Carro diff --git a/OneBus.Domain/Resources/Messages.Designer.cs b/OneBus.Domain/Resources/Messages.Designer.cs index 8ae2b7b..a821a24 100644 --- a/OneBus.Domain/Resources/Messages.Designer.cs +++ b/OneBus.Domain/Resources/Messages.Designer.cs @@ -132,6 +132,51 @@ internal static string Domingos_Feriados { } } + /// + /// Consulta uma cadeia de caracteres localizada semelhante a Em Manutenção. + /// + internal static string Em_Manutenção { + get { + return ResourceManager.GetString("Em_Manutenção", resourceCulture); + } + } + + /// + /// Consulta uma cadeia de caracteres localizada semelhante a Em Operação. + /// + internal static string Em_Operação { + get { + return ResourceManager.GetString("Em_Operação", resourceCulture); + } + } + + /// + /// Consulta uma cadeia de caracteres localizada semelhante a Gás Natural. + /// + internal static string Gas_Natural { + get { + return ResourceManager.GetString("Gas_Natural", resourceCulture); + } + } + + /// + /// Consulta uma cadeia de caracteres localizada semelhante a Mercedes Benz. + /// + internal static string Mercedes_Benz { + get { + return ResourceManager.GetString("Mercedes_Benz", resourceCulture); + } + } + + /// + /// Consulta uma cadeia de caracteres localizada semelhante a Micro Ônibus. + /// + internal static string Micro_Ônibus { + get { + return ResourceManager.GetString("Micro_Ônibus", resourceCulture); + } + } + /// /// Consulta uma cadeia de caracteres localizada semelhante a Motorista e Cobrador. /// @@ -159,6 +204,15 @@ internal static string O_Positive { } } + /// + /// Consulta uma cadeia de caracteres localizada semelhante a Ônibus Articulado. + /// + internal static string Ônibus_Articulado { + get { + return ResourceManager.GetString("Ônibus_Articulado", resourceCulture); + } + } + /// /// Consulta uma cadeia de caracteres localizada semelhante a Em Processo de Contratação. /// diff --git a/OneBus.Domain/Resources/Messages.resx b/OneBus.Domain/Resources/Messages.resx index 9b21cad..2d13651 100644 --- a/OneBus.Domain/Resources/Messages.resx +++ b/OneBus.Domain/Resources/Messages.resx @@ -141,6 +141,21 @@ Domingos e Feriados + + Em Manutenção + + + Em Operação + + + Gás Natural + + + Mercedes Benz + + + Micro Ônibus + Motorista e Cobrador @@ -153,4 +168,7 @@ Em Processo de Contratação + + Ônibus Articulado + \ No newline at end of file From 628811bea5544fe3689fa0398187e7b2c9a7083e Mon Sep 17 00:00:00 2001 From: Eduardo Rezende Date: Sat, 4 Oct 2025 22:24:35 -0300 Subject: [PATCH 19/99] =?UTF-8?q?=E2=99=BB=EF=B8=8Frefactor:=20Update=20Ve?= =?UTF-8?q?hicle=20DTOs?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Updating fields --- .../DTOs/Vehicle/CreateVehicleDTO.cs | 2 ++ .../DTOs/Vehicle/ReadVehicleDTO.cs | 16 ++++++++++++++++ 2 files changed, 18 insertions(+) diff --git a/OneBus.Application/DTOs/Vehicle/CreateVehicleDTO.cs b/OneBus.Application/DTOs/Vehicle/CreateVehicleDTO.cs index 14c7646..f859441 100644 --- a/OneBus.Application/DTOs/Vehicle/CreateVehicleDTO.cs +++ b/OneBus.Application/DTOs/Vehicle/CreateVehicleDTO.cs @@ -10,6 +10,8 @@ public CreateVehicleDTO() Renavam = string.Empty; } + public byte Type { get; set; } + public string Prefix { get; set; } public byte NumberDoors { get; set; } diff --git a/OneBus.Application/DTOs/Vehicle/ReadVehicleDTO.cs b/OneBus.Application/DTOs/Vehicle/ReadVehicleDTO.cs index c99e462..ac4efb5 100644 --- a/OneBus.Application/DTOs/Vehicle/ReadVehicleDTO.cs +++ b/OneBus.Application/DTOs/Vehicle/ReadVehicleDTO.cs @@ -12,6 +12,8 @@ public ReadVehicleDTO() public byte Type { get; set; } + public string? TypeName { get; set; } + public string Prefix { get; set; } public byte NumberDoors { get; set; } @@ -22,8 +24,12 @@ public ReadVehicleDTO() public byte FuelType { get; set; } + public string? FuelTypeName { get; set; } + public byte Brand { get; set; } + public string? BrandName { get; set; } + public string Model { get; set; } public ushort Year { get; set; } @@ -32,6 +38,8 @@ public ReadVehicleDTO() public byte? Color { get; set; } + public string? ColorName { get; set; } + public string? BodyworkNumber { get; set; } public string? NumberChassis { get; set; } @@ -48,15 +56,23 @@ public ReadVehicleDTO() public byte TransmissionType { get; set; } + public string? TransmissionTypeName { get; set; } + public DateOnly AcquisitionDate { get; set; } public byte Status { get; set; } + public string? StatusName { get; set; } + public byte[]? Image { get; set; } public byte? BusServiceType { get; set; } + public string? BusServiceTypeName { get; set; } + public byte? BusChassisBrand { get; set; } + + public string? BusChassisBrandName { get; set; } public string? BusChassisModel { get; set; } From 9f03716605ee2418acffb51c1c8ec2c06f280ac2 Mon Sep 17 00:00:00 2001 From: Eduardo Rezende Date: Sat, 4 Oct 2025 22:25:20 -0300 Subject: [PATCH 20/99] =?UTF-8?q?=E2=99=BB=EF=B8=8Frefactor:=20Add=20valid?= =?UTF-8?q?ators=20to=20Vehicle?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Adding validators logic to Vehicle Creation and Edition --- .../Vehicle/CreateVehicleDTOValidator.cs | 111 ++++++++++++++++++ .../Vehicle/UpdateVehicleDTOValidator.cs | 109 +++++++++++++++++ 2 files changed, 220 insertions(+) diff --git a/OneBus.Application/Validators/Vehicle/CreateVehicleDTOValidator.cs b/OneBus.Application/Validators/Vehicle/CreateVehicleDTOValidator.cs index 2ff123d..b9b86ab 100644 --- a/OneBus.Application/Validators/Vehicle/CreateVehicleDTOValidator.cs +++ b/OneBus.Application/Validators/Vehicle/CreateVehicleDTOValidator.cs @@ -1,9 +1,120 @@ using FluentValidation; using OneBus.Application.DTOs.Vehicle; +using OneBus.Application.Utils; +using OneBus.Domain.Commons; +using OneBus.Domain.Enums.Vehicle; +using OneBus.Domain.Interfaces.Repositories; namespace OneBus.Application.Validators.Vehicle { public class CreateVehicleDTOValidator : AbstractValidator { + private readonly IVehicleRepository _vehicleRepository; + + public CreateVehicleDTOValidator(IVehicleRepository vehicleRepository) + { + _vehicleRepository = vehicleRepository; + + RuleFor(c => c.Type) + .Must(ValidationUtils.IsValidEnumValue) + .OverridePropertyName("Tipo"); + + RuleFor(c => c.Prefix) + .MustAsync(async (prefix, ct) => !await IsPrefixInUseAsync(prefix, ct)) + .WithMessage(ErrorUtils.AlreadyExists("Prefixo").Message) + .NotEmpty() + .OverridePropertyName("Prefixo"); + + RuleFor(c => c.FuelType) + .Must(ValidationUtils.IsValidEnumValue) + .OverridePropertyName("Tipo de Combustível"); + + RuleFor(c => c.Brand) + .Must(ValidationUtils.IsValidEnumValue) + .OverridePropertyName("Marca"); + + RuleFor(c => c.Model) + .NotEmpty() + .OverridePropertyName("Modelo"); + + RuleFor(c => c.Plate) + .MustAsync(async (plate, ct) => !await IsPlateInUseAsync(plate, ct)) + .WithMessage(ErrorUtils.AlreadyExists("Placa").Message) + .NotEmpty() + .OverridePropertyName("Placa"); + + RuleFor(c => c.Renavam) + .MustAsync(async (renavam, ct) => !await IsRenavamInUseAsync(renavam, ct)) + .When(c => !string.IsNullOrWhiteSpace(c.Renavam)) + .WithMessage(ErrorUtils.AlreadyExists("Renavam").Message) + .OverridePropertyName("Renavam"); + + RuleFor(c => c.NumberChassis) + .MustAsync(async (numberChassis, ct) => !await IsNumberChassisInUseAsync(numberChassis, ct)) + .When(c => !string.IsNullOrWhiteSpace(c.NumberChassis)) + .WithMessage(ErrorUtils.AlreadyExists("Número do Chassi").Message) + .OverridePropertyName("Número do Chassi"); + + RuleFor(c => c.BodyworkNumber) + .MustAsync(async (bodyworkNumber, ct) => !await IsBodyworkNumberInUseAsync(bodyworkNumber, ct)) + .When(c => !string.IsNullOrWhiteSpace(c.BodyworkNumber)) + .WithMessage(ErrorUtils.AlreadyExists("Número da Carroceria").Message) + .OverridePropertyName("Número da Carroceria"); + + RuleFor(c => c.Status) + .Must(ValidationUtils.IsValidEnumValue) + .OverridePropertyName("Status"); + + RuleFor(c => c.BusServiceType) + .Must(ValidationUtils.IsValidEnumValue) + .OverridePropertyName("Tipo de Serviço"); + + RuleFor(c => c.BusChassisBrand) + .Must(ValidationUtils.IsValidEnumValue) + .OverridePropertyName("Marca do Chassi"); + + RuleFor(c => c.BusChassisModel) + .NotEmpty() + .OverridePropertyName("Modelo do Chassi"); + + RuleFor(c => c.Color) + .Must(ValidationUtils.IsValidEnumValue) + .When(c => c.Color != null) + .OverridePropertyName("Cor"); + + RuleFor(c => c.TransmissionType) + .Must(ValidationUtils.IsValidEnumValue) + .OverridePropertyName("Tipo de Transmissão"); + } + + private async Task IsPrefixInUseAsync(string prefix, CancellationToken cancellationToken = default) + { + return await _vehicleRepository.AnyAsync(c => c.Prefix.ToLower().Equals(prefix) && c.Status != (byte)VehicleStatus.Desativado, + cancellationToken: cancellationToken); + } + + private async Task IsPlateInUseAsync(string plate, CancellationToken cancellationToken = default) + { + return await _vehicleRepository.AnyAsync(c => c.Plate.ToLower().Equals(plate), + cancellationToken: cancellationToken); + } + + private async Task IsRenavamInUseAsync(string renavam, CancellationToken cancellationToken = default) + { + return await _vehicleRepository.AnyAsync(c => c.Renavam.ToLower().Equals(renavam), + cancellationToken: cancellationToken); + } + + private async Task IsNumberChassisInUseAsync(string? numberChassis, CancellationToken cancellationToken = default) + { + return await _vehicleRepository.AnyAsync(c => !string.IsNullOrWhiteSpace(c.NumberChassis) && c.NumberChassis.ToLower().Equals(numberChassis), + cancellationToken: cancellationToken); + } + + private async Task IsBodyworkNumberInUseAsync(string? bodyworkNumber, CancellationToken cancellationToken = default) + { + return await _vehicleRepository.AnyAsync(c => !string.IsNullOrWhiteSpace(c.BodyworkNumber) && c.BodyworkNumber.ToLower().Equals(bodyworkNumber), + cancellationToken: cancellationToken); + } } } diff --git a/OneBus.Application/Validators/Vehicle/UpdateVehicleDTOValidator.cs b/OneBus.Application/Validators/Vehicle/UpdateVehicleDTOValidator.cs index 688c066..8f6f573 100644 --- a/OneBus.Application/Validators/Vehicle/UpdateVehicleDTOValidator.cs +++ b/OneBus.Application/Validators/Vehicle/UpdateVehicleDTOValidator.cs @@ -1,9 +1,118 @@ using FluentValidation; using OneBus.Application.DTOs.Vehicle; +using OneBus.Application.Utils; +using OneBus.Domain.Commons; +using OneBus.Domain.Enums.Vehicle; +using OneBus.Domain.Interfaces.Repositories; namespace OneBus.Application.Validators.Vehicle { public class UpdateVehicleDTOValidator : AbstractValidator { + private readonly IVehicleRepository _vehicleRepository; + + public UpdateVehicleDTOValidator(IVehicleRepository vehicleRepository) + { + _vehicleRepository = vehicleRepository; + + RuleFor(c => c.Id).GreaterThan(0); + + RuleFor(c => c.Prefix) + .MustAsync(async (prefix, ct) => !await IsPrefixInUseAsync(prefix, ct)) + .WithMessage(ErrorUtils.AlreadyExists("Prefixo").Message) + .NotEmpty() + .OverridePropertyName("Prefixo"); + + RuleFor(c => c.FuelType) + .Must(ValidationUtils.IsValidEnumValue) + .OverridePropertyName("Tipo de Combustível"); + + RuleFor(c => c.Brand) + .Must(ValidationUtils.IsValidEnumValue) + .OverridePropertyName("Marca"); + + RuleFor(c => c.Model) + .NotEmpty() + .OverridePropertyName("Modelo"); + + RuleFor(c => c.Plate) + .MustAsync(async (plate, ct) => !await IsPlateInUseAsync(plate, ct)) + .WithMessage(ErrorUtils.AlreadyExists("Placa").Message) + .NotEmpty() + .OverridePropertyName("Placa"); + + RuleFor(c => c.Renavam) + .MustAsync(async (renavam, ct) => !await IsRenavamInUseAsync(renavam, ct)) + .When(c => !string.IsNullOrWhiteSpace(c.Renavam)) + .WithMessage(ErrorUtils.AlreadyExists("Renavam").Message) + .OverridePropertyName("Renavam"); + + RuleFor(c => c.NumberChassis) + .MustAsync(async (numberChassis, ct) => !await IsNumberChassisInUseAsync(numberChassis, ct)) + .When(c => !string.IsNullOrWhiteSpace(c.NumberChassis)) + .WithMessage(ErrorUtils.AlreadyExists("Número do Chassi").Message) + .OverridePropertyName("Número do Chassi"); + + RuleFor(c => c.BodyworkNumber) + .MustAsync(async (bodyworkNumber, ct) => !await IsBodyworkNumberInUseAsync(bodyworkNumber, ct)) + .When(c => !string.IsNullOrWhiteSpace(c.BodyworkNumber)) + .WithMessage(ErrorUtils.AlreadyExists("Número da Carroceria").Message) + .OverridePropertyName("Número da Carroceria"); + + RuleFor(c => c.Status) + .Must(ValidationUtils.IsValidEnumValue) + .OverridePropertyName("Status"); + + RuleFor(c => c.BusServiceType) + .Must(ValidationUtils.IsValidEnumValue) + .OverridePropertyName("Tipo de Serviço"); + + RuleFor(c => c.BusChassisBrand) + .Must(ValidationUtils.IsValidEnumValue) + .OverridePropertyName("Marca do Chassi"); + + RuleFor(c => c.BusChassisModel) + .NotEmpty() + .OverridePropertyName("Modelo do Chassi"); + + RuleFor(c => c.Color) + .Must(ValidationUtils.IsValidEnumValue) + .When(c => c.Color != null) + .OverridePropertyName("Cor"); + + RuleFor(c => c.TransmissionType) + .Must(ValidationUtils.IsValidEnumValue) + .OverridePropertyName("Tipo de Transmissão"); + } + + private async Task IsPrefixInUseAsync(string prefix, CancellationToken cancellationToken = default) + { + return await _vehicleRepository.AnyAsync(c => c.Prefix.ToLower().Equals(prefix) && c.Status != (byte)VehicleStatus.Desativado, + cancellationToken: cancellationToken); + } + + private async Task IsPlateInUseAsync(string plate, CancellationToken cancellationToken = default) + { + return await _vehicleRepository.AnyAsync(c => c.Plate.ToLower().Equals(plate), + cancellationToken: cancellationToken); + } + + private async Task IsRenavamInUseAsync(string renavam, CancellationToken cancellationToken = default) + { + return await _vehicleRepository.AnyAsync(c => c.Renavam.ToLower().Equals(renavam), + cancellationToken: cancellationToken); + } + + private async Task IsNumberChassisInUseAsync(string? numberChassis, CancellationToken cancellationToken = default) + { + return await _vehicleRepository.AnyAsync(c => !string.IsNullOrWhiteSpace(c.NumberChassis) && c.NumberChassis.ToLower().Equals(numberChassis), + cancellationToken: cancellationToken); + } + + private async Task IsBodyworkNumberInUseAsync(string? bodyworkNumber, CancellationToken cancellationToken = default) + { + return await _vehicleRepository.AnyAsync(c => !string.IsNullOrWhiteSpace(c.BodyworkNumber) && c.BodyworkNumber.ToLower().Equals(bodyworkNumber), + cancellationToken: cancellationToken); + } } } From 5311170b68204630eb4081e0ff9f9f417bae11e2 Mon Sep 17 00:00:00 2001 From: Eduardo Rezende Date: Sat, 4 Oct 2025 22:26:36 -0300 Subject: [PATCH 21/99] =?UTF-8?q?=E2=99=BB=EF=B8=8Frefactor:=20Add=20valid?= =?UTF-8?q?ators=20Service?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Updating GET methods --- OneBus.Application/Services/VehicleService.cs | 50 +++++++++++++++++++ 1 file changed, 50 insertions(+) diff --git a/OneBus.Application/Services/VehicleService.cs b/OneBus.Application/Services/VehicleService.cs index 9983923..100acc4 100644 --- a/OneBus.Application/Services/VehicleService.cs +++ b/OneBus.Application/Services/VehicleService.cs @@ -1,6 +1,7 @@ using FluentValidation; using OneBus.Application.DTOs.Vehicle; using OneBus.Application.Interfaces.Services; +using OneBus.Domain.Commons; using OneBus.Domain.Commons.Result; using OneBus.Domain.Entities; using OneBus.Domain.Enums.Vehicle; @@ -21,6 +22,55 @@ public VehicleService( { } + public override async Task>> GetPaginedAsync( + BaseFilter filter, + DbQueryOptions? dbQueryOptions = null, + CancellationToken cancellationToken = default) + { + var result = await base.GetPaginedAsync(filter, cancellationToken: cancellationToken); + + if (!result.Sucess) + return result; + + foreach (var vehicle in result.Value!.Items) + { + vehicle.ColorName = ((Color?)vehicle.Color)?.ToString()?.Localize(); + vehicle.TypeName = ((VehicleType)vehicle.Type).ToString().Localize(); + vehicle.BrandName = ((VehicleBrands)vehicle.Brand).ToString().Localize(); + vehicle.FuelTypeName = ((FuelType)vehicle.FuelType).ToString().Localize(); + vehicle.StatusName = ((VehicleStatus)vehicle.Status).ToString().Localize(); + vehicle.TransmissionTypeName = ((VehicleStatus)vehicle.TransmissionType).ToString().Localize(); + vehicle.BusServiceTypeName = ((BusServiceType?)vehicle.BusServiceType)?.ToString()?.Localize(); + vehicle.BusChassisBrandName = ((BusChassisBrands?)vehicle.BusChassisBrand)?.ToString()?.Localize(); + } + + return result; + } + + public override async Task> GetByIdAsync( + long id, + DbQueryOptions? dbQueryOptions = null, + CancellationToken cancellationToken = default) + { + var result = await base.GetByIdAsync(id, cancellationToken: cancellationToken); + + if (!result.Sucess) + return result; + + var vehicle = result.Value!; + + vehicle.ColorName = ((Color?)vehicle.Color)?.ToString()?.Localize(); + vehicle.TypeName = ((VehicleType)vehicle.Type).ToString().Localize(); + vehicle.BrandName = ((VehicleBrands)vehicle.Brand).ToString().Localize(); + vehicle.FuelTypeName = ((FuelType)vehicle.FuelType).ToString().Localize(); + vehicle.StatusName = ((VehicleStatus)vehicle.Status).ToString().Localize(); + vehicle.TransmissionTypeName = ((VehicleStatus)vehicle.TransmissionType).ToString().Localize(); + vehicle.BusServiceTypeName = ((BusServiceType?)vehicle.BusServiceType)?.ToString()?.Localize(); + vehicle.BusChassisBrandName = ((BusChassisBrands?)vehicle.BusChassisBrand)?.ToString()?.Localize(); + + return result; + } + public Result> GetStatus() { var values = Enum.GetValues(); From 44c8a23df170aeb15e35372b1b1c6f70c4256eda Mon Sep 17 00:00:00 2001 From: Eduardo Rezende Date: Sat, 4 Oct 2025 22:33:01 -0300 Subject: [PATCH 22/99] =?UTF-8?q?=E2=9C=A8feat:=20Add=20VehicleFilter?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Adding filter class for Vehicle --- OneBus.Domain/Filters/VehicleFilter.cs | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 OneBus.Domain/Filters/VehicleFilter.cs diff --git a/OneBus.Domain/Filters/VehicleFilter.cs b/OneBus.Domain/Filters/VehicleFilter.cs new file mode 100644 index 0000000..40bb049 --- /dev/null +++ b/OneBus.Domain/Filters/VehicleFilter.cs @@ -0,0 +1,21 @@ +namespace OneBus.Domain.Filters +{ + public class VehicleFilter : BaseFilter + { + public byte? Status { get; set; } + + public byte? Type { get; set; } + + public byte? Brand { get; set; } + + public byte? BusChassisBrand { get; set; } + + public byte? BusServiceType { get; set; } + + public byte? Color { get; set; } + + public byte? FuelType { get; set; } + + public byte? TransmissionType { get; set; } + } +} From 1133e4913f0b154026857126946cc17dc9bd239f Mon Sep 17 00:00:00 2001 From: Eduardo Rezende Date: Sat, 4 Oct 2025 22:34:23 -0300 Subject: [PATCH 23/99] =?UTF-8?q?=E2=99=BB=EF=B8=8Frefactor:=20Update=20Ve?= =?UTF-8?q?hicle=20classes?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Updating VehicleFilter references --- OneBus.API/Controllers/VehicleController.cs | 2 +- OneBus.Application/Interfaces/Services/IVehicleService.cs | 2 +- OneBus.Application/Services/VehicleService.cs | 6 +++--- OneBus.Domain/Interfaces/Repositories/IVehicleRepository.cs | 2 +- OneBus.Infra.Data/Repositories/VehicleRepository.cs | 2 +- 5 files changed, 7 insertions(+), 7 deletions(-) diff --git a/OneBus.API/Controllers/VehicleController.cs b/OneBus.API/Controllers/VehicleController.cs index 8320ff7..fdab4b8 100644 --- a/OneBus.API/Controllers/VehicleController.cs +++ b/OneBus.API/Controllers/VehicleController.cs @@ -101,7 +101,7 @@ public async Task DeleteAsync([FromRoute] long id, CancellationTo /// Veículos 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] VehicleFilter filter, CancellationToken cancellationToken = default) { return (await _vehicleService.GetPaginedAsync(filter, cancellationToken: cancellationToken)).ToActionResult(); } diff --git a/OneBus.Application/Interfaces/Services/IVehicleService.cs b/OneBus.Application/Interfaces/Services/IVehicleService.cs index e992de7..efca8b5 100644 --- a/OneBus.Application/Interfaces/Services/IVehicleService.cs +++ b/OneBus.Application/Interfaces/Services/IVehicleService.cs @@ -6,7 +6,7 @@ namespace OneBus.Application.Interfaces.Services { public interface IVehicleService : - IBaseService + IBaseService { Result> GetBrands(); diff --git a/OneBus.Application/Services/VehicleService.cs b/OneBus.Application/Services/VehicleService.cs index 100acc4..488b009 100644 --- a/OneBus.Application/Services/VehicleService.cs +++ b/OneBus.Application/Services/VehicleService.cs @@ -11,11 +11,11 @@ namespace OneBus.Application.Services { - public class VehicleService : BaseService, + public class VehicleService : BaseService, IVehicleService { public VehicleService( - IBaseRepository baseRepository, + IBaseRepository baseRepository, IValidator createValidator, IValidator updateValidator) : base(baseRepository, createValidator, updateValidator) @@ -23,7 +23,7 @@ public VehicleService( } public override async Task>> GetPaginedAsync( - BaseFilter filter, + VehicleFilter filter, DbQueryOptions? dbQueryOptions = null, CancellationToken cancellationToken = default) { diff --git a/OneBus.Domain/Interfaces/Repositories/IVehicleRepository.cs b/OneBus.Domain/Interfaces/Repositories/IVehicleRepository.cs index c6a593f..3478e52 100644 --- a/OneBus.Domain/Interfaces/Repositories/IVehicleRepository.cs +++ b/OneBus.Domain/Interfaces/Repositories/IVehicleRepository.cs @@ -3,7 +3,7 @@ namespace OneBus.Domain.Interfaces.Repositories { - public interface IVehicleRepository : IBaseRepository + public interface IVehicleRepository : IBaseRepository { } } diff --git a/OneBus.Infra.Data/Repositories/VehicleRepository.cs b/OneBus.Infra.Data/Repositories/VehicleRepository.cs index c825152..aeef8e2 100644 --- a/OneBus.Infra.Data/Repositories/VehicleRepository.cs +++ b/OneBus.Infra.Data/Repositories/VehicleRepository.cs @@ -5,7 +5,7 @@ namespace OneBus.Infra.Data.Repositories { - public class VehicleRepository : BaseRepository, IVehicleRepository + public class VehicleRepository : BaseRepository, IVehicleRepository { public VehicleRepository(OneBusDbContext dbContext) : base(dbContext) { From 1bc90368b9117981560e5882b6d47e0dbfb34e8d Mon Sep 17 00:00:00 2001 From: Eduardo Rezende Date: Sat, 4 Oct 2025 22:46:28 -0300 Subject: [PATCH 24/99] =?UTF-8?q?=E2=99=BB=EF=B8=8Frefactor:=20Update=20Ve?= =?UTF-8?q?hicle=20Repository?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Adding filtering logic --- .../Repositories/VehicleRepository.cs | 25 +++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/OneBus.Infra.Data/Repositories/VehicleRepository.cs b/OneBus.Infra.Data/Repositories/VehicleRepository.cs index aeef8e2..e68aff2 100644 --- a/OneBus.Infra.Data/Repositories/VehicleRepository.cs +++ b/OneBus.Infra.Data/Repositories/VehicleRepository.cs @@ -2,6 +2,7 @@ using OneBus.Domain.Filters; using OneBus.Domain.Interfaces.Repositories; using OneBus.Infra.Data.DbContexts; +using System.Linq.Expressions; namespace OneBus.Infra.Data.Repositories { @@ -10,5 +11,29 @@ public class VehicleRepository : BaseRepository, IVehicl public VehicleRepository(OneBusDbContext dbContext) : base(dbContext) { } + + protected override Expression> ApplyFilter(VehicleFilter filter) + { + var value = filter.Value?.ToLower(); + + return c => + (filter.Type == null || c.Type == filter.Type) && + (filter.Color == null || c.Color == filter.Color) && + (filter.Brand == null || c.Brand == filter.Brand) && + (filter.Status == null || c.Status == filter.Status) && + (filter.FuelType == null || c.FuelType == filter.FuelType) && + (filter.BusServiceType == null || c.BusServiceType == filter.BusServiceType) && + (filter.BusChassisBrand == null || c.BusChassisBrand == filter.BusChassisBrand) && + (filter.TransmissionType == null || c.TransmissionType == filter.TransmissionType) && + (string.IsNullOrWhiteSpace(value) || + ((c.Prefix.ToLower().Contains(value) || + c.Model.ToLower().Contains(value) || + c.Plate.ToLower().Contains(value) || + c.Renavam.ToLower().Contains(value) || + c.NumberChassis!.ToLower().Contains(value) || + c.BodyworkNumber!.ToLower().Contains(value) || + c.BusChassisModel!.ToLower().Contains(value) || + c.EngineNumber!.ToLower().Contains(value)) && value != string.Empty)); + } } } From 59535d0d2d06587a5a369d85b31922b8a28001d4 Mon Sep 17 00:00:00 2001 From: Eduardo Rezende Date: Sat, 4 Oct 2025 22:47:02 -0300 Subject: [PATCH 25/99] =?UTF-8?q?=E2=99=BB=EF=B8=8Frefactor:=20Update=20Ve?= =?UTF-8?q?hicle=20Validators?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Adding validation over EngineNumber field --- .../Vehicle/CreateVehicleDTOValidator.cs | 14 +++++++++++++- .../Vehicle/UpdateVehicleDTOValidator.cs | 12 ++++++++++++ 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/OneBus.Application/Validators/Vehicle/CreateVehicleDTOValidator.cs b/OneBus.Application/Validators/Vehicle/CreateVehicleDTOValidator.cs index b9b86ab..1190f26 100644 --- a/OneBus.Application/Validators/Vehicle/CreateVehicleDTOValidator.cs +++ b/OneBus.Application/Validators/Vehicle/CreateVehicleDTOValidator.cs @@ -61,6 +61,12 @@ public CreateVehicleDTOValidator(IVehicleRepository vehicleRepository) .WithMessage(ErrorUtils.AlreadyExists("Número da Carroceria").Message) .OverridePropertyName("Número da Carroceria"); + RuleFor(c => c.EngineNumber) + .MustAsync(async (engineNumber, ct) => !await IsEngineNumberInUseAsync(engineNumber, ct)) + .When(c => !string.IsNullOrWhiteSpace(c.EngineNumber)) + .WithMessage(ErrorUtils.AlreadyExists("Número do Motor").Message) + .OverridePropertyName("Número do Motor"); + RuleFor(c => c.Status) .Must(ValidationUtils.IsValidEnumValue) .OverridePropertyName("Status"); @@ -83,7 +89,7 @@ public CreateVehicleDTOValidator(IVehicleRepository vehicleRepository) .OverridePropertyName("Cor"); RuleFor(c => c.TransmissionType) - .Must(ValidationUtils.IsValidEnumValue) + .Must(ValidationUtils.IsValidEnumValue) .OverridePropertyName("Tipo de Transmissão"); } @@ -116,5 +122,11 @@ private async Task IsBodyworkNumberInUseAsync(string? bodyworkNumber, Canc return await _vehicleRepository.AnyAsync(c => !string.IsNullOrWhiteSpace(c.BodyworkNumber) && c.BodyworkNumber.ToLower().Equals(bodyworkNumber), cancellationToken: cancellationToken); } + + private async Task IsEngineNumberInUseAsync(string? engineNumber, CancellationToken cancellationToken = default) + { + return await _vehicleRepository.AnyAsync(c => !string.IsNullOrWhiteSpace(c.EngineNumber) && c.EngineNumber.ToLower().Equals(engineNumber), + cancellationToken: cancellationToken); + } } } diff --git a/OneBus.Application/Validators/Vehicle/UpdateVehicleDTOValidator.cs b/OneBus.Application/Validators/Vehicle/UpdateVehicleDTOValidator.cs index 8f6f573..5efcbc4 100644 --- a/OneBus.Application/Validators/Vehicle/UpdateVehicleDTOValidator.cs +++ b/OneBus.Application/Validators/Vehicle/UpdateVehicleDTOValidator.cs @@ -59,6 +59,12 @@ public UpdateVehicleDTOValidator(IVehicleRepository vehicleRepository) .WithMessage(ErrorUtils.AlreadyExists("Número da Carroceria").Message) .OverridePropertyName("Número da Carroceria"); + RuleFor(c => c.EngineNumber) + .MustAsync(async (engineNumber, ct) => !await IsEngineNumberInUseAsync(engineNumber, ct)) + .When(c => !string.IsNullOrWhiteSpace(c.EngineNumber)) + .WithMessage(ErrorUtils.AlreadyExists("Número do Motor").Message) + .OverridePropertyName("Número do Motor"); + RuleFor(c => c.Status) .Must(ValidationUtils.IsValidEnumValue) .OverridePropertyName("Status"); @@ -114,5 +120,11 @@ private async Task IsBodyworkNumberInUseAsync(string? bodyworkNumber, Canc return await _vehicleRepository.AnyAsync(c => !string.IsNullOrWhiteSpace(c.BodyworkNumber) && c.BodyworkNumber.ToLower().Equals(bodyworkNumber), cancellationToken: cancellationToken); } + + private async Task IsEngineNumberInUseAsync(string? engineNumber, CancellationToken cancellationToken = default) + { + return await _vehicleRepository.AnyAsync(c => !string.IsNullOrWhiteSpace(c.EngineNumber) && c.EngineNumber.ToLower().Equals(engineNumber), + cancellationToken: cancellationToken); + } } } From 7ee72f4daf977efda010893c950e89155a6e9230 Mon Sep 17 00:00:00 2001 From: Eduardo Rezende Date: Sat, 4 Oct 2025 23:15:34 -0300 Subject: [PATCH 26/99] =?UTF-8?q?=E2=99=BB=EF=B8=8Frefactor:=20Update=20Ve?= =?UTF-8?q?hicle=20field?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Adding Licensing field --- OneBus.Domain/Entities/Vehicle.cs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/OneBus.Domain/Entities/Vehicle.cs b/OneBus.Domain/Entities/Vehicle.cs index 3573fd7..9ae8132 100644 --- a/OneBus.Domain/Entities/Vehicle.cs +++ b/OneBus.Domain/Entities/Vehicle.cs @@ -8,6 +8,7 @@ public Vehicle() Model = string.Empty; Plate = string.Empty; Renavam = string.Empty; + Licensing = string.Empty; } public byte Type { get; set; } @@ -42,7 +43,7 @@ public Vehicle() public DateOnly IpvaExpiration { get; set; } - public DateOnly LicensingExpiration { get; set; } + public string Licensing { get; set; } public string Renavam { get; set; } From 56cadc1f7c067c1c5e3482ac423876cb1d554c79 Mon Sep 17 00:00:00 2001 From: Eduardo Rezende Date: Sat, 4 Oct 2025 23:15:59 -0300 Subject: [PATCH 27/99] =?UTF-8?q?=E2=99=BB=EF=B8=8Frefactor:=20Update=20Ve?= =?UTF-8?q?hicle=20Mapping?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Mapping Licensing field --- OneBus.Infra.Data/Mappings/VehicleMapping.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/OneBus.Infra.Data/Mappings/VehicleMapping.cs b/OneBus.Infra.Data/Mappings/VehicleMapping.cs index 007b5cf..3b8d555 100644 --- a/OneBus.Infra.Data/Mappings/VehicleMapping.cs +++ b/OneBus.Infra.Data/Mappings/VehicleMapping.cs @@ -13,6 +13,7 @@ public override void Configure(EntityTypeBuilder builder) builder.Property(c => c.Plate).HasMaxLength(20); builder.Property(c => c.Model).HasMaxLength(50); builder.Property(c => c.Prefix).HasMaxLength(30); + builder.Property(c => c.Licensing).HasMaxLength(50); builder.Property(c => c.EngineNumber).HasMaxLength(20); builder.Property(c => c.NumberChassis).HasMaxLength(20); builder.Property(c => c.BodyworkNumber).HasMaxLength(20); From ebb1b072eeac1ad07a2a9b53c5958d19b46133bf Mon Sep 17 00:00:00 2001 From: Eduardo Rezende Date: Sat, 4 Oct 2025 23:16:37 -0300 Subject: [PATCH 28/99] =?UTF-8?q?=E2=9C=A8feat:=20Add=20Migration?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Adding Licensing field into Vehicle table --- ...51005021356_UpdateVehicleField.Designer.cs | 592 ++++++++++++++++++ .../20251005021356_UpdateVehicleField.cs | 43 ++ .../OneBusDbContextModelSnapshot.cs | 7 +- 3 files changed, 640 insertions(+), 2 deletions(-) create mode 100644 OneBus.Infra.Data/Migrations/20251005021356_UpdateVehicleField.Designer.cs create mode 100644 OneBus.Infra.Data/Migrations/20251005021356_UpdateVehicleField.cs diff --git a/OneBus.Infra.Data/Migrations/20251005021356_UpdateVehicleField.Designer.cs b/OneBus.Infra.Data/Migrations/20251005021356_UpdateVehicleField.Designer.cs new file mode 100644 index 0000000..8041e4a --- /dev/null +++ b/OneBus.Infra.Data/Migrations/20251005021356_UpdateVehicleField.Designer.cs @@ -0,0 +1,592 @@ +// +using System; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; +using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; +using OneBus.Infra.Data.DbContexts; + +#nullable disable + +namespace OneBus.Infra.Data.Migrations +{ + [DbContext(typeof(OneBusDbContext))] + [Migration("20251005021356_UpdateVehicleField")] + partial class UpdateVehicleField + { + /// + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("ProductVersion", "9.0.9") + .HasAnnotation("Relational:MaxIdentifierLength", 63); + + NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder); + + modelBuilder.Entity("OneBus.Domain.Entities.Employee", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("bigint"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("BloodType") + .HasColumnType("smallint"); + + b.Property("CnhCategory") + .HasColumnType("smallint"); + + b.Property("CnhExpiration") + .HasColumnType("date"); + + b.Property("CnhNumber") + .HasMaxLength(20) + .IsUnicode(false) + .HasColumnType("character varying(20)"); + + b.Property("Code") + .IsRequired() + .HasMaxLength(30) + .IsUnicode(false) + .HasColumnType("character varying(30)"); + + b.Property("Cpf") + .IsRequired() + .HasMaxLength(20) + .IsUnicode(false) + .HasColumnType("character varying(20)"); + + b.Property("CreatedAt") + .HasColumnType("timestamp with time zone"); + + b.Property("Email") + .IsRequired() + .HasMaxLength(80) + .IsUnicode(false) + .HasColumnType("character varying(80)"); + + b.Property("HiringDate") + .HasColumnType("date"); + + b.Property("Image") + .HasColumnType("bytea"); + + b.Property("IsDeleted") + .HasColumnType("boolean"); + + b.Property("Name") + .IsRequired() + .HasMaxLength(80) + .IsUnicode(false) + .HasColumnType("character varying(80)"); + + b.Property("Phone") + .IsRequired() + .HasMaxLength(20) + .IsUnicode(false) + .HasColumnType("character varying(20)"); + + b.Property("Rg") + .IsRequired() + .HasMaxLength(20) + .IsUnicode(false) + .HasColumnType("character varying(20)"); + + b.Property("Role") + .HasColumnType("smallint"); + + b.Property("Status") + .HasColumnType("smallint"); + + b.HasKey("Id"); + + b.HasIndex("CnhNumber"); + + b.HasIndex("Code"); + + b.HasIndex("Cpf"); + + b.ToTable("Employee"); + }); + + modelBuilder.Entity("OneBus.Domain.Entities.EmployeeWorkday", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("bigint"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("CreatedAt") + .HasColumnType("timestamp with time zone"); + + b.Property("DayType") + .HasColumnType("smallint"); + + b.Property("EmployeeId") + .HasColumnType("bigint"); + + b.Property("EndTime") + .HasColumnType("time without time zone"); + + b.Property("IsDeleted") + .HasColumnType("boolean"); + + b.Property("StartTime") + .HasColumnType("time without time zone"); + + b.HasKey("Id"); + + b.HasIndex("EmployeeId"); + + b.ToTable("EmployeeWorkday"); + }); + + modelBuilder.Entity("OneBus.Domain.Entities.Line", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("bigint"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("CreatedAt") + .HasColumnType("timestamp with time zone"); + + b.Property("IsDeleted") + .HasColumnType("boolean"); + + b.Property("MaxNumberBuses") + .HasColumnType("smallint"); + + b.Property("Mileage") + .HasPrecision(19, 4) + .HasColumnType("numeric(19,4)"); + + b.Property("MinNumberBuses") + .HasColumnType("smallint"); + + b.Property("Name") + .IsRequired() + .HasMaxLength(80) + .IsUnicode(false) + .HasColumnType("character varying(80)"); + + b.Property("Number") + .IsRequired() + .HasMaxLength(20) + .IsUnicode(false) + .HasColumnType("character varying(20)"); + + b.Property("TravelTime") + .HasColumnType("time without time zone"); + + b.Property("Type") + .HasColumnType("smallint"); + + b.HasKey("Id"); + + b.ToTable("Line"); + }); + + modelBuilder.Entity("OneBus.Domain.Entities.LineTime", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("bigint"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("CreatedAt") + .HasColumnType("timestamp with time zone"); + + b.Property("DayType") + .HasColumnType("smallint"); + + b.Property("EndTime") + .HasColumnType("time without time zone"); + + b.Property("IsDeleted") + .HasColumnType("boolean"); + + b.Property("LineId") + .HasColumnType("bigint"); + + b.Property("StartTime") + .HasColumnType("time without time zone"); + + b.HasKey("Id"); + + b.HasIndex("LineId"); + + b.ToTable("LineTime"); + }); + + modelBuilder.Entity("OneBus.Domain.Entities.Maintenance", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("bigint"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("Cost") + .HasPrecision(19, 4) + .HasColumnType("numeric(19,4)"); + + b.Property("CreatedAt") + .HasColumnType("timestamp with time zone"); + + b.Property("Description") + .IsRequired() + .HasMaxLength(150) + .IsUnicode(false) + .HasColumnType("character varying(150)"); + + b.Property("EndDate") + .HasColumnType("date"); + + b.Property("IsDeleted") + .HasColumnType("boolean"); + + b.Property("Sector") + .HasColumnType("smallint"); + + b.Property("StartDate") + .HasColumnType("date"); + + b.Property("SurveyExpiration") + .HasColumnType("date"); + + b.Property("VehicleId") + .HasColumnType("bigint"); + + b.HasKey("Id"); + + b.HasIndex("VehicleId"); + + b.ToTable("Maintenance"); + }); + + modelBuilder.Entity("OneBus.Domain.Entities.User", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("bigint"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("CreatedAt") + .HasColumnType("timestamp with time zone"); + + b.Property("Email") + .IsRequired() + .HasMaxLength(80) + .IsUnicode(false) + .HasColumnType("character varying(80)"); + + b.Property("IsDeleted") + .HasColumnType("boolean"); + + b.Property("Name") + .IsRequired() + .HasMaxLength(80) + .IsUnicode(false) + .HasColumnType("character varying(80)"); + + b.Property("Password") + .IsRequired() + .HasMaxLength(50) + .IsUnicode(false) + .HasColumnType("character varying(50)"); + + b.Property("Salt") + .IsRequired() + .HasMaxLength(32) + .IsUnicode(false) + .HasColumnType("character varying(32)"); + + b.HasKey("Id"); + + b.ToTable("User"); + + b.HasData( + new + { + Id = 1L, + CreatedAt = new DateTime(2025, 8, 25, 0, 0, 0, 0, DateTimeKind.Utc), + Email = "onebus@admin", + IsDeleted = false, + Name = "Administrador", + Password = "YRT66Z4XEJ2SSNaJVDIXQW7uvC8LSvOxDU1sH/Sr/ic=", + Salt = "c37b6028194d489192aac9391801594a" + }); + }); + + modelBuilder.Entity("OneBus.Domain.Entities.Vehicle", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("bigint"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("AcquisitionDate") + .HasColumnType("date"); + + b.Property("AxesNumber") + .HasColumnType("smallint"); + + b.Property("BodyworkNumber") + .HasMaxLength(20) + .IsUnicode(false) + .HasColumnType("character varying(20)"); + + b.Property("Brand") + .HasColumnType("smallint"); + + b.Property("BusChassisBrand") + .HasColumnType("smallint"); + + b.Property("BusChassisModel") + .HasMaxLength(50) + .IsUnicode(false) + .HasColumnType("character varying(50)"); + + b.Property("BusChassisYear") + .HasColumnType("smallint"); + + b.Property("BusFumigateExpiration") + .HasColumnType("date"); + + b.Property("BusHasLeftDoors") + .HasColumnType("boolean"); + + b.Property("BusHasLowFloor") + .HasColumnType("boolean"); + + b.Property("BusInsuranceExpiration") + .HasColumnType("date"); + + b.Property("BusServiceType") + .HasColumnType("smallint"); + + b.Property("Color") + .HasColumnType("smallint"); + + b.Property("CreatedAt") + .HasColumnType("timestamp with time zone"); + + b.Property("EngineNumber") + .HasMaxLength(20) + .IsUnicode(false) + .HasColumnType("character varying(20)"); + + b.Property("FuelType") + .HasColumnType("smallint"); + + b.Property("HasAccessibility") + .HasColumnType("boolean"); + + b.Property("Image") + .HasColumnType("bytea"); + + b.Property("IpvaExpiration") + .HasColumnType("date"); + + b.Property("IsDeleted") + .HasColumnType("boolean"); + + b.Property("Licensing") + .IsRequired() + .HasMaxLength(50) + .IsUnicode(false) + .HasColumnType("character varying(50)"); + + b.Property("Model") + .IsRequired() + .HasMaxLength(50) + .IsUnicode(false) + .HasColumnType("character varying(50)"); + + b.Property("NumberChassis") + .HasMaxLength(20) + .IsUnicode(false) + .HasColumnType("character varying(20)"); + + b.Property("NumberDoors") + .HasColumnType("smallint"); + + b.Property("NumberSeats") + .HasColumnType("smallint"); + + b.Property("Plate") + .IsRequired() + .HasMaxLength(20) + .IsUnicode(false) + .HasColumnType("character varying(20)"); + + b.Property("Prefix") + .IsRequired() + .HasMaxLength(30) + .IsUnicode(false) + .HasColumnType("character varying(30)"); + + b.Property("Renavam") + .IsRequired() + .HasMaxLength(20) + .IsUnicode(false) + .HasColumnType("character varying(20)"); + + b.Property("Status") + .HasColumnType("smallint"); + + b.Property("TransmissionType") + .HasColumnType("smallint"); + + b.Property("Type") + .HasColumnType("smallint"); + + b.Property("Year") + .HasColumnType("integer"); + + b.HasKey("Id"); + + b.HasIndex("Plate"); + + b.HasIndex("Prefix"); + + b.HasIndex("Renavam"); + + b.ToTable("Vehicle"); + }); + + modelBuilder.Entity("OneBus.Domain.Entities.VehicleOperation", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("bigint"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("CreatedAt") + .HasColumnType("timestamp with time zone"); + + b.Property("Date") + .HasColumnType("date"); + + b.Property("EmployeeWorkdayId") + .HasColumnType("bigint"); + + b.Property("IsDeleted") + .HasColumnType("boolean"); + + b.Property("LineTimeId") + .HasColumnType("bigint"); + + b.Property("VehicleId") + .HasColumnType("bigint"); + + b.HasKey("Id"); + + b.HasIndex("EmployeeWorkdayId"); + + b.HasIndex("LineTimeId"); + + b.HasIndex("VehicleId"); + + b.ToTable("VehicleOperation"); + }); + + modelBuilder.Entity("OneBus.Domain.Entities.EmployeeWorkday", b => + { + b.HasOne("OneBus.Domain.Entities.Employee", "Employee") + .WithMany("EmployeeWorkdays") + .HasForeignKey("EmployeeId") + .OnDelete(DeleteBehavior.Restrict) + .IsRequired(); + + b.Navigation("Employee"); + }); + + modelBuilder.Entity("OneBus.Domain.Entities.LineTime", b => + { + b.HasOne("OneBus.Domain.Entities.Line", "Line") + .WithMany("LineTimes") + .HasForeignKey("LineId") + .OnDelete(DeleteBehavior.Restrict) + .IsRequired(); + + b.Navigation("Line"); + }); + + modelBuilder.Entity("OneBus.Domain.Entities.Maintenance", b => + { + b.HasOne("OneBus.Domain.Entities.Vehicle", "Vehicle") + .WithMany("Maintenances") + .HasForeignKey("VehicleId") + .OnDelete(DeleteBehavior.Restrict) + .IsRequired(); + + b.Navigation("Vehicle"); + }); + + modelBuilder.Entity("OneBus.Domain.Entities.VehicleOperation", b => + { + b.HasOne("OneBus.Domain.Entities.EmployeeWorkday", "EmployeeWorkday") + .WithMany("VehicleOperations") + .HasForeignKey("EmployeeWorkdayId") + .OnDelete(DeleteBehavior.Restrict) + .IsRequired(); + + b.HasOne("OneBus.Domain.Entities.LineTime", "LineTime") + .WithMany("VehicleOperations") + .HasForeignKey("LineTimeId") + .OnDelete(DeleteBehavior.Restrict); + + b.HasOne("OneBus.Domain.Entities.Vehicle", "Vehicle") + .WithMany("VehicleOperations") + .HasForeignKey("VehicleId") + .OnDelete(DeleteBehavior.Restrict) + .IsRequired(); + + b.Navigation("EmployeeWorkday"); + + b.Navigation("LineTime"); + + b.Navigation("Vehicle"); + }); + + modelBuilder.Entity("OneBus.Domain.Entities.Employee", b => + { + b.Navigation("EmployeeWorkdays"); + }); + + modelBuilder.Entity("OneBus.Domain.Entities.EmployeeWorkday", b => + { + b.Navigation("VehicleOperations"); + }); + + modelBuilder.Entity("OneBus.Domain.Entities.Line", b => + { + b.Navigation("LineTimes"); + }); + + modelBuilder.Entity("OneBus.Domain.Entities.LineTime", b => + { + b.Navigation("VehicleOperations"); + }); + + modelBuilder.Entity("OneBus.Domain.Entities.Vehicle", b => + { + b.Navigation("Maintenances"); + + b.Navigation("VehicleOperations"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/OneBus.Infra.Data/Migrations/20251005021356_UpdateVehicleField.cs b/OneBus.Infra.Data/Migrations/20251005021356_UpdateVehicleField.cs new file mode 100644 index 0000000..5072a1d --- /dev/null +++ b/OneBus.Infra.Data/Migrations/20251005021356_UpdateVehicleField.cs @@ -0,0 +1,43 @@ +using System; +using Microsoft.EntityFrameworkCore.Migrations; + +#nullable disable + +namespace OneBus.Infra.Data.Migrations +{ + /// + public partial class UpdateVehicleField : Migration + { + /// + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropColumn( + name: "LicensingExpiration", + table: "Vehicle"); + + migrationBuilder.AddColumn( + name: "Licensing", + table: "Vehicle", + type: "character varying(50)", + unicode: false, + maxLength: 50, + nullable: false, + defaultValue: ""); + } + + /// + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropColumn( + name: "Licensing", + table: "Vehicle"); + + migrationBuilder.AddColumn( + name: "LicensingExpiration", + table: "Vehicle", + type: "date", + nullable: false, + defaultValue: new DateOnly(1, 1, 1)); + } + } +} diff --git a/OneBus.Infra.Data/Migrations/OneBusDbContextModelSnapshot.cs b/OneBus.Infra.Data/Migrations/OneBusDbContextModelSnapshot.cs index 541d643..a1200e6 100644 --- a/OneBus.Infra.Data/Migrations/OneBusDbContextModelSnapshot.cs +++ b/OneBus.Infra.Data/Migrations/OneBusDbContextModelSnapshot.cs @@ -397,8 +397,11 @@ protected override void BuildModel(ModelBuilder modelBuilder) b.Property("IsDeleted") .HasColumnType("boolean"); - b.Property("LicensingExpiration") - .HasColumnType("date"); + b.Property("Licensing") + .IsRequired() + .HasMaxLength(50) + .IsUnicode(false) + .HasColumnType("character varying(50)"); b.Property("Model") .IsRequired() From f1e97a8c6f29aacbce8a1412e6fa4b80d217557e Mon Sep 17 00:00:00 2001 From: Eduardo Rezende Date: Sat, 4 Oct 2025 23:17:03 -0300 Subject: [PATCH 29/99] =?UTF-8?q?=E2=99=BB=EF=B8=8Frefactor:=20Update=20Ve?= =?UTF-8?q?hicle=20Repository?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Adding Licensing field to filtering logic --- OneBus.Infra.Data/Repositories/VehicleRepository.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/OneBus.Infra.Data/Repositories/VehicleRepository.cs b/OneBus.Infra.Data/Repositories/VehicleRepository.cs index e68aff2..4c74d8f 100644 --- a/OneBus.Infra.Data/Repositories/VehicleRepository.cs +++ b/OneBus.Infra.Data/Repositories/VehicleRepository.cs @@ -30,6 +30,7 @@ protected override Expression> ApplyFilter(VehicleFilter fil c.Model.ToLower().Contains(value) || c.Plate.ToLower().Contains(value) || c.Renavam.ToLower().Contains(value) || + c.Licensing!.ToLower().Contains(value) || c.NumberChassis!.ToLower().Contains(value) || c.BodyworkNumber!.ToLower().Contains(value) || c.BusChassisModel!.ToLower().Contains(value) || From 030e7080f0e2b6f5e9bea9588a93c8c51a0142e8 Mon Sep 17 00:00:00 2001 From: Eduardo Rezende Date: Sat, 4 Oct 2025 23:17:23 -0300 Subject: [PATCH 30/99] =?UTF-8?q?=E2=99=BB=EF=B8=8Frefactor:=20Update=20Ve?= =?UTF-8?q?hicle=20DTOs?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Adding Licensing field --- OneBus.Application/DTOs/Vehicle/CreateVehicleDTO.cs | 3 ++- OneBus.Application/DTOs/Vehicle/ReadVehicleDTO.cs | 3 ++- OneBus.Application/DTOs/Vehicle/UpdateVehicleDTO.cs | 3 ++- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/OneBus.Application/DTOs/Vehicle/CreateVehicleDTO.cs b/OneBus.Application/DTOs/Vehicle/CreateVehicleDTO.cs index f859441..5e26783 100644 --- a/OneBus.Application/DTOs/Vehicle/CreateVehicleDTO.cs +++ b/OneBus.Application/DTOs/Vehicle/CreateVehicleDTO.cs @@ -8,6 +8,7 @@ public CreateVehicleDTO() Model = string.Empty; Plate = string.Empty; Renavam = string.Empty; + Licensing = string.Empty; } public byte Type { get; set; } @@ -42,7 +43,7 @@ public CreateVehicleDTO() public DateOnly IpvaExpiration { get; set; } - public DateOnly LicensingExpiration { get; set; } + public string Licensing { get; set; } public string Renavam { get; set; } diff --git a/OneBus.Application/DTOs/Vehicle/ReadVehicleDTO.cs b/OneBus.Application/DTOs/Vehicle/ReadVehicleDTO.cs index ac4efb5..7f97eba 100644 --- a/OneBus.Application/DTOs/Vehicle/ReadVehicleDTO.cs +++ b/OneBus.Application/DTOs/Vehicle/ReadVehicleDTO.cs @@ -8,6 +8,7 @@ public ReadVehicleDTO() Model = string.Empty; Plate = string.Empty; Renavam = string.Empty; + Licensing = string.Empty; } public byte Type { get; set; } @@ -50,7 +51,7 @@ public ReadVehicleDTO() public DateOnly IpvaExpiration { get; set; } - public DateOnly LicensingExpiration { get; set; } + public string Licensing { get; set; } public string Renavam { get; set; } diff --git a/OneBus.Application/DTOs/Vehicle/UpdateVehicleDTO.cs b/OneBus.Application/DTOs/Vehicle/UpdateVehicleDTO.cs index 7825963..182d8d5 100644 --- a/OneBus.Application/DTOs/Vehicle/UpdateVehicleDTO.cs +++ b/OneBus.Application/DTOs/Vehicle/UpdateVehicleDTO.cs @@ -8,6 +8,7 @@ public UpdateVehicleDTO() Model = string.Empty; Plate = string.Empty; Renavam = string.Empty; + Licensing = string.Empty; } public string Prefix { get; set; } @@ -40,7 +41,7 @@ public UpdateVehicleDTO() public DateOnly IpvaExpiration { get; set; } - public DateOnly LicensingExpiration { get; set; } + public string Licensing { get; set; } public string Renavam { get; set; } From 8f7447cacbc3bbedb1a8ce900e270a348437ca5d Mon Sep 17 00:00:00 2001 From: Eduardo Rezende Date: Sat, 4 Oct 2025 23:17:50 -0300 Subject: [PATCH 31/99] =?UTF-8?q?=E2=99=BB=EF=B8=8Frefactor:=20Update=20Ve?= =?UTF-8?q?hicle=20Service?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Updating UpdateFields method --- OneBus.Application/Services/VehicleService.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/OneBus.Application/Services/VehicleService.cs b/OneBus.Application/Services/VehicleService.cs index 488b009..ab0faed 100644 --- a/OneBus.Application/Services/VehicleService.cs +++ b/OneBus.Application/Services/VehicleService.cs @@ -195,6 +195,7 @@ protected override void UpdateFields(Vehicle entity, UpdateVehicleDTO updateDTO) entity.Status = updateDTO.Status; entity.Renavam = updateDTO.Renavam; entity.FuelType = updateDTO.FuelType; + entity.Licensing = updateDTO.Licensing; entity.AxesNumber = updateDTO.AxesNumber; entity.NumberDoors = updateDTO.NumberDoors; entity.NumberSeats = updateDTO.NumberSeats; @@ -211,7 +212,6 @@ protected override void UpdateFields(Vehicle entity, UpdateVehicleDTO updateDTO) entity.BusHasLeftDoors = updateDTO.BusHasLeftDoors; entity.HasAccessibility = updateDTO.HasAccessibility; entity.TransmissionType = updateDTO.TransmissionType; - entity.LicensingExpiration = updateDTO.LicensingExpiration; entity.BusFumigateExpiration = updateDTO.BusFumigateExpiration; entity.BusInsuranceExpiration = updateDTO.BusInsuranceExpiration; } From 2531d4844d596d44810dcb2cdff6342bdbe0e94d Mon Sep 17 00:00:00 2001 From: Eduardo Rezende Date: Sat, 4 Oct 2025 23:18:15 -0300 Subject: [PATCH 32/99] =?UTF-8?q?=E2=99=BB=EF=B8=8Frefactor:=20Update=20Ve?= =?UTF-8?q?hicle=20Validators?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Improving validations over fields --- .../Vehicle/CreateVehicleDTOValidator.cs | 40 ++++++++-- .../Vehicle/UpdateVehicleDTOValidator.cs | 79 +++++++++++++------ 2 files changed, 85 insertions(+), 34 deletions(-) diff --git a/OneBus.Application/Validators/Vehicle/CreateVehicleDTOValidator.cs b/OneBus.Application/Validators/Vehicle/CreateVehicleDTOValidator.cs index 1190f26..94fb496 100644 --- a/OneBus.Application/Validators/Vehicle/CreateVehicleDTOValidator.cs +++ b/OneBus.Application/Validators/Vehicle/CreateVehicleDTOValidator.cs @@ -37,6 +37,10 @@ public CreateVehicleDTOValidator(IVehicleRepository vehicleRepository) .NotEmpty() .OverridePropertyName("Modelo"); + RuleFor(c => c.Licensing) + .NotEmpty() + .OverridePropertyName("Licenciamento"); + RuleFor(c => c.Plate) .MustAsync(async (plate, ct) => !await IsPlateInUseAsync(plate, ct)) .WithMessage(ErrorUtils.AlreadyExists("Placa").Message) @@ -71,6 +75,15 @@ public CreateVehicleDTOValidator(IVehicleRepository vehicleRepository) .Must(ValidationUtils.IsValidEnumValue) .OverridePropertyName("Status"); + RuleFor(c => c.Color) + .Must(ValidationUtils.IsValidEnumValue) + .When(c => c.Color != null) + .OverridePropertyName("Cor"); + + RuleFor(c => c.TransmissionType) + .Must(ValidationUtils.IsValidEnumValue) + .OverridePropertyName("Tipo de Transmissão"); + RuleFor(c => c.BusServiceType) .Must(ValidationUtils.IsValidEnumValue) .OverridePropertyName("Tipo de Serviço"); @@ -83,14 +96,25 @@ public CreateVehicleDTOValidator(IVehicleRepository vehicleRepository) .NotEmpty() .OverridePropertyName("Modelo do Chassi"); - RuleFor(c => c.Color) - .Must(ValidationUtils.IsValidEnumValue) - .When(c => c.Color != null) - .OverridePropertyName("Cor"); - - RuleFor(c => c.TransmissionType) - .Must(ValidationUtils.IsValidEnumValue) - .OverridePropertyName("Tipo de Transmissão"); + RuleFor(c => c.BusChassisYear) + .NotNull() + .When(c => c.BusChassisYear != null) + .OverridePropertyName("Ano do Chassi"); + + RuleFor(c => c.BusHasLowFloor) + .NotNull() + .When(c => c.BusHasLowFloor != null) + .OverridePropertyName("Possui Piso Baixo"); + + RuleFor(c => c.BusHasLeftDoors) + .NotNull() + .When(c => c.BusHasLeftDoors != null) + .OverridePropertyName("Possui Portas a Esquerda"); + + RuleFor(c => c.BusInsuranceExpiration) + .NotNull() + .When(c => c.BusInsuranceExpiration != null) + .OverridePropertyName("Vencimento do Seguro"); } private async Task IsPrefixInUseAsync(string prefix, CancellationToken cancellationToken = default) diff --git a/OneBus.Application/Validators/Vehicle/UpdateVehicleDTOValidator.cs b/OneBus.Application/Validators/Vehicle/UpdateVehicleDTOValidator.cs index 5efcbc4..bfd3e88 100644 --- a/OneBus.Application/Validators/Vehicle/UpdateVehicleDTOValidator.cs +++ b/OneBus.Application/Validators/Vehicle/UpdateVehicleDTOValidator.cs @@ -18,7 +18,7 @@ public UpdateVehicleDTOValidator(IVehicleRepository vehicleRepository) RuleFor(c => c.Id).GreaterThan(0); RuleFor(c => c.Prefix) - .MustAsync(async (prefix, ct) => !await IsPrefixInUseAsync(prefix, ct)) + .MustAsync(async (vehicle, prefix, ct) => !await IsPrefixInUseAsync(vehicle.Id, prefix, ct)) .WithMessage(ErrorUtils.AlreadyExists("Prefixo").Message) .NotEmpty() .OverridePropertyName("Prefixo"); @@ -35,32 +35,36 @@ public UpdateVehicleDTOValidator(IVehicleRepository vehicleRepository) .NotEmpty() .OverridePropertyName("Modelo"); + RuleFor(c => c.Licensing) + .NotEmpty() + .OverridePropertyName("Licenciamento"); + RuleFor(c => c.Plate) - .MustAsync(async (plate, ct) => !await IsPlateInUseAsync(plate, ct)) + .MustAsync(async (vehicle, plate, ct) => !await IsPlateInUseAsync(vehicle.Id, plate, ct)) .WithMessage(ErrorUtils.AlreadyExists("Placa").Message) .NotEmpty() .OverridePropertyName("Placa"); RuleFor(c => c.Renavam) - .MustAsync(async (renavam, ct) => !await IsRenavamInUseAsync(renavam, ct)) + .MustAsync(async (vehicle, renavam, ct) => !await IsRenavamInUseAsync(vehicle.Id, renavam, ct)) .When(c => !string.IsNullOrWhiteSpace(c.Renavam)) .WithMessage(ErrorUtils.AlreadyExists("Renavam").Message) .OverridePropertyName("Renavam"); RuleFor(c => c.NumberChassis) - .MustAsync(async (numberChassis, ct) => !await IsNumberChassisInUseAsync(numberChassis, ct)) + .MustAsync(async (vehicle, numberChassis, ct) => !await IsNumberChassisInUseAsync(vehicle.Id, numberChassis, ct)) .When(c => !string.IsNullOrWhiteSpace(c.NumberChassis)) .WithMessage(ErrorUtils.AlreadyExists("Número do Chassi").Message) .OverridePropertyName("Número do Chassi"); RuleFor(c => c.BodyworkNumber) - .MustAsync(async (bodyworkNumber, ct) => !await IsBodyworkNumberInUseAsync(bodyworkNumber, ct)) + .MustAsync(async (vehicle, bodyworkNumber, ct) => !await IsBodyworkNumberInUseAsync(vehicle.Id, bodyworkNumber, ct)) .When(c => !string.IsNullOrWhiteSpace(c.BodyworkNumber)) .WithMessage(ErrorUtils.AlreadyExists("Número da Carroceria").Message) .OverridePropertyName("Número da Carroceria"); RuleFor(c => c.EngineNumber) - .MustAsync(async (engineNumber, ct) => !await IsEngineNumberInUseAsync(engineNumber, ct)) + .MustAsync(async (vehicle, engineNumber, ct) => !await IsEngineNumberInUseAsync(vehicle.Id, engineNumber, ct)) .When(c => !string.IsNullOrWhiteSpace(c.EngineNumber)) .WithMessage(ErrorUtils.AlreadyExists("Número do Motor").Message) .OverridePropertyName("Número do Motor"); @@ -69,61 +73,84 @@ public UpdateVehicleDTOValidator(IVehicleRepository vehicleRepository) .Must(ValidationUtils.IsValidEnumValue) .OverridePropertyName("Status"); + RuleFor(c => c.Color) + .Must(ValidationUtils.IsValidEnumValue) + .When(c => c.Color != null) + .OverridePropertyName("Cor"); + + RuleFor(c => c.TransmissionType) + .Must(ValidationUtils.IsValidEnumValue) + .OverridePropertyName("Tipo de Transmissão"); + RuleFor(c => c.BusServiceType) .Must(ValidationUtils.IsValidEnumValue) + .When(c => c.BusServiceType != null) .OverridePropertyName("Tipo de Serviço"); RuleFor(c => c.BusChassisBrand) .Must(ValidationUtils.IsValidEnumValue) + .When(c => c.BusChassisBrand != null) .OverridePropertyName("Marca do Chassi"); RuleFor(c => c.BusChassisModel) .NotEmpty() + .When(c => c.BusChassisModel != null) .OverridePropertyName("Modelo do Chassi"); - RuleFor(c => c.Color) - .Must(ValidationUtils.IsValidEnumValue) - .When(c => c.Color != null) - .OverridePropertyName("Cor"); - - RuleFor(c => c.TransmissionType) - .Must(ValidationUtils.IsValidEnumValue) - .OverridePropertyName("Tipo de Transmissão"); + RuleFor(c => c.BusChassisYear) + .NotNull() + .When(c => c.BusChassisYear != null) + .OverridePropertyName("Ano do Chassi"); + + RuleFor(c => c.BusHasLowFloor) + .NotNull() + .When(c => c.BusHasLowFloor != null) + .OverridePropertyName("Possui Piso Baixo"); + + RuleFor(c => c.BusHasLeftDoors) + .NotNull() + .When(c => c.BusHasLeftDoors != null) + .OverridePropertyName("Possui Portas a Esquerda"); + + RuleFor(c => c.BusInsuranceExpiration) + .NotNull() + .When(c => c.BusInsuranceExpiration != null) + .OverridePropertyName("Vencimento do Seguro"); } - private async Task IsPrefixInUseAsync(string prefix, CancellationToken cancellationToken = default) + private async Task IsPrefixInUseAsync(long id, string prefix, CancellationToken cancellationToken = default) { - return await _vehicleRepository.AnyAsync(c => c.Prefix.ToLower().Equals(prefix) && c.Status != (byte)VehicleStatus.Desativado, + return await _vehicleRepository.AnyAsync(c => c.Prefix.ToLower().Equals(prefix) && c.Status != (byte)VehicleStatus.Desativado && c.Id != id, cancellationToken: cancellationToken); } - private async Task IsPlateInUseAsync(string plate, CancellationToken cancellationToken = default) + private async Task IsPlateInUseAsync(long id, string plate, CancellationToken cancellationToken = default) { - return await _vehicleRepository.AnyAsync(c => c.Plate.ToLower().Equals(plate), + return await _vehicleRepository.AnyAsync(c => c.Plate.ToLower().Equals(plate) && c.Id != id, cancellationToken: cancellationToken); } - private async Task IsRenavamInUseAsync(string renavam, CancellationToken cancellationToken = default) + private async Task IsRenavamInUseAsync(long id, string renavam, CancellationToken cancellationToken = default) { - return await _vehicleRepository.AnyAsync(c => c.Renavam.ToLower().Equals(renavam), + return await _vehicleRepository.AnyAsync(c => c.Renavam.ToLower().Equals(renavam) && c.Id != id, cancellationToken: cancellationToken); } - private async Task IsNumberChassisInUseAsync(string? numberChassis, CancellationToken cancellationToken = default) + private async Task IsNumberChassisInUseAsync(long id, string? numberChassis, CancellationToken cancellationToken = default) { - return await _vehicleRepository.AnyAsync(c => !string.IsNullOrWhiteSpace(c.NumberChassis) && c.NumberChassis.ToLower().Equals(numberChassis), + return await _vehicleRepository.AnyAsync(c => !string.IsNullOrWhiteSpace(c.NumberChassis) && c.NumberChassis.ToLower().Equals(numberChassis) && c.Id != id, cancellationToken: cancellationToken); } - private async Task IsBodyworkNumberInUseAsync(string? bodyworkNumber, CancellationToken cancellationToken = default) + private async Task IsBodyworkNumberInUseAsync(long id, string? bodyworkNumber, CancellationToken cancellationToken = default) { - return await _vehicleRepository.AnyAsync(c => !string.IsNullOrWhiteSpace(c.BodyworkNumber) && c.BodyworkNumber.ToLower().Equals(bodyworkNumber), + return await _vehicleRepository.AnyAsync(c => !string.IsNullOrWhiteSpace(c.BodyworkNumber) && c.BodyworkNumber.ToLower().Equals(bodyworkNumber) && c.Id != id, cancellationToken: cancellationToken); } - private async Task IsEngineNumberInUseAsync(string? engineNumber, CancellationToken cancellationToken = default) + private async Task IsEngineNumberInUseAsync(long id, string? engineNumber, CancellationToken cancellationToken = default) { - return await _vehicleRepository.AnyAsync(c => !string.IsNullOrWhiteSpace(c.EngineNumber) && c.EngineNumber.ToLower().Equals(engineNumber), + return await _vehicleRepository.AnyAsync(c => !string.IsNullOrWhiteSpace(c.EngineNumber) && c.EngineNumber.ToLower().Equals(engineNumber) && c.Id != id, cancellationToken: cancellationToken); } } From 89ed13031d5293dd636990ab0a9aee92f9297118 Mon Sep 17 00:00:00 2001 From: Eduardo Rezende Date: Sat, 4 Oct 2025 23:23:14 -0300 Subject: [PATCH 33/99] =?UTF-8?q?=E2=99=BB=EF=B8=8Frefactor:=20Update=20Ve?= =?UTF-8?q?hicle=20Create=20Validator?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Adding more validations over Bus fields --- .../Validators/Vehicle/CreateVehicleDTOValidator.cs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/OneBus.Application/Validators/Vehicle/CreateVehicleDTOValidator.cs b/OneBus.Application/Validators/Vehicle/CreateVehicleDTOValidator.cs index 94fb496..a68178e 100644 --- a/OneBus.Application/Validators/Vehicle/CreateVehicleDTOValidator.cs +++ b/OneBus.Application/Validators/Vehicle/CreateVehicleDTOValidator.cs @@ -86,14 +86,17 @@ public CreateVehicleDTOValidator(IVehicleRepository vehicleRepository) RuleFor(c => c.BusServiceType) .Must(ValidationUtils.IsValidEnumValue) + .When(c => c.BusServiceType != null) .OverridePropertyName("Tipo de Serviço"); RuleFor(c => c.BusChassisBrand) .Must(ValidationUtils.IsValidEnumValue) + .When(c => c.BusChassisBrand != null) .OverridePropertyName("Marca do Chassi"); RuleFor(c => c.BusChassisModel) .NotEmpty() + .When(c => c.BusChassisModel != null) .OverridePropertyName("Modelo do Chassi"); RuleFor(c => c.BusChassisYear) From 5e46cefa7df8cb087ee9f1430ec59179941277e3 Mon Sep 17 00:00:00 2001 From: Eduardo Rezende Date: Sat, 4 Oct 2025 23:45:42 -0300 Subject: [PATCH 34/99] =?UTF-8?q?=F0=9F=90=9Bfix:=20Update=20Vehicle=20Ser?= =?UTF-8?q?vice?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fixing GET methods localization --- OneBus.Application/Services/VehicleService.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/OneBus.Application/Services/VehicleService.cs b/OneBus.Application/Services/VehicleService.cs index ab0faed..fc02ee4 100644 --- a/OneBus.Application/Services/VehicleService.cs +++ b/OneBus.Application/Services/VehicleService.cs @@ -39,8 +39,8 @@ public override async Task>> GetPaginedAsync( vehicle.BrandName = ((VehicleBrands)vehicle.Brand).ToString().Localize(); vehicle.FuelTypeName = ((FuelType)vehicle.FuelType).ToString().Localize(); vehicle.StatusName = ((VehicleStatus)vehicle.Status).ToString().Localize(); - vehicle.TransmissionTypeName = ((VehicleStatus)vehicle.TransmissionType).ToString().Localize(); vehicle.BusServiceTypeName = ((BusServiceType?)vehicle.BusServiceType)?.ToString()?.Localize(); + vehicle.TransmissionTypeName = ((TransmissionType)vehicle.TransmissionType).ToString().Localize(); vehicle.BusChassisBrandName = ((BusChassisBrands?)vehicle.BusChassisBrand)?.ToString()?.Localize(); } @@ -64,8 +64,8 @@ public override async Task> GetByIdAsync( vehicle.BrandName = ((VehicleBrands)vehicle.Brand).ToString().Localize(); vehicle.FuelTypeName = ((FuelType)vehicle.FuelType).ToString().Localize(); vehicle.StatusName = ((VehicleStatus)vehicle.Status).ToString().Localize(); - vehicle.TransmissionTypeName = ((VehicleStatus)vehicle.TransmissionType).ToString().Localize(); vehicle.BusServiceTypeName = ((BusServiceType?)vehicle.BusServiceType)?.ToString()?.Localize(); + vehicle.TransmissionTypeName = ((TransmissionType)vehicle.TransmissionType).ToString().Localize(); vehicle.BusChassisBrandName = ((BusChassisBrands?)vehicle.BusChassisBrand)?.ToString()?.Localize(); return result; From 1e45ac6cd8800aa9939da0dd1196980923c9ae9e Mon Sep 17 00:00:00 2001 From: Eduardo Rezende Date: Sun, 5 Oct 2025 00:07:11 -0300 Subject: [PATCH 35/99] =?UTF-8?q?=E2=99=BB=EF=B8=8Frefactor:=20Update=20Ve?= =?UTF-8?q?hicle=20Type=20DTO?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Updating VehicleType DTOs references --- OneBus.API/Controllers/VehicleController.cs | 2 +- .../Vehicle/{ReadTypeDTO.cs => ReadVehicleTypeDTO.cs} | 4 ++-- OneBus.Application/Interfaces/Services/IVehicleService.cs | 2 +- OneBus.Application/Services/VehicleService.cs | 8 ++++---- 4 files changed, 8 insertions(+), 8 deletions(-) rename OneBus.Application/DTOs/Vehicle/{ReadTypeDTO.cs => ReadVehicleTypeDTO.cs} (73%) diff --git a/OneBus.API/Controllers/VehicleController.cs b/OneBus.API/Controllers/VehicleController.cs index fdab4b8..61c7c3a 100644 --- a/OneBus.API/Controllers/VehicleController.cs +++ b/OneBus.API/Controllers/VehicleController.cs @@ -239,7 +239,7 @@ public IActionResult GetTransmissionTypes() /// Tipos de veículo disponíveis /// Tipos de veículo retornados com sucesso [HttpGet("types")] - [ProducesResponseType(typeof(SuccessResult>), StatusCodes.Status200OK)] + [ProducesResponseType(typeof(SuccessResult>), StatusCodes.Status200OK)] public IActionResult GetVehicleTypes() { return _vehicleService.GetVehicleTypes().ToActionResult(); diff --git a/OneBus.Application/DTOs/Vehicle/ReadTypeDTO.cs b/OneBus.Application/DTOs/Vehicle/ReadVehicleTypeDTO.cs similarity index 73% rename from OneBus.Application/DTOs/Vehicle/ReadTypeDTO.cs rename to OneBus.Application/DTOs/Vehicle/ReadVehicleTypeDTO.cs index f4a904f..8590dbe 100644 --- a/OneBus.Application/DTOs/Vehicle/ReadTypeDTO.cs +++ b/OneBus.Application/DTOs/Vehicle/ReadVehicleTypeDTO.cs @@ -1,8 +1,8 @@ namespace OneBus.Application.DTOs.Vehicle { - public class ReadTypeDTO + public class ReadVehicleTypeDTO { - public ReadTypeDTO() + public ReadVehicleTypeDTO() { Name = string.Empty; } diff --git a/OneBus.Application/Interfaces/Services/IVehicleService.cs b/OneBus.Application/Interfaces/Services/IVehicleService.cs index efca8b5..8d4d4f9 100644 --- a/OneBus.Application/Interfaces/Services/IVehicleService.cs +++ b/OneBus.Application/Interfaces/Services/IVehicleService.cs @@ -22,6 +22,6 @@ public interface IVehicleService : Result> GetTransmissionTypes(); - Result> GetVehicleTypes(); + Result> GetVehicleTypes(); } } diff --git a/OneBus.Application/Services/VehicleService.cs b/OneBus.Application/Services/VehicleService.cs index fc02ee4..f7d40b0 100644 --- a/OneBus.Application/Services/VehicleService.cs +++ b/OneBus.Application/Services/VehicleService.cs @@ -169,18 +169,18 @@ public Result> GetTransmissionTypes() return SuccessResult>.Create(status); } - public Result> GetVehicleTypes() + public Result> GetVehicleTypes() { var values = Enum.GetValues(); - List status = []; + List status = []; foreach (var value in values) { - status.Add(new ReadTypeDTO { Value = (byte)value, Name = value.ToString().Localize() }); + status.Add(new ReadVehicleTypeDTO { Value = (byte)value, Name = value.ToString().Localize() }); } - return SuccessResult>.Create(status); + return SuccessResult>.Create(status); } protected override void UpdateFields(Vehicle entity, UpdateVehicleDTO updateDTO) From 2511c93fd2dbf79876c66365b907a98ca79c027d Mon Sep 17 00:00:00 2001 From: Eduardo Rezende Date: Sun, 5 Oct 2025 00:11:44 -0300 Subject: [PATCH 36/99] =?UTF-8?q?=E2=99=BB=EF=B8=8Frefactor:=20Update=20Ut?= =?UTF-8?q?ils=20class=20references?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Updating ValidationUtils namespace --- .../Validators/Employee/CreateEmployeeDTOValidator.cs | 2 +- .../Validators/Employee/UpdateEmployeeDTOValidator.cs | 2 +- .../EmployeeWorkday/CreateEmployeeWorkdayDTOValidator.cs | 2 +- .../Validators/Vehicle/CreateVehicleDTOValidator.cs | 2 +- .../Validators/Vehicle/UpdateVehicleDTOValidator.cs | 2 +- {OneBus.Application => OneBus.Domain}/Utils/ValidationUtils.cs | 2 +- 6 files changed, 6 insertions(+), 6 deletions(-) rename {OneBus.Application => OneBus.Domain}/Utils/ValidationUtils.cs (92%) diff --git a/OneBus.Application/Validators/Employee/CreateEmployeeDTOValidator.cs b/OneBus.Application/Validators/Employee/CreateEmployeeDTOValidator.cs index 4edee42..8a475b6 100644 --- a/OneBus.Application/Validators/Employee/CreateEmployeeDTOValidator.cs +++ b/OneBus.Application/Validators/Employee/CreateEmployeeDTOValidator.cs @@ -1,9 +1,9 @@ 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; +using OneBus.Domain.Utils; namespace OneBus.Application.Validators.Employee { diff --git a/OneBus.Application/Validators/Employee/UpdateEmployeeDTOValidator.cs b/OneBus.Application/Validators/Employee/UpdateEmployeeDTOValidator.cs index 9762db7..2571101 100644 --- a/OneBus.Application/Validators/Employee/UpdateEmployeeDTOValidator.cs +++ b/OneBus.Application/Validators/Employee/UpdateEmployeeDTOValidator.cs @@ -1,9 +1,9 @@ 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; +using OneBus.Domain.Utils; namespace OneBus.Application.Validators.Employee { diff --git a/OneBus.Application/Validators/EmployeeWorkday/CreateEmployeeWorkdayDTOValidator.cs b/OneBus.Application/Validators/EmployeeWorkday/CreateEmployeeWorkdayDTOValidator.cs index 2c90fab..44948bf 100644 --- a/OneBus.Application/Validators/EmployeeWorkday/CreateEmployeeWorkdayDTOValidator.cs +++ b/OneBus.Application/Validators/EmployeeWorkday/CreateEmployeeWorkdayDTOValidator.cs @@ -1,9 +1,9 @@ using FluentValidation; using OneBus.Application.DTOs.EmployeeWorkday; -using OneBus.Application.Utils; using OneBus.Domain.Commons; using OneBus.Domain.Enums; using OneBus.Domain.Interfaces.Repositories; +using OneBus.Domain.Utils; namespace OneBus.Application.Validators.EmployeeWorkday { diff --git a/OneBus.Application/Validators/Vehicle/CreateVehicleDTOValidator.cs b/OneBus.Application/Validators/Vehicle/CreateVehicleDTOValidator.cs index a68178e..b20f400 100644 --- a/OneBus.Application/Validators/Vehicle/CreateVehicleDTOValidator.cs +++ b/OneBus.Application/Validators/Vehicle/CreateVehicleDTOValidator.cs @@ -1,9 +1,9 @@ using FluentValidation; using OneBus.Application.DTOs.Vehicle; -using OneBus.Application.Utils; using OneBus.Domain.Commons; using OneBus.Domain.Enums.Vehicle; using OneBus.Domain.Interfaces.Repositories; +using OneBus.Domain.Utils; namespace OneBus.Application.Validators.Vehicle { diff --git a/OneBus.Application/Validators/Vehicle/UpdateVehicleDTOValidator.cs b/OneBus.Application/Validators/Vehicle/UpdateVehicleDTOValidator.cs index bfd3e88..eac5e51 100644 --- a/OneBus.Application/Validators/Vehicle/UpdateVehicleDTOValidator.cs +++ b/OneBus.Application/Validators/Vehicle/UpdateVehicleDTOValidator.cs @@ -1,9 +1,9 @@ using FluentValidation; using OneBus.Application.DTOs.Vehicle; -using OneBus.Application.Utils; using OneBus.Domain.Commons; using OneBus.Domain.Enums.Vehicle; using OneBus.Domain.Interfaces.Repositories; +using OneBus.Domain.Utils; namespace OneBus.Application.Validators.Vehicle { diff --git a/OneBus.Application/Utils/ValidationUtils.cs b/OneBus.Domain/Utils/ValidationUtils.cs similarity index 92% rename from OneBus.Application/Utils/ValidationUtils.cs rename to OneBus.Domain/Utils/ValidationUtils.cs index 1213843..fa1b01f 100644 --- a/OneBus.Application/Utils/ValidationUtils.cs +++ b/OneBus.Domain/Utils/ValidationUtils.cs @@ -1,4 +1,4 @@ -namespace OneBus.Application.Utils +namespace OneBus.Domain.Utils { public static class ValidationUtils { From 1b3ec0001660ab52967b5b1adc80ccea1e2f758d Mon Sep 17 00:00:00 2001 From: Eduardo Rezende Date: Tue, 7 Oct 2025 19:34:53 -0300 Subject: [PATCH 37/99] =?UTF-8?q?=E2=99=BB=EF=B8=8Frefactor:=20Update=20Bu?= =?UTF-8?q?sServiceType?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Adding 'Seletivo' option --- OneBus.Domain/Enums/Vehicle/BusServiceType.cs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/OneBus.Domain/Enums/Vehicle/BusServiceType.cs b/OneBus.Domain/Enums/Vehicle/BusServiceType.cs index aa01621..99205bb 100644 --- a/OneBus.Domain/Enums/Vehicle/BusServiceType.cs +++ b/OneBus.Domain/Enums/Vehicle/BusServiceType.cs @@ -4,6 +4,7 @@ public enum BusServiceType : byte { Municipal, Intermunicipal, - Suburbano + Suburbano, + Seletivo } } From d4a60ff93b175c6f8da8761c30442ac0ebf70f17 Mon Sep 17 00:00:00 2001 From: Eduardo Rezende Date: Tue, 7 Oct 2025 20:16:57 -0300 Subject: [PATCH 38/99] =?UTF-8?q?=F0=9F=90=9Bfix:=20Update=20Validators?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Adding ToLower() for comparing values and improving validations logic --- .../Employee/CreateEmployeeDTOValidator.cs | 10 ++++---- .../Employee/UpdateEmployeeDTOValidator.cs | 10 ++++---- .../Vehicle/CreateVehicleDTOValidator.cs | 23 +++++++++++++------ .../Vehicle/UpdateVehicleDTOValidator.cs | 23 +++++++++++++------ 4 files changed, 42 insertions(+), 24 deletions(-) diff --git a/OneBus.Application/Validators/Employee/CreateEmployeeDTOValidator.cs b/OneBus.Application/Validators/Employee/CreateEmployeeDTOValidator.cs index 8a475b6..0c5a842 100644 --- a/OneBus.Application/Validators/Employee/CreateEmployeeDTOValidator.cs +++ b/OneBus.Application/Validators/Employee/CreateEmployeeDTOValidator.cs @@ -52,25 +52,25 @@ public CreateEmployeeDTOValidator(IEmployeeRepository employeeRepository) private async Task CpfAlreadyExistsAsync(string cpf, CancellationToken cancellationToken = default) { - return await _employeeRepository.AnyAsync(c => c.Cpf.ToLower().Equals(cpf), + return await _employeeRepository.AnyAsync(c => c.Cpf.ToLower().Equals(cpf.ToLower()), cancellationToken: cancellationToken); } private async Task CodeAlreadyExistsAsync(string code, CancellationToken cancellationToken = default) { - return await _employeeRepository.AnyAsync(c => c.Code.ToLower().Equals(code), + return await _employeeRepository.AnyAsync(c => c.Code.ToLower().Equals(code.ToLower()), cancellationToken: cancellationToken); } private async Task EmailAlreadyExistsAsync(string email, CancellationToken cancellationToken = default) { - return await _employeeRepository.AnyAsync(c => c.Email.ToLower().Equals(email), + return await _employeeRepository.AnyAsync(c => c.Email.ToLower().Equals(email.ToLower()), cancellationToken: cancellationToken); } private async Task PhoneAlreadyExistsAsync(string phone, CancellationToken cancellationToken = default) { - return await _employeeRepository.AnyAsync(c => c.Phone.ToLower().Equals(phone), + return await _employeeRepository.AnyAsync(c => c.Phone.ToLower().Equals(phone.ToLower()), cancellationToken: cancellationToken); } @@ -79,7 +79,7 @@ private async Task CnhNumberAlreadyExistsAsync(string? cnhNumber, Cancella if (string.IsNullOrWhiteSpace(cnhNumber)) return false; - return await _employeeRepository.AnyAsync(c => c.CnhNumber!.ToLower().Equals(cnhNumber), + return await _employeeRepository.AnyAsync(c => c.CnhNumber!.ToLower().Equals(cnhNumber.ToLower()), cancellationToken: cancellationToken); } } diff --git a/OneBus.Application/Validators/Employee/UpdateEmployeeDTOValidator.cs b/OneBus.Application/Validators/Employee/UpdateEmployeeDTOValidator.cs index 2571101..26378c4 100644 --- a/OneBus.Application/Validators/Employee/UpdateEmployeeDTOValidator.cs +++ b/OneBus.Application/Validators/Employee/UpdateEmployeeDTOValidator.cs @@ -53,25 +53,25 @@ public UpdateEmployeeDTOValidator(IEmployeeRepository employeeRepository) private async Task CpfAlreadyExistsAsync(long id, string cpf, CancellationToken cancellationToken = default) { - return await _employeeRepository.AnyAsync(c => c.Cpf.ToLower().Equals(cpf) && c.Id != id, + return await _employeeRepository.AnyAsync(c => c.Cpf.ToLower().Equals(cpf.ToLower()) && 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, + return await _employeeRepository.AnyAsync(c => c.Code.ToLower().Equals(code.ToLower()) && 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, + return await _employeeRepository.AnyAsync(c => c.Email.ToLower().Equals(email.ToLower()) && 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, + return await _employeeRepository.AnyAsync(c => c.Phone.ToLower().Equals(phone.ToLower()) && c.Id != id, cancellationToken: cancellationToken); } @@ -80,7 +80,7 @@ private async Task CnhNumberAlreadyExistsAsync(long id, string? cnhNumber, if (string.IsNullOrWhiteSpace(cnhNumber)) return false; - return await _employeeRepository.AnyAsync(c => c.CnhNumber!.ToLower().Equals(cnhNumber) && c.Id != id, + return await _employeeRepository.AnyAsync(c => c.CnhNumber!.ToLower().Equals(cnhNumber.ToLower()) && c.Id != id, cancellationToken: cancellationToken); } } diff --git a/OneBus.Application/Validators/Vehicle/CreateVehicleDTOValidator.cs b/OneBus.Application/Validators/Vehicle/CreateVehicleDTOValidator.cs index b20f400..cce2b6e 100644 --- a/OneBus.Application/Validators/Vehicle/CreateVehicleDTOValidator.cs +++ b/OneBus.Application/Validators/Vehicle/CreateVehicleDTOValidator.cs @@ -122,37 +122,46 @@ public CreateVehicleDTOValidator(IVehicleRepository vehicleRepository) private async Task IsPrefixInUseAsync(string prefix, CancellationToken cancellationToken = default) { - return await _vehicleRepository.AnyAsync(c => c.Prefix.ToLower().Equals(prefix) && c.Status != (byte)VehicleStatus.Desativado, + return await _vehicleRepository.AnyAsync(c => c.Prefix.ToLower().Equals(prefix.ToLower()) && c.Status != (byte)VehicleStatus.Desativado, cancellationToken: cancellationToken); } private async Task IsPlateInUseAsync(string plate, CancellationToken cancellationToken = default) { - return await _vehicleRepository.AnyAsync(c => c.Plate.ToLower().Equals(plate), + return await _vehicleRepository.AnyAsync(c => c.Plate.ToLower().Equals(plate.ToLower()), cancellationToken: cancellationToken); } private async Task IsRenavamInUseAsync(string renavam, CancellationToken cancellationToken = default) - { - return await _vehicleRepository.AnyAsync(c => c.Renavam.ToLower().Equals(renavam), + { + return await _vehicleRepository.AnyAsync(c => c.Renavam.ToLower().Equals(renavam.ToLower()), cancellationToken: cancellationToken); } private async Task IsNumberChassisInUseAsync(string? numberChassis, CancellationToken cancellationToken = default) { - return await _vehicleRepository.AnyAsync(c => !string.IsNullOrWhiteSpace(c.NumberChassis) && c.NumberChassis.ToLower().Equals(numberChassis), + if (string.IsNullOrWhiteSpace(numberChassis)) + return false; + + return await _vehicleRepository.AnyAsync(c => c.NumberChassis!.ToLower().Equals(numberChassis.ToLower()), cancellationToken: cancellationToken); } private async Task IsBodyworkNumberInUseAsync(string? bodyworkNumber, CancellationToken cancellationToken = default) { - return await _vehicleRepository.AnyAsync(c => !string.IsNullOrWhiteSpace(c.BodyworkNumber) && c.BodyworkNumber.ToLower().Equals(bodyworkNumber), + if (string.IsNullOrWhiteSpace(bodyworkNumber)) + return false; + + return await _vehicleRepository.AnyAsync(c => c.BodyworkNumber!.ToLower().Equals(bodyworkNumber.ToLower()), cancellationToken: cancellationToken); } private async Task IsEngineNumberInUseAsync(string? engineNumber, CancellationToken cancellationToken = default) { - return await _vehicleRepository.AnyAsync(c => !string.IsNullOrWhiteSpace(c.EngineNumber) && c.EngineNumber.ToLower().Equals(engineNumber), + if (string.IsNullOrWhiteSpace(engineNumber)) + return false; + + return await _vehicleRepository.AnyAsync(c => c.EngineNumber!.ToLower().Equals(engineNumber.ToLower()), cancellationToken: cancellationToken); } } diff --git a/OneBus.Application/Validators/Vehicle/UpdateVehicleDTOValidator.cs b/OneBus.Application/Validators/Vehicle/UpdateVehicleDTOValidator.cs index eac5e51..315c9c4 100644 --- a/OneBus.Application/Validators/Vehicle/UpdateVehicleDTOValidator.cs +++ b/OneBus.Application/Validators/Vehicle/UpdateVehicleDTOValidator.cs @@ -106,7 +106,7 @@ public UpdateVehicleDTOValidator(IVehicleRepository vehicleRepository) .NotNull() .When(c => c.BusHasLowFloor != null) .OverridePropertyName("Possui Piso Baixo"); - + RuleFor(c => c.BusHasLeftDoors) .NotNull() .When(c => c.BusHasLeftDoors != null) @@ -120,37 +120,46 @@ public UpdateVehicleDTOValidator(IVehicleRepository vehicleRepository) private async Task IsPrefixInUseAsync(long id, string prefix, CancellationToken cancellationToken = default) { - return await _vehicleRepository.AnyAsync(c => c.Prefix.ToLower().Equals(prefix) && c.Status != (byte)VehicleStatus.Desativado && c.Id != id, + return await _vehicleRepository.AnyAsync(c => c.Prefix.ToLower().Equals(prefix.ToLower()) && c.Status != (byte)VehicleStatus.Desativado && c.Id != id, cancellationToken: cancellationToken); } private async Task IsPlateInUseAsync(long id, string plate, CancellationToken cancellationToken = default) { - return await _vehicleRepository.AnyAsync(c => c.Plate.ToLower().Equals(plate) && c.Id != id, + return await _vehicleRepository.AnyAsync(c => c.Plate.ToLower().Equals(plate.ToLower()) && c.Id != id, cancellationToken: cancellationToken); } private async Task IsRenavamInUseAsync(long id, string renavam, CancellationToken cancellationToken = default) { - return await _vehicleRepository.AnyAsync(c => c.Renavam.ToLower().Equals(renavam) && c.Id != id, + return await _vehicleRepository.AnyAsync(c => c.Renavam.ToLower().Equals(renavam.ToLower()) && c.Id != id, cancellationToken: cancellationToken); } private async Task IsNumberChassisInUseAsync(long id, string? numberChassis, CancellationToken cancellationToken = default) { - return await _vehicleRepository.AnyAsync(c => !string.IsNullOrWhiteSpace(c.NumberChassis) && c.NumberChassis.ToLower().Equals(numberChassis) && c.Id != id, + if (string.IsNullOrWhiteSpace(numberChassis)) + return false; + + return await _vehicleRepository.AnyAsync(c => c.NumberChassis!.ToLower().Equals(numberChassis.ToLower()) && c.Id != id, cancellationToken: cancellationToken); } private async Task IsBodyworkNumberInUseAsync(long id, string? bodyworkNumber, CancellationToken cancellationToken = default) { - return await _vehicleRepository.AnyAsync(c => !string.IsNullOrWhiteSpace(c.BodyworkNumber) && c.BodyworkNumber.ToLower().Equals(bodyworkNumber) && c.Id != id, + if (string.IsNullOrWhiteSpace(bodyworkNumber)) + return false; + + return await _vehicleRepository.AnyAsync(c => c.BodyworkNumber!.ToLower().Equals(bodyworkNumber.ToLower()) && c.Id != id, cancellationToken: cancellationToken); } private async Task IsEngineNumberInUseAsync(long id, string? engineNumber, CancellationToken cancellationToken = default) { - return await _vehicleRepository.AnyAsync(c => !string.IsNullOrWhiteSpace(c.EngineNumber) && c.EngineNumber.ToLower().Equals(engineNumber) && c.Id != id, + if (string.IsNullOrWhiteSpace(engineNumber)) + return false; + + return await _vehicleRepository.AnyAsync(c => c.EngineNumber!.ToLower().Equals(engineNumber.ToLower()) && c.Id != id, cancellationToken: cancellationToken); } } From bf9b52e79aa24fcd71f2c3ad2ffcda606e0e7d74 Mon Sep 17 00:00:00 2001 From: Eduardo Rezende Date: Tue, 7 Oct 2025 20:22:49 -0300 Subject: [PATCH 39/99] =?UTF-8?q?=E2=99=BB=EF=B8=8Frefactor:=20Update=20En?= =?UTF-8?q?ums?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Adding DirectionType enum for Lines and updating LineType values --- OneBus.Domain/Enums/Line/DirectionType.cs | 9 +++++++++ OneBus.Domain/Enums/Line/LineType.cs | 6 ++++-- 2 files changed, 13 insertions(+), 2 deletions(-) create mode 100644 OneBus.Domain/Enums/Line/DirectionType.cs diff --git a/OneBus.Domain/Enums/Line/DirectionType.cs b/OneBus.Domain/Enums/Line/DirectionType.cs new file mode 100644 index 0000000..b9b884a --- /dev/null +++ b/OneBus.Domain/Enums/Line/DirectionType.cs @@ -0,0 +1,9 @@ +namespace OneBus.Domain.Enums.Line +{ + public enum DirectionType + { + Ida, + Volta, + Circular + } +} diff --git a/OneBus.Domain/Enums/Line/LineType.cs b/OneBus.Domain/Enums/Line/LineType.cs index bb7e9b9..9091d80 100644 --- a/OneBus.Domain/Enums/Line/LineType.cs +++ b/OneBus.Domain/Enums/Line/LineType.cs @@ -2,8 +2,10 @@ { public enum LineType : byte { - Corredor, + Corredor, + Intermunicipal, + Municipal, Seletivo, - Normal, + Suburbano } } From 6422c1b310586d689f0aa937e2313e950fed287a Mon Sep 17 00:00:00 2001 From: Eduardo Rezende Date: Tue, 7 Oct 2025 21:11:49 -0300 Subject: [PATCH 40/99] =?UTF-8?q?=E2=99=BB=EF=B8=8Frefactor:=20Update=20Li?= =?UTF-8?q?ne?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Adding DirectionType field --- OneBus.Domain/Entities/Line.cs | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/OneBus.Domain/Entities/Line.cs b/OneBus.Domain/Entities/Line.cs index d437f56..402462d 100644 --- a/OneBus.Domain/Entities/Line.cs +++ b/OneBus.Domain/Entities/Line.cs @@ -18,9 +18,7 @@ public Line() public decimal Mileage { get; set; } - public byte MinNumberBuses { get; set; } - - public byte MaxNumberBuses { get; set; } + public byte DirectionType { get; set; } public ICollection? LineTimes { get; set; } } From b757b7c3328ed1cfb83670263042f39e481b47a3 Mon Sep 17 00:00:00 2001 From: Eduardo Rezende Date: Tue, 7 Oct 2025 21:12:12 -0300 Subject: [PATCH 41/99] =?UTF-8?q?=E2=9C=A8feat:=20Add=20LineFilter?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Adding filter class for Line --- OneBus.Domain/Filters/LineFilter.cs | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 OneBus.Domain/Filters/LineFilter.cs diff --git a/OneBus.Domain/Filters/LineFilter.cs b/OneBus.Domain/Filters/LineFilter.cs new file mode 100644 index 0000000..2701987 --- /dev/null +++ b/OneBus.Domain/Filters/LineFilter.cs @@ -0,0 +1,9 @@ +namespace OneBus.Domain.Filters +{ + public class LineFilter : BaseFilter + { + public byte? Type { get; set; } + + public byte? DirectionType { get; set; } + } +} From 9ef557274d5df8ebd3399ff04bec8ef7a8375d1f Mon Sep 17 00:00:00 2001 From: Eduardo Rezende Date: Tue, 7 Oct 2025 21:12:42 -0300 Subject: [PATCH 42/99] =?UTF-8?q?=E2=99=BB=EF=B8=8Frefactor:=20Update=20Di?= =?UTF-8?q?rectionType=20enum?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Adding byte type for the enum --- OneBus.Domain/Enums/Line/DirectionType.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/OneBus.Domain/Enums/Line/DirectionType.cs b/OneBus.Domain/Enums/Line/DirectionType.cs index b9b884a..bb1be93 100644 --- a/OneBus.Domain/Enums/Line/DirectionType.cs +++ b/OneBus.Domain/Enums/Line/DirectionType.cs @@ -1,6 +1,6 @@ namespace OneBus.Domain.Enums.Line { - public enum DirectionType + public enum DirectionType : byte { Ida, Volta, From fc62f9b6a2251430fb51d640423ae66caf8ffe66 Mon Sep 17 00:00:00 2001 From: Eduardo Rezende Date: Tue, 7 Oct 2025 21:13:07 -0300 Subject: [PATCH 43/99] =?UTF-8?q?=E2=9C=A8feat:=20Add=20Migration?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Adding DirectionType field into Line table --- ...07232852_UpdateLineTableFields.Designer.cs | 589 ++++++++++++++++++ .../20251007232852_UpdateLineTableFields.cs | 39 ++ .../OneBusDbContextModelSnapshot.cs | 9 +- 3 files changed, 631 insertions(+), 6 deletions(-) create mode 100644 OneBus.Infra.Data/Migrations/20251007232852_UpdateLineTableFields.Designer.cs create mode 100644 OneBus.Infra.Data/Migrations/20251007232852_UpdateLineTableFields.cs diff --git a/OneBus.Infra.Data/Migrations/20251007232852_UpdateLineTableFields.Designer.cs b/OneBus.Infra.Data/Migrations/20251007232852_UpdateLineTableFields.Designer.cs new file mode 100644 index 0000000..e32a03e --- /dev/null +++ b/OneBus.Infra.Data/Migrations/20251007232852_UpdateLineTableFields.Designer.cs @@ -0,0 +1,589 @@ +// +using System; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; +using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; +using OneBus.Infra.Data.DbContexts; + +#nullable disable + +namespace OneBus.Infra.Data.Migrations +{ + [DbContext(typeof(OneBusDbContext))] + [Migration("20251007232852_UpdateLineTableFields")] + partial class UpdateLineTableFields + { + /// + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("ProductVersion", "9.0.9") + .HasAnnotation("Relational:MaxIdentifierLength", 63); + + NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder); + + modelBuilder.Entity("OneBus.Domain.Entities.Employee", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("bigint"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("BloodType") + .HasColumnType("smallint"); + + b.Property("CnhCategory") + .HasColumnType("smallint"); + + b.Property("CnhExpiration") + .HasColumnType("date"); + + b.Property("CnhNumber") + .HasMaxLength(20) + .IsUnicode(false) + .HasColumnType("character varying(20)"); + + b.Property("Code") + .IsRequired() + .HasMaxLength(30) + .IsUnicode(false) + .HasColumnType("character varying(30)"); + + b.Property("Cpf") + .IsRequired() + .HasMaxLength(20) + .IsUnicode(false) + .HasColumnType("character varying(20)"); + + b.Property("CreatedAt") + .HasColumnType("timestamp with time zone"); + + b.Property("Email") + .IsRequired() + .HasMaxLength(80) + .IsUnicode(false) + .HasColumnType("character varying(80)"); + + b.Property("HiringDate") + .HasColumnType("date"); + + b.Property("Image") + .HasColumnType("bytea"); + + b.Property("IsDeleted") + .HasColumnType("boolean"); + + b.Property("Name") + .IsRequired() + .HasMaxLength(80) + .IsUnicode(false) + .HasColumnType("character varying(80)"); + + b.Property("Phone") + .IsRequired() + .HasMaxLength(20) + .IsUnicode(false) + .HasColumnType("character varying(20)"); + + b.Property("Rg") + .IsRequired() + .HasMaxLength(20) + .IsUnicode(false) + .HasColumnType("character varying(20)"); + + b.Property("Role") + .HasColumnType("smallint"); + + b.Property("Status") + .HasColumnType("smallint"); + + b.HasKey("Id"); + + b.HasIndex("CnhNumber"); + + b.HasIndex("Code"); + + b.HasIndex("Cpf"); + + b.ToTable("Employee"); + }); + + modelBuilder.Entity("OneBus.Domain.Entities.EmployeeWorkday", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("bigint"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("CreatedAt") + .HasColumnType("timestamp with time zone"); + + b.Property("DayType") + .HasColumnType("smallint"); + + b.Property("EmployeeId") + .HasColumnType("bigint"); + + b.Property("EndTime") + .HasColumnType("time without time zone"); + + b.Property("IsDeleted") + .HasColumnType("boolean"); + + b.Property("StartTime") + .HasColumnType("time without time zone"); + + b.HasKey("Id"); + + b.HasIndex("EmployeeId"); + + b.ToTable("EmployeeWorkday"); + }); + + modelBuilder.Entity("OneBus.Domain.Entities.Line", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("bigint"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("CreatedAt") + .HasColumnType("timestamp with time zone"); + + b.Property("DirectionType") + .HasColumnType("smallint"); + + b.Property("IsDeleted") + .HasColumnType("boolean"); + + b.Property("Mileage") + .HasPrecision(19, 4) + .HasColumnType("numeric(19,4)"); + + b.Property("Name") + .IsRequired() + .HasMaxLength(80) + .IsUnicode(false) + .HasColumnType("character varying(80)"); + + b.Property("Number") + .IsRequired() + .HasMaxLength(20) + .IsUnicode(false) + .HasColumnType("character varying(20)"); + + b.Property("TravelTime") + .HasColumnType("time without time zone"); + + b.Property("Type") + .HasColumnType("smallint"); + + b.HasKey("Id"); + + b.ToTable("Line"); + }); + + modelBuilder.Entity("OneBus.Domain.Entities.LineTime", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("bigint"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("CreatedAt") + .HasColumnType("timestamp with time zone"); + + b.Property("DayType") + .HasColumnType("smallint"); + + b.Property("EndTime") + .HasColumnType("time without time zone"); + + b.Property("IsDeleted") + .HasColumnType("boolean"); + + b.Property("LineId") + .HasColumnType("bigint"); + + b.Property("StartTime") + .HasColumnType("time without time zone"); + + b.HasKey("Id"); + + b.HasIndex("LineId"); + + b.ToTable("LineTime"); + }); + + modelBuilder.Entity("OneBus.Domain.Entities.Maintenance", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("bigint"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("Cost") + .HasPrecision(19, 4) + .HasColumnType("numeric(19,4)"); + + b.Property("CreatedAt") + .HasColumnType("timestamp with time zone"); + + b.Property("Description") + .IsRequired() + .HasMaxLength(150) + .IsUnicode(false) + .HasColumnType("character varying(150)"); + + b.Property("EndDate") + .HasColumnType("date"); + + b.Property("IsDeleted") + .HasColumnType("boolean"); + + b.Property("Sector") + .HasColumnType("smallint"); + + b.Property("StartDate") + .HasColumnType("date"); + + b.Property("SurveyExpiration") + .HasColumnType("date"); + + b.Property("VehicleId") + .HasColumnType("bigint"); + + b.HasKey("Id"); + + b.HasIndex("VehicleId"); + + b.ToTable("Maintenance"); + }); + + modelBuilder.Entity("OneBus.Domain.Entities.User", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("bigint"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("CreatedAt") + .HasColumnType("timestamp with time zone"); + + b.Property("Email") + .IsRequired() + .HasMaxLength(80) + .IsUnicode(false) + .HasColumnType("character varying(80)"); + + b.Property("IsDeleted") + .HasColumnType("boolean"); + + b.Property("Name") + .IsRequired() + .HasMaxLength(80) + .IsUnicode(false) + .HasColumnType("character varying(80)"); + + b.Property("Password") + .IsRequired() + .HasMaxLength(50) + .IsUnicode(false) + .HasColumnType("character varying(50)"); + + b.Property("Salt") + .IsRequired() + .HasMaxLength(32) + .IsUnicode(false) + .HasColumnType("character varying(32)"); + + b.HasKey("Id"); + + b.ToTable("User"); + + b.HasData( + new + { + Id = 1L, + CreatedAt = new DateTime(2025, 8, 25, 0, 0, 0, 0, DateTimeKind.Utc), + Email = "onebus@admin", + IsDeleted = false, + Name = "Administrador", + Password = "YRT66Z4XEJ2SSNaJVDIXQW7uvC8LSvOxDU1sH/Sr/ic=", + Salt = "c37b6028194d489192aac9391801594a" + }); + }); + + modelBuilder.Entity("OneBus.Domain.Entities.Vehicle", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("bigint"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("AcquisitionDate") + .HasColumnType("date"); + + b.Property("AxesNumber") + .HasColumnType("smallint"); + + b.Property("BodyworkNumber") + .HasMaxLength(20) + .IsUnicode(false) + .HasColumnType("character varying(20)"); + + b.Property("Brand") + .HasColumnType("smallint"); + + b.Property("BusChassisBrand") + .HasColumnType("smallint"); + + b.Property("BusChassisModel") + .HasMaxLength(50) + .IsUnicode(false) + .HasColumnType("character varying(50)"); + + b.Property("BusChassisYear") + .HasColumnType("smallint"); + + b.Property("BusFumigateExpiration") + .HasColumnType("date"); + + b.Property("BusHasLeftDoors") + .HasColumnType("boolean"); + + b.Property("BusHasLowFloor") + .HasColumnType("boolean"); + + b.Property("BusInsuranceExpiration") + .HasColumnType("date"); + + b.Property("BusServiceType") + .HasColumnType("smallint"); + + b.Property("Color") + .HasColumnType("smallint"); + + b.Property("CreatedAt") + .HasColumnType("timestamp with time zone"); + + b.Property("EngineNumber") + .HasMaxLength(20) + .IsUnicode(false) + .HasColumnType("character varying(20)"); + + b.Property("FuelType") + .HasColumnType("smallint"); + + b.Property("HasAccessibility") + .HasColumnType("boolean"); + + b.Property("Image") + .HasColumnType("bytea"); + + b.Property("IpvaExpiration") + .HasColumnType("date"); + + b.Property("IsDeleted") + .HasColumnType("boolean"); + + b.Property("Licensing") + .IsRequired() + .HasMaxLength(50) + .IsUnicode(false) + .HasColumnType("character varying(50)"); + + b.Property("Model") + .IsRequired() + .HasMaxLength(50) + .IsUnicode(false) + .HasColumnType("character varying(50)"); + + b.Property("NumberChassis") + .HasMaxLength(20) + .IsUnicode(false) + .HasColumnType("character varying(20)"); + + b.Property("NumberDoors") + .HasColumnType("smallint"); + + b.Property("NumberSeats") + .HasColumnType("smallint"); + + b.Property("Plate") + .IsRequired() + .HasMaxLength(20) + .IsUnicode(false) + .HasColumnType("character varying(20)"); + + b.Property("Prefix") + .IsRequired() + .HasMaxLength(30) + .IsUnicode(false) + .HasColumnType("character varying(30)"); + + b.Property("Renavam") + .IsRequired() + .HasMaxLength(20) + .IsUnicode(false) + .HasColumnType("character varying(20)"); + + b.Property("Status") + .HasColumnType("smallint"); + + b.Property("TransmissionType") + .HasColumnType("smallint"); + + b.Property("Type") + .HasColumnType("smallint"); + + b.Property("Year") + .HasColumnType("integer"); + + b.HasKey("Id"); + + b.HasIndex("Plate"); + + b.HasIndex("Prefix"); + + b.HasIndex("Renavam"); + + b.ToTable("Vehicle"); + }); + + modelBuilder.Entity("OneBus.Domain.Entities.VehicleOperation", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("bigint"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("CreatedAt") + .HasColumnType("timestamp with time zone"); + + b.Property("Date") + .HasColumnType("date"); + + b.Property("EmployeeWorkdayId") + .HasColumnType("bigint"); + + b.Property("IsDeleted") + .HasColumnType("boolean"); + + b.Property("LineTimeId") + .HasColumnType("bigint"); + + b.Property("VehicleId") + .HasColumnType("bigint"); + + b.HasKey("Id"); + + b.HasIndex("EmployeeWorkdayId"); + + b.HasIndex("LineTimeId"); + + b.HasIndex("VehicleId"); + + b.ToTable("VehicleOperation"); + }); + + modelBuilder.Entity("OneBus.Domain.Entities.EmployeeWorkday", b => + { + b.HasOne("OneBus.Domain.Entities.Employee", "Employee") + .WithMany("EmployeeWorkdays") + .HasForeignKey("EmployeeId") + .OnDelete(DeleteBehavior.Restrict) + .IsRequired(); + + b.Navigation("Employee"); + }); + + modelBuilder.Entity("OneBus.Domain.Entities.LineTime", b => + { + b.HasOne("OneBus.Domain.Entities.Line", "Line") + .WithMany("LineTimes") + .HasForeignKey("LineId") + .OnDelete(DeleteBehavior.Restrict) + .IsRequired(); + + b.Navigation("Line"); + }); + + modelBuilder.Entity("OneBus.Domain.Entities.Maintenance", b => + { + b.HasOne("OneBus.Domain.Entities.Vehicle", "Vehicle") + .WithMany("Maintenances") + .HasForeignKey("VehicleId") + .OnDelete(DeleteBehavior.Restrict) + .IsRequired(); + + b.Navigation("Vehicle"); + }); + + modelBuilder.Entity("OneBus.Domain.Entities.VehicleOperation", b => + { + b.HasOne("OneBus.Domain.Entities.EmployeeWorkday", "EmployeeWorkday") + .WithMany("VehicleOperations") + .HasForeignKey("EmployeeWorkdayId") + .OnDelete(DeleteBehavior.Restrict) + .IsRequired(); + + b.HasOne("OneBus.Domain.Entities.LineTime", "LineTime") + .WithMany("VehicleOperations") + .HasForeignKey("LineTimeId") + .OnDelete(DeleteBehavior.Restrict); + + b.HasOne("OneBus.Domain.Entities.Vehicle", "Vehicle") + .WithMany("VehicleOperations") + .HasForeignKey("VehicleId") + .OnDelete(DeleteBehavior.Restrict) + .IsRequired(); + + b.Navigation("EmployeeWorkday"); + + b.Navigation("LineTime"); + + b.Navigation("Vehicle"); + }); + + modelBuilder.Entity("OneBus.Domain.Entities.Employee", b => + { + b.Navigation("EmployeeWorkdays"); + }); + + modelBuilder.Entity("OneBus.Domain.Entities.EmployeeWorkday", b => + { + b.Navigation("VehicleOperations"); + }); + + modelBuilder.Entity("OneBus.Domain.Entities.Line", b => + { + b.Navigation("LineTimes"); + }); + + modelBuilder.Entity("OneBus.Domain.Entities.LineTime", b => + { + b.Navigation("VehicleOperations"); + }); + + modelBuilder.Entity("OneBus.Domain.Entities.Vehicle", b => + { + b.Navigation("Maintenances"); + + b.Navigation("VehicleOperations"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/OneBus.Infra.Data/Migrations/20251007232852_UpdateLineTableFields.cs b/OneBus.Infra.Data/Migrations/20251007232852_UpdateLineTableFields.cs new file mode 100644 index 0000000..11fbafb --- /dev/null +++ b/OneBus.Infra.Data/Migrations/20251007232852_UpdateLineTableFields.cs @@ -0,0 +1,39 @@ +using Microsoft.EntityFrameworkCore.Migrations; + +#nullable disable + +namespace OneBus.Infra.Data.Migrations +{ + /// + public partial class UpdateLineTableFields : Migration + { + /// + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropColumn( + name: "MaxNumberBuses", + table: "Line"); + + migrationBuilder.RenameColumn( + name: "MinNumberBuses", + table: "Line", + newName: "DirectionType"); + } + + /// + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.RenameColumn( + name: "DirectionType", + table: "Line", + newName: "MinNumberBuses"); + + migrationBuilder.AddColumn( + name: "MaxNumberBuses", + table: "Line", + type: "smallint", + nullable: false, + defaultValue: (byte)0); + } + } +} diff --git a/OneBus.Infra.Data/Migrations/OneBusDbContextModelSnapshot.cs b/OneBus.Infra.Data/Migrations/OneBusDbContextModelSnapshot.cs index a1200e6..abb7ddf 100644 --- a/OneBus.Infra.Data/Migrations/OneBusDbContextModelSnapshot.cs +++ b/OneBus.Infra.Data/Migrations/OneBusDbContextModelSnapshot.cs @@ -153,19 +153,16 @@ protected override void BuildModel(ModelBuilder modelBuilder) b.Property("CreatedAt") .HasColumnType("timestamp with time zone"); + b.Property("DirectionType") + .HasColumnType("smallint"); + b.Property("IsDeleted") .HasColumnType("boolean"); - b.Property("MaxNumberBuses") - .HasColumnType("smallint"); - b.Property("Mileage") .HasPrecision(19, 4) .HasColumnType("numeric(19,4)"); - b.Property("MinNumberBuses") - .HasColumnType("smallint"); - b.Property("Name") .IsRequired() .HasMaxLength(80) From fb7e3e0e05391c53df41c453e98d194e13165c0f Mon Sep 17 00:00:00 2001 From: Eduardo Rezende Date: Tue, 7 Oct 2025 21:14:08 -0300 Subject: [PATCH 44/99] =?UTF-8?q?=E2=99=BB=EF=B8=8Frefactor:=20Update=20Li?= =?UTF-8?q?ne=20Repository?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Adding filtering logic --- .../Interfaces/Repositories/ILineRepository.cs | 2 +- OneBus.Infra.Data/Repositories/LineRepository.cs | 16 +++++++++++++++- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/OneBus.Domain/Interfaces/Repositories/ILineRepository.cs b/OneBus.Domain/Interfaces/Repositories/ILineRepository.cs index a38b2a8..64b52b1 100644 --- a/OneBus.Domain/Interfaces/Repositories/ILineRepository.cs +++ b/OneBus.Domain/Interfaces/Repositories/ILineRepository.cs @@ -3,7 +3,7 @@ namespace OneBus.Domain.Interfaces.Repositories { - public interface ILineRepository : IBaseRepository + public interface ILineRepository : IBaseRepository { } } diff --git a/OneBus.Infra.Data/Repositories/LineRepository.cs b/OneBus.Infra.Data/Repositories/LineRepository.cs index 62d9a9a..d9629c1 100644 --- a/OneBus.Infra.Data/Repositories/LineRepository.cs +++ b/OneBus.Infra.Data/Repositories/LineRepository.cs @@ -2,13 +2,27 @@ 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 LineRepository : BaseRepository, ILineRepository + public class LineRepository : BaseRepository, ILineRepository { public LineRepository(OneBusDbContext dbContext) : base(dbContext) { } + + protected override Expression> ApplyFilter(LineFilter filter) + { + var value = filter.Value?.ToLower(); + + return c => + (filter.Type == null || c.Type == filter.Type) && + (filter.DirectionType == null || c.DirectionType == filter.DirectionType) && + (string.IsNullOrWhiteSpace(value) || + ((c.Name.ToLower().Contains(value) || + c.Mileage.ToString().Contains(value) || + c.Number.ToLower().Contains(value)) && value != string.Empty)); + } } } From 73f79784546258cd91572f22feafde56a636354e Mon Sep 17 00:00:00 2001 From: Eduardo Rezende Date: Tue, 7 Oct 2025 21:14:46 -0300 Subject: [PATCH 45/99] =?UTF-8?q?=E2=99=BB=EF=B8=8Frefactor:=20Update=20Li?= =?UTF-8?q?ne=20DTOs?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Adding fields to the DTOs --- OneBus.Application/DTOs/Line/CreateLineDTO.cs | 17 +++++++++++++++ .../DTOs/Line/ReadDirectionTypeDTO.cs | 14 +++++++++++++ OneBus.Application/DTOs/Line/ReadLineDTO.cs | 21 +++++++++++++++++++ .../DTOs/Line/ReadLineTypeDTO.cs | 14 +++++++++++++ OneBus.Application/DTOs/Line/UpdateLineDTO.cs | 15 +++++++++++++ 5 files changed, 81 insertions(+) create mode 100644 OneBus.Application/DTOs/Line/ReadDirectionTypeDTO.cs create mode 100644 OneBus.Application/DTOs/Line/ReadLineTypeDTO.cs diff --git a/OneBus.Application/DTOs/Line/CreateLineDTO.cs b/OneBus.Application/DTOs/Line/CreateLineDTO.cs index 19b04c0..436353e 100644 --- a/OneBus.Application/DTOs/Line/CreateLineDTO.cs +++ b/OneBus.Application/DTOs/Line/CreateLineDTO.cs @@ -2,5 +2,22 @@ { public class CreateLineDTO : BaseCreateDTO { + public CreateLineDTO() + { + Name = string.Empty; + Number = string.Empty; + } + + public string Number { get; set; } + + public string Name { get; set; } + + public byte Type { get; set; } + + public TimeOnly TravelTime { get; set; } + + public decimal Mileage { get; set; } + + public byte DirectionType { get; set; } } } diff --git a/OneBus.Application/DTOs/Line/ReadDirectionTypeDTO.cs b/OneBus.Application/DTOs/Line/ReadDirectionTypeDTO.cs new file mode 100644 index 0000000..48c9475 --- /dev/null +++ b/OneBus.Application/DTOs/Line/ReadDirectionTypeDTO.cs @@ -0,0 +1,14 @@ +namespace OneBus.Application.DTOs.Line +{ + public class ReadDirectionTypeDTO + { + public ReadDirectionTypeDTO() + { + Name = string.Empty; + } + + public byte Value { get; set; } + + public string Name { get; set; } + } +} diff --git a/OneBus.Application/DTOs/Line/ReadLineDTO.cs b/OneBus.Application/DTOs/Line/ReadLineDTO.cs index 4ee74db..6bfaa01 100644 --- a/OneBus.Application/DTOs/Line/ReadLineDTO.cs +++ b/OneBus.Application/DTOs/Line/ReadLineDTO.cs @@ -2,5 +2,26 @@ { public class ReadLineDTO : BaseReadDTO { + public ReadLineDTO() + { + Name = string.Empty; + Number = string.Empty; + } + + public string Number { get; set; } + + public string Name { get; set; } + + public byte Type { get; set; } + + public string? TypeName { get; set; } + + public TimeOnly TravelTime { get; set; } + + public decimal Mileage { get; set; } + + public byte DirectionType { get; set; } + + public string? DirectionTypeName { get; set; } } } diff --git a/OneBus.Application/DTOs/Line/ReadLineTypeDTO.cs b/OneBus.Application/DTOs/Line/ReadLineTypeDTO.cs new file mode 100644 index 0000000..cf1422d --- /dev/null +++ b/OneBus.Application/DTOs/Line/ReadLineTypeDTO.cs @@ -0,0 +1,14 @@ +namespace OneBus.Application.DTOs.Line +{ + public class ReadLineTypeDTO + { + public ReadLineTypeDTO() + { + Name = string.Empty; + } + + public byte Value { get; set; } + + public string Name { get; set; } + } +} diff --git a/OneBus.Application/DTOs/Line/UpdateLineDTO.cs b/OneBus.Application/DTOs/Line/UpdateLineDTO.cs index 7b7fc44..ddfa457 100644 --- a/OneBus.Application/DTOs/Line/UpdateLineDTO.cs +++ b/OneBus.Application/DTOs/Line/UpdateLineDTO.cs @@ -2,5 +2,20 @@ { public class UpdateLineDTO : BaseUpdateDTO { + public UpdateLineDTO() + { + Name = string.Empty; + Number = string.Empty; + } + + public string Number { get; set; } + + public string Name { get; set; } + + public TimeOnly TravelTime { get; set; } + + public decimal Mileage { get; set; } + + public byte DirectionType { get; set; } } } From 2924879554e5b5151f57bdabfd547a092eee4e5a Mon Sep 17 00:00:00 2001 From: Eduardo Rezende Date: Tue, 7 Oct 2025 21:17:25 -0300 Subject: [PATCH 46/99] =?UTF-8?q?=E2=99=BB=EF=B8=8Frefactor:=20Update=20Li?= =?UTF-8?q?ne=20Service?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Adding GET methods logic --- .../Interfaces/Services/ILineService.cs | 7 +- OneBus.Application/Services/LineService.cs | 78 ++++++++++++++++++- 2 files changed, 80 insertions(+), 5 deletions(-) diff --git a/OneBus.Application/Interfaces/Services/ILineService.cs b/OneBus.Application/Interfaces/Services/ILineService.cs index c51fd07..4ada52f 100644 --- a/OneBus.Application/Interfaces/Services/ILineService.cs +++ b/OneBus.Application/Interfaces/Services/ILineService.cs @@ -1,11 +1,14 @@ using OneBus.Application.DTOs.Line; +using OneBus.Domain.Commons.Result; using OneBus.Domain.Entities; using OneBus.Domain.Filters; namespace OneBus.Application.Interfaces.Services { - public interface ILineService : - IBaseService + public interface ILineService : + IBaseService { + Result> GetDirectionTypes(); + Result> GetLineTypes(); } } diff --git a/OneBus.Application/Services/LineService.cs b/OneBus.Application/Services/LineService.cs index c46d45d..3924819 100644 --- a/OneBus.Application/Services/LineService.cs +++ b/OneBus.Application/Services/LineService.cs @@ -1,26 +1,98 @@ using FluentValidation; using OneBus.Application.DTOs.Line; using OneBus.Application.Interfaces.Services; +using OneBus.Domain.Commons; +using OneBus.Domain.Commons.Result; using OneBus.Domain.Entities; +using OneBus.Domain.Enums.Line; +using OneBus.Domain.Extensions; using OneBus.Domain.Filters; using OneBus.Domain.Interfaces.Repositories; namespace OneBus.Application.Services { - public class LineService : BaseService, + public class LineService : BaseService, ILineService { public LineService( - IBaseRepository baseRepository, + IBaseRepository baseRepository, IValidator createValidator, IValidator updateValidator) : base(baseRepository, createValidator, updateValidator) { } + public override async Task>> GetPaginedAsync( + LineFilter filter, + DbQueryOptions? dbQueryOptions = null, + CancellationToken cancellationToken = default) + { + var result = await base.GetPaginedAsync(filter, cancellationToken: cancellationToken); + + if (!result.Sucess) + return result; + + foreach (var line in result.Value!.Items) + { + line.TypeName = ((LineType)line.Type).ToString().Localize(); + line.DirectionTypeName = ((DirectionType)line.DirectionType).ToString().Localize(); + } + + return result; + } + + public override async Task> GetByIdAsync( + long id, + DbQueryOptions? dbQueryOptions = null, + CancellationToken cancellationToken = default) + { + var result = await base.GetByIdAsync(id, cancellationToken: cancellationToken); + + if (!result.Sucess) + return result; + + var line = result.Value!; + line.TypeName = ((LineType)line.Type).ToString().Localize(); + line.DirectionTypeName = ((DirectionType)line.DirectionType).ToString().Localize(); + + return result; + } + + public Result> GetLineTypes() + { + var values = Enum.GetValues(); + + List status = []; + + foreach (var value in values) + { + status.Add(new ReadLineTypeDTO { Value = (byte)value, Name = value.ToString().Localize() }); + } + + return SuccessResult>.Create(status); + } + + public Result> GetDirectionTypes() + { + var values = Enum.GetValues(); + + List status = []; + + foreach (var value in values) + { + status.Add(new ReadDirectionTypeDTO { Value = (byte)value, Name = value.ToString().Localize() }); + } + + return SuccessResult>.Create(status); + } + protected override void UpdateFields(Line entity, UpdateLineDTO updateDTO) { - throw new NotImplementedException(); + entity.Name = updateDTO.Name; + entity.Number = updateDTO.Number; + entity.Mileage = updateDTO.Mileage; + entity.TravelTime = updateDTO.TravelTime; + entity.DirectionType = updateDTO.DirectionType; } } } From 039f3a3d6e43b0e66704f820aeaa1d60ff0a1ad8 Mon Sep 17 00:00:00 2001 From: Eduardo Rezende Date: Tue, 7 Oct 2025 21:17:50 -0300 Subject: [PATCH 47/99] =?UTF-8?q?=E2=99=BB=EF=B8=8Frefactor:=20Update=20Li?= =?UTF-8?q?ne=20Validators?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Adding validations logic --- .../Validators/Line/CreateLineDTOValidator.cs | 34 +++++++++++++++++ .../Validators/Line/UpdateLineDTOValidator.cs | 37 +++++++++++++++++++ 2 files changed, 71 insertions(+) diff --git a/OneBus.Application/Validators/Line/CreateLineDTOValidator.cs b/OneBus.Application/Validators/Line/CreateLineDTOValidator.cs index f1d032b..d4148ee 100644 --- a/OneBus.Application/Validators/Line/CreateLineDTOValidator.cs +++ b/OneBus.Application/Validators/Line/CreateLineDTOValidator.cs @@ -1,9 +1,43 @@ using FluentValidation; using OneBus.Application.DTOs.Line; +using OneBus.Domain.Commons; +using OneBus.Domain.Enums.Line; +using OneBus.Domain.Interfaces.Repositories; +using OneBus.Domain.Utils; namespace OneBus.Application.Validators.Line { public class CreateLineDTOValidator : AbstractValidator { + private readonly ILineRepository _lineRepository; + + public CreateLineDTOValidator(ILineRepository lineRepository) + { + _lineRepository = lineRepository; + + RuleFor(c => c.Type) + .Must(ValidationUtils.IsValidEnumValue) + .OverridePropertyName("Tipo"); + + RuleFor(c => c.DirectionType) + .Must(ValidationUtils.IsValidEnumValue) + .OverridePropertyName("Tipo de Direção"); + + RuleFor(c => c.Number) + .MustAsync(async (line, number, ct) => !await IsNumberInUse(number, line.Type, ct)) + .WithMessage(ErrorUtils.AlreadyExists("Número").Message) + .NotEmpty() + .OverridePropertyName("Número"); + + RuleFor(c => c.Name) + .NotEmpty() + .OverridePropertyName("Nome"); + } + + private async Task IsNumberInUse(string number, byte type, CancellationToken cancellationToken = default) + { + return await _lineRepository.AnyAsync(c => c.Number.ToLower().Equals(number.ToLower()) && c.Type == type, + cancellationToken: cancellationToken); + } } } diff --git a/OneBus.Application/Validators/Line/UpdateLineDTOValidator.cs b/OneBus.Application/Validators/Line/UpdateLineDTOValidator.cs index e74b13b..265f0f1 100644 --- a/OneBus.Application/Validators/Line/UpdateLineDTOValidator.cs +++ b/OneBus.Application/Validators/Line/UpdateLineDTOValidator.cs @@ -1,9 +1,46 @@ using FluentValidation; using OneBus.Application.DTOs.Line; +using OneBus.Domain.Commons; +using OneBus.Domain.Enums.Line; +using OneBus.Domain.Interfaces.Repositories; +using OneBus.Domain.Utils; namespace OneBus.Application.Validators.Line { public class UpdateLineDTOValidator : AbstractValidator { + private readonly ILineRepository _lineRepository; + + public UpdateLineDTOValidator(ILineRepository lineRepository) + { + _lineRepository = lineRepository; + + RuleFor(c => c.Id).GreaterThan(0); + + RuleFor(c => c.DirectionType) + .Must(ValidationUtils.IsValidEnumValue) + .OverridePropertyName("Tipo de Direção"); + + RuleFor(c => c.Number) + .MustAsync(async (line, number, ct) => !await IsNumberInUse(line.Id, number, ct)) + .WithMessage(ErrorUtils.AlreadyExists("Número").Message) + .NotEmpty() + .OverridePropertyName("Número"); + + RuleFor(c => c.Name) + .NotEmpty() + .OverridePropertyName("Nome"); + } + + private async Task IsNumberInUse(long id, string number, CancellationToken cancellationToken = default) + { + var line = await _lineRepository.GetOneAsync(c => c.Id == id, cancellationToken: cancellationToken); + + if (line is null) + return false; + + return await _lineRepository.AnyAsync(c => c.Number.ToLower().Equals(number.ToLower()) && c.Type == line.Type && c.Id != id, + cancellationToken: cancellationToken); + } } } From 233f7dbdedee8cd89ef08106722045c1ad60cff8 Mon Sep 17 00:00:00 2001 From: Eduardo Rezende Date: Tue, 7 Oct 2025 21:18:36 -0300 Subject: [PATCH 48/99] =?UTF-8?q?=E2=99=BB=EF=B8=8Frefactor:=20Update=20Li?= =?UTF-8?q?ne=20Controller?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Adding GET endpoints for direction types and types --- OneBus.API/Controllers/LineController.cs | 33 ++++++++++++++++++++++-- 1 file changed, 31 insertions(+), 2 deletions(-) diff --git a/OneBus.API/Controllers/LineController.cs b/OneBus.API/Controllers/LineController.cs index 029d3ea..10ae33a 100644 --- a/OneBus.API/Controllers/LineController.cs +++ b/OneBus.API/Controllers/LineController.cs @@ -10,7 +10,6 @@ namespace OneBus.API.Controllers { - [NonController] [Route("api/v1/lines")] [ApiController] [Produces("application/json")] @@ -102,7 +101,7 @@ public async Task DeleteAsync([FromRoute] long id, CancellationTo /// Linhas paginadas e filtradas com sucesso [HttpGet] [ProducesResponseType(typeof(SuccessResult>), StatusCodes.Status200OK)] - public async Task GetPaginedAsync([FromQuery] BaseFilter filter, CancellationToken cancellationToken = default) + public async Task GetPaginedAsync([FromQuery] LineFilter filter, CancellationToken cancellationToken = default) { return (await _lineService.GetPaginedAsync(filter, cancellationToken: cancellationToken)).ToActionResult(); } @@ -125,5 +124,35 @@ public async Task GetByIdAsync([FromRoute] long id, CancellationT { return (await _lineService.GetByIdAsync(id, cancellationToken: cancellationToken)).ToActionResult(); } + + /// + /// Listar tipos de linhas + /// + /// + /// GET de tipos de linhas + /// + /// Tipos de linhas disponíveis + /// Tipos de linhas retornadas com sucesso + [HttpGet("types")] + [ProducesResponseType(typeof(SuccessResult>), StatusCodes.Status200OK)] + public IActionResult GetVehicleTypes() + { + return _lineService.GetLineTypes().ToActionResult(); + } + + /// + /// Listar tipos de direção + /// + /// + /// GET de tipos de direção + /// + /// Tipos de direção disponíveis + /// Tipos de direção retornadas com sucesso + [HttpGet("directionTypes")] + [ProducesResponseType(typeof(SuccessResult>), StatusCodes.Status200OK)] + public IActionResult GetDirectionTypes() + { + return _lineService.GetDirectionTypes().ToActionResult(); + } } } From 434a24c98ff15e4174f6a2e8b08c9fb84d4cd10d Mon Sep 17 00:00:00 2001 From: Eduardo Rezende Date: Thu, 23 Oct 2025 20:59:49 -0300 Subject: [PATCH 49/99] =?UTF-8?q?=E2=99=BB=EF=B8=8Frefactor:=20Update=20pr?= =?UTF-8?q?ojects=20packages?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Updating nuget packages --- OneBus.API/OneBus.API.csproj | 6 +++--- OneBus.Application/OneBus.Application.csproj | 2 +- OneBus.Infra.Data/OneBus.Infra.Data.csproj | 6 +++--- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/OneBus.API/OneBus.API.csproj b/OneBus.API/OneBus.API.csproj index a5f1f82..f7ffcd0 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 eee47b5..e9d26ee 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 f78bd31..a6f0fe5 100644 --- a/OneBus.Infra.Data/OneBus.Infra.Data.csproj +++ b/OneBus.Infra.Data/OneBus.Infra.Data.csproj @@ -7,16 +7,16 @@ - + all runtime; build; native; contentfiles; analyzers; buildtransitive - + all runtime; build; native; contentfiles; analyzers; buildtransitive - + From 29382f878e639defcc75c3e5b0c6c9cfc8c7cf06 Mon Sep 17 00:00:00 2001 From: Eduardo Rezende Date: Thu, 23 Oct 2025 21:04:47 -0300 Subject: [PATCH 50/99] =?UTF-8?q?=E2=99=BB=EF=B8=8Frefactor:=20Update=20Li?= =?UTF-8?q?ne=20Validators?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Updating validation over Number field --- .../Validators/Line/CreateLineDTOValidator.cs | 6 +++--- .../Validators/Line/UpdateLineDTOValidator.cs | 3 ++- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/OneBus.Application/Validators/Line/CreateLineDTOValidator.cs b/OneBus.Application/Validators/Line/CreateLineDTOValidator.cs index d4148ee..9d4ef5f 100644 --- a/OneBus.Application/Validators/Line/CreateLineDTOValidator.cs +++ b/OneBus.Application/Validators/Line/CreateLineDTOValidator.cs @@ -24,7 +24,7 @@ public CreateLineDTOValidator(ILineRepository lineRepository) .OverridePropertyName("Tipo de Direção"); RuleFor(c => c.Number) - .MustAsync(async (line, number, ct) => !await IsNumberInUse(number, line.Type, ct)) + .MustAsync(async (line, number, ct) => !await IsNumberInUse(number, line.Type, line.DirectionType, ct)) .WithMessage(ErrorUtils.AlreadyExists("Número").Message) .NotEmpty() .OverridePropertyName("Número"); @@ -34,9 +34,9 @@ public CreateLineDTOValidator(ILineRepository lineRepository) .OverridePropertyName("Nome"); } - private async Task IsNumberInUse(string number, byte type, CancellationToken cancellationToken = default) + private async Task IsNumberInUse(string number, byte type, byte directionType, CancellationToken cancellationToken = default) { - return await _lineRepository.AnyAsync(c => c.Number.ToLower().Equals(number.ToLower()) && c.Type == type, + return await _lineRepository.AnyAsync(c => c.Number.ToLower().Equals(number.ToLower()) && c.Type == type && c.DirectionType == directionType, cancellationToken: cancellationToken); } } diff --git a/OneBus.Application/Validators/Line/UpdateLineDTOValidator.cs b/OneBus.Application/Validators/Line/UpdateLineDTOValidator.cs index 265f0f1..4bd7ba4 100644 --- a/OneBus.Application/Validators/Line/UpdateLineDTOValidator.cs +++ b/OneBus.Application/Validators/Line/UpdateLineDTOValidator.cs @@ -39,7 +39,8 @@ private async Task IsNumberInUse(long id, string number, CancellationToken if (line is null) return false; - return await _lineRepository.AnyAsync(c => c.Number.ToLower().Equals(number.ToLower()) && c.Type == line.Type && c.Id != id, + return await _lineRepository.AnyAsync(c => c.Number.ToLower().Equals(number.ToLower()) && + c.Type == line.Type && c.DirectionType == line.DirectionType && c.Id != id, cancellationToken: cancellationToken); } } From 94fb294945a9223a97c6332f1fe0cee6f9b04d99 Mon Sep 17 00:00:00 2001 From: Eduardo Rezende Date: Thu, 23 Oct 2025 21:46:42 -0300 Subject: [PATCH 51/99] =?UTF-8?q?=E2=9C=A8feat:=20Add=20LineTimeFilter?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Adding filtering fields --- OneBus.Domain/Filters/LineTimeFilter.cs | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 OneBus.Domain/Filters/LineTimeFilter.cs diff --git a/OneBus.Domain/Filters/LineTimeFilter.cs b/OneBus.Domain/Filters/LineTimeFilter.cs new file mode 100644 index 0000000..177411f --- /dev/null +++ b/OneBus.Domain/Filters/LineTimeFilter.cs @@ -0,0 +1,9 @@ +namespace OneBus.Domain.Filters +{ + public class LineTimeFilter : BaseFilter + { + public byte? DirectionType { get; set; } + + public byte? DayType { get; set; } + } +} From 77b913688248e80658b088a96434047a5f7e36ef Mon Sep 17 00:00:00 2001 From: Eduardo Rezende Date: Thu, 23 Oct 2025 21:47:47 -0300 Subject: [PATCH 52/99] =?UTF-8?q?=E2=99=BB=EF=B8=8Frefactor:=20Update=20Li?= =?UTF-8?q?neTime=20Entity?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Updating entity fieds --- OneBus.Domain/Entities/LineTime.cs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/OneBus.Domain/Entities/LineTime.cs b/OneBus.Domain/Entities/LineTime.cs index f2baab9..cf59831 100644 --- a/OneBus.Domain/Entities/LineTime.cs +++ b/OneBus.Domain/Entities/LineTime.cs @@ -4,12 +4,12 @@ public class LineTime : BaseEntity { public long LineId { get; set; } - public TimeOnly StartTime { get; set; } - - public TimeOnly EndTime { get; set; } - + public TimeOnly Time { get; set; } + public byte DayType { get; set; } + public byte DirectionType { get; set; } + public Line? Line { get; set; } public ICollection? VehicleOperations { get; set; } From 07c0da3975f302696ad010db23c9e239b647cee7 Mon Sep 17 00:00:00 2001 From: Eduardo Rezende Date: Thu, 23 Oct 2025 21:48:21 -0300 Subject: [PATCH 53/99] =?UTF-8?q?=E2=9C=A8feat:=20Add=20Migration?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Updating LineTime table fields --- ...024001111_UpdateLineTimeFields.Designer.cs | 589 ++++++++++++++++++ .../20251024001111_UpdateLineTimeFields.cs | 51 ++ .../OneBusDbContextModelSnapshot.cs | 8 +- 3 files changed, 644 insertions(+), 4 deletions(-) create mode 100644 OneBus.Infra.Data/Migrations/20251024001111_UpdateLineTimeFields.Designer.cs create mode 100644 OneBus.Infra.Data/Migrations/20251024001111_UpdateLineTimeFields.cs diff --git a/OneBus.Infra.Data/Migrations/20251024001111_UpdateLineTimeFields.Designer.cs b/OneBus.Infra.Data/Migrations/20251024001111_UpdateLineTimeFields.Designer.cs new file mode 100644 index 0000000..0423f24 --- /dev/null +++ b/OneBus.Infra.Data/Migrations/20251024001111_UpdateLineTimeFields.Designer.cs @@ -0,0 +1,589 @@ +// +using System; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; +using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; +using OneBus.Infra.Data.DbContexts; + +#nullable disable + +namespace OneBus.Infra.Data.Migrations +{ + [DbContext(typeof(OneBusDbContext))] + [Migration("20251024001111_UpdateLineTimeFields")] + partial class UpdateLineTimeFields + { + /// + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("ProductVersion", "9.0.10") + .HasAnnotation("Relational:MaxIdentifierLength", 63); + + NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder); + + modelBuilder.Entity("OneBus.Domain.Entities.Employee", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("bigint"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("BloodType") + .HasColumnType("smallint"); + + b.Property("CnhCategory") + .HasColumnType("smallint"); + + b.Property("CnhExpiration") + .HasColumnType("date"); + + b.Property("CnhNumber") + .HasMaxLength(20) + .IsUnicode(false) + .HasColumnType("character varying(20)"); + + b.Property("Code") + .IsRequired() + .HasMaxLength(30) + .IsUnicode(false) + .HasColumnType("character varying(30)"); + + b.Property("Cpf") + .IsRequired() + .HasMaxLength(20) + .IsUnicode(false) + .HasColumnType("character varying(20)"); + + b.Property("CreatedAt") + .HasColumnType("timestamp with time zone"); + + b.Property("Email") + .IsRequired() + .HasMaxLength(80) + .IsUnicode(false) + .HasColumnType("character varying(80)"); + + b.Property("HiringDate") + .HasColumnType("date"); + + b.Property("Image") + .HasColumnType("bytea"); + + b.Property("IsDeleted") + .HasColumnType("boolean"); + + b.Property("Name") + .IsRequired() + .HasMaxLength(80) + .IsUnicode(false) + .HasColumnType("character varying(80)"); + + b.Property("Phone") + .IsRequired() + .HasMaxLength(20) + .IsUnicode(false) + .HasColumnType("character varying(20)"); + + b.Property("Rg") + .IsRequired() + .HasMaxLength(20) + .IsUnicode(false) + .HasColumnType("character varying(20)"); + + b.Property("Role") + .HasColumnType("smallint"); + + b.Property("Status") + .HasColumnType("smallint"); + + b.HasKey("Id"); + + b.HasIndex("CnhNumber"); + + b.HasIndex("Code"); + + b.HasIndex("Cpf"); + + b.ToTable("Employee"); + }); + + modelBuilder.Entity("OneBus.Domain.Entities.EmployeeWorkday", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("bigint"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("CreatedAt") + .HasColumnType("timestamp with time zone"); + + b.Property("DayType") + .HasColumnType("smallint"); + + b.Property("EmployeeId") + .HasColumnType("bigint"); + + b.Property("EndTime") + .HasColumnType("time without time zone"); + + b.Property("IsDeleted") + .HasColumnType("boolean"); + + b.Property("StartTime") + .HasColumnType("time without time zone"); + + b.HasKey("Id"); + + b.HasIndex("EmployeeId"); + + b.ToTable("EmployeeWorkday"); + }); + + modelBuilder.Entity("OneBus.Domain.Entities.Line", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("bigint"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("CreatedAt") + .HasColumnType("timestamp with time zone"); + + b.Property("DirectionType") + .HasColumnType("smallint"); + + b.Property("IsDeleted") + .HasColumnType("boolean"); + + b.Property("Mileage") + .HasPrecision(19, 4) + .HasColumnType("numeric(19,4)"); + + b.Property("Name") + .IsRequired() + .HasMaxLength(80) + .IsUnicode(false) + .HasColumnType("character varying(80)"); + + b.Property("Number") + .IsRequired() + .HasMaxLength(20) + .IsUnicode(false) + .HasColumnType("character varying(20)"); + + b.Property("TravelTime") + .HasColumnType("time without time zone"); + + b.Property("Type") + .HasColumnType("smallint"); + + b.HasKey("Id"); + + b.ToTable("Line"); + }); + + modelBuilder.Entity("OneBus.Domain.Entities.LineTime", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("bigint"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("CreatedAt") + .HasColumnType("timestamp with time zone"); + + b.Property("DayType") + .HasColumnType("smallint"); + + b.Property("DirectionType") + .HasColumnType("smallint"); + + b.Property("IsDeleted") + .HasColumnType("boolean"); + + b.Property("LineId") + .HasColumnType("bigint"); + + b.Property("Time") + .HasColumnType("time without time zone"); + + b.HasKey("Id"); + + b.HasIndex("LineId"); + + b.ToTable("LineTime"); + }); + + modelBuilder.Entity("OneBus.Domain.Entities.Maintenance", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("bigint"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("Cost") + .HasPrecision(19, 4) + .HasColumnType("numeric(19,4)"); + + b.Property("CreatedAt") + .HasColumnType("timestamp with time zone"); + + b.Property("Description") + .IsRequired() + .HasMaxLength(150) + .IsUnicode(false) + .HasColumnType("character varying(150)"); + + b.Property("EndDate") + .HasColumnType("date"); + + b.Property("IsDeleted") + .HasColumnType("boolean"); + + b.Property("Sector") + .HasColumnType("smallint"); + + b.Property("StartDate") + .HasColumnType("date"); + + b.Property("SurveyExpiration") + .HasColumnType("date"); + + b.Property("VehicleId") + .HasColumnType("bigint"); + + b.HasKey("Id"); + + b.HasIndex("VehicleId"); + + b.ToTable("Maintenance"); + }); + + modelBuilder.Entity("OneBus.Domain.Entities.User", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("bigint"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("CreatedAt") + .HasColumnType("timestamp with time zone"); + + b.Property("Email") + .IsRequired() + .HasMaxLength(80) + .IsUnicode(false) + .HasColumnType("character varying(80)"); + + b.Property("IsDeleted") + .HasColumnType("boolean"); + + b.Property("Name") + .IsRequired() + .HasMaxLength(80) + .IsUnicode(false) + .HasColumnType("character varying(80)"); + + b.Property("Password") + .IsRequired() + .HasMaxLength(50) + .IsUnicode(false) + .HasColumnType("character varying(50)"); + + b.Property("Salt") + .IsRequired() + .HasMaxLength(32) + .IsUnicode(false) + .HasColumnType("character varying(32)"); + + b.HasKey("Id"); + + b.ToTable("User"); + + b.HasData( + new + { + Id = 1L, + CreatedAt = new DateTime(2025, 8, 25, 0, 0, 0, 0, DateTimeKind.Utc), + Email = "onebus@admin", + IsDeleted = false, + Name = "Administrador", + Password = "YRT66Z4XEJ2SSNaJVDIXQW7uvC8LSvOxDU1sH/Sr/ic=", + Salt = "c37b6028194d489192aac9391801594a" + }); + }); + + modelBuilder.Entity("OneBus.Domain.Entities.Vehicle", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("bigint"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("AcquisitionDate") + .HasColumnType("date"); + + b.Property("AxesNumber") + .HasColumnType("smallint"); + + b.Property("BodyworkNumber") + .HasMaxLength(20) + .IsUnicode(false) + .HasColumnType("character varying(20)"); + + b.Property("Brand") + .HasColumnType("smallint"); + + b.Property("BusChassisBrand") + .HasColumnType("smallint"); + + b.Property("BusChassisModel") + .HasMaxLength(50) + .IsUnicode(false) + .HasColumnType("character varying(50)"); + + b.Property("BusChassisYear") + .HasColumnType("smallint"); + + b.Property("BusFumigateExpiration") + .HasColumnType("date"); + + b.Property("BusHasLeftDoors") + .HasColumnType("boolean"); + + b.Property("BusHasLowFloor") + .HasColumnType("boolean"); + + b.Property("BusInsuranceExpiration") + .HasColumnType("date"); + + b.Property("BusServiceType") + .HasColumnType("smallint"); + + b.Property("Color") + .HasColumnType("smallint"); + + b.Property("CreatedAt") + .HasColumnType("timestamp with time zone"); + + b.Property("EngineNumber") + .HasMaxLength(20) + .IsUnicode(false) + .HasColumnType("character varying(20)"); + + b.Property("FuelType") + .HasColumnType("smallint"); + + b.Property("HasAccessibility") + .HasColumnType("boolean"); + + b.Property("Image") + .HasColumnType("bytea"); + + b.Property("IpvaExpiration") + .HasColumnType("date"); + + b.Property("IsDeleted") + .HasColumnType("boolean"); + + b.Property("Licensing") + .IsRequired() + .HasMaxLength(50) + .IsUnicode(false) + .HasColumnType("character varying(50)"); + + b.Property("Model") + .IsRequired() + .HasMaxLength(50) + .IsUnicode(false) + .HasColumnType("character varying(50)"); + + b.Property("NumberChassis") + .HasMaxLength(20) + .IsUnicode(false) + .HasColumnType("character varying(20)"); + + b.Property("NumberDoors") + .HasColumnType("smallint"); + + b.Property("NumberSeats") + .HasColumnType("smallint"); + + b.Property("Plate") + .IsRequired() + .HasMaxLength(20) + .IsUnicode(false) + .HasColumnType("character varying(20)"); + + b.Property("Prefix") + .IsRequired() + .HasMaxLength(30) + .IsUnicode(false) + .HasColumnType("character varying(30)"); + + b.Property("Renavam") + .IsRequired() + .HasMaxLength(20) + .IsUnicode(false) + .HasColumnType("character varying(20)"); + + b.Property("Status") + .HasColumnType("smallint"); + + b.Property("TransmissionType") + .HasColumnType("smallint"); + + b.Property("Type") + .HasColumnType("smallint"); + + b.Property("Year") + .HasColumnType("integer"); + + b.HasKey("Id"); + + b.HasIndex("Plate"); + + b.HasIndex("Prefix"); + + b.HasIndex("Renavam"); + + b.ToTable("Vehicle"); + }); + + modelBuilder.Entity("OneBus.Domain.Entities.VehicleOperation", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("bigint"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("CreatedAt") + .HasColumnType("timestamp with time zone"); + + b.Property("Date") + .HasColumnType("date"); + + b.Property("EmployeeWorkdayId") + .HasColumnType("bigint"); + + b.Property("IsDeleted") + .HasColumnType("boolean"); + + b.Property("LineTimeId") + .HasColumnType("bigint"); + + b.Property("VehicleId") + .HasColumnType("bigint"); + + b.HasKey("Id"); + + b.HasIndex("EmployeeWorkdayId"); + + b.HasIndex("LineTimeId"); + + b.HasIndex("VehicleId"); + + b.ToTable("VehicleOperation"); + }); + + modelBuilder.Entity("OneBus.Domain.Entities.EmployeeWorkday", b => + { + b.HasOne("OneBus.Domain.Entities.Employee", "Employee") + .WithMany("EmployeeWorkdays") + .HasForeignKey("EmployeeId") + .OnDelete(DeleteBehavior.Restrict) + .IsRequired(); + + b.Navigation("Employee"); + }); + + modelBuilder.Entity("OneBus.Domain.Entities.LineTime", b => + { + b.HasOne("OneBus.Domain.Entities.Line", "Line") + .WithMany("LineTimes") + .HasForeignKey("LineId") + .OnDelete(DeleteBehavior.Restrict) + .IsRequired(); + + b.Navigation("Line"); + }); + + modelBuilder.Entity("OneBus.Domain.Entities.Maintenance", b => + { + b.HasOne("OneBus.Domain.Entities.Vehicle", "Vehicle") + .WithMany("Maintenances") + .HasForeignKey("VehicleId") + .OnDelete(DeleteBehavior.Restrict) + .IsRequired(); + + b.Navigation("Vehicle"); + }); + + modelBuilder.Entity("OneBus.Domain.Entities.VehicleOperation", b => + { + b.HasOne("OneBus.Domain.Entities.EmployeeWorkday", "EmployeeWorkday") + .WithMany("VehicleOperations") + .HasForeignKey("EmployeeWorkdayId") + .OnDelete(DeleteBehavior.Restrict) + .IsRequired(); + + b.HasOne("OneBus.Domain.Entities.LineTime", "LineTime") + .WithMany("VehicleOperations") + .HasForeignKey("LineTimeId") + .OnDelete(DeleteBehavior.Restrict); + + b.HasOne("OneBus.Domain.Entities.Vehicle", "Vehicle") + .WithMany("VehicleOperations") + .HasForeignKey("VehicleId") + .OnDelete(DeleteBehavior.Restrict) + .IsRequired(); + + b.Navigation("EmployeeWorkday"); + + b.Navigation("LineTime"); + + b.Navigation("Vehicle"); + }); + + modelBuilder.Entity("OneBus.Domain.Entities.Employee", b => + { + b.Navigation("EmployeeWorkdays"); + }); + + modelBuilder.Entity("OneBus.Domain.Entities.EmployeeWorkday", b => + { + b.Navigation("VehicleOperations"); + }); + + modelBuilder.Entity("OneBus.Domain.Entities.Line", b => + { + b.Navigation("LineTimes"); + }); + + modelBuilder.Entity("OneBus.Domain.Entities.LineTime", b => + { + b.Navigation("VehicleOperations"); + }); + + modelBuilder.Entity("OneBus.Domain.Entities.Vehicle", b => + { + b.Navigation("Maintenances"); + + b.Navigation("VehicleOperations"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/OneBus.Infra.Data/Migrations/20251024001111_UpdateLineTimeFields.cs b/OneBus.Infra.Data/Migrations/20251024001111_UpdateLineTimeFields.cs new file mode 100644 index 0000000..ad2928e --- /dev/null +++ b/OneBus.Infra.Data/Migrations/20251024001111_UpdateLineTimeFields.cs @@ -0,0 +1,51 @@ +using System; +using Microsoft.EntityFrameworkCore.Migrations; + +#nullable disable + +namespace OneBus.Infra.Data.Migrations +{ + /// + public partial class UpdateLineTimeFields : Migration + { + /// + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropColumn( + name: "EndTime", + table: "LineTime"); + + migrationBuilder.RenameColumn( + name: "StartTime", + table: "LineTime", + newName: "Time"); + + migrationBuilder.AddColumn( + name: "DirectionType", + table: "LineTime", + type: "smallint", + nullable: false, + defaultValue: (byte)0); + } + + /// + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropColumn( + name: "DirectionType", + table: "LineTime"); + + migrationBuilder.RenameColumn( + name: "Time", + table: "LineTime", + newName: "StartTime"); + + migrationBuilder.AddColumn( + name: "EndTime", + table: "LineTime", + type: "time without time zone", + nullable: false, + defaultValue: new TimeOnly(0, 0, 0)); + } + } +} diff --git a/OneBus.Infra.Data/Migrations/OneBusDbContextModelSnapshot.cs b/OneBus.Infra.Data/Migrations/OneBusDbContextModelSnapshot.cs index abb7ddf..f73050b 100644 --- a/OneBus.Infra.Data/Migrations/OneBusDbContextModelSnapshot.cs +++ b/OneBus.Infra.Data/Migrations/OneBusDbContextModelSnapshot.cs @@ -17,7 +17,7 @@ protected override void BuildModel(ModelBuilder modelBuilder) { #pragma warning disable 612, 618 modelBuilder - .HasAnnotation("ProductVersion", "9.0.9") + .HasAnnotation("ProductVersion", "9.0.10") .HasAnnotation("Relational:MaxIdentifierLength", 63); NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder); @@ -200,8 +200,8 @@ protected override void BuildModel(ModelBuilder modelBuilder) b.Property("DayType") .HasColumnType("smallint"); - b.Property("EndTime") - .HasColumnType("time without time zone"); + b.Property("DirectionType") + .HasColumnType("smallint"); b.Property("IsDeleted") .HasColumnType("boolean"); @@ -209,7 +209,7 @@ protected override void BuildModel(ModelBuilder modelBuilder) b.Property("LineId") .HasColumnType("bigint"); - b.Property("StartTime") + b.Property("Time") .HasColumnType("time without time zone"); b.HasKey("Id"); From 956b87e9d7d774d8a293d3404418eb065aa6e137 Mon Sep 17 00:00:00 2001 From: Eduardo Rezende Date: Thu, 23 Oct 2025 21:48:53 -0300 Subject: [PATCH 54/99] =?UTF-8?q?=E2=99=BB=EF=B8=8Frefactor:=20Update=20Li?= =?UTF-8?q?neTime=20Repository?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Adding filtering logic --- .../Repositories/ILineTimeRepository.cs | 2 +- .../Repositories/LineTimeRepository.cs | 16 +++++++++++++++- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/OneBus.Domain/Interfaces/Repositories/ILineTimeRepository.cs b/OneBus.Domain/Interfaces/Repositories/ILineTimeRepository.cs index 3b2f606..53b8e32 100644 --- a/OneBus.Domain/Interfaces/Repositories/ILineTimeRepository.cs +++ b/OneBus.Domain/Interfaces/Repositories/ILineTimeRepository.cs @@ -3,7 +3,7 @@ namespace OneBus.Domain.Interfaces.Repositories { - public interface ILineTimeRepository : IBaseRepository + public interface ILineTimeRepository : IBaseRepository { } } diff --git a/OneBus.Infra.Data/Repositories/LineTimeRepository.cs b/OneBus.Infra.Data/Repositories/LineTimeRepository.cs index 2bd6dea..03e145b 100644 --- a/OneBus.Infra.Data/Repositories/LineTimeRepository.cs +++ b/OneBus.Infra.Data/Repositories/LineTimeRepository.cs @@ -2,13 +2,27 @@ 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 LineTimeRepository : BaseRepository, ILineTimeRepository + public class LineTimeRepository : BaseRepository, ILineTimeRepository { public LineTimeRepository(OneBusDbContext dbContext) : base(dbContext) { } + + protected override Expression> ApplyFilter(LineTimeFilter filter) + { + var value = filter.Value?.ToLower(); + + return c => + (filter.DayType == null || c.DayType == filter.DayType) && + (filter.DirectionType == null || c.DirectionType == filter.DirectionType) && + (string.IsNullOrWhiteSpace(value) || + ((c.Line!.Name.ToLower().Contains(value) || + c.Line.Mileage.ToString().Contains(value) || + c.Line.Number.ToLower().Contains(value)) && value != string.Empty)); + } } } From ad12ab49cb4afa7debe4cb019bc3a3873cb62200 Mon Sep 17 00:00:00 2001 From: Eduardo Rezende Date: Thu, 23 Oct 2025 21:49:49 -0300 Subject: [PATCH 55/99] =?UTF-8?q?=E2=99=BB=EF=B8=8Frefactor:=20Update=20Li?= =?UTF-8?q?neTime=20DTOs?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Updating DTOs with fields --- .../DTOs/LineTime/CreateLineTimeDTO.cs | 7 +++++++ .../DTOs/LineTime/ReadLineTimeDTO.cs | 15 +++++++++++++++ .../DTOs/LineTime/UpdateLineTimeDTO.cs | 7 ++++++- 3 files changed, 28 insertions(+), 1 deletion(-) diff --git a/OneBus.Application/DTOs/LineTime/CreateLineTimeDTO.cs b/OneBus.Application/DTOs/LineTime/CreateLineTimeDTO.cs index 5460d6f..55aaf1f 100644 --- a/OneBus.Application/DTOs/LineTime/CreateLineTimeDTO.cs +++ b/OneBus.Application/DTOs/LineTime/CreateLineTimeDTO.cs @@ -2,5 +2,12 @@ { public class CreateLineTimeDTO : BaseCreateDTO { + public long LineId { get; set; } + + public TimeOnly Time { get; set; } + + public byte DayType { get; set; } + + public byte DirectionType { get; set; } } } diff --git a/OneBus.Application/DTOs/LineTime/ReadLineTimeDTO.cs b/OneBus.Application/DTOs/LineTime/ReadLineTimeDTO.cs index c8ff899..4287228 100644 --- a/OneBus.Application/DTOs/LineTime/ReadLineTimeDTO.cs +++ b/OneBus.Application/DTOs/LineTime/ReadLineTimeDTO.cs @@ -2,5 +2,20 @@ { public class ReadLineTimeDTO : BaseReadDTO { + public long LineId { get; set; } + + public string? LineNumber { get; set; } + + public string? LineName { get; set; } + + public TimeOnly Time { get; set; } + + public byte DayType { get; set; } + + public string? DayTypeName { get; set; } + + public byte DirectionType { get; set; } + + public string? DirectionTypeName { get; set; } } } diff --git a/OneBus.Application/DTOs/LineTime/UpdateLineTimeDTO.cs b/OneBus.Application/DTOs/LineTime/UpdateLineTimeDTO.cs index 0166816..733cd1a 100644 --- a/OneBus.Application/DTOs/LineTime/UpdateLineTimeDTO.cs +++ b/OneBus.Application/DTOs/LineTime/UpdateLineTimeDTO.cs @@ -1,6 +1,11 @@ namespace OneBus.Application.DTOs.LineTime { public class UpdateLineTimeDTO : BaseUpdateDTO - { + { + public TimeOnly Time { get; set; } + + public byte DayType { get; set; } + + public byte DirectionType { get; set; } } } From 77ebf270b1bd2f98d3e1f406f782e9a09f64bfd6 Mon Sep 17 00:00:00 2001 From: Eduardo Rezende Date: Thu, 23 Oct 2025 21:50:13 -0300 Subject: [PATCH 56/99] =?UTF-8?q?=E2=99=BB=EF=B8=8Frefactor:=20Update=20Li?= =?UTF-8?q?neTime=20Validators?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Adding validators logic --- .../LineTime/CreateLineTimeDTOValidator.cs | 33 +++++++++++++++++++ .../LineTime/UpdateLineTimeDTOValidator.cs | 16 ++++++++- 2 files changed, 48 insertions(+), 1 deletion(-) diff --git a/OneBus.Application/Validators/LineTime/CreateLineTimeDTOValidator.cs b/OneBus.Application/Validators/LineTime/CreateLineTimeDTOValidator.cs index 5837c3e..9816f53 100644 --- a/OneBus.Application/Validators/LineTime/CreateLineTimeDTOValidator.cs +++ b/OneBus.Application/Validators/LineTime/CreateLineTimeDTOValidator.cs @@ -1,9 +1,42 @@ using FluentValidation; using OneBus.Application.DTOs.LineTime; +using OneBus.Domain.Commons; +using OneBus.Domain.Enums; +using OneBus.Domain.Enums.Line; +using OneBus.Domain.Interfaces.Repositories; +using OneBus.Domain.Utils; namespace OneBus.Application.Validators.LineTime { public class CreateLineTimeDTOValidator : AbstractValidator { + private readonly ILineRepository _lineRepository; + + const string LineIdPropertyName = "Id da Linha"; + + public CreateLineTimeDTOValidator(ILineRepository lineRepository) + { + _lineRepository = lineRepository; + + RuleFor(c => c.LineId).GreaterThan(0) + .OverridePropertyName(LineIdPropertyName); + + RuleFor(c => c.LineId) + .MustAsync(ExistsAsync) + .WithMessage(ErrorUtils.EntityNotFound(LineIdPropertyName).Message) + .OverridePropertyName(LineIdPropertyName); + + RuleFor(c => c.DirectionType) + .Must(ValidationUtils.IsValidEnumValue) + .OverridePropertyName("Tipo de Direção"); + + RuleFor(c => c.DayType).Must(ValidationUtils.IsValidEnumValue) + .OverridePropertyName("Dia da Semana"); + } + + private async Task ExistsAsync(long lineId, CancellationToken ct = default) + { + return await _lineRepository.AnyAsync(c => c.Id == lineId, cancellationToken: ct); + } } } diff --git a/OneBus.Application/Validators/LineTime/UpdateLineTimeDTOValidator.cs b/OneBus.Application/Validators/LineTime/UpdateLineTimeDTOValidator.cs index 72a0302..823c012 100644 --- a/OneBus.Application/Validators/LineTime/UpdateLineTimeDTOValidator.cs +++ b/OneBus.Application/Validators/LineTime/UpdateLineTimeDTOValidator.cs @@ -1,9 +1,23 @@ using FluentValidation; using OneBus.Application.DTOs.LineTime; +using OneBus.Domain.Enums; +using OneBus.Domain.Enums.Line; +using OneBus.Domain.Utils; namespace OneBus.Application.Validators.LineTime { public class UpdateLineTimeDTOValidator : AbstractValidator - { + { + public UpdateLineTimeDTOValidator() + { + RuleFor(c => c.Id).GreaterThan(0); + + RuleFor(c => c.DirectionType) + .Must(ValidationUtils.IsValidEnumValue) + .OverridePropertyName("Tipo de Direção"); + + RuleFor(c => c.DayType).Must(ValidationUtils.IsValidEnumValue) + .OverridePropertyName("Dia da Semana"); + } } } From 565509c313d97807a44f477468344cbb0da50bbf Mon Sep 17 00:00:00 2001 From: Eduardo Rezende Date: Thu, 23 Oct 2025 21:52:09 -0300 Subject: [PATCH 57/99] =?UTF-8?q?=E2=99=BB=EF=B8=8Frefactor:=20Update=20Li?= =?UTF-8?q?neTime=20Service?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Updating Get methods and update fields --- .../Interfaces/Services/ILineTimeService.cs | 2 +- .../Services/LineTimeService.cs | 49 +++++++++++++++++-- 2 files changed, 47 insertions(+), 4 deletions(-) diff --git a/OneBus.Application/Interfaces/Services/ILineTimeService.cs b/OneBus.Application/Interfaces/Services/ILineTimeService.cs index 6f6ea5d..ca32205 100644 --- a/OneBus.Application/Interfaces/Services/ILineTimeService.cs +++ b/OneBus.Application/Interfaces/Services/ILineTimeService.cs @@ -5,7 +5,7 @@ namespace OneBus.Application.Interfaces.Services { public interface ILineTimeService : - IBaseService + IBaseService { } } diff --git a/OneBus.Application/Services/LineTimeService.cs b/OneBus.Application/Services/LineTimeService.cs index d895b3c..f3c7c06 100644 --- a/OneBus.Application/Services/LineTimeService.cs +++ b/OneBus.Application/Services/LineTimeService.cs @@ -1,26 +1,69 @@ using FluentValidation; using OneBus.Application.DTOs.LineTime; 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.Enums.Line; +using OneBus.Domain.Extensions; using OneBus.Domain.Filters; using OneBus.Domain.Interfaces.Repositories; namespace OneBus.Application.Services { - public class LineTimeService : BaseService, + public class LineTimeService : BaseService, ILineTimeService { public LineTimeService( - IBaseRepository baseRepository, + IBaseRepository baseRepository, IValidator createValidator, IValidator updateValidator) : base(baseRepository, createValidator, updateValidator) { } + public async override Task>> GetPaginedAsync( + LineTimeFilter filter, + DbQueryOptions? dbQueryOptions = null, + CancellationToken cancellationToken = default) + { + var result = await base.GetPaginedAsync(filter, dbQueryOptions, cancellationToken); + + if (!result.Sucess) + return result; + + foreach (var lineTime in result.Value!.Items) + { + lineTime.DayTypeName = ((DayType)lineTime.DayType).ToString().Localize(); + lineTime.DirectionTypeName = ((DirectionType)lineTime.DirectionType).ToString().Localize(); + } + + return result; + } + + public async override Task> GetByIdAsync( + long id, + DbQueryOptions? dbQueryOptions = null, + CancellationToken cancellationToken = default) + { + var result = await base.GetByIdAsync(id, dbQueryOptions, cancellationToken); + + if (!result.Sucess) + return result; + + var lineTime = result.Value!; + lineTime.DayTypeName = ((DayType)lineTime.DayType).ToString().Localize(); + lineTime.DirectionTypeName = ((DirectionType)lineTime.DirectionType).ToString().Localize(); + + return result; + } + protected override void UpdateFields(LineTime entity, UpdateLineTimeDTO updateDTO) { - throw new NotImplementedException(); + entity.Time = updateDTO.Time; + entity.DayType = updateDTO.DayType; + entity.DirectionType = updateDTO.DirectionType; } } } From d40d4491c96bfd9b28e22559b54237a2a8e5a336 Mon Sep 17 00:00:00 2001 From: Eduardo Rezende Date: Thu, 23 Oct 2025 21:53:21 -0300 Subject: [PATCH 58/99] =?UTF-8?q?=E2=99=BB=EF=B8=8Frefactor:=20Update=20Se?= =?UTF-8?q?rvice=20classes?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fixing get methods --- OneBus.Application/Services/EmployeeService.cs | 4 ++-- OneBus.Application/Services/LineService.cs | 4 ++-- OneBus.Application/Services/UserService.cs | 5 +---- OneBus.Application/Services/VehicleService.cs | 4 ++-- 4 files changed, 7 insertions(+), 10 deletions(-) diff --git a/OneBus.Application/Services/EmployeeService.cs b/OneBus.Application/Services/EmployeeService.cs index 8059bb8..c6819f5 100644 --- a/OneBus.Application/Services/EmployeeService.cs +++ b/OneBus.Application/Services/EmployeeService.cs @@ -27,7 +27,7 @@ public override async Task>> GetPaginedAsync( DbQueryOptions? dbQueryOptions = null, CancellationToken cancellationToken = default) { - var result = await base.GetPaginedAsync(filter, cancellationToken: cancellationToken); + var result = await base.GetPaginedAsync(filter, dbQueryOptions, cancellationToken); if (!result.Sucess) return result; @@ -47,7 +47,7 @@ public override async Task> GetByIdAsync( DbQueryOptions? dbQueryOptions = null, CancellationToken cancellationToken = default) { - var result = await base.GetByIdAsync(id, cancellationToken: cancellationToken); + var result = await base.GetByIdAsync(id, dbQueryOptions, cancellationToken); if (!result.Sucess) return result; diff --git a/OneBus.Application/Services/LineService.cs b/OneBus.Application/Services/LineService.cs index 3924819..12ca50c 100644 --- a/OneBus.Application/Services/LineService.cs +++ b/OneBus.Application/Services/LineService.cs @@ -27,7 +27,7 @@ public override async Task>> GetPaginedAsync( DbQueryOptions? dbQueryOptions = null, CancellationToken cancellationToken = default) { - var result = await base.GetPaginedAsync(filter, cancellationToken: cancellationToken); + var result = await base.GetPaginedAsync(filter, dbQueryOptions, cancellationToken); if (!result.Sucess) return result; @@ -46,7 +46,7 @@ public override async Task> GetByIdAsync( DbQueryOptions? dbQueryOptions = null, CancellationToken cancellationToken = default) { - var result = await base.GetByIdAsync(id, cancellationToken: cancellationToken); + var result = await base.GetByIdAsync(id, dbQueryOptions, cancellationToken); if (!result.Sucess) return result; diff --git a/OneBus.Application/Services/UserService.cs b/OneBus.Application/Services/UserService.cs index 412dd53..c6fca91 100644 --- a/OneBus.Application/Services/UserService.cs +++ b/OneBus.Application/Services/UserService.cs @@ -49,9 +49,6 @@ public async Task> LoginAsync( return SuccessResult.Create(tokenModel); } - protected override void UpdateFields(User entity, UpdateUserDTO updateDTO) - { - throw new NotImplementedException(); - } + protected override void UpdateFields(User entity, UpdateUserDTO updateDTO) { } } } diff --git a/OneBus.Application/Services/VehicleService.cs b/OneBus.Application/Services/VehicleService.cs index f7d40b0..fed8b1b 100644 --- a/OneBus.Application/Services/VehicleService.cs +++ b/OneBus.Application/Services/VehicleService.cs @@ -27,7 +27,7 @@ public override async Task>> GetPaginedAsync( DbQueryOptions? dbQueryOptions = null, CancellationToken cancellationToken = default) { - var result = await base.GetPaginedAsync(filter, cancellationToken: cancellationToken); + var result = await base.GetPaginedAsync(filter, dbQueryOptions, cancellationToken); if (!result.Sucess) return result; @@ -52,7 +52,7 @@ public override async Task> GetByIdAsync( DbQueryOptions? dbQueryOptions = null, CancellationToken cancellationToken = default) { - var result = await base.GetByIdAsync(id, cancellationToken: cancellationToken); + var result = await base.GetByIdAsync(id, dbQueryOptions, cancellationToken); if (!result.Sucess) return result; From 62d9ba28dea0263f86a060059b94dbe00d6cec72 Mon Sep 17 00:00:00 2001 From: Eduardo Rezende Date: Thu, 23 Oct 2025 21:54:07 -0300 Subject: [PATCH 59/99] =?UTF-8?q?=E2=99=BB=EF=B8=8Frefactor:=20Update=20Li?= =?UTF-8?q?neTime=20Controller?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Removing NonController attribute and adding include parameters --- OneBus.API/Controllers/LineTimeController.cs | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/OneBus.API/Controllers/LineTimeController.cs b/OneBus.API/Controllers/LineTimeController.cs index 40e174c..6554215 100644 --- a/OneBus.API/Controllers/LineTimeController.cs +++ b/OneBus.API/Controllers/LineTimeController.cs @@ -10,7 +10,6 @@ namespace OneBus.API.Controllers { - [NonController] [Route("api/v1/linesTimes")] [ApiController] [Produces("application/json")] @@ -102,9 +101,11 @@ public async Task DeleteAsync([FromRoute] long id, CancellationTo /// Horários de Linha 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] LineTimeFilter filter, CancellationToken cancellationToken = default) { - return (await _lineTimeService.GetPaginedAsync(filter, cancellationToken: cancellationToken)).ToActionResult(); + return (await _lineTimeService.GetPaginedAsync(filter, + DbQueryOptions.Create(["Line"]), + cancellationToken)).ToActionResult(); } /// @@ -123,7 +124,9 @@ 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: cancellationToken)).ToActionResult(); + return (await _lineTimeService.GetByIdAsync(id, + DbQueryOptions.Create(["Line"]), + cancellationToken)).ToActionResult(); } } } From 9407d4c926f81494354c71d7d574aac72e95f5fb Mon Sep 17 00:00:00 2001 From: Eduardo Rezende Date: Thu, 23 Oct 2025 22:39:48 -0300 Subject: [PATCH 60/99] =?UTF-8?q?=E2=99=BB=EF=B8=8Frefactor:=20Update=20Se?= =?UTF-8?q?ctor=20enum?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Adding 'Outros' value --- OneBus.Domain/Enums/Maintenance/Sector.cs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/OneBus.Domain/Enums/Maintenance/Sector.cs b/OneBus.Domain/Enums/Maintenance/Sector.cs index 760b5ba..9066d3e 100644 --- a/OneBus.Domain/Enums/Maintenance/Sector.cs +++ b/OneBus.Domain/Enums/Maintenance/Sector.cs @@ -6,6 +6,7 @@ public enum Sector : byte Funilaria, Mecânica, Elétrica, - Inspeção + Inspeção, + Outros } } From c457fe51367e734b389dab25d48bfca548cb2ab4 Mon Sep 17 00:00:00 2001 From: Eduardo Rezende Date: Thu, 23 Oct 2025 22:40:28 -0300 Subject: [PATCH 61/99] =?UTF-8?q?=E2=9C=A8feat:=20Add=20Maintenance=20Filt?= =?UTF-8?q?er?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Adding filtering fields --- OneBus.Domain/Filters/MaintenanceFilter.cs | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 OneBus.Domain/Filters/MaintenanceFilter.cs diff --git a/OneBus.Domain/Filters/MaintenanceFilter.cs b/OneBus.Domain/Filters/MaintenanceFilter.cs new file mode 100644 index 0000000..8fd8d6b --- /dev/null +++ b/OneBus.Domain/Filters/MaintenanceFilter.cs @@ -0,0 +1,7 @@ +namespace OneBus.Domain.Filters +{ + public class MaintenanceFilter : BaseFilter + { + public byte? Sector { get; set; } + } +} From 98270c125fbfb7b95f74465ee0fbfa76b2d416ca Mon Sep 17 00:00:00 2001 From: Eduardo Rezende Date: Thu, 23 Oct 2025 22:41:35 -0300 Subject: [PATCH 62/99] =?UTF-8?q?=E2=99=BB=EF=B8=8Frefactor:=20Update=20Ma?= =?UTF-8?q?intenance=20Repository?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Adding filtering logic --- .../Repositories/IMaintenanceRepository.cs | 2 +- .../Repositories/MaintenanceRepository.cs | 22 ++++++++++++++++++- 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/OneBus.Domain/Interfaces/Repositories/IMaintenanceRepository.cs b/OneBus.Domain/Interfaces/Repositories/IMaintenanceRepository.cs index 861a00a..d59b978 100644 --- a/OneBus.Domain/Interfaces/Repositories/IMaintenanceRepository.cs +++ b/OneBus.Domain/Interfaces/Repositories/IMaintenanceRepository.cs @@ -3,7 +3,7 @@ namespace OneBus.Domain.Interfaces.Repositories { - public interface IMaintenanceRepository : IBaseRepository + public interface IMaintenanceRepository : IBaseRepository { } } diff --git a/OneBus.Infra.Data/Repositories/MaintenanceRepository.cs b/OneBus.Infra.Data/Repositories/MaintenanceRepository.cs index e70842f..b4e610e 100644 --- a/OneBus.Infra.Data/Repositories/MaintenanceRepository.cs +++ b/OneBus.Infra.Data/Repositories/MaintenanceRepository.cs @@ -2,13 +2,33 @@ 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 MaintenanceRepository : BaseRepository, IMaintenanceRepository + public class MaintenanceRepository : BaseRepository, IMaintenanceRepository { public MaintenanceRepository(OneBusDbContext dbContext) : base(dbContext) { } + + protected override Expression> ApplyFilter(MaintenanceFilter filter) + { + var value = filter.Value?.ToLower(); + + return c => + (filter.Sector == null || c.Sector == filter.Sector) && + (string.IsNullOrWhiteSpace(value) || + ((c.Description.ToLower().Contains(value) || + c.Cost.ToString().Contains(value) || + c.Vehicle!.Model.ToLower().Contains(value) || + c.Vehicle.Plate.ToLower().Contains(value) || + c.Vehicle.Renavam.ToLower().Contains(value) || + c.Vehicle.Prefix.ToLower().Contains(value) || + c.Vehicle.Licensing!.ToLower().Contains(value) || + c.Vehicle.NumberChassis!.ToLower().Contains(value) || + c.Vehicle.BodyworkNumber!.ToLower().Contains(value) || + c.Vehicle.BusChassisModel!.ToLower().Contains(value)) && value != string.Empty)); + } } } From 1c365a87fc1051468606e2c70af273596d56cc22 Mon Sep 17 00:00:00 2001 From: Eduardo Rezende Date: Thu, 23 Oct 2025 22:42:18 -0300 Subject: [PATCH 63/99] =?UTF-8?q?=E2=99=BB=EF=B8=8Frefactor:=20Update=20Ma?= =?UTF-8?q?intenance=20DTOs?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Updating DTOs with fields --- .../DTOs/Maintenance/CreateMaintenanceDTO.cs | 18 +++++++++++++++ .../DTOs/Maintenance/ReadMaintenanceDTO.cs | 22 +++++++++++++++++++ .../DTOs/Maintenance/ReadSectorDTO.cs | 14 ++++++++++++ .../DTOs/Maintenance/UpdateMaintenanceDTO.cs | 16 ++++++++++++++ 4 files changed, 70 insertions(+) create mode 100644 OneBus.Application/DTOs/Maintenance/ReadSectorDTO.cs diff --git a/OneBus.Application/DTOs/Maintenance/CreateMaintenanceDTO.cs b/OneBus.Application/DTOs/Maintenance/CreateMaintenanceDTO.cs index 7995cfb..125d91d 100644 --- a/OneBus.Application/DTOs/Maintenance/CreateMaintenanceDTO.cs +++ b/OneBus.Application/DTOs/Maintenance/CreateMaintenanceDTO.cs @@ -2,5 +2,23 @@ { public class CreateMaintenanceDTO : BaseCreateDTO { + public CreateMaintenanceDTO() + { + Description = string.Empty; + } + + public long VehicleId { get; set; } + + public byte Sector { get; set; } + + public string Description { get; set; } + + public DateOnly StartDate { get; set; } + + public DateOnly EndDate { get; set; } + + public DateOnly SurveyExpiration { get; set; } + + public decimal Cost { get; set; } } } diff --git a/OneBus.Application/DTOs/Maintenance/ReadMaintenanceDTO.cs b/OneBus.Application/DTOs/Maintenance/ReadMaintenanceDTO.cs index 9cb1631..e185a66 100644 --- a/OneBus.Application/DTOs/Maintenance/ReadMaintenanceDTO.cs +++ b/OneBus.Application/DTOs/Maintenance/ReadMaintenanceDTO.cs @@ -2,5 +2,27 @@ { public class ReadMaintenanceDTO : BaseReadDTO { + public ReadMaintenanceDTO() + { + Description = string.Empty; + } + + public long VehicleId { get; set; } + + public string? VehiclePrefix { get; set; } + + public byte Sector { get; set; } + + public string? SectorName { get; set; } + + public string Description { get; set; } + + public DateOnly StartDate { get; set; } + + public DateOnly EndDate { get; set; } + + public DateOnly SurveyExpiration { get; set; } + + public decimal Cost { get; set; } } } diff --git a/OneBus.Application/DTOs/Maintenance/ReadSectorDTO.cs b/OneBus.Application/DTOs/Maintenance/ReadSectorDTO.cs new file mode 100644 index 0000000..27741a7 --- /dev/null +++ b/OneBus.Application/DTOs/Maintenance/ReadSectorDTO.cs @@ -0,0 +1,14 @@ +namespace OneBus.Application.DTOs.Maintenance +{ + public class ReadSectorDTO + { + public ReadSectorDTO() + { + Name = string.Empty; + } + + public byte Value { get; set; } + + public string Name { get; set; } + } +} diff --git a/OneBus.Application/DTOs/Maintenance/UpdateMaintenanceDTO.cs b/OneBus.Application/DTOs/Maintenance/UpdateMaintenanceDTO.cs index 765265a..791f239 100644 --- a/OneBus.Application/DTOs/Maintenance/UpdateMaintenanceDTO.cs +++ b/OneBus.Application/DTOs/Maintenance/UpdateMaintenanceDTO.cs @@ -2,5 +2,21 @@ { public class UpdateMaintenanceDTO : BaseUpdateDTO { + public UpdateMaintenanceDTO() + { + Description = string.Empty; + } + + public byte Sector { get; set; } + + public string Description { get; set; } + + public DateOnly StartDate { get; set; } + + public DateOnly EndDate { get; set; } + + public DateOnly SurveyExpiration { get; set; } + + public decimal Cost { get; set; } } } From 7ca6cff752ccef6ec27d079ce302338a8ef5aff8 Mon Sep 17 00:00:00 2001 From: Eduardo Rezende Date: Thu, 23 Oct 2025 22:42:59 -0300 Subject: [PATCH 64/99] =?UTF-8?q?=E2=99=BB=EF=B8=8Frefactor:=20Update=20Ma?= =?UTF-8?q?intenance=20Validators?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Adding validators logic --- .../CreateMaintenanceDTOValidator.cs | 41 +++++++++++++++++++ .../UpdateMaintenanceDTOValidator.cs | 22 ++++++++++ 2 files changed, 63 insertions(+) diff --git a/OneBus.Application/Validators/Maintenance/CreateMaintenanceDTOValidator.cs b/OneBus.Application/Validators/Maintenance/CreateMaintenanceDTOValidator.cs index 3bc45f7..2686ca1 100644 --- a/OneBus.Application/Validators/Maintenance/CreateMaintenanceDTOValidator.cs +++ b/OneBus.Application/Validators/Maintenance/CreateMaintenanceDTOValidator.cs @@ -1,9 +1,50 @@ using FluentValidation; using OneBus.Application.DTOs.Maintenance; +using OneBus.Domain.Commons; +using OneBus.Domain.Enums.Maintenance; +using OneBus.Domain.Interfaces.Repositories; +using OneBus.Domain.Utils; namespace OneBus.Application.Validators.Maintenance { public class CreateMaintenanceDTOValidator : AbstractValidator { + private readonly IVehicleRepository _vehicleRepository; + + const string VehicleIdPropertyName = "Id do Veículo"; + + public CreateMaintenanceDTOValidator(IVehicleRepository vehicleRepository) + { + _vehicleRepository = vehicleRepository; + + RuleFor(c => c.VehicleId).GreaterThan(0) + .OverridePropertyName(VehicleIdPropertyName); + + RuleFor(c => c.VehicleId) + .MustAsync(ExistsAsync) + .WithMessage(ErrorUtils.EntityNotFound(VehicleIdPropertyName).Message) + .OverridePropertyName(VehicleIdPropertyName); + + RuleFor(c => c.Description) + .NotEmpty() + .OverridePropertyName("Descrição"); + + RuleFor(c => c.Cost).GreaterThanOrEqualTo(0) + .OverridePropertyName("Custo"); + + RuleFor(c => c.Sector) + .Must(ValidationUtils.IsValidEnumValue) + .OverridePropertyName("Setor"); + + RuleFor(c => c.EndDate) + .Must((dto, endTime) => endTime >= dto.StartDate) + .WithMessage("Horário inválido") + .OverridePropertyName("Horário de Término"); + } + + private async Task ExistsAsync(long vehicleId, CancellationToken ct = default) + { + return await _vehicleRepository.AnyAsync(c => c.Id == vehicleId, cancellationToken: ct); + } } } diff --git a/OneBus.Application/Validators/Maintenance/UpdateMaintenanceDTOValidator.cs b/OneBus.Application/Validators/Maintenance/UpdateMaintenanceDTOValidator.cs index c53765f..f2fcd51 100644 --- a/OneBus.Application/Validators/Maintenance/UpdateMaintenanceDTOValidator.cs +++ b/OneBus.Application/Validators/Maintenance/UpdateMaintenanceDTOValidator.cs @@ -1,9 +1,31 @@ using FluentValidation; using OneBus.Application.DTOs.Maintenance; +using OneBus.Domain.Enums.Maintenance; +using OneBus.Domain.Utils; namespace OneBus.Application.Validators.Maintenance { public class UpdateMaintenanceDTOValidator : AbstractValidator { + public UpdateMaintenanceDTOValidator() + { + RuleFor(c => c.Id).GreaterThan(0); + + RuleFor(c => c.Description) + .NotEmpty() + .OverridePropertyName("Descrição"); + + RuleFor(c => c.Cost).GreaterThanOrEqualTo(0) + .OverridePropertyName("Custo"); + + RuleFor(c => c.Sector) + .Must(ValidationUtils.IsValidEnumValue) + .OverridePropertyName("Setor"); + + RuleFor(c => c.EndDate) + .Must((dto, endTime) => endTime >= dto.StartDate) + .WithMessage("Horário inválido") + .OverridePropertyName("Horário de Término"); + } } } From 94836eed07c8490c334f1c4870655536aac53e18 Mon Sep 17 00:00:00 2001 From: Eduardo Rezende Date: Thu, 23 Oct 2025 22:43:49 -0300 Subject: [PATCH 65/99] =?UTF-8?q?=E2=99=BB=EF=B8=8Frefactor:=20Update=20Ma?= =?UTF-8?q?intenance=20Service?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Updating Get methods and update fields --- .../Services/IMaintenanceService.cs | 6 +- .../Services/MaintenanceService.cs | 67 +++++++++++++++++-- 2 files changed, 66 insertions(+), 7 deletions(-) diff --git a/OneBus.Application/Interfaces/Services/IMaintenanceService.cs b/OneBus.Application/Interfaces/Services/IMaintenanceService.cs index 36d7701..5abc42a 100644 --- a/OneBus.Application/Interfaces/Services/IMaintenanceService.cs +++ b/OneBus.Application/Interfaces/Services/IMaintenanceService.cs @@ -1,11 +1,13 @@ using OneBus.Application.DTOs.Maintenance; +using OneBus.Domain.Commons.Result; using OneBus.Domain.Entities; using OneBus.Domain.Filters; namespace OneBus.Application.Interfaces.Services { - public interface IMaintenanceService : - IBaseService + public interface IMaintenanceService : + IBaseService { + Result> GetSectors(); } } diff --git a/OneBus.Application/Services/MaintenanceService.cs b/OneBus.Application/Services/MaintenanceService.cs index 394e293..1b44d02 100644 --- a/OneBus.Application/Services/MaintenanceService.cs +++ b/OneBus.Application/Services/MaintenanceService.cs @@ -1,26 +1,83 @@ using FluentValidation; using OneBus.Application.DTOs.Maintenance; using OneBus.Application.Interfaces.Services; +using OneBus.Domain.Commons; +using OneBus.Domain.Commons.Result; using OneBus.Domain.Entities; +using OneBus.Domain.Enums.Maintenance; +using OneBus.Domain.Extensions; using OneBus.Domain.Filters; using OneBus.Domain.Interfaces.Repositories; namespace OneBus.Application.Services { - public class MaintenanceService : BaseService, + public class MaintenanceService : BaseService, IMaintenanceService { public MaintenanceService( - IBaseRepository baseRepository, - IValidator createValidator, - IValidator updateValidator) + IBaseRepository baseRepository, + IValidator createValidator, + IValidator updateValidator) : base(baseRepository, createValidator, updateValidator) { } + public async override Task>> GetPaginedAsync( + MaintenanceFilter filter, + DbQueryOptions? dbQueryOptions = null, + CancellationToken cancellationToken = default) + { + var result = await base.GetPaginedAsync(filter, dbQueryOptions, cancellationToken); + + if (!result.Sucess) + return result; + + foreach (var maintenance in result.Value!.Items) + { + maintenance.SectorName = ((Sector)maintenance.Sector).ToString().Localize(); + } + + return result; + } + + public async override Task> GetByIdAsync( + long id, + DbQueryOptions? dbQueryOptions = null, + CancellationToken cancellationToken = default) + { + var result = await base.GetByIdAsync(id, dbQueryOptions, cancellationToken); + + if (!result.Sucess) + return result; + + var maintenance = result.Value!; + maintenance.SectorName = ((Sector)maintenance.Sector).ToString().Localize(); + + return result; + } + + public Result> GetSectors() + { + var values = Enum.GetValues(); + + List status = []; + + foreach (var value in values) + { + status.Add(new ReadSectorDTO { Value = (byte)value, Name = value.ToString().Localize() }); + } + + return SuccessResult>.Create(status); + } + protected override void UpdateFields(Maintenance entity, UpdateMaintenanceDTO updateDTO) { - throw new NotImplementedException(); + entity.Cost = updateDTO.Cost; + entity.Sector = updateDTO.Sector; + entity.EndDate = updateDTO.EndDate; + entity.StartDate = updateDTO.StartDate; + entity.Description = updateDTO.Description; + entity.SurveyExpiration = updateDTO.SurveyExpiration; } } } From a2d734cd38f3d79e231cdd5e63803a4282a79caa Mon Sep 17 00:00:00 2001 From: Eduardo Rezende Date: Thu, 23 Oct 2025 22:44:28 -0300 Subject: [PATCH 66/99] =?UTF-8?q?=E2=99=BB=EF=B8=8Frefactor:=20Update=20Ma?= =?UTF-8?q?intenance=20Controller?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Removing NonController attribute and adding include parameters --- .../Controllers/MaintenanceController.cs | 26 ++++++++++++++++--- 1 file changed, 22 insertions(+), 4 deletions(-) diff --git a/OneBus.API/Controllers/MaintenanceController.cs b/OneBus.API/Controllers/MaintenanceController.cs index f7dcb88..122c3db 100644 --- a/OneBus.API/Controllers/MaintenanceController.cs +++ b/OneBus.API/Controllers/MaintenanceController.cs @@ -10,7 +10,6 @@ namespace OneBus.API.Controllers { - [NonController] [Route("api/v1/maintenances")] [ApiController] [Produces("application/json")] @@ -102,9 +101,11 @@ public async Task DeleteAsync([FromRoute] long id, CancellationTo /// Manutenções paginadas e filtradas com sucesso [HttpGet] [ProducesResponseType(typeof(SuccessResult>), StatusCodes.Status200OK)] - public async Task GetPaginedAsync([FromQuery] BaseFilter filter, CancellationToken cancellationToken = default) + public async Task GetPaginedAsync([FromQuery] MaintenanceFilter filter, CancellationToken cancellationToken = default) { - return (await _maintenanceService.GetPaginedAsync(filter, cancellationToken: cancellationToken)).ToActionResult(); + return (await _maintenanceService.GetPaginedAsync(filter, + DbQueryOptions.Create(["Vehicle"]), + 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 _maintenanceService.GetByIdAsync(id, cancellationToken: cancellationToken)).ToActionResult(); + return (await _maintenanceService.GetByIdAsync(id, + DbQueryOptions.Create(["Vehicle"]), + cancellationToken)).ToActionResult(); + } + + /// + /// Listar tipos de setores + /// + /// + /// GET de tipos de setores + /// + /// Tipos de Setores disponíveis + /// Setores retornados com sucesso + [HttpGet("sectors")] + [ProducesResponseType(typeof(SuccessResult>), StatusCodes.Status200OK)] + public IActionResult GetSectors() + { + return _maintenanceService.GetSectors().ToActionResult(); } } } From 02d652afc03f8b7d4aa0bf7d6f30c7a64ee4d93e Mon Sep 17 00:00:00 2001 From: Eduardo Rezende Date: Sat, 1 Nov 2025 19:15:36 -0300 Subject: [PATCH 67/99] =?UTF-8?q?=E2=9C=A8feat:=20Add=20new=20field=20into?= =?UTF-8?q?=20ReadEmployeeWorkday=20DTO?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Adding EmployeeImage field --- .../DTOs/EmployeeWorkday/ReadEmployeeWorkdayDTO.cs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/OneBus.Application/DTOs/EmployeeWorkday/ReadEmployeeWorkdayDTO.cs b/OneBus.Application/DTOs/EmployeeWorkday/ReadEmployeeWorkdayDTO.cs index 701d2bb..0a5653e 100644 --- a/OneBus.Application/DTOs/EmployeeWorkday/ReadEmployeeWorkdayDTO.cs +++ b/OneBus.Application/DTOs/EmployeeWorkday/ReadEmployeeWorkdayDTO.cs @@ -5,6 +5,8 @@ public class ReadEmployeeWorkdayDTO : BaseReadDTO public long EmployeeId { get; set; } public string? EmployeeName { get; set; } + + public byte[]? EmployeeImage { get; set; } public string? EmployeeCpf { get; set; } From 1a78d700e49d3a12501a9a9e93d581515fe3c09b Mon Sep 17 00:00:00 2001 From: Eduardo Rezende Date: Sat, 1 Nov 2025 19:16:24 -0300 Subject: [PATCH 68/99] =?UTF-8?q?=E2=99=BB=EF=B8=8Frefactor:=20Update=20ti?= =?UTF-8?q?me=20validations?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Removing time validations from validators --- .../EmployeeWorkday/CreateEmployeeWorkdayDTOValidator.cs | 7 +------ .../EmployeeWorkday/UpdateEmployeeWorkdayDTOValidator.cs | 6 +----- .../Maintenance/CreateMaintenanceDTOValidator.cs | 7 +------ .../Maintenance/UpdateMaintenanceDTOValidator.cs | 7 +------ 4 files changed, 4 insertions(+), 23 deletions(-) diff --git a/OneBus.Application/Validators/EmployeeWorkday/CreateEmployeeWorkdayDTOValidator.cs b/OneBus.Application/Validators/EmployeeWorkday/CreateEmployeeWorkdayDTOValidator.cs index 44948bf..4cf3f42 100644 --- a/OneBus.Application/Validators/EmployeeWorkday/CreateEmployeeWorkdayDTOValidator.cs +++ b/OneBus.Application/Validators/EmployeeWorkday/CreateEmployeeWorkdayDTOValidator.cs @@ -26,12 +26,7 @@ public CreateEmployeeWorkdayDTOValidator(IEmployeeRepository employeeRepository) .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"); + .OverridePropertyName("Dia da Semana"); } private async Task ExistsAsync(long employeeId, CancellationToken ct = default) diff --git a/OneBus.Application/Validators/EmployeeWorkday/UpdateEmployeeWorkdayDTOValidator.cs b/OneBus.Application/Validators/EmployeeWorkday/UpdateEmployeeWorkdayDTOValidator.cs index 95effef..16057d1 100644 --- a/OneBus.Application/Validators/EmployeeWorkday/UpdateEmployeeWorkdayDTOValidator.cs +++ b/OneBus.Application/Validators/EmployeeWorkday/UpdateEmployeeWorkdayDTOValidator.cs @@ -6,11 +6,7 @@ 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"); + { } } } diff --git a/OneBus.Application/Validators/Maintenance/CreateMaintenanceDTOValidator.cs b/OneBus.Application/Validators/Maintenance/CreateMaintenanceDTOValidator.cs index 2686ca1..0df8bfa 100644 --- a/OneBus.Application/Validators/Maintenance/CreateMaintenanceDTOValidator.cs +++ b/OneBus.Application/Validators/Maintenance/CreateMaintenanceDTOValidator.cs @@ -34,12 +34,7 @@ public CreateMaintenanceDTOValidator(IVehicleRepository vehicleRepository) RuleFor(c => c.Sector) .Must(ValidationUtils.IsValidEnumValue) - .OverridePropertyName("Setor"); - - RuleFor(c => c.EndDate) - .Must((dto, endTime) => endTime >= dto.StartDate) - .WithMessage("Horário inválido") - .OverridePropertyName("Horário de Término"); + .OverridePropertyName("Setor"); } private async Task ExistsAsync(long vehicleId, CancellationToken ct = default) diff --git a/OneBus.Application/Validators/Maintenance/UpdateMaintenanceDTOValidator.cs b/OneBus.Application/Validators/Maintenance/UpdateMaintenanceDTOValidator.cs index f2fcd51..445fd4a 100644 --- a/OneBus.Application/Validators/Maintenance/UpdateMaintenanceDTOValidator.cs +++ b/OneBus.Application/Validators/Maintenance/UpdateMaintenanceDTOValidator.cs @@ -20,12 +20,7 @@ public UpdateMaintenanceDTOValidator() RuleFor(c => c.Sector) .Must(ValidationUtils.IsValidEnumValue) - .OverridePropertyName("Setor"); - - RuleFor(c => c.EndDate) - .Must((dto, endTime) => endTime >= dto.StartDate) - .WithMessage("Horário inválido") - .OverridePropertyName("Horário de Término"); + .OverridePropertyName("Setor"); } } } From 57b8df949315d3b7e063c1e36d29795d5fa6cf77 Mon Sep 17 00:00:00 2001 From: Eduardo Rezende Date: Sat, 1 Nov 2025 20:30:08 -0300 Subject: [PATCH 69/99] =?UTF-8?q?=E2=99=BB=EF=B8=8Frefactor:=20Update=20Ve?= =?UTF-8?q?hicle=20Operation=20entity?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Removing fields --- OneBus.Domain/Entities/VehicleOperation.cs | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/OneBus.Domain/Entities/VehicleOperation.cs b/OneBus.Domain/Entities/VehicleOperation.cs index fd1a149..12552f1 100644 --- a/OneBus.Domain/Entities/VehicleOperation.cs +++ b/OneBus.Domain/Entities/VehicleOperation.cs @@ -2,14 +2,12 @@ { public class VehicleOperation : BaseEntity { - public long? LineTimeId { get; set; } + public long LineTimeId { get; set; } public long EmployeeWorkdayId { get; set; } public long VehicleId { get; set; } - - public DateOnly Date { get; set; } - + public EmployeeWorkday? EmployeeWorkday { get; set; } public Vehicle? Vehicle { get; set; } From 0d86917fcf0a6e4ce8226529dd2264fb1aef9a88 Mon Sep 17 00:00:00 2001 From: Eduardo Rezende Date: Sat, 1 Nov 2025 20:30:49 -0300 Subject: [PATCH 70/99] =?UTF-8?q?=E2=9C=A8feat:=20Add=20Migration?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Updating Vehicle Operation table fields --- ...14_UpdateVehicleOperationTable.Designer.cs | 587 ++++++++++++++++++ ...51101221914_UpdateVehicleOperationTable.cs | 48 ++ .../OneBusDbContextModelSnapshot.cs | 8 +- 3 files changed, 638 insertions(+), 5 deletions(-) create mode 100644 OneBus.Infra.Data/Migrations/20251101221914_UpdateVehicleOperationTable.Designer.cs create mode 100644 OneBus.Infra.Data/Migrations/20251101221914_UpdateVehicleOperationTable.cs diff --git a/OneBus.Infra.Data/Migrations/20251101221914_UpdateVehicleOperationTable.Designer.cs b/OneBus.Infra.Data/Migrations/20251101221914_UpdateVehicleOperationTable.Designer.cs new file mode 100644 index 0000000..a5bfa97 --- /dev/null +++ b/OneBus.Infra.Data/Migrations/20251101221914_UpdateVehicleOperationTable.Designer.cs @@ -0,0 +1,587 @@ +// +using System; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; +using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; +using OneBus.Infra.Data.DbContexts; + +#nullable disable + +namespace OneBus.Infra.Data.Migrations +{ + [DbContext(typeof(OneBusDbContext))] + [Migration("20251101221914_UpdateVehicleOperationTable")] + partial class UpdateVehicleOperationTable + { + /// + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("ProductVersion", "9.0.10") + .HasAnnotation("Relational:MaxIdentifierLength", 63); + + NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder); + + modelBuilder.Entity("OneBus.Domain.Entities.Employee", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("bigint"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("BloodType") + .HasColumnType("smallint"); + + b.Property("CnhCategory") + .HasColumnType("smallint"); + + b.Property("CnhExpiration") + .HasColumnType("date"); + + b.Property("CnhNumber") + .HasMaxLength(20) + .IsUnicode(false) + .HasColumnType("character varying(20)"); + + b.Property("Code") + .IsRequired() + .HasMaxLength(30) + .IsUnicode(false) + .HasColumnType("character varying(30)"); + + b.Property("Cpf") + .IsRequired() + .HasMaxLength(20) + .IsUnicode(false) + .HasColumnType("character varying(20)"); + + b.Property("CreatedAt") + .HasColumnType("timestamp with time zone"); + + b.Property("Email") + .IsRequired() + .HasMaxLength(80) + .IsUnicode(false) + .HasColumnType("character varying(80)"); + + b.Property("HiringDate") + .HasColumnType("date"); + + b.Property("Image") + .HasColumnType("bytea"); + + b.Property("IsDeleted") + .HasColumnType("boolean"); + + b.Property("Name") + .IsRequired() + .HasMaxLength(80) + .IsUnicode(false) + .HasColumnType("character varying(80)"); + + b.Property("Phone") + .IsRequired() + .HasMaxLength(20) + .IsUnicode(false) + .HasColumnType("character varying(20)"); + + b.Property("Rg") + .IsRequired() + .HasMaxLength(20) + .IsUnicode(false) + .HasColumnType("character varying(20)"); + + b.Property("Role") + .HasColumnType("smallint"); + + b.Property("Status") + .HasColumnType("smallint"); + + b.HasKey("Id"); + + b.HasIndex("CnhNumber"); + + b.HasIndex("Code"); + + b.HasIndex("Cpf"); + + b.ToTable("Employee"); + }); + + modelBuilder.Entity("OneBus.Domain.Entities.EmployeeWorkday", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("bigint"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("CreatedAt") + .HasColumnType("timestamp with time zone"); + + b.Property("DayType") + .HasColumnType("smallint"); + + b.Property("EmployeeId") + .HasColumnType("bigint"); + + b.Property("EndTime") + .HasColumnType("time without time zone"); + + b.Property("IsDeleted") + .HasColumnType("boolean"); + + b.Property("StartTime") + .HasColumnType("time without time zone"); + + b.HasKey("Id"); + + b.HasIndex("EmployeeId"); + + b.ToTable("EmployeeWorkday"); + }); + + modelBuilder.Entity("OneBus.Domain.Entities.Line", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("bigint"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("CreatedAt") + .HasColumnType("timestamp with time zone"); + + b.Property("DirectionType") + .HasColumnType("smallint"); + + b.Property("IsDeleted") + .HasColumnType("boolean"); + + b.Property("Mileage") + .HasPrecision(19, 4) + .HasColumnType("numeric(19,4)"); + + b.Property("Name") + .IsRequired() + .HasMaxLength(80) + .IsUnicode(false) + .HasColumnType("character varying(80)"); + + b.Property("Number") + .IsRequired() + .HasMaxLength(20) + .IsUnicode(false) + .HasColumnType("character varying(20)"); + + b.Property("TravelTime") + .HasColumnType("time without time zone"); + + b.Property("Type") + .HasColumnType("smallint"); + + b.HasKey("Id"); + + b.ToTable("Line"); + }); + + modelBuilder.Entity("OneBus.Domain.Entities.LineTime", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("bigint"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("CreatedAt") + .HasColumnType("timestamp with time zone"); + + b.Property("DayType") + .HasColumnType("smallint"); + + b.Property("DirectionType") + .HasColumnType("smallint"); + + b.Property("IsDeleted") + .HasColumnType("boolean"); + + b.Property("LineId") + .HasColumnType("bigint"); + + b.Property("Time") + .HasColumnType("time without time zone"); + + b.HasKey("Id"); + + b.HasIndex("LineId"); + + b.ToTable("LineTime"); + }); + + modelBuilder.Entity("OneBus.Domain.Entities.Maintenance", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("bigint"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("Cost") + .HasPrecision(19, 4) + .HasColumnType("numeric(19,4)"); + + b.Property("CreatedAt") + .HasColumnType("timestamp with time zone"); + + b.Property("Description") + .IsRequired() + .HasMaxLength(150) + .IsUnicode(false) + .HasColumnType("character varying(150)"); + + b.Property("EndDate") + .HasColumnType("date"); + + b.Property("IsDeleted") + .HasColumnType("boolean"); + + b.Property("Sector") + .HasColumnType("smallint"); + + b.Property("StartDate") + .HasColumnType("date"); + + b.Property("SurveyExpiration") + .HasColumnType("date"); + + b.Property("VehicleId") + .HasColumnType("bigint"); + + b.HasKey("Id"); + + b.HasIndex("VehicleId"); + + b.ToTable("Maintenance"); + }); + + modelBuilder.Entity("OneBus.Domain.Entities.User", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("bigint"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("CreatedAt") + .HasColumnType("timestamp with time zone"); + + b.Property("Email") + .IsRequired() + .HasMaxLength(80) + .IsUnicode(false) + .HasColumnType("character varying(80)"); + + b.Property("IsDeleted") + .HasColumnType("boolean"); + + b.Property("Name") + .IsRequired() + .HasMaxLength(80) + .IsUnicode(false) + .HasColumnType("character varying(80)"); + + b.Property("Password") + .IsRequired() + .HasMaxLength(50) + .IsUnicode(false) + .HasColumnType("character varying(50)"); + + b.Property("Salt") + .IsRequired() + .HasMaxLength(32) + .IsUnicode(false) + .HasColumnType("character varying(32)"); + + b.HasKey("Id"); + + b.ToTable("User"); + + b.HasData( + new + { + Id = 1L, + CreatedAt = new DateTime(2025, 8, 25, 0, 0, 0, 0, DateTimeKind.Utc), + Email = "onebus@admin", + IsDeleted = false, + Name = "Administrador", + Password = "YRT66Z4XEJ2SSNaJVDIXQW7uvC8LSvOxDU1sH/Sr/ic=", + Salt = "c37b6028194d489192aac9391801594a" + }); + }); + + modelBuilder.Entity("OneBus.Domain.Entities.Vehicle", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("bigint"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("AcquisitionDate") + .HasColumnType("date"); + + b.Property("AxesNumber") + .HasColumnType("smallint"); + + b.Property("BodyworkNumber") + .HasMaxLength(20) + .IsUnicode(false) + .HasColumnType("character varying(20)"); + + b.Property("Brand") + .HasColumnType("smallint"); + + b.Property("BusChassisBrand") + .HasColumnType("smallint"); + + b.Property("BusChassisModel") + .HasMaxLength(50) + .IsUnicode(false) + .HasColumnType("character varying(50)"); + + b.Property("BusChassisYear") + .HasColumnType("smallint"); + + b.Property("BusFumigateExpiration") + .HasColumnType("date"); + + b.Property("BusHasLeftDoors") + .HasColumnType("boolean"); + + b.Property("BusHasLowFloor") + .HasColumnType("boolean"); + + b.Property("BusInsuranceExpiration") + .HasColumnType("date"); + + b.Property("BusServiceType") + .HasColumnType("smallint"); + + b.Property("Color") + .HasColumnType("smallint"); + + b.Property("CreatedAt") + .HasColumnType("timestamp with time zone"); + + b.Property("EngineNumber") + .HasMaxLength(20) + .IsUnicode(false) + .HasColumnType("character varying(20)"); + + b.Property("FuelType") + .HasColumnType("smallint"); + + b.Property("HasAccessibility") + .HasColumnType("boolean"); + + b.Property("Image") + .HasColumnType("bytea"); + + b.Property("IpvaExpiration") + .HasColumnType("date"); + + b.Property("IsDeleted") + .HasColumnType("boolean"); + + b.Property("Licensing") + .IsRequired() + .HasMaxLength(50) + .IsUnicode(false) + .HasColumnType("character varying(50)"); + + b.Property("Model") + .IsRequired() + .HasMaxLength(50) + .IsUnicode(false) + .HasColumnType("character varying(50)"); + + b.Property("NumberChassis") + .HasMaxLength(20) + .IsUnicode(false) + .HasColumnType("character varying(20)"); + + b.Property("NumberDoors") + .HasColumnType("smallint"); + + b.Property("NumberSeats") + .HasColumnType("smallint"); + + b.Property("Plate") + .IsRequired() + .HasMaxLength(20) + .IsUnicode(false) + .HasColumnType("character varying(20)"); + + b.Property("Prefix") + .IsRequired() + .HasMaxLength(30) + .IsUnicode(false) + .HasColumnType("character varying(30)"); + + b.Property("Renavam") + .IsRequired() + .HasMaxLength(20) + .IsUnicode(false) + .HasColumnType("character varying(20)"); + + b.Property("Status") + .HasColumnType("smallint"); + + b.Property("TransmissionType") + .HasColumnType("smallint"); + + b.Property("Type") + .HasColumnType("smallint"); + + b.Property("Year") + .HasColumnType("integer"); + + b.HasKey("Id"); + + b.HasIndex("Plate"); + + b.HasIndex("Prefix"); + + b.HasIndex("Renavam"); + + b.ToTable("Vehicle"); + }); + + modelBuilder.Entity("OneBus.Domain.Entities.VehicleOperation", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("bigint"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("CreatedAt") + .HasColumnType("timestamp with time zone"); + + b.Property("EmployeeWorkdayId") + .HasColumnType("bigint"); + + b.Property("IsDeleted") + .HasColumnType("boolean"); + + b.Property("LineTimeId") + .HasColumnType("bigint"); + + b.Property("VehicleId") + .HasColumnType("bigint"); + + b.HasKey("Id"); + + b.HasIndex("EmployeeWorkdayId"); + + b.HasIndex("LineTimeId"); + + b.HasIndex("VehicleId"); + + b.ToTable("VehicleOperation"); + }); + + modelBuilder.Entity("OneBus.Domain.Entities.EmployeeWorkday", b => + { + b.HasOne("OneBus.Domain.Entities.Employee", "Employee") + .WithMany("EmployeeWorkdays") + .HasForeignKey("EmployeeId") + .OnDelete(DeleteBehavior.Restrict) + .IsRequired(); + + b.Navigation("Employee"); + }); + + modelBuilder.Entity("OneBus.Domain.Entities.LineTime", b => + { + b.HasOne("OneBus.Domain.Entities.Line", "Line") + .WithMany("LineTimes") + .HasForeignKey("LineId") + .OnDelete(DeleteBehavior.Restrict) + .IsRequired(); + + b.Navigation("Line"); + }); + + modelBuilder.Entity("OneBus.Domain.Entities.Maintenance", b => + { + b.HasOne("OneBus.Domain.Entities.Vehicle", "Vehicle") + .WithMany("Maintenances") + .HasForeignKey("VehicleId") + .OnDelete(DeleteBehavior.Restrict) + .IsRequired(); + + b.Navigation("Vehicle"); + }); + + modelBuilder.Entity("OneBus.Domain.Entities.VehicleOperation", b => + { + b.HasOne("OneBus.Domain.Entities.EmployeeWorkday", "EmployeeWorkday") + .WithMany("VehicleOperations") + .HasForeignKey("EmployeeWorkdayId") + .OnDelete(DeleteBehavior.Restrict) + .IsRequired(); + + b.HasOne("OneBus.Domain.Entities.LineTime", "LineTime") + .WithMany("VehicleOperations") + .HasForeignKey("LineTimeId") + .OnDelete(DeleteBehavior.Restrict) + .IsRequired(); + + b.HasOne("OneBus.Domain.Entities.Vehicle", "Vehicle") + .WithMany("VehicleOperations") + .HasForeignKey("VehicleId") + .OnDelete(DeleteBehavior.Restrict) + .IsRequired(); + + b.Navigation("EmployeeWorkday"); + + b.Navigation("LineTime"); + + b.Navigation("Vehicle"); + }); + + modelBuilder.Entity("OneBus.Domain.Entities.Employee", b => + { + b.Navigation("EmployeeWorkdays"); + }); + + modelBuilder.Entity("OneBus.Domain.Entities.EmployeeWorkday", b => + { + b.Navigation("VehicleOperations"); + }); + + modelBuilder.Entity("OneBus.Domain.Entities.Line", b => + { + b.Navigation("LineTimes"); + }); + + modelBuilder.Entity("OneBus.Domain.Entities.LineTime", b => + { + b.Navigation("VehicleOperations"); + }); + + modelBuilder.Entity("OneBus.Domain.Entities.Vehicle", b => + { + b.Navigation("Maintenances"); + + b.Navigation("VehicleOperations"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/OneBus.Infra.Data/Migrations/20251101221914_UpdateVehicleOperationTable.cs b/OneBus.Infra.Data/Migrations/20251101221914_UpdateVehicleOperationTable.cs new file mode 100644 index 0000000..1152964 --- /dev/null +++ b/OneBus.Infra.Data/Migrations/20251101221914_UpdateVehicleOperationTable.cs @@ -0,0 +1,48 @@ +using System; +using Microsoft.EntityFrameworkCore.Migrations; + +#nullable disable + +namespace OneBus.Infra.Data.Migrations +{ + /// + public partial class UpdateVehicleOperationTable : Migration + { + /// + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropColumn( + name: "Date", + table: "VehicleOperation"); + + migrationBuilder.AlterColumn( + name: "LineTimeId", + table: "VehicleOperation", + type: "bigint", + nullable: false, + defaultValue: 0L, + oldClrType: typeof(long), + oldType: "bigint", + oldNullable: true); + } + + /// + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.AlterColumn( + name: "LineTimeId", + table: "VehicleOperation", + type: "bigint", + nullable: true, + oldClrType: typeof(long), + oldType: "bigint"); + + migrationBuilder.AddColumn( + name: "Date", + table: "VehicleOperation", + type: "date", + nullable: false, + defaultValue: new DateOnly(1, 1, 1)); + } + } +} diff --git a/OneBus.Infra.Data/Migrations/OneBusDbContextModelSnapshot.cs b/OneBus.Infra.Data/Migrations/OneBusDbContextModelSnapshot.cs index f73050b..ee86dca 100644 --- a/OneBus.Infra.Data/Migrations/OneBusDbContextModelSnapshot.cs +++ b/OneBus.Infra.Data/Migrations/OneBusDbContextModelSnapshot.cs @@ -469,16 +469,13 @@ protected override void BuildModel(ModelBuilder modelBuilder) b.Property("CreatedAt") .HasColumnType("timestamp with time zone"); - b.Property("Date") - .HasColumnType("date"); - b.Property("EmployeeWorkdayId") .HasColumnType("bigint"); b.Property("IsDeleted") .HasColumnType("boolean"); - b.Property("LineTimeId") + b.Property("LineTimeId") .HasColumnType("bigint"); b.Property("VehicleId") @@ -539,7 +536,8 @@ protected override void BuildModel(ModelBuilder modelBuilder) b.HasOne("OneBus.Domain.Entities.LineTime", "LineTime") .WithMany("VehicleOperations") .HasForeignKey("LineTimeId") - .OnDelete(DeleteBehavior.Restrict); + .OnDelete(DeleteBehavior.Restrict) + .IsRequired(); b.HasOne("OneBus.Domain.Entities.Vehicle", "Vehicle") .WithMany("VehicleOperations") From c3fa05592728492f6dde60a87b480b1746294f82 Mon Sep 17 00:00:00 2001 From: Eduardo Rezende Date: Sat, 1 Nov 2025 20:31:55 -0300 Subject: [PATCH 71/99] =?UTF-8?q?=E2=9C=A8feat:=20Add=20Vehicle=20Operatio?= =?UTF-8?q?n=20filter?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Adding filter class --- .../Filters/VehicleOperationFilter.cs | 37 +++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 OneBus.Domain/Filters/VehicleOperationFilter.cs diff --git a/OneBus.Domain/Filters/VehicleOperationFilter.cs b/OneBus.Domain/Filters/VehicleOperationFilter.cs new file mode 100644 index 0000000..5d8cc3a --- /dev/null +++ b/OneBus.Domain/Filters/VehicleOperationFilter.cs @@ -0,0 +1,37 @@ +namespace OneBus.Domain.Filters +{ + public class VehicleOperationFilter : BaseFilter + { + public byte? EmployeeStatus { get; set; } + + public byte? EmployeeRole { get; set; } + + public byte? EmployeeBloodType { get; set; } + + public byte? EmployeeWorkDayDayType { get; set; } + + public byte? LineType { get; set; } + + public byte? LineDirectionType { get; set; } + + public byte? LineTimeDirectionType { get; set; } + + public byte? LineTimeDayType { get; set; } + + public byte? VehicleStatus { get; set; } + + public byte? VehicleType { get; set; } + + public byte? VehicleBrand { get; set; } + + public byte? VehicleBusChassisBrand { get; set; } + + public byte? VehicleBusServiceType { get; set; } + + public byte? VehicleColor { get; set; } + + public byte? VehicleFuelType { get; set; } + + public byte? VehicleTransmissionType { get; set; } + } +} From 56306ca93f9e65769252a04b3839722eb2458bd0 Mon Sep 17 00:00:00 2001 From: Eduardo Rezende Date: Sat, 1 Nov 2025 20:32:33 -0300 Subject: [PATCH 72/99] =?UTF-8?q?=E2=99=BB=EF=B8=8Frefactor:=20Update=20Ve?= =?UTF-8?q?hicle=20Operation=20Repository?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Adding filtering logic --- .../IVehicleOperationRepository.cs | 2 +- .../VehicleOperationRepository.cs | 51 +++++++++++++++++-- 2 files changed, 48 insertions(+), 5 deletions(-) diff --git a/OneBus.Domain/Interfaces/Repositories/IVehicleOperationRepository.cs b/OneBus.Domain/Interfaces/Repositories/IVehicleOperationRepository.cs index f51954c..8d6052a 100644 --- a/OneBus.Domain/Interfaces/Repositories/IVehicleOperationRepository.cs +++ b/OneBus.Domain/Interfaces/Repositories/IVehicleOperationRepository.cs @@ -3,7 +3,7 @@ namespace OneBus.Domain.Interfaces.Repositories { - public interface IVehicleOperationRepository : IBaseRepository + public interface IVehicleOperationRepository : IBaseRepository { } } diff --git a/OneBus.Infra.Data/Repositories/VehicleOperationRepository.cs b/OneBus.Infra.Data/Repositories/VehicleOperationRepository.cs index c7ccb68..6c84784 100644 --- a/OneBus.Infra.Data/Repositories/VehicleOperationRepository.cs +++ b/OneBus.Infra.Data/Repositories/VehicleOperationRepository.cs @@ -1,14 +1,57 @@ -using OneBus.Domain.Entities; -using OneBus.Domain.Filters; -using OneBus.Domain.Interfaces.Repositories; +using OneBus.Domain.Filters; +using OneBus.Domain.Entities; +using System.Linq.Expressions; using OneBus.Infra.Data.DbContexts; +using OneBus.Domain.Interfaces.Repositories; namespace OneBus.Infra.Data.Repositories { - public class VehicleOperationRepository : BaseRepository, IVehicleOperationRepository + public class VehicleOperationRepository : BaseRepository, IVehicleOperationRepository { public VehicleOperationRepository(OneBusDbContext dbContext) : base(dbContext) { } + + protected override Expression> ApplyFilter(VehicleOperationFilter filter) + { + var value = filter.Value?.ToLower(); + + return c => + (filter.LineType == null || c.LineTime!.Line!.Type == filter.LineType) && + (filter.VehicleType == null || c.Vehicle!.Type == filter.VehicleType) && + (filter.VehicleColor == null || c.Vehicle!.Color == filter.VehicleColor) && + (filter.VehicleBrand == null || c.Vehicle!.Brand == filter.VehicleBrand) && + (filter.VehicleStatus == null || c.Vehicle!.Status == filter.VehicleStatus) && + (filter.VehicleFuelType == null || c.Vehicle!.FuelType == filter.VehicleFuelType) && + (filter.LineTimeDayType == null || c.LineTime!.DayType == filter.LineTimeDayType) && + (filter.EmployeeRole == null || c.EmployeeWorkday!.Employee!.Role == filter.EmployeeRole) && + (filter.EmployeeStatus == null || c.EmployeeWorkday!.Employee!.Status == filter.EmployeeStatus) && + (filter.LineDirectionType == null || c.LineTime!.Line!.DirectionType == filter.LineDirectionType) && + (filter.VehicleBusServiceType == null || c.Vehicle!.BusServiceType == filter.VehicleBusServiceType) && + (filter.LineTimeDirectionType == null || c.LineTime!.DirectionType == filter.LineTimeDirectionType) && + (filter.VehicleBusChassisBrand == null || c.Vehicle!.BusChassisBrand == filter.VehicleBusChassisBrand) && + (filter.EmployeeWorkDayDayType == null || c.EmployeeWorkday!.DayType == filter.EmployeeWorkDayDayType) && + (filter.EmployeeBloodType == null || c.EmployeeWorkday!.Employee!.BloodType == filter.EmployeeBloodType) && + (filter.VehicleTransmissionType == null || c.Vehicle!.TransmissionType == filter.VehicleTransmissionType) && + (string.IsNullOrWhiteSpace(value) || + ((c.EmployeeWorkday!.Employee!.Name.ToLower().Contains(value) || + c.EmployeeWorkday!.Employee!.Code.ToLower().Contains(value) || + c.LineTime!.Line!.Mileage.ToString().Contains(value) || + c.LineTime!.Line!.Name.ToLower().Contains(value) || + c.LineTime!.Line!.Number.ToLower().Contains(value) || + c.Vehicle!.Prefix.ToLower().Contains(value) || + c.Vehicle!.Model.ToLower().Contains(value) || + c.Vehicle!.Plate.ToLower().Contains(value) || + c.Vehicle!.Renavam.ToLower().Contains(value) || + c.Vehicle!.Licensing!.ToLower().Contains(value) || + c.Vehicle!.NumberChassis!.ToLower().Contains(value) || + c.Vehicle!.BodyworkNumber!.ToLower().Contains(value) || + c.Vehicle!.BusChassisModel!.ToLower().Contains(value) || + c.Vehicle!.EngineNumber!.ToLower().Contains(value) || + c.EmployeeWorkday!.Employee!.Rg.ToLower().Contains(value) || + c.EmployeeWorkday!.Employee!.Cpf.ToLower().Contains(value) || + c.EmployeeWorkday!.Employee!.Phone.ToLower().Contains(value) || + c.EmployeeWorkday!.Employee!.CnhNumber!.ToLower().Contains(value)) && value != string.Empty)); + } } } From c009bcf2537901936b3276fd41919c33e9a1d9d2 Mon Sep 17 00:00:00 2001 From: Eduardo Rezende Date: Sat, 1 Nov 2025 20:32:49 -0300 Subject: [PATCH 73/99] =?UTF-8?q?=E2=99=BB=EF=B8=8Frefactor:=20Update=20Ve?= =?UTF-8?q?hicle=20Operation=20DTOs?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Adding fields --- .../CreateVehicleOperationDTO.cs | 5 ++ .../ReadVehicleOperationDTO.cs | 69 ++++++++++++++++++- .../UpdateVehicleOperationDTO.cs | 5 ++ 3 files changed, 78 insertions(+), 1 deletion(-) diff --git a/OneBus.Application/DTOs/VehicleOperation/CreateVehicleOperationDTO.cs b/OneBus.Application/DTOs/VehicleOperation/CreateVehicleOperationDTO.cs index 0fa953c..bab4a08 100644 --- a/OneBus.Application/DTOs/VehicleOperation/CreateVehicleOperationDTO.cs +++ b/OneBus.Application/DTOs/VehicleOperation/CreateVehicleOperationDTO.cs @@ -2,5 +2,10 @@ { public class CreateVehicleOperationDTO : BaseCreateDTO { + public long LineTimeId { get; set; } + + public long EmployeeWorkdayId { get; set; } + + public long VehicleId { get; set; } } } diff --git a/OneBus.Application/DTOs/VehicleOperation/ReadVehicleOperationDTO.cs b/OneBus.Application/DTOs/VehicleOperation/ReadVehicleOperationDTO.cs index 2d9b991..273781b 100644 --- a/OneBus.Application/DTOs/VehicleOperation/ReadVehicleOperationDTO.cs +++ b/OneBus.Application/DTOs/VehicleOperation/ReadVehicleOperationDTO.cs @@ -1,6 +1,73 @@ -namespace OneBus.Application.DTOs.VehicleOperation +using System.Text.Json.Serialization; + +namespace OneBus.Application.DTOs.VehicleOperation { public class ReadVehicleOperationDTO : BaseReadDTO { + public long LineTimeId { get; set; } + + public TimeOnly? LineTimeTime { get; set; } + + public byte? LineTimeDayType { get; set; } + + public string? LineTimeDayTypeName { get; set; } + + public byte? LineTimeDirectionType { get; set; } + + public string? LineTimeDirectionTypeName { get; set; } + + [JsonPropertyName("lineId")] + public long? LineTimeLineId { get; set; } + + [JsonPropertyName("lineDirectionType")] + public byte? LineTimeLineDirectionType { get; set; } + + [JsonPropertyName("lineDirectionTypeName")] + public string? LineTimeLineDirectionTypeName { get; set; } + + [JsonPropertyName("lineType")] + public byte? LineTimeLineType { get; set; } + + [JsonPropertyName("lineTypeName")] + public string? LineTimeLineTypeName { get; set; } + + [JsonPropertyName("lineNumber")] + public string? LineTimeLineNumber { get; set; } + + [JsonPropertyName("lineName")] + public string? LineTimeLineName { get; set; } + + public long EmployeeWorkdayId { get; set; } + + public TimeOnly? EmployeeWorkdayStartTime { get; set; } + + public TimeOnly? EmployeeWorkdayEndTime { get; set; } + + public byte? EmployeeWorkdayDayType { get; set; } + + public string? EmployeeWorkdayDayTypeName { get; set; } + + [JsonPropertyName("employeeId")] + public long? EmployeeWorkdayEmployeeId { get; set; } + + [JsonPropertyName("employeeName")] + public string? EmployeeWorkdayEmployeeName { get; set; } + + [JsonPropertyName("employeeImage")] + public byte[]? EmployeeWorkdayEmployeeImage { get; set; } + + [JsonPropertyName("employeeCpf")] + public string? EmployeeWorkdayEmployeeCpf { get; set; } + + [JsonPropertyName("employeeCode")] + public string? EmployeeWorkdayEmployeeCode { get; set; } + + public long VehicleId { get; set; } + + public string? VehiclePrefix { get; set; } + + public byte? VehicleType { get; set; } + + public string? VehicleTypeName { get; set; } } } diff --git a/OneBus.Application/DTOs/VehicleOperation/UpdateVehicleOperationDTO.cs b/OneBus.Application/DTOs/VehicleOperation/UpdateVehicleOperationDTO.cs index 6bf63a5..503ccf9 100644 --- a/OneBus.Application/DTOs/VehicleOperation/UpdateVehicleOperationDTO.cs +++ b/OneBus.Application/DTOs/VehicleOperation/UpdateVehicleOperationDTO.cs @@ -2,5 +2,10 @@ { public class UpdateVehicleOperationDTO : BaseUpdateDTO { + public long LineTimeId { get; set; } + + public long EmployeeWorkdayId { get; set; } + + public long VehicleId { get; set; } } } From a1e7ce1fc03ac1225cc089013b2b7783a15bd5c5 Mon Sep 17 00:00:00 2001 From: Eduardo Rezende Date: Sat, 1 Nov 2025 20:33:40 -0300 Subject: [PATCH 74/99] =?UTF-8?q?=E2=99=BB=EF=B8=8Frefactor:=20Update=20Ve?= =?UTF-8?q?hicle=20Operation=20Validators?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Adding validation logic for Create anda Update DTOs --- .../Validators/Line/CreateLineDTOValidator.cs | 2 + .../CreateVehicleOperationDTOValidator.cs | 49 +++++++++++++++++++ .../UpdateVehicleOperationDTOValidator.cs | 47 ++++++++++++++++++ 3 files changed, 98 insertions(+) diff --git a/OneBus.Application/Validators/Line/CreateLineDTOValidator.cs b/OneBus.Application/Validators/Line/CreateLineDTOValidator.cs index 9d4ef5f..0135f23 100644 --- a/OneBus.Application/Validators/Line/CreateLineDTOValidator.cs +++ b/OneBus.Application/Validators/Line/CreateLineDTOValidator.cs @@ -11,6 +11,8 @@ public class CreateLineDTOValidator : AbstractValidator { private readonly ILineRepository _lineRepository; + //TODO: Não deixar a mesma linha pode pode ter sentido de ida e volta, mas não de circular e + //uma linha circular não pode ter outro cadastro com sentido de ida ou volta public CreateLineDTOValidator(ILineRepository lineRepository) { _lineRepository = lineRepository; diff --git a/OneBus.Application/Validators/VehicleOperation/CreateVehicleOperationDTOValidator.cs b/OneBus.Application/Validators/VehicleOperation/CreateVehicleOperationDTOValidator.cs index cb6668f..355e501 100644 --- a/OneBus.Application/Validators/VehicleOperation/CreateVehicleOperationDTOValidator.cs +++ b/OneBus.Application/Validators/VehicleOperation/CreateVehicleOperationDTOValidator.cs @@ -1,9 +1,58 @@ using FluentValidation; +using OneBus.Domain.Commons; +using OneBus.Domain.Interfaces.Repositories; using OneBus.Application.DTOs.VehicleOperation; namespace OneBus.Application.Validators.VehicleOperation { public class CreateVehicleOperationDTOValidator : AbstractValidator { + private readonly IVehicleRepository _vehicleRepository; + private readonly ILineTimeRepository _lineTimeRepository; + private readonly IEmployeeWorkdayRepository _employeeWorkdayRepository; + + public const string VehicleIdPropertyName = "Id do Veículo"; + public const string LineTimeIdPropertyName = "Id do Horário Linha"; + public const string EmployeeWorkdayIdPropertyName = "Id do Horário Funcionário"; + + public CreateVehicleOperationDTOValidator( + IVehicleRepository vehicleRepository, + ILineTimeRepository lineTimeRepository, + IEmployeeWorkdayRepository employeeWorkdayRepository) + { + _vehicleRepository = vehicleRepository; + _lineTimeRepository = lineTimeRepository; + _employeeWorkdayRepository = employeeWorkdayRepository; + + RuleFor(c => c.VehicleId) + .MustAsync(VehicleExistsAsync) + .WithMessage(ErrorUtils.EntityNotFound(VehicleIdPropertyName).Message) + .OverridePropertyName(VehicleIdPropertyName); + + RuleFor(c => c.LineTimeId) + .MustAsync(LineTimeExistsAsync) + .WithMessage(ErrorUtils.EntityNotFound(LineTimeIdPropertyName).Message) + .OverridePropertyName(LineTimeIdPropertyName); + + RuleFor(c => c.EmployeeWorkdayId) + .MustAsync(EmployeeWorkdayExistsAsync) + .WithMessage(ErrorUtils.EntityNotFound(EmployeeWorkdayIdPropertyName).Message) + .OverridePropertyName(EmployeeWorkdayIdPropertyName); + } + + private async Task VehicleExistsAsync(long vehicleId, CancellationToken ct = default) + { + return await _vehicleRepository.AnyAsync(c => c.Id == vehicleId, cancellationToken: ct); + } + + private async Task LineTimeExistsAsync(long lineTimeId, CancellationToken ct = default) + { + return await _lineTimeRepository.AnyAsync(c => c.Id == lineTimeId, cancellationToken: ct); + } + + private async Task EmployeeWorkdayExistsAsync(long employeeWorkdayId, CancellationToken ct = default) + { + return await _employeeWorkdayRepository.AnyAsync(c => c.Id == employeeWorkdayId, cancellationToken: ct); + } } } diff --git a/OneBus.Application/Validators/VehicleOperation/UpdateVehicleOperationDTOValidator.cs b/OneBus.Application/Validators/VehicleOperation/UpdateVehicleOperationDTOValidator.cs index 8811d8c..2698054 100644 --- a/OneBus.Application/Validators/VehicleOperation/UpdateVehicleOperationDTOValidator.cs +++ b/OneBus.Application/Validators/VehicleOperation/UpdateVehicleOperationDTOValidator.cs @@ -1,9 +1,56 @@ using FluentValidation; +using OneBus.Domain.Commons; +using OneBus.Domain.Interfaces.Repositories; using OneBus.Application.DTOs.VehicleOperation; namespace OneBus.Application.Validators.VehicleOperation { public class UpdateVehicleOperationDTOValidator : AbstractValidator { + private readonly IVehicleRepository _vehicleRepository; + private readonly ILineTimeRepository _lineTimeRepository; + private readonly IEmployeeWorkdayRepository _employeeWorkdayRepository; + + public UpdateVehicleOperationDTOValidator( + IVehicleRepository vehicleRepository, + ILineTimeRepository lineTimeRepository, + IEmployeeWorkdayRepository employeeWorkdayRepository) + { + _vehicleRepository = vehicleRepository; + _lineTimeRepository = lineTimeRepository; + _employeeWorkdayRepository = employeeWorkdayRepository; + + RuleFor(c => c.Id).GreaterThan(0); + + RuleFor(c => c.VehicleId) + .MustAsync(VehicleExistsAsync) + .WithMessage(ErrorUtils.EntityNotFound(CreateVehicleOperationDTOValidator.VehicleIdPropertyName).Message) + .OverridePropertyName(CreateVehicleOperationDTOValidator.VehicleIdPropertyName); + + RuleFor(c => c.LineTimeId) + .MustAsync(LineTimeExistsAsync) + .WithMessage(ErrorUtils.EntityNotFound(CreateVehicleOperationDTOValidator.LineTimeIdPropertyName).Message) + .OverridePropertyName(CreateVehicleOperationDTOValidator.LineTimeIdPropertyName); + + RuleFor(c => c.EmployeeWorkdayId) + .MustAsync(EmployeeWorkdayExistsAsync) + .WithMessage(ErrorUtils.EntityNotFound(CreateVehicleOperationDTOValidator.EmployeeWorkdayIdPropertyName).Message) + .OverridePropertyName(CreateVehicleOperationDTOValidator.EmployeeWorkdayIdPropertyName); + } + + private async Task VehicleExistsAsync(long vehicleId, CancellationToken ct = default) + { + return await _vehicleRepository.AnyAsync(c => c.Id == vehicleId, cancellationToken: ct); + } + + private async Task LineTimeExistsAsync(long lineTimeId, CancellationToken ct = default) + { + return await _lineTimeRepository.AnyAsync(c => c.Id == lineTimeId, cancellationToken: ct); + } + + private async Task EmployeeWorkdayExistsAsync(long employeeWorkdayId, CancellationToken ct = default) + { + return await _employeeWorkdayRepository.AnyAsync(c => c.Id == employeeWorkdayId, cancellationToken: ct); + } } } From c14c16b0d9180f07bfb2ea31b08043ff93185199 Mon Sep 17 00:00:00 2001 From: Eduardo Rezende Date: Sat, 1 Nov 2025 20:34:45 -0300 Subject: [PATCH 75/99] =?UTF-8?q?=E2=99=BB=EF=B8=8Frefactor:=20Update=20Ve?= =?UTF-8?q?hicle=20Operation=20Service?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Updating GET methods and implementing UpdateFields method --- .../Services/IVehicleOperationService.cs | 2 +- .../Services/VehicleOperationService.cs | 58 ++++++++++++++++++- 2 files changed, 56 insertions(+), 4 deletions(-) diff --git a/OneBus.Application/Interfaces/Services/IVehicleOperationService.cs b/OneBus.Application/Interfaces/Services/IVehicleOperationService.cs index 4b81d0e..f776053 100644 --- a/OneBus.Application/Interfaces/Services/IVehicleOperationService.cs +++ b/OneBus.Application/Interfaces/Services/IVehicleOperationService.cs @@ -5,7 +5,7 @@ namespace OneBus.Application.Interfaces.Services { public interface IVehicleOperationService : - IBaseService + IBaseService { } } diff --git a/OneBus.Application/Services/VehicleOperationService.cs b/OneBus.Application/Services/VehicleOperationService.cs index 93f3b93..b3836bf 100644 --- a/OneBus.Application/Services/VehicleOperationService.cs +++ b/OneBus.Application/Services/VehicleOperationService.cs @@ -1,26 +1,78 @@ using FluentValidation; using OneBus.Application.DTOs.VehicleOperation; 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.Enums.Line; +using OneBus.Domain.Enums.Vehicle; +using OneBus.Domain.Extensions; using OneBus.Domain.Filters; using OneBus.Domain.Interfaces.Repositories; namespace OneBus.Application.Services { - public class VehicleOperationService : BaseService, + public class VehicleOperationService : BaseService, IVehicleOperationService { public VehicleOperationService( - IBaseRepository baseRepository, + IBaseRepository baseRepository, IValidator createValidator, IValidator updateValidator) : base(baseRepository, createValidator, updateValidator) { } + public override async Task>> GetPaginedAsync( + VehicleOperationFilter filter, + DbQueryOptions? dbQueryOptions = null, + CancellationToken cancellationToken = default) + { + var result = await base.GetPaginedAsync(filter, dbQueryOptions, cancellationToken); + + if (!result.Sucess) + return result; + + foreach (var vehicleOperation in result.Value!.Items) + { + vehicleOperation.VehicleTypeName = ((VehicleType?)vehicleOperation.VehicleType)?.ToString()?.Localize(); + vehicleOperation.LineTimeDayTypeName = ((DayType?)vehicleOperation.LineTimeDayType)?.ToString()?.Localize(); + vehicleOperation.LineTimeLineTypeName = ((LineType?)vehicleOperation.LineTimeLineType)?.ToString()?.Localize(); + vehicleOperation.LineTimeDirectionTypeName = ((DirectionType?)vehicleOperation.LineTimeDirectionType)?.ToString()?.Localize(); + vehicleOperation.EmployeeWorkdayDayTypeName = ((DayType?)vehicleOperation.EmployeeWorkdayDayType)?.ToString()?.Localize(); + vehicleOperation.LineTimeLineDirectionTypeName = ((DirectionType?)vehicleOperation.LineTimeLineDirectionType)?.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 vehicleOperation = result.Value!; + vehicleOperation.VehicleTypeName = ((VehicleType?)vehicleOperation.VehicleType)?.ToString()?.Localize(); + vehicleOperation.LineTimeDayTypeName = ((DayType?)vehicleOperation.LineTimeDayType)?.ToString()?.Localize(); + vehicleOperation.LineTimeLineTypeName = ((LineType?)vehicleOperation.LineTimeLineType)?.ToString()?.Localize(); + vehicleOperation.LineTimeDirectionTypeName = ((DirectionType?)vehicleOperation.LineTimeDirectionType)?.ToString()?.Localize(); + vehicleOperation.EmployeeWorkdayDayTypeName = ((DayType?)vehicleOperation.EmployeeWorkdayDayType)?.ToString()?.Localize(); + vehicleOperation.LineTimeLineDirectionTypeName = ((DirectionType?)vehicleOperation.LineTimeLineDirectionType)?.ToString()?.Localize(); + + return result; + } + protected override void UpdateFields(VehicleOperation entity, UpdateVehicleOperationDTO updateDTO) { - throw new NotImplementedException(); + entity.VehicleId = updateDTO.VehicleId; + entity.LineTimeId = updateDTO.LineTimeId; + entity.EmployeeWorkdayId = updateDTO.EmployeeWorkdayId; } } } From 2f0a9da8b109b0aaad72cd77c481a0c3addd8978 Mon Sep 17 00:00:00 2001 From: Eduardo Rezende Date: Sat, 1 Nov 2025 20:35:48 -0300 Subject: [PATCH 76/99] =?UTF-8?q?=E2=99=BB=EF=B8=8Frefactor:=20Update=20Ve?= =?UTF-8?q?hicle=20Operation=20Controller?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Adding include options for GET endpoints --- OneBus.API/Controllers/VehicleOperationController.cs | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/OneBus.API/Controllers/VehicleOperationController.cs b/OneBus.API/Controllers/VehicleOperationController.cs index aa611cb..b3d36be 100644 --- a/OneBus.API/Controllers/VehicleOperationController.cs +++ b/OneBus.API/Controllers/VehicleOperationController.cs @@ -10,7 +10,6 @@ namespace OneBus.API.Controllers { - [NonController] [Route("api/v1/vehiclesOperations")] [ApiController] [Produces("application/json")] @@ -102,9 +101,11 @@ public async Task DeleteAsync([FromRoute] long id, CancellationTo /// Operações de Veículos paginadas e filtradas com sucesso [HttpGet] [ProducesResponseType(typeof(SuccessResult>), StatusCodes.Status200OK)] - public async Task GetPaginedAsync([FromQuery] BaseFilter filter, CancellationToken cancellationToken = default) + public async Task GetPaginedAsync([FromQuery] VehicleOperationFilter filter, CancellationToken cancellationToken = default) { - return (await _vehicleOperationService.GetPaginedAsync(filter, cancellationToken: cancellationToken)).ToActionResult(); + return (await _vehicleOperationService.GetPaginedAsync(filter, + DbQueryOptions.Create(["LineTime.Line", "EmployeeWorkday.Employee", "Vehicle"]), + cancellationToken)).ToActionResult(); } /// @@ -123,7 +124,9 @@ 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: cancellationToken)).ToActionResult(); + return (await _vehicleOperationService.GetByIdAsync(id, + DbQueryOptions.Create(["LineTime.Line", "EmployeeWorkday.Employee", "Vehicle"]), + cancellationToken)).ToActionResult(); } } } From 915185fd687b0f93f9bfa7e751f2cef5e3b4f481 Mon Sep 17 00:00:00 2001 From: Eduardo Rezende Date: Tue, 4 Nov 2025 20:35:38 -0300 Subject: [PATCH 77/99] =?UTF-8?q?=E2=99=BB=EF=B8=8Frefactor:=20Update=20pr?= =?UTF-8?q?oject=20package?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Updating FluentValidation package --- OneBus.Application/OneBus.Application.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/OneBus.Application/OneBus.Application.csproj b/OneBus.Application/OneBus.Application.csproj index e9d26ee..389288f 100644 --- a/OneBus.Application/OneBus.Application.csproj +++ b/OneBus.Application/OneBus.Application.csproj @@ -7,7 +7,7 @@ - + From 33b7cef9f6362d04d6e780c42e48119dfef21566 Mon Sep 17 00:00:00 2001 From: Eduardo Rezende Date: Tue, 4 Nov 2025 20:36:01 -0300 Subject: [PATCH 78/99] =?UTF-8?q?=E2=99=BB=EF=B8=8Frefactor:=20Update=20Li?= =?UTF-8?q?neTime?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Removing DirectionType field --- OneBus.Domain/Entities/LineTime.cs | 2 -- 1 file changed, 2 deletions(-) diff --git a/OneBus.Domain/Entities/LineTime.cs b/OneBus.Domain/Entities/LineTime.cs index cf59831..d4db1cd 100644 --- a/OneBus.Domain/Entities/LineTime.cs +++ b/OneBus.Domain/Entities/LineTime.cs @@ -8,8 +8,6 @@ public class LineTime : BaseEntity public byte DayType { get; set; } - public byte DirectionType { get; set; } - public Line? Line { get; set; } public ICollection? VehicleOperations { get; set; } From 98faecc98bbd267ae7603eb13873815b5febd04d Mon Sep 17 00:00:00 2001 From: Eduardo Rezende Date: Tue, 4 Nov 2025 20:36:38 -0300 Subject: [PATCH 79/99] =?UTF-8?q?=E2=9C=A8feat:=20Add=20Migration?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Removing DirectionType field from LineTime table --- ...DirectionTypeFromLineTimeTable.Designer.cs | 584 ++++++++++++++++++ ...37_RemoveDirectionTypeFromLineTimeTable.cs | 29 + .../OneBusDbContextModelSnapshot.cs | 3 - 3 files changed, 613 insertions(+), 3 deletions(-) create mode 100644 OneBus.Infra.Data/Migrations/20251104233237_RemoveDirectionTypeFromLineTimeTable.Designer.cs create mode 100644 OneBus.Infra.Data/Migrations/20251104233237_RemoveDirectionTypeFromLineTimeTable.cs diff --git a/OneBus.Infra.Data/Migrations/20251104233237_RemoveDirectionTypeFromLineTimeTable.Designer.cs b/OneBus.Infra.Data/Migrations/20251104233237_RemoveDirectionTypeFromLineTimeTable.Designer.cs new file mode 100644 index 0000000..18bb5d7 --- /dev/null +++ b/OneBus.Infra.Data/Migrations/20251104233237_RemoveDirectionTypeFromLineTimeTable.Designer.cs @@ -0,0 +1,584 @@ +// +using System; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; +using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; +using OneBus.Infra.Data.DbContexts; + +#nullable disable + +namespace OneBus.Infra.Data.Migrations +{ + [DbContext(typeof(OneBusDbContext))] + [Migration("20251104233237_RemoveDirectionTypeFromLineTimeTable")] + partial class RemoveDirectionTypeFromLineTimeTable + { + /// + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("ProductVersion", "9.0.10") + .HasAnnotation("Relational:MaxIdentifierLength", 63); + + NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder); + + modelBuilder.Entity("OneBus.Domain.Entities.Employee", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("bigint"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("BloodType") + .HasColumnType("smallint"); + + b.Property("CnhCategory") + .HasColumnType("smallint"); + + b.Property("CnhExpiration") + .HasColumnType("date"); + + b.Property("CnhNumber") + .HasMaxLength(20) + .IsUnicode(false) + .HasColumnType("character varying(20)"); + + b.Property("Code") + .IsRequired() + .HasMaxLength(30) + .IsUnicode(false) + .HasColumnType("character varying(30)"); + + b.Property("Cpf") + .IsRequired() + .HasMaxLength(20) + .IsUnicode(false) + .HasColumnType("character varying(20)"); + + b.Property("CreatedAt") + .HasColumnType("timestamp with time zone"); + + b.Property("Email") + .IsRequired() + .HasMaxLength(80) + .IsUnicode(false) + .HasColumnType("character varying(80)"); + + b.Property("HiringDate") + .HasColumnType("date"); + + b.Property("Image") + .HasColumnType("bytea"); + + b.Property("IsDeleted") + .HasColumnType("boolean"); + + b.Property("Name") + .IsRequired() + .HasMaxLength(80) + .IsUnicode(false) + .HasColumnType("character varying(80)"); + + b.Property("Phone") + .IsRequired() + .HasMaxLength(20) + .IsUnicode(false) + .HasColumnType("character varying(20)"); + + b.Property("Rg") + .IsRequired() + .HasMaxLength(20) + .IsUnicode(false) + .HasColumnType("character varying(20)"); + + b.Property("Role") + .HasColumnType("smallint"); + + b.Property("Status") + .HasColumnType("smallint"); + + b.HasKey("Id"); + + b.HasIndex("CnhNumber"); + + b.HasIndex("Code"); + + b.HasIndex("Cpf"); + + b.ToTable("Employee"); + }); + + modelBuilder.Entity("OneBus.Domain.Entities.EmployeeWorkday", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("bigint"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("CreatedAt") + .HasColumnType("timestamp with time zone"); + + b.Property("DayType") + .HasColumnType("smallint"); + + b.Property("EmployeeId") + .HasColumnType("bigint"); + + b.Property("EndTime") + .HasColumnType("time without time zone"); + + b.Property("IsDeleted") + .HasColumnType("boolean"); + + b.Property("StartTime") + .HasColumnType("time without time zone"); + + b.HasKey("Id"); + + b.HasIndex("EmployeeId"); + + b.ToTable("EmployeeWorkday"); + }); + + modelBuilder.Entity("OneBus.Domain.Entities.Line", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("bigint"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("CreatedAt") + .HasColumnType("timestamp with time zone"); + + b.Property("DirectionType") + .HasColumnType("smallint"); + + b.Property("IsDeleted") + .HasColumnType("boolean"); + + b.Property("Mileage") + .HasPrecision(19, 4) + .HasColumnType("numeric(19,4)"); + + b.Property("Name") + .IsRequired() + .HasMaxLength(80) + .IsUnicode(false) + .HasColumnType("character varying(80)"); + + b.Property("Number") + .IsRequired() + .HasMaxLength(20) + .IsUnicode(false) + .HasColumnType("character varying(20)"); + + b.Property("TravelTime") + .HasColumnType("time without time zone"); + + b.Property("Type") + .HasColumnType("smallint"); + + b.HasKey("Id"); + + b.ToTable("Line"); + }); + + modelBuilder.Entity("OneBus.Domain.Entities.LineTime", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("bigint"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("CreatedAt") + .HasColumnType("timestamp with time zone"); + + b.Property("DayType") + .HasColumnType("smallint"); + + b.Property("IsDeleted") + .HasColumnType("boolean"); + + b.Property("LineId") + .HasColumnType("bigint"); + + b.Property("Time") + .HasColumnType("time without time zone"); + + b.HasKey("Id"); + + b.HasIndex("LineId"); + + b.ToTable("LineTime"); + }); + + modelBuilder.Entity("OneBus.Domain.Entities.Maintenance", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("bigint"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("Cost") + .HasPrecision(19, 4) + .HasColumnType("numeric(19,4)"); + + b.Property("CreatedAt") + .HasColumnType("timestamp with time zone"); + + b.Property("Description") + .IsRequired() + .HasMaxLength(150) + .IsUnicode(false) + .HasColumnType("character varying(150)"); + + b.Property("EndDate") + .HasColumnType("date"); + + b.Property("IsDeleted") + .HasColumnType("boolean"); + + b.Property("Sector") + .HasColumnType("smallint"); + + b.Property("StartDate") + .HasColumnType("date"); + + b.Property("SurveyExpiration") + .HasColumnType("date"); + + b.Property("VehicleId") + .HasColumnType("bigint"); + + b.HasKey("Id"); + + b.HasIndex("VehicleId"); + + b.ToTable("Maintenance"); + }); + + modelBuilder.Entity("OneBus.Domain.Entities.User", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("bigint"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("CreatedAt") + .HasColumnType("timestamp with time zone"); + + b.Property("Email") + .IsRequired() + .HasMaxLength(80) + .IsUnicode(false) + .HasColumnType("character varying(80)"); + + b.Property("IsDeleted") + .HasColumnType("boolean"); + + b.Property("Name") + .IsRequired() + .HasMaxLength(80) + .IsUnicode(false) + .HasColumnType("character varying(80)"); + + b.Property("Password") + .IsRequired() + .HasMaxLength(50) + .IsUnicode(false) + .HasColumnType("character varying(50)"); + + b.Property("Salt") + .IsRequired() + .HasMaxLength(32) + .IsUnicode(false) + .HasColumnType("character varying(32)"); + + b.HasKey("Id"); + + b.ToTable("User"); + + b.HasData( + new + { + Id = 1L, + CreatedAt = new DateTime(2025, 8, 25, 0, 0, 0, 0, DateTimeKind.Utc), + Email = "onebus@admin", + IsDeleted = false, + Name = "Administrador", + Password = "YRT66Z4XEJ2SSNaJVDIXQW7uvC8LSvOxDU1sH/Sr/ic=", + Salt = "c37b6028194d489192aac9391801594a" + }); + }); + + modelBuilder.Entity("OneBus.Domain.Entities.Vehicle", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("bigint"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("AcquisitionDate") + .HasColumnType("date"); + + b.Property("AxesNumber") + .HasColumnType("smallint"); + + b.Property("BodyworkNumber") + .HasMaxLength(20) + .IsUnicode(false) + .HasColumnType("character varying(20)"); + + b.Property("Brand") + .HasColumnType("smallint"); + + b.Property("BusChassisBrand") + .HasColumnType("smallint"); + + b.Property("BusChassisModel") + .HasMaxLength(50) + .IsUnicode(false) + .HasColumnType("character varying(50)"); + + b.Property("BusChassisYear") + .HasColumnType("smallint"); + + b.Property("BusFumigateExpiration") + .HasColumnType("date"); + + b.Property("BusHasLeftDoors") + .HasColumnType("boolean"); + + b.Property("BusHasLowFloor") + .HasColumnType("boolean"); + + b.Property("BusInsuranceExpiration") + .HasColumnType("date"); + + b.Property("BusServiceType") + .HasColumnType("smallint"); + + b.Property("Color") + .HasColumnType("smallint"); + + b.Property("CreatedAt") + .HasColumnType("timestamp with time zone"); + + b.Property("EngineNumber") + .HasMaxLength(20) + .IsUnicode(false) + .HasColumnType("character varying(20)"); + + b.Property("FuelType") + .HasColumnType("smallint"); + + b.Property("HasAccessibility") + .HasColumnType("boolean"); + + b.Property("Image") + .HasColumnType("bytea"); + + b.Property("IpvaExpiration") + .HasColumnType("date"); + + b.Property("IsDeleted") + .HasColumnType("boolean"); + + b.Property("Licensing") + .IsRequired() + .HasMaxLength(50) + .IsUnicode(false) + .HasColumnType("character varying(50)"); + + b.Property("Model") + .IsRequired() + .HasMaxLength(50) + .IsUnicode(false) + .HasColumnType("character varying(50)"); + + b.Property("NumberChassis") + .HasMaxLength(20) + .IsUnicode(false) + .HasColumnType("character varying(20)"); + + b.Property("NumberDoors") + .HasColumnType("smallint"); + + b.Property("NumberSeats") + .HasColumnType("smallint"); + + b.Property("Plate") + .IsRequired() + .HasMaxLength(20) + .IsUnicode(false) + .HasColumnType("character varying(20)"); + + b.Property("Prefix") + .IsRequired() + .HasMaxLength(30) + .IsUnicode(false) + .HasColumnType("character varying(30)"); + + b.Property("Renavam") + .IsRequired() + .HasMaxLength(20) + .IsUnicode(false) + .HasColumnType("character varying(20)"); + + b.Property("Status") + .HasColumnType("smallint"); + + b.Property("TransmissionType") + .HasColumnType("smallint"); + + b.Property("Type") + .HasColumnType("smallint"); + + b.Property("Year") + .HasColumnType("integer"); + + b.HasKey("Id"); + + b.HasIndex("Plate"); + + b.HasIndex("Prefix"); + + b.HasIndex("Renavam"); + + b.ToTable("Vehicle"); + }); + + modelBuilder.Entity("OneBus.Domain.Entities.VehicleOperation", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("bigint"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("CreatedAt") + .HasColumnType("timestamp with time zone"); + + b.Property("EmployeeWorkdayId") + .HasColumnType("bigint"); + + b.Property("IsDeleted") + .HasColumnType("boolean"); + + b.Property("LineTimeId") + .HasColumnType("bigint"); + + b.Property("VehicleId") + .HasColumnType("bigint"); + + b.HasKey("Id"); + + b.HasIndex("EmployeeWorkdayId"); + + b.HasIndex("LineTimeId"); + + b.HasIndex("VehicleId"); + + b.ToTable("VehicleOperation"); + }); + + modelBuilder.Entity("OneBus.Domain.Entities.EmployeeWorkday", b => + { + b.HasOne("OneBus.Domain.Entities.Employee", "Employee") + .WithMany("EmployeeWorkdays") + .HasForeignKey("EmployeeId") + .OnDelete(DeleteBehavior.Restrict) + .IsRequired(); + + b.Navigation("Employee"); + }); + + modelBuilder.Entity("OneBus.Domain.Entities.LineTime", b => + { + b.HasOne("OneBus.Domain.Entities.Line", "Line") + .WithMany("LineTimes") + .HasForeignKey("LineId") + .OnDelete(DeleteBehavior.Restrict) + .IsRequired(); + + b.Navigation("Line"); + }); + + modelBuilder.Entity("OneBus.Domain.Entities.Maintenance", b => + { + b.HasOne("OneBus.Domain.Entities.Vehicle", "Vehicle") + .WithMany("Maintenances") + .HasForeignKey("VehicleId") + .OnDelete(DeleteBehavior.Restrict) + .IsRequired(); + + b.Navigation("Vehicle"); + }); + + modelBuilder.Entity("OneBus.Domain.Entities.VehicleOperation", b => + { + b.HasOne("OneBus.Domain.Entities.EmployeeWorkday", "EmployeeWorkday") + .WithMany("VehicleOperations") + .HasForeignKey("EmployeeWorkdayId") + .OnDelete(DeleteBehavior.Restrict) + .IsRequired(); + + b.HasOne("OneBus.Domain.Entities.LineTime", "LineTime") + .WithMany("VehicleOperations") + .HasForeignKey("LineTimeId") + .OnDelete(DeleteBehavior.Restrict) + .IsRequired(); + + b.HasOne("OneBus.Domain.Entities.Vehicle", "Vehicle") + .WithMany("VehicleOperations") + .HasForeignKey("VehicleId") + .OnDelete(DeleteBehavior.Restrict) + .IsRequired(); + + b.Navigation("EmployeeWorkday"); + + b.Navigation("LineTime"); + + b.Navigation("Vehicle"); + }); + + modelBuilder.Entity("OneBus.Domain.Entities.Employee", b => + { + b.Navigation("EmployeeWorkdays"); + }); + + modelBuilder.Entity("OneBus.Domain.Entities.EmployeeWorkday", b => + { + b.Navigation("VehicleOperations"); + }); + + modelBuilder.Entity("OneBus.Domain.Entities.Line", b => + { + b.Navigation("LineTimes"); + }); + + modelBuilder.Entity("OneBus.Domain.Entities.LineTime", b => + { + b.Navigation("VehicleOperations"); + }); + + modelBuilder.Entity("OneBus.Domain.Entities.Vehicle", b => + { + b.Navigation("Maintenances"); + + b.Navigation("VehicleOperations"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/OneBus.Infra.Data/Migrations/20251104233237_RemoveDirectionTypeFromLineTimeTable.cs b/OneBus.Infra.Data/Migrations/20251104233237_RemoveDirectionTypeFromLineTimeTable.cs new file mode 100644 index 0000000..3e4a64e --- /dev/null +++ b/OneBus.Infra.Data/Migrations/20251104233237_RemoveDirectionTypeFromLineTimeTable.cs @@ -0,0 +1,29 @@ +using Microsoft.EntityFrameworkCore.Migrations; + +#nullable disable + +namespace OneBus.Infra.Data.Migrations +{ + /// + public partial class RemoveDirectionTypeFromLineTimeTable : Migration + { + /// + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropColumn( + name: "DirectionType", + table: "LineTime"); + } + + /// + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.AddColumn( + name: "DirectionType", + table: "LineTime", + type: "smallint", + nullable: false, + defaultValue: (byte)0); + } + } +} diff --git a/OneBus.Infra.Data/Migrations/OneBusDbContextModelSnapshot.cs b/OneBus.Infra.Data/Migrations/OneBusDbContextModelSnapshot.cs index ee86dca..341b6d7 100644 --- a/OneBus.Infra.Data/Migrations/OneBusDbContextModelSnapshot.cs +++ b/OneBus.Infra.Data/Migrations/OneBusDbContextModelSnapshot.cs @@ -200,9 +200,6 @@ protected override void BuildModel(ModelBuilder modelBuilder) b.Property("DayType") .HasColumnType("smallint"); - b.Property("DirectionType") - .HasColumnType("smallint"); - b.Property("IsDeleted") .HasColumnType("boolean"); From c6f69a943b5be35f4e81cb10278246dce9ce2272 Mon Sep 17 00:00:00 2001 From: Eduardo Rezende Date: Tue, 4 Nov 2025 20:37:11 -0300 Subject: [PATCH 80/99] =?UTF-8?q?=E2=99=BB=EF=B8=8Frefactor:=20Update=20pr?= =?UTF-8?q?oject=20package?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Updating FluentValidation.DependencyInjectionExtension package --- OneBus.Infra.Ioc/OneBus.Infra.Ioc.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/OneBus.Infra.Ioc/OneBus.Infra.Ioc.csproj b/OneBus.Infra.Ioc/OneBus.Infra.Ioc.csproj index e317c8d..6b5ef34 100644 --- a/OneBus.Infra.Ioc/OneBus.Infra.Ioc.csproj +++ b/OneBus.Infra.Ioc/OneBus.Infra.Ioc.csproj @@ -7,7 +7,7 @@ - + From df0b10aef6b6fbfbe72f3080d911b40a61b73027 Mon Sep 17 00:00:00 2001 From: Eduardo Rezende Date: Tue, 4 Nov 2025 20:37:40 -0300 Subject: [PATCH 81/99] =?UTF-8?q?=E2=99=BB=EF=B8=8Frefactor:=20Update=20Ve?= =?UTF-8?q?hicleOperation=20Filter?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Removing LineTimeDirectionType field --- OneBus.Domain/Filters/VehicleOperationFilter.cs | 2 -- 1 file changed, 2 deletions(-) diff --git a/OneBus.Domain/Filters/VehicleOperationFilter.cs b/OneBus.Domain/Filters/VehicleOperationFilter.cs index 5d8cc3a..e4d9dd7 100644 --- a/OneBus.Domain/Filters/VehicleOperationFilter.cs +++ b/OneBus.Domain/Filters/VehicleOperationFilter.cs @@ -14,8 +14,6 @@ public class VehicleOperationFilter : BaseFilter public byte? LineDirectionType { get; set; } - public byte? LineTimeDirectionType { get; set; } - public byte? LineTimeDayType { get; set; } public byte? VehicleStatus { get; set; } From 1e11e792b7692ae464a268f90e42a0a07645624d Mon Sep 17 00:00:00 2001 From: Eduardo Rezende Date: Tue, 4 Nov 2025 20:38:26 -0300 Subject: [PATCH 82/99] =?UTF-8?q?=E2=99=BB=EF=B8=8Frefactor:=20Update=20Re?= =?UTF-8?q?positories?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Updating LineTimeDirectionType query filter references --- OneBus.Infra.Data/Repositories/LineTimeRepository.cs | 2 +- OneBus.Infra.Data/Repositories/VehicleOperationRepository.cs | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/OneBus.Infra.Data/Repositories/LineTimeRepository.cs b/OneBus.Infra.Data/Repositories/LineTimeRepository.cs index 03e145b..418cb76 100644 --- a/OneBus.Infra.Data/Repositories/LineTimeRepository.cs +++ b/OneBus.Infra.Data/Repositories/LineTimeRepository.cs @@ -18,7 +18,7 @@ protected override Expression> ApplyFilter(LineTimeFilter f return c => (filter.DayType == null || c.DayType == filter.DayType) && - (filter.DirectionType == null || c.DirectionType == filter.DirectionType) && + (filter.DirectionType == null || c.Line!.DirectionType == filter.DirectionType) && (string.IsNullOrWhiteSpace(value) || ((c.Line!.Name.ToLower().Contains(value) || c.Line.Mileage.ToString().Contains(value) || diff --git a/OneBus.Infra.Data/Repositories/VehicleOperationRepository.cs b/OneBus.Infra.Data/Repositories/VehicleOperationRepository.cs index 6c84784..614fd7c 100644 --- a/OneBus.Infra.Data/Repositories/VehicleOperationRepository.cs +++ b/OneBus.Infra.Data/Repositories/VehicleOperationRepository.cs @@ -28,7 +28,6 @@ protected override Expression> ApplyFilter(VehicleO (filter.EmployeeStatus == null || c.EmployeeWorkday!.Employee!.Status == filter.EmployeeStatus) && (filter.LineDirectionType == null || c.LineTime!.Line!.DirectionType == filter.LineDirectionType) && (filter.VehicleBusServiceType == null || c.Vehicle!.BusServiceType == filter.VehicleBusServiceType) && - (filter.LineTimeDirectionType == null || c.LineTime!.DirectionType == filter.LineTimeDirectionType) && (filter.VehicleBusChassisBrand == null || c.Vehicle!.BusChassisBrand == filter.VehicleBusChassisBrand) && (filter.EmployeeWorkDayDayType == null || c.EmployeeWorkday!.DayType == filter.EmployeeWorkDayDayType) && (filter.EmployeeBloodType == null || c.EmployeeWorkday!.Employee!.BloodType == filter.EmployeeBloodType) && From 29eb917a86ae65a6c14f036526a34e1f03baceba Mon Sep 17 00:00:00 2001 From: Eduardo Rezende Date: Tue, 4 Nov 2025 20:38:58 -0300 Subject: [PATCH 83/99] =?UTF-8?q?=E2=99=BB=EF=B8=8Frefactor:=20Update=20Li?= =?UTF-8?q?neTime=20DTOs?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Removing DirectionType fields --- OneBus.Application/DTOs/LineTime/CreateLineTimeDTO.cs | 2 -- OneBus.Application/DTOs/LineTime/ReadLineTimeDTO.cs | 8 ++++---- OneBus.Application/DTOs/LineTime/UpdateLineTimeDTO.cs | 2 -- 3 files changed, 4 insertions(+), 8 deletions(-) diff --git a/OneBus.Application/DTOs/LineTime/CreateLineTimeDTO.cs b/OneBus.Application/DTOs/LineTime/CreateLineTimeDTO.cs index 55aaf1f..b2ec3f8 100644 --- a/OneBus.Application/DTOs/LineTime/CreateLineTimeDTO.cs +++ b/OneBus.Application/DTOs/LineTime/CreateLineTimeDTO.cs @@ -7,7 +7,5 @@ public class CreateLineTimeDTO : BaseCreateDTO public TimeOnly Time { get; set; } public byte DayType { get; set; } - - public byte DirectionType { get; set; } } } diff --git a/OneBus.Application/DTOs/LineTime/ReadLineTimeDTO.cs b/OneBus.Application/DTOs/LineTime/ReadLineTimeDTO.cs index 4287228..c2ccc88 100644 --- a/OneBus.Application/DTOs/LineTime/ReadLineTimeDTO.cs +++ b/OneBus.Application/DTOs/LineTime/ReadLineTimeDTO.cs @@ -8,14 +8,14 @@ public class ReadLineTimeDTO : BaseReadDTO public string? LineName { get; set; } + public byte LineDirectionType { get; set; } + + public string? LineDirectionTypeName { get; set; } + public TimeOnly Time { get; set; } public byte DayType { get; set; } public string? DayTypeName { get; set; } - - public byte DirectionType { get; set; } - - public string? DirectionTypeName { get; set; } } } diff --git a/OneBus.Application/DTOs/LineTime/UpdateLineTimeDTO.cs b/OneBus.Application/DTOs/LineTime/UpdateLineTimeDTO.cs index 733cd1a..b4e7a45 100644 --- a/OneBus.Application/DTOs/LineTime/UpdateLineTimeDTO.cs +++ b/OneBus.Application/DTOs/LineTime/UpdateLineTimeDTO.cs @@ -5,7 +5,5 @@ public class UpdateLineTimeDTO : BaseUpdateDTO public TimeOnly Time { get; set; } public byte DayType { get; set; } - - public byte DirectionType { get; set; } } } From 0c4b63122501914606e53c7f8520bd9814b3947d Mon Sep 17 00:00:00 2001 From: Eduardo Rezende Date: Tue, 4 Nov 2025 20:39:17 -0300 Subject: [PATCH 84/99] =?UTF-8?q?=E2=99=BB=EF=B8=8Frefactor:=20Update=20Li?= =?UTF-8?q?neTime=20Service?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Updating GET methods --- OneBus.Application/Services/LineTimeService.cs | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/OneBus.Application/Services/LineTimeService.cs b/OneBus.Application/Services/LineTimeService.cs index f3c7c06..e45eb5c 100644 --- a/OneBus.Application/Services/LineTimeService.cs +++ b/OneBus.Application/Services/LineTimeService.cs @@ -36,7 +36,7 @@ public async override Task>> GetPaginedAsync( foreach (var lineTime in result.Value!.Items) { lineTime.DayTypeName = ((DayType)lineTime.DayType).ToString().Localize(); - lineTime.DirectionTypeName = ((DirectionType)lineTime.DirectionType).ToString().Localize(); + lineTime.LineDirectionTypeName = ((DirectionType)lineTime.LineDirectionType).ToString().Localize(); } return result; @@ -54,7 +54,7 @@ public async override Task> GetByIdAsync( var lineTime = result.Value!; lineTime.DayTypeName = ((DayType)lineTime.DayType).ToString().Localize(); - lineTime.DirectionTypeName = ((DirectionType)lineTime.DirectionType).ToString().Localize(); + lineTime.LineDirectionTypeName = ((DirectionType)lineTime.LineDirectionType).ToString().Localize(); return result; } @@ -63,7 +63,6 @@ protected override void UpdateFields(LineTime entity, UpdateLineTimeDTO updateDT { entity.Time = updateDTO.Time; entity.DayType = updateDTO.DayType; - entity.DirectionType = updateDTO.DirectionType; } } } From 7bcbfb6934438bd3881c8d89fe5448c1d8af0e75 Mon Sep 17 00:00:00 2001 From: Eduardo Rezende Date: Tue, 4 Nov 2025 20:40:13 -0300 Subject: [PATCH 85/99] =?UTF-8?q?=E2=99=BB=EF=B8=8Frefactor:=20Update=20Li?= =?UTF-8?q?neTime=20Validators?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Removing DirectionType validations --- .../Validators/LineTime/CreateLineTimeDTOValidator.cs | 7 +------ .../Validators/LineTime/UpdateLineTimeDTOValidator.cs | 6 +----- 2 files changed, 2 insertions(+), 11 deletions(-) diff --git a/OneBus.Application/Validators/LineTime/CreateLineTimeDTOValidator.cs b/OneBus.Application/Validators/LineTime/CreateLineTimeDTOValidator.cs index 9816f53..f6b05a8 100644 --- a/OneBus.Application/Validators/LineTime/CreateLineTimeDTOValidator.cs +++ b/OneBus.Application/Validators/LineTime/CreateLineTimeDTOValidator.cs @@ -2,7 +2,6 @@ using OneBus.Application.DTOs.LineTime; using OneBus.Domain.Commons; using OneBus.Domain.Enums; -using OneBus.Domain.Enums.Line; using OneBus.Domain.Interfaces.Repositories; using OneBus.Domain.Utils; @@ -24,11 +23,7 @@ public CreateLineTimeDTOValidator(ILineRepository lineRepository) RuleFor(c => c.LineId) .MustAsync(ExistsAsync) .WithMessage(ErrorUtils.EntityNotFound(LineIdPropertyName).Message) - .OverridePropertyName(LineIdPropertyName); - - RuleFor(c => c.DirectionType) - .Must(ValidationUtils.IsValidEnumValue) - .OverridePropertyName("Tipo de Direção"); + .OverridePropertyName(LineIdPropertyName); RuleFor(c => c.DayType).Must(ValidationUtils.IsValidEnumValue) .OverridePropertyName("Dia da Semana"); diff --git a/OneBus.Application/Validators/LineTime/UpdateLineTimeDTOValidator.cs b/OneBus.Application/Validators/LineTime/UpdateLineTimeDTOValidator.cs index 823c012..f82ed91 100644 --- a/OneBus.Application/Validators/LineTime/UpdateLineTimeDTOValidator.cs +++ b/OneBus.Application/Validators/LineTime/UpdateLineTimeDTOValidator.cs @@ -11,11 +11,7 @@ public class UpdateLineTimeDTOValidator : AbstractValidator public UpdateLineTimeDTOValidator() { RuleFor(c => c.Id).GreaterThan(0); - - RuleFor(c => c.DirectionType) - .Must(ValidationUtils.IsValidEnumValue) - .OverridePropertyName("Tipo de Direção"); - + RuleFor(c => c.DayType).Must(ValidationUtils.IsValidEnumValue) .OverridePropertyName("Dia da Semana"); } From cbcc87f0409c3eecf8d253d172b71c85d0c2c626 Mon Sep 17 00:00:00 2001 From: Eduardo Rezende Date: Tue, 4 Nov 2025 21:48:06 -0300 Subject: [PATCH 86/99] =?UTF-8?q?=E2=9C=A8feat:=20Add=20Dashboard=20DTOs?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Adding DTOs for Dashboard --- .../DTOs/Dashboard/ReadEmployeeCountDTO.cs | 21 +++++++++++++++++++ .../Dashboard/ReadEmployeeTotalCountDTO.cs | 14 +++++++++++++ .../DTOs/Dashboard/ReadVehicleCountDTO.cs | 21 +++++++++++++++++++ .../Dashboard/ReadVehicleTotalCountDTO.cs | 14 +++++++++++++ .../ReadVehicleOperationDTO.cs | 4 ++++ 5 files changed, 74 insertions(+) create mode 100644 OneBus.Application/DTOs/Dashboard/ReadEmployeeCountDTO.cs create mode 100644 OneBus.Application/DTOs/Dashboard/ReadEmployeeTotalCountDTO.cs create mode 100644 OneBus.Application/DTOs/Dashboard/ReadVehicleCountDTO.cs create mode 100644 OneBus.Application/DTOs/Dashboard/ReadVehicleTotalCountDTO.cs diff --git a/OneBus.Application/DTOs/Dashboard/ReadEmployeeCountDTO.cs b/OneBus.Application/DTOs/Dashboard/ReadEmployeeCountDTO.cs new file mode 100644 index 0000000..388ff44 --- /dev/null +++ b/OneBus.Application/DTOs/Dashboard/ReadEmployeeCountDTO.cs @@ -0,0 +1,21 @@ +using OneBus.Application.DTOs.Employee; + +namespace OneBus.Application.DTOs.Dashboard +{ + public class ReadEmployeeCountDTO + { + public ReadEmployeeCountDTO() + { + StatusName = string.Empty; + Employees = []; + } + + public long Count { get { return Employees.LongCount(); } } + + public byte Status { get; set; } + + public string StatusName { get; set; } + + public IEnumerable Employees { get; set; } + } +} diff --git a/OneBus.Application/DTOs/Dashboard/ReadEmployeeTotalCountDTO.cs b/OneBus.Application/DTOs/Dashboard/ReadEmployeeTotalCountDTO.cs new file mode 100644 index 0000000..a1a67dd --- /dev/null +++ b/OneBus.Application/DTOs/Dashboard/ReadEmployeeTotalCountDTO.cs @@ -0,0 +1,14 @@ +namespace OneBus.Application.DTOs.Dashboard +{ + public class ReadEmployeeTotalCountDTO + { + public ReadEmployeeTotalCountDTO(IEnumerable employeeCounts) + { + EmployeeCounts = employeeCounts; + } + + public long TotalCount { get { return EmployeeCounts.SelectMany(c => c.Employees).LongCount(); } } + + public IEnumerable EmployeeCounts { get; set; } + } +} diff --git a/OneBus.Application/DTOs/Dashboard/ReadVehicleCountDTO.cs b/OneBus.Application/DTOs/Dashboard/ReadVehicleCountDTO.cs new file mode 100644 index 0000000..18372fb --- /dev/null +++ b/OneBus.Application/DTOs/Dashboard/ReadVehicleCountDTO.cs @@ -0,0 +1,21 @@ +using OneBus.Application.DTOs.Vehicle; + +namespace OneBus.Application.DTOs.Dashboard +{ + public class ReadVehicleCountDTO + { + public ReadVehicleCountDTO() + { + StatusName = string.Empty; + Vehicles = []; + } + + public long Count { get { return Vehicles.LongCount(); } } + + public byte Status { get; set; } + + public string StatusName { get; set; } + + public IEnumerable Vehicles { get; set; } + } +} diff --git a/OneBus.Application/DTOs/Dashboard/ReadVehicleTotalCountDTO.cs b/OneBus.Application/DTOs/Dashboard/ReadVehicleTotalCountDTO.cs new file mode 100644 index 0000000..fba2f41 --- /dev/null +++ b/OneBus.Application/DTOs/Dashboard/ReadVehicleTotalCountDTO.cs @@ -0,0 +1,14 @@ +namespace OneBus.Application.DTOs.Dashboard +{ + public class ReadVehicleTotalCountDTO + { + public ReadVehicleTotalCountDTO(IEnumerable vehicleCounts) + { + VehicleCounts = vehicleCounts; + } + + public long TotalCount { get { return VehicleCounts.SelectMany(c => c.Vehicles).LongCount(); } } + + public IEnumerable VehicleCounts { get; set; } + } +} diff --git a/OneBus.Application/DTOs/VehicleOperation/ReadVehicleOperationDTO.cs b/OneBus.Application/DTOs/VehicleOperation/ReadVehicleOperationDTO.cs index 273781b..0d23814 100644 --- a/OneBus.Application/DTOs/VehicleOperation/ReadVehicleOperationDTO.cs +++ b/OneBus.Application/DTOs/VehicleOperation/ReadVehicleOperationDTO.cs @@ -69,5 +69,9 @@ public class ReadVehicleOperationDTO : BaseReadDTO public byte? VehicleType { get; set; } public string? VehicleTypeName { get; set; } + + public byte? VehicleStatus { get; set; } + + public string? VehicleStatusName { get; set; } } } From b9874d3d669080f577291607bdb1f710e1457b79 Mon Sep 17 00:00:00 2001 From: Eduardo Rezende Date: Tue, 4 Nov 2025 21:49:27 -0300 Subject: [PATCH 87/99] =?UTF-8?q?=E2=99=BB=EF=B8=8Frefactor:=20Fixing=20Pa?= =?UTF-8?q?gination?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Updating field types to int --- OneBus.Domain/Commons/Pagination.cs | 10 +++++----- OneBus.Domain/Filters/BaseFilter.cs | 4 ++-- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/OneBus.Domain/Commons/Pagination.cs b/OneBus.Domain/Commons/Pagination.cs index 342d109..688a3f4 100644 --- a/OneBus.Domain/Commons/Pagination.cs +++ b/OneBus.Domain/Commons/Pagination.cs @@ -10,12 +10,12 @@ public class Pagination /// /// A página atual (começando do 1, geralmente). /// - public uint CurrentPage { get; private set; } + public int CurrentPage { get; private set; } /// /// Quantidade de itens por página. /// - public uint PageSize { get; private set; } + public int PageSize { get; private set; } /// /// Total de itens no conjunto original (com filtros de página). @@ -25,7 +25,7 @@ public class Pagination /// /// Número total de páginas (calculado). /// - public uint TotalPages { get; private set; } + public int TotalPages { get; private set; } /// /// Se existe uma página anterior. @@ -37,13 +37,13 @@ public class Pagination /// public bool HasNextPage { get { return CurrentPage < TotalPages; } } - public Pagination(IEnumerable items, long totalItems, uint currentPage, uint pageSize) + public Pagination(IEnumerable items, long totalItems, int currentPage, int pageSize) { Items = [.. items]; TotalItems = totalItems; CurrentPage = currentPage; PageSize = pageSize; - TotalPages = (uint)Math.Ceiling(totalItems / (double)pageSize); + TotalPages = (int)Math.Ceiling(totalItems / (double)pageSize); } } } diff --git a/OneBus.Domain/Filters/BaseFilter.cs b/OneBus.Domain/Filters/BaseFilter.cs index 5c40220..42b2db8 100644 --- a/OneBus.Domain/Filters/BaseFilter.cs +++ b/OneBus.Domain/Filters/BaseFilter.cs @@ -16,10 +16,10 @@ protected BaseFilter() public string? Value { get; set; } [DefaultValue(1)] - public uint CurrentPage { get; set; } + public int CurrentPage { get; set; } [DefaultValue(15)] - public uint PageSize { get; set; } + public int PageSize { get; set; } [DefaultValue("id")] public string OrderField { get; set; } From 63f2cf95eda4d932b440115758152173d66b3e3e Mon Sep 17 00:00:00 2001 From: Eduardo Rezende Date: Tue, 4 Nov 2025 21:49:58 -0300 Subject: [PATCH 88/99] =?UTF-8?q?=E2=99=BB=EF=B8=8Frefactor:=20Updating=20?= =?UTF-8?q?VehicleOperation=20Service?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Adding VehicleStatus field value --- OneBus.Application/Services/VehicleOperationService.cs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/OneBus.Application/Services/VehicleOperationService.cs b/OneBus.Application/Services/VehicleOperationService.cs index b3836bf..fcb9d74 100644 --- a/OneBus.Application/Services/VehicleOperationService.cs +++ b/OneBus.Application/Services/VehicleOperationService.cs @@ -37,7 +37,8 @@ public override async Task>> GetPagin foreach (var vehicleOperation in result.Value!.Items) { vehicleOperation.VehicleTypeName = ((VehicleType?)vehicleOperation.VehicleType)?.ToString()?.Localize(); - vehicleOperation.LineTimeDayTypeName = ((DayType?)vehicleOperation.LineTimeDayType)?.ToString()?.Localize(); + vehicleOperation.LineTimeDayTypeName = ((DayType?)vehicleOperation.LineTimeDayType)?.ToString()?.Localize(); + vehicleOperation.VehicleStatusName = ((VehicleStatus?)vehicleOperation.VehicleStatus)?.ToString()?.Localize(); vehicleOperation.LineTimeLineTypeName = ((LineType?)vehicleOperation.LineTimeLineType)?.ToString()?.Localize(); vehicleOperation.LineTimeDirectionTypeName = ((DirectionType?)vehicleOperation.LineTimeDirectionType)?.ToString()?.Localize(); vehicleOperation.EmployeeWorkdayDayTypeName = ((DayType?)vehicleOperation.EmployeeWorkdayDayType)?.ToString()?.Localize(); @@ -60,6 +61,7 @@ public override async Task> GetByIdAsync( var vehicleOperation = result.Value!; vehicleOperation.VehicleTypeName = ((VehicleType?)vehicleOperation.VehicleType)?.ToString()?.Localize(); vehicleOperation.LineTimeDayTypeName = ((DayType?)vehicleOperation.LineTimeDayType)?.ToString()?.Localize(); + vehicleOperation.VehicleStatusName = ((VehicleStatus?)vehicleOperation.VehicleStatus)?.ToString()?.Localize(); vehicleOperation.LineTimeLineTypeName = ((LineType?)vehicleOperation.LineTimeLineType)?.ToString()?.Localize(); vehicleOperation.LineTimeDirectionTypeName = ((DirectionType?)vehicleOperation.LineTimeDirectionType)?.ToString()?.Localize(); vehicleOperation.EmployeeWorkdayDayTypeName = ((DayType?)vehicleOperation.EmployeeWorkdayDayType)?.ToString()?.Localize(); From f713bd190015768ece7f658dc21a94788f517ea2 Mon Sep 17 00:00:00 2001 From: Eduardo Rezende Date: Tue, 4 Nov 2025 21:50:17 -0300 Subject: [PATCH 89/99] =?UTF-8?q?=E2=9C=A8feat:=20Add=20Dashboard=20Servic?= =?UTF-8?q?e?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Adding dashboard methods logic --- .../Interfaces/Services/IDashboardService.cs | 12 +++ .../Services/DashboardService.cs | 80 +++++++++++++++++++ 2 files changed, 92 insertions(+) create mode 100644 OneBus.Application/Interfaces/Services/IDashboardService.cs create mode 100644 OneBus.Application/Services/DashboardService.cs diff --git a/OneBus.Application/Interfaces/Services/IDashboardService.cs b/OneBus.Application/Interfaces/Services/IDashboardService.cs new file mode 100644 index 0000000..ea4e080 --- /dev/null +++ b/OneBus.Application/Interfaces/Services/IDashboardService.cs @@ -0,0 +1,12 @@ +using OneBus.Application.DTOs.Dashboard; +using OneBus.Domain.Commons.Result; + +namespace OneBus.Application.Interfaces.Services +{ + public interface IDashboardService + { + Task> GetEmployeeStatusAsync(CancellationToken cancellationToken = default); + + Task> GetVehicleStatusAsync(CancellationToken cancellationToken = default); + } +} diff --git a/OneBus.Application/Services/DashboardService.cs b/OneBus.Application/Services/DashboardService.cs new file mode 100644 index 0000000..977f9e9 --- /dev/null +++ b/OneBus.Application/Services/DashboardService.cs @@ -0,0 +1,80 @@ +using OneBus.Application.DTOs.Dashboard; +using OneBus.Application.Interfaces.Services; +using OneBus.Domain.Commons.Result; +using OneBus.Domain.Enums.Employee; +using OneBus.Domain.Enums.Vehicle; +using OneBus.Domain.Extensions; + +namespace OneBus.Application.Services +{ + public class DashboardService : IDashboardService + { + private readonly IVehicleService _vehicleService; + private readonly IEmployeeService _employeeService; + + public DashboardService( + IVehicleService vehicleService, + IEmployeeService employeeService) + { + _vehicleService = vehicleService; + _employeeService = employeeService; + } + + public async Task> GetEmployeeStatusAsync( + CancellationToken cancellationToken = default) + { + var employeesPagination = await _employeeService.GetPaginedAsync( + new Domain.Filters.EmployeeFilter { PageSize = int.MaxValue }, + cancellationToken: cancellationToken); + + if (!employeesPagination.Sucess || !employeesPagination.Value!.Items.Any()) + return SuccessResult.Create(new ReadEmployeeTotalCountDTO([])); + + var employees = employeesPagination.Value.Items; + + var groupByStatus = employees.GroupBy(c => c.Status).ToList(); + + List employeeCounts = []; + foreach (var group in groupByStatus) + { + employeeCounts.Add(new ReadEmployeeCountDTO + { + Status = group.Key, + StatusName = ((EmployeeStatus)group.Key).ToString().Localize(), + Employees = group.Select(c => c) + }); + } + + var result = new ReadEmployeeTotalCountDTO(employeeCounts); + return SuccessResult.Create(result); + } + + public async Task> GetVehicleStatusAsync(CancellationToken cancellationToken = default) + { + var vehiclesPagination = await _vehicleService.GetPaginedAsync( + new Domain.Filters.VehicleFilter { PageSize = int.MaxValue }, + cancellationToken: cancellationToken); + + if (!vehiclesPagination.Sucess || !vehiclesPagination.Value!.Items.Any()) + return SuccessResult.Create(new ReadVehicleTotalCountDTO([])); + + var vehicles = vehiclesPagination.Value.Items; + + var groupByStatus = vehicles.GroupBy(c => c.Status).ToList(); + + List vehicleCounts = []; + foreach (var group in groupByStatus) + { + vehicleCounts.Add(new ReadVehicleCountDTO + { + Status = group.Key, + StatusName = ((VehicleStatus)group.Key).ToString().Localize(), + Vehicles = group.Select(c => c) + }); + } + + var result = new ReadVehicleTotalCountDTO(vehicleCounts); + return SuccessResult.Create(result); + } + } +} From 7a744f57755bd27b0856c81c852b69c17193fcec Mon Sep 17 00:00:00 2001 From: Eduardo Rezende Date: Tue, 4 Nov 2025 21:50:35 -0300 Subject: [PATCH 90/99] =?UTF-8?q?=E2=99=BB=EF=B8=8Frefactor:=20Updating=20?= =?UTF-8?q?Dependency=20Injection?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Adding DashboardService --- OneBus.Infra.Ioc/DependencyInjection.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/OneBus.Infra.Ioc/DependencyInjection.cs b/OneBus.Infra.Ioc/DependencyInjection.cs index d5d36fd..12a5206 100644 --- a/OneBus.Infra.Ioc/DependencyInjection.cs +++ b/OneBus.Infra.Ioc/DependencyInjection.cs @@ -28,6 +28,7 @@ public static IServiceCollection AddInfrastructure(this IServiceCollection servi .WithScopedLifetime()); services.AddScoped(); + services.AddScoped(); return services; } } From 5b343c42c9680be6e471cdf6dadc0ef76bf818b5 Mon Sep 17 00:00:00 2001 From: Eduardo Rezende Date: Tue, 4 Nov 2025 21:50:56 -0300 Subject: [PATCH 91/99] =?UTF-8?q?=E2=9C=A8feat:=20Add=20Dashboard=20Contro?= =?UTF-8?q?ller?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Adding dashboard endpoints --- OneBus.API/Controllers/DashboardController.cs | 57 +++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 OneBus.API/Controllers/DashboardController.cs diff --git a/OneBus.API/Controllers/DashboardController.cs b/OneBus.API/Controllers/DashboardController.cs new file mode 100644 index 0000000..ef321df --- /dev/null +++ b/OneBus.API/Controllers/DashboardController.cs @@ -0,0 +1,57 @@ +using Microsoft.AspNetCore.Authorization; +using Microsoft.AspNetCore.Mvc; +using OneBus.API.Extensions; +using OneBus.Application.DTOs.Dashboard; +using OneBus.Application.Interfaces.Services; +using OneBus.Domain.Commons.Result; +using Swashbuckle.AspNetCore.Annotations; + +namespace OneBus.API.Controllers +{ + [Route("api/v1/dashboards")] + [ApiController] + [Produces("application/json")] + [Authorize] + [SwaggerTag("Controlador responsável por listar Dashboards")] + public class DashboardController : ControllerBase + { + private readonly IDashboardService _dashboardService; + + public DashboardController(IDashboardService dashboardService) + { + _dashboardService = dashboardService; + } + + /// + /// Obter status dos funcionários + /// + /// + /// GET de status dos funcionários + /// + /// + /// Status dos funcionários categorizados + /// Status dos funcionários categorizados com sucesso + [HttpGet("employees")] + [ProducesResponseType(typeof(SuccessResult), StatusCodes.Status200OK)] + public async Task GetEmployeeStatusAsync(CancellationToken cancellationToken = default) + { + return (await _dashboardService.GetEmployeeStatusAsync(cancellationToken)).ToActionResult(); + } + + /// + /// Obter status dos veículos + /// + /// + /// GET de status dos veículos + /// + /// + /// Status dos veículos categorizados + /// Status dos veículos categorizados com sucesso + [HttpGet("vehicles")] + [ProducesResponseType(typeof(SuccessResult), StatusCodes.Status200OK)] + public async Task GetVehicleStatusAsync(CancellationToken cancellationToken = default) + { + return (await _dashboardService.GetVehicleStatusAsync(cancellationToken)).ToActionResult(); + } + } +} From 3e3ada6e0a26254e35c3b3c0bbebc31828449dc5 Mon Sep 17 00:00:00 2001 From: Eduardo Rezende Date: Tue, 4 Nov 2025 22:56:44 -0300 Subject: [PATCH 92/99] =?UTF-8?q?=E2=99=BB=EF=B8=8Frefactor:=20Update=20pr?= =?UTF-8?q?oject=20package?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Adding Hosting.Abstractions package --- OneBus.Application/OneBus.Application.csproj | 1 + 1 file changed, 1 insertion(+) diff --git a/OneBus.Application/OneBus.Application.csproj b/OneBus.Application/OneBus.Application.csproj index 389288f..eae80e9 100644 --- a/OneBus.Application/OneBus.Application.csproj +++ b/OneBus.Application/OneBus.Application.csproj @@ -10,6 +10,7 @@ + From 9a09cc38148f4896b856ed862871fb46b093d05a Mon Sep 17 00:00:00 2001 From: Eduardo Rezende Date: Tue, 4 Nov 2025 22:57:37 -0300 Subject: [PATCH 93/99] =?UTF-8?q?=E2=99=BB=EF=B8=8Frefactor:=20Update=20\R?= =?UTF-8?q?eadVehicleOperation=20DTO?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Adding EmployeeWorkdayEmployeeStatus, VehicleImage and removing LineTimeDirectionType fields --- .../DTOs/VehicleOperation/ReadVehicleOperationDTO.cs | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/OneBus.Application/DTOs/VehicleOperation/ReadVehicleOperationDTO.cs b/OneBus.Application/DTOs/VehicleOperation/ReadVehicleOperationDTO.cs index 0d23814..0496378 100644 --- a/OneBus.Application/DTOs/VehicleOperation/ReadVehicleOperationDTO.cs +++ b/OneBus.Application/DTOs/VehicleOperation/ReadVehicleOperationDTO.cs @@ -12,10 +12,6 @@ public class ReadVehicleOperationDTO : BaseReadDTO public string? LineTimeDayTypeName { get; set; } - public byte? LineTimeDirectionType { get; set; } - - public string? LineTimeDirectionTypeName { get; set; } - [JsonPropertyName("lineId")] public long? LineTimeLineId { get; set; } @@ -62,6 +58,12 @@ public class ReadVehicleOperationDTO : BaseReadDTO [JsonPropertyName("employeeCode")] public string? EmployeeWorkdayEmployeeCode { get; set; } + [JsonPropertyName("employeeStatus")] + public byte? EmployeeWorkdayEmployeeStatus { get; set; } + + [JsonPropertyName("employeeStatusName")] + public string? EmployeeWorkdayEmployeeStatusName { get; set; } + public long VehicleId { get; set; } public string? VehiclePrefix { get; set; } @@ -73,5 +75,7 @@ public class ReadVehicleOperationDTO : BaseReadDTO public byte? VehicleStatus { get; set; } public string? VehicleStatusName { get; set; } + + public byte[]? VehicleImage { get; set; } } } From 38b4afadcb7aacf584b3f9b1fa6a4b55fef89f22 Mon Sep 17 00:00:00 2001 From: Eduardo Rezende Date: Tue, 4 Nov 2025 22:57:53 -0300 Subject: [PATCH 94/99] =?UTF-8?q?=E2=99=BB=EF=B8=8Frefactor:=20Updating=20?= =?UTF-8?q?VehicleOperation=20Service?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Updating Get methods --- OneBus.Application/Services/VehicleOperationService.cs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/OneBus.Application/Services/VehicleOperationService.cs b/OneBus.Application/Services/VehicleOperationService.cs index fcb9d74..d9b1114 100644 --- a/OneBus.Application/Services/VehicleOperationService.cs +++ b/OneBus.Application/Services/VehicleOperationService.cs @@ -5,6 +5,7 @@ using OneBus.Domain.Commons.Result; using OneBus.Domain.Entities; using OneBus.Domain.Enums; +using OneBus.Domain.Enums.Employee; using OneBus.Domain.Enums.Line; using OneBus.Domain.Enums.Vehicle; using OneBus.Domain.Extensions; @@ -40,9 +41,9 @@ public override async Task>> GetPagin vehicleOperation.LineTimeDayTypeName = ((DayType?)vehicleOperation.LineTimeDayType)?.ToString()?.Localize(); vehicleOperation.VehicleStatusName = ((VehicleStatus?)vehicleOperation.VehicleStatus)?.ToString()?.Localize(); vehicleOperation.LineTimeLineTypeName = ((LineType?)vehicleOperation.LineTimeLineType)?.ToString()?.Localize(); - vehicleOperation.LineTimeDirectionTypeName = ((DirectionType?)vehicleOperation.LineTimeDirectionType)?.ToString()?.Localize(); vehicleOperation.EmployeeWorkdayDayTypeName = ((DayType?)vehicleOperation.EmployeeWorkdayDayType)?.ToString()?.Localize(); vehicleOperation.LineTimeLineDirectionTypeName = ((DirectionType?)vehicleOperation.LineTimeLineDirectionType)?.ToString()?.Localize(); + vehicleOperation.EmployeeWorkdayEmployeeStatusName = ((EmployeeStatus?)vehicleOperation.EmployeeWorkdayEmployeeStatus)?.ToString()?.Localize(); } return result; @@ -63,9 +64,9 @@ public override async Task> GetByIdAsync( vehicleOperation.LineTimeDayTypeName = ((DayType?)vehicleOperation.LineTimeDayType)?.ToString()?.Localize(); vehicleOperation.VehicleStatusName = ((VehicleStatus?)vehicleOperation.VehicleStatus)?.ToString()?.Localize(); vehicleOperation.LineTimeLineTypeName = ((LineType?)vehicleOperation.LineTimeLineType)?.ToString()?.Localize(); - vehicleOperation.LineTimeDirectionTypeName = ((DirectionType?)vehicleOperation.LineTimeDirectionType)?.ToString()?.Localize(); vehicleOperation.EmployeeWorkdayDayTypeName = ((DayType?)vehicleOperation.EmployeeWorkdayDayType)?.ToString()?.Localize(); vehicleOperation.LineTimeLineDirectionTypeName = ((DirectionType?)vehicleOperation.LineTimeLineDirectionType)?.ToString()?.Localize(); + vehicleOperation.EmployeeWorkdayEmployeeStatusName = ((EmployeeStatus?)vehicleOperation.EmployeeWorkdayEmployeeStatus)?.ToString()?.Localize(); return result; } From 1233e982f6f4979f9ce0774c642d1cd785beee11 Mon Sep 17 00:00:00 2001 From: Eduardo Rezende Date: Tue, 4 Nov 2025 22:58:48 -0300 Subject: [PATCH 95/99] =?UTF-8?q?=E2=9C=A8feat:=20Add=20VehicleRepository?= =?UTF-8?q?=20new=20method?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Adding SetStatus method --- .../Repositories/IVehicleRepository.cs | 2 ++ .../Repositories/VehicleRepository.cs | 18 +++++++++++++++++- 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/OneBus.Domain/Interfaces/Repositories/IVehicleRepository.cs b/OneBus.Domain/Interfaces/Repositories/IVehicleRepository.cs index 3478e52..bc2d70b 100644 --- a/OneBus.Domain/Interfaces/Repositories/IVehicleRepository.cs +++ b/OneBus.Domain/Interfaces/Repositories/IVehicleRepository.cs @@ -1,9 +1,11 @@ using OneBus.Domain.Entities; +using OneBus.Domain.Enums.Vehicle; using OneBus.Domain.Filters; namespace OneBus.Domain.Interfaces.Repositories { public interface IVehicleRepository : IBaseRepository { + Task SetStatusAsync(IEnumerable ids, VehicleStatus status, CancellationToken cancellationToken = default); } } diff --git a/OneBus.Infra.Data/Repositories/VehicleRepository.cs b/OneBus.Infra.Data/Repositories/VehicleRepository.cs index 4c74d8f..443c744 100644 --- a/OneBus.Infra.Data/Repositories/VehicleRepository.cs +++ b/OneBus.Infra.Data/Repositories/VehicleRepository.cs @@ -1,4 +1,6 @@ -using OneBus.Domain.Entities; +using Microsoft.EntityFrameworkCore; +using OneBus.Domain.Entities; +using OneBus.Domain.Enums.Vehicle; using OneBus.Domain.Filters; using OneBus.Domain.Interfaces.Repositories; using OneBus.Infra.Data.DbContexts; @@ -12,6 +14,20 @@ public VehicleRepository(OneBusDbContext dbContext) : base(dbContext) { } + public virtual async Task SetStatusAsync( + IEnumerable ids, + VehicleStatus status, + CancellationToken cancellationToken = default) + { + ArgumentNullException.ThrowIfNull(ids, nameof(ids)); + + return await _dbSet + .Where(c => ids.Contains(c.Id)) + .ExecuteUpdateAsync(setters => setters + .SetProperty(c => c.Status, (byte)status), + cancellationToken) == ids.LongCount(); + } + protected override Expression> ApplyFilter(VehicleFilter filter) { var value = filter.Value?.ToLower(); From 0ccc02fd572adca1e46ff77bb7317b75e004872f Mon Sep 17 00:00:00 2001 From: Eduardo Rezende Date: Tue, 4 Nov 2025 23:00:03 -0300 Subject: [PATCH 96/99] =?UTF-8?q?=E2=9C=A8feat:=20Add=20ehicleOperation=20?= =?UTF-8?q?Worker?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Adding Worker to run foreach 5 minutes and sync vehicle status operation --- .../Workers/VehicleOperationWorker.cs | 119 ++++++++++++++++++ 1 file changed, 119 insertions(+) create mode 100644 OneBus.Application/Workers/VehicleOperationWorker.cs diff --git a/OneBus.Application/Workers/VehicleOperationWorker.cs b/OneBus.Application/Workers/VehicleOperationWorker.cs new file mode 100644 index 0000000..fd31ce3 --- /dev/null +++ b/OneBus.Application/Workers/VehicleOperationWorker.cs @@ -0,0 +1,119 @@ +using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Hosting; +using OneBus.Application.DTOs.VehicleOperation; +using OneBus.Application.Interfaces.Services; +using OneBus.Domain.Commons; +using OneBus.Domain.Enums.Employee; +using OneBus.Domain.Enums.Vehicle; +using OneBus.Domain.Interfaces.Repositories; + +namespace OneBus.Application.Workers +{ + public class VehicleOperationWorker : BackgroundService + { + private readonly SemaphoreSlim _semaphoreSlim; + private readonly IServiceProvider _serviceProvider; + + const int Interval = 5; + + public VehicleOperationWorker(IServiceProvider serviceProvider) + { + _serviceProvider = serviceProvider; + _semaphoreSlim = new(initialCount: 1, maxCount: 1); + } + + protected async override Task ExecuteAsync(CancellationToken stoppingToken) + { + var timeSpan = TimeSpan.FromMinutes(Interval); + using var timer = new PeriodicTimer(timeSpan); + + do + { + if (!await _semaphoreSlim.WaitAsync(millisecondsTimeout: 0, stoppingToken)) + { + continue; + } + + try + { + await DoWorkAsync(stoppingToken); + } + catch (Exception ex) + { + Console.WriteLine(ex.Message); + } + finally + { + _semaphoreSlim.Release(); + } + + } while (await timer.WaitForNextTickAsync(stoppingToken) && !stoppingToken.IsCancellationRequested); + } + + private async Task DoWorkAsync(CancellationToken cancellationToken) + { + using var scope = _serviceProvider.CreateScope(); + var vehicleOperationService = scope.ServiceProvider.GetRequiredService(); + + var vehicleOperationsPagination = await vehicleOperationService.GetPaginedAsync( + new Domain.Filters.VehicleOperationFilter { PageSize = int.MaxValue }, + DbQueryOptions.Create(["Vehicle", "LineTime.Line", "EmployeeWorkday.Employee"]), + cancellationToken); + + if (!vehicleOperationsPagination.Sucess || !vehicleOperationsPagination.Value!.Items.Any()) + return; + + var vehiclesOperations = vehicleOperationsPagination.Value.Items; + + await UpdateVehicleStatusAsync(vehiclesOperations, cancellationToken); + } + + private async Task UpdateVehicleStatusAsync(IEnumerable vehicleOperations, CancellationToken cancellationToken) + { + if (vehicleOperations is null || !vehicleOperations.Any()) + return; + + await SyncRangeOperationsAsync(vehicleOperations, cancellationToken); + await SyncOutOfRangeOperationsAsync(vehicleOperations, cancellationToken); + } + + private async Task SyncOutOfRangeOperationsAsync(IEnumerable vehicleOperations, CancellationToken cancellationToken) + { + if (vehicleOperations is null || !vehicleOperations.Any()) + return; + + var rangeOperations = vehicleOperations.Where(c => (c.LineTimeTime < c.EmployeeWorkdayStartTime || + c.LineTimeTime > c.EmployeeWorkdayEndTime) && + c.VehicleStatus is (byte)VehicleStatus.Em_Operação); + + if (!rangeOperations.Any()) + return; + + using var scope = _serviceProvider.CreateScope(); + var vehicleRepository = scope.ServiceProvider.GetRequiredService(); + + var vehicleIds = rangeOperations.Select(c => c.VehicleId); + await vehicleRepository.SetStatusAsync(vehicleIds, VehicleStatus.Disponível, cancellationToken); + } + + private async Task SyncRangeOperationsAsync(IEnumerable vehicleOperations, CancellationToken cancellationToken) + { + if (vehicleOperations is null || !vehicleOperations.Any()) + return; + + var rangeOperations = vehicleOperations.Where(c => c.LineTimeTime >= c.EmployeeWorkdayStartTime && + c.LineTimeTime <= c.EmployeeWorkdayEndTime && + c.VehicleStatus is (byte)VehicleStatus.Disponível && + c.EmployeeWorkdayEmployeeStatus is (byte)EmployeeStatus.Ativo); + + if (!rangeOperations.Any()) + return; + + using var scope = _serviceProvider.CreateScope(); + var vehicleRepository = scope.ServiceProvider.GetRequiredService(); + + var vehicleIds = rangeOperations.Select(c => c.VehicleId); + await vehicleRepository.SetStatusAsync(vehicleIds, VehicleStatus.Em_Operação, cancellationToken); + } + } +} From ab325b7a9886e4b61e33de9d2f7f04e4e7a8e2d6 Mon Sep 17 00:00:00 2001 From: Eduardo Rezende Date: Tue, 4 Nov 2025 23:00:19 -0300 Subject: [PATCH 97/99] =?UTF-8?q?=E2=99=BB=EF=B8=8Frefactor:=20Updating=20?= =?UTF-8?q?Dependency=20Injection?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Adding the HostedService --- OneBus.Infra.Ioc/DependencyInjection.cs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/OneBus.Infra.Ioc/DependencyInjection.cs b/OneBus.Infra.Ioc/DependencyInjection.cs index 12a5206..36fb18c 100644 --- a/OneBus.Infra.Ioc/DependencyInjection.cs +++ b/OneBus.Infra.Ioc/DependencyInjection.cs @@ -2,6 +2,7 @@ using Microsoft.Extensions.DependencyInjection; using OneBus.Application.Interfaces.Services; using OneBus.Application.Services; +using OneBus.Application.Workers; using OneBus.Domain.Interfaces.Repositories; using OneBus.Infra.Data.Repositories; using System.Globalization; @@ -27,6 +28,8 @@ public static IServiceCollection AddInfrastructure(this IServiceCollection servi .AsImplementedInterfaces() .WithScopedLifetime()); + services.AddHostedService(); + services.AddScoped(); services.AddScoped(); return services; From e64c2f376a5bfa8b212802bc16f6c764dae47e2c Mon Sep 17 00:00:00 2001 From: Eduardo Rezende Date: Tue, 4 Nov 2025 23:10:12 -0300 Subject: [PATCH 98/99] =?UTF-8?q?=E2=99=BB=EF=B8=8Frefactor:=20Updating=20?= =?UTF-8?q?Maintenance=20Service?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Adding logic to update vehicle status when creating new maintenance --- .../Services/MaintenanceService.cs | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/OneBus.Application/Services/MaintenanceService.cs b/OneBus.Application/Services/MaintenanceService.cs index 1b44d02..4e74d85 100644 --- a/OneBus.Application/Services/MaintenanceService.cs +++ b/OneBus.Application/Services/MaintenanceService.cs @@ -14,12 +14,16 @@ namespace OneBus.Application.Services public class MaintenanceService : BaseService, IMaintenanceService { + private readonly IVehicleRepository _vehicleRepository; + public MaintenanceService( IBaseRepository baseRepository, IValidator createValidator, - IValidator updateValidator) + IValidator updateValidator, + IVehicleRepository vehicleRepository) : base(baseRepository, createValidator, updateValidator) { + _vehicleRepository = vehicleRepository; } public async override Task>> GetPaginedAsync( @@ -70,6 +74,19 @@ public Result> GetSectors() return SuccessResult>.Create(status); } + public async override Task> CreateAsync( + CreateMaintenanceDTO createDTO, + CancellationToken cancellationToken = default) + { + var result = await base.CreateAsync(createDTO, cancellationToken); + + if (!result.Sucess) + return result; + + await _vehicleRepository.SetStatusAsync([createDTO.VehicleId], Domain.Enums.Vehicle.VehicleStatus.Em_Manutenção, cancellationToken); + return result; + } + protected override void UpdateFields(Maintenance entity, UpdateMaintenanceDTO updateDTO) { entity.Cost = updateDTO.Cost; From ae5d5459c62060392f828b77d63820f8953e6be6 Mon Sep 17 00:00:00 2001 From: Eduardo Rezende Date: Wed, 5 Nov 2025 00:22:26 -0300 Subject: [PATCH 99/99] =?UTF-8?q?=E2=99=BB=EF=B8=8Frefactor:=20Updating=20?= =?UTF-8?q?Line=20Validators?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Adding IsValidDirectionType validation methods logic --- .../Validators/Line/CreateLineDTOValidator.cs | 30 +++++++++++++++++-- .../Validators/Line/UpdateLineDTOValidator.cs | 29 ++++++++++++++++++ 2 files changed, 56 insertions(+), 3 deletions(-) diff --git a/OneBus.Application/Validators/Line/CreateLineDTOValidator.cs b/OneBus.Application/Validators/Line/CreateLineDTOValidator.cs index 0135f23..f7c4dca 100644 --- a/OneBus.Application/Validators/Line/CreateLineDTOValidator.cs +++ b/OneBus.Application/Validators/Line/CreateLineDTOValidator.cs @@ -11,8 +11,8 @@ public class CreateLineDTOValidator : AbstractValidator { private readonly ILineRepository _lineRepository; - //TODO: Não deixar a mesma linha pode pode ter sentido de ida e volta, mas não de circular e - //uma linha circular não pode ter outro cadastro com sentido de ida ou volta + public const string InvalidDirectionType = "Tipo de Direção inválida, verifique se a linha é circular ou a direção é repetida."; + public CreateLineDTOValidator(ILineRepository lineRepository) { _lineRepository = lineRepository; @@ -20,9 +20,11 @@ public CreateLineDTOValidator(ILineRepository lineRepository) RuleFor(c => c.Type) .Must(ValidationUtils.IsValidEnumValue) .OverridePropertyName("Tipo"); - + RuleFor(c => c.DirectionType) .Must(ValidationUtils.IsValidEnumValue) + .MustAsync(IsValidDirectionTypeAsync) + .WithMessage(InvalidDirectionType) .OverridePropertyName("Tipo de Direção"); RuleFor(c => c.Number) @@ -36,6 +38,28 @@ public CreateLineDTOValidator(ILineRepository lineRepository) .OverridePropertyName("Nome"); } + private async Task IsValidDirectionTypeAsync(CreateLineDTO lineDTO, byte directionType, CancellationToken cancellationToken = default) + { + var lines = await _lineRepository.GetManyAsync(c => c.Number.ToLower().Equals(lineDTO.Number.ToLower()) && c.Type == lineDTO.Type, + cancellationToken: cancellationToken); + + if (lines is null || !lines.Any()) + return true; + + if (lines.Any(c => c.DirectionType == directionType)) + return false; + + if (directionType is (byte)DirectionType.Circular && + lines.Any(c => c.DirectionType is (byte)DirectionType.Ida or (byte)DirectionType.Volta)) + return false; + + if (directionType is (byte)DirectionType.Ida or (byte)DirectionType.Volta && + lines.Any(c => c.DirectionType is (byte)DirectionType.Circular)) + return false; + + return true; + } + private async Task IsNumberInUse(string number, byte type, byte directionType, CancellationToken cancellationToken = default) { return await _lineRepository.AnyAsync(c => c.Number.ToLower().Equals(number.ToLower()) && c.Type == type && c.DirectionType == directionType, diff --git a/OneBus.Application/Validators/Line/UpdateLineDTOValidator.cs b/OneBus.Application/Validators/Line/UpdateLineDTOValidator.cs index 4bd7ba4..e6eebd5 100644 --- a/OneBus.Application/Validators/Line/UpdateLineDTOValidator.cs +++ b/OneBus.Application/Validators/Line/UpdateLineDTOValidator.cs @@ -19,6 +19,8 @@ public UpdateLineDTOValidator(ILineRepository lineRepository) RuleFor(c => c.DirectionType) .Must(ValidationUtils.IsValidEnumValue) + .MustAsync(IsValidDirectionTypeAsync) + .WithMessage(CreateLineDTOValidator.InvalidDirectionType) .OverridePropertyName("Tipo de Direção"); RuleFor(c => c.Number) @@ -32,6 +34,33 @@ public UpdateLineDTOValidator(ILineRepository lineRepository) .OverridePropertyName("Nome"); } + private async Task IsValidDirectionTypeAsync(UpdateLineDTO lineDTO, byte directionType, CancellationToken cancellationToken = default) + { + var line = await _lineRepository.GetOneAsync(c => c.Id == lineDTO.Id, cancellationToken: cancellationToken); + + if (line is null) + return false; + + var lines = await _lineRepository.GetManyAsync(c => c.Number.ToLower().Equals(line.Number.ToLower()) && c.Type == line.Type, + cancellationToken: cancellationToken); + + if (lines is null || !lines.Any()) + return false; + + if (lines.Any(c => c.DirectionType == directionType)) + return false; + + if (directionType is (byte)DirectionType.Circular && + lines.Any(c => c.DirectionType is (byte)DirectionType.Ida or (byte)DirectionType.Volta)) + return false; + + if (directionType is (byte)DirectionType.Ida or (byte)DirectionType.Volta && + lines.Any(c => c.DirectionType is (byte)DirectionType.Circular)) + return false; + + return true; + } + private async Task IsNumberInUse(long id, string number, CancellationToken cancellationToken = default) { var line = await _lineRepository.GetOneAsync(c => c.Id == id, cancellationToken: cancellationToken);