Skip to content

Commit

Permalink
Remove block scoped namespace
Browse files Browse the repository at this point in the history
  • Loading branch information
vanderlan committed Oct 14, 2023
1 parent a56c173 commit b6985ce
Show file tree
Hide file tree
Showing 83 changed files with 2,429 additions and 2,512 deletions.
11 changes: 5 additions & 6 deletions src/Orion.Api/Attributes/AuthorizeForAttribute.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
using Microsoft.AspNetCore.Authorization;

namespace Orion.Api.Attributes
namespace Orion.Api.Attributes;

public class AuthorizeForAttribute : AuthorizeAttribute
{
public class AuthorizeForAttribute : AuthorizeAttribute
public AuthorizeForAttribute(params string[] roles)
{
public AuthorizeForAttribute(params string[] roles)
{
Roles = string.Join(",", roles);
}
Roles = string.Join(",", roles);
}
}
41 changes: 20 additions & 21 deletions src/Orion.Api/Attributes/CustomValidationAttribute.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,32 +3,31 @@
using Orion.Domain.Exceptions;
using System.Text.Json;

namespace Orion.Api.Attributes
namespace Orion.Api.Attributes;

/// <summary>
/// This filter changes the FluentValidation default response
/// </summary>
public class CustomValidationAttribute : ActionFilterAttribute
{
/// <summary>
/// This filter changes the FluentValidation default response
/// </summary>
public class CustomValidationAttribute : ActionFilterAttribute
public override void OnActionExecuting(ActionExecutingContext context)
{
public override void OnActionExecuting(ActionExecutingContext context)
if (!context.ModelState.IsValid)
{
if (!context.ModelState.IsValid)
{
var errors = context.ModelState.Values.Where(v => v.Errors.Count > 0)
.SelectMany(v => v.Errors)
.Select(v => v.ErrorMessage)
.ToArray();
var errors = context.ModelState.Values.Where(v => v.Errors.Count > 0)
.SelectMany(v => v.Errors)
.Select(v => v.ErrorMessage)
.ToArray();

var response = new ExceptionResponse(errors, NotificationType.Error)
{
Title = "Validation Error"
};
var response = new ExceptionResponse(errors, NotificationType.Error)
{
Title = "Validation Error"
};

context.Result = new JsonResult(response, new JsonSerializerOptions())
{
StatusCode = StatusCodes.Status400BadRequest
};
}
context.Result = new JsonResult(response, new JsonSerializerOptions())
{
StatusCode = StatusCodes.Status400BadRequest
};
}
}
}
19 changes: 9 additions & 10 deletions src/Orion.Api/AutoMapper/AutoMapperConfiguration.cs
Original file line number Diff line number Diff line change
@@ -1,19 +1,18 @@
using AutoMapper;
using Orion.Api.AutoMapper.Config;

namespace Orion.Api.AutoMapper
namespace Orion.Api.AutoMapper;

public static class AutoMapperConfiguration
{
public static class AutoMapperConfiguration
public static void ConfigureAutoMapper(this IServiceCollection services)
{
public static void ConfigureAutoMapper(this IServiceCollection services)
var mappingConfig = new MapperConfiguration(mc =>
{
var mappingConfig = new MapperConfiguration(mc =>
{
mc.AddProfile(new InputToDomainProfile());
mc.AddProfile(new DomainToOutputProfile());
});
mc.AddProfile(new InputToDomainProfile());
mc.AddProfile(new DomainToOutputProfile());
});

services.AddScoped(_ => mappingConfig.CreateMapper());
}
services.AddScoped(_ => mappingConfig.CreateMapper());
}
}
19 changes: 9 additions & 10 deletions src/Orion.Api/AutoMapper/Config/DomainToOutputProfile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,17 @@
using Orion.Domain.Entities;
using Orion.Domain.Entities.ValueObjects.Pagination;

namespace Orion.Api.AutoMapper.Config
namespace Orion.Api.AutoMapper.Config;

public class DomainToOutputProfile : Profile
{
public class DomainToOutputProfile : Profile
public DomainToOutputProfile()
{
public DomainToOutputProfile()
{
CreateMap<Customer, CustomerOutput>();
CreateMap<PagedList<Customer>, PagedList<CustomerOutput>>();
CreateMap<PagedList<User>, PagedList<UserOutput>>();
CreateMap<Customer, CustomerOutput>();
CreateMap<PagedList<Customer>, PagedList<CustomerOutput>>();
CreateMap<PagedList<User>, PagedList<UserOutput>>();

CreateMap<User, UserOutput>()
.ForMember(x => x.ProfileDescription, opt => opt.Ignore());
}
CreateMap<User, UserOutput>()
.ForMember(x => x.ProfileDescription, opt => opt.Ignore());
}
}
25 changes: 12 additions & 13 deletions src/Orion.Api/AutoMapper/Config/InputToDomainProfile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,20 @@
using Orion.Api.AutoMapper.Input;
using Orion.Domain.Entities;

