From d166c2ec9d427789a40ced8fec6791e1002a27fd Mon Sep 17 00:00:00 2001 From: Denis Prokhorchik Date: Thu, 13 Jan 2022 04:52:18 +0300 Subject: [PATCH] chore(issue-146): add a little changes for e-sender --- .../Controllers/EmailSenderController.cs | 10 ++++++---- .../IoC/ServiceCollectionExtensions.cs | 11 +++++++++-- .../e-sender/O2NextGen.ESender.Api/Startup.cs | 2 +- 3 files changed, 16 insertions(+), 7 deletions(-) diff --git a/src/Services/e-sender/O2NextGen.ESender.Api/Controllers/EmailSenderController.cs b/src/Services/e-sender/O2NextGen.ESender.Api/Controllers/EmailSenderController.cs index e685ff3a..0fcc4ec2 100644 --- a/src/Services/e-sender/O2NextGen.ESender.Api/Controllers/EmailSenderController.cs +++ b/src/Services/e-sender/O2NextGen.ESender.Api/Controllers/EmailSenderController.cs @@ -1,5 +1,6 @@ using System.Threading; using System.Threading.Tasks; +using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; using O2NextGen.ESender.Api.Helpers; using O2NextGen.ESender.Api.Mappings; @@ -8,6 +9,7 @@ namespace O2NextGen.ESender.Api.Controllers { + [AllowAnonymous] [Route("api/[controller]")] public class EmailSenderController : ControllerBase { @@ -48,7 +50,7 @@ public async Task GetByIdAsync(long id, CancellationToken ct) [HttpPut] [Route("id")] - public async Task UpdateAsync(long id, MailRequestViewModel model, CancellationToken ct) + public async Task UpdateAsync(long id, [FromBody]MailRequestViewModel model, CancellationToken ct) { var certificate = await _emailSenderService.UpdateAsync(model.ToModel(), ct); return Ok(certificate.ToViewModel()); @@ -57,10 +59,10 @@ public async Task UpdateAsync(long id, MailRequestViewModel model [HttpPost] [HttpPut] [Route("")] - public async Task AddAsync(MailRequestViewModel model, CancellationToken ct) + public async Task AddAsync([FromBody]MailRequestViewModel model, CancellationToken ct) { - var certificate = await _emailSenderService.AddAsync(model.ToModel(), ct); - return CreatedAtAction(nameof(GetByIdAsync), new {id = certificate.Id}, certificate); + var emailRequest = await _emailSenderService.AddAsync(model.ToModel(), ct); + return CreatedAtAction(nameof(GetByIdAsync), new {id = emailRequest.Id}, emailRequest); } #endregion diff --git a/src/Services/e-sender/O2NextGen.ESender.Api/IoC/ServiceCollectionExtensions.cs b/src/Services/e-sender/O2NextGen.ESender.Api/IoC/ServiceCollectionExtensions.cs index a6ed6969..7a9bf6f3 100644 --- a/src/Services/e-sender/O2NextGen.ESender.Api/IoC/ServiceCollectionExtensions.cs +++ b/src/Services/e-sender/O2NextGen.ESender.Api/IoC/ServiceCollectionExtensions.cs @@ -1,7 +1,12 @@ using System; +using System.Linq; using Microsoft.AspNetCore.Mvc; +using Microsoft.AspNetCore.Mvc.Formatters; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; +using Newtonsoft.Json; +using Newtonsoft.Json.Converters; +using Newtonsoft.Json.Serialization; using O2NextGen.ESender.Api.Filters; using O2NextGen.ESender.Api.Helpers; using O2NextGen.ESender.Business.Services; @@ -40,8 +45,10 @@ public static IServiceCollection AddBusiness(this IServiceCollection services) public static IServiceCollection AddRequiredMvcComponents(this IServiceCollection services) { services.AddTransient(); - - var mvcBuilder = services.AddMvcCore(options => { options.Filters.Add(); }); + var mvcBuilder = services.AddMvcCore(options => + { + options.Filters.Add(); + }); mvcBuilder.SetCompatibilityVersion(CompatibilityVersion.Version_2_2); mvcBuilder.AddJsonFormatters(); return services; diff --git a/src/Services/e-sender/O2NextGen.ESender.Api/Startup.cs b/src/Services/e-sender/O2NextGen.ESender.Api/Startup.cs index 7c9ddff9..2d1b1a7a 100644 --- a/src/Services/e-sender/O2NextGen.ESender.Api/Startup.cs +++ b/src/Services/e-sender/O2NextGen.ESender.Api/Startup.cs @@ -21,7 +21,7 @@ public Startup(IConfiguration appConfiguration) public void ConfigureServices(IServiceCollection services) { - services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_1); + services.AddRequiredMvcComponents(); services.AddBusiness(); services.ConfigurePOCO(AppConfiguration.GetSection("Sender")); }