-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(issue-149): implement api gateway for e-sender api
Merge pull request #151 from live-dev999/live-dev999/issue149
- Loading branch information
Showing
12 changed files
with
254 additions
and
28 deletions.
There are no files selected for viewing
8 changes: 8 additions & 0 deletions
8
src/ApiGateways/O2NextGen.Web.BFF.Core/O2NextGen.Web.BFF.Core/Config/UrlsConfig.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
namespace O2NextGen.Web.BFF.Core.Config | ||
{ | ||
public class UrlsConfig | ||
{ | ||
public string ESenderUrl { get; set; } | ||
public string CGenUrl { get; set; } | ||
} | ||
} |
8 changes: 2 additions & 6 deletions
8
...ys/O2NextGen.Web.BFF.Core/O2NextGen.Web.BFF.Core/Features/C-Gen/CertificatesController.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 2 additions & 6 deletions
8
...ateways/O2NextGen.Web.BFF.Core/O2NextGen.Web.BFF.Core/Features/C-Gen/VersionController.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
64 changes: 64 additions & 0 deletions
64
...ways/O2NextGen.Web.BFF.Core/O2NextGen.Web.BFF.Core/Features/E-Sender/ESenderController.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
using System; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
using Microsoft.AspNetCore.Mvc; | ||
using O2NextGen.Web.BFF.Core.Features.E_Sender.Models; | ||
using O2NextGen.Web.BFF.Core.Features.E_Sender.Services; | ||
|
||
namespace O2NextGen.Web.BFF.Core.Features.E_Sender | ||
{ | ||
[Route("api/features/e-sender")] | ||
public class ESenderController : Controller | ||
{ | ||
private readonly IESenderService _senderService; | ||
|
||
public ESenderController(IESenderService senderService) | ||
{ | ||
_senderService = senderService; | ||
} | ||
|
||
#region Methods | ||
|
||
[HttpGet] | ||
[Route("")] | ||
public async Task<IActionResult> GetAllAsync() | ||
{ | ||
throw new NotImplementedException(); | ||
} | ||
|
||
[HttpGet] | ||
[Route("{id}")] | ||
public async Task<IActionResult> GetByIdAsync(long id, CancellationToken ct) | ||
{ | ||
var result = _senderService.GetAsync(id, ct); | ||
return Ok(result); | ||
} | ||
|
||
[HttpPut] | ||
[Route("id")] | ||
public async Task<IActionResult> UpdateAsync(long id, [FromBody] MailRequestViewModel model, | ||
CancellationToken ct) | ||
{ | ||
throw new NotImplementedException(); | ||
} | ||
|
||
[HttpPost] | ||
[HttpPut] | ||
[Route("")] | ||
public async Task<IActionResult> AddAsync([FromBody] MailRequestViewModel model, CancellationToken ct) | ||
{ | ||
var result = await _senderService.AddAsync(model, ct); | ||
return CreatedAtAction(nameof(GetByIdAsync), new {id = result.Id}, result); | ||
} | ||
|
||
#endregion | ||
|
||
[HttpDelete] | ||
[Route("id")] | ||
public async Task<IActionResult> RemoveAsync(long id, CancellationToken ct) | ||
{ | ||
throw new NotImplementedException(); | ||
} | ||
} | ||
} | ||
|
12 changes: 12 additions & 0 deletions
12
...tGen.Web.BFF.Core/O2NextGen.Web.BFF.Core/Features/E-Sender/Models/MailRequestViewModel.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
namespace O2NextGen.Web.BFF.Core.Features.E_Sender.Models | ||
{ | ||
public class MailRequestViewModel | ||
{ | ||
public long Id { get; set; } | ||
public string From { get; set; } | ||
public string To { get; set; } | ||
public string Body { get; set; } | ||
public string Subject { get; set; } | ||
} | ||
} | ||
|
35 changes: 35 additions & 0 deletions
35
...2NextGen.Web.BFF.Core/O2NextGen.Web.BFF.Core/Features/E-Sender/Services/ESenderService.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
using System; | ||
using System.Net.Http; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
using Microsoft.Extensions.Options; | ||
using O2NextGen.Web.BFF.Core.Config; | ||
using O2NextGen.Web.BFF.Core.Features.E_Sender.Models; | ||
|
||
namespace O2NextGen.Web.BFF.Core.Features.E_Sender.Services | ||
{ | ||
public class ESenderService: IESenderService | ||
{ | ||
private readonly HttpClient _httpClient; | ||
private readonly IOptions<UrlsConfig> _config; | ||
private string ApiVersion { get; } = "1.0"; | ||
|
||
public ESenderService(HttpClient httpClient, IOptions<UrlsConfig> config) | ||
{ | ||
_httpClient = httpClient ?? throw new ArgumentNullException(nameof(httpClient)); | ||
_config = config ?? throw new ArgumentNullException(nameof(config)); | ||
} | ||
public async Task<MailRequestViewModel> AddAsync(MailRequestViewModel model, CancellationToken ct) | ||
{ | ||
var response = await _httpClient.PostAsJsonAsync(_config.Value.ESenderUrl+"/api/emailsender",model,ct); | ||
return await response.Content.ReadAsAsync<MailRequestViewModel>(ct); | ||
} | ||
|
||
public async Task<MailRequestViewModel> GetAsync(long id, CancellationToken ct) | ||
{ | ||
var response = await _httpClient.GetAsync(_config.Value.ESenderUrl+"/api/emailsender",ct); | ||
return await response.Content.ReadAsAsync<MailRequestViewModel>(ct); | ||
|
||
} | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
...NextGen.Web.BFF.Core/O2NextGen.Web.BFF.Core/Features/E-Sender/Services/IESenderService.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
using O2NextGen.Web.BFF.Core.Features.E_Sender.Models; | ||
|
||
namespace O2NextGen.Web.BFF.Core.Features.E_Sender.Services | ||
{ | ||
public interface IESenderService | ||
{ | ||
Task<MailRequestViewModel> AddAsync(MailRequestViewModel model, CancellationToken ct); | ||
Task<MailRequestViewModel> GetAsync(long id, CancellationToken ct); | ||
} | ||
} |
8 changes: 2 additions & 6 deletions
8
...ways/O2NextGen.Web.BFF.Core/O2NextGen.Web.BFF.Core/Features/E-Sender/VersionController.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
50 changes: 50 additions & 0 deletions
50
...FF.Core/O2NextGen.Web.BFF.Core/Infrastructure/HttpClientAuthorizationDelegatingHandler.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
using System.Collections.Generic; | ||
using System.Net.Http; | ||
using System.Net.Http.Headers; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
using Microsoft.AspNetCore.Authentication; | ||
using Microsoft.AspNetCore.Http; | ||
|
||
namespace O2NextGen.Web.BFF.Core.Infrastructure | ||
{ | ||
public class HttpClientAuthorizationDelegatingHandler | ||
: DelegatingHandler | ||
{ | ||
private readonly IHttpContextAccessor _httpContextAccesor; | ||
|
||
public HttpClientAuthorizationDelegatingHandler(IHttpContextAccessor httpContextAccesor) | ||
{ | ||
_httpContextAccesor = httpContextAccesor; | ||
} | ||
|
||
protected override async Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, | ||
CancellationToken cancellationToken) | ||
{ | ||
var authorizationHeader = _httpContextAccesor.HttpContext | ||
.Request.Headers["Authorization"]; | ||
|
||
if (!string.IsNullOrEmpty(authorizationHeader)) | ||
{ | ||
request.Headers.Add("Authorization", new List<string>() {authorizationHeader}); | ||
} | ||
|
||
var token = await GetToken(); | ||
|
||
if (token != null) | ||
{ | ||
request.Headers.Authorization = new AuthenticationHeaderValue("Bearer", token); | ||
} | ||
|
||
return await base.SendAsync(request, cancellationToken); | ||
} | ||
|
||
async Task<string> GetToken() | ||
{ | ||
const string ACCESS_TOKEN = "access_token"; | ||
|
||
return await _httpContextAccesor.HttpContext | ||
.GetTokenAsync(ACCESS_TOKEN); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,6 +4,9 @@ | |
"Default": "Warning" | ||
} | ||
}, | ||
"AllowedHosts": "*" | ||
"AllowedHosts": "*", | ||
"urls": { | ||
"ESenderUrl": "https://e-sender" | ||
} | ||
} | ||
|