namespace Orion.Api.AutoMapper.Config
namespace Orion.Api.AutoMapper.Config;

public class InputToDomainProfile : Profile
{
public class InputToDomainProfile : Profile
public InputToDomainProfile()
{
public InputToDomainProfile()
{
CreateMap<CustomerInput, Customer>()
.ForMember(x => x.CustomerId, opt => opt.Ignore())
.ForMember(x => x.LastUpdated, opt => opt.Ignore())
.ForMember(x => x.CreatedAt, opt => opt.Ignore());
CreateMap<CustomerInput, Customer>()
.ForMember(x => x.CustomerId, opt => opt.Ignore())
.ForMember(x => x.LastUpdated, opt => opt.Ignore())
.ForMember(x => x.CreatedAt, opt => opt.Ignore());

CreateMap<UserInput, User>()
.ForMember(x => x.UserId, opt => opt.Ignore())
.ForMember(x => x.LastUpdated, opt => opt.Ignore())
.ForMember(x => x.CreatedAt, opt => opt.Ignore());
}
CreateMap<UserInput, User>()
.ForMember(x => x.UserId, opt => opt.Ignore())
.ForMember(x => x.LastUpdated, opt => opt.Ignore())
.ForMember(x => x.CreatedAt, opt => opt.Ignore());
}
}
11 changes: 5 additions & 6 deletions src/Orion.Api/AutoMapper/Input/CustomerInput.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
namespace Orion.Api.AutoMapper.Input
namespace Orion.Api.AutoMapper.Input;

public class CustomerInput
{
public class CustomerInput
{
public string PublicId { get; set; }
public string Name { get; set; }
}
public string PublicId { get; set; }
public string Name { get; set; }
}
17 changes: 8 additions & 9 deletions src/Orion.Api/AutoMapper/Input/UserInput.cs
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
using Orion.Domain.Entities.Enuns;

namespace Orion.Api.AutoMapper.Input
namespace Orion.Api.AutoMapper.Input;

public class UserInput
{
public class UserInput
{
public string PublicId { get; set; }
public string Name { get; set; }
public string Email { get; set; }
public string Password { get; set; }
public UserProfile Profile { get; set; }
}
public string PublicId { get; set; }
public string Name { get; set; }
public string Email { get; set; }
public string Password { get; set; }
public UserProfile Profile { get; set; }
}
15 changes: 7 additions & 8 deletions src/Orion.Api/AutoMapper/Output/CustomerOutput.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
namespace Orion.Api.AutoMapper.Output
namespace Orion.Api.AutoMapper.Output;

public class CustomerOutput
{
public class CustomerOutput
{
public string PublicId { get; set; }
public string Name { get; set; }
public DateTime LastUpdated { get; set; }
public DateTime CreatedAt { get; set; }
}
public string PublicId { get; set; }
public string Name { get; set; }
public DateTime LastUpdated { get; set; }
public DateTime CreatedAt { get; set; }
}
17 changes: 8 additions & 9 deletions src/Orion.Api/AutoMapper/Output/UserOutput.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,13 @@
using Orion.Domain.Entities.Enuns;
using Orion.Domain.Authentication;

namespace Orion.Api.AutoMapper.Output
namespace Orion.Api.AutoMapper.Output;

public class UserOutput
{
public class UserOutput
{
public string PublicId { get; set; }
public string Name { get; set; }
public string Email { get; set; }
public UserProfile Profile { get; set; }
public string ProfileDescription => Profile == UserProfile.Admin ? AuthorizationConfiguration.Roles.Admin : AuthorizationConfiguration.Roles.Customer;
}
public string PublicId { get; set; }
public string Name { get; set; }
public string Email { get; set; }
public UserProfile Profile { get; set; }
public string ProfileDescription => Profile == UserProfile.Admin ? AuthorizationConfiguration.Roles.Admin : AuthorizationConfiguration.Roles.Customer;
}
91 changes: 45 additions & 46 deletions src/Orion.Api/Bootstrapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,71 +8,70 @@
using Orion.Api.Validators;
using Orion.Ioc.Dependencies;

