From d3ed7abe8976f47b0c2997dfa10e24184da4d60d Mon Sep 17 00:00:00 2001 From: cuqmbr Date: Sun, 13 Nov 2022 16:10:09 +0200 Subject: [PATCH] refactor: change controllers' names, implemented inheritance in dtos --- Server/Configurations/MapperInitializer.cs | 1 + ...mentController.cs => AddressController.cs} | 4 +-- ...agementController.cs => CityController.cs} | 4 +-- ...mentController.cs => CompanyController.cs} | 4 +-- ...mentController.cs => CountryController.cs} | 4 +-- ...ementController.cs => ReviewController.cs} | 4 +-- ...ontroller.cs => RouteAddressController.cs} | 4 +-- ...gementController.cs => RouteController.cs} | 4 +-- ...gementController.cs => StateController.cs} | 4 +-- ...ementController.cs => TicketController.cs} | 4 +-- ...mentController.cs => VehicleController.cs} | 4 +-- ...ller.cs => VehicleEnrollmentController.cs} | 4 +-- .../DataTransferObjects/CompanyDto.cs | 10 ++----- SharedModels/DataTransferObjects/ReviewDto.cs | 15 ++-------- .../DataTransferObjects/RouteAddressDto.cs | 22 +++++--------- SharedModels/DataTransferObjects/RouteDto.cs | 8 ++--- SharedModels/DataTransferObjects/TicketDto.cs | 5 +++- .../DataTransferObjects/VehicleDto.cs | 30 ++----------------- .../VehicleEnrollmentDto.cs | 24 ++++----------- 19 files changed, 49 insertions(+), 110 deletions(-) rename Server/Controllers/{AddressManagementController.cs => AddressController.cs} (91%) rename Server/Controllers/{CityManagementController.cs => CityController.cs} (91%) rename Server/Controllers/{CompanyManagementController.cs => CompanyController.cs} (94%) rename Server/Controllers/{CountryManagementController.cs => CountryController.cs} (91%) rename Server/Controllers/{ReviewManagementController.cs => ReviewController.cs} (94%) rename Server/Controllers/{RouteAddressManagementController.cs => RouteAddressController.cs} (94%) rename Server/Controllers/{RouteManagementController.cs => RouteController.cs} (94%) rename Server/Controllers/{StateManagementController.cs => StateController.cs} (91%) rename Server/Controllers/{TicketManagementController.cs => TicketController.cs} (94%) rename Server/Controllers/{VehicleManagementController.cs => VehicleController.cs} (94%) rename Server/Controllers/{VehicleEnrollmentManagementController.cs => VehicleEnrollmentController.cs} (93%) diff --git a/Server/Configurations/MapperInitializer.cs b/Server/Configurations/MapperInitializer.cs index 2cb5d5e..6385eaa 100644 --- a/Server/Configurations/MapperInitializer.cs +++ b/Server/Configurations/MapperInitializer.cs @@ -35,6 +35,7 @@ public class MapperInitializer : Profile CreateMap().ReverseMap(); CreateMap().ReverseMap(); CreateMap().ReverseMap(); + CreateMap().ReverseMap(); CreateMap().ReverseMap(); CreateMap().ReverseMap(); diff --git a/Server/Controllers/AddressManagementController.cs b/Server/Controllers/AddressController.cs similarity index 91% rename from Server/Controllers/AddressManagementController.cs rename to Server/Controllers/AddressController.cs index e0d2bf5..4085edd 100644 --- a/Server/Controllers/AddressManagementController.cs +++ b/Server/Controllers/AddressController.cs @@ -8,11 +8,11 @@ namespace Server.Controllers; [Route("api/addresses")] [ApiController] -public class AddressManagementController : ControllerBase +public class AddressController : ControllerBase { private readonly IAddressManagementService _addressManagementService; - public AddressManagementController(IAddressManagementService addressManagementService) + public AddressController(IAddressManagementService addressManagementService) { _addressManagementService = addressManagementService; } diff --git a/Server/Controllers/CityManagementController.cs b/Server/Controllers/CityController.cs similarity index 91% rename from Server/Controllers/CityManagementController.cs rename to Server/Controllers/CityController.cs index f8177e7..1255cad 100644 --- a/Server/Controllers/CityManagementController.cs +++ b/Server/Controllers/CityController.cs @@ -8,11 +8,11 @@ namespace Server.Controllers; [Route("api/cities")] [ApiController] -public class CityManagementController : ControllerBase +public class CityController : ControllerBase { private readonly ICityManagementService _cityManagementService; - public CityManagementController(ICityManagementService cityManagementService) + public CityController(ICityManagementService cityManagementService) { _cityManagementService = cityManagementService; } diff --git a/Server/Controllers/CompanyManagementController.cs b/Server/Controllers/CompanyController.cs similarity index 94% rename from Server/Controllers/CompanyManagementController.cs rename to Server/Controllers/CompanyController.cs index 8d86713..020d916 100644 --- a/Server/Controllers/CompanyManagementController.cs +++ b/Server/Controllers/CompanyController.cs @@ -8,11 +8,11 @@ namespace Server.Controllers; [Route("api/companies")] [ApiController] -public class CompanyManagementController : ControllerBase +public class CompanyController : ControllerBase { private readonly ICompanyManagementService _companyManagementService; - public CompanyManagementController(ICompanyManagementService companyManagementService) + public CompanyController(ICompanyManagementService companyManagementService) { _companyManagementService = companyManagementService; } diff --git a/Server/Controllers/CountryManagementController.cs b/Server/Controllers/CountryController.cs similarity index 91% rename from Server/Controllers/CountryManagementController.cs rename to Server/Controllers/CountryController.cs index fe6b01b..f8b709a 100644 --- a/Server/Controllers/CountryManagementController.cs +++ b/Server/Controllers/CountryController.cs @@ -8,11 +8,11 @@ namespace Server.Controllers; [Route("api/countries")] [ApiController] -public class CountryManagementController : ControllerBase +public class CountryController : ControllerBase { private readonly ICountryManagementService _countryManagementService; - public CountryManagementController(ICountryManagementService countryManagementService) + public CountryController(ICountryManagementService countryManagementService) { _countryManagementService = countryManagementService; } diff --git a/Server/Controllers/ReviewManagementController.cs b/Server/Controllers/ReviewController.cs similarity index 94% rename from Server/Controllers/ReviewManagementController.cs rename to Server/Controllers/ReviewController.cs index bd96895..7864c37 100644 --- a/Server/Controllers/ReviewManagementController.cs +++ b/Server/Controllers/ReviewController.cs @@ -8,11 +8,11 @@ namespace Server.Controllers; [Route("api/reviews")] [ApiController] -public class ReviewManagementController : ControllerBase +public class ReviewController : ControllerBase { private readonly IReviewManagementService _reviewManagementService; - public ReviewManagementController(IReviewManagementService reviewManagementService) + public ReviewController(IReviewManagementService reviewManagementService) { _reviewManagementService = reviewManagementService; } diff --git a/Server/Controllers/RouteAddressManagementController.cs b/Server/Controllers/RouteAddressController.cs similarity index 94% rename from Server/Controllers/RouteAddressManagementController.cs rename to Server/Controllers/RouteAddressController.cs index b65aa26..004ae0c 100644 --- a/Server/Controllers/RouteAddressManagementController.cs +++ b/Server/Controllers/RouteAddressController.cs @@ -8,11 +8,11 @@ namespace Server.Controllers; [Route("api/routeAddresses")] [ApiController] -public class RouteAddressManagementController : ControllerBase +public class RouteAddressController : ControllerBase { private readonly IRouteAddressManagementService _routeAddressManagementService; - public RouteAddressManagementController(IRouteAddressManagementService routeAddressManagementService) + public RouteAddressController(IRouteAddressManagementService routeAddressManagementService) { _routeAddressManagementService = routeAddressManagementService; } diff --git a/Server/Controllers/RouteManagementController.cs b/Server/Controllers/RouteController.cs similarity index 94% rename from Server/Controllers/RouteManagementController.cs rename to Server/Controllers/RouteController.cs index 51e6132..b5e0329 100644 --- a/Server/Controllers/RouteManagementController.cs +++ b/Server/Controllers/RouteController.cs @@ -8,11 +8,11 @@ namespace Server.Controllers; [Route("api/routes")] [ApiController] -public class RouteManagementController : ControllerBase +public class RouteController : ControllerBase { private readonly IRouteManagementService _routeManagementService; - public RouteManagementController(IRouteManagementService routeManagementService) + public RouteController(IRouteManagementService routeManagementService) { _routeManagementService = routeManagementService; } diff --git a/Server/Controllers/StateManagementController.cs b/Server/Controllers/StateController.cs similarity index 91% rename from Server/Controllers/StateManagementController.cs rename to Server/Controllers/StateController.cs index f43c637..2a5b0a5 100644 --- a/Server/Controllers/StateManagementController.cs +++ b/Server/Controllers/StateController.cs @@ -8,11 +8,11 @@ namespace Server.Controllers; [Route("api/states")] [ApiController] -public class StateManagementController : ControllerBase +public class StateController : ControllerBase { private readonly IStateManagementService _stateManagementService; - public StateManagementController(IStateManagementService stateManagementService) + public StateController(IStateManagementService stateManagementService) { _stateManagementService = stateManagementService; } diff --git a/Server/Controllers/TicketManagementController.cs b/Server/Controllers/TicketController.cs similarity index 94% rename from Server/Controllers/TicketManagementController.cs rename to Server/Controllers/TicketController.cs index 3392007..08159f1 100644 --- a/Server/Controllers/TicketManagementController.cs +++ b/Server/Controllers/TicketController.cs @@ -8,11 +8,11 @@ namespace Server.Controllers; [Route("api/tickets")] [ApiController] -public class TicketManagementController : ControllerBase +public class TicketController : ControllerBase { private readonly ITicketManagementService _ticketManagementService; - public TicketManagementController(ITicketManagementService ticketManagementService) + public TicketController(ITicketManagementService ticketManagementService) { _ticketManagementService = ticketManagementService; } diff --git a/Server/Controllers/VehicleManagementController.cs b/Server/Controllers/VehicleController.cs similarity index 94% rename from Server/Controllers/VehicleManagementController.cs rename to Server/Controllers/VehicleController.cs index 3da8158..3fa207f 100644 --- a/Server/Controllers/VehicleManagementController.cs +++ b/Server/Controllers/VehicleController.cs @@ -8,11 +8,11 @@ namespace Server.Controllers; [Route("api/vehicles")] [ApiController] -public class VehicleManagementController : ControllerBase +public class VehicleController : ControllerBase { private readonly IVehicleManagementService _vehicleManagementService; - public VehicleManagementController(IVehicleManagementService vehicleManagementService) + public VehicleController(IVehicleManagementService vehicleManagementService) { _vehicleManagementService = vehicleManagementService; } diff --git a/Server/Controllers/VehicleEnrollmentManagementController.cs b/Server/Controllers/VehicleEnrollmentController.cs similarity index 93% rename from Server/Controllers/VehicleEnrollmentManagementController.cs rename to Server/Controllers/VehicleEnrollmentController.cs index db576b1..db05c3f 100644 --- a/Server/Controllers/VehicleEnrollmentManagementController.cs +++ b/Server/Controllers/VehicleEnrollmentController.cs @@ -9,11 +9,11 @@ namespace Server.Controllers; [Route("api/vehicleEnrollments")] [ApiController] -public class VehicleEnrollmentManagementController : ControllerBase +public class VehicleEnrollmentController : ControllerBase { private readonly IVehicleEnrollmentManagementService _vehicleEnrollmentManagementService; - public VehicleEnrollmentManagementController(IVehicleEnrollmentManagementService vehicleEnrollmentManagementService) + public VehicleEnrollmentController(IVehicleEnrollmentManagementService vehicleEnrollmentManagementService) { _vehicleEnrollmentManagementService = vehicleEnrollmentManagementService; } diff --git a/SharedModels/DataTransferObjects/CompanyDto.cs b/SharedModels/DataTransferObjects/CompanyDto.cs index 1e74214..b51d803 100644 --- a/SharedModels/DataTransferObjects/CompanyDto.cs +++ b/SharedModels/DataTransferObjects/CompanyDto.cs @@ -2,12 +2,9 @@ using System.ComponentModel.DataAnnotations; namespace SharedModels.DataTransferObjects; -public class CompanyDto +public class CompanyDto : CreateCompanyDto { public int Id { get; set; } - - public string Name { get; set; } = null!; - public string OwnerId { get; set; } = null!; } public class CreateCompanyDto @@ -19,11 +16,8 @@ public class CreateCompanyDto public string OwnerId { get; set; } = null!; } -public class UpdateCompanyDto +public class UpdateCompanyDto : CreateCompanyDto { [Required] public int Id { get; set; } - - public string Name { get; set; } = null!; - public string OwnerId { get; set; } = null!; } \ No newline at end of file diff --git a/SharedModels/DataTransferObjects/ReviewDto.cs b/SharedModels/DataTransferObjects/ReviewDto.cs index d1eb431..f8b9a3e 100644 --- a/SharedModels/DataTransferObjects/ReviewDto.cs +++ b/SharedModels/DataTransferObjects/ReviewDto.cs @@ -2,11 +2,9 @@ using System.ComponentModel.DataAnnotations; namespace SharedModels.DataTransferObjects; -public class ReviewDto +public class ReviewDto : CreateReviewDto { public int Id { get; set; } - public int Rating { get; set; } - public string Comment { get; set; } = null!; } public class CreateReviewDto @@ -24,17 +22,8 @@ public class CreateReviewDto public string Comment { get; set; } = null!; } -public class UpdateReviewDto +public class UpdateReviewDto : CreateReviewDto { [Required] public int Id { get; set; } - - public string UserId { get; set; } = null!; - public int VehicleEnrollmentId { get; set; } - - [Range(0,100)] - public int Rating { get; set; } - - [MaxLength(255)] - public string Comment { get; set; } = null!; } \ No newline at end of file diff --git a/SharedModels/DataTransferObjects/RouteAddressDto.cs b/SharedModels/DataTransferObjects/RouteAddressDto.cs index 0fd6f2b..5a17060 100644 --- a/SharedModels/DataTransferObjects/RouteAddressDto.cs +++ b/SharedModels/DataTransferObjects/RouteAddressDto.cs @@ -2,18 +2,9 @@ using System.ComponentModel.DataAnnotations; namespace SharedModels.DataTransferObjects; -public class RouteAddressDto +public class RouteAddressDto : CreateRouteAddressDto { public int Id { get; set; } - public int RouteId { get; set; } - public int AddressId { get; set; } - public int Order { get; set; } - [DataType(DataType.Duration)] - public TimeSpan TimeSpanToNextCity { get; set; } - [DataType(DataType.Duration)] - public TimeSpan WaitTimeSpan { get; set; } - [DataType(DataType.Currency)] - public double CostToNextCity { get; set; } } public class CreateRouteAddressDto @@ -40,17 +31,18 @@ public class CreateRouteAddressDto public double CostToNextCity { get; set; } } -public class UpdateRouteAddressDto +public class UpdateRouteAddressDto : CreateRouteAddressDto { [Required] public int Id { get; set; } - public int RouteId { get; set; } +} + +public class InRouteRouteAddressDto +{ + public int Id { get; set; } public int AddressId { get; set; } public int Order { get; set; } - [DataType(DataType.Duration)] public TimeSpan TimeSpanToNextCity { get; set; } - [DataType(DataType.Duration)] public TimeSpan WaitTimeSpan { get; set; } - [DataType(DataType.Currency)] public double CostToNextCity { get; set; } } \ No newline at end of file diff --git a/SharedModels/DataTransferObjects/RouteDto.cs b/SharedModels/DataTransferObjects/RouteDto.cs index c34b903..7663d0f 100644 --- a/SharedModels/DataTransferObjects/RouteDto.cs +++ b/SharedModels/DataTransferObjects/RouteDto.cs @@ -2,11 +2,11 @@ using System.ComponentModel.DataAnnotations; namespace SharedModels.DataTransferObjects; -public class RouteDto +public class RouteDto : CreateRouteDto { public int Id { get; set; } - public string Type { get; set; } = null!; + public virtual IList RouteAddresses { get; set; } = null!; } public class CreateRouteDto @@ -15,10 +15,8 @@ public class CreateRouteDto public string Type { get; set; } = null!; } -public class UpdateRouteDto +public class UpdateRouteDto : CreateRouteDto { [Required] public int Id { get; set; } - - public string Type { get; set; } = null!; } \ No newline at end of file diff --git a/SharedModels/DataTransferObjects/TicketDto.cs b/SharedModels/DataTransferObjects/TicketDto.cs index 78eeea1..bd20620 100644 --- a/SharedModels/DataTransferObjects/TicketDto.cs +++ b/SharedModels/DataTransferObjects/TicketDto.cs @@ -20,11 +20,14 @@ public class CreateTicketDto public int VehicleEnrollmentId { get; set; } } -public class UpdateTicketDto : CreateTicketDto +public class UpdateTicketDto { [Required] public int Id { get; set; } + public string? UserId { get; set; } = null!; + public int? VehicleEnrollmentId { get; set; } + [DataType(DataType.DateTime)] public DateTime PurchaseDateTimeUtc { get; set; } public bool IsReturned { get; set; } = false; diff --git a/SharedModels/DataTransferObjects/VehicleDto.cs b/SharedModels/DataTransferObjects/VehicleDto.cs index 8715390..796422c 100644 --- a/SharedModels/DataTransferObjects/VehicleDto.cs +++ b/SharedModels/DataTransferObjects/VehicleDto.cs @@ -2,20 +2,9 @@ using System.ComponentModel.DataAnnotations; namespace SharedModels.DataTransferObjects; -public class VehicleDto +public class VehicleDto : CreateVehicleDto { public int Id { get; set; } - public string? Number { get; set; } - public string? Type { get; set; } - public int Capacity { get; set; } - public bool HasClimateControl { get; set; } - public bool HasWiFi { get; set; } - public bool HasWC { get; set; } - public bool HasStewardess { get; set; } - public bool HasTV { get; set; } - public bool HasOutlet { get; set; } - public bool HasBelts { get; set; } - public int CompanyId { get; set; } } public class CreateVehicleDto @@ -56,23 +45,8 @@ public class CreateVehicleDto public int CompanyId { get; set; } } -public class UpdateVehicleDto +public class UpdateVehicleDto : CreateVehicleDto { [Required] public int Id { get; set; } - - [MaxLength(8)] - public string? Number { get; set; } - public string? Type { get; set; } - - [Range(10, 100)] - public int Capacity { get; set; } - public bool HasClimateControl { get; set; } = false; - public bool HasWiFi { get; set; } = false; - public bool HasWC { get; set; } = false; - public bool HasStewardess { get; set; } = false; - public bool HasTV { get; set; } = false; - public bool HasOutlet { get; set; } = false; - public bool HasBelts { get; set; } = false; - public int CompanyId { get; set; } } \ No newline at end of file diff --git a/SharedModels/DataTransferObjects/VehicleEnrollmentDto.cs b/SharedModels/DataTransferObjects/VehicleEnrollmentDto.cs index 9d993e6..a818a4f 100644 --- a/SharedModels/DataTransferObjects/VehicleEnrollmentDto.cs +++ b/SharedModels/DataTransferObjects/VehicleEnrollmentDto.cs @@ -2,15 +2,9 @@ using System.ComponentModel.DataAnnotations; namespace SharedModels.DataTransferObjects; -public class VehicleEnrollmentDto +public class VehicleEnrollmentDto : CreateVehicleEnrollmentDto { public int Id { get; set; } - public int VehicleId { get; set; } - public int RouteId { get; set; } - public DateTime DepartureDateTimeUtc { get; set; } - public TimeSpan DelayTimeSpan { get; set; } - public bool IsCanceled {get; set; } - public string CancelationComment { get; set; } = null!; } public class CreateVehicleEnrollmentDto @@ -24,21 +18,15 @@ public class CreateVehicleEnrollmentDto [Required] [DataType(DataType.DateTime)] public DateTime DepartureDateTimeUtc { get; set; } - - public TimeSpan DelayTimeSpan { get; set; } = TimeSpan.Zero; - - public bool IsCanceled { get; set; } = false; - public string? CancelationComment { get; set; } = null!; } -public class UpdateVehicleEnrollmentDto +public class UpdateVehicleEnrollmentDto : CreateVehicleEnrollmentDto { [Required] public int Id { get; set; } - public int VehicleId { get; set; } - public int RouteId { get; set; } - public DateTime DepartureDateTimeUtc { get; set; } - public TimeSpan DelayTimeSpan { get; set; } - public bool IsCanceled {get; set; } + + public TimeSpan DelayTimeSpan { get; set; } = TimeSpan.Zero; + + public bool IsCanceled { get; set; } = false; public string CancelationComment { get; set; } = null!; } \ No newline at end of file