file-scoped namespaces
This commit is contained in:
		| @@ -3,12 +3,12 @@ using ApplicationLayer.InfrastructureServicesInterfaces; | ||||
| using ApplicationLayer.Services.AuthServices.NeededServices; | ||||
| using Microsoft.Extensions.DependencyInjection; | ||||
|  | ||||
| namespace Infrastructure.Auth | ||||
| namespace Infrastructure.Auth; | ||||
|  | ||||
| public static class ServiceCollectionsExtensions | ||||
| { | ||||
|     public static class ServiceCollectionsExtensions | ||||
|     public static IServiceCollection AddTokenGenerator(this IServiceCollection services, TokenGeneratorOptions options) | ||||
|     { | ||||
|         public static IServiceCollection AddTokenGenerator(this IServiceCollection services, TokenGeneratorOptions options) | ||||
|         { | ||||
|             services.AddSingleton<JwtSecurityTokenHandler>(); | ||||
|             services.AddSingleton<ITokenGenerator, TokenGenerator>(provider => | ||||
|             { | ||||
| @@ -20,5 +20,4 @@ namespace Infrastructure.Auth | ||||
|  | ||||
|             return services; | ||||
|         } | ||||
|     } | ||||
| } | ||||
| } | ||||
| @@ -4,27 +4,26 @@ using ApplicationLayer.InfrastructureServicesInterfaces; | ||||
| using ApplicationLayer.Services.AuthServices.NeededServices; | ||||
| using Domains.Users; | ||||
|  | ||||
| namespace Infrastructure.Auth | ||||
| namespace Infrastructure.Auth; | ||||
|  | ||||
| public class TokenGenerator(TokenGeneratorOptions options, JwtSecurityTokenHandler tokenHandler, IDateTimeProvider dateTimeProvider) | ||||
|     : ITokenGenerator | ||||
| { | ||||
|     public class TokenGenerator(TokenGeneratorOptions options, JwtSecurityTokenHandler tokenHandler, IDateTimeProvider dateTimeProvider) | ||||
|         : ITokenGenerator | ||||
|     public string CreateToken(User user) | ||||
|     { | ||||
|         public string CreateToken(User user) | ||||
|         var claims = new List<Claim> | ||||
|         { | ||||
|             var claims = new List<Claim> | ||||
|             { | ||||
|                 new(ClaimTypes.Role, user.Role.ToString()), | ||||
|                 new(ClaimTypes.NameIdentifier, user.Id.ToString()) | ||||
|             }; | ||||
|             new(ClaimTypes.Role, user.Role.ToString()), | ||||
|             new(ClaimTypes.NameIdentifier, user.Id.ToString()) | ||||
|         }; | ||||
|  | ||||
|             var token = new JwtSecurityToken( | ||||
|                 issuer: options.Issuer, | ||||
|                 audience: options.Audience, | ||||
|                 expires: dateTimeProvider.Now().Add(options.ValidTime), | ||||
|                 signingCredentials: options.Credentials, | ||||
|                 claims: claims); | ||||
|         var token = new JwtSecurityToken( | ||||
|             issuer: options.Issuer, | ||||
|             audience: options.Audience, | ||||
|             expires: dateTimeProvider.Now().Add(options.ValidTime), | ||||
|             signingCredentials: options.Credentials, | ||||
|             claims: claims); | ||||
|  | ||||
|             return tokenHandler.WriteToken(token); | ||||
|         } | ||||
|         return tokenHandler.WriteToken(token); | ||||
|     } | ||||
| } | ||||
| } | ||||
| @@ -1,6 +1,5 @@ | ||||
| using Microsoft.IdentityModel.Tokens; | ||||
|  | ||||
| namespace Infrastructure.Auth | ||||
| { | ||||
|     public record TokenGeneratorOptions(string Issuer, string Audience, TimeSpan ValidTime, SigningCredentials Credentials); | ||||
| } | ||||
| namespace Infrastructure.Auth; | ||||
|  | ||||
| public record TokenGeneratorOptions(string Issuer, string Audience, TimeSpan ValidTime, SigningCredentials Credentials); | ||||
| @@ -3,12 +3,12 @@ using ApplicationLayer.Services.AuthServices.Requests; | ||||
| using AutoMapper; | ||||
| using Domains.ApplicantDomain; | ||||
|  | ||||
| namespace Infrastructure.Automapper.Profiles | ||||
| namespace Infrastructure.Automapper.Profiles; | ||||
|  | ||||
| public class ApplicantProfile : Profile | ||||
| { | ||||
|     public class ApplicantProfile : Profile | ||||
|     public ApplicantProfile() | ||||
|     { | ||||
|         public ApplicantProfile() | ||||
|         { | ||||
|             CreateMap<Applicant, ApplicantModel>(MemberList.Destination); | ||||
|  | ||||
|             CreateMap<RegisterApplicantRequest, Applicant>(MemberList.Destination) | ||||
| @@ -16,5 +16,4 @@ namespace Infrastructure.Automapper.Profiles | ||||
|                 .ForMember(a => a.Name, | ||||
|                     opts => opts.MapFrom(r => r.ApplicantName)); | ||||
|         } | ||||
|     } | ||||
| } | ||||
| } | ||||
| @@ -2,15 +2,14 @@ | ||||
| using AutoMapper; | ||||
| using Domains.ApplicantDomain; | ||||
|  | ||||
| namespace Infrastructure.Automapper.Profiles | ||||
| namespace Infrastructure.Automapper.Profiles; | ||||
|  | ||||
| public class PlaceOfWorkProfile : Profile | ||||
| { | ||||
|     public class PlaceOfWorkProfile : Profile | ||||
|     public PlaceOfWorkProfile() | ||||
|     { | ||||
|         public PlaceOfWorkProfile() | ||||
|         { | ||||
|             CreateMap<PlaceOfWorkModel, PlaceOfWork>(MemberList.Destination) | ||||
|                 .ForMember(p => p.Id, | ||||
|                     opts => opts.UseDestinationValue()); | ||||
|         } | ||||
|     } | ||||
| } | ||||
| } | ||||
| @@ -2,15 +2,14 @@ | ||||
| using AutoMapper; | ||||
| using Domains.Users; | ||||
|  | ||||
| namespace Infrastructure.Automapper.Profiles | ||||
| namespace Infrastructure.Automapper.Profiles; | ||||
|  | ||||
| public class UserProfile : Profile | ||||
| { | ||||
|     public class UserProfile : Profile | ||||
|     public UserProfile() | ||||
|     { | ||||
|         public UserProfile() | ||||
|         { | ||||
|             CreateMap<AuthData, User>(MemberList.Destination) | ||||
|                 .ForMember(u => u.Role, | ||||
|                     opts => opts.Ignore()); | ||||
|         } | ||||
|     } | ||||
| } | ||||
| } | ||||
| @@ -3,12 +3,12 @@ using ApplicationLayer.Services.VisaApplications.Requests; | ||||
| using AutoMapper; | ||||
| using Domains.VisaApplicationDomain; | ||||
|  | ||||
| namespace Infrastructure.Automapper.Profiles | ||||
| namespace Infrastructure.Automapper.Profiles; | ||||
|  | ||||
| public class VisaApplicationProfile : Profile | ||||
| { | ||||
|     public class VisaApplicationProfile : Profile | ||||
|     public VisaApplicationProfile() | ||||
|     { | ||||
|         public VisaApplicationProfile() | ||||
|         { | ||||
|             CreateMap<VisaApplication, VisaApplicationModelForApplicant>(MemberList.Destination); | ||||
|  | ||||
|             CreateMap<VisaApplication, VisaApplicationModelForAuthority>(MemberList.Destination) | ||||
| @@ -21,5 +21,4 @@ namespace Infrastructure.Automapper.Profiles | ||||
|                 .ForMember(va => va.ApplicantId, | ||||
|                 opts => opts.Ignore()); | ||||
|         } | ||||
|     } | ||||
| } | ||||
| } | ||||
| @@ -1,10 +1,9 @@ | ||||
| using ApplicationLayer.InfrastructureServicesInterfaces; | ||||
|  | ||||
| namespace Infrastructure.Common | ||||
| namespace Infrastructure.Common; | ||||
|  | ||||
| /// Implements <see cref="IDateTimeProvider"/> | ||||
| public class DateTimeProvider : IDateTimeProvider | ||||
| { | ||||
|     /// Implements <see cref="IDateTimeProvider"/> | ||||
|     public class DateTimeProvider : IDateTimeProvider | ||||
|     { | ||||
|         DateTime IDateTimeProvider.Now() => DateTime.Now; | ||||
|     } | ||||
| } | ||||
|     DateTime IDateTimeProvider.Now() => DateTime.Now; | ||||
| } | ||||
| @@ -2,12 +2,12 @@ | ||||
| using ApplicationLayer.InfrastructureServicesInterfaces; | ||||
| using Microsoft.AspNetCore.Http; | ||||
|  | ||||
| namespace Infrastructure.Common | ||||
| namespace Infrastructure.Common; | ||||
|  | ||||
| public class UserIdProvider(IHttpContextAccessor contextAccessor) : IUserIdProvider | ||||
| { | ||||
|     public class UserIdProvider(IHttpContextAccessor contextAccessor) : IUserIdProvider | ||||
|     Guid IUserIdProvider.GetUserId() | ||||
|     { | ||||
|         Guid IUserIdProvider.GetUserId() | ||||
|         { | ||||
|             var claim = contextAccessor.HttpContext!.User.Claims.SingleOrDefault(claim => claim.Type == ClaimTypes.NameIdentifier); | ||||
|             if (claim is null) | ||||
|             { | ||||
| @@ -15,5 +15,4 @@ namespace Infrastructure.Common | ||||
|             } | ||||
|             return Guid.Parse(claim.Value); | ||||
|         } | ||||
|     } | ||||
| } | ||||
| } | ||||
| @@ -1,6 +1,5 @@ | ||||
| using ApplicationLayer.Services.GeneralExceptions; | ||||
|  | ||||
| namespace Infrastructure.Database.Applicants.Repositories.Exceptions | ||||
| { | ||||
|     public class ApplicantNotFoundByUserIdException() : EntityNotFoundException("Applicant not found."); | ||||
| } | ||||
| namespace Infrastructure.Database.Applicants.Repositories.Exceptions; | ||||
|  | ||||
| public class ApplicantNotFoundByUserIdException() : EntityNotFoundException("Applicant not found."); | ||||
|   | ||||
| @@ -3,12 +3,12 @@ using Domains.Users; | ||||
| using Microsoft.EntityFrameworkCore; | ||||
| using Microsoft.EntityFrameworkCore.Metadata.Builders; | ||||
|  | ||||
| namespace Infrastructure.Database.Users.Configuration | ||||
| namespace Infrastructure.Database.Users.Configuration; | ||||
|  | ||||
| public class UserConfiguration : IEntityTypeConfiguration<User> | ||||
| { | ||||
|     public class UserConfiguration : IEntityTypeConfiguration<User> | ||||
|     public void Configure(EntityTypeBuilder<User> entity) | ||||
|     { | ||||
|         public void Configure(EntityTypeBuilder<User> entity) | ||||
|         { | ||||
|             entity.Property(u => u.Email) | ||||
|                 .IsUnicode(false) | ||||
|                 .HasMaxLength(ConfigurationConstraints.EmailLength); | ||||
| @@ -19,5 +19,4 @@ namespace Infrastructure.Database.Users.Configuration | ||||
|                 .IsUnicode(false) | ||||
|                 .HasMaxLength(ConfigurationConstraints.PasswordLength); | ||||
|         } | ||||
|     } | ||||
| } | ||||
| } | ||||
| @@ -3,20 +3,19 @@ using Domains.Users; | ||||
| using Infrastructure.Database.Generic; | ||||
| using Microsoft.EntityFrameworkCore; | ||||
|  | ||||
| namespace Infrastructure.Database.Users.Repositories | ||||
| namespace Infrastructure.Database.Users.Repositories; | ||||
|  | ||||
| /// <inheritdoc cref="IUsersRepository"/> | ||||
| public class UsersRepository(IGenericReader reader, IGenericWriter writer) | ||||
|     : GenericRepository<User>(reader, writer), IUsersRepository | ||||
| { | ||||
|     /// <inheritdoc cref="IUsersRepository"/> | ||||
|     public class UsersRepository(IGenericReader reader, IGenericWriter writer) | ||||
|         : GenericRepository<User>(reader, writer), IUsersRepository | ||||
|     async Task<User?> IUsersRepository.FindByEmailAsync(string email, CancellationToken cancellationToken) | ||||
|     { | ||||
|         async Task<User?> IUsersRepository.FindByEmailAsync(string email, CancellationToken cancellationToken) | ||||
|         { | ||||
|             return await LoadDomain().SingleOrDefaultAsync(u => u.Email == email, cancellationToken); | ||||
|         } | ||||
|  | ||||
|         async Task<List<User>> IUsersRepository.GetAllOfRoleAsync(Role role, CancellationToken cancellationToken) | ||||
|         { | ||||
|     async Task<List<User>> IUsersRepository.GetAllOfRoleAsync(Role role, CancellationToken cancellationToken) | ||||
|     { | ||||
|             return await LoadDomain().Where(u => u.Role == role).ToListAsync(cancellationToken); | ||||
|         } | ||||
|     } | ||||
| } | ||||
| } | ||||
| @@ -2,15 +2,14 @@ | ||||
| using Domains.VisaApplicationDomain; | ||||
| using Microsoft.EntityFrameworkCore.Metadata.Builders; | ||||
|  | ||||
| namespace Infrastructure.Database.VisaApplications.Configuration | ||||
| namespace Infrastructure.Database.VisaApplications.Configuration; | ||||
|  | ||||
| public static class PastVisitConfiguration<T> where T : class, IEntity | ||||
| { | ||||
|     public static class PastVisitConfiguration<T> where T : class, IEntity | ||||
|     public static void Configure(OwnedNavigationBuilder<T, PastVisit> entity) | ||||
|     { | ||||
|         public static void Configure(OwnedNavigationBuilder<T, PastVisit> entity) | ||||
|         { | ||||
|             entity.Property(pv => pv.DestinationCountry) | ||||
|                 .IsUnicode(false) | ||||
|                 .HasMaxLength(ConfigurationConstraints.CountryNameLength); | ||||
|         } | ||||
|     } | ||||
| } | ||||
| } | ||||
| @@ -1,7 +1,6 @@ | ||||
| using ApplicationLayer.Services.GeneralExceptions; | ||||
|  | ||||
| namespace Infrastructure.Database.VisaApplications.Repositories.Exceptions | ||||
| { | ||||
|     public class ApplicationNotFoundByApplicantAndApplicationIdException(Guid applicationId) | ||||
|         : EntityNotFoundException($"Application with id {applicationId} not found for authenticated user"); | ||||
| } | ||||
| namespace Infrastructure.Database.VisaApplications.Repositories.Exceptions; | ||||
|  | ||||
| public class ApplicationNotFoundByApplicantAndApplicationIdException(Guid applicationId) | ||||
|     : EntityNotFoundException($"Application with id {applicationId} not found for authenticated user"); | ||||
		Reference in New Issue
	
	Block a user