Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 48 additions & 0 deletions BackendTest.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.0.31903.59
MinimumVisualStudioVersion = 10.0.40219.1
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{1FA8D7EC-62D2-4671-A019-5F281786963B}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Book.Application", "src\Book.Application\Book.Application.csproj", "{ACC26AFA-DFC1-4C23-98BB-142D3FAD8DAF}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Book.Domain", "src\Book.Domain\Book.Domain.csproj", "{FB8FC627-58A4-4F75-AAB1-49962CB2D759}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Book.Infra.Data", "src\Book.Infra.Data\Book.Infra.Data.csproj", "{F01392B5-D9FF-43D2-8FA2-01CB923E7E98}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Book.Service", "src\Book.Service\Book.Service.csproj", "{4149E5E5-3A55-4383-81A5-8D60289BF15C}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{ACC26AFA-DFC1-4C23-98BB-142D3FAD8DAF}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{ACC26AFA-DFC1-4C23-98BB-142D3FAD8DAF}.Debug|Any CPU.Build.0 = Debug|Any CPU
{ACC26AFA-DFC1-4C23-98BB-142D3FAD8DAF}.Release|Any CPU.ActiveCfg = Release|Any CPU
{ACC26AFA-DFC1-4C23-98BB-142D3FAD8DAF}.Release|Any CPU.Build.0 = Release|Any CPU
{FB8FC627-58A4-4F75-AAB1-49962CB2D759}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{FB8FC627-58A4-4F75-AAB1-49962CB2D759}.Debug|Any CPU.Build.0 = Debug|Any CPU
{FB8FC627-58A4-4F75-AAB1-49962CB2D759}.Release|Any CPU.ActiveCfg = Release|Any CPU
{FB8FC627-58A4-4F75-AAB1-49962CB2D759}.Release|Any CPU.Build.0 = Release|Any CPU
{F01392B5-D9FF-43D2-8FA2-01CB923E7E98}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{F01392B5-D9FF-43D2-8FA2-01CB923E7E98}.Debug|Any CPU.Build.0 = Debug|Any CPU
{F01392B5-D9FF-43D2-8FA2-01CB923E7E98}.Release|Any CPU.ActiveCfg = Release|Any CPU
{F01392B5-D9FF-43D2-8FA2-01CB923E7E98}.Release|Any CPU.Build.0 = Release|Any CPU
{4149E5E5-3A55-4383-81A5-8D60289BF15C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{4149E5E5-3A55-4383-81A5-8D60289BF15C}.Debug|Any CPU.Build.0 = Debug|Any CPU
{4149E5E5-3A55-4383-81A5-8D60289BF15C}.Release|Any CPU.ActiveCfg = Release|Any CPU
{4149E5E5-3A55-4383-81A5-8D60289BF15C}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(NestedProjects) = preSolution
{ACC26AFA-DFC1-4C23-98BB-142D3FAD8DAF} = {1FA8D7EC-62D2-4671-A019-5F281786963B}
{FB8FC627-58A4-4F75-AAB1-49962CB2D759} = {1FA8D7EC-62D2-4671-A019-5F281786963B}
{F01392B5-D9FF-43D2-8FA2-01CB923E7E98} = {1FA8D7EC-62D2-4671-A019-5F281786963B}
{4149E5E5-3A55-4383-81A5-8D60289BF15C} = {1FA8D7EC-62D2-4671-A019-5F281786963B}
EndGlobalSection
EndGlobal
35 changes: 35 additions & 0 deletions src/.vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
{
"version": "0.2.0",
"configurations": [
{
// Use IntelliSense to find out which attributes exist for C# debugging
// Use hover for the description of the existing attributes
// For further information visit https://github.com/OmniSharp/omnisharp-vscode/blob/master/debugger-launchjson.md
"name": ".NET Core Launch (web)",
"type": "coreclr",
"request": "launch",
"preLaunchTask": "build",
// If you have changed target frameworks, make sure to update the program path.
"program": "${workspaceFolder}/bin/Debug/net6.0/BackendTest.dll",
"args": [],
"cwd": "${workspaceFolder}",
"stopAtEntry": false,
// Enable launching a web browser when ASP.NET Core starts. For more information: https://aka.ms/VSCode-CS-LaunchJson-WebBrowser
"serverReadyAction": {
"action": "openExternally",
"pattern": "\\bNow listening on:\\s+(https?://\\S+)"
},
"env": {
"ASPNETCORE_ENVIRONMENT": "Development"
},
"sourceFileMap": {
"/Views": "${workspaceFolder}/Views"
}
},
{
"name": ".NET Core Attach",
"type": "coreclr",
"request": "attach"
}
]
}
3 changes: 3 additions & 0 deletions src/.vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"sqltools.connections": []
}
41 changes: 41 additions & 0 deletions src/.vscode/tasks.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
{
"version": "2.0.0",
"tasks": [
{
"label": "build",
"command": "dotnet",
"type": "process",
"args": [
"build",
"${workspaceFolder}/BackendTest.csproj",
"/property:GenerateFullPaths=true",
"/consoleloggerparameters:NoSummary"
],
"problemMatcher": "$msCompile"
},
{
"label": "publish",
"command": "dotnet",
"type": "process",
"args": [
"publish",
"${workspaceFolder}/BackendTest.csproj",
"/property:GenerateFullPaths=true",
"/consoleloggerparameters:NoSummary"
],
"problemMatcher": "$msCompile"
},
{
"label": "watch",
"command": "dotnet",
"type": "process",
"args": [
"watch",
"run",
"--project",
"${workspaceFolder}/BackendTest.csproj"
],
"problemMatcher": "$msCompile"
}
]
}
100 changes: 100 additions & 0 deletions src/Book.Aplication/Configuration/ApiConfig.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
using BackendTest.Extensions;
using HealthChecks.UI.Client;
using Microsoft.AspNetCore.Diagnostics.HealthChecks;
using Microsoft.AspNetCore.Mvc;

