diff --git a/.gitignore b/.gitignore index 8a30d25..90c3e2c 100644 --- a/.gitignore +++ b/.gitignore @@ -396,3 +396,6 @@ FodyWeavers.xsd # JetBrains Rider *.sln.iml + +WorkshopBackend/OrderService/appsettings.json +/WorkshopBackend/OrderService/appsettings.json diff --git a/README.md b/README.md index e08400b..a6c14e4 100644 --- a/README.md +++ b/README.md @@ -5,15 +5,15 @@ Note in Every command and URL being called there are fields that need to be repl Example replacements (make sure to replace the curly brackets as well: don't keep curly brackets) -`{studentName}` - example `ajdewilzin` - this can be your name, independent of your login details +`agronmetaj` - example `ajdewilzin` - this can be your name, independent of your login details -`{region}` - example `eu-north-1` +`eu-north-1` - example `eu-north-1` ### Steps 1. Create an SNS Topic: ```bash -aws sns create-topic --name {studentName}OrderCreatedTopic +aws sns create-topic --name agronmetajOrderCreatedTopic ``` If successful, you will see in your terminal a JSON response that includes `"TopicArn": "...`. @@ -22,7 +22,7 @@ Replace `_topicArn` in your Controller code with the generated `TopicArn` value 2. Create an SQS Queue: ```bash -aws sqs create-queue --queue-name {studentName}OrderQueue +aws sqs create-queue --queue-name agronmetajOrderQueue ``` If successful, you will see in your terminal a JSON response that includes `"QueueUrl": "some_aws_url`. @@ -31,7 +31,7 @@ Replace `_queueUrl` in your Controller code with the generated `QueueUrl` from t ```bash -aws sns subscribe --topic-arn arn:aws:sns:{region}:637423341661:{studentName}OrderCreatedTopic --protocol sqs --notification-endpoint arn:aws:sqs:{region}:637423341661:{studentName}OrderQueue +aws sns subscribe --topic-arn arn:aws:sns:eu-north-1:637423341661:agronmetajOrderCreatedTopic --protocol sqs --notification-endpoint arn:aws:sqs:eu-north-1:637423341661:agronmetajOrderQueue ``` You don't need to save the generated SubscriptionArn. @@ -39,13 +39,13 @@ You don't need to save the generated SubscriptionArn. 3. Create an EventBridge Event Bus: ```bash -aws events create-event-bus --name {StudentName}CustomEventBus --region {region} +aws events create-event-bus --name agronmetajCustomEventBus --region eu-north-1 ``` 4. Create an EventBridge Rule: ```bash -aws events put-rule --name {StudentName}OrderProcessedRule --event-pattern '{\"source\": [\"order.service\"]}' --event-bus-name {StudentName}CustomEventBus +aws events put-rule --name agronmetajOrderProcessedRule --event-pattern '{\"source\": [\"order.service\"]}' --event-bus-name agronmetajCustomEventBus ``` If your terminal complains about double quotes, you might need to remove the backslash `\` from the command above (and commands later on). @@ -54,11 +54,11 @@ If your terminal complains about double quotes, you might need to remove the bac 5. Subscribe the SQS Queue to the SNS Topic ```bash -aws sqs get-queue-attributes --queue-url https://sqs.{region}.amazonaws.com/637423341661/{studentName}OrderQueue --attribute-name QueueArn --region {region} +aws sqs get-queue-attributes --queue-url https://sqs.eu-north-1.amazonaws.com/637423341661/agronmetajOrderQueue --attribute-name QueueArn --region eu-north-1 ``` ```bash -aws sns subscribe --topic-arn arn:aws:sns:{region}:637423341661:{studentName}OrderCreatedTopic --protocol sqs --notification-endpoint arn:aws:sqs:{region}:637423341661:{studentName}OrderQueue --region {region} +aws sns subscribe --topic-arn arn:aws:sns:eu-north-1:637423341661:agronmetajOrderCreatedTopic --protocol sqs --notification-endpoint arn:aws:sqs:eu-north-1:637423341661:agronmetajOrderQueue --region eu-north-1 ``` 6. Grant SNS Permissions to SQS @@ -66,7 +66,7 @@ aws sns subscribe --topic-arn arn:aws:sns:{region}:637423341661:{studentName}Ord In Bash/Unix terminals you can run this command: ```bash -aws sqs set-queue-attributes --queue-url https://sqs.{region}.amazonaws.com/637423341661/{studentName}OrderQueue --attributes '{"Policy":"{\"Version\":\"2012-10-17\",\"Statement\":[{\"Effect\":\"Allow\",\"Principal\":{\"AWS\":\"*\"},\"Action\":\"SQS:SendMessage\",\"Resource\":\"arn:aws:sqs:{region}:637423341661:{studentName}OrderQueue\",\"Condition\":{\"ArnEquals\":{\"aws:SourceArn\":\"arn:aws:sns:{region}:637423341661:{studentName}OrderCreatedTopic\"}}}]}"}' --region {region} +$ aws sqs set-queue-attributes --queue-url https://sqs.eu-north-1.amazonaws.com/637423341661/agronmetajOrderQueue --attributes file://sqs-policy.json --region eu-north-1 ``` diff --git a/WorkshopBackend/.gitignore b/WorkshopBackend/.gitignore new file mode 100644 index 0000000..104b544 --- /dev/null +++ b/WorkshopBackend/.gitignore @@ -0,0 +1,484 @@ +## Ignore Visual Studio temporary files, build results, and +## files generated by popular Visual Studio add-ons. +## +## Get latest from `dotnet new gitignore` + +# dotenv files +.env + +# User-specific files +*.rsuser +*.suo +*.user +*.userosscache +*.sln.docstates + +# User-specific files (MonoDevelop/Xamarin Studio) +*.userprefs + +# Mono auto generated files +mono_crash.* + +# Build results +[Dd]ebug/ +[Dd]ebugPublic/ +[Rr]elease/ +[Rr]eleases/ +x64/ +x86/ +[Ww][Ii][Nn]32/ +[Aa][Rr][Mm]/ +[Aa][Rr][Mm]64/ +bld/ +[Bb]in/ +[Oo]bj/ +[Ll]og/ +[Ll]ogs/ + +# Visual Studio 2015/2017 cache/options directory +.vs/ +# Uncomment if you have tasks that create the project's static files in wwwroot +#wwwroot/ + +# Visual Studio 2017 auto generated files +Generated\ Files/ + +# MSTest test Results +[Tt]est[Rr]esult*/ +[Bb]uild[Ll]og.* + +# NUnit +*.VisualState.xml +TestResult.xml +nunit-*.xml + +# Build Results of an ATL Project +[Dd]ebugPS/ +[Rr]eleasePS/ +dlldata.c + +# Benchmark Results +BenchmarkDotNet.Artifacts/ + +# .NET +project.lock.json +project.fragment.lock.json +artifacts/ + +# Tye +.tye/ + +# ASP.NET Scaffolding +ScaffoldingReadMe.txt + +# StyleCop +StyleCopReport.xml + +# Files built by Visual Studio +*_i.c +*_p.c +*_h.h +*.ilk +*.meta +*.obj +*.iobj +*.pch +*.pdb +*.ipdb +*.pgc +*.pgd +*.rsp +*.sbr +*.tlb +*.tli +*.tlh +*.tmp +*.tmp_proj +*_wpftmp.csproj +*.log +*.tlog +*.vspscc +*.vssscc +.builds +*.pidb +*.svclog +*.scc + +# Chutzpah Test files +_Chutzpah* + +# Visual C++ cache files +ipch/ +*.aps +*.ncb +*.opendb +*.opensdf +*.sdf +*.cachefile +*.VC.db +*.VC.VC.opendb + +# Visual Studio profiler +*.psess +*.vsp +*.vspx +*.sap + +# Visual Studio Trace Files +*.e2e + +# TFS 2012 Local Workspace +$tf/ + +# Guidance Automation Toolkit +*.gpState + +# ReSharper is a .NET coding add-in +_ReSharper*/ +*.[Rr]e[Ss]harper +*.DotSettings.user + +# TeamCity is a build add-in +_TeamCity* + +# DotCover is a Code Coverage Tool +*.dotCover + +# AxoCover is a Code Coverage Tool +.axoCover/* +!.axoCover/settings.json + +# Coverlet is a free, cross platform Code Coverage Tool +coverage*.json +coverage*.xml +coverage*.info + +# Visual Studio code coverage results +*.coverage +*.coveragexml + +# NCrunch +_NCrunch_* +.*crunch*.local.xml +nCrunchTemp_* + +# MightyMoose +*.mm.* +AutoTest.Net/ + +# Web workbench (sass) +.sass-cache/ + +# Installshield output folder +[Ee]xpress/ + +# DocProject is a documentation generator add-in +DocProject/buildhelp/ +DocProject/Help/*.HxT +DocProject/Help/*.HxC +DocProject/Help/*.hhc +DocProject/Help/*.hhk +DocProject/Help/*.hhp +DocProject/Help/Html2 +DocProject/Help/html + +# Click-Once directory +publish/ + +# Publish Web Output +*.[Pp]ublish.xml +*.azurePubxml +# Note: Comment the next line if you want to checkin your web deploy settings, +# but database connection strings (with potential passwords) will be unencrypted +*.pubxml +*.publishproj + +# Microsoft Azure Web App publish settings. Comment the next line if you want to +# checkin your Azure Web App publish settings, but sensitive information contained +# in these scripts will be unencrypted +PublishScripts/ + +# NuGet Packages +*.nupkg +# NuGet Symbol Packages +*.snupkg +# The packages folder can be ignored because of Package Restore +**/[Pp]ackages/* +# except build/, which is used as an MSBuild target. +!**/[Pp]ackages/build/ +# Uncomment if necessary however generally it will be regenerated when needed +#!**/[Pp]ackages/repositories.config +# NuGet v3's project.json files produces more ignorable files +*.nuget.props +*.nuget.targets + +# Microsoft Azure Build Output +csx/ +*.build.csdef + +# Microsoft Azure Emulator +ecf/ +rcf/ + +# Windows Store app package directories and files +AppPackages/ +BundleArtifacts/ +Package.StoreAssociation.xml +_pkginfo.txt +*.appx +*.appxbundle +*.appxupload + +# Visual Studio cache files +# files ending in .cache can be ignored +*.[Cc]ache +# but keep track of directories ending in .cache +!?*.[Cc]ache/ + +# Others +ClientBin/ +~$* +*~ +*.dbmdl +*.dbproj.schemaview +*.jfm +*.pfx +*.publishsettings +orleans.codegen.cs + +# Including strong name files can present a security risk +# (https://github.com/github/gitignore/pull/2483#issue-259490424) +#*.snk + +# Since there are multiple workflows, uncomment next line to ignore bower_components +# (https://github.com/github/gitignore/pull/1529#issuecomment-104372622) +#bower_components/ + +# RIA/Silverlight projects +Generated_Code/ + +# Backup & report files from converting an old project file +# to a newer Visual Studio version. Backup files are not needed, +# because we have git ;-) +_UpgradeReport_Files/ +Backup*/ +UpgradeLog*.XML +UpgradeLog*.htm +ServiceFabricBackup/ +*.rptproj.bak + +# SQL Server files +*.mdf +*.ldf +*.ndf + +# Business Intelligence projects +*.rdl.data +*.bim.layout +*.bim_*.settings +*.rptproj.rsuser +*- [Bb]ackup.rdl +*- [Bb]ackup ([0-9]).rdl +*- [Bb]ackup ([0-9][0-9]).rdl + +# Microsoft Fakes +FakesAssemblies/ + +# GhostDoc plugin setting file +*.GhostDoc.xml + +# Node.js Tools for Visual Studio +.ntvs_analysis.dat +node_modules/ + +# Visual Studio 6 build log +*.plg + +# Visual Studio 6 workspace options file +*.opt + +# Visual Studio 6 auto-generated workspace file (contains which files were open etc.) +*.vbw + +# Visual Studio 6 auto-generated project file (contains which files were open etc.) +*.vbp + +# Visual Studio 6 workspace and project file (working project files containing files to include in project) +*.dsw +*.dsp + +# Visual Studio 6 technical files +*.ncb +*.aps + +# Visual Studio LightSwitch build output +**/*.HTMLClient/GeneratedArtifacts +**/*.DesktopClient/GeneratedArtifacts +**/*.DesktopClient/ModelManifest.xml +**/*.Server/GeneratedArtifacts +**/*.Server/ModelManifest.xml +_Pvt_Extensions + +# Paket dependency manager +.paket/paket.exe +paket-files/ + +# FAKE - F# Make +.fake/ + +# CodeRush personal settings +.cr/personal + +# Python Tools for Visual Studio (PTVS) +__pycache__/ +*.pyc + +# Cake - Uncomment if you are using it +# tools/** +# !tools/packages.config + +# Tabs Studio +*.tss + +# Telerik's JustMock configuration file +*.jmconfig + +# BizTalk build output +*.btp.cs +*.btm.cs +*.odx.cs +*.xsd.cs + +# OpenCover UI analysis results +OpenCover/ + +# Azure Stream Analytics local run output +ASALocalRun/ + +# MSBuild Binary and Structured Log +*.binlog + +# NVidia Nsight GPU debugger configuration file +*.nvuser + +# MFractors (Xamarin productivity tool) working folder +.mfractor/ + +# Local History for Visual Studio +.localhistory/ + +# Visual Studio History (VSHistory) files +.vshistory/ + +# BeatPulse healthcheck temp database +healthchecksdb + +# Backup folder for Package Reference Convert tool in Visual Studio 2017 +MigrationBackup/ + +# Ionide (cross platform F# VS Code tools) working folder +.ionide/ + +# Fody - auto-generated XML schema +FodyWeavers.xsd + +# VS Code files for those working on multiple tools +.vscode/* +!.vscode/settings.json +!.vscode/tasks.json +!.vscode/launch.json +!.vscode/extensions.json +*.code-workspace + +# Local History for Visual Studio Code +.history/ + +# Windows Installer files from build outputs +*.cab +*.msi +*.msix +*.msm +*.msp + +# JetBrains Rider +*.sln.iml +.idea + +## +## Visual studio for Mac +## + + +# globs +Makefile.in +*.userprefs +*.usertasks +config.make +config.status +aclocal.m4 +install-sh +autom4te.cache/ +*.tar.gz +tarballs/ +test-results/ + +# Mac bundle stuff +*.dmg +*.app + +# content below from: https://github.com/github/gitignore/blob/master/Global/macOS.gitignore +# General +.DS_Store +.AppleDouble +.LSOverride + +# Icon must end with two \r +Icon + + +# Thumbnails +._* + +# Files that might appear in the root of a volume +.DocumentRevisions-V100 +.fseventsd +.Spotlight-V100 +.TemporaryItems +.Trashes +.VolumeIcon.icns +.com.apple.timemachine.donotpresent + +# Directories potentially created on remote AFP share +.AppleDB +.AppleDesktop +Network Trash Folder +Temporary Items +.apdisk + +# content below from: https://github.com/github/gitignore/blob/master/Global/Windows.gitignore +# Windows thumbnail cache files +Thumbs.db +ehthumbs.db +ehthumbs_vista.db + +# Dump file +*.stackdump + +# Folder config file +[Dd]esktop.ini + +# Recycle Bin used on file shares +$RECYCLE.BIN/ + +# Windows Installer files +*.cab +*.msi +*.msix +*.msm +*.msp + +# Windows shortcuts +*.lnk + +# Vim temporary swap files +*.swp diff --git a/WorkshopBackend/OrderService/Context/OrderContext.cs b/WorkshopBackend/OrderService/Context/OrderContext.cs new file mode 100644 index 0000000..69a78b9 --- /dev/null +++ b/WorkshopBackend/OrderService/Context/OrderContext.cs @@ -0,0 +1,12 @@ +using Microsoft.EntityFrameworkCore; +using InventoryService.Models; + +namespace OrderService.Context +{ + public class OrderContext : DbContext + { + public OrderContext(DbContextOptions options) : base(options) { } + + public DbSet Orders { get; set; } + } +} diff --git a/WorkshopBackend/OrderService/Controllers/OrderController.cs b/WorkshopBackend/OrderService/Controllers/OrderController.cs index e49adda..7a8cf8a 100644 --- a/WorkshopBackend/OrderService/Controllers/OrderController.cs +++ b/WorkshopBackend/OrderService/Controllers/OrderController.cs @@ -7,6 +7,8 @@ using Amazon.EventBridge.Model; using System.Text.Json; using InventoryService.Models; +using OrderService.Context; +using Microsoft.EntityFrameworkCore; [ApiController] [Route("[controller]")] @@ -15,15 +17,16 @@ public class OrderController : ControllerBase private readonly IAmazonSQS _sqs; private readonly IAmazonSimpleNotificationService _sns; private readonly IAmazonEventBridge _eventBridge; - private readonly string _queueUrl = ""; // Format of https://.* - private readonly string _topicArn = ""; // Format of arn:aws.* - - public OrderController() + private readonly string _queueUrl = "https://sqs.eu-north-1.amazonaws.com/637423341661/agronmetajOrderQueue"; // Format of https://.* + private readonly string _topicArn = "arn:aws:sns:eu-north-1:637423341661:agronmetajOrderCreatedTopic"; // Format of arn:aws.* + private OrderContext _db; + public OrderController(OrderContext db) { // Instantiate clients with default configuration _sqs = new AmazonSQSClient(); _sns = new AmazonSimpleNotificationServiceClient(); _eventBridge = new AmazonEventBridgeClient(); + _db = db; } [HttpGet] @@ -44,13 +47,32 @@ public async Task GetOrdersAndProcess() foreach (var message in response.Messages) { - var order = JsonSerializer.Deserialize(message.Body); - // Process order (e.g., update inventory) + // Define the order variable + Order? order = null; + using (JsonDocument document = JsonDocument.Parse(message.Body)) + { + string innerMessage = document.RootElement.GetProperty("Message").GetString(); + + order = JsonSerializer.Deserialize(innerMessage); + } - // Delete message after processing + // Process order (e.g., update inventory) + if (order != null) + { + var existingOrder = await _db.Orders.FindAsync(order.OrderId); + if (existingOrder != null) + { + //Calculate the total and change processed flag to true + existingOrder.Total = existingOrder.Quantity * existingOrder.Amount; + existingOrder.Processed = true; + // Update the order on RDS + _db.Entry(existingOrder).State = EntityState.Modified; + await _db.SaveChangesAsync(); + } + } await _sqs.DeleteMessageAsync(_queueUrl, message.ReceiptHandle); } - return Ok(new { Status = $"{response.Messages.Count()}Order have been processed" }); + return Ok(new { Status = $"{response.Messages.Count()} Order have been processed" }); } [HttpPost] @@ -60,6 +82,11 @@ public async Task CreateOrder([FromBody] Order order) * AmazonSimpleNotificationServiceClient * */ + + order.Processed = false; + await _db.Orders.AddAsync(order); + await _db.SaveChangesAsync(); + // Publish to SNS var message = JsonSerializer.Serialize(order); var publishRequest = new PublishRequest diff --git a/WorkshopBackend/OrderService/Migrations/20241017080823_InitialCreate.Designer.cs b/WorkshopBackend/OrderService/Migrations/20241017080823_InitialCreate.Designer.cs new file mode 100644 index 0000000..1e19d39 --- /dev/null +++ b/WorkshopBackend/OrderService/Migrations/20241017080823_InitialCreate.Designer.cs @@ -0,0 +1,59 @@ +// +using System; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; +using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; +using OrderService.Context; + +#nullable disable + +namespace OrderService.Migrations +{ + [DbContext(typeof(OrderContext))] + [Migration("20241017080823_InitialCreate")] + partial class InitialCreate + { + /// + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("ProductVersion", "8.0.10") + .HasAnnotation("Relational:MaxIdentifierLength", 63); + + NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder); + + modelBuilder.Entity("InventoryService.Models.Order", b => + { + b.Property("OrderId") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("OrderId")); + + b.Property("Amount") + .HasColumnType("integer"); + + b.Property("Processed") + .HasColumnType("boolean"); + + b.Property("Product") + .IsRequired() + .HasColumnType("text"); + + b.Property("Quantity") + .HasColumnType("integer"); + + b.Property("Total") + .HasColumnType("integer"); + + b.HasKey("OrderId"); + + b.ToTable("Orders"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/WorkshopBackend/OrderService/Migrations/20241017080823_InitialCreate.cs b/WorkshopBackend/OrderService/Migrations/20241017080823_InitialCreate.cs new file mode 100644 index 0000000..75befd4 --- /dev/null +++ b/WorkshopBackend/OrderService/Migrations/20241017080823_InitialCreate.cs @@ -0,0 +1,39 @@ +using Microsoft.EntityFrameworkCore.Migrations; +using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; + +#nullable disable + +namespace OrderService.Migrations +{ + /// + public partial class InitialCreate : Migration + { + /// + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.CreateTable( + name: "Orders", + columns: table => new + { + OrderId = table.Column(type: "integer", nullable: false) + .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), + Product = table.Column(type: "text", nullable: false), + Quantity = table.Column(type: "integer", nullable: false), + Amount = table.Column(type: "integer", nullable: false), + Processed = table.Column(type: "boolean", nullable: true), + Total = table.Column(type: "integer", nullable: true) + }, + constraints: table => + { + table.PrimaryKey("PK_Orders", x => x.OrderId); + }); + } + + /// + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropTable( + name: "Orders"); + } + } +} diff --git a/WorkshopBackend/OrderService/Migrations/OrderContextModelSnapshot.cs b/WorkshopBackend/OrderService/Migrations/OrderContextModelSnapshot.cs new file mode 100644 index 0000000..cb936b1 --- /dev/null +++ b/WorkshopBackend/OrderService/Migrations/OrderContextModelSnapshot.cs @@ -0,0 +1,56 @@ +// +using System; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; +using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; +using OrderService.Context; + +#nullable disable + +namespace OrderService.Migrations +{ + [DbContext(typeof(OrderContext))] + partial class OrderContextModelSnapshot : ModelSnapshot + { + protected override void BuildModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("ProductVersion", "8.0.10") + .HasAnnotation("Relational:MaxIdentifierLength", 63); + + NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder); + + modelBuilder.Entity("InventoryService.Models.Order", b => + { + b.Property("OrderId") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("OrderId")); + + b.Property("Amount") + .HasColumnType("integer"); + + b.Property("Processed") + .HasColumnType("boolean"); + + b.Property("Product") + .IsRequired() + .HasColumnType("text"); + + b.Property("Quantity") + .HasColumnType("integer"); + + b.Property("Total") + .HasColumnType("integer"); + + b.HasKey("OrderId"); + + b.ToTable("Orders"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/WorkshopBackend/OrderService/OrderService.csproj b/WorkshopBackend/OrderService/OrderService.csproj index 385ff06..d80a6a3 100644 --- a/WorkshopBackend/OrderService/OrderService.csproj +++ b/WorkshopBackend/OrderService/OrderService.csproj @@ -1,18 +1,26 @@ - - net8.0 - enable - enable - + + net8.0 + enable + enable + - - - - - - - - + + + + + + + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + + + + + - + \ No newline at end of file diff --git a/WorkshopBackend/OrderService/Program.cs b/WorkshopBackend/OrderService/Program.cs index 10621e8..bedb05a 100644 --- a/WorkshopBackend/OrderService/Program.cs +++ b/WorkshopBackend/OrderService/Program.cs @@ -1,4 +1,6 @@ +using Microsoft.EntityFrameworkCore; using Microsoft.OpenApi.Models; +using OrderService.Context; var builder = WebApplication.CreateBuilder(args); @@ -24,6 +26,9 @@ .AllowAnyHeader() )); +var connectionString = builder.Configuration.GetConnectionString("DefaultConnection"); +builder.Services.AddDbContext(options => options.UseNpgsql(connectionString)); + var app = builder.Build(); app.UseCors("CorsPolicy"); diff --git a/WorkshopBackend/OrderService/appsettings.json b/WorkshopBackend/OrderService/appsettings.json deleted file mode 100644 index 1c233fe..0000000 --- a/WorkshopBackend/OrderService/appsettings.json +++ /dev/null @@ -1,13 +0,0 @@ -{ - "AWS": { - "Profile": "default", - "Region": "us-west-2" - }, - "Logging": { - "LogLevel": { - "Default": "Information", - "Microsoft.AspNetCore": "Warning" - } - }, - "AllowedHosts": "*" -} diff --git a/WorkshopBackend/WorkshopBackend.sln b/WorkshopBackend/WorkshopBackend.sln index 005d47c..47f4fb9 100644 --- a/WorkshopBackend/WorkshopBackend.sln +++ b/WorkshopBackend/WorkshopBackend.sln @@ -8,6 +8,7 @@ EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{E49EF9F2-F493-4887-B8CF-FCF54A7C151D}" ProjectSection(SolutionItems) = preProject ..\README.md = ..\README.md + sqs-policy.json = sqs-policy.json EndProjectSection EndProject Global diff --git a/WorkshopBackend/sqs-policy.json b/WorkshopBackend/sqs-policy.json new file mode 100644 index 0000000..618b58a --- /dev/null +++ b/WorkshopBackend/sqs-policy.json @@ -0,0 +1,3 @@ +{ + "Policy": "{\"Version\":\"2012-10-17\",\"Statement\":[{\"Effect\":\"Allow\",\"Principal\":{\"AWS\":\"*\"},\"Action\":\"SQS:SendMessage\",\"Resource\":\"arn:aws:sqs:eu-north-1:637423341661:agronmetajOrderQueue\",\"Condition\":{\"ArnEquals\":{\"aws:SourceArn\":\"arn:aws:sns:eu-north-1:637423341661:agronmetajOrderCreatedTopic\"}}}]}" +}