diff --git a/src/BSMS.API/Controllers/BusController.cs b/src/BSMS.API/Controllers/BusController.cs index 585ed35..810034e 100644 --- a/src/BSMS.API/Controllers/BusController.cs +++ b/src/BSMS.API/Controllers/BusController.cs @@ -12,12 +12,12 @@ namespace BSMS.API.Controllers; public class BusController(ISender mediator) : ControllerBase { /// - /// Create new bus with its schedule + /// Create new bus with it's schedule /// - /// Bus parameters and its schedule data - /// ID of created bus + /// Bus data and its schedule data + /// ID of the created bus [HttpPost("Create")] - public async Task> CreateBus(CreateBusCommand command) + public async Task> Create(CreateBusCommand command) { var result = await mediator.Send(command); diff --git a/src/BSMS.API/Controllers/CompanyController.cs b/src/BSMS.API/Controllers/CompanyController.cs new file mode 100644 index 0000000..a8cce5f --- /dev/null +++ b/src/BSMS.API/Controllers/CompanyController.cs @@ -0,0 +1,25 @@ +using BSMS.API.Extensions; +using BSMS.Application.Features.Company.Commands.Create; +using MediatR; +using Microsoft.AspNetCore.Mvc; + +namespace BSMS.API.Controllers; + +/// +[ApiController] +[Route("api/[controller]")] +public class CompanyController(ISender sender) : ControllerBase +{ + /// + /// Create new transport company + /// + /// Company's data + /// ID of the created company + [HttpPost("Create")] + public async Task> Create(CreateCompanyCommand command) + { + var result = await sender.Send(command); + + return result.DecideWhatToReturn(); + } +} \ No newline at end of file diff --git a/src/BSMS.API/Controllers/DriverController.cs b/src/BSMS.API/Controllers/DriverController.cs new file mode 100644 index 0000000..6aeadf3 --- /dev/null +++ b/src/BSMS.API/Controllers/DriverController.cs @@ -0,0 +1,25 @@ +using BSMS.API.Extensions; +using BSMS.Application.Features.Driver.Commands.Create; +using MediatR; +using Microsoft.AspNetCore.Mvc; + +namespace BSMS.API.Controllers; + +/// +[ApiController] +[Route("api/[controller]")] +public class DriverController(ISender mediator) : ControllerBase +{ + /// + /// Create new driver (with company and bus (both optional)) + /// + /// Driver data + /// ID of the created driver + [HttpPost("Create")] + public async Task> Create(CreateDriverCommand command) + { + var result = await mediator.Send(command); + + return result.DecideWhatToReturn(); + } +} \ No newline at end of file diff --git a/src/BSMS.API/Controllers/PassengerController.cs b/src/BSMS.API/Controllers/PassengerController.cs new file mode 100644 index 0000000..a74822f --- /dev/null +++ b/src/BSMS.API/Controllers/PassengerController.cs @@ -0,0 +1,25 @@ +using BSMS.API.Extensions; +using BSMS.Application.Features.Passenger.Commands.Create; +using MediatR; +using Microsoft.AspNetCore.Mvc; + +namespace BSMS.API.Controllers; + +/// +[ApiController] +[Route("api/[controller]")] +public class PassengerController(ISender mediator) : ControllerBase +{ + /// + /// Create new passenger + /// + /// Passenger's data + /// ID of the created passenger + [HttpPost("Create")] + public async Task> Create(CreatePassengerCommand command) + { + var result = await mediator.Send(command); + + return result.DecideWhatToReturn(); + } +} \ No newline at end of file diff --git a/src/BSMS.API/Controllers/RouteController.cs b/src/BSMS.API/Controllers/RouteController.cs index 2121df4..4b51119 100644 --- a/src/BSMS.API/Controllers/RouteController.cs +++ b/src/BSMS.API/Controllers/RouteController.cs @@ -11,10 +11,10 @@ namespace BSMS.API.Controllers; public class RouteController(ISender mediator) : ControllerBase { /// - /// create new route (with stops included) + /// Create new route (with stops included) /// /// Contains origin and destination of route and list of it's stops names - /// + /// ID of the created route [HttpPost("Create")] public async Task> Create(CreateRouteCommand command) { diff --git a/src/BSMS.Application/ApplicationRegistration.cs b/src/BSMS.Application/ApplicationRegistration.cs index 4870a4b..796f7fb 100644 --- a/src/BSMS.Application/ApplicationRegistration.cs +++ b/src/BSMS.Application/ApplicationRegistration.cs @@ -1,4 +1,8 @@ using System.Reflection; +using BSMS.Application.Features.Bus.Commands.Create; +using BSMS.Application.Features.Company.Commands.Create; +using BSMS.Application.Features.Driver.Commands.Create; +using BSMS.Application.Features.Passenger.Commands.Create; using BSMS.Application.Features.Route.Commands.Create; using BSMS.Application.Helpers; using FluentValidation; @@ -20,7 +24,18 @@ public static IServiceCollection AddApplicationServices(this IServiceCollection services.AddScoped(); services.AddMediatR(cfg => cfg.RegisterServicesFromAssembly(Assembly.GetExecutingAssembly())); - services.AddScoped, CreateRouteCommandValidator>(); + + AddValidators(services); + return services; } + + private static void AddValidators(IServiceCollection services) + { + services.AddScoped, CreateRouteCommandValidator>(); + services.AddScoped, CreateBusCommandValidator>(); + services.AddScoped, CreatePassengerCommandValidator>(); + services.AddScoped, CreateDriverCommandValidator>(); + services.AddScoped, CreateCompanyCommandValidator>(); + } } \ No newline at end of file diff --git a/src/BSMS.Application/BSMS.Application.csproj b/src/BSMS.Application/BSMS.Application.csproj index ad16b54..7264ecc 100644 --- a/src/BSMS.Application/BSMS.Application.csproj +++ b/src/BSMS.Application/BSMS.Application.csproj @@ -8,10 +8,8 @@ - - diff --git a/src/BSMS.Application/Contracts/IRouteRepository.cs b/src/BSMS.Application/Contracts/IRouteRepository.cs deleted file mode 100644 index 26d8579..0000000 --- a/src/BSMS.Application/Contracts/IRouteRepository.cs +++ /dev/null @@ -1,9 +0,0 @@ -using BSMS.Application.Contracts.Persistence; -using BSMS.Core.Entities; - -namespace BSMS.Application.Contracts; - -public interface IRouteRepository : IGenericRepository -{ - -} \ No newline at end of file diff --git a/src/BSMS.Application/Contracts/Persistence/ICompanyRepository.cs b/src/BSMS.Application/Contracts/Persistence/ICompanyRepository.cs new file mode 100644 index 0000000..fc7dc6c --- /dev/null +++ b/src/BSMS.Application/Contracts/Persistence/ICompanyRepository.cs @@ -0,0 +1,7 @@ +using BSMS.Core.Entities; + +namespace BSMS.Application.Contracts.Persistence; + +public interface ICompanyRepository : IGenericRepository +{ +} \ No newline at end of file diff --git a/src/BSMS.Application/Contracts/Persistence/IDriverRepository.cs b/src/BSMS.Application/Contracts/Persistence/IDriverRepository.cs new file mode 100644 index 0000000..4706aaf --- /dev/null +++ b/src/BSMS.Application/Contracts/Persistence/IDriverRepository.cs @@ -0,0 +1,7 @@ +using BSMS.Core.Entities; + +namespace BSMS.Application.Contracts.Persistence; + +public interface IDriverRepository : IGenericRepository +{ +} \ No newline at end of file diff --git a/src/BSMS.Application/Contracts/Persistence/IPassengerRepository.cs b/src/BSMS.Application/Contracts/Persistence/IPassengerRepository.cs new file mode 100644 index 0000000..e98bc68 --- /dev/null +++ b/src/BSMS.Application/Contracts/Persistence/IPassengerRepository.cs @@ -0,0 +1,7 @@ +using BSMS.Core.Entities; + +namespace BSMS.Application.Contracts.Persistence; + +public interface IPassengerRepository : IGenericRepository +{ +} \ No newline at end of file diff --git a/src/BSMS.Application/Contracts/Persistence/IRouteRepository.cs b/src/BSMS.Application/Contracts/Persistence/IRouteRepository.cs new file mode 100644 index 0000000..619f260 --- /dev/null +++ b/src/BSMS.Application/Contracts/Persistence/IRouteRepository.cs @@ -0,0 +1,8 @@ +using BSMS.Core.Entities; + +namespace BSMS.Application.Contracts.Persistence; + +public interface IRouteRepository : IGenericRepository +{ + +} \ No newline at end of file diff --git a/src/BSMS.Application/Features/Bus/Commands/Create/CreateBusCommandValidator.cs b/src/BSMS.Application/Features/Bus/Commands/Create/CreateBusCommandValidator.cs index 5cb82b0..e3fc58b 100644 --- a/src/BSMS.Application/Features/Bus/Commands/Create/CreateBusCommandValidator.cs +++ b/src/BSMS.Application/Features/Bus/Commands/Create/CreateBusCommandValidator.cs @@ -1,4 +1,5 @@ -using BSMS.Application.Contracts; +using BSMS.Application.Contracts.Persistence; +using BSMS.Application.Helpers; using FluentValidation; namespace BSMS.Application.Features.Bus.Commands.Create; @@ -10,6 +11,22 @@ public CreateBusCommandValidator(IRouteRepository routeRepository) { _routeRepository = routeRepository; + RuleFor(c => c.Brand) + .NotEmpty() + .Length(3, 50) + .Matches(RegexConstants.LettersOnly) + .WithMessage("{PropertyName} must consist only from letters"); + + RuleFor(c => c.Capacity) + .GreaterThanOrEqualTo(5) + .LessThanOrEqualTo(30); + + RuleFor(c => c.Number) + .NotEmpty() + .Length(3, 7) + .Matches(RegexConstants.LettersAndNumbers) + .WithMessage("{PropertyName} must consist only from letters and numbers"); + RuleFor(c => c) .MustAsync(HaveValidRoutesForSchedule) .WithMessage("Invalid routes selected"); diff --git a/src/BSMS.Application/Features/Company/Commands/Create/CreateCompanyCommandHandler.cs b/src/BSMS.Application/Features/Company/Commands/Create/CreateCompanyCommandHandler.cs new file mode 100644 index 0000000..72ab6da --- /dev/null +++ b/src/BSMS.Application/Features/Company/Commands/Create/CreateCompanyCommandHandler.cs @@ -0,0 +1,44 @@ +using System.Net; +using BSMS.Application.Contracts.Persistence; +using BSMS.Application.Extensions; +using BSMS.Application.Features.Common; +using BSMS.Application.Helpers; +using FluentValidation; +using MapsterMapper; +using MediatR; + +namespace BSMS.Application.Features.Company.Commands.Create; + +public record CreateCompanyCommand( + string Name, + string Address, + string Phone, + string Email) : IRequest>; + +public class CreateCompanyCommandHandler( + ICompanyRepository repository, + IMapper mapper, + IValidator validator, + MethodResultFactory methodResultFactory) + : IRequestHandler> +{ + public async Task> Handle(CreateCompanyCommand request, CancellationToken cancellationToken) + { + var result = methodResultFactory.Create(); + + var validationResult = await validator.ValidateAsync(request, cancellationToken); + if (!validationResult.IsValid) + { + result.SetError(validationResult.Errors.ToResponse(), HttpStatusCode.BadRequest); + return result; + } + + var company = mapper.Map(request); + + await repository.InsertAsync(company); + + result.Data = new CreatedEntityResponse(company.CompanyId); + + return result; + } +} \ No newline at end of file diff --git a/src/BSMS.Application/Features/Company/Commands/Create/CreateCompanyCommandValidator.cs b/src/BSMS.Application/Features/Company/Commands/Create/CreateCompanyCommandValidator.cs new file mode 100644 index 0000000..53bc8b2 --- /dev/null +++ b/src/BSMS.Application/Features/Company/Commands/Create/CreateCompanyCommandValidator.cs @@ -0,0 +1,28 @@ +using BSMS.Application.Helpers; +using FluentValidation; + +namespace BSMS.Application.Features.Company.Commands.Create; + +public class CreateCompanyCommandValidator : AbstractValidator +{ + public CreateCompanyCommandValidator() + { + RuleFor(c => c.Name) + .NotEmpty() + .NotNull() + .Length(3, 50) + .Matches(RegexConstants.LettersOnly) + .WithMessage("{PropertyName} must consist only from letters"); + + RuleFor(c => c.Phone) + .NotEmpty() + .Matches(RegexConstants.PhoneNumber) + .WithMessage("Invalid phone number format"); + + RuleFor(c => c.Email) + .NotEmpty() + .MaximumLength(50) + .Matches(RegexConstants.Email) + .WithMessage("Invalid email format"); + } +} \ No newline at end of file diff --git a/src/BSMS.Application/Features/Driver/Commands/Create/CreateDriverCommandHandler.cs b/src/BSMS.Application/Features/Driver/Commands/Create/CreateDriverCommandHandler.cs new file mode 100644 index 0000000..763a9c4 --- /dev/null +++ b/src/BSMS.Application/Features/Driver/Commands/Create/CreateDriverCommandHandler.cs @@ -0,0 +1,44 @@ +using System.Net; +using BSMS.Application.Contracts.Persistence; +using BSMS.Application.Extensions; +using BSMS.Application.Features.Common; +using BSMS.Application.Helpers; +using FluentValidation; +using MapsterMapper; +using MediatR; + +namespace BSMS.Application.Features.Driver.Commands.Create; + +public record CreateDriverCommand( + string FirstName, + string LastName, + string DriverLicense, + int? CompanyId, + int? BusId) : IRequest>; + +public class CreateDriverCommandHandler( + IDriverRepository repository, + IMapper mapper, + IValidator validator, + MethodResultFactory methodResultFactory) : IRequestHandler> +{ + public async Task> Handle(CreateDriverCommand request, CancellationToken cancellationToken) + { + var result = methodResultFactory.Create(); + + var validationResult = await validator.ValidateAsync(request, cancellationToken); + if (!validationResult.IsValid) + { + result.SetError(validationResult.Errors.ToResponse(), HttpStatusCode.BadRequest); + return result; + } + + var driver = mapper.Map(request); + + await repository.InsertAsync(driver); + + result.Data = new CreatedEntityResponse(driver.DriverId); + + return result; + } +} \ No newline at end of file diff --git a/src/BSMS.Application/Features/Driver/Commands/Create/CreateDriverCommandValidator.cs b/src/BSMS.Application/Features/Driver/Commands/Create/CreateDriverCommandValidator.cs new file mode 100644 index 0000000..f489f76 --- /dev/null +++ b/src/BSMS.Application/Features/Driver/Commands/Create/CreateDriverCommandValidator.cs @@ -0,0 +1,52 @@ +using BSMS.Application.Contracts.Persistence; +using BSMS.Application.Helpers; +using FluentValidation; + +namespace BSMS.Application.Features.Driver.Commands.Create; + +public class CreateDriverCommandValidator : AbstractValidator +{ + private readonly ICompanyRepository _companyRepository; + private readonly IBusRepository _busRepository; + public CreateDriverCommandValidator(ICompanyRepository companyRepository, IBusRepository busRepository) + { + _companyRepository = companyRepository; + _busRepository = busRepository; + + RuleFor(c => c.FirstName) + .NotEmpty() + .NotNull() + .Length(3, 50) + .Matches(RegexConstants.LettersOnly) + .WithMessage("{PropertyName} must consist only from letters"); + + RuleFor(c => c.LastName) + .NotEmpty() + .NotNull() + .Length(3, 50) + .Matches(RegexConstants.LettersOnly) + .WithMessage("{PropertyName} must consist only from letters"); + + RuleFor(x => x.DriverLicense) + .Matches(RegexConstants.DriverLicense) + .WithMessage("Invalid driver license format"); + + RuleFor(c => c.CompanyId) + .MustAsync(CompanyExists) + .WithMessage("Chosen company must exist!"); + + RuleFor(c => c.BusId) + .MustAsync(BusExists) + .WithMessage("Chosen bus must exist!"); + } + + private Task CompanyExists(int? companyId, CancellationToken cancellationToken) + { + return companyId is not null ? _companyRepository.AnyAsync(c => c.CompanyId == companyId) : Task.FromResult(true); + } + + private Task BusExists(int? busId, CancellationToken cancellationToken) + { + return busId is not null ? _busRepository.AnyAsync(b => b.BusId == busId) : Task.FromResult(true); + } +} \ No newline at end of file diff --git a/src/BSMS.Application/Features/Passenger/Commands/Create/CreatePassengerCommandHandler.cs b/src/BSMS.Application/Features/Passenger/Commands/Create/CreatePassengerCommandHandler.cs new file mode 100644 index 0000000..0e3a8b1 --- /dev/null +++ b/src/BSMS.Application/Features/Passenger/Commands/Create/CreatePassengerCommandHandler.cs @@ -0,0 +1,43 @@ +using System.Net; +using BSMS.Application.Contracts.Persistence; +using BSMS.Application.Extensions; +using BSMS.Application.Features.Common; +using BSMS.Application.Helpers; +using FluentValidation; +using MapsterMapper; +using MediatR; + +namespace BSMS.Application.Features.Passenger.Commands.Create; + +public record CreatePassengerCommand( + string FirstName, + string LastName, + string PhoneNumber, + string Email) : IRequest>; + +public class CreatePassengerCommandHandler( + IPassengerRepository passengerRepository, + IValidator validator, + IMapper mapper, + MethodResultFactory methodResultFactory) : IRequestHandler> +{ + public async Task> Handle(CreatePassengerCommand request, CancellationToken cancellationToken) + { + var result = methodResultFactory.Create(); + + var validationResult = await validator.ValidateAsync(request, cancellationToken); + if (!validationResult.IsValid) + { + result.SetError(validationResult.Errors.ToResponse(), HttpStatusCode.BadRequest); + return result; + } + + var passenger = mapper.Map(request); + + await passengerRepository.InsertAsync(passenger); + + result.Data = new CreatedEntityResponse(passenger.PassengerId); + + return result; + } +} \ No newline at end of file diff --git a/src/BSMS.Application/Features/Passenger/Commands/Create/CreatePassengerCommandValidator.cs b/src/BSMS.Application/Features/Passenger/Commands/Create/CreatePassengerCommandValidator.cs new file mode 100644 index 0000000..414a860 --- /dev/null +++ b/src/BSMS.Application/Features/Passenger/Commands/Create/CreatePassengerCommandValidator.cs @@ -0,0 +1,34 @@ +using BSMS.Application.Helpers; +using FluentValidation; + +namespace BSMS.Application.Features.Passenger.Commands.Create; + +public class CreatePassengerCommandValidator : AbstractValidator +{ + public CreatePassengerCommandValidator() + { + RuleFor(c => c.FirstName) + .NotEmpty() + .NotNull() + .Length(3, 50) + .Matches(RegexConstants.LettersOnly) + .WithMessage("{PropertyName} must consist only from letters"); + + RuleFor(c => c.LastName) + .NotEmpty() + .NotNull() + .Length(3, 50) + .Matches(RegexConstants.LettersOnly) + .WithMessage("{PropertyName} must consist only from letters"); + + RuleFor(c => c.PhoneNumber) + .NotEmpty() + .Matches(RegexConstants.PhoneNumber) + .WithMessage("Invalid phone number format"); + + RuleFor(c => c.Email) + .NotEmpty() + .MaximumLength(50) + .Matches(RegexConstants.Email).WithMessage("Invalid email format"); + } +} \ No newline at end of file diff --git a/src/BSMS.Application/Features/Route/Commands/Create/CreateRouteCommandHandler.cs b/src/BSMS.Application/Features/Route/Commands/Create/CreateRouteCommandHandler.cs index 86b26ad..2f750d4 100644 --- a/src/BSMS.Application/Features/Route/Commands/Create/CreateRouteCommandHandler.cs +++ b/src/BSMS.Application/Features/Route/Commands/Create/CreateRouteCommandHandler.cs @@ -1,5 +1,6 @@ using System.Net; using BSMS.Application.Contracts; +using BSMS.Application.Contracts.Persistence; using BSMS.Application.Extensions; using BSMS.Application.Features.Common; using BSMS.Application.Helpers; diff --git a/src/BSMS.Application/Features/Route/Commands/Create/CreateRouteCommandValidator.cs b/src/BSMS.Application/Features/Route/Commands/Create/CreateRouteCommandValidator.cs index d729e76..b305d29 100644 --- a/src/BSMS.Application/Features/Route/Commands/Create/CreateRouteCommandValidator.cs +++ b/src/BSMS.Application/Features/Route/Commands/Create/CreateRouteCommandValidator.cs @@ -8,13 +8,11 @@ public CreateRouteCommandValidator() { RuleFor(c => c.Origin) .NotNull() - .NotEmpty() - .WithMessage("Origin cannot be empty"); + .NotEmpty(); RuleFor(c => c.Destination) .NotNull() - .NotEmpty() - .WithMessage("Destination cannot be empty"); + .NotEmpty(); RuleFor(command => command) .Must(HaveValidPath) diff --git a/src/BSMS.Application/Helpers/RegexConstants.cs b/src/BSMS.Application/Helpers/RegexConstants.cs new file mode 100644 index 0000000..2bbb908 --- /dev/null +++ b/src/BSMS.Application/Helpers/RegexConstants.cs @@ -0,0 +1,10 @@ +namespace BSMS.Application.Helpers; + +public static class RegexConstants +{ + public const string LettersOnly = @"^[a-zA-Z]+$"; + public const string LettersAndNumbers = @"^[a-zA-Z0-9]+$"; + public const string PhoneNumber = @"^\+?(\d[\d-. ]+)?(\([\d-. ]+\))?[\d-. ]+\d$"; + public const string Email = @"^[\w-]+(\.[\w-]+)*@([\w-]+\.)+[a-zA-Z]{2,7}$"; + public const string DriverLicense = @"^[A-Z0-9]{5}-[A-Z0-9]{5}-[A-Z0-9]{5}-[A-Z0-9]{5}$"; +} \ No newline at end of file diff --git a/src/BSMS.Application/MappingProfiles/CompanyProfile.cs b/src/BSMS.Application/MappingProfiles/CompanyProfile.cs new file mode 100644 index 0000000..d6a4144 --- /dev/null +++ b/src/BSMS.Application/MappingProfiles/CompanyProfile.cs @@ -0,0 +1,15 @@ +using BSMS.Application.Features.Company.Commands.Create; +using BSMS.Core.Entities; +using Mapster; + +namespace BSMS.Application.MappingProfiles; + +public class CompanyProfile : IRegister +{ + public void Register(TypeAdapterConfig config) + { + config.NewConfig() + .Map(dest => dest.ContactPhone, src => src.Phone) + .Map(dest => dest.ContactEmail, src => src.Email); + } +} \ No newline at end of file diff --git a/src/BSMS.Application/MappingProfiles/RouteProfile.cs b/src/BSMS.Application/MappingProfiles/RouteProfile.cs index 7e46fe7..5b46c31 100644 --- a/src/BSMS.Application/MappingProfiles/RouteProfile.cs +++ b/src/BSMS.Application/MappingProfiles/RouteProfile.cs @@ -10,7 +10,7 @@ public void Register(TypeAdapterConfig config) { config.NewConfig() .Map(dest => dest.Stops, src => src.StopsList) - .AfterMapping((src, dest) => + .AfterMapping((_, dest) => { // assign stops order if (dest.Stops.Count > 1) diff --git a/src/BSMS.Infrastructure/Persistence/Repositories/CompanyRepository.cs b/src/BSMS.Infrastructure/Persistence/Repositories/CompanyRepository.cs new file mode 100644 index 0000000..4c886c1 --- /dev/null +++ b/src/BSMS.Infrastructure/Persistence/Repositories/CompanyRepository.cs @@ -0,0 +1,11 @@ +using BSMS.Application.Contracts.Persistence; +using BSMS.Core.Entities; + +namespace BSMS.Infrastructure.Persistence.Repositories; + +public class CompanyRepository : GenericRepository, ICompanyRepository +{ + public CompanyRepository(BusStationContext context) : base(context) + { + } +} \ No newline at end of file diff --git a/src/BSMS.Infrastructure/Persistence/Repositories/DriverRepository.cs b/src/BSMS.Infrastructure/Persistence/Repositories/DriverRepository.cs new file mode 100644 index 0000000..eed5164 --- /dev/null +++ b/src/BSMS.Infrastructure/Persistence/Repositories/DriverRepository.cs @@ -0,0 +1,11 @@ +using BSMS.Application.Contracts.Persistence; +using BSMS.Core.Entities; + +namespace BSMS.Infrastructure.Persistence.Repositories; + +public class DriverRepository : GenericRepository, IDriverRepository +{ + public DriverRepository(BusStationContext context) : base(context) + { + } +} \ No newline at end of file diff --git a/src/BSMS.Infrastructure/Persistence/Repositories/PassengerRepository.cs b/src/BSMS.Infrastructure/Persistence/Repositories/PassengerRepository.cs new file mode 100644 index 0000000..c8b34cd --- /dev/null +++ b/src/BSMS.Infrastructure/Persistence/Repositories/PassengerRepository.cs @@ -0,0 +1,11 @@ +using BSMS.Application.Contracts.Persistence; +using BSMS.Core.Entities; + +namespace BSMS.Infrastructure.Persistence.Repositories; + +public class PassengerRepository : GenericRepository, IPassengerRepository +{ + public PassengerRepository(BusStationContext context) : base(context) + { + } +} \ No newline at end of file diff --git a/src/BSMS.Infrastructure/Persistence/Repositories/RouteRepository.cs b/src/BSMS.Infrastructure/Persistence/Repositories/RouteRepository.cs index 3cc97bb..48af23e 100644 --- a/src/BSMS.Infrastructure/Persistence/Repositories/RouteRepository.cs +++ b/src/BSMS.Infrastructure/Persistence/Repositories/RouteRepository.cs @@ -1,4 +1,4 @@ -using BSMS.Application.Contracts; +using BSMS.Application.Contracts.Persistence; using BSMS.Core.Entities; namespace BSMS.Infrastructure.Persistence.Repositories; diff --git a/src/BSMS.Infrastructure/PersistenceRegistration.cs b/src/BSMS.Infrastructure/PersistenceRegistration.cs index dad4dc7..93728d9 100644 --- a/src/BSMS.Infrastructure/PersistenceRegistration.cs +++ b/src/BSMS.Infrastructure/PersistenceRegistration.cs @@ -1,5 +1,4 @@ -using BSMS.Application.Contracts; -using BSMS.Application.Contracts.Persistence; +using BSMS.Application.Contracts.Persistence; using BSMS.Infrastructure.Persistence; using BSMS.Infrastructure.Persistence.Repositories; using Microsoft.EntityFrameworkCore; @@ -17,10 +16,18 @@ public static IServiceCollection AddPersistenceServices(this IServiceCollection opt.UseSqlServer(configuration.GetConnectionString("DefaultLocal")); }); + AddRepositories(services); + + return services; + } + + private static void AddRepositories(IServiceCollection services) + { services.AddScoped(typeof(IGenericRepository<>), typeof(GenericRepository<>)); services.AddScoped(); services.AddScoped(); - - return services; + services.AddScoped(); + services.AddScoped(); + services.AddScoped(); } } \ No newline at end of file