namespace BackendTest.Configuration
{
public static class ApiConfig
{
public static IServiceCollection AddApiConfig(this IServiceCollection services)
{
services.AddControllers();

services.AddApiVersioning(options =>
{
options.AssumeDefaultVersionWhenUnspecified = true;
options.DefaultApiVersion = new ApiVersion(1, 0);
options.ReportApiVersions = true;
});

services.AddVersionedApiExplorer(option =>
{
option.GroupNameFormat = "'v'VVV";
option.SubstituteApiVersionInUrl = true;
});

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

services.AddCors(options =>
{
options.AddPolicy("Development",
builder =>
builder
.AllowAnyOrigin()
.AllowAnyMethod()
.AllowAnyHeader());

options.AddPolicy("Production",
builder =>
builder
.WithMethods("GET")
.WithOrigins("http://desenvolvedor.io")
.SetIsOriginAllowedToAllowWildcardSubdomains()
.AllowAnyHeader());
});

return services;
}

public static IApplicationBuilder UseApiConfig(this IApplicationBuilder app, IWebHostEnvironment env)
{
if (env.IsDevelopment())
{
app.UseCors("Development");
app.UseDeveloperExceptionPage();
}
else
{
app.UseCors("Development");
app.UseHsts();
}

app.UseMiddleware<ExceptionMiddleware>();

app.UseHttpsRedirection();

app.UseRouting();

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

app.UseStaticFiles();

app.UseEndpoints(endpoints =>
{
endpoints.MapControllers();
endpoints.MapHealthChecks("/api/hc", new HealthCheckOptions()
{
Predicate = _ => true,
ResponseWriter = UIResponseWriter.WriteHealthCheckUIResponse
});
endpoints.MapHealthChecksUI(options =>
{
options.UIPath = "/api/hc-ui";
options.ResourcesPath = "/api/hc-ui-resources";

options.UseRelativeApiPath = false;
options.UseRelativeResourcesPath = false;
options.UseRelativeWebhookPath = false;
});

});

return app;
}
}
}
13 changes: 13 additions & 0 deletions src/Book.Aplication/Configuration/AutoMapperConfig.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
using AutoMapper;
using BackendTest.Models;

namespace BackendTest.Configuration
{
public class AutoMapperConfig : Profile
{
public AutoMapperConfig()
{
CreateMap<Book, Book>();
}
}
}
30 changes: 30 additions & 0 deletions src/Book.Aplication/Configuration/DependencyInjectionConfig.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
using BackendTest.Context;
using BackendTest.Extensions;
using BackendTest.Interfaces;
using BackendTest.Notifications;
using BackendTest.Repository;
using BackendTest.Services;
using Microsoft.Extensions.Options;
using Swashbuckle.AspNetCore.SwaggerGen;

namespace BackendTest.Configuration
{
public static class DependencyInjectionConfig
{
public static IServiceCollection ResolveDependencies(this IServiceCollection services)
{
services.AddScoped<BookApiDbContext>();
services.AddScoped<IBookRepository, BookRepository>();

services.AddScoped<INotifier, Notifier>();
services.AddScoped<IBookService, BookService>();

services.AddSingleton<IHttpContextAccessor, HttpContextAccessor>();
services.AddScoped<IUser, AspNetUser>();

services.AddTransient<IConfigureOptions<SwaggerGenOptions>, ConfigureSwaggerOptions>();

return services;
}
}
}
53 changes: 53 additions & 0 deletions src/Book.Aplication/Configuration/IdentityConfig.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
using System.Text;
using BackendTest.Extensions;
using BackendTest.Data;
using Microsoft.AspNetCore.Authentication.JwtBearer;
using Microsoft.AspNetCore.Identity;
using Microsoft.IdentityModel.Tokens;

namespace BackendTest.Configuration
{
public static class IdentityConfig
{
public static IServiceCollection AddIdentityConfig(this IServiceCollection services,
IConfiguration configuration)
{
services.AddDbContext<ApplicationDbContext>();

services.AddDefaultIdentity<IdentityUser>()
.AddRoles<IdentityRole>()
.AddEntityFrameworkStores<ApplicationDbContext>()
.AddErrorDescriber<IdentityMessagesPortuguese>()
.AddDefaultTokenProviders();

// JWT

var appSettingsSection = configuration.GetSection("AppSettings");
services.Configure<AppSettings>(appSettingsSection);

var appSettings = appSettingsSection.Get<AppSettings>();
var key = Encoding.ASCII.GetBytes(appSettings.Secret);

services.AddAuthentication(x =>
{
x.DefaultAuthenticateScheme = JwtBearerDefaults.AuthenticationScheme;
x.DefaultChallengeScheme = JwtBearerDefaults.AuthenticationScheme;
}).AddJwtBearer(x =>
{
x.RequireHttpsMetadata = true;
x.SaveToken = true;
x.TokenValidationParameters = new TokenValidationParameters
{
ValidateIssuerSigningKey = true,
IssuerSigningKey = new SymmetricSecurityKey(key),
ValidateIssuer = true,
ValidateAudience = true,
ValidAudience = appSettings.ValidoEm,
ValidIssuer = appSettings.Emissor
};
});

return services;
}
}
}
39 changes: 39 additions & 0 deletions src/Book.Aplication/Configuration/LoggerConfig.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
using BackendTest.Extensions;

namespace BackendTest.Configuration
{
public static class LoggerConfig
{
public static IServiceCollection AddLoggingConfig(this IServiceCollection services, IConfiguration configuration)
{
services.AddElmahIo(o =>
{
o.ApiKey = "388dd3a277cb44c4aa128b5c899a3106";
o.LogId = new Guid("c468b2b8-b35d-4f1a-849d-f47b60eef096");
});

services.AddHealthChecks()
.AddElmahIoPublisher(options =>
{
options.ApiKey = "388dd3a277cb44c4aa128b5c899a3106";
options.LogId = new Guid("c468b2b8-b35d-4f1a-849d-f47b60eef096");
options.HeartbeatId = "API Fornecedores";

})
.AddCheck("Produtos", new SqlServerHealthCheck(configuration.GetConnectionString("DefaultConnection")))
.AddSqlServer(configuration.GetConnectionString("DefaultConnection"), name: "BancoSQL");

services.AddHealthChecksUI()
.AddSqlServerStorage(configuration.GetConnectionString("DefaultConnection"));

return services;
}

public static IApplicationBuilder UseLoggingConfiguration(this IApplicationBuilder app)
{
app.UseElmahIo();

return app;
}
}
}
Loading