-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat ✨ : add userid saving logic along with the order
- Loading branch information
1 parent
507c981
commit f957f4f
Showing
23 changed files
with
318 additions
and
5 deletions.
There are no files selected for viewing
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
7 changes: 7 additions & 0 deletions
7
src/services/Florage.Notifications/Contracts/IEmailService.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,7 @@ | ||
namespace Florage.Notifications.Contracts | ||
{ | ||
public interface IEmailService | ||
{ | ||
void SendOrderNotification(string userName, string orderId, float price); | ||
} | ||
} |
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,7 @@ | ||
namespace Florage.Notifications.Contracts | ||
{ | ||
public interface ISmsService | ||
{ | ||
void SendOrderNotification(string userName, string orderId, float price); | ||
} | ||
} |
34 changes: 34 additions & 0 deletions
34
src/services/Florage.Notifications/Controllers/EmailController.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,34 @@ | ||
using Florage.Notifications.Contracts; | ||
using Microsoft.AspNetCore.Mvc; | ||
|
||
namespace Florage.Notifications.Controllers | ||
{ | ||
[Route("api/notifications")] | ||
[ApiController] | ||
public class EmailController : ControllerBase | ||
{ | ||
private readonly IEmailService _emailService; | ||
private readonly ISmsService _smsService; | ||
|
||
public EmailController(IEmailService emailService, ISmsService smsService) | ||
{ | ||
_emailService = emailService; | ||
_smsService = smsService; | ||
} | ||
|
||
[HttpGet("mail")] | ||
public IActionResult SendEmail() | ||
{ | ||
_emailService.SendOrderNotification("Pasindu", "123", 1000.00f); | ||
return Ok(); | ||
} | ||
|
||
|
||
[HttpGet("sms")] | ||
public IActionResult SendSms() | ||
{ | ||
_smsService.SendOrderNotification("Pasindu", "123", 1000.00f); | ||
return Ok(); | ||
} | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
src/services/Florage.Notifications/Florage.Notifications.csproj
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,15 @@ | ||
<Project Sdk="Microsoft.NET.Sdk.Web"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>net6.0</TargetFramework> | ||
<Nullable>enable</Nullable> | ||
<ImplicitUsings>enable</ImplicitUsings> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="Azure.Communication.Email" Version="1.0.0" /> | ||
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.2.3" /> | ||
<PackageReference Include="Vonage" Version="6.2.0" /> | ||
</ItemGroup> | ||
|
||
</Project> |
25 changes: 25 additions & 0 deletions
25
src/services/Florage.Notifications/Florage.Notifications.sln
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,25 @@ | ||
|
||
Microsoft Visual Studio Solution File, Format Version 12.00 | ||
# Visual Studio Version 17 | ||
VisualStudioVersion = 17.2.32630.192 | ||
MinimumVisualStudioVersion = 10.0.40219.1 | ||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Florage.Notifications", "Florage.Notifications.csproj", "{872E8CDA-2ECB-498A-8F9F-B65503399939}" | ||
EndProject | ||
Global | ||
GlobalSection(SolutionConfigurationPlatforms) = preSolution | ||
Debug|Any CPU = Debug|Any CPU | ||
Release|Any CPU = Release|Any CPU | ||
EndGlobalSection | ||
GlobalSection(ProjectConfigurationPlatforms) = postSolution | ||
{872E8CDA-2ECB-498A-8F9F-B65503399939}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | ||
{872E8CDA-2ECB-498A-8F9F-B65503399939}.Debug|Any CPU.Build.0 = Debug|Any CPU | ||
{872E8CDA-2ECB-498A-8F9F-B65503399939}.Release|Any CPU.ActiveCfg = Release|Any CPU | ||
{872E8CDA-2ECB-498A-8F9F-B65503399939}.Release|Any CPU.Build.0 = Release|Any CPU | ||
EndGlobalSection | ||
GlobalSection(SolutionProperties) = preSolution | ||
HideSolutionNode = FALSE | ||
EndGlobalSection | ||
GlobalSection(ExtensibilityGlobals) = postSolution | ||
SolutionGuid = {A8E366EB-5BA9-4898-A24C-28489421035C} | ||
EndGlobalSection | ||
EndGlobal |
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,26 @@ | ||
using Florage.Notifications.Contracts; | ||
using Florage.Notifications.Services; | ||
|
||
var builder = WebApplication.CreateBuilder(args); | ||
|
||
builder.Services.AddControllers(); | ||
builder.Services.AddEndpointsApiExplorer(); | ||
builder.Services.AddSwaggerGen(); | ||
builder.Services.AddScoped<IEmailService, EmailService>(); | ||
builder.Services.AddScoped<ISmsService, SmsService>(); | ||
|
||
var app = builder.Build(); | ||
|
||
if (app.Environment.IsDevelopment()) | ||
{ | ||
app.UseSwagger(); | ||
app.UseSwaggerUI(); | ||
} | ||
|
||
app.UseHttpsRedirection(); | ||
|
||
app.UseAuthorization(); | ||
|
||
app.MapControllers(); | ||
|
||
app.Run(); |
31 changes: 31 additions & 0 deletions
31
src/services/Florage.Notifications/Properties/launchSettings.json
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,31 @@ | ||
{ | ||
"$schema": "https://json.schemastore.org/launchsettings.json", | ||
"iisSettings": { | ||
"windowsAuthentication": false, | ||
"anonymousAuthentication": true, | ||
"iisExpress": { | ||
"applicationUrl": "http://localhost:44537", | ||
"sslPort": 44366 | ||
} | ||
}, | ||
"profiles": { | ||
"Florage.Notifications": { | ||
"commandName": "Project", | ||
"dotnetRunMessages": true, | ||
"launchBrowser": true, | ||
"launchUrl": "swagger", | ||
"applicationUrl": "https://localhost:7202;http://localhost:5202", | ||
"environmentVariables": { | ||
"ASPNETCORE_ENVIRONMENT": "Development" | ||
} | ||
}, | ||
"IIS Express": { | ||
"commandName": "IISExpress", | ||
"launchBrowser": true, | ||
"launchUrl": "swagger", | ||
"environmentVariables": { | ||
"ASPNETCORE_ENVIRONMENT": "Development" | ||
} | ||
} | ||
} | ||
} |
46 changes: 46 additions & 0 deletions
46
src/services/Florage.Notifications/Services/EmailService.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,46 @@ | ||
using Azure; | ||
using Azure.Communication.Email; | ||
using Florage.Notifications.Contracts; | ||
using Florage.Notifications.Settings; | ||
|
||
namespace Florage.Notifications.Services | ||
{ | ||
public class EmailService: IEmailService | ||
{ | ||
|
||
private readonly IConfiguration _configuration; | ||
private readonly ILogger _logger; | ||
|
||
public EmailService(IConfiguration configuration, ILogger<EmailService> logger) | ||
{ | ||
_configuration = configuration; | ||
_logger = logger; | ||
} | ||
|
||
public void SendOrderNotification(string userName, string orderId, float price) | ||
{ | ||
EmailSettings mailSettings = _configuration.GetSection("EmailSettings").Get<EmailSettings>(); ; | ||
var client = new EmailClient(mailSettings.ConnectionString); | ||
|
||
try | ||
{ | ||
var emailSendOperation = client.Send( | ||
wait: WaitUntil.Completed, | ||
senderAddress: "[email protected]", | ||
recipientAddress: "[email protected]", | ||
subject: "This is the subject", | ||
htmlContent: "<html><body>This is the html body</body></html>"); | ||
|
||
_logger.LogInformation($"Email Sent. Status = {emailSendOperation.Value.Status}"); | ||
|
||
/// Get the OperationId so that it can be used for tracking the message for troubleshooting | ||
string operationId = emailSendOperation.Id; | ||
_logger.LogInformation($"Email operation id = {operationId}"); | ||
} | ||
catch (RequestFailedException ex) | ||
{ | ||
_logger.LogInformation($"Email send operation failed with error code: {ex.ErrorCode}, message: {ex.Message}"); | ||
} | ||
} | ||
} | ||
} |
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,33 @@ | ||
using Florage.Notifications.Contracts; | ||
using Vonage; | ||
using Vonage.Request; | ||
|
||
namespace Florage.Notifications.Services | ||
{ | ||
public class SmsService : ISmsService | ||
{ | ||
private readonly VonageClient _client; | ||
private readonly IConfiguration _configuration; | ||
private Credentials credentials = Credentials.FromApiKeyAndSecret( | ||
"5330883a", | ||
"cteW8eTUQEQrNzb9" | ||
); | ||
|
||
public SmsService(IConfiguration configuration) | ||
{ | ||
_client = new VonageClient(credentials); | ||
_configuration = configuration; | ||
} | ||
|
||
public void SendOrderNotification(string userName, string orderId, float price) | ||
{ | ||
|
||
var response = _client.SmsClient.SendAnSms(new Vonage.Messaging.SendSmsRequest() | ||
{ | ||
To = "94773279388", | ||
From = "Florage Store", | ||
Text = "A text message sent using the Vonage SMS API" | ||
}); | ||
} | ||
} | ||
} |
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,7 @@ | ||
namespace Florage.Notifications.Settings | ||
{ | ||
public class EmailSettings | ||
{ | ||
public string ConnectionString { get; set; } = string.Empty; | ||
} | ||
} |
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,9 @@ | ||
namespace Florage.Notifications.Settings | ||
{ | ||
public class SmsSettings | ||
{ | ||
public string ApiKey { get; set; } = string.Empty; | ||
public string ApiSecret { get; set; } = string.Empty; | ||
public | ||
} | ||
} |
8 changes: 8 additions & 0 deletions
8
src/services/Florage.Notifications/appsettings.Development.json
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 @@ | ||
{ | ||
"Logging": { | ||
"LogLevel": { | ||
"Default": "Information", | ||
"Microsoft.AspNetCore": "Warning" | ||
} | ||
} | ||
} |
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 @@ | ||
{ | ||
"Logging": { | ||
"LogLevel": { | ||
"Default": "Information", | ||
"Microsoft.AspNetCore": "Warning" | ||
} | ||
}, | ||
"EmailSettings": { | ||
"ConnectionString": "endpoint=https://cs-florage-comminucation-server.communication.azure.com/;accesskey=s+0+kPh9OQE2nz8sKszeRueHdLZUrMBDVu7Zr0yA9Lpt3xrGckTH0zZDtDmJwZaQSBt/lyNkWaXCVPeYf49cPg==" | ||
}, | ||
"AllowedHosts": "*" | ||
} |
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
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
20 changes: 20 additions & 0 deletions
20
src/services/Florage.Payments/AsyncMessagingServices/Publishers/PaymentPublishingService.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,20 @@ | ||
using Florage.Payments.Dtos; | ||
using MassTransit; | ||
|
||
namespace Florage.Payments.AsyncMessagingServices.Publishers | ||
{ | ||
public class PaymentPublishingService | ||
{ | ||
private readonly IPublishEndpoint _publishEndpoint; | ||
|
||
public PaymentPublishingService(IPublishEndpoint publishEndpoint) | ||
{ | ||
_publishEndpoint = publishEndpoint; | ||
} | ||
|
||
public async Task PublishPaymentCreatedEvent(PublishPaymentCreatedDto paymentCreatedEvent) | ||
{ | ||
await _publishEndpoint.Publish(paymentCreatedEvent); | ||
} | ||
} | ||
} |
Oops, something went wrong.