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(); + } + } +} 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/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(); + } } } 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(); } } } 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(); } } } 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" /// } /// /// diff --git a/OneBus.API/Controllers/VehicleController.cs b/OneBus.API/Controllers/VehicleController.cs index 7185c78..61c7c3a 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")] @@ -102,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(); } @@ -125,5 +124,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(); + } } } 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(); } } } diff --git a/OneBus.API/OneBus.API.csproj b/OneBus.API/OneBus.API.csproj index 56da312..f7ffcd0 100644 --- a/OneBus.API/OneBus.API.csproj +++ b/OneBus.API/OneBus.API.csproj @@ -11,17 +11,17 @@ - - - + + + all runtime; build; native; contentfiles; analyzers; buildtransitive - - - - + + + + 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/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/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/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; } 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; } } } diff --git a/OneBus.Application/DTOs/LineTime/CreateLineTimeDTO.cs b/OneBus.Application/DTOs/LineTime/CreateLineTimeDTO.cs index 5460d6f..b2ec3f8 100644 --- a/OneBus.Application/DTOs/LineTime/CreateLineTimeDTO.cs +++ b/OneBus.Application/DTOs/LineTime/CreateLineTimeDTO.cs @@ -2,5 +2,10 @@ { public class CreateLineTimeDTO : BaseCreateDTO { + public long LineId { get; set; } + + public TimeOnly Time { get; set; } + + public byte DayType { get; set; } } } diff --git a/OneBus.Application/DTOs/LineTime/ReadLineTimeDTO.cs b/OneBus.Application/DTOs/LineTime/ReadLineTimeDTO.cs index c8ff899..c2ccc88 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 byte LineDirectionType { get; set; } + + public string? LineDirectionTypeName { get; set; } + + public TimeOnly Time { get; set; } + + public byte DayType { get; set; } + + public string? DayTypeName { get; set; } } } diff --git a/OneBus.Application/DTOs/LineTime/UpdateLineTimeDTO.cs b/OneBus.Application/DTOs/LineTime/UpdateLineTimeDTO.cs index 0166816..b4e7a45 100644 --- a/OneBus.Application/DTOs/LineTime/UpdateLineTimeDTO.cs +++ b/OneBus.Application/DTOs/LineTime/UpdateLineTimeDTO.cs @@ -1,6 +1,9 @@ namespace OneBus.Application.DTOs.LineTime { public class UpdateLineTimeDTO : BaseUpdateDTO - { + { + public TimeOnly Time { get; set; } + + public byte DayType { get; set; } } } 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; } } } diff --git a/OneBus.Application/DTOs/Vehicle/CreateVehicleDTO.cs b/OneBus.Application/DTOs/Vehicle/CreateVehicleDTO.cs index 731fa48..5e26783 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; + Model = string.Empty; + Plate = string.Empty; + Renavam = string.Empty; + Licensing = 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 byte Brand { get; set; } + + public string Model { get; set; } + + public ushort Year { get; set; } + + public string Plate { get; set; } + + public byte? 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 string Licensing { 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 byte? 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/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/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/ReadVehicleDTO.cs b/OneBus.Application/DTOs/Vehicle/ReadVehicleDTO.cs index e1d240b..7f97eba 100644 --- a/OneBus.Application/DTOs/Vehicle/ReadVehicleDTO.cs +++ b/OneBus.Application/DTOs/Vehicle/ReadVehicleDTO.cs @@ -2,5 +2,89 @@ { public class ReadVehicleDTO : BaseReadDTO { + public ReadVehicleDTO() + { + Prefix = string.Empty; + Model = string.Empty; + Plate = string.Empty; + Renavam = string.Empty; + Licensing = string.Empty; + } + + public byte Type { get; set; } + + public string? TypeName { 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? FuelTypeName { get; set; } + + public byte Brand { get; set; } + + public string? BrandName { get; set; } + + public string Model { get; set; } + + public ushort Year { get; set; } + + public string Plate { get; set; } + + public byte? Color { get; set; } + + public string? ColorName { 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 string Licensing { get; set; } + + public string Renavam { get; set; } + + 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; } + + 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/ReadVehicleStatusDTO.cs b/OneBus.Application/DTOs/Vehicle/ReadVehicleStatusDTO.cs new file mode 100644 index 0000000..02b6262 --- /dev/null +++ b/OneBus.Application/DTOs/Vehicle/ReadVehicleStatusDTO.cs @@ -0,0 +1,14 @@ +namespace OneBus.Application.DTOs.Vehicle +{ + public class ReadVehicleStatusDTO + { + public ReadVehicleStatusDTO() + { + Name = string.Empty; + } + + public byte Value { get; set; } + + public string Name { get; set; } + } +} diff --git a/OneBus.Application/DTOs/Vehicle/ReadVehicleTypeDTO.cs b/OneBus.Application/DTOs/Vehicle/ReadVehicleTypeDTO.cs new file mode 100644 index 0000000..8590dbe --- /dev/null +++ b/OneBus.Application/DTOs/Vehicle/ReadVehicleTypeDTO.cs @@ -0,0 +1,14 @@ +namespace OneBus.Application.DTOs.Vehicle +{ + public class ReadVehicleTypeDTO + { + public ReadVehicleTypeDTO() + { + Name = string.Empty; + } + + public byte Value { get; set; } + + public string Name { get; set; } + } +} diff --git a/OneBus.Application/DTOs/Vehicle/UpdateVehicleDTO.cs b/OneBus.Application/DTOs/Vehicle/UpdateVehicleDTO.cs index e0fa962..182d8d5 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; + Model = string.Empty; + Plate = string.Empty; + Renavam = string.Empty; + Licensing = 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 byte Brand { get; set; } + + public string Model { get; set; } + + public ushort Year { get; set; } + + public string Plate { get; set; } + + public byte? 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 string Licensing { 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 byte? 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/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..0496378 100644 --- a/OneBus.Application/DTOs/VehicleOperation/ReadVehicleOperationDTO.cs +++ b/OneBus.Application/DTOs/VehicleOperation/ReadVehicleOperationDTO.cs @@ -1,6 +1,81 @@ -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; } + + [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; } + + [JsonPropertyName("employeeStatus")] + public byte? EmployeeWorkdayEmployeeStatus { get; set; } + + [JsonPropertyName("employeeStatusName")] + public string? EmployeeWorkdayEmployeeStatusName { get; set; } + + public long VehicleId { get; set; } + + public string? VehiclePrefix { get; set; } + + public byte? VehicleType { get; set; } + + public string? VehicleTypeName { get; set; } + + public byte? VehicleStatus { get; set; } + + public string? VehicleStatusName { get; set; } + + public byte[]? VehicleImage { 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; } } } 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/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/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/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/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/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/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/Interfaces/Services/IVehicleService.cs b/OneBus.Application/Interfaces/Services/IVehicleService.cs index ac0f422..8d4d4f9 100644 --- a/OneBus.Application/Interfaces/Services/IVehicleService.cs +++ b/OneBus.Application/Interfaces/Services/IVehicleService.cs @@ -1,11 +1,27 @@ using OneBus.Application.DTOs.Vehicle; +using OneBus.Domain.Commons.Result; using OneBus.Domain.Entities; using OneBus.Domain.Filters; namespace OneBus.Application.Interfaces.Services { public interface IVehicleService : - IBaseService + IBaseService { + Result> GetBrands(); + + Result> GetBusChassisBrands(); + + Result> GetBusServiceTypes(); + + Result> GetColors(); + + Result> GetFuelTypes(); + + Result> GetStatus(); + + Result> GetTransmissionTypes(); + + Result> GetVehicleTypes(); } } diff --git a/OneBus.Application/OneBus.Application.csproj b/OneBus.Application/OneBus.Application.csproj index eee47b5..eae80e9 100644 --- a/OneBus.Application/OneBus.Application.csproj +++ b/OneBus.Application/OneBus.Application.csproj @@ -7,10 +7,11 @@ - + - + + 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/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); + } + } +} diff --git a/OneBus.Application/Services/EmployeeService.cs b/OneBus.Application/Services/EmployeeService.cs index 8114cd2..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; @@ -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/LineService.cs b/OneBus.Application/Services/LineService.cs index c46d45d..12ca50c 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, dbQueryOptions, 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, dbQueryOptions, 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; } } } diff --git a/OneBus.Application/Services/LineTimeService.cs b/OneBus.Application/Services/LineTimeService.cs index d895b3c..e45eb5c 100644 --- a/OneBus.Application/Services/LineTimeService.cs +++ b/OneBus.Application/Services/LineTimeService.cs @@ -1,26 +1,68 @@ 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.LineDirectionTypeName = ((DirectionType)lineTime.LineDirectionType).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.LineDirectionTypeName = ((DirectionType)lineTime.LineDirectionType).ToString().Localize(); + + return result; + } + protected override void UpdateFields(LineTime entity, UpdateLineTimeDTO updateDTO) { - throw new NotImplementedException(); + entity.Time = updateDTO.Time; + entity.DayType = updateDTO.DayType; } } } diff --git a/OneBus.Application/Services/MaintenanceService.cs b/OneBus.Application/Services/MaintenanceService.cs index 394e293..4e74d85 100644 --- a/OneBus.Application/Services/MaintenanceService.cs +++ b/OneBus.Application/Services/MaintenanceService.cs @@ -1,26 +1,100 @@ 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 { + private readonly IVehicleRepository _vehicleRepository; + public MaintenanceService( - IBaseRepository baseRepository, - IValidator createValidator, - IValidator updateValidator) + IBaseRepository baseRepository, + IValidator createValidator, + IValidator updateValidator, + IVehicleRepository vehicleRepository) : base(baseRepository, createValidator, updateValidator) { + _vehicleRepository = vehicleRepository; + } + + 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); + } + + 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) { - 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; } } } 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/VehicleOperationService.cs b/OneBus.Application/Services/VehicleOperationService.cs index 93f3b93..d9b1114 100644 --- a/OneBus.Application/Services/VehicleOperationService.cs +++ b/OneBus.Application/Services/VehicleOperationService.cs @@ -1,26 +1,81 @@ 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.Employee; +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.VehicleStatusName = ((VehicleStatus?)vehicleOperation.VehicleStatus)?.ToString()?.Localize(); + vehicleOperation.LineTimeLineTypeName = ((LineType?)vehicleOperation.LineTimeLineType)?.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; + } + + 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.VehicleStatusName = ((VehicleStatus?)vehicleOperation.VehicleStatus)?.ToString()?.Localize(); + vehicleOperation.LineTimeLineTypeName = ((LineType?)vehicleOperation.LineTimeLineType)?.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; + } + protected override void UpdateFields(VehicleOperation entity, UpdateVehicleOperationDTO updateDTO) { - throw new NotImplementedException(); + entity.VehicleId = updateDTO.VehicleId; + entity.LineTimeId = updateDTO.LineTimeId; + entity.EmployeeWorkdayId = updateDTO.EmployeeWorkdayId; } } } diff --git a/OneBus.Application/Services/VehicleService.cs b/OneBus.Application/Services/VehicleService.cs index bf793c1..fed8b1b 100644 --- a/OneBus.Application/Services/VehicleService.cs +++ b/OneBus.Application/Services/VehicleService.cs @@ -1,26 +1,219 @@ 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; +using OneBus.Domain.Extensions; using OneBus.Domain.Filters; using OneBus.Domain.Interfaces.Repositories; namespace OneBus.Application.Services { - public class VehicleService : BaseService, + public class VehicleService : BaseService, IVehicleService { public VehicleService( - IBaseRepository baseRepository, - IValidator createValidator, - IValidator updateValidator) + IBaseRepository baseRepository, + IValidator createValidator, + IValidator updateValidator) : base(baseRepository, createValidator, updateValidator) { } + public override async Task>> GetPaginedAsync( + VehicleFilter filter, + DbQueryOptions? dbQueryOptions = null, + CancellationToken cancellationToken = default) + { + var result = await base.GetPaginedAsync(filter, dbQueryOptions, 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.BusServiceTypeName = ((BusServiceType?)vehicle.BusServiceType)?.ToString()?.Localize(); + vehicle.TransmissionTypeName = ((TransmissionType)vehicle.TransmissionType).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, dbQueryOptions, 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.BusServiceTypeName = ((BusServiceType?)vehicle.BusServiceType)?.ToString()?.Localize(); + vehicle.TransmissionTypeName = ((TransmissionType)vehicle.TransmissionType).ToString().Localize(); + vehicle.BusChassisBrandName = ((BusChassisBrands?)vehicle.BusChassisBrand)?.ToString()?.Localize(); + + return result; + } + + public Result> GetStatus() + { + var values = Enum.GetValues(); + + List status = []; + + foreach (var value in values) + { + status.Add(new ReadVehicleStatusDTO { 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 ReadVehicleTypeDTO { Value = (byte)value, Name = value.ToString().Localize() }); + } + + return SuccessResult>.Create(status); + } + 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.Licensing = updateDTO.Licensing; + 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.BusFumigateExpiration = updateDTO.BusFumigateExpiration; + entity.BusInsuranceExpiration = updateDTO.BusInsuranceExpiration; } } } 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.Application/Validators/Employee/CreateEmployeeDTOValidator.cs b/OneBus.Application/Validators/Employee/CreateEmployeeDTOValidator.cs index 4edee42..0c5a842 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 { @@ -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 9762db7..26378c4 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 { @@ -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/EmployeeWorkday/CreateEmployeeWorkdayDTOValidator.cs b/OneBus.Application/Validators/EmployeeWorkday/CreateEmployeeWorkdayDTOValidator.cs index 2c90fab..4cf3f42 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 { @@ -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/Line/CreateLineDTOValidator.cs b/OneBus.Application/Validators/Line/CreateLineDTOValidator.cs index f1d032b..f7c4dca 100644 --- a/OneBus.Application/Validators/Line/CreateLineDTOValidator.cs +++ b/OneBus.Application/Validators/Line/CreateLineDTOValidator.cs @@ -1,9 +1,69 @@ 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 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; + + 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) + .MustAsync(async (line, number, ct) => !await IsNumberInUse(number, line.Type, line.DirectionType, ct)) + .WithMessage(ErrorUtils.AlreadyExists("Número").Message) + .NotEmpty() + .OverridePropertyName("Número"); + + RuleFor(c => c.Name) + .NotEmpty() + .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, + cancellationToken: cancellationToken); + } } } diff --git a/OneBus.Application/Validators/Line/UpdateLineDTOValidator.cs b/OneBus.Application/Validators/Line/UpdateLineDTOValidator.cs index e74b13b..e6eebd5 100644 --- a/OneBus.Application/Validators/Line/UpdateLineDTOValidator.cs +++ b/OneBus.Application/Validators/Line/UpdateLineDTOValidator.cs @@ -1,9 +1,76 @@ 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) + .MustAsync(IsValidDirectionTypeAsync) + .WithMessage(CreateLineDTOValidator.InvalidDirectionType) + .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 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); + + if (line is null) + return false; + + return await _lineRepository.AnyAsync(c => c.Number.ToLower().Equals(number.ToLower()) && + c.Type == line.Type && c.DirectionType == line.DirectionType && c.Id != id, + cancellationToken: cancellationToken); + } } } diff --git a/OneBus.Application/Validators/LineTime/CreateLineTimeDTOValidator.cs b/OneBus.Application/Validators/LineTime/CreateLineTimeDTOValidator.cs index 5837c3e..f6b05a8 100644 --- a/OneBus.Application/Validators/LineTime/CreateLineTimeDTOValidator.cs +++ b/OneBus.Application/Validators/LineTime/CreateLineTimeDTOValidator.cs @@ -1,9 +1,37 @@ using FluentValidation; using OneBus.Application.DTOs.LineTime; +using OneBus.Domain.Commons; +using OneBus.Domain.Enums; +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.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..f82ed91 100644 --- a/OneBus.Application/Validators/LineTime/UpdateLineTimeDTOValidator.cs +++ b/OneBus.Application/Validators/LineTime/UpdateLineTimeDTOValidator.cs @@ -1,9 +1,19 @@ 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.DayType).Must(ValidationUtils.IsValidEnumValue) + .OverridePropertyName("Dia da Semana"); + } } } diff --git a/OneBus.Application/Validators/Maintenance/CreateMaintenanceDTOValidator.cs b/OneBus.Application/Validators/Maintenance/CreateMaintenanceDTOValidator.cs index 3bc45f7..0df8bfa 100644 --- a/OneBus.Application/Validators/Maintenance/CreateMaintenanceDTOValidator.cs +++ b/OneBus.Application/Validators/Maintenance/CreateMaintenanceDTOValidator.cs @@ -1,9 +1,45 @@ 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"); + } + + 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..445fd4a 100644 --- a/OneBus.Application/Validators/Maintenance/UpdateMaintenanceDTOValidator.cs +++ b/OneBus.Application/Validators/Maintenance/UpdateMaintenanceDTOValidator.cs @@ -1,9 +1,26 @@ 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"); + } } } diff --git a/OneBus.Application/Validators/Vehicle/CreateVehicleDTOValidator.cs b/OneBus.Application/Validators/Vehicle/CreateVehicleDTOValidator.cs index 2ff123d..cce2b6e 100644 --- a/OneBus.Application/Validators/Vehicle/CreateVehicleDTOValidator.cs +++ b/OneBus.Application/Validators/Vehicle/CreateVehicleDTOValidator.cs @@ -1,9 +1,168 @@ using FluentValidation; using OneBus.Application.DTOs.Vehicle; +using OneBus.Domain.Commons; +using OneBus.Domain.Enums.Vehicle; +using OneBus.Domain.Interfaces.Repositories; +using OneBus.Domain.Utils; 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.Licensing) + .NotEmpty() + .OverridePropertyName("Licenciamento"); + + 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.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"); + + 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.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) + { + 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.ToLower()), + cancellationToken: cancellationToken); + } + + private async Task IsRenavamInUseAsync(string renavam, CancellationToken cancellationToken = default) + { + return await _vehicleRepository.AnyAsync(c => c.Renavam.ToLower().Equals(renavam.ToLower()), + cancellationToken: cancellationToken); + } + + private async Task IsNumberChassisInUseAsync(string? numberChassis, CancellationToken cancellationToken = default) + { + 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) + { + 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) + { + 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 688c066..315c9c4 100644 --- a/OneBus.Application/Validators/Vehicle/UpdateVehicleDTOValidator.cs +++ b/OneBus.Application/Validators/Vehicle/UpdateVehicleDTOValidator.cs @@ -1,9 +1,166 @@ using FluentValidation; using OneBus.Application.DTOs.Vehicle; +using OneBus.Domain.Commons; +using OneBus.Domain.Enums.Vehicle; +using OneBus.Domain.Interfaces.Repositories; +using OneBus.Domain.Utils; 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 (vehicle, prefix, ct) => !await IsPrefixInUseAsync(vehicle.Id, 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.Licensing) + .NotEmpty() + .OverridePropertyName("Licenciamento"); + + RuleFor(c => c.Plate) + .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 (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 (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 (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 (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"); + + RuleFor(c => c.Status) + .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.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(long id, string prefix, CancellationToken cancellationToken = default) + { + 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.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.ToLower()) && c.Id != id, + cancellationToken: cancellationToken); + } + + private async Task IsNumberChassisInUseAsync(long id, string? numberChassis, CancellationToken cancellationToken = default) + { + 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) + { + 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) + { + if (string.IsNullOrWhiteSpace(engineNumber)) + return false; + + return await _vehicleRepository.AnyAsync(c => c.EngineNumber!.ToLower().Equals(engineNumber.ToLower()) && c.Id != id, + cancellationToken: cancellationToken); + } } } 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); + } } } 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); + } + } +} 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/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/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/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; } } diff --git a/OneBus.Domain/Entities/LineTime.cs b/OneBus.Domain/Entities/LineTime.cs index d3c4b07..d4db1cd 100644 --- a/OneBus.Domain/Entities/LineTime.cs +++ b/OneBus.Domain/Entities/LineTime.cs @@ -4,14 +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 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..9ae8132 100644 --- a/OneBus.Domain/Entities/Vehicle.cs +++ b/OneBus.Domain/Entities/Vehicle.cs @@ -5,10 +5,10 @@ public class Vehicle : BaseEntity public Vehicle() { Prefix = string.Empty; - Brand = string.Empty; Model = string.Empty; Plate = string.Empty; Renavam = string.Empty; + Licensing = string.Empty; } public byte Type { get; set; } @@ -23,7 +23,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 +31,7 @@ public Vehicle() public string Plate { get; set; } - public string? Color { get; set; } + public byte? Color { get; set; } public string? BodyworkNumber { get; set; } @@ -43,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; } @@ -55,7 +55,21 @@ public Vehicle() public byte[]? Image { get; set; } - public ICollection? Buses { get; set; } + public byte? BusServiceType { get; set; } + + public byte? 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..12552f1 100644 --- a/OneBus.Domain/Entities/VehicleOperation.cs +++ b/OneBus.Domain/Entities/VehicleOperation.cs @@ -2,14 +2,16 @@ { public class VehicleOperation : BaseEntity { + 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; } + + public LineTime? LineTime { get; set; } } } diff --git a/OneBus.Domain/Enums/Bus/ServiceType.cs b/OneBus.Domain/Enums/Bus/ServiceType.cs deleted file mode 100644 index fbbfe05..0000000 --- a/OneBus.Domain/Enums/Bus/ServiceType.cs +++ /dev/null @@ -1,9 +0,0 @@ -namespace OneBus.Domain.Enums.Bus -{ - public enum ServiceType : byte - { - Municipal, - Intermunicipal, - Suburbano - } -} diff --git a/OneBus.Domain/Enums/Line/DirectionType.cs b/OneBus.Domain/Enums/Line/DirectionType.cs new file mode 100644 index 0000000..bb1be93 --- /dev/null +++ b/OneBus.Domain/Enums/Line/DirectionType.cs @@ -0,0 +1,9 @@ +namespace OneBus.Domain.Enums.Line +{ + public enum DirectionType : byte + { + 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 } } 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 } } 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/Vehicle/BusServiceType.cs b/OneBus.Domain/Enums/Vehicle/BusServiceType.cs new file mode 100644 index 0000000..99205bb --- /dev/null +++ b/OneBus.Domain/Enums/Vehicle/BusServiceType.cs @@ -0,0 +1,10 @@ +namespace OneBus.Domain.Enums.Vehicle +{ + public enum BusServiceType : byte + { + Municipal, + Intermunicipal, + Suburbano, + Seletivo + } +} 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..08e70ce 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, + Elétrico, + 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..ea4f4c8 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 + Ônibus_Articulado, + Van, + Caminhão, + Carro } } 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; } 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; } + } +} 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; } + } +} 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; } + } +} 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; } + } +} diff --git a/OneBus.Domain/Filters/VehicleOperationFilter.cs b/OneBus.Domain/Filters/VehicleOperationFilter.cs new file mode 100644 index 0000000..e4d9dd7 --- /dev/null +++ b/OneBus.Domain/Filters/VehicleOperationFilter.cs @@ -0,0 +1,35 @@ +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? 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; } + } +} 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.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.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.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.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.Domain/Interfaces/Repositories/IVehicleRepository.cs b/OneBus.Domain/Interfaces/Repositories/IVehicleRepository.cs index c6a593f..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 + public interface IVehicleRepository : IBaseRepository { + Task SetStatusAsync(IEnumerable ids, VehicleStatus status, CancellationToken cancellationToken = default); } } 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 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 { 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/Mappings/VehicleMapping.cs b/OneBus.Infra.Data/Mappings/VehicleMapping.cs index 814a9b7..3b8d555 100644 --- a/OneBus.Infra.Data/Mappings/VehicleMapping.cs +++ b/OneBus.Infra.Data/Mappings/VehicleMapping.cs @@ -10,15 +10,16 @@ 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); + 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); + 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) 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/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/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/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/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/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/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 657adab..341b6d7 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.10") .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") @@ -244,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) @@ -294,16 +200,13 @@ protected override void BuildModel(ModelBuilder modelBuilder) 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") + b.Property("Time") .HasColumnType("time without time zone"); b.HasKey("Id"); @@ -433,16 +336,37 @@ protected override void BuildModel(ModelBuilder modelBuilder) .IsUnicode(false) .HasColumnType("character varying(20)"); - b.Property("Brand") - .IsRequired() + b.Property("Brand") + .HasColumnType("smallint"); + + b.Property("BusChassisBrand") + .HasColumnType("smallint"); + + b.Property("BusChassisModel") .HasMaxLength(50) .IsUnicode(false) .HasColumnType("character varying(50)"); - b.Property("Color") - .HasMaxLength(20) - .IsUnicode(false) - .HasColumnType("character varying(20)"); + 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"); @@ -467,8 +391,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() @@ -539,15 +466,15 @@ 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") + .HasColumnType("bigint"); + b.Property("VehicleId") .HasColumnType("bigint"); @@ -555,49 +482,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 +530,12 @@ protected override void BuildModel(ModelBuilder modelBuilder) .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") @@ -647,12 +544,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 +556,6 @@ protected override void BuildModel(ModelBuilder modelBuilder) modelBuilder.Entity("OneBus.Domain.Entities.EmployeeWorkday", b => { - b.Navigation("BusOperations"); - b.Navigation("VehicleOperations"); }); @@ -674,13 +566,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"); diff --git a/OneBus.Infra.Data/OneBus.Infra.Data.csproj b/OneBus.Infra.Data/OneBus.Infra.Data.csproj index aecb86e..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 - + 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) - { - } - } -} 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)); + } } } diff --git a/OneBus.Infra.Data/Repositories/LineTimeRepository.cs b/OneBus.Infra.Data/Repositories/LineTimeRepository.cs index 2bd6dea..418cb76 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.Line!.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)); + } } } 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)); + } } } diff --git a/OneBus.Infra.Data/Repositories/VehicleOperationRepository.cs b/OneBus.Infra.Data/Repositories/VehicleOperationRepository.cs index c7ccb68..614fd7c 100644 --- a/OneBus.Infra.Data/Repositories/VehicleOperationRepository.cs +++ b/OneBus.Infra.Data/Repositories/VehicleOperationRepository.cs @@ -1,14 +1,56 @@ -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.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)); + } } } diff --git a/OneBus.Infra.Data/Repositories/VehicleRepository.cs b/OneBus.Infra.Data/Repositories/VehicleRepository.cs index c825152..443c744 100644 --- a/OneBus.Infra.Data/Repositories/VehicleRepository.cs +++ b/OneBus.Infra.Data/Repositories/VehicleRepository.cs @@ -1,14 +1,56 @@ -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; +using System.Linq.Expressions; namespace OneBus.Infra.Data.Repositories { - public class VehicleRepository : BaseRepository, IVehicleRepository + public class VehicleRepository : BaseRepository, IVehicleRepository { 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(); + + 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.Licensing!.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)); + } } } diff --git a/OneBus.Infra.Ioc/DependencyInjection.cs b/OneBus.Infra.Ioc/DependencyInjection.cs index d5d36fd..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,7 +28,10 @@ public static IServiceCollection AddInfrastructure(this IServiceCollection servi .AsImplementedInterfaces() .WithScopedLifetime()); + services.AddHostedService(); + services.AddScoped(); + services.AddScoped(); return services; } } 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 @@ - + 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