From 1212889080d951b72a70f97f70731617b9eeabb4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Valentina=20Cupa=C4=87?= Date: Sat, 18 Jun 2022 19:23:43 +0200 Subject: [PATCH] #26 REST API - BankAccountController --- README.md | 6 ++++ .../Controllers/BankAccountController.cs | 33 +++++++++++++++++++ .../IServiceCollectionExtensions.cs | 2 +- .../Optivem.Kata.Banking.Web.csproj | 4 +++ .../System/BankAccountControllerSystemTest.cs | 3 ++ 5 files changed, 47 insertions(+), 1 deletion(-) create mode 100644 src/Optivem.Kata.Banking.Web/Controllers/BankAccountController.cs diff --git a/README.md b/README.md index fa8e2e6..73fba6b 100644 --- a/README.md +++ b/README.md @@ -35,3 +35,9 @@ Run Tests: ``` dotnet test Optivem.Kata.Banking.sln ``` + +## Migrations + +``` +dotnet ef migrations add InitialMigration --project .\src\Optivem.Kata.Banking.Web +``` diff --git a/src/Optivem.Kata.Banking.Web/Controllers/BankAccountController.cs b/src/Optivem.Kata.Banking.Web/Controllers/BankAccountController.cs new file mode 100644 index 0000000..e8f75e0 --- /dev/null +++ b/src/Optivem.Kata.Banking.Web/Controllers/BankAccountController.cs @@ -0,0 +1,33 @@ +using MediatR; +using Microsoft.AspNetCore.Mvc; +using Optivem.Kata.Banking.Core.UseCases.OpenAccount; +using Optivem.Kata.Banking.Core.UseCases.ViewAccount; + +namespace Optivem.Kata.Banking.Web.Controllers +{ + [ApiController] + [Route("bank-accounts")] + public class BankAccountController : ControllerBase + { + private readonly IMediator _mediator; + + public BankAccountController(IMediator mediator) + { + _mediator = mediator; + } + + [HttpPost] + public async Task> OpenAccount(OpenAccountRequest request) + { + // TODO: VC: Helpr base method which is async + var response = await _mediator.Send(request); + return CreatedAtAction(nameof(ViewAccount), new { accountNumber = response.AccountNumber }, response); + } + + [HttpGet("{accountNumber}")] + public async Task> ViewAccount(string accountNumber) + { + throw new NotImplementedException(); + } + } +} diff --git a/src/Optivem.Kata.Banking.Web/Extensions/IServiceCollectionExtensions.cs b/src/Optivem.Kata.Banking.Web/Extensions/IServiceCollectionExtensions.cs index b6ceb40..cd90d26 100644 --- a/src/Optivem.Kata.Banking.Web/Extensions/IServiceCollectionExtensions.cs +++ b/src/Optivem.Kata.Banking.Web/Extensions/IServiceCollectionExtensions.cs @@ -23,7 +23,7 @@ public static void Register(this IServiceCollection services, ConfigurationManag services.AddDbContext(options => { - options.UseSqlServer(configuration.GetConnectionString("BankingDatabase")); + options.UseSqlServer(configuration.GetConnectionString("BankingDatabase"), b => b.MigrationsAssembly("Optivem.Kata.Banking.Infrastructure")); }); services.AddMediatR(typeof(CoreModule)); diff --git a/src/Optivem.Kata.Banking.Web/Optivem.Kata.Banking.Web.csproj b/src/Optivem.Kata.Banking.Web/Optivem.Kata.Banking.Web.csproj index 6e72ea7..3347096 100644 --- a/src/Optivem.Kata.Banking.Web/Optivem.Kata.Banking.Web.csproj +++ b/src/Optivem.Kata.Banking.Web/Optivem.Kata.Banking.Web.csproj @@ -8,6 +8,10 @@ + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + diff --git a/test/Optivem.Kata.Banking.Test/System/BankAccountControllerSystemTest.cs b/test/Optivem.Kata.Banking.Test/System/BankAccountControllerSystemTest.cs index 4c8073b..e8a1347 100644 --- a/test/Optivem.Kata.Banking.Test/System/BankAccountControllerSystemTest.cs +++ b/test/Optivem.Kata.Banking.Test/System/BankAccountControllerSystemTest.cs @@ -20,6 +20,9 @@ public BankAccountControllerSystemTest() var application = new WebApplicationFactory() .WithWebHostBuilder(builder => { + // var configuration = builder.Ser + + // builder.ConfigureServices(services => services.Register(builder.Conf)) // TODO: VC: Configure });