From c3d52518d71a64e633f4b8acd9f23de4497a9fe2 Mon Sep 17 00:00:00 2001 From: Kalil Teixeira Ventura Monteiro Date: Sat, 18 Apr 2020 16:40:20 -0300 Subject: [PATCH 1/4] Exclusao de variaveis desnecessarias --- .../Controllers/CategoryController.cs | 19 ++++++++++--------- .../Controllers/Generic/BaseCRUDController.cs | 7 +------ 2 files changed, 11 insertions(+), 15 deletions(-) diff --git a/ShareBook/ShareBook.Api/Controllers/CategoryController.cs b/ShareBook/ShareBook.Api/Controllers/CategoryController.cs index cb91ba4c..62280e96 100644 --- a/ShareBook/ShareBook.Api/Controllers/CategoryController.cs +++ b/ShareBook/ShareBook.Api/Controllers/CategoryController.cs @@ -4,16 +4,17 @@ using ShareBook.Domain.Common; using ShareBook.Service; -namespace ShareBook.Api.Controllers { - [Route ("api/[controller]")] - public class CategoryController : BaseCrudController { - private readonly IMapper _mapper; - public CategoryController (ICategoryService categoryService, - IMapper mapper) : base (categoryService, mapper) { - _mapper = mapper; - SetDefault (x => x.Name); +namespace ShareBook.Api.Controllers +{ + [Route("api/[controller]")] + public class CategoryController : BaseCrudController + { + public CategoryController(ICategoryService categoryService, + IMapper mapper) : base(categoryService, mapper) + { + SetDefault(x => x.Name); } - public override PagedList GetAll () => Paged (1, 50); + public override PagedList GetAll() => Paged(1, 50); } } \ No newline at end of file diff --git a/ShareBook/ShareBook.Api/Controllers/Generic/BaseCRUDController.cs b/ShareBook/ShareBook.Api/Controllers/Generic/BaseCRUDController.cs index 71dc8335..53781ec6 100644 --- a/ShareBook/ShareBook.Api/Controllers/Generic/BaseCRUDController.cs +++ b/ShareBook/ShareBook.Api/Controllers/Generic/BaseCRUDController.cs @@ -13,12 +13,7 @@ namespace ShareBook.Api.Controllers public class BaseCrudController : BaseCrudController where T : BaseEntity { - protected readonly IMapper _mapper; - - public BaseCrudController(IBaseService service, IMapper mapper) : base(service, mapper) - { - _mapper = mapper; - } + public BaseCrudController(IBaseService service, IMapper mapper) : base(service, mapper) { } } public class BaseCrudController : BaseDeleteController From 4e9173671968b494df77ab7c142fbb4f1bd01bfe Mon Sep 17 00:00:00 2001 From: Kalil Teixeira Ventura Monteiro Date: Sat, 18 Apr 2020 17:18:33 -0300 Subject: [PATCH 2/4] Melhoria no Swagger --- .../ShareBook.Api/Configuration/SwaggerConfiguration.cs | 6 ++---- ShareBook/ShareBook.Api/Startup.cs | 2 +- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/ShareBook/ShareBook.Api/Configuration/SwaggerConfiguration.cs b/ShareBook/ShareBook.Api/Configuration/SwaggerConfiguration.cs index b3d58a11..d1675c01 100644 --- a/ShareBook/ShareBook.Api/Configuration/SwaggerConfiguration.cs +++ b/ShareBook/ShareBook.Api/Configuration/SwaggerConfiguration.cs @@ -1,9 +1,7 @@ using Microsoft.Extensions.DependencyInjection; using Microsoft.OpenApi.Models; using System; -using System.Collections.Generic; using System.Linq; -using System.Threading.Tasks; namespace ShareBook.Api.Configuration { @@ -25,8 +23,8 @@ public static IServiceCollection RegisterSwagger(this IServiceCollection service }, License = new OpenApiLicense { - Name = "", - //Url = new Uri("") + Name = "MIT License", + Url = new Uri("https://opensource.org/licenses/MIT") } }); swagger.ResolveConflictingActions(x => x.First()); diff --git a/ShareBook/ShareBook.Api/Startup.cs b/ShareBook/ShareBook.Api/Startup.cs index 37796097..4d9a6826 100644 --- a/ShareBook/ShareBook.Api/Startup.cs +++ b/ShareBook/ShareBook.Api/Startup.cs @@ -140,7 +140,7 @@ public void Configure(IApplicationBuilder app, IWebHostEnvironment env) app.UseSwagger(); app.UseSwaggerUI(c => { - c.SwaggerEndpoint("/swagger/v1/swagger.json", "SHAREBOOK API V1"); + c.SwaggerEndpoint("/swagger/v2/swagger.json", "SHAREBOOK API V2"); }); // IMPORTANT: Make sure UseCors() is called BEFORE this From a5212815f13284333be6196c0f37b9c2c26dfc3d Mon Sep 17 00:00:00 2001 From: Kalil Teixeira Ventura Monteiro Date: Sat, 18 Apr 2020 22:38:08 -0300 Subject: [PATCH 3/4] Limpeza das classes --- .../AutoMapper/AutoMapperConfig.cs | 16 -------- .../Middleware/ExceptionHandlerMiddleware.cs | 3 +- ShareBook/ShareBook.Api/Startup.cs | 41 ------------------- .../ViewModels/AddFaciclitatorNotesVM.cs | 3 +- 4 files changed, 2 insertions(+), 61 deletions(-) delete mode 100644 ShareBook/ShareBook.Api/AutoMapper/AutoMapperConfig.cs diff --git a/ShareBook/ShareBook.Api/AutoMapper/AutoMapperConfig.cs b/ShareBook/ShareBook.Api/AutoMapper/AutoMapperConfig.cs deleted file mode 100644 index b2dd5138..00000000 --- a/ShareBook/ShareBook.Api/AutoMapper/AutoMapperConfig.cs +++ /dev/null @@ -1,16 +0,0 @@ -using AutoMapper; - -namespace ShareBook.Api.AutoMapper -{ - //public class AutoMapperConfig - //{ - // public static void RegisterMappings() - // { - // Mapper.Initialize(x => - // { - // x.AddProfile(); - // x.AddProfile(); - // }); - // } - //} -} \ No newline at end of file diff --git a/ShareBook/ShareBook.Api/Middleware/ExceptionHandlerMiddleware.cs b/ShareBook/ShareBook.Api/Middleware/ExceptionHandlerMiddleware.cs index 990f8158..827d7c45 100644 --- a/ShareBook/ShareBook.Api/Middleware/ExceptionHandlerMiddleware.cs +++ b/ShareBook/ShareBook.Api/Middleware/ExceptionHandlerMiddleware.cs @@ -10,7 +10,6 @@ namespace ShareBook.Api.Middleware { - // You may need to install the Microsoft.AspNetCore.Http.Abstractions package into your project public class ExceptionHandlerMiddleware { private readonly RequestDelegate _next; @@ -60,7 +59,7 @@ private void SendErrorToRollbar(Exception ex) StackTrace = ex.StackTrace, Source = ex.Source }; - + RollbarLocator.RollbarInstance.Log(ErrorLevel.Critical, error); } } diff --git a/ShareBook/ShareBook.Api/Startup.cs b/ShareBook/ShareBook.Api/Startup.cs index 4d9a6826..9da613cf 100644 --- a/ShareBook/ShareBook.Api/Startup.cs +++ b/ShareBook/ShareBook.Api/Startup.cs @@ -3,7 +3,6 @@ using Microsoft.AspNetCore.Diagnostics.HealthChecks; using Microsoft.AspNetCore.Hosting; using Microsoft.AspNetCore.Http; -using Microsoft.AspNetCore.Mvc; using Microsoft.EntityFrameworkCore; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; @@ -11,7 +10,6 @@ using Microsoft.Extensions.Hosting; using Microsoft.Extensions.Logging; using Rollbar.NetCore.AspNet; -using ShareBook.Api.AutoMapper; using ShareBook.Api.Configuration; using ShareBook.Api.Middleware; using ShareBook.Api.Services; @@ -21,10 +19,7 @@ using ShareBook.Service.Notification; using ShareBook.Service.Server; using ShareBook.Service.Upload; -using Swashbuckle.AspNetCore.Swagger; using System; -using System.Collections.Generic; -using System.Linq; namespace ShareBook.Api { @@ -37,15 +32,11 @@ public Startup(IConfiguration configuration) public IConfiguration Configuration { get; } - // This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { RegisterHealthChecks(services, Configuration.GetConnectionString("DefaultConnection")); services.RegisterRepositoryServices(); - //auto mapper start - //AutoMapperConfig.RegisterMappings(); - services.AddAutoMapper(typeof(Startup)); services @@ -53,9 +44,7 @@ public void ConfigureServices(IServiceCollection services) .AddJsonOptions(options => { options.JsonSerializerOptions.IgnoreNullValues = true; - //options.SerializerSettings.NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore; }); - //.SetCompatibilityVersion(CompatibilityVersion.Version_2_2); services .AddHttpContextAccessor() @@ -76,21 +65,6 @@ public void ConfigureServices(IServiceCollection services) services.RegisterSwagger(); - //services.AddSwaggerGen(c => - //{ - // c.SwaggerDoc("v1", new Info { Title = "SHAREBOOK API", Version = "v1" }); - // c.ResolveConflictingActions(x => x.First()); - // c.AddSecurityDefinition("Bearer", new ApiKeyScheme - // { - // Description = "JWT Authorization header using the Bearer scheme. Example: \"Authorization: Bearer {token}\"", - // Name = "Authorization", - // In = "header", - // Type = "apiKey" - // }); - // c.AddSecurityRequirement(new Dictionary> { { "Bearer", Enumerable.Empty () }, - // }); - //}); - services.AddCors(options => { options.AddPolicy("AllowAllHeaders", @@ -112,8 +86,6 @@ public void ConfigureServices(IServiceCollection services) MuambatorConfigurator.Configure(Configuration.GetSection("Muambator:Token").Value, Configuration.GetSection("Muambator:IsActive").Value); } - // This method gets called by the runtime. Use this method to configure the HTTP request pipeline. - //public void Configure(IApplicationBuilder app, IHostingEnvironment env) public void Configure(IApplicationBuilder app, IWebHostEnvironment env) { bool rollbarActive = Convert.ToBoolean(Configuration.GetSection("Rollbar:IsActive").Value.ToLower()); @@ -123,8 +95,6 @@ public void Configure(IApplicationBuilder app, IWebHostEnvironment env) } app.UseHealthChecks("/hc"); - //app.UseCors("AllowAllHeaders"); - app.UseDeveloperExceptionPage(); app.UseExceptionHandlerMiddleware(); @@ -143,17 +113,6 @@ public void Configure(IApplicationBuilder app, IWebHostEnvironment env) c.SwaggerEndpoint("/swagger/v2/swagger.json", "SHAREBOOK API V2"); }); - // IMPORTANT: Make sure UseCors() is called BEFORE this - //app.UseMvc(routes => - //{ - // routes.MapRoute( - // name: "default", - // template: "{controller=Book}/{action=Index}/{id?}"); - - // routes.MapSpaFallbackRoute( - // name: "spa-fallback", - // defaults: new { controller = "ClientSpa", action = "Index" }); - //}); app.UseRouting(); app.UseCors("AllowAllHeaders"); diff --git a/ShareBook/ShareBook.Api/ViewModels/AddFaciclitatorNotesVM.cs b/ShareBook/ShareBook.Api/ViewModels/AddFaciclitatorNotesVM.cs index 02b1962c..7843854e 100644 --- a/ShareBook/ShareBook.Api/ViewModels/AddFaciclitatorNotesVM.cs +++ b/ShareBook/ShareBook.Api/ViewModels/AddFaciclitatorNotesVM.cs @@ -1,5 +1,4 @@ -using ShareBook.Domain.Enums; -using System; +using System; namespace ShareBook.Api.ViewModels { From 017f135f55e99a22f22ad20f0b316ed9b1e0e992 Mon Sep 17 00:00:00 2001 From: Kalil Teixeira Ventura Monteiro Date: Sun, 19 Apr 2020 14:10:11 -0300 Subject: [PATCH 4/4] =?UTF-8?q?Corre=C3=A7=C3=A3o=20da=20vers=C3=A3o=20da?= =?UTF-8?q?=20API?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ShareBook/ShareBook.Api/Configuration/SwaggerConfiguration.cs | 4 ++-- ShareBook/ShareBook.Api/Startup.cs | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/ShareBook/ShareBook.Api/Configuration/SwaggerConfiguration.cs b/ShareBook/ShareBook.Api/Configuration/SwaggerConfiguration.cs index d1675c01..d6bb00c0 100644 --- a/ShareBook/ShareBook.Api/Configuration/SwaggerConfiguration.cs +++ b/ShareBook/ShareBook.Api/Configuration/SwaggerConfiguration.cs @@ -11,10 +11,10 @@ public static IServiceCollection RegisterSwagger(this IServiceCollection service { services.AddSwaggerGen(swagger => { - swagger.SwaggerDoc("v2", new OpenApiInfo + swagger.SwaggerDoc("v1", new OpenApiInfo { Title = "SHAREBOOK API", - Version = "v2", + Version = "v1", Description = "Open Source project", Contact = new OpenApiContact { diff --git a/ShareBook/ShareBook.Api/Startup.cs b/ShareBook/ShareBook.Api/Startup.cs index 9da613cf..8e3f15fe 100644 --- a/ShareBook/ShareBook.Api/Startup.cs +++ b/ShareBook/ShareBook.Api/Startup.cs @@ -110,7 +110,7 @@ public void Configure(IApplicationBuilder app, IWebHostEnvironment env) app.UseSwagger(); app.UseSwaggerUI(c => { - c.SwaggerEndpoint("/swagger/v2/swagger.json", "SHAREBOOK API V2"); + c.SwaggerEndpoint("/swagger/v1/swagger.json", "SHAREBOOK API V1"); }); app.UseRouting();