namespace Orion.Api
namespace Orion.Api;

public static class Bootstrapper
{
public static class Bootstrapper
public static void ConfigureApp(this IApplicationBuilder app)
{
public static void ConfigureApp(this IApplicationBuilder app)
app.UseSwagger();
app.UseSwaggerUI(c =>
{
app.UseSwagger();
app.UseSwaggerUI(c =>
{
c.SwaggerEndpoint("/swagger/v1/swagger.json", "Orion API");
});

app.UseCors(options => options.WithOrigins("*")
.AllowAnyMethod()
.AllowAnyOrigin()
.AllowAnyHeader());
c.SwaggerEndpoint("/swagger/v1/swagger.json", "Orion API");
});

app.ConfigureGlobalization();
app.UseCors(options => options.WithOrigins("*")
.AllowAnyMethod()
.AllowAnyOrigin()
.AllowAnyHeader());

app.ConfigureHealthCheck();
app.ConfigureGlobalization();

app.UseRouting();
app.ConfigureHealthCheck();

app.UseAuthentication();
app.UseAuthorization();
app.UseRouting();

app.UseEndpoints(endpoints =>
{
endpoints.MapDefaultControllerRoute();
});
}
app.UseAuthentication();
app.UseAuthorization();

public static void ConfigureServices(this IServiceCollection services, IConfiguration configuration)
app.UseEndpoints(endpoints =>
{
services.AddCors();
endpoints.MapDefaultControllerRoute();
});
}

services.ConfigureAuthentication(configuration);
public static void ConfigureServices(this IServiceCollection services, IConfiguration configuration)
{
services.AddCors();

services.ConfigureAuthentication(configuration);

services.AddControllers();
services.AddControllers();

services.AddFluentValidationAutoValidation();
services.AddFluentValidationAutoValidation();

services.AddValidatorsFromAssemblyContaining<CustomerValidator>();
services.AddValidatorsFromAssemblyContaining<CustomerValidator>();

services.AddMvc(options =>
{
options.Filters.Add(typeof(CustomValidationAttribute));
})
.AddViewLocalization(LanguageViewLocationExpanderFormat.Suffix)
.AddDataAnnotationsLocalization();
services.AddMvc(options =>
{
options.Filters.Add(typeof(CustomValidationAttribute));
})
.AddViewLocalization(LanguageViewLocationExpanderFormat.Suffix)
.AddDataAnnotationsLocalization();

services.Configure<ApiBehaviorOptions>(options =>
{
options.SuppressModelStateInvalidFilter = true;
});
services.Configure<ApiBehaviorOptions>(options =>
{
options.SuppressModelStateInvalidFilter = true;
});

services.AddLocalization(options => options.ResourcesPath = @"Resources");
services.AddApplicationHealthChecks(configuration);
services.AddLocalization(options => options.ResourcesPath = @"Resources");
services.AddApplicationHealthChecks(configuration);

services.ConfigureSwagger();
services.ConfigureApiVersioning();
services.ConfigureSwagger();
services.ConfigureApiVersioning();

services.AddDomainServices();
services.AddDomainServices();

services.ConfigureAutoMapper();
}
services.ConfigureAutoMapper();
}
}
21 changes: 10 additions & 11 deletions src/Orion.Api/Configuration/ApiVersioningConfiguration.cs
Original file line number Diff line number Diff line change
@@ -1,19 +1,18 @@
using Microsoft.AspNetCore.Mvc.Versioning;
using Microsoft.AspNetCore.Mvc;

namespace Orion.Api.Configuration
namespace Orion.Api.Configuration;

public static class ApiVersioningConfiguration
{
public static class ApiVersioningConfiguration
public static void ConfigureApiVersioning(this IServiceCollection services)
{
public static void ConfigureApiVersioning(this IServiceCollection services)
services.AddApiVersioning(o =>
{
services.AddApiVersioning(o =>
{
o.ReportApiVersions = true;
o.AssumeDefaultVersionWhenUnspecified = true;
o.DefaultApiVersion = new ApiVersion(1, 0);
o.ApiVersionReader = new HeaderApiVersionReader("x-api-version");
});
}
o.ReportApiVersions = true;
o.AssumeDefaultVersionWhenUnspecified = true;
o.DefaultApiVersion = new ApiVersion(1, 0);
o.ApiVersionReader = new HeaderApiVersionReader("x-api-version");
});
}
}
Loading

0 comments on commit b6985ce

Please sign in to